Skip to content

Instantly share code, notes, and snippets.

@khustochka
Last active January 1, 2016 01:19
Show Gist options
  • Save khustochka/8071697 to your computer and use it in GitHub Desktop.
Save khustochka/8071697 to your computer and use it in GitHub Desktop.
Active record failure, 4.1.0.beta1
unless File.exists?('Gemfile')
File.write('Gemfile', <<-GEMFILE)
source 'https://rubygems.org'
gem 'rails', github: 'rails/rails'
gem 'sqlite3'
GEMFILE
system 'bundle'
end
require 'bundler'
Bundler.setup(:default)
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 :cards do |t|
end
create_table :animals do |t|
end
create_table :observations do |t|
t.integer :animal_id
t.integer :card_id
t.integer :image_id
end
create_table :images do |t|
end
end
class Image < ActiveRecord::Base
has_many :observations
has_many :animals, through: :observations
end
class Observation < ActiveRecord::Base
belongs_to :animal
belongs_to :card
belongs_to :image
end
class Card < ActiveRecord::Base
has_many :observations
end
class Animal < ActiveRecord::Base
has_many :observations
end
class BugTest < MiniTest::Unit::TestCase
def test_association_stuff
sp = Animal.create!
card = Card.create!
obs = Observation.create!(animal: sp, card: card)
im = Image.create!
im.observations = [obs]
im.save!
# These three lines pass
assert Image.preload(:animals, :observations).to_a
assert Image.preload(:observations => :card).to_a
assert Image.preload({:observations => :card}, :animals).to_a
# This line fails
assert Image.preload(:animals, :observations => :card).to_a
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment