Skip to content

Instantly share code, notes, and snippets.

@thiagofm
Created April 10, 2015 15:51
Show Gist options
  • Save thiagofm/3dd44f4d4eebbbfea088 to your computer and use it in GitHub Desktop.
Save thiagofm/3dd44f4d4eebbbfea088 to your computer and use it in GitHub Desktop.
require "active_support/core_ext"
def bookable? booked_day, now
now <= cancellable_until(booked_day)
end
def cancellable_until booked_day
booked_day + 2.days + 12.hours
end
describe "bookable?" do
it "books before in time" do
booked_day = Time.new(2015, 04, 10)
now = Time.new(2015, 04, 12, 11, 59, 00)
expect(bookable?(booked_day, now)).to be true
end
it "books on time" do
booked_day = Time.new(2015, 04, 10)
now = Time.new(2015, 04, 12, 12, 00, 00)
expect(bookable?(booked_day, now)).to be true
end
it "doesn't books after time" do
booked_day = Time.new(2015, 04, 10)
now = Time.new(2015, 04, 12, 12, 01, 00)
expect(bookable?(booked_day, now)).to be false
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment