Skip to content
This repository
Browse code

patching to ensure separator is printed with order [#5816 state:resol…

…ved]

Signed-off-by: Santiago Pastorino <santiago@wyeworks.com>
  • Loading branch information...
commit 920660b19c5419c6df1c234a84e7fec71b169544 1 parent 9c9f416
Aditya Sanghi authored October 15, 2010 spastorino committed November 11, 2010
2  actionpack/lib/action_view/helpers/date_helper.rb
@@ -882,6 +882,8 @@ def build_selects_from_types(order)
882 882
         # Returns the separator for a given datetime component
883 883
         def separator(type)
884 884
           case type
  885
+            when :year
  886
+              @options[:discard_year] ? "" : @options[:date_separator]
885 887
             when :month
886 888
               @options[:discard_month] ? "" : @options[:date_separator]
887 889
             when :day
41  actionpack/test/template/date_helper_test.rb
@@ -1584,6 +1584,47 @@ def test_date_select_with_separator
1584 1584
     assert_dom_equal expected, date_select("post", "written_on", { :date_separator => " / " })
1585 1585
   end
1586 1586
 
  1587
+  def test_date_select_with_separator_and_order
  1588
+    @post = Post.new
  1589
+    @post.written_on = Date.new(2004, 6, 15)
  1590
+
  1591
+    expected = %{<select id="post_written_on_3i" name="post[written_on(3i)]">\n}
  1592
+    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" selected="selected">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<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}
  1593
+    expected << "</select>\n"
  1594
+
  1595
+    expected << " / "
  1596
+
  1597
+    expected << %{<select id="post_written_on_2i" name="post[written_on(2i)]">\n}
  1598
+    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}
  1599
+    expected << "</select>\n"
  1600
+
  1601
+    expected << " / "
  1602
+
  1603
+    expected << %{<select id="post_written_on_1i" name="post[written_on(1i)]">\n}
  1604
+    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}
  1605
+    expected << "</select>\n"
  1606
+
  1607
+    assert_dom_equal expected, date_select("post", "written_on", { :order => [:day, :month, :year], :date_separator => " / " })
  1608
+  end
  1609
+
  1610
+  def test_date_select_with_separator_and_order_and_year_discarded
  1611
+    @post = Post.new
  1612
+    @post.written_on = Date.new(2004, 6, 15)
  1613
+
  1614
+    expected = %{<select id="post_written_on_3i" name="post[written_on(3i)]">\n}
  1615
+    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" selected="selected">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<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}
  1616
+    expected << "</select>\n"
  1617
+
  1618
+    expected << " / "
  1619
+
  1620
+    expected << %{<select id="post_written_on_2i" name="post[written_on(2i)]">\n}
  1621
+    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}
  1622
+    expected << "</select>\n"
  1623
+    expected << %{<input type="hidden" id="post_written_on_1i" name="post[written_on(1i)]" value="2004" />\n}
  1624
+
  1625
+    assert_dom_equal expected, date_select("post", "written_on", { :order => [:day, :month, :year], :discard_year => true, :date_separator => " / " })
  1626
+  end
  1627
+
1587 1628
   def test_date_select_with_default_prompt
1588 1629
     @post = Post.new
1589 1630
     @post.written_on = Date.new(2004, 6, 15)

0 notes on commit 920660b

Please sign in to comment.
Something went wrong with that request. Please try again.