public
Description: Ruby on Rails
Homepage: http://rubyonrails.org
Clone URL: git://github.com/rails/rails.git
Fix regression bug that made date_select and datetime_select raise a Null 
Pointer Exception when a nil date/datetime was passed and only month and year 
were displayed [#1289 state:committed]

Signed-off-by: David Heinemeier Hansson <david@loudthinking.com>
bernardo (author)
Mon Nov 03 18:28:17 -0800 2008
dhh (committer)
Tue Nov 04 09:15:54 -0800 2008
commit  b2cd318c2e3f4d19813a5c62903319a6683aa561
tree    f30348da0b0661a4351a9c2d171e199db3ceee96
parent  a909eecbbd42e70a5bc0e099485f07dc64db5d38
...
1
2
 
 
3
4
5
...
1
2
3
4
5
6
7
0
@@ -1,5 +1,7 @@
0
 *2.2.1 [RC2 or 2.2 final]*
0
 
0
+* Fix regression bug that made date_select and datetime_select raise a Null Pointer Exception when a nil date/datetime was passed and only month and year were displayed #1289 [Bernardo Padua/Tor Erik]
0
+
0
 * Simplified the logging format for parameters (don't include controller, action, and format as duplicates) [DHH]
0
 
0
 * Remove the logging of the Session ID when the session store is CookieStore [DHH]
...
539
540
541
542
 
543
544
545
...
567
568
569
570
 
571
572
573
...
539
540
541
 
542
543
544
545
...
567
568
569
 
570
571
572
573
0
@@ -539,7 +539,7 @@ module ActionView
0
 
0
           # If the day is hidden and the month is visible, the day should be set to the 1st so all month choices are
0
           # valid (otherwise it could be 31 and february wouldn't be a valid date)
0
-          if @options[:discard_day] && !@options[:discard_month]
0
+          if @datetime && @options[:discard_day] && !@options[:discard_month]
0
             @datetime = @datetime.change(:day => 1)
0
           end
0
 
0
@@ -567,7 +567,7 @@ module ActionView
0
 
0
           # If the day is hidden and the month is visible, the day should be set to the 1st so all month choices are
0
           # valid (otherwise it could be 31 and february wouldn't be a valid date)
0
-          if @options[:discard_day] && !@options[:discard_month]
0
+          if @datetime && @options[:discard_day] && !@options[:discard_month]
0
             @datetime = @datetime.change(:day => 1)
0
           end
0
         end
...
1149
1150
1151
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1152
1153
1154
...
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
0
@@ -1149,6 +1149,46 @@ class DateHelperTest < ActionView::TestCase
0
 
0
     assert_dom_equal expected, date_select("post", "written_on", :include_blank => true)
0
   end
0
+  
0
+  def test_date_select_with_nil_and_blank_and_order
0
+    @post = Post.new
0
+
0
+    start_year = Time.now.year-5
0
+    end_year   = Time.now.year+5
0
+    
0
+    expected = '<input name="post[written_on(3i)]" type="hidden" id="post_written_on_3i"/>' + "\n"
0
+    expected <<   %{<select id="post_written_on_1i" name="post[written_on(1i)]">\n}
0
+    expected << "<option value=\"\"></option>\n"
0
+    start_year.upto(end_year) { |i| expected << %(<option value="#{i}">#{i}</option>\n) }
0
+    expected << "</select>\n"
0
+
0
+    expected << %{<select id="post_written_on_2i" name="post[written_on(2i)]">\n}
0
+    expected << "<option value=\"\"></option>\n"
0
+    1.upto(12) { |i| expected << %(<option value="#{i}">#{Date::MONTHNAMES[i]}</option>\n) }
0
+    expected << "</select>\n"
0
+
0
+    assert_dom_equal expected, date_select("post", "written_on", :order=>[:year, :month], :include_blank=>true)
0
+  end
0
+
0
+  def test_date_select_with_nil_and_blank_and_order
0
+    @post = Post.new
0
+
0
+    start_year = Time.now.year-5
0
+    end_year   = Time.now.year+5
0
+
0
+    expected = '<input name="post[written_on(3i)]" type="hidden" id="post_written_on_3i"/>' + "\n"
0
+    expected <<   %{<select id="post_written_on_1i" name="post[written_on(1i)]">\n}
0
+    expected << "<option value=\"\"></option>\n"
0
+    start_year.upto(end_year) { |i| expected << %(<option value="#{i}">#{i}</option>\n) }
0
+    expected << "</select>\n"
0
+
0
+    expected << %{<select id="post_written_on_2i" name="post[written_on(2i)]">\n}
0
+    expected << "<option value=\"\"></option>\n"
0
+    1.upto(12) { |i| expected << %(<option value="#{i}">#{Date::MONTHNAMES[i]}</option>\n) }
0
+    expected << "</select>\n"
0
+
0
+    assert_dom_equal expected, date_select("post", "written_on", :order=>[:year, :month], :include_blank=>true)
0
+  end
0
 
0
   def test_date_select_cant_override_discard_hour
0
     @post = Post.new

Comments