aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/aggregations_test.rb
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2006-05-21 17:32:37 +0000
committerDavid Heinemeier Hansson <david@loudthinking.com>2006-05-21 17:32:37 +0000
commit59c8c63ecd751136c5ed6d2e3c04a54af2025eb0 (patch)
tree050f58c08dff7884b70bb6a7d19fec925e98b632 /activerecord/test/aggregations_test.rb
parentfa207c24468b3b7c32b3c6d7128ec13a7b7d4a16 (diff)
downloadrails-59c8c63ecd751136c5ed6d2e3c04a54af2025eb0.tar.gz
rails-59c8c63ecd751136c5ed6d2e3c04a54af2025eb0.tar.bz2
rails-59c8c63ecd751136c5ed6d2e3c04a54af2025eb0.zip
Added :allow_nil option for aggregations (closes #5091) [ian.w.white@gmail.com]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4353 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/test/aggregations_test.rb')
-rw-r--r--activerecord/test/aggregations_test.rb29
1 files changed, 29 insertions, 0 deletions
diff --git a/activerecord/test/aggregations_test.rb b/activerecord/test/aggregations_test.rb
index 39adedae53..8cd4bfe481 100644
--- a/activerecord/test/aggregations_test.rb
+++ b/activerecord/test/aggregations_test.rb
@@ -63,4 +63,33 @@ class AggregationsTest < Test::Unit::TestCase
def test_gps_inequality
assert GpsLocation.new('39x110') != GpsLocation.new('39x111')
end
+
+ def test_allow_nil_gps_is_nil
+ assert_equal nil, customers(:zaphod).gps_location
+ end
+
+ def test_allow_nil_gps_set_to_nil
+ customers(:david).gps_location = nil
+ customers(:david).save
+ customers(:david).reload
+ assert_equal nil, customers(:david).gps_location
+ end
+
+ def test_allow_nil_set_address_attributes_to_nil
+ customers(:zaphod).address = nil
+ assert_equal nil, customers(:zaphod).attributes[:address_street]
+ assert_equal nil, customers(:zaphod).attributes[:address_city]
+ assert_equal nil, customers(:zaphod).attributes[:address_country]
+ end
+
+ def test_allow_nil_address_set_to_nil
+ customers(:zaphod).address = nil
+ customers(:zaphod).save
+ customers(:zaphod).reload
+ assert_equal nil, customers(:zaphod).address
+ end
+
+ def test_nil_raises_error_when_allow_nil_is_false
+ assert_raises(NoMethodError) { customers(:david).balance = nil }
+ end
end