Forked from neerajsingh0101/with_published_versions.rb
Last active
December 15, 2015 07:08
-
-
Save betelgeuse/5220770 to your computer and use it in GitHub Desktop.
This file contains 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
gem 'activerecord', ENV['ACTIVE_RECORD_VERSION'] || '3.2.13' | |
require 'active_record' | |
require "minitest/autorun" | |
require 'minitest/pride' | |
ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: ':memory:') | |
ActiveRecord::Schema.define do | |
create_table :as, force: true do |t| | |
t.integer :b_id | |
end | |
create_table :bs, force: true do |t| | |
t.integer :d_id | |
end | |
create_table :cs, force: true do |t| | |
t.integer :thing_id | |
t.string :thing_type | |
end | |
create_table :ds, force: true do |t| | |
end | |
end | |
class A < ActiveRecord::Base | |
belongs_to :b | |
has_one :c, through: :b | |
end | |
class B < ActiveRecord::Base | |
belongs_to :d | |
has_one :c, as: :thing | |
end | |
class C < ActiveRecord::Base | |
belongs_to :thing, polymorphic: true | |
end | |
class D < ActiveRecord::Base | |
end | |
class HasManyBugTest < ActiveRecord::TestCase | |
def setup | |
A.create!(b: B.create!(d: D.create!)) | |
end | |
def test_includes | |
objects = A.includes(b: :d).includes(:c).to_a | |
queries = [] | |
ActiveSupport::Notifications.subscribe('sql.active_record') do |name, s, f, id, values| | |
queries << values[:sql] | |
end | |
objects.each { |o| o.b.d.to_s } | |
assert_empty queries | |
end | |
def teardown | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment