aboutsummaryrefslogtreecommitdiffstats
path: root/actionview/test
diff options
context:
space:
mode:
authorKoki Ryu <liukoki@gmail.com>2018-03-06 22:27:23 +0900
committerKoki Ryu <liukoki@gmail.com>2018-06-10 21:07:59 +0900
commit8f46a23d378cd807ff6c4a3b8e35723d4ef81432 (patch)
treeb639e9e230da476c41906816af19fae0e2bbda8c /actionview/test
parentfcfe29cd2641b2ce3c01bc13f39d617ec302fc8d (diff)
downloadrails-8f46a23d378cd807ff6c4a3b8e35723d4ef81432.tar.gz
rails-8f46a23d378cd807ff6c4a3b8e35723d4ef81432.tar.bz2
rails-8f46a23d378cd807ff6c4a3b8e35723d4ef81432.zip
Add `year_format` option to date_select tag. This option makes it possible to customize year
names. Lambda should be passed to use this option. Example: date_select('user_birthday', '', start_year: 1998, end_year: 2000, year_format: ->year { "Heisei #{year - 1988}" }) The HTML produced: <select id="user_birthday__1i" name="user_birthday[(1i)]"> <option value="1998">Heisei 10</option> <option value="1999">Heisei 11</option> <option value="2000">Heisei 12</option> </select> /* The rest is omitted */
Diffstat (limited to 'actionview/test')
-rw-r--r--actionview/test/template/date_helper_test.rb9
1 files changed, 9 insertions, 0 deletions
diff --git a/actionview/test/template/date_helper_test.rb b/actionview/test/template/date_helper_test.rb
index 4b4939d705..701e6c86fd 100644
--- a/actionview/test/template/date_helper_test.rb
+++ b/actionview/test/template/date_helper_test.rb
@@ -560,6 +560,15 @@ class DateHelperTest < ActionView::TestCase
assert_dom_equal expected, select_year(Date.current, include_position: true, start_year: 2003, end_year: 2005)
end
+ def test_select_year_with_custom_names
+ year_format_lambda = ->year { "Heisei #{ year - 1988 }" }
+ expected = %(<select id="date_year" name="date[year]">\n).dup
+ expected << %(<option value="2003">Heisei 15</option>\n<option value="2004">Heisei 16</option>\n<option value="2005">Heisei 17</option>\n)
+ expected << "</select>\n"
+
+ assert_dom_equal expected, select_year(nil, start_year: 2003, end_year: 2005, year_format: year_format_lambda)
+ end
+
def test_select_hour
expected = %(<select id="date_hour" name="date[hour]">\n).dup
expected << %(<option value="00">00</option>\n<option value="01">01</option>\n<option value="02">02</option>\n<option value="03">03</option>\n<option value="04">04</option>\n<option value="05">05</option>\n<option value="06">06</option>\n<option value="07">07</option>\n<option value="08" selected="selected">08</option>\n<option value="09">09</option>\n<option value="10">10</option>\n<option value="11">11</option>\n<option value="12">12</option>\n<option value="13">13</option>\n<option value="14">14</option>\n<option value="15">15</option>\n<option value="16">16</option>\n<option value="17">17</option>\n<option value="18">18</option>\n<option value="19">19</option>\n<option value="20">20</option>\n<option value="21">21</option>\n<option value="22">22</option>\n<option value="23">23</option>\n)