Created
February 10, 2014 15:09
-
-
Save senny/8917564 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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