├── .gitignore
├── Gemfile
├── LICENSE
├── README.rdoc
├── Rakefile
├── app
├── controllers
│ └── timecop_console
│ │ └── main_controller.rb
├── helpers
│ └── timecop_console
│ │ └── main_helper.rb
└── views
│ └── timecop_console
│ └── _console_layout.html.erb
├── config
└── routes.rb
├── lib
├── timecop_console.rb
└── timecop_console
│ ├── controller_methods.rb
│ ├── engine.rb
│ └── version.rb
├── spec
├── controllers
│ ├── main_controller_spec.rb
│ └── sample_controller_spec.rb
├── dummy_app
│ ├── Gemfile
│ ├── Gemfile.lock
│ ├── README.rdoc
│ ├── Rakefile
│ ├── app
│ │ ├── assets
│ │ │ ├── images
│ │ │ │ └── rails.png
│ │ │ ├── javascripts
│ │ │ │ └── application.js
│ │ │ └── stylesheets
│ │ │ │ └── application.css
│ │ ├── controllers
│ │ │ ├── application_controller.rb
│ │ │ └── sample_controller.rb
│ │ ├── helpers
│ │ │ └── application_helper.rb
│ │ └── views
│ │ │ ├── layouts
│ │ │ └── application.html.erb
│ │ │ └── sample
│ │ │ └── index.html.erb
│ ├── config.ru
│ ├── config
│ │ ├── application.rb
│ │ ├── boot.rb
│ │ ├── environment.rb
│ │ ├── environments
│ │ │ ├── development.rb
│ │ │ ├── production.rb
│ │ │ └── test.rb
│ │ ├── initializers
│ │ │ ├── backtrace_silencers.rb
│ │ │ ├── inflections.rb
│ │ │ ├── mime_types.rb
│ │ │ ├── secret_token.rb
│ │ │ ├── session_store.rb
│ │ │ └── wrap_parameters.rb
│ │ ├── locales
│ │ │ └── en.yml
│ │ └── routes.rb
│ ├── db
│ │ └── seeds.rb
│ ├── doc
│ │ └── README_FOR_APP
│ ├── public
│ │ ├── 404.html
│ │ ├── 422.html
│ │ ├── 500.html
│ │ ├── favicon.ico
│ │ └── robots.txt
│ └── script
│ │ └── rails
├── helpers
│ └── main_helper_spec.rb
└── spec_helper.rb
└── timecop-console.gemspec
/.gitignore:
--------------------------------------------------------------------------------
1 | *.gem
2 | .rvmrc
3 | .bundle
4 | *.sw?
5 | .DS_Store
6 | coverage
7 | rdoc
8 | pkg
9 | Gemfile.lock
10 | spec/dummy_app/log
11 | spec/dummy_app/tmp
12 |
--------------------------------------------------------------------------------
/Gemfile:
--------------------------------------------------------------------------------
1 | source 'https://rubygems.org'
2 |
3 | group :test do
4 | gem 'simplecov', :require => false
5 | gem 'rspec-rails'
6 | end
7 |
8 | group :development, :test do
9 | gem 'pry'
10 | end
11 |
12 | gemspec
13 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Copyright (c) 2009 John Trupiano
2 |
3 | Permission is hereby granted, free of charge, to any person obtaining
4 | a copy of this software and associated documentation files (the
5 | "Software"), to deal in the Software without restriction, including
6 | without limitation the rights to use, copy, modify, merge, publish,
7 | distribute, sublicense, and/or sell copies of the Software, and to
8 | permit persons to whom the Software is furnished to do so, subject to
9 | the following conditions:
10 |
11 | The above copyright notice and this permission notice shall be
12 | included in all copies or substantial portions of the Software.
13 |
14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 |
--------------------------------------------------------------------------------
/README.rdoc:
--------------------------------------------------------------------------------
1 | = timecop-console
2 |
3 | timecop-console exposes controllers/routes for manipulating Time.now (using the Timecop gem) from your app. This is especially useful
4 | during development and QA, as you can very easily simulate the movement of time. Just as timecop gives you this ability within your tests,
5 | you can now easily make this available to your dev and QA team through a debug console.
6 |
7 | == How to Use
8 |
9 | Add to your `Gemfile`:
10 |
11 | group :development, :staging do
12 | gem 'timecop-console', :require => 'timecop_console'
13 | end
14 |
15 | Avoid having `timecop-console` gem as part of `test` group if you use Timecop in your tests to avoid any hard-to-debug exceptions.
16 |
17 | By requiring this dependency, it will open up ActionController::Base and inject an around_filter that will manage Time.now and friends for you.
18 |
19 | 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:
20 |
21 | if Rails.env.development? || Rails.env.staging?
22 | mount TimecopConsole::Engine => '/timecop_console'
23 | end
24 |
25 | 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.:
26 |
27 | <% if Rails.env.development? || Rails.env.staging? %>
28 | <%= timecop_console_layout %>
29 | <% end %>
30 |
31 | 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.
32 |
33 | == Helpers
34 |
35 | Use time_travel_to to create a button which will jump directly to a specific date:
36 |
37 | <%= time_travel_to App.launch_date %>
38 |
39 | 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:
40 |
41 | <%= time_travel_to App.launch_date, "LAUNCH DATE" %>
42 |
43 | == Copyright
44 |
45 | Copyright (c) 2009 John Trupiano. See LICENSE for details.
46 |
--------------------------------------------------------------------------------
/Rakefile:
--------------------------------------------------------------------------------
1 | require 'bundler'
2 | Bundler::GemHelper.install_tasks
3 |
4 | require 'rspec/core/rake_task'
5 | RSpec::Core::RakeTask.new(:spec)
6 |
7 | task :test => :spec
8 | task :default => :spec
9 | namespace :spec do
10 | task :coverage do
11 | ENV['INVOKE_SIMPLECOV'] = 'true'
12 | Rake::Task[:spec].invoke
13 | end
14 | end
15 |
--------------------------------------------------------------------------------
/app/controllers/timecop_console/main_controller.rb:
--------------------------------------------------------------------------------
1 | module TimecopConsole
2 | class MainController < ::ApplicationController
3 | skip_filter :handle_timecop_offset
4 |
5 | def update
6 | if date_select_format?
7 | year = params['timecop']['current_time(1i)']
8 | month = params['timecop']['current_time(2i)']
9 | day = params['timecop']['current_time(3i)']
10 | hour = params['timecop']['current_time(4i)']
11 | minute = params['timecop']['current_time(5i)']
12 | second = Time.now.sec
13 | else
14 | # backward compatible format
15 | year = params[:year]
16 | month = params[:month]
17 | day = params[:day]
18 | hour = params[:hour]
19 | minute = params[:min]
20 | second = params[:sec]
21 | end
22 |
23 | session[SESSION_KEY_NAME] = Time.zone.local(year, month, day, hour, minute, second)
24 | redirect_to :back
25 | end
26 |
27 | def reset
28 | session[SESSION_KEY_NAME] = nil
29 | redirect_to :back
30 | end
31 |
32 | private
33 |
34 | # http://api.rubyonrails.org/classes/ActionView/Helpers/DateHelper.html#method-i-date_select
35 | def date_select_format?
36 | params['timecop'].present? && params['timecop']['current_time(1i)'].present?
37 | end
38 | end
39 | end
40 |
--------------------------------------------------------------------------------
/app/helpers/timecop_console/main_helper.rb:
--------------------------------------------------------------------------------
1 | module TimecopConsole
2 | module MainHelper
3 | def time_travel_to(date, name = nil)
4 | unless date.respond_to?(:year) && date.respond_to?(:month) && date.respond_to?(:day)
5 | raise ArgumentError, "Argument must be a Date object"
6 | end
7 |
8 | name ||= date.strftime("%B %d, %Y")
9 | hour = date.respond_to?(:hour) ? date.hour : 12
10 | min = date.respond_to?(:min) ? date.min : 0
11 |
12 | update_path = timecop_console.update_path(timecop: {
13 | 'current_time(1i)' => date.year,
14 | 'current_time(2i)' => date.month,
15 | 'current_time(3i)' => date.day,
16 | 'current_time(4i)' => hour,
17 | 'current_time(5i)' => min
18 | })
19 |
20 | button_to(name, update_path)
21 | end
22 |
23 | def timecop_console_layout
24 | render partial: 'timecop_console/console_layout', layout: false
25 | end
26 | end
27 | end
28 |
--------------------------------------------------------------------------------
/app/views/timecop_console/_console_layout.html.erb:
--------------------------------------------------------------------------------
1 |
2 |
3 | <%= Time.now.strftime("Current time is: %D %r") %>
4 |
5 | <%= form_tag timecop_console.update_path do %>
6 |
7 | <%= datetime_select("timecop", "current_time") %>
8 |
9 |
10 | <%= submit_tag "Time Travel", :class => 'btn' %>
11 |
12 | <% end %>
13 | <%= link_to "Reset", timecop_console.reset_path %>
14 |
15 |
--------------------------------------------------------------------------------
/config/routes.rb:
--------------------------------------------------------------------------------
1 | TimecopConsole::Engine.routes.draw do
2 | match '/update' => 'main#update', :as => :update, :via => [:post, :put]
3 | match '/reset' => 'main#reset', :as => :reset, :via => [:get]
4 | end
5 |
--------------------------------------------------------------------------------
/lib/timecop_console.rb:
--------------------------------------------------------------------------------
1 | require 'timecop_console/engine'
2 | require 'timecop_console/controller_methods'
3 |
4 | module TimecopConsole
5 | SESSION_KEY_NAME = :timecop_adjusted_time unless defined?(SESSION_KEY_NAME)
6 | end
7 |
8 | ActionController::Base.send(:include, TimecopConsole::ControllerMethods)
9 |
--------------------------------------------------------------------------------
/lib/timecop_console/controller_methods.rb:
--------------------------------------------------------------------------------
1 | # Defines extensions applied to ActionController::Base to support our time travel
2 | module TimecopConsole
3 | module ControllerMethods
4 | def self.included(base)
5 | base.class_eval do
6 | around_filter :handle_timecop_offset
7 | end
8 | end
9 |
10 | # to be used as an around_filter
11 | def handle_timecop_offset
12 | # Establish now
13 | if session[TimecopConsole::SESSION_KEY_NAME].present?
14 | Rails.logger.debug "[timecop-console] Time traveling to #{session[TimecopConsole::SESSION_KEY_NAME].to_s}"
15 | Timecop.travel(session[TimecopConsole::SESSION_KEY_NAME])
16 | else
17 | Timecop.return
18 | end
19 |
20 | # Run the intended action
21 | yield
22 |
23 | if session[TimecopConsole::SESSION_KEY_NAME].present?
24 | # we want to continue to slide time forward, even if it's only 3 seconds at a time.
25 | # this ensures that subsequent calls during the same "time travel" actually pass time
26 | adjusted_time = Time.now + 3
27 | Rails.logger.debug "[timecop-console] Resetting session to: #{adjusted_time}"
28 | session[TimecopConsole::SESSION_KEY_NAME] = adjusted_time
29 | end
30 | end
31 |
32 | private :handle_timecop_offset
33 | end
34 | end
35 |
--------------------------------------------------------------------------------
/lib/timecop_console/engine.rb:
--------------------------------------------------------------------------------
1 | require 'rails'
2 | require 'timecop'
3 | require 'timecop_console'
4 |
5 | module TimecopConsole
6 | class Engine < Rails::Engine
7 | isolate_namespace TimecopConsole
8 | config.to_prepare do
9 | ApplicationController.helper(MainHelper)
10 | end
11 | end
12 | end
13 |
--------------------------------------------------------------------------------
/lib/timecop_console/version.rb:
--------------------------------------------------------------------------------
1 | module TimecopConsole
2 | class Version
3 | MAJOR ||= 0
4 | MINOR ||= 3
5 | PATCH ||= 1
6 |
7 | class << self
8 | def to_s
9 | [MAJOR, MINOR, PATCH].compact.join('.')
10 | end
11 | end
12 | end
13 | end
14 |
--------------------------------------------------------------------------------
/spec/controllers/main_controller_spec.rb:
--------------------------------------------------------------------------------
1 | require 'spec_helper'
2 |
3 | describe TimecopConsole::MainController do
4 | before(:each) do
5 | request.env["HTTP_REFERER"] = "where_i_came_from"
6 | end
7 |
8 | describe "POST to :update" do
9 | let(:timecop_param) do
10 | {
11 | 'current_time(1i)' => 2012,
12 | 'current_time(2i)' => 11,
13 | 'current_time(3i)' => 30,
14 | 'current_time(4i)' => 22,
15 | 'current_time(5i)' => 01
16 | }
17 | end
18 |
19 | it 'redirects back' do
20 | post :update, :timecop => timecop_param, :use_route => :timecop_console
21 |
22 | response.should redirect_to("where_i_came_from")
23 | end
24 |
25 | context "with backward compatible format" do
26 | let(:date_params) do
27 | { year: 2013, month: 8, day: 22, hour: 12, min: 0, sec: 0 }
28 | end
29 |
30 | it 'redirects back' do
31 | post :update, date_params.merge(use_route: :timecop_console)
32 |
33 | response.should redirect_to("where_i_came_from")
34 | end
35 |
36 | it 'sets virtual time with respect to Time.zone setting' do
37 | Time.zone = ActiveSupport::TimeZone.all.detect { |tz| tz.name == 'Central Time (US & Canada)' } or raise("can not find TZ")
38 |
39 | post :update, date_params.merge(use_route: :timecop_console)
40 |
41 | session[TimecopConsole::SESSION_KEY_NAME].strftime('%d %b %H:%M %Z').should eq("22 Aug 12:00 CDT")
42 | end
43 | end
44 | end
45 |
46 | describe "GET to :reset" do
47 | it 'redirects back' do
48 | get :reset, :use_route => :timecop_console
49 |
50 | response.should redirect_to "where_i_came_from"
51 | end
52 | end
53 | end
54 |
--------------------------------------------------------------------------------
/spec/controllers/sample_controller_spec.rb:
--------------------------------------------------------------------------------
1 | require 'spec_helper'
2 |
3 | describe SampleController do
4 | describe "GET to :index" do
5 | controller do
6 | def index
7 | render :nothing => true
8 | end
9 | end
10 |
11 | it 'calls around filter method' do
12 | controller.should_receive(:handle_timecop_offset)
13 |
14 | get :index
15 | end
16 | end
17 |
18 | describe "#handle_timecop_offset" do
19 | controller do
20 | def index
21 | raise Time.zone.now.to_s
22 | end
23 | end
24 |
25 | it 'sets proper time inside action method' do
26 | frozen_time = 1.year.from_now
27 |
28 | session[TimecopConsole::SESSION_KEY_NAME] = frozen_time
29 |
30 | expect { get :index }.to raise_error(frozen_time.to_s)
31 | end
32 | end
33 | end
34 |
--------------------------------------------------------------------------------
/spec/dummy_app/Gemfile:
--------------------------------------------------------------------------------
1 | source 'https://rubygems.org'
2 |
3 | gem 'rails', '~> 4.0'
4 | gem 'jquery-rails'
5 | gem 'pry'
6 |
7 | gem 'timecop-console', :path => '../../', :require => 'timecop_console'
8 |
--------------------------------------------------------------------------------
/spec/dummy_app/Gemfile.lock:
--------------------------------------------------------------------------------
1 | PATH
2 | remote: ../../
3 | specs:
4 | timecop-console (0.3.1)
5 | railties (>= 3.1, < 5.0)
6 | timecop (>= 0.5)
7 |
8 | GEM
9 | remote: https://rubygems.org/
10 | specs:
11 | actionmailer (4.0.3)
12 | actionpack (= 4.0.3)
13 | mail (~> 2.5.4)
14 | actionpack (4.0.3)
15 | activesupport (= 4.0.3)
16 | builder (~> 3.1.0)
17 | erubis (~> 2.7.0)
18 | rack (~> 1.5.2)
19 | rack-test (~> 0.6.2)
20 | activemodel (4.0.3)
21 | activesupport (= 4.0.3)
22 | builder (~> 3.1.0)
23 | activerecord (4.0.3)
24 | activemodel (= 4.0.3)
25 | activerecord-deprecated_finders (~> 1.0.2)
26 | activesupport (= 4.0.3)
27 | arel (~> 4.0.0)
28 | activerecord-deprecated_finders (1.0.3)
29 | activesupport (4.0.3)
30 | i18n (~> 0.6, >= 0.6.4)
31 | minitest (~> 4.2)
32 | multi_json (~> 1.3)
33 | thread_safe (~> 0.1)
34 | tzinfo (~> 0.3.37)
35 | arel (4.0.2)
36 | atomic (1.1.15)
37 | builder (3.1.4)
38 | coderay (1.1.0)
39 | erubis (2.7.0)
40 | hike (1.2.3)
41 | i18n (0.6.9)
42 | jquery-rails (3.1.0)
43 | railties (>= 3.0, < 5.0)
44 | thor (>= 0.14, < 2.0)
45 | mail (2.5.4)
46 | mime-types (~> 1.16)
47 | treetop (~> 1.4.8)
48 | method_source (0.8.2)
49 | mime-types (1.25.1)
50 | minitest (4.7.5)
51 | multi_json (1.8.4)
52 | polyglot (0.3.4)
53 | pry (0.9.12.6)
54 | coderay (~> 1.0)
55 | method_source (~> 0.8)
56 | slop (~> 3.4)
57 | rack (1.5.2)
58 | rack-test (0.6.2)
59 | rack (>= 1.0)
60 | rails (4.0.3)
61 | actionmailer (= 4.0.3)
62 | actionpack (= 4.0.3)
63 | activerecord (= 4.0.3)
64 | activesupport (= 4.0.3)
65 | bundler (>= 1.3.0, < 2.0)
66 | railties (= 4.0.3)
67 | sprockets-rails (~> 2.0.0)
68 | railties (4.0.3)
69 | actionpack (= 4.0.3)
70 | activesupport (= 4.0.3)
71 | rake (>= 0.8.7)
72 | thor (>= 0.18.1, < 2.0)
73 | rake (10.1.1)
74 | slop (3.4.7)
75 | sprockets (2.11.0)
76 | hike (~> 1.2)
77 | multi_json (~> 1.0)
78 | rack (~> 1.0)
79 | tilt (~> 1.1, != 1.3.0)
80 | sprockets-rails (2.0.1)
81 | actionpack (>= 3.0)
82 | activesupport (>= 3.0)
83 | sprockets (~> 2.8)
84 | thor (0.18.1)
85 | thread_safe (0.2.0)
86 | atomic (>= 1.1.7, < 2)
87 | tilt (1.4.1)
88 | timecop (0.7.1)
89 | treetop (1.4.15)
90 | polyglot
91 | polyglot (>= 0.3.1)
92 | tzinfo (0.3.38)
93 |
94 | PLATFORMS
95 | ruby
96 |
97 | DEPENDENCIES
98 | jquery-rails
99 | pry
100 | rails (~> 4.0)
101 | timecop-console!
102 |
--------------------------------------------------------------------------------
/spec/dummy_app/README.rdoc:
--------------------------------------------------------------------------------
1 | == Welcome to Rails
2 |
3 | Rails is a web-application framework that includes everything needed to create
4 | database-backed web applications according to the Model-View-Control pattern.
5 |
6 | This pattern splits the view (also called the presentation) into "dumb"
7 | templates that are primarily responsible for inserting pre-built data in between
8 | HTML tags. The model contains the "smart" domain objects (such as Account,
9 | Product, Person, Post) that holds all the business logic and knows how to
10 | persist themselves to a database. The controller handles the incoming requests
11 | (such as Save New Account, Update Product, Show Post) by manipulating the model
12 | and directing data to the view.
13 |
14 | In Rails, the model is handled by what's called an object-relational mapping
15 | layer entitled Active Record. This layer allows you to present the data from
16 | database rows as objects and embellish these data objects with business logic
17 | methods. You can read more about Active Record in
18 | link:files/vendor/rails/activerecord/README.html.
19 |
20 | The controller and view are handled by the Action Pack, which handles both
21 | layers by its two parts: Action View and Action Controller. These two layers
22 | are bundled in a single package due to their heavy interdependence. This is
23 | unlike the relationship between the Active Record and Action Pack that is much
24 | more separate. Each of these packages can be used independently outside of
25 | Rails. You can read more about Action Pack in
26 | link:files/vendor/rails/actionpack/README.html.
27 |
28 |
29 | == Getting Started
30 |
31 | 1. At the command prompt, create a new Rails application:
32 | rails new myapp (where myapp is the application name)
33 |
34 | 2. Change directory to myapp and start the web server:
35 | cd myapp; rails server (run with --help for options)
36 |
37 | 3. Go to http://localhost:3000/ and you'll see:
38 | "Welcome aboard: You're riding Ruby on Rails!"
39 |
40 | 4. Follow the guidelines to start developing your application. You can find
41 | the following resources handy:
42 |
43 | * The Getting Started Guide: http://guides.rubyonrails.org/getting_started.html
44 | * Ruby on Rails Tutorial Book: http://www.railstutorial.org/
45 |
46 |
47 | == Debugging Rails
48 |
49 | Sometimes your application goes wrong. Fortunately there are a lot of tools that
50 | will help you debug it and get it back on the rails.
51 |
52 | First area to check is the application log files. Have "tail -f" commands
53 | running on the server.log and development.log. Rails will automatically display
54 | debugging and runtime information to these files. Debugging info will also be
55 | shown in the browser on requests from 127.0.0.1.
56 |
57 | You can also log your own messages directly into the log file from your code
58 | using the Ruby logger class from inside your controllers. Example:
59 |
60 | class WeblogController < ActionController::Base
61 | def destroy
62 | @weblog = Weblog.find(params[:id])
63 | @weblog.destroy
64 | logger.info("#{Time.now} Destroyed Weblog ID ##{@weblog.id}!")
65 | end
66 | end
67 |
68 | The result will be a message in your log file along the lines of:
69 |
70 | Mon Oct 08 14:22:29 +1000 2007 Destroyed Weblog ID #1!
71 |
72 | More information on how to use the logger is at http://www.ruby-doc.org/core/
73 |
74 | Also, Ruby documentation can be found at http://www.ruby-lang.org/. There are
75 | several books available online as well:
76 |
77 | * Programming Ruby: http://www.ruby-doc.org/docs/ProgrammingRuby/ (Pickaxe)
78 | * Learn to Program: http://pine.fm/LearnToProgram/ (a beginners guide)
79 |
80 | These two books will bring you up to speed on the Ruby language and also on
81 | programming in general.
82 |
83 |
84 | == Debugger
85 |
86 | Debugger support is available through the debugger command when you start your
87 | Mongrel or WEBrick server with --debugger. This means that you can break out of
88 | execution at any point in the code, investigate and change the model, and then,
89 | resume execution! You need to install ruby-debug to run the server in debugging
90 | mode. With gems, use sudo gem install ruby-debug. Example:
91 |
92 | class WeblogController < ActionController::Base
93 | def index
94 | @posts = Post.all
95 | debugger
96 | end
97 | end
98 |
99 | So the controller will accept the action, run the first line, then present you
100 | with a IRB prompt in the server window. Here you can do things like:
101 |
102 | >> @posts.inspect
103 | => "[#nil, "body"=>nil, "id"=>"1"}>,
105 | #"Rails", "body"=>"Only ten..", "id"=>"2"}>]"
107 | >> @posts.first.title = "hello from a debugger"
108 | => "hello from a debugger"
109 |
110 | ...and even better, you can examine how your runtime objects actually work:
111 |
112 | >> f = @posts.first
113 | => #nil, "body"=>nil, "id"=>"1"}>
114 | >> f.
115 | Display all 152 possibilities? (y or n)
116 |
117 | Finally, when you're ready to resume execution, you can enter "cont".
118 |
119 |
120 | == Console
121 |
122 | The console is a Ruby shell, which allows you to interact with your
123 | application's domain model. Here you'll have all parts of the application
124 | configured, just like it is when the application is running. You can inspect
125 | domain models, change values, and save to the database. Starting the script
126 | without arguments will launch it in the development environment.
127 |
128 | To start the console, run rails console from the application
129 | directory.
130 |
131 | Options:
132 |
133 | * Passing the -s, --sandbox argument will rollback any modifications
134 | made to the database.
135 | * Passing an environment name as an argument will load the corresponding
136 | environment. Example: rails console production.
137 |
138 | To reload your controllers and models after launching the console run
139 | reload!
140 |
141 | More information about irb can be found at:
142 | link:http://www.rubycentral.org/pickaxe/irb.html
143 |
144 |
145 | == dbconsole
146 |
147 | You can go to the command line of your database directly through rails
148 | dbconsole. You would be connected to the database with the credentials
149 | defined in database.yml. Starting the script without arguments will connect you
150 | to the development database. Passing an argument will connect you to a different
151 | database, like rails dbconsole production. Currently works for MySQL,
152 | PostgreSQL and SQLite 3.
153 |
154 | == Description of Contents
155 |
156 | The default directory structure of a generated Ruby on Rails application:
157 |
158 | |-- app
159 | | |-- assets
160 | | |-- images
161 | | |-- javascripts
162 | | `-- stylesheets
163 | | |-- controllers
164 | | |-- helpers
165 | | |-- mailers
166 | | |-- models
167 | | `-- views
168 | | `-- layouts
169 | |-- config
170 | | |-- environments
171 | | |-- initializers
172 | | `-- locales
173 | |-- db
174 | |-- doc
175 | |-- lib
176 | | `-- tasks
177 | |-- log
178 | |-- public
179 | |-- script
180 | |-- test
181 | | |-- fixtures
182 | | |-- functional
183 | | |-- integration
184 | | |-- performance
185 | | `-- unit
186 | |-- tmp
187 | | |-- cache
188 | | |-- pids
189 | | |-- sessions
190 | | `-- sockets
191 | `-- vendor
192 | |-- assets
193 | `-- stylesheets
194 | `-- plugins
195 |
196 | app
197 | Holds all the code that's specific to this particular application.
198 |
199 | app/assets
200 | Contains subdirectories for images, stylesheets, and JavaScript files.
201 |
202 | app/controllers
203 | Holds controllers that should be named like weblogs_controller.rb for
204 | automated URL mapping. All controllers should descend from
205 | ApplicationController which itself descends from ActionController::Base.
206 |
207 | app/models
208 | Holds models that should be named like post.rb. Models descend from
209 | ActiveRecord::Base by default.
210 |
211 | app/views
212 | Holds the template files for the view that should be named like
213 | weblogs/index.html.erb for the WeblogsController#index action. All views use
214 | eRuby syntax by default.
215 |
216 | app/views/layouts
217 | Holds the template files for layouts to be used with views. This models the
218 | common header/footer method of wrapping views. In your views, define a layout
219 | using the layout :default and create a file named default.html.erb.
220 | Inside default.html.erb, call <% yield %> to render the view using this
221 | layout.
222 |
223 | app/helpers
224 | Holds view helpers that should be named like weblogs_helper.rb. These are
225 | generated for you automatically when using generators for controllers.
226 | Helpers can be used to wrap functionality for your views into methods.
227 |
228 | config
229 | Configuration files for the Rails environment, the routing map, the database,
230 | and other dependencies.
231 |
232 | db
233 | Contains the database schema in schema.rb. db/migrate contains all the
234 | sequence of Migrations for your schema.
235 |
236 | doc
237 | This directory is where your application documentation will be stored when
238 | generated using rake doc:app
239 |
240 | lib
241 | Application specific libraries. Basically, any kind of custom code that
242 | doesn't belong under controllers, models, or helpers. This directory is in
243 | the load path.
244 |
245 | public
246 | The directory available for the web server. Also contains the dispatchers and the
247 | default HTML files. This should be set as the DOCUMENT_ROOT of your web
248 | server.
249 |
250 | script
251 | Helper scripts for automation and generation.
252 |
253 | test
254 | Unit and functional tests along with fixtures. When using the rails generate
255 | command, template test files will be generated for you and placed in this
256 | directory.
257 |
258 | vendor
259 | External libraries that the application depends on. Also includes the plugins
260 | subdirectory. If the app has frozen rails, those gems also go here, under
261 | vendor/rails/. This directory is in the load path.
262 |
--------------------------------------------------------------------------------
/spec/dummy_app/Rakefile:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env rake
2 | # Add your own tasks in files placed in lib/tasks ending in .rake,
3 | # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
4 |
5 | require File.expand_path('../config/application', __FILE__)
6 |
7 | DummyApp::Application.load_tasks
8 |
--------------------------------------------------------------------------------
/spec/dummy_app/app/assets/images/rails.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ferndopolis/timecop-console/30491e690e9882701ef0609e2fe87b3573b5efcb/spec/dummy_app/app/assets/images/rails.png
--------------------------------------------------------------------------------
/spec/dummy_app/app/assets/javascripts/application.js:
--------------------------------------------------------------------------------
1 | // This is a manifest file that'll be compiled into application.js, which will include all the files
2 | // listed below.
3 | //
4 | // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5 | // or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
6 | //
7 | // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8 | // the compiled file.
9 | //
10 | // WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
11 | // GO AFTER THE REQUIRES BELOW.
12 | //
13 | //= require_tree .
14 |
--------------------------------------------------------------------------------
/spec/dummy_app/app/assets/stylesheets/application.css:
--------------------------------------------------------------------------------
1 | /*
2 | * This is a manifest file that'll be compiled into application.css, which will include all the files
3 | * listed below.
4 | *
5 | * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6 | * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
7 | *
8 | * You're free to add application-wide styles to this file and they'll appear at the top of the
9 | * compiled file, but it's generally better to create a new file per style scope.
10 | *
11 | *= require_self
12 | *= require_tree .
13 | */
14 |
--------------------------------------------------------------------------------
/spec/dummy_app/app/controllers/application_controller.rb:
--------------------------------------------------------------------------------
1 | class ApplicationController < ActionController::Base
2 | protect_from_forgery
3 | end
4 |
--------------------------------------------------------------------------------
/spec/dummy_app/app/controllers/sample_controller.rb:
--------------------------------------------------------------------------------
1 | class SampleController < ApplicationController
2 | end
3 |
--------------------------------------------------------------------------------
/spec/dummy_app/app/helpers/application_helper.rb:
--------------------------------------------------------------------------------
1 | module ApplicationHelper
2 | end
3 |
--------------------------------------------------------------------------------
/spec/dummy_app/app/views/layouts/application.html.erb:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | DummyApp
5 | <%= stylesheet_link_tag "application", :media => "all" %>
6 | <%= javascript_include_tag "application" %>
7 | <%= csrf_meta_tags %>
8 |
9 |
10 |
11 | <%= yield %>
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/spec/dummy_app/app/views/sample/index.html.erb:
--------------------------------------------------------------------------------
1 | TimeCopConsole Demo
2 | Hello world!
3 |
4 | <%= timecop_console_layout %>
5 |
--------------------------------------------------------------------------------
/spec/dummy_app/config.ru:
--------------------------------------------------------------------------------
1 | # This file is used by Rack-based servers to start the application.
2 |
3 | require ::File.expand_path('../config/environment', __FILE__)
4 | run DummyApp::Application
5 |
--------------------------------------------------------------------------------
/spec/dummy_app/config/application.rb:
--------------------------------------------------------------------------------
1 | require File.expand_path('../boot', __FILE__)
2 |
3 | # Pick the frameworks you want:
4 | # require "active_record/railtie"
5 | require "action_controller/railtie"
6 | #require "action_mailer/railtie"
7 | #require "active_resource/railtie"
8 | # require "rails/test_unit/railtie"
9 |
10 | Bundler.require(*Rails.groups)
11 | require 'timecop_console'
12 |
13 | module DummyApp
14 | class Application < Rails::Application
15 | # Settings in config/environments/* take precedence over those specified here.
16 | # Application configuration should go into files in config/initializers
17 | # -- all .rb files in that directory are automatically loaded.
18 |
19 | # Custom directories with classes and modules you want to be autoloadable.
20 | # config.autoload_paths += %W(#{config.root}/extras)
21 |
22 | # Only load the plugins named here, in the order given (default is alphabetical).
23 | # :all can be used as a placeholder for all plugins not explicitly named.
24 | # config.plugins = [ :exception_notification, :ssl_requirement, :all ]
25 |
26 | # Activate observers that should always be running.
27 | # config.active_record.observers = :cacher, :garbage_collector, :forum_observer
28 |
29 | # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
30 | # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
31 | # config.time_zone = 'Central Time (US & Canada)'
32 |
33 | # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
34 | # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
35 | # config.i18n.default_locale = :de
36 |
37 | # Configure the default encoding used in templates for Ruby 1.9.
38 | config.encoding = "utf-8"
39 |
40 | # Configure sensitive parameters which will be filtered from the log file.
41 | config.filter_parameters += [:password]
42 |
43 | # Enable escaping HTML in JSON.
44 | config.active_support.escape_html_entities_in_json = true
45 |
46 | # Use SQL instead of Active Record's schema dumper when creating the database.
47 | # This is necessary if your schema can't be completely dumped by the schema dumper,
48 | # like if you have constraints or database-specific column types
49 | # config.active_record.schema_format = :sql
50 |
51 | # Enforce whitelist mode for mass assignment.
52 | # This will create an empty whitelist of attributes available for mass-assignment for all models
53 | # in your app. As such, your models will need to explicitly whitelist or blacklist accessible
54 | # parameters by using an attr_accessible or attr_protected declaration.
55 | # config.active_record.whitelist_attributes = true
56 |
57 | end
58 | end
59 |
--------------------------------------------------------------------------------
/spec/dummy_app/config/boot.rb:
--------------------------------------------------------------------------------
1 | require 'rubygems'
2 |
3 | # Set up gems listed in the Gemfile.
4 | ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
5 |
6 | require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])
7 |
--------------------------------------------------------------------------------
/spec/dummy_app/config/environment.rb:
--------------------------------------------------------------------------------
1 | # Load the rails application
2 | require File.expand_path('../application', __FILE__)
3 |
4 | # Initialize the rails application
5 | DummyApp::Application.initialize!
6 |
--------------------------------------------------------------------------------
/spec/dummy_app/config/environments/development.rb:
--------------------------------------------------------------------------------
1 | require "sprockets/railtie"
2 |
3 | DummyApp::Application.configure do
4 | # Settings specified here will take precedence over those in config/application.rb
5 |
6 | # In the development environment your application's code is reloaded on
7 | # every request. This slows down response time but is perfect for development
8 | # since you don't have to restart the web server when you make code changes.
9 | config.cache_classes = false
10 |
11 | # Show full error reports and disable caching
12 | config.consider_all_requests_local = true
13 | config.action_controller.perform_caching = false
14 |
15 | # Don't care if the mailer can't send
16 | # config.action_mailer.raise_delivery_errors = false
17 |
18 | # Print deprecation notices to the Rails logger
19 | config.active_support.deprecation = :log
20 |
21 | # Only use best-standards-support built into browsers
22 | config.action_dispatch.best_standards_support = :builtin
23 |
24 | config.eager_load = false
25 |
26 | config.assets.debug = true
27 |
28 | end
29 |
--------------------------------------------------------------------------------
/spec/dummy_app/config/environments/production.rb:
--------------------------------------------------------------------------------
1 | DummyApp::Application.configure do
2 | # Settings specified here will take precedence over those in config/application.rb
3 |
4 | # Code is not reloaded between requests
5 | config.cache_classes = true
6 |
7 | # Full error reports are disabled and caching is turned on
8 | config.consider_all_requests_local = false
9 | config.action_controller.perform_caching = true
10 |
11 | # Disable Rails's static asset server (Apache or nginx will already do this)
12 | config.serve_static_assets = false
13 |
14 |
15 | # Specifies the header that your server uses for sending files
16 | # config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache
17 | # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx
18 |
19 | # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
20 | # config.force_ssl = true
21 |
22 | # See everything in the log (default is :info)
23 | # config.log_level = :debug
24 |
25 | # Prepend all log lines with the following tags
26 | # config.log_tags = [ :subdomain, :uuid ]
27 |
28 | # Use a different logger for distributed setups
29 | # config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new)
30 |
31 | # Use a different cache store in production
32 | # config.cache_store = :mem_cache_store
33 |
34 | # Enable serving of images, stylesheets, and JavaScripts from an asset server
35 | # config.action_controller.asset_host = "http://assets.example.com"
36 |
37 |
38 | # Disable delivery errors, bad email addresses will be ignored
39 | # config.action_mailer.raise_delivery_errors = false
40 |
41 | # Enable threaded mode
42 | # config.threadsafe!
43 |
44 | # Enable locale fallbacks for I18n (makes lookups for any locale fall back to
45 | # the I18n.default_locale when a translation can not be found)
46 | config.i18n.fallbacks = true
47 |
48 | # Send deprecation notices to registered listeners
49 | config.active_support.deprecation = :notify
50 |
51 | config.eager_load = true
52 | end
53 |
--------------------------------------------------------------------------------
/spec/dummy_app/config/environments/test.rb:
--------------------------------------------------------------------------------
1 | DummyApp::Application.configure do
2 | # Settings specified here will take precedence over those in config/application.rb
3 |
4 | # The test environment is used exclusively to run your application's
5 | # test suite. You never need to work with it otherwise. Remember that
6 | # your test database is "scratch space" for the test suite and is wiped
7 | # and recreated between test runs. Don't rely on the data there!
8 | config.cache_classes = true
9 |
10 | # Configure static asset server for tests with Cache-Control for performance
11 | config.serve_static_assets = true
12 | config.static_cache_control = "public, max-age=3600"
13 |
14 | # Show full error reports and disable caching
15 | config.consider_all_requests_local = true
16 | config.action_controller.perform_caching = false
17 |
18 | # Raise exceptions instead of rendering exception templates
19 | config.action_dispatch.show_exceptions = false
20 |
21 | # Disable request forgery protection in test environment
22 | config.action_controller.allow_forgery_protection = false
23 |
24 | # Tell Action Mailer not to deliver emails to the real world.
25 | # The :test delivery method accumulates sent emails in the
26 | # ActionMailer::Base.deliveries array.
27 | #config.action_mailer.delivery_method = :test
28 |
29 |
30 | # Print deprecation notices to the stderr
31 | config.active_support.deprecation = :stderr
32 |
33 | config.eager_load = false
34 | end
35 |
--------------------------------------------------------------------------------
/spec/dummy_app/config/initializers/backtrace_silencers.rb:
--------------------------------------------------------------------------------
1 | # Be sure to restart your server when you modify this file.
2 |
3 | # You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces.
4 | # Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ }
5 |
6 | # You can also remove all the silencers if you're trying to debug a problem that might stem from framework code.
7 | # Rails.backtrace_cleaner.remove_silencers!
8 |
--------------------------------------------------------------------------------
/spec/dummy_app/config/initializers/inflections.rb:
--------------------------------------------------------------------------------
1 | # Be sure to restart your server when you modify this file.
2 |
3 | # Add new inflection rules using the following format
4 | # (all these examples are active by default):
5 | # ActiveSupport::Inflector.inflections do |inflect|
6 | # inflect.plural /^(ox)$/i, '\1en'
7 | # inflect.singular /^(ox)en/i, '\1'
8 | # inflect.irregular 'person', 'people'
9 | # inflect.uncountable %w( fish sheep )
10 | # end
11 | #
12 | # These inflection rules are supported but not enabled by default:
13 | # ActiveSupport::Inflector.inflections do |inflect|
14 | # inflect.acronym 'RESTful'
15 | # end
16 |
--------------------------------------------------------------------------------
/spec/dummy_app/config/initializers/mime_types.rb:
--------------------------------------------------------------------------------
1 | # Be sure to restart your server when you modify this file.
2 |
3 | # Add new mime types for use in respond_to blocks:
4 | # Mime::Type.register "text/richtext", :rtf
5 | # Mime::Type.register_alias "text/html", :iphone
6 |
--------------------------------------------------------------------------------
/spec/dummy_app/config/initializers/secret_token.rb:
--------------------------------------------------------------------------------
1 | # Be sure to restart your server when you modify this file.
2 |
3 | # Your secret key for verifying the integrity of signed cookies.
4 | # If you change this key, all old signed cookies will become invalid!
5 | # Make sure the secret is at least 30 characters and all random,
6 | # no regular words or you'll be exposed to dictionary attacks.
7 | DummyApp::Application.config.secret_token = 'e45f2b6bb14131aae78a6c66726f943886687582bee47c75ae04f4c7329c46101029848e17b8e17ed275d844c2d6afe80be5ad49519a15fe511148cbf7945e03'
8 |
--------------------------------------------------------------------------------
/spec/dummy_app/config/initializers/session_store.rb:
--------------------------------------------------------------------------------
1 | # Be sure to restart your server when you modify this file.
2 |
3 | DummyApp::Application.config.session_store :cookie_store, :key => '_dummy_app_session'
4 |
5 | # Use the database for sessions instead of the cookie-based default,
6 | # which shouldn't be used to store highly confidential information
7 | # (create the session table with "rails generate session_migration")
8 | # DummyApp::Application.config.session_store :active_record_store
9 |
--------------------------------------------------------------------------------
/spec/dummy_app/config/initializers/wrap_parameters.rb:
--------------------------------------------------------------------------------
1 | # Be sure to restart your server when you modify this file.
2 | #
3 | # This file contains settings for ActionController::ParamsWrapper which
4 | # is enabled by default.
5 |
6 | # Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array.
7 | ActiveSupport.on_load(:action_controller) do
8 | wrap_parameters :format => [:json]
9 | end
10 |
11 |
--------------------------------------------------------------------------------
/spec/dummy_app/config/locales/en.yml:
--------------------------------------------------------------------------------
1 | # Sample localization file for English. Add more files in this directory for other locales.
2 | # See https://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points.
3 |
4 | en:
5 | hello: "Hello world"
6 |
--------------------------------------------------------------------------------
/spec/dummy_app/config/routes.rb:
--------------------------------------------------------------------------------
1 | DummyApp::Application.routes.draw do
2 | mount TimecopConsole::Engine => '/timecop_console'
3 | root 'sample#index'
4 | end
5 |
--------------------------------------------------------------------------------
/spec/dummy_app/db/seeds.rb:
--------------------------------------------------------------------------------
1 | # This file should contain all the record creation needed to seed the database with its default values.
2 | # The data can then be loaded with the rake db:seed (or created alongside the db with db:setup).
3 | #
4 | # Examples:
5 | #
6 | # cities = City.create([{ :name => 'Chicago' }, { :name => 'Copenhagen' }])
7 | # Mayor.create(:name => 'Emanuel', :city => cities.first)
8 |
--------------------------------------------------------------------------------
/spec/dummy_app/doc/README_FOR_APP:
--------------------------------------------------------------------------------
1 | Use this README file to introduce your application and point to useful places in the API for learning more.
2 | Run "rake doc:app" to generate API documentation for your models, controllers, helpers, and libraries.
3 |
--------------------------------------------------------------------------------
/spec/dummy_app/public/404.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | The page you were looking for doesn't exist (404)
5 |
17 |
18 |
19 |
20 |
21 |
22 |
The page you were looking for doesn't exist.
23 |
You may have mistyped the address or the page may have moved.
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/spec/dummy_app/public/422.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | The change you wanted was rejected (422)
5 |
17 |
18 |
19 |
20 |
21 |
22 |
The change you wanted was rejected.
23 |
Maybe you tried to change something you didn't have access to.
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/spec/dummy_app/public/500.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | We're sorry, but something went wrong (500)
5 |
17 |
18 |
19 |
20 |
21 |
22 |
We're sorry, but something went wrong.
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/spec/dummy_app/public/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ferndopolis/timecop-console/30491e690e9882701ef0609e2fe87b3573b5efcb/spec/dummy_app/public/favicon.ico
--------------------------------------------------------------------------------
/spec/dummy_app/public/robots.txt:
--------------------------------------------------------------------------------
1 | # See http://www.robotstxt.org/wc/norobots.html for documentation on how to use the robots.txt file
2 | #
3 | # To ban all spiders from the entire site uncomment the next two lines:
4 | # User-Agent: *
5 | # Disallow: /
6 |
--------------------------------------------------------------------------------
/spec/dummy_app/script/rails:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env ruby
2 | # This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
3 |
4 | APP_PATH = File.expand_path('../../config/application', __FILE__)
5 | require File.expand_path('../../config/boot', __FILE__)
6 | require 'rails/commands'
7 |
--------------------------------------------------------------------------------
/spec/helpers/main_helper_spec.rb:
--------------------------------------------------------------------------------
1 | require 'spec_helper'
2 |
3 | describe TimecopConsole::MainHelper do
4 | describe "#time_travel_to" do
5 | context "when a Date object is passed" do
6 | let(:date) { Date.parse('Dec 12, 1950') }
7 |
8 | it 'should return a button with timecop console route' do
9 | helper.time_travel_to(date).should == ""
10 | end
11 |
12 | it 'should set the hour to default of 12' do
13 | helper.time_travel_to(date).should include("current_time%284i%29%5D=12")
14 | end
15 |
16 | context "when a custom name is passed" do
17 | let(:name) { "important_event" }
18 | it "should pass the name as the button name" do
19 | helper.time_travel_to(date, name).should include("value=\"important_event\"")
20 | end
21 | end
22 | end
23 |
24 | context "when a DateTime object is passed" do
25 | let(:date) { DateTime.parse('2001-02-03T04:05:06+07:00') }
26 |
27 | it "should set the hour accordingly" do
28 | helper.time_travel_to(date).should include("current_time%284i%29%5D=4")
29 | end
30 | it "should set the minute accordingly" do
31 | helper.time_travel_to(date).should include("current_time%285i%29%5D=5")
32 | end
33 | end
34 |
35 | context "when a string is passed" do
36 | let(:date) { "12-12-1950" }
37 | it "should raise an ArgumentError" do
38 | expect { helper.time_travel_to(date) }.to raise_error(ArgumentError, "Argument must be a Date object")
39 | end
40 | end
41 | end
42 | end
43 |
--------------------------------------------------------------------------------
/spec/spec_helper.rb:
--------------------------------------------------------------------------------
1 | # Configure Rails Envinronment
2 | ENV["RAILS_ENV"] ||= "test"
3 | require File.expand_path('../dummy_app/config/environment', __FILE__)
4 | require 'rspec/rails'
5 | require 'rspec/autorun'
6 |
7 | require 'simplecov'
8 | SimpleCov.start do
9 | add_filter '/config/'
10 | add_group 'Controllers', 'app/controllers'
11 | add_group 'Libraries', 'lib'
12 | add_group 'Specs', 'spec'
13 | end
14 |
15 | RSpec.configure do |config|
16 | config.include TimecopConsole::Engine.routes.url_helpers
17 | end
18 |
--------------------------------------------------------------------------------
/timecop-console.gemspec:
--------------------------------------------------------------------------------
1 | # encoding: utf-8
2 | require File.expand_path('../lib/timecop_console/version', __FILE__)
3 |
4 | Gem::Specification.new do |spec|
5 | spec.add_dependency "railties", '>= 3.1', '< 5.0'
6 | spec.add_dependency 'timecop', '>= 0.5'
7 | spec.authors = ["John Trupiano"]
8 | spec.description = %q{TimecopConsole manipulates Time.now using Timecop gem.}
9 | spec.email = ['jtrupiano@gmail.com']
10 | spec.files = Dir['Gemfile', 'LICENSE', 'README.rdoc', 'Rakefile', 'app/**/*', 'config/**/*', 'lib/**/*']
11 | spec.homepage = 'https://github.com/ferndopolis/timecop-console'
12 | spec.name = 'timecop-console'
13 | spec.require_paths = ['lib']
14 | spec.required_rubygems_version = Gem::Requirement.new('>= 1.3.6')
15 | spec.summary = %q{Expose Timecop's capabilities to the UI in your rails app, allowing QA to take advantage of it.}
16 | spec.test_files = Dir['spec/**/*']
17 | spec.version = TimecopConsole::Version
18 | end
19 |
--------------------------------------------------------------------------------