Skip to content

Instantly share code, notes, and snippets.

@batter
Created October 30, 2013 16:48
Show Gist options
  • Save batter/7235993 to your computer and use it in GitHub Desktop.
Save batter/7235993 to your computer and use it in GitHub Desktop.
Bug report test created from the ActiveRecord template for gems for [rails/rails#12664](https://github.com/rails/rails/pull/12664) and [rails/rails#12242](https://github.com/rails/rails/issues/12242).
# Activate the gem you are reporting the issue against.
gem 'activerecord', '4.0.0'
require 'active_record'
require 'minitest/autorun'
require 'logger'
# This connection will do for database-independent bug reports.
ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: ':memory:')
ActiveRecord::Base.logger = Logger.new(STDOUT)
ActiveRecord::Schema.define do
create_table :users do |t|
t.string :name
end
create_table :dogs do |t|
t.string :name
t.references :user
end
add_index :dogs, :user_id
create_table :dog_toys do |t|
t.string :name
t.references :dog
end
add_index :dog_toys, :dog_id
end
class User < ActiveRecord::Base
has_many :dogs, -> { includes :dog_toys }, :inverse_of => :user
has_many :dog_toys, :through => :dogs # this association seems to break because of the `includes` option on the `dogs` association
has_many :throughable_dogs, :class_name => 'Dog'
has_many :working_dog_toys, :class_name => 'DogToy', :through => :throughable_dogs, :source => :dog_toys # this seems to work though
end
class Dog < ActiveRecord::Base
belongs_to :user, :inverse_of => :dogs
has_many :dog_toys, :inverse_of => :dog
end
class DogToy < ActiveRecord::Base
belongs_to :dog, :inverse_of => :dog_toys
end
class BugTest < MiniTest::Unit::TestCase
def test_changed_attributes_of_serialized_attribute
user = User.create!(name: 'Mario')
dog = user.dogs.create!(name: 'Poochie')
dog.dog_toys.create!(name: 'Bone')
p user.dog_toys # raises error
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment