diff options
author | José Valim <jose.valim@gmail.com> | 2011-12-14 12:37:22 -0800 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2011-12-14 12:37:22 -0800 |
commit | 2a10b914adb9329013a0c841e2155307cfd667ed (patch) | |
tree | 7bcee193934b56eec46db15c48a6d03fb8ed06f6 | |
parent | 889e8bee82ea4f75adb6de5badad512d2c615b7f (diff) | |
parent | caa1c1978733b6271309db5af488c39aacff6c5a (diff) | |
download | rails-2a10b914adb9329013a0c841e2155307cfd667ed.tar.gz rails-2a10b914adb9329013a0c841e2155307cfd667ed.tar.bz2 rails-2a10b914adb9329013a0c841e2155307cfd667ed.zip |
Merge pull request #3988 from lest/fix-date-select
fix separator insertion in date_select helper
-rw-r--r-- | actionpack/lib/action_view/helpers/date_helper.rb | 3 | ||||
-rw-r--r-- | actionpack/test/template/date_helper_test.rb | 19 |
2 files changed, 21 insertions, 1 deletions
diff --git a/actionpack/lib/action_view/helpers/date_helper.rb b/actionpack/lib/action_view/helpers/date_helper.rb index 38cf922ef4..dd2b59cb0a 100644 --- a/actionpack/lib/action_view/helpers/date_helper.rb +++ b/actionpack/lib/action_view/helpers/date_helper.rb @@ -947,8 +947,9 @@ module ActionView # and join them with their appropriate separators. def build_selects_from_types(order) select = '' + first_visible = order.find { |type| !@options[:"discard_#{type}"] } order.reverse.each do |type| - separator = separator(type) unless type == order.first # don't add on last field + separator = separator(type) unless type == first_visible # don't add before first visible field select.insert(0, separator.to_s + send("select_#{type}").to_s) end select.html_safe diff --git a/actionpack/test/template/date_helper_test.rb b/actionpack/test/template/date_helper_test.rb index 57a5895cec..fadfb59572 100644 --- a/actionpack/test/template/date_helper_test.rb +++ b/actionpack/test/template/date_helper_test.rb @@ -1396,6 +1396,25 @@ class DateHelperTest < ActionView::TestCase assert_dom_equal expected, date_select("post", "written_on", :order => [ :month, :year ]) end + def test_date_select_without_day_with_separator + @post = Post.new + @post.written_on = Date.new(2004, 6, 15) + + expected = "<input type=\"hidden\" id=\"post_written_on_3i\" name=\"post[written_on(3i)]\" value=\"1\" />\n" + + expected << %{<select id="post_written_on_2i" name="post[written_on(2i)]">\n} + expected << %{<option value="1">January</option>\n<option value="2">February</option>\n<option value="3">March</option>\n<option value="4">April</option>\n<option value="5">May</option>\n<option value="6" selected="selected">June</option>\n<option value="7">July</option>\n<option value="8">August</option>\n<option value="9">September</option>\n<option value="10">October</option>\n<option value="11">November</option>\n<option value="12">December</option>\n} + expected << "</select>\n" + + expected << "/" + + expected << %{<select id="post_written_on_1i" name="post[written_on(1i)]">\n} + expected << %{<option value="1999">1999</option>\n<option value="2000">2000</option>\n<option value="2001">2001</option>\n<option value="2002">2002</option>\n<option value="2003">2003</option>\n<option value="2004" selected="selected">2004</option>\n<option value="2005">2005</option>\n<option value="2006">2006</option>\n<option value="2007">2007</option>\n<option value="2008">2008</option>\n<option value="2009">2009</option>\n} + expected << "</select>\n" + + assert_dom_equal expected, date_select("post", "written_on", :date_separator => '/', :order => [ :month, :year ]) + end + def test_date_select_without_day_and_with_disabled_html_option @post = Post.new @post.written_on = Date.new(2004, 6, 15) |