diff options
author | George Brocklehurst <george.brocklehurst@gmail.com> | 2012-10-25 23:48:22 +0200 |
---|---|---|
committer | George Brocklehurst <george.brocklehurst@gmail.com> | 2012-11-10 13:32:55 +0100 |
commit | b6a2baee830f464344b7cb82caaa528be1db7389 (patch) | |
tree | 0d66a6d0d9b12cd69fc6341ca37d4da8a6c73f75 /activerecord | |
parent | a3cf03ef99b2cfd811e0ca5cd31ef57976a9408b (diff) | |
download | rails-b6a2baee830f464344b7cb82caaa528be1db7389.tar.gz rails-b6a2baee830f464344b7cb82caaa528be1db7389.tar.bz2 rails-b6a2baee830f464344b7cb82caaa528be1db7389.zip |
Test/changelog for has_many bug on unsaved records
See issue #7950.
The previous commit fixes this bug, and is a backport of
4bc2ae0da1dd812aee759f6d13ad428354cd0e13.
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/CHANGELOG.md | 6 | ||||
-rw-r--r-- | activerecord/test/cases/associations/has_many_associations_test.rb | 7 |
2 files changed, 13 insertions, 0 deletions
diff --git a/activerecord/CHANGELOG.md b/activerecord/CHANGELOG.md index bcc7765d2e..d3abe6062e 100644 --- a/activerecord/CHANGELOG.md +++ b/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* diff --git a/activerecord/test/cases/associations/has_many_associations_test.rb b/activerecord/test/cases/associations/has_many_associations_test.rb index ed4475770b..c311bf70d2 100644 --- a/activerecord/test/cases/associations/has_many_associations_test.rb +++ b/activerecord/test/cases/associations/has_many_associations_test.rb @@ -1225,6 +1225,13 @@ class HasManyAssociationsTest < ActiveRecord::TestCase 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 |