Skip to content

Instantly share code, notes, and snippets.

@softwaregravy
Created October 13, 2011 16:38
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 softwaregravy/1284731 to your computer and use it in GitHub Desktop.
Save softwaregravy/1284731 to your computer and use it in GitHub Desktop.
Time Period Refactor
# before
describe "<=>" do
it "first compares days" do
l = TimePeriod.create(:start_day => 1, :start_time => 10.hours.to_i, :duration => 1.hours.to_i)
r = TimePeriod.create(:start_day => 2, :start_time => 10.hours.to_i, :duration => 1.hours.to_i)
(l <=> r).should == -1
(r <=> l).should == 1
end
end
# after
describe "<=>" do
it "first compares days" do
l = TimePeriod.new(:start_day => 1, :start_time => 10.hours.to_i, :duration => 1.hours.to_i)
r = TimePeriod.new(:start_day => 2, :start_time => 10.hours.to_i, :duration => 1.hours.to_i)
(l <=> r).should == -1
(r <=> l).should == 1
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment