<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -1,5 +1,7 @@
 *2.2.1 [RC2 or 2.2 final]*
 
+* 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]
+
 * Simplified the logging format for parameters (don't include controller, action, and format as duplicates) [DHH]
 
 * Remove the logging of the Session ID when the session store is CookieStore [DHH]</diff>
      <filename>actionpack/CHANGELOG</filename>
    </modified>
    <modified>
      <diff>@@ -539,7 +539,7 @@ module ActionView
 
           # If the day is hidden and the month is visible, the day should be set to the 1st so all month choices are
           # valid (otherwise it could be 31 and february wouldn't be a valid date)
-          if @options[:discard_day] &amp;&amp; !@options[:discard_month]
+          if @datetime &amp;&amp; @options[:discard_day] &amp;&amp; !@options[:discard_month]
             @datetime = @datetime.change(:day =&gt; 1)
           end
 
@@ -567,7 +567,7 @@ module ActionView
 
           # If the day is hidden and the month is visible, the day should be set to the 1st so all month choices are
           # valid (otherwise it could be 31 and february wouldn't be a valid date)
-          if @options[:discard_day] &amp;&amp; !@options[:discard_month]
+          if @datetime &amp;&amp; @options[:discard_day] &amp;&amp; !@options[:discard_month]
             @datetime = @datetime.change(:day =&gt; 1)
           end
         end</diff>
      <filename>actionpack/lib/action_view/helpers/date_helper.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1149,6 +1149,46 @@ class DateHelperTest &lt; ActionView::TestCase
 
     assert_dom_equal expected, date_select(&quot;post&quot;, &quot;written_on&quot;, :include_blank =&gt; true)
   end
+  
+  def test_date_select_with_nil_and_blank_and_order
+    @post = Post.new
+
+    start_year = Time.now.year-5
+    end_year   = Time.now.year+5
+    
+    expected = '&lt;input name=&quot;post[written_on(3i)]&quot; type=&quot;hidden&quot; id=&quot;post_written_on_3i&quot;/&gt;' + &quot;\n&quot;
+    expected &lt;&lt;   %{&lt;select id=&quot;post_written_on_1i&quot; name=&quot;post[written_on(1i)]&quot;&gt;\n}
+    expected &lt;&lt; &quot;&lt;option value=\&quot;\&quot;&gt;&lt;/option&gt;\n&quot;
+    start_year.upto(end_year) { |i| expected &lt;&lt; %(&lt;option value=&quot;#{i}&quot;&gt;#{i}&lt;/option&gt;\n) }
+    expected &lt;&lt; &quot;&lt;/select&gt;\n&quot;
+
+    expected &lt;&lt; %{&lt;select id=&quot;post_written_on_2i&quot; name=&quot;post[written_on(2i)]&quot;&gt;\n}
+    expected &lt;&lt; &quot;&lt;option value=\&quot;\&quot;&gt;&lt;/option&gt;\n&quot;
+    1.upto(12) { |i| expected &lt;&lt; %(&lt;option value=&quot;#{i}&quot;&gt;#{Date::MONTHNAMES[i]}&lt;/option&gt;\n) }
+    expected &lt;&lt; &quot;&lt;/select&gt;\n&quot;
+
+    assert_dom_equal expected, date_select(&quot;post&quot;, &quot;written_on&quot;, :order=&gt;[:year, :month], :include_blank=&gt;true)
+  end
+
+  def test_date_select_with_nil_and_blank_and_order
+    @post = Post.new
+
+    start_year = Time.now.year-5
+    end_year   = Time.now.year+5
+
+    expected = '&lt;input name=&quot;post[written_on(3i)]&quot; type=&quot;hidden&quot; id=&quot;post_written_on_3i&quot;/&gt;' + &quot;\n&quot;
+    expected &lt;&lt;   %{&lt;select id=&quot;post_written_on_1i&quot; name=&quot;post[written_on(1i)]&quot;&gt;\n}
+    expected &lt;&lt; &quot;&lt;option value=\&quot;\&quot;&gt;&lt;/option&gt;\n&quot;
+    start_year.upto(end_year) { |i| expected &lt;&lt; %(&lt;option value=&quot;#{i}&quot;&gt;#{i}&lt;/option&gt;\n) }
+    expected &lt;&lt; &quot;&lt;/select&gt;\n&quot;
+
+    expected &lt;&lt; %{&lt;select id=&quot;post_written_on_2i&quot; name=&quot;post[written_on(2i)]&quot;&gt;\n}
+    expected &lt;&lt; &quot;&lt;option value=\&quot;\&quot;&gt;&lt;/option&gt;\n&quot;
+    1.upto(12) { |i| expected &lt;&lt; %(&lt;option value=&quot;#{i}&quot;&gt;#{Date::MONTHNAMES[i]}&lt;/option&gt;\n) }
+    expected &lt;&lt; &quot;&lt;/select&gt;\n&quot;
+
+    assert_dom_equal expected, date_select(&quot;post&quot;, &quot;written_on&quot;, :order=&gt;[:year, :month], :include_blank=&gt;true)
+  end
 
   def test_date_select_cant_override_discard_hour
     @post = Post.new</diff>
      <filename>actionpack/test/template/date_helper_test.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>a909eecbbd42e70a5bc0e099485f07dc64db5d38</id>
    </parent>
  </parents>
  <author>
    <name>Bernardo de P&#225;dua</name>
    <email>berpasan@gmail.com</email>
  </author>
  <url>http://github.com/rails/rails/commit/b2cd318c2e3f4d19813a5c62903319a6683aa561</url>
  <id>b2cd318c2e3f4d19813a5c62903319a6683aa561</id>
  <committed-date>2008-11-04T09:15:54-08:00</committed-date>
  <authored-date>2008-11-03T18:28:17-08:00</authored-date>
  <message>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 &lt;david@loudthinking.com&gt;</message>
  <tree>f30348da0b0661a4351a9c2d171e199db3ceee96</tree>
  <committer>
    <name>David Heinemeier Hansson</name>
    <email>david@loudthinking.com</email>
  </committer>
</commit>
