Skip to content

Instantly share code, notes, and snippets.

@senny
Created February 10, 2014 15:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save senny/8917564 to your computer and use it in GitHub Desktop.
Save senny/8917564 to your computer and use it in GitHub Desktop.
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 :things do |t|
end
create_table :foos do |t|
t.integer :thing_id
end
create_table :bars do |t|
t.integer :thing_id
end
end
class Thing < ActiveRecord::Base
has_many :foos
has_many :bars
scope :with_foos, -> { preload(:foos) }
scope :with_bars, -> { preload(:bars) }
end
class Foo < ActiveRecord::Base
belongs_to :thing
end
class Bar < ActiveRecord::Base
belongs_to :thing
end
class BugTest < Minitest::Unit::TestCase
def test_association_stuff
assert_equal [:foos, :bars], Thing.with_foos.with_bars.preload_values
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment