From c220e558be33e30a7946d3604d45ba671b2e7c31 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Tue, 23 Oct 2007 17:29:42 +0000 Subject: Assigning nil to a composed_of aggregate also sets its immediate value to nil. Closes #9843. git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8002 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- activerecord/test/aggregations_test.rb | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'activerecord/test/aggregations_test.rb') diff --git a/activerecord/test/aggregations_test.rb b/activerecord/test/aggregations_test.rb index 8cd4bfe481..89927e5044 100644 --- a/activerecord/test/aggregations_test.rb +++ b/activerecord/test/aggregations_test.rb @@ -92,4 +92,19 @@ class AggregationsTest < Test::Unit::TestCase def test_nil_raises_error_when_allow_nil_is_false assert_raises(NoMethodError) { customers(:david).balance = nil } end + + def test_allow_nil_address_loaded_when_only_some_attributes_are_nil + customers(:zaphod).address_street = nil + customers(:zaphod).save + customers(:zaphod).reload + assert_kind_of Address, customers(:zaphod).address + assert customers(:zaphod).address.street.nil? + end + + def test_nil_assignment_results_in_nil + customers(:david).gps_location = GpsLocation.new('39x111') + assert_not_equal nil, customers(:david).gps_location + customers(:david).gps_location = nil + assert_equal nil, customers(:david).gps_location + end end -- cgit v1.2.3