diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2012-01-24 16:37:39 -0200 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2012-01-24 16:38:08 -0200 |
commit | c4b7ca06a4f80983a531b1e5094043be1e13f53a (patch) | |
tree | ec3502e0185dda11d11c48b29fa53acb16ff6a0e /actionpack/test/template | |
parent | d92b5fe07cc178f14bdd5a4ecf4adb8b96dcdd7e (diff) | |
download | rails-c4b7ca06a4f80983a531b1e5094043be1e13f53a.tar.gz rails-c4b7ca06a4f80983a531b1e5094043be1e13f53a.tar.bz2 rails-c4b7ca06a4f80983a531b1e5094043be1e13f53a.zip |
Fix date_select with discard_month and discard_year options
Closes #4553 and #4633
Diffstat (limited to 'actionpack/test/template')
-rw-r--r-- | actionpack/test/template/date_helper_test.rb | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/actionpack/test/template/date_helper_test.rb b/actionpack/test/template/date_helper_test.rb index 3614d2e77d..b69c47b476 100644 --- a/actionpack/test/template/date_helper_test.rb +++ b/actionpack/test/template/date_helper_test.rb @@ -1601,6 +1601,43 @@ class DateHelperTest < ActionView::TestCase assert_dom_equal expected, date_select("post", "written_on", :order=>[:year, :month], :include_blank=>true) end + def test_date_select_with_nil_and_blank_and_discard_month + @post = Post.new + + start_year = Time.now.year-5 + end_year = Time.now.year+5 + + expected = %{<select id="post_written_on_1i" name="post[written_on(1i)]">\n} + expected << "<option value=\"\"></option>\n" + start_year.upto(end_year) { |i| expected << %(<option value="#{i}">#{i}</option>\n) } + expected << "</select>\n" + expected << '<input name="post[written_on(2i)]" type="hidden" id="post_written_on_2i" value="1"/>' + "\n" + expected << '<input name="post[written_on(3i)]" type="hidden" id="post_written_on_3i" value="1"/>' + "\n" + + assert_dom_equal expected, date_select("post", "written_on", :discard_month => true, :include_blank=>true) + end + + def test_date_select_with_nil_and_blank_and_discard_year + @post = Post.new + + start_year = Time.now.year-5 + end_year = Time.now.year+5 + + expected = '<input id="post_written_on_1i" name="post[written_on(1i)]" type="hidden" value="1" />' + "\n" + + expected << %{<select id="post_written_on_2i" name="post[written_on(2i)]">\n} + expected << "<option value=\"\"></option>\n" + 1.upto(12) { |i| expected << %(<option value="#{i}">#{Date::MONTHNAMES[i]}</option>\n) } + expected << "</select>\n" + + expected << %{<select id="post_written_on_3i" name="post[written_on(3i)]">\n} + expected << "<option value=\"\"></option>\n" + 1.upto(31) { |i| expected << %(<option value="#{i}">#{i}</option>\n) } + expected << "</select>\n" + + assert_dom_equal expected, date_select("post", "written_on", :discard_year => true, :include_blank=>true) + end + def test_date_select_cant_override_discard_hour @post = Post.new @post.written_on = Date.new(2004, 6, 15) |