Skip to content

Commit

Permalink
Created task model specs that prove Andrew's theory
Browse files Browse the repository at this point in the history
  • Loading branch information
Mike Dvorkin committed Sep 15, 2009
1 parent d268961 commit fcf5003
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 12 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG
Expand Up @@ -4,6 +4,11 @@ It does not matter how slowly you go as long as you do not stop.
First they ignore you, then they laugh at you, then they fight you,
then you win. –- Mahatma Gandhi

Mon, Sep 14, 2009
---------------------------------------------------------------------
- Merged in Andrew's patch that solves disappearing tasks puzzle (thanks, Andrew!)
- Created task model specs that prove Andrew's theory.

Sun, Sep 13, 2009
---------------------------------------------------------------------
- Added [get_*] controller hooks.
Expand Down
48 changes: 36 additions & 12 deletions spec/models/task_spec.rb
Expand Up @@ -34,6 +34,24 @@
task = Factory(:task)
task.should be_valid
end

[ nil, Time.now.utc_offset + 3600 ].each do |offset|
before(:each) do
adjust_timezone(offset)
end

it "should create a task with due date selected from dropdown within #{offset ? 'different' : 'current'} timezone" do
task = Factory(:task, :due_at => Time.now.end_of_week, :bucket => "due_this_week")
task.bucket.should == "due_this_week"
task.due_at.should == Time.zone.now.end_of_week
end

it "should create a task with due date selected from the calendar within #{offset ? 'different' : 'current'} timezone" do
task = Factory(:task, :bucket => "specific_time", :calendar => "01/31/2020")
task.bucket.should == "specific_time"
task.due_at.should == Time.zone.parse("01/31/2020")
end
end
end

describe "Task/Update" do
Expand Down Expand Up @@ -66,18 +84,24 @@
task.assignee.should == nil
end

it "should update due date based on selected bucket" do
task = Factory(:task, :due_at => Time.zone.now.midnight.tomorrow, :bucket => "due_tomorrow")
task.update_attributes( { :bucket => "due_this_week" } )
task.bucket.should == "due_this_week"
task.due_at.should == Time.zone.now.end_of_week
end

it "should update due date if specific calendar date selected" do
task = Factory(:task, :due_at => Time.zone.now.midnight.tomorrow, :bucket => "due_tomorrow")
task.update_attributes( { :bucket => "specific_time", :calendar => "01/31/2020" } )
task.bucket.should == "specific_time"
task.due_at.should == Time.zone.parse("01/31/2020")
[ nil, Time.now.utc_offset + 3600 ].each do |offset|
before(:each) do
adjust_timezone(offset)
end

it "should update due date based on selected bucket within #{offset ? 'different' : 'current'} timezone" do
task = Factory(:task, :due_at => Time.now.midnight.tomorrow, :bucket => "due_tomorrow")
task.update_attributes( { :bucket => "due_this_week" } )
task.bucket.should == "due_this_week"
task.due_at.should == Time.zone.now.end_of_week
end

it "should update due date if specific calendar date selected within #{offset ? 'different' : 'current'} timezone" do
task = Factory(:task, :due_at => Time.now.midnight.tomorrow, :bucket => "due_tomorrow")
task.update_attributes( { :bucket => "specific_time", :calendar => "01/31/2020" } )
task.bucket.should == "specific_time"
task.due_at.should == Time.zone.parse("01/31/2020")
end
end

end
Expand Down
10 changes: 10 additions & 0 deletions spec/spec_helper.rb
Expand Up @@ -118,3 +118,13 @@ def set_timezone
offset *= 3600 if offset.abs < 13
Time.zone = ActiveSupport::TimeZone.all.select { |zone| zone.utc_offset == offset }.first
end

# Adjusts current timezone by given offset (in seconds).
#----------------------------------------------------------------------------
def adjust_timezone(offset)
if offset
ActiveSupport::TimeZone[offset]
adjusted_time = Time.now + offset.seconds
Time.stub(:now).and_return(adjusted_time)
end
end

0 comments on commit fcf5003

Please sign in to comment.