aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/associations/has_many_associations_test.rb
diff options
context:
space:
mode:
authorRyuta Kamizono <kamipo@gmail.com>2017-03-09 10:13:09 +0900
committerRyuta Kamizono <kamipo@gmail.com>2017-03-09 14:21:27 +0900
commitef3d6fc1d304dbfed7e49fdf501818891839ef65 (patch)
treeca24b6ccfe2277aa34821799dc4838f1c8efdfcc /activerecord/test/cases/associations/has_many_associations_test.rb
parentc741b493409a5d8ae1f2514f73570a014ddc6b57 (diff)
downloadrails-ef3d6fc1d304dbfed7e49fdf501818891839ef65.tar.gz
rails-ef3d6fc1d304dbfed7e49fdf501818891839ef65.tar.bz2
rails-ef3d6fc1d304dbfed7e49fdf501818891839ef65.zip
Fix select with block doesn't return newly built records in has_many association
The `select` in `QueryMethods` is also an enumerable method. Enumerable methods with block should delegate to `records` on `CollectionProxy`, not `scope`. Fixes #28348.
Diffstat (limited to 'activerecord/test/cases/associations/has_many_associations_test.rb')
-rw-r--r--activerecord/test/cases/associations/has_many_associations_test.rb6
1 files changed, 6 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 ede3a44090..14f515fa1c 100644
--- a/activerecord/test/cases/associations/has_many_associations_test.rb
+++ b/activerecord/test/cases/associations/has_many_associations_test.rb
@@ -783,6 +783,12 @@ class HasManyAssociationsTest < ActiveRecord::TestCase
assert_equal [1], posts(:welcome).comments.select { |c| c.id == 1 }.map(&:id)
end
+ def test_select_with_block_and_dirty_target
+ assert_equal 2, posts(:welcome).comments.select { true }.size
+ posts(:welcome).comments.build
+ assert_equal 3, posts(:welcome).comments.select { true }.size
+ end
+
def test_select_without_foreign_key
assert_equal companies(:first_firm).accounts.first.credit_limit, companies(:first_firm).accounts.select(:credit_limit).first.credit_limit
end