diff options
author | Izumi Wong-Horiuchi <izumiwongh@gmail.com> | 2014-03-21 16:28:47 -0400 |
---|---|---|
committer | Izumi Wong-Horiuchi <izumiwongh@gmail.com> | 2014-03-24 20:00:20 -0400 |
commit | 60ed9d62826678006f0c8abde25ee779b1740c3a (patch) | |
tree | 61e4141d658d399eed92e853c9b312866f395322 /actionview | |
parent | b9440c36dd881ca2643127ba372b2a40e2a4d37b (diff) | |
download | rails-60ed9d62826678006f0c8abde25ee779b1740c3a.tar.gz rails-60ed9d62826678006f0c8abde25ee779b1740c3a.tar.bz2 rails-60ed9d62826678006f0c8abde25ee779b1740c3a.zip |
Fix date_select option overwriting html classes
with_css_classes: true option overwrites other html classes.
Concatenate day month and year classes rather than overwriting.
Diffstat (limited to 'actionview')
-rw-r--r-- | actionview/CHANGELOG.md | 4 | ||||
-rw-r--r-- | actionview/lib/action_view/helpers/date_helper.rb | 2 | ||||
-rw-r--r-- | actionview/test/template/date_helper_test.rb | 16 |
3 files changed, 21 insertions, 1 deletions
diff --git a/actionview/CHANGELOG.md b/actionview/CHANGELOG.md index db3fa3be86..8c6db33be7 100644 --- a/actionview/CHANGELOG.md +++ b/actionview/CHANGELOG.md @@ -1,3 +1,7 @@ +* `date_select` helper with option `with_css_classes: true` does not overwrite other classes. + + *Izumi Wong-Horiuchi* + * `number_to_percentage` does not crash with `Float::NAN` or `Float::INFINITY` as input. diff --git a/actionview/lib/action_view/helpers/date_helper.rb b/actionview/lib/action_view/helpers/date_helper.rb index 1738df9cac..2efb9612ac 100644 --- a/actionview/lib/action_view/helpers/date_helper.rb +++ b/actionview/lib/action_view/helpers/date_helper.rb @@ -965,7 +965,7 @@ module ActionView :name => input_name_from_type(type) }.merge!(@html_options) select_options[:disabled] = 'disabled' if @options[:disabled] - select_options[:class] = type if @options[:with_css_classes] + select_options[:class] = [select_options[:class], type].compact.join(' ') if @options[:with_css_classes] select_html = "\n" select_html << content_tag(:option, '', :value => '') + "\n" if @options[:include_blank] diff --git a/actionview/test/template/date_helper_test.rb b/actionview/test/template/date_helper_test.rb index 6f77c3c99d..b86ae910c4 100644 --- a/actionview/test/template/date_helper_test.rb +++ b/actionview/test/template/date_helper_test.rb @@ -1040,6 +1040,22 @@ class DateHelperTest < ActionView::TestCase assert_dom_equal expected, select_date(Time.mktime(2003, 8, 16), {:start_year => 2003, :end_year => 2005, :prefix => "date[first]", :with_css_classes => true}) end + def test_select_date_with_css_classes_option_and_html_class_option + expected = %(<select id="date_first_year" name="date[first][year]" class="datetime optional year">\n) + expected << %(<option value="2003" selected="selected">2003</option>\n<option value="2004">2004</option>\n<option value="2005">2005</option>\n) + expected << "</select>\n" + + expected << %(<select id="date_first_month" name="date[first][month]" class="datetime optional month">\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">June</option>\n<option value="7">July</option>\n<option value="8" selected="selected">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 << %(<select id="date_first_day" name="date[first][day]" class="datetime optional day">\n) + expected << %(<option value="1">1</option>\n<option value="2">2</option>\n<option value="3">3</option>\n<option value="4">4</option>\n<option value="5">5</option>\n<option value="6">6</option>\n<option value="7">7</option>\n<option value="8">8</option>\n<option value="9">9</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" selected="selected">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<option value="24">24</option>\n<option value="25">25</option>\n<option value="26">26</option>\n<option value="27">27</option>\n<option value="28">28</option>\n<option value="29">29</option>\n<option value="30">30</option>\n<option value="31">31</option>\n) + expected << "</select>\n" + + assert_dom_equal expected, select_date(Time.mktime(2003, 8, 16), {:start_year => 2003, :end_year => 2005, :prefix => "date[first]", :with_css_classes => true}, { class: 'datetime optional' }) + end + def test_select_datetime expected = %(<select id="date_first_year" name="date[first][year]">\n) expected << %(<option value="2003" selected="selected">2003</option>\n<option value="2004">2004</option>\n<option value="2005">2005</option>\n) |