Skip to content

ferndopolis/timecop-console

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

79 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

timecop-console

timecop-console exposes controllers/routes for manipulating Time.now (using the Timecop gem) from your app. This is especially useful during development and QA, as you can very easily simulate the movement of time. Just as timecop gives you this ability within your tests, you can now easily make this available to your dev and QA team through a debug console.

How to Use

Add to your ‘Gemfile`:

group :development, :staging do
  gem 'timecop-console', :require => 'timecop_console'
end

Avoid having ‘timecop-console` gem as part of `test` group if you use Timecop in your tests to avoid any hard-to-debug exceptions.

By requiring this dependency, it will open up ActionController::Base and inject an around_filter that will manage Time.now and friends for you.

You’ll want to hook in the mountable engine for handling time changes in the specific environments that you want this to load in (probably only development, staging). Modify your ‘config/routes.rb`, adding:

if Rails.env.development? || Rails.env.staging?
  mount TimecopConsole::Engine => '/timecop_console'
end

Then, to take advantage of this, you’ll want to add a snippet of code to the bottom of your application’s layout file, e.g.:

<% if Rails.env.development? || Rails.env.staging? %>
  <%= timecop_console_layout %>
<% end %>

This snippet exposes fields to allow you to alter each component of time (year, month, day, hour, minute, second). It’s raw, and there is no validation whatsoever. A default (and customizable) snippet like this will be added to this library shortly. In the meantime, you can hand-write it.

Helpers

Use time_travel_to to create a button which will jump directly to a specific date:

<%= time_travel_to App.launch_date %>

Where App.launch_date is a Date or DateTime object. By default the button will format to that date, but can be overwritten by passing a string:

<%= time_travel_to App.launch_date, "LAUNCH DATE" %>

Copyright © 2009 John Trupiano. See LICENSE for details.

About

Expose Timecop's capabilities to the UI in your rails app, allowing QA to take advantage of it.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •