Permalink
Browse files

Merge pull request #28354 from kamipo/fix_select_with_block_and_dirty…

…_target

Fix select with block doesn't return newly built records in has_many association
  • Loading branch information...
eileencodes committed Mar 9, 2017
2 parents 17c6534 + ef3d6fc commit c77cbaff49218db7e5fe93cffc2f5333e63a99c9
@@ -1,3 +1,9 @@
* Fix select with block doesn't return newly built records in has_many association.
Fixes #28348.
*Ryuta Kamizono*
* Check whether `Rails.application` defined before calling it
In #27674 we changed the migration generator to generate migrations at the
@@ -78,7 +78,7 @@ def loaded?
# # #<Pet id: nil, name: "Choo-Choo">
# # ]
#
# person.pets.select(:id, :name )
# person.pets.select(:id, :name)
# # => [
# # #<Pet id: 1, name: "Fancy-Fancy">,
# # #<Pet id: 2, name: "Spook">,
@@ -1121,7 +1121,7 @@ def reset
SpawnMethods,
].flat_map { |klass|
klass.public_instance_methods(false)
} - self.public_instance_methods(false) + [:scoping]
} - self.public_instance_methods(false) - [:select] + [:scoping]
delegate(*delegate_methods, to: :scope)
@@ -783,6 +783,12 @@ def test_select_with_block
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

0 comments on commit c77cbaf

Please sign in to comment.