From 8f46a23d378cd807ff6c4a3b8e35723d4ef81432 Mon Sep 17 00:00:00 2001 From: Koki Ryu Date: Tue, 6 Mar 2018 22:27:23 +0900 Subject: 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: /* The rest is omitted */ --- actionview/test/template/date_helper_test.rb | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'actionview/test') 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 = %(\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 = %(