<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -2,13 +2,27 @@ module PageHelper
   
   # TODO: should be made customisable
   MEETING_WDAY = 3        # Wednesday
-  
-  # returns the date for the next meeting
+
+  # returns the date for the next meeting from today and formats the output for display
   def next_meeting_date
-    last_day_of_month = Date.today.end_of_month
+    meeting_date(Date.today).to_s(:rfc822)
+  end
+  
+  # returns the date for the next meeting after a particular date
+  def meeting_date(date)
+    last_day_of_month = date.end_of_month
     total = last_day_of_month.wday + MEETING_WDAY + 1
     total -= 7 if total &gt;= 7
-    return last_day_of_month - total.days
+    the_meeting_date = last_day_of_month - total.days
+    if the_meeting_date &lt; date
+      meeting_date(date.next_month.beginning_of_month)
+    else
+      the_meeting_date
+    end
+  rescue
+    # TODO: what to return if a DateTime is not passed? should I not worry?
+    # TODO: maybe allow passing of month number of the current year as an integer
+    &quot;&quot;
   end
   
 end</diff>
      <filename>app/helpers/page_helper.rb</filename>
    </modified>
    <modified>
      <diff>@@ -22,7 +22,7 @@
   http://groups.google.com/group/canberra-ruby
 
 %h2 Meetings
-%p== We aim to have meetups on the last Wednesday of the month. According to the calendar that may well be #{next_meeting_date.to_s(:rfc822)} (check for announcements in the mailing list).
+%p== We aim to have meetups on the last Wednesday of the month. According to the calendar that may well be #{next_meeting_date} (check for announcements in the mailing list).
 
 %h2 Peeps
 #peeps</diff>
      <filename>app/views/pages/home.haml</filename>
    </modified>
    <modified>
      <diff>@@ -2,80 +2,93 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
 
 describe PageHelper do
   include PageHelper
+
+  describe &quot;next meeting date&quot; do
+    before(:each) do
+      @mock_today = Date.new(2008,1,1)
+    end
+    it &quot;should call meeting date helper&quot; do
+      Date.stub!(:today).and_return(@mock_today)
+      should_receive(:meeting_date).with(@mock_today).and_return(@mock_today)
+      next_meeting_date
+    end
+    it &quot;should format the output&quot; do
+      stub!(:meeting_date).and_return(@mock_today)
+      @mock_today.should_receive(:to_s).with(:rfc822)
+      next_meeting_date
+    end
+  end
   
   # TODO: change the tests so that it is not tied to the particular day of the week
-  describe &quot;next_meeting_date (Wednesday)&quot; do
+  describe &quot;meeting date&quot; do
     
-    it &quot;should return last Wednesday for month ending on a Wednesday&quot; do
-      mock_today = Date.new(2008,12,1)
-      last_wednesday = mock_today.end_of_month
-      1.upto(31) { |d|
-        Date.stub!(:today).and_return(mock_today)
-        next_meeting_date.should eql(last_wednesday)      
-        mock_today += 1.day
-      }
-    end
+    describe &quot;for current month has not passed&quot; do
+      it &quot;should return last Wednesday for month ending on a Wednesday&quot; do
+        mock_today = Date.new(2008,12,1)
+        last_wednesday = mock_today.end_of_month
+        meeting_date(mock_today).should eql(last_wednesday)      
+      end
 
-    it &quot;should return last Wednesday for month ending on a Thursday&quot; do
-      mock_today = Date.new(2008,7,1)
-      last_wednesday = mock_today.end_of_month - 1.day
-      1.upto(31) { |d|
-        Date.stub!(:today).and_return(mock_today)
-        next_meeting_date.should eql(last_wednesday)      
-        mock_today += 1.day
-      }
-    end
+      it &quot;should return last Wednesday for month ending on a Thursday&quot; do
+        mock_today = Date.new(2008,7,1)
+        last_wednesday = mock_today.end_of_month - 1.day
+        meeting_date(mock_today).should eql(last_wednesday)      
+      end
 
-    it &quot;should return last Wednesday for month ending on a Friday&quot; do
-      mock_today = Date.new(2008,10,1)
-      last_wednesday = mock_today.end_of_month - 2.days
-      1.upto(31) { |d|
-        Date.stub!(:today).and_return(mock_today)
-        next_meeting_date.should eql(last_wednesday)      
-        mock_today += 1.day
-      }
-    end
+      it &quot;should return last Wednesday for month ending on a Friday&quot; do
+        mock_today = Date.new(2008,10,1)
+        last_wednesday = mock_today.end_of_month - 2.days
+        meeting_date(mock_today).should eql(last_wednesday)      
+      end
 
-    it &quot;should return last Wednesday for month ending on a Saturday&quot; do
-      mock_today = Date.new(2008,5,1)
-      last_wednesday = mock_today.end_of_month - 3.days
-      1.upto(30) { |d|
-        Date.stub!(:today).and_return(mock_today)
-        next_meeting_date.should eql(last_wednesday)      
-        mock_today += 1.day
-      }
-    end
+      it &quot;should return last Wednesday for month ending on a Saturday&quot; do
+        mock_today = Date.new(2008,5,1)
+        last_wednesday = mock_today.end_of_month - 3.days
+        meeting_date(mock_today).should eql(last_wednesday)      
+      end
 
-    it &quot;should return last Wednesday for month ending on a Sunday&quot; do
-      mock_today = Date.new(2008,8,1)
-      last_wednesday = mock_today.end_of_month - 4.days
-      1.upto(31) { |d|
-        Date.stub!(:today).and_return(mock_today)
-        next_meeting_date.should eql(last_wednesday)      
-        mock_today += 1.day
-      }
-    end
+      it &quot;should return last Wednesday for month ending on a Sunday&quot; do
+        mock_today = Date.new(2008,8,1)
+        last_wednesday = mock_today.end_of_month - 4.days
+        meeting_date(mock_today).should eql(last_wednesday)      
+      end
        
-    it &quot;should return last Wednesday for month ending on a Monday&quot; do
-      mock_today = Date.new(2008,6,1)
-      last_wednesday = mock_today.end_of_month - 5.days
-      1.upto(30) { |d|
-        Date.stub!(:today).and_return(mock_today)
-        next_meeting_date.should eql(last_wednesday)      
-        mock_today += 1.day
-      }
-    end
+      it &quot;should return last Wednesday for month ending on a Monday&quot; do
+        mock_today = Date.new(2008,6,1)
+        last_wednesday = mock_today.end_of_month - 5.days
+        meeting_date(mock_today).should eql(last_wednesday)      
+      end
 
-    it &quot;should return last Wednesday for month ending on a Tuesday&quot; do
-      mock_today = Date.new(2008,9,1)
-      last_wednesday = mock_today.end_of_month - 6.days
-      1.upto(30) { |d|      
-        Date.stub!(:today).and_return(mock_today)
-        next_meeting_date.should eql(last_wednesday)
-        mock_today += 1.day     
-      }
+      it &quot;should return last Wednesday for month ending on a Tuesday&quot; do
+        mock_today = Date.new(2008,9,1)
+        last_wednesday = mock_today.end_of_month - 6.days
+        meeting_date(mock_today).should eql(last_wednesday)      
+      end
     end
-          
+    
+    describe &quot;for current month is today&quot; do
+      it &quot;should return today as the last Wednesday for the month&quot; do
+        mock_today = Date.new(2008,3,26)        # last Wednesday of the month
+        last_wednesday = mock_today
+        meeting_date(mock_today).should eql(last_wednesday)
+      end
+    end
+    
+    describe &quot;for current month has passed&quot; do
+      it &quot;should return last Wednesday for next month&quot; do
+        mock_today = Date.new(2008,9,25)        # day after the last wednesday
+        last_wednesday = Date.new(2008,10,29)   # last wednesday of next month
+        meeting_date(mock_today).should eql(last_wednesday)      
+      end
+    end
+    
+    describe &quot;is passed an invalid date&quot; do
+      it &quot;should return empty string&quot; do
+        mock_today = &quot;Today&quot;
+        meeting_date(mock_today).should eql(&quot;&quot;)
+      end
+    end
+    
   end
 
 end</diff>
      <filename>spec/helpers/page_helper_spec.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>d0aa182ccdf6d5fc35bc613a6a96562669631309</id>
    </parent>
  </parents>
  <author>
    <name>Michael MacDonald</name>
    <email>michaelm@amc.org.au</email>
  </author>
  <url>http://github.com/artpop/crc_site/commit/1c5f88026ef9fb1a15e067e2e37daff8786f6df6</url>
  <id>1c5f88026ef9fb1a15e067e2e37daff8786f6df6</id>
  <committed-date>2008-10-16T05:39:33-07:00</committed-date>
  <authored-date>2008-10-16T05:39:33-07:00</authored-date>
  <message>Renamed and refactored next_meeting_date helper to meeting_date(date) so that any date can be passed and it now correctly shows the next month's meeting date if the meeting date for the chosen date has passed</message>
  <tree>84644cb8f1f26c22b0f803bd03e8b8cd1c5f049e</tree>
  <committer>
    <name>Michael MacDonald</name>
    <email>michaelm@amc.org.au</email>
  </committer>
</commit>
