aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/associations/has_many_associations_test.rb
diff options
context:
space:
mode:
authorRyuta Kamizono <kamipo@gmail.com>2018-01-03 05:44:11 +0900
committerRyuta Kamizono <kamipo@gmail.com>2018-01-03 05:44:11 +0900
commit401c42e3c3ed78e6222dd6abb982216ccd8d519e (patch)
treea611f42dd75bb28880b6a1a442b43020b806aa75 /activerecord/test/cases/associations/has_many_associations_test.rb
parenta954e1e81711def521644050db9a08f073d0636c (diff)
parent4a7b4f88cd3fc10ab56edc3f88d5db0c4f871dc9 (diff)
downloadrails-401c42e3c3ed78e6222dd6abb982216ccd8d519e.tar.gz
rails-401c42e3c3ed78e6222dd6abb982216ccd8d519e.tar.bz2
rails-401c42e3c3ed78e6222dd6abb982216ccd8d519e.zip
Merge pull request #27561 from fishbrain/count-all-in-has-many-association
Use `count(:all)` in HasManyAssociation#count_records
Diffstat (limited to 'activerecord/test/cases/associations/has_many_associations_test.rb')
-rw-r--r--activerecord/test/cases/associations/has_many_associations_test.rb8
1 files changed, 8 insertions, 0 deletions
diff --git a/activerecord/test/cases/associations/has_many_associations_test.rb b/activerecord/test/cases/associations/has_many_associations_test.rb
index 0eafd3a4e2..18548f8516 100644
--- a/activerecord/test/cases/associations/has_many_associations_test.rb
+++ b/activerecord/test/cases/associations/has_many_associations_test.rb
@@ -2529,6 +2529,14 @@ class HasManyAssociationsTest < ActiveRecord::TestCase
assert_equal [first_bulb, second_bulb], car.bulbs
end
+ test "association size calculation works with default scoped selects when not previously fetched" do
+ firm = Firm.create!(name: "Firm")
+ 5.times { firm.developers_with_select << Developer.create!(name: "Developer") }
+
+ same_firm = Firm.find(firm.id)
+ assert_equal 5, same_firm.developers_with_select.size
+ end
+
test "prevent double insertion of new object when the parent association loaded in the after save callback" do
reset_callbacks(:save, Bulb) do
Bulb.after_save { |record| record.car.bulbs.load }