aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test
diff options
context:
space:
mode:
authorHugo Peixoto <theorem@Nayru.(none)>2009-08-09 09:20:18 +0100
committerJeremy Kemper <jeremy@bitsweat.net>2009-08-09 13:39:47 -0700
commit870750ed4b1e0b0e574aaec86db3e2cdf94b1190 (patch)
tree6e3b9b0c25c2f56ab3b8a934b258f274d28243d2 /activerecord/test
parent3e0951632c52018eefb86d9e0bfe77383f9622fb (diff)
downloadrails-870750ed4b1e0b0e574aaec86db3e2cdf94b1190.tar.gz
rails-870750ed4b1e0b0e574aaec86db3e2cdf94b1190.tar.bz2
rails-870750ed4b1e0b0e574aaec86db3e2cdf94b1190.zip
With multiparameter date attributes, the behaviour when empty fields are present is now coherent with the one described in the date_select documentation.
[#1715 state:committed] Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
Diffstat (limited to 'activerecord/test')
-rwxr-xr-xactiverecord/test/cases/base_test.rb47
1 files changed, 46 insertions, 1 deletions
diff --git a/activerecord/test/cases/base_test.rb b/activerecord/test/cases/base_test.rb
index 16364141df..88738d90b1 100755
--- a/activerecord/test/cases/base_test.rb
+++ b/activerecord/test/cases/base_test.rb
@@ -1070,7 +1070,25 @@ class BasicsTest < ActiveRecord::TestCase
assert_date_from_db Date.new(2004, 6, 24), topic.last_read.to_date
end
- def test_multiparameter_attributes_on_date_with_empty_date
+ def test_multiparameter_attributes_on_date_with_empty_year
+ attributes = { "last_read(1i)" => "", "last_read(2i)" => "6", "last_read(3i)" => "24" }
+ topic = Topic.find(1)
+ topic.attributes = attributes
+ # note that extra #to_date call allows test to pass for Oracle, which
+ # treats dates/times the same
+ assert_date_from_db Date.new(1, 6, 24), topic.last_read.to_date
+ end
+
+ def test_multiparameter_attributes_on_date_with_empty_month
+ attributes = { "last_read(1i)" => "2004", "last_read(2i)" => "", "last_read(3i)" => "24" }
+ topic = Topic.find(1)
+ topic.attributes = attributes
+ # note that extra #to_date call allows test to pass for Oracle, which
+ # treats dates/times the same
+ assert_date_from_db Date.new(2004, 1, 24), topic.last_read.to_date
+ end
+
+ def test_multiparameter_attributes_on_date_with_empty_day
attributes = { "last_read(1i)" => "2004", "last_read(2i)" => "6", "last_read(3i)" => "" }
topic = Topic.find(1)
topic.attributes = attributes
@@ -1079,6 +1097,33 @@ class BasicsTest < ActiveRecord::TestCase
assert_date_from_db Date.new(2004, 6, 1), topic.last_read.to_date
end
+ def test_multiparameter_attributes_on_date_with_empty_day_and_year
+ attributes = { "last_read(1i)" => "", "last_read(2i)" => "6", "last_read(3i)" => "" }
+ topic = Topic.find(1)
+ topic.attributes = attributes
+ # note that extra #to_date call allows test to pass for Oracle, which
+ # treats dates/times the same
+ assert_date_from_db Date.new(1, 6, 1), topic.last_read.to_date
+ end
+
+ def test_multiparameter_attributes_on_date_with_empty_day_and_month
+ attributes = { "last_read(1i)" => "2004", "last_read(2i)" => "", "last_read(3i)" => "" }
+ topic = Topic.find(1)
+ topic.attributes = attributes
+ # note that extra #to_date call allows test to pass for Oracle, which
+ # treats dates/times the same
+ assert_date_from_db Date.new(2004, 1, 1), topic.last_read.to_date
+ end
+
+ def test_multiparameter_attributes_on_date_with_empty_year_and_month
+ attributes = { "last_read(1i)" => "", "last_read(2i)" => "", "last_read(3i)" => "24" }
+ topic = Topic.find(1)
+ topic.attributes = attributes
+ # note that extra #to_date call allows test to pass for Oracle, which
+ # treats dates/times the same
+ assert_date_from_db Date.new(1, 1, 24), topic.last_read.to_date
+ end
+
def test_multiparameter_attributes_on_date_with_all_empty
attributes = { "last_read(1i)" => "", "last_read(2i)" => "", "last_read(3i)" => "" }
topic = Topic.find(1)