diff options
Diffstat (limited to 'spec/models')
-rw-r--r-- | spec/models/holiday_spec.rb | 43 | ||||
-rw-r--r-- | spec/models/info_request_spec.rb | 36 |
2 files changed, 43 insertions, 36 deletions
diff --git a/spec/models/holiday_spec.rb b/spec/models/holiday_spec.rb new file mode 100644 index 000000000..f4dfc7476 --- /dev/null +++ b/spec/models/holiday_spec.rb @@ -0,0 +1,43 @@ +require File.dirname(__FILE__) + '/../spec_helper' + +describe Holiday, " when calculating due date" do + fixtures :holidays + + def due_date(ymd) + return Holiday.due_date_from(Date.strptime(ymd)).strftime("%F") + end + + it "handles no holidays" do + due_date('2008-10-01').should == '2008-10-29' + end + + it "handles non leap years" do + due_date('2007-02-01').should == '2007-03-01' + end + + it "handles leap years" do + due_date('2008-02-01').should == '2008-02-29' + end + + it "handles Thursday start" do + due_date('2009-03-12').should == '2009-04-14' + end + + it "handles Friday start" do + due_date('2009-03-13').should == '2009-04-15' + end + + it "handles Saturday start" do + due_date('2009-03-14').should == '2009-04-16' + end + + it "handles Sunday start" do + due_date('2009-03-15').should == '2009-04-16' + end + + it "handles Monday start" do + due_date('2009-03-16').should == '2009-04-16' + end + +end + diff --git a/spec/models/info_request_spec.rb b/spec/models/info_request_spec.rb index acb046e03..5866e4bca 100644 --- a/spec/models/info_request_spec.rb +++ b/spec/models/info_request_spec.rb @@ -78,42 +78,6 @@ describe InfoRequest, " when emailing" do end -describe InfoRequest, " when calculating due date" do - fixtures :info_requests, :info_request_events, :public_bodies, :users, :holidays - - before do - @ir = info_requests(:fancy_dog_request) - end - - it "knows when it needs answered by" do - @ir.date_response_required_by.strftime("%F").should == '2007-11-22' - end - - # These ones should all move when the underlying method moves - # I'm not sure what the best way is in RSpec to do this sort of data - # driven test so that it reports which one is failing rather than - # breaking out on first failure - - test_dates = { - 'no_holidays' => ['2008-10-01' , '2008-10-29' ], - 'not_leap_year' => ['2007-02-01' , '2007-03-01' ], - 'leap_year' => ['2008-02-01' , '2008-02-29' ], - 'on_thu' => ['2009-03-12' , '2009-04-14' ], - 'on_fri' => ['2009-03-13' , '2009-04-15' ], - 'on_sat' => ['2009-03-14' , '2009-04-16' ], - 'on_sun' => ['2009-03-15' , '2009-04-16' ], - 'on_mon' => ['2009-03-16' , '2009-04-16' ], - } - - it "gets it right" do - test_dates.each_pair do |name, date| - reqdate = Date.strptime(date[0]) - @ir.due_date_for_request_date(reqdate).strftime("%F").should == date[1] - end - end - -end - describe InfoRequest, "when calculating status" do fixtures :public_bodies, :users |