Skip to content

Instantly share code, notes, and snippets.

@naveedkakal
Created March 31, 2017 11:22
Show Gist options
  • Save naveedkakal/97544531c74976fb4c29b386daf65bb6 to your computer and use it in GitHub Desktop.
Save naveedkakal/97544531c74976fb4c29b386daf65bb6 to your computer and use it in GitHub Desktop.
# This allows us to set a different date
# in the admin area, and use TimeCop to process each
# request as being on that different date - useful for
# testing different phases of the challenge.
module TimeTravelFilters
extend ActiveSupport::Concern
included do
if Rails.env.development? || Rails.env.staging?
around_filter :time_travel_for_request
end
end
def time_travel_for_request
time_travel
yield
time_travel_return
end
def time_travel
logger.info 'TIME TRAVEL START'
if session[:timecop_date]
Timecop.travel(session[:timecop_date])
else
Timecop.return
end
end
def time_travel_return
logger.info 'TIME TRAVEL RETURN'
Timecop.return
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment