Skip to content
This repository
Browse code

Merge pull request #4641 from rafaelfranca/date_select-fix-3-2

date_select fixes [3-2-stable]
  • Loading branch information...
commit 5a66d33e28e1eed5c424d46c72ab348d7f8202e3 2 parents e0fe62b + c4b7ca0
José Valim authored January 24, 2012
6  actionpack/lib/action_view/helpers/date_helper.rb
@@ -734,7 +734,7 @@ def select_hour
734 734
 
735 735
       def select_day
736 736
         if @options[:use_hidden] || @options[:discard_day]
737  
-          build_hidden(:day, day)
  737
+          build_hidden(:day, day || 1)
738 738
         else
739 739
           build_options_and_select(:day, day, :start => 1, :end => 31, :leading_zeros => false, :use_two_digit_numbers => @options[:use_two_digit_numbers])
740 740
         end
@@ -742,7 +742,7 @@ def select_day
742 742
 
743 743
       def select_month
744 744
         if @options[:use_hidden] || @options[:discard_month]
745  
-          build_hidden(:month, month)
  745
+          build_hidden(:month, month || 1)
746 746
         else
747 747
           month_options = []
748 748
           1.upto(12) do |month_number|
@@ -756,7 +756,7 @@ def select_month
756 756
 
757 757
       def select_year
758 758
         if !@datetime || @datetime == 0
759  
-          val = ''
  759
+          val = '1'
760 760
           middle_year = Date.today.year
761 761
         else
762 762
           val = middle_year = year
39  actionpack/test/template/date_helper_test.rb
@@ -1587,7 +1587,7 @@ def test_date_select_with_nil_and_blank_and_order
1587 1587
     start_year = Time.now.year-5
1588 1588
     end_year   = Time.now.year+5
1589 1589
 
1590  
-    expected = '<input name="post[written_on(3i)]" type="hidden" id="post_written_on_3i"/>' + "\n"
  1590
+    expected = '<input name="post[written_on(3i)]" type="hidden" id="post_written_on_3i" value="1"/>' + "\n"
1591 1591
     expected <<   %{<select id="post_written_on_1i" name="post[written_on(1i)]">\n}
1592 1592
     expected << "<option value=\"\"></option>\n"
1593 1593
     start_year.upto(end_year) { |i| expected << %(<option value="#{i}">#{i}</option>\n) }
@@ -1601,6 +1601,43 @@ def test_date_select_with_nil_and_blank_and_order
1601 1601
     assert_dom_equal expected, date_select("post", "written_on", :order=>[:year, :month], :include_blank=>true)
1602 1602
   end
1603 1603
 
  1604
+  def test_date_select_with_nil_and_blank_and_discard_month
  1605
+    @post = Post.new
  1606
+
  1607
+    start_year = Time.now.year-5
  1608
+    end_year   = Time.now.year+5
  1609
+
  1610
+    expected = %{<select id="post_written_on_1i" name="post[written_on(1i)]">\n}
  1611
+    expected << "<option value=\"\"></option>\n"
  1612
+    start_year.upto(end_year) { |i| expected << %(<option value="#{i}">#{i}</option>\n) }
  1613
+    expected << "</select>\n"
  1614
+    expected << '<input name="post[written_on(2i)]" type="hidden" id="post_written_on_2i" value="1"/>' + "\n"
  1615
+    expected << '<input name="post[written_on(3i)]" type="hidden" id="post_written_on_3i" value="1"/>' + "\n"
  1616
+
  1617
+    assert_dom_equal expected, date_select("post", "written_on", :discard_month => true, :include_blank=>true)
  1618
+  end
  1619
+
  1620
+  def test_date_select_with_nil_and_blank_and_discard_year
  1621
+    @post = Post.new
  1622
+
  1623
+    start_year = Time.now.year-5
  1624
+    end_year   = Time.now.year+5
  1625
+
  1626
+    expected = '<input id="post_written_on_1i" name="post[written_on(1i)]" type="hidden" value="1" />' + "\n"
  1627
+
  1628
+    expected << %{<select id="post_written_on_2i" name="post[written_on(2i)]">\n}
  1629
+    expected << "<option value=\"\"></option>\n"
  1630
+    1.upto(12) { |i| expected << %(<option value="#{i}">#{Date::MONTHNAMES[i]}</option>\n) }
  1631
+    expected << "</select>\n"
  1632
+
  1633
+    expected << %{<select id="post_written_on_3i" name="post[written_on(3i)]">\n}
  1634
+    expected << "<option value=\"\"></option>\n"
  1635
+    1.upto(31) { |i| expected << %(<option value="#{i}">#{i}</option>\n) }
  1636
+    expected << "</select>\n"
  1637
+
  1638
+    assert_dom_equal expected, date_select("post", "written_on", :discard_year => true, :include_blank=>true)
  1639
+  end
  1640
+
1604 1641
   def test_date_select_cant_override_discard_hour
1605 1642
     @post = Post.new
1606 1643
     @post.written_on = Date.new(2004, 6, 15)

0 notes on commit 5a66d33

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