Skip to content

Instantly share code, notes, and snippets.

@batasrki
Created September 25, 2011 23:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save batasrki/1241298 to your computer and use it in GitHub Desktop.
Save batasrki/1241298 to your computer and use it in GitHub Desktop.
Example model display work window spec
describe Job do
before :each do
@mock_job_category = JobCategory.create!({:name => "Tester"})
@mock_client = mock_model(Client, {:name => "Test Client"})
@job = Job.new(:name => "test job", :client => @mock_client,
:category => @mock_job_category)
end
describe "work window date range" do
before :each do
@now = DateTime.now.in_time_zone
@formatted_now = @now.strftime("%b %d, %Y")
end
it "should display a generic message if there's no start or end time" do
@job.display_work_window.should == "No date range specified"
end
it "should display a work commencment message if there's a start date, but no end date" do
@job.starttime = @now
@job.display_work_window.should == "Work commences on #{@formatted_now}"
end
it "should display a work completed message if there's a end date, but no start date" do
@job.endtime = @now
@job.display_work_window.should == "Work completed by #{@formatted_now}"
end
it "should display a date range if both start and end date exist" do
@job.starttime = @now
@job.endtime = @now + 1.week
formatted_end = (@now + 1.week).strftime("%b %d, %Y")
@job.display_work_window.should == "#{@formatted_now} ~ #{formatted_end}"
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment