I continue working on the homepage mini-calendar tonight. Last night and tonight, I drive by example the following Haml template:
- week = 0I cannot help thinking that I could have done this without the
- while ((sunday0 + week*7).mon <= day1.mon)
%tr{:class => "week#{week+1}"}
- (0..6).map{|d| sunday0 + d + week*7}.each do |date|
%td{:id => date.to_s}
= date.mday if date.mon == day1.mon
- week = week + 1
week
accumulator, but this is what the examples drove me to:cstrom@jaynestown:~/repos/eee-code$ spec ./spec/views/mini_calendar.haml_spec.rb -cfsI will consider this the "get it done" phase. The "do it right" phase can wait for another day.
mini_calendar.haml
- should show a human readable month and year
- should show a human readable month and year for other months
- should not include previous month's dates
- should have the first of the month in the first week
- should have the last of the month
- should not include next month's dates
Next, I need to link to meals in this month. In RSpec speak:
describe "mini_calendar.haml" doTo make that example pass, I add another layer of conditionals, checking the
before(:each) do
assigns[:month] = "2009-08"
assigns[:meals_by_date] = {"2009-08-08" => "Meal Title"}
end
it "should link to meals this month" do
render("views/mini_calendar.haml")
response.should have_selector("td#2009-08-08 a",
:href => "/meals/2009/08/08",
:title => "Meal Title")
end
@meals_by_date
instance variable:- week = 0With that, I can mark one more step as complete. In my Cucumber scenario there should be 3 days in the month with meals:
- while ((sunday0 + week*7).mon <= day1.mon)
%tr{:class => "week#{week+1}"}
- (0..6).map{|d| sunday0 + d + week*7}.each do |date|
%td{:id => date.to_s}
- if date.mon == day1.mon
- if @meals_by_date.include?(date.to_s)
%a{:href => date.strftime("/meals/%Y/%m/%d"),
:title => @meals_by_date[date.to_s]}
= date.mday
- else
= date.mday
- week = week + 1
Then /^there should be 3 links to meals$/ doRunning the Cucumber scenario, I do indeed have one more step done:
response.should have_selector("td a", :count => 3)
end
Tomorrow I need to add navigation between months. I think I may have missed an edge case here as well, so another Cucumber scenario is in order.
No comments:
Post a Comment