Skip to content

Instantly share code, notes, and snippets.

@alexcameron89
Created June 19, 2017 16:05
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexcameron89/1fcf7f00cfad0aa9fe04f41e71a2318e to your computer and use it in GitHub Desktop.
Save alexcameron89/1fcf7f00cfad0aa9fe04f41e71a2318e to your computer and use it in GitHub Desktop.
begin
require "bundler/inline"
rescue LoadError => e
$stderr.puts "Bundler version 1.10 or later is required. Please update your Bundler"
raise e
end
gemfile(true) do
source "https://rubygems.org"
gem "rails", "5.0.3"
gem "pg"
end
require "active_record"
require "minitest/autorun"
require "logger"
# This connection will do for database-independent bug reports.
ActiveRecord::Base.establish_connection(adapter: "postgresql", database: "rails")
ActiveRecord::Base.logger = Logger.new(STDOUT)
ActiveRecord::Schema.define do
drop_table :things, if_exists: true
create_table :things do |t|
t.text :tags, array: true, default: []
t.timestamps
end
drop_table :other_things, if_exists: true
create_table :other_things do |t|
t.text :tags, array: true, default: []
t.timestamps
end
end
class Thing < ActiveRecord::Base
serialize(:tags, Array)
end
class OtherThing < ActiveRecord::Base
end
class BugTest < Minitest::Test
def test_pg_array_stuff_with_serialize
thing = Thing.create(tags: ["a", "b", "c"])
assert thing.persisted?
assert_equal ["a", "b", "c"], thing.tags
end
def test_pg_array_stuff_without_serialize
other_thing = OtherThing.create(tags: ["a", "b", "c"])
assert other_thing.persisted?
assert_equal ["a", "b", "c"], other_thing.tags
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment