Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save arktisklada/48b8d606cffe8b5ad41d3e156752eb91 to your computer and use it in GitHub Desktop.
Save arktisklada/48b8d606cffe8b5ad41d3e156752eb91 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', '4.2.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', host: 'localhost', username: 'claytonliggitt', password: '', database: 'rails', encoding: 'utf8')
ActiveRecord::Base.logger = Logger.new(STDOUT)
ActiveRecord::Schema.define do
create_table :users, force: true do |t|
end
create_table :departments, force: true do |t|
t.belongs_to :user
t.integer :account_ids, array: true, default: []
end
end
class User < ActiveRecord::Base
has_many :departments
end
class Department < ActiveRecord::Base
belongs_to :user
end
class BugTest < Minitest::Test
def test_association_pluck_array_field
user = User.create!
3.times do
user.departments.create! account_ids: [1, 2, 3]
end
assert_equal user.departments.pluck(:account_ids), [[1, 2, 3], [1, 2, 3], [1, 2, 3]]
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment