Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Test/changelog for has_many bug on unsaved records

See issue #7950.

The previous commit fixes this bug, and is a backport of
4bc2ae0.
  • Loading branch information...
commit b6a2baee830f464344b7cb82caaa528be1db7389 1 parent a3cf03e
@georgebrock georgebrock authored
View
6 activerecord/CHANGELOG.md
@@ -1,5 +1,11 @@
## Rails 3.2.10 (unreleased)
+* Calling `include?` on `has_many` associations on unsaved records no longer
+ returns `true` when passed a record with a `nil` foreign key.
+ Fixes #7950.
+
+ *George Brocklehurst*
+
* `AR::Base#attributes_before_type_cast` now returns unserialized values for serialized attributes.
*Nikita Afanasenko*
View
7 activerecord/test/cases/associations/has_many_associations_test.rb
@@ -1225,6 +1225,13 @@ def test_included_in_collection
assert companies(:first_firm).clients.include?(Client.find(2))
end
+ def test_included_in_collection_for_new_records
+ client = Client.create(:name => 'Persisted')
+ assert_nil client.client_of
+ assert !Firm.new.clients_of_firm.include?(client),
+ 'includes a client that does not belong to any firm'
+ end
+
def test_adding_array_and_collection
assert_nothing_raised { Firm.find(:first).clients + Firm.find(:all).last.clients }
end
Please sign in to comment.
Something went wrong with that request. Please try again.