Replace Timecop with new ActiveSupport helpers

This commit is contained in:
Dan Rice 2014-05-16 13:24:40 -04:00
parent 7d7e47deff
commit d0cec167a8
13 changed files with 24 additions and 27 deletions

View file

@ -59,7 +59,6 @@ group :test do
gem "mocha", :require => false
gem "aruba", git: 'https://github.com/cucumber/aruba', :require => false # need 0.5.4 for piping files; 0.5.3 is latest
gem "timecop", "~> 0.6.2"
# Note that > 2.14 has problems, see:
# https://code.google.com/p/selenium/issues/detail?id=3075

View file

@ -189,7 +189,6 @@ GEM
thor (0.19.1)
thread_safe (0.3.3)
tilt (1.4.1)
timecop (0.6.3)
tolk (1.5.0)
safe_yaml (~> 0.8)
will_paginate
@ -243,7 +242,6 @@ DEPENDENCIES
sqlite3
swf_fu
therubyracer
timecop (~> 0.6.2)
tolk (>= 1.5.0)
uglifier (>= 1.3.0)
will_paginate

View file

@ -12,7 +12,7 @@ end
Given /^the date is "(.*?)"$/ do |date|
# remember to tag the scenario with @reset_time to reset this travel
Timecop.travel(date)
travel_to date
end
Given(/^I have selected the view for group by (project|context)$/) do |grouping|

View file

@ -9,5 +9,5 @@ Before('@aruba') do
end
After('@reset_time') do
Timecop.return
travel_back
end

View file

@ -183,7 +183,7 @@ class RecurringTodosControllerTest < ActionController::TestCase
# this test is a duplicate of the unit test. Only this test covers the
# codepath in the controllers
Timecop.travel(Time.local(2012,1,1)) do
travel_to Time.local(2012,1,1) do
login_as(:admin_user)
@ -292,7 +292,7 @@ class RecurringTodosControllerTest < ActionController::TestCase
end
def test_start_on_monthly_rec_todo
Timecop.travel(Time.local(2012,1,1)) do
travel_to Time.local(2012,1,1) do
login_as(:admin_user)

View file

@ -97,7 +97,7 @@ class StatsControllerTest < ActionController::TestCase
end
def test_actions_done_last12months_data
Timecop.travel(Time.local(2013, 1, 15)) do
travel_to Time.local(2013, 1, 15) do
login_as(:admin_user)
@current_user = User.find(users(:admin_user).id)
@current_user.todos.delete_all
@ -143,7 +143,7 @@ class StatsControllerTest < ActionController::TestCase
end
def test_empty_last12months_data
Timecop.travel(Time.local(2013, 1, 15)) do
travel_to Time.local(2013, 1, 15) do
login_as(:admin_user)
@current_user = User.find(users(:admin_user).id)
@current_user.todos.delete_all

View file

@ -435,7 +435,7 @@ class TodosControllerTest < ActionController::TestCase
login_as(:admin_user)
# given a todo in the tickler that should be activated
Timecop.travel(2.weeks.ago) do
travel_to 2.weeks.ago do
create_todo(
description: "tickler",
show_from: 1.week.from_now.
@ -715,7 +715,7 @@ class TodosControllerTest < ActionController::TestCase
end
def test_toggle_check_on_rec_todo_show_from_today
Timecop.travel(2014, 1, 15) do
travel_to Time.zone.local(2014, 1, 15) do
login_as(:admin_user)
# link todo_1 and recurring_todo_1

View file

@ -101,7 +101,7 @@ module RecurringTodos
end
def test_determine_start
Timecop.travel(2013,1,1) do
travel_to Time.zone.local(2013,1,1) do
rt = create_recurring_todo
assert_equal "2013-01-01 00:00:00", rt.send(:determine_start, nil).to_s(:db), "no previous date, use today"
assert_equal "2013-01-01 00:00:00", rt.send(:determine_start, nil, 1.day).to_s(:db), "no previous date, use today without offset"

View file

@ -1,9 +1,10 @@
require_relative '../minimal_test_helper'
require_relative '../../lib/staleness'
require_relative '../../lib/user_time'
require 'timecop'
class StalenessTest < Minitest::Test
include ActiveSupport::Testing::TimeHelpers
FakePrefs = Struct.new(:time_zone)
FakeUser = Struct.new(:time) do
def prefs
@ -36,11 +37,11 @@ class StalenessTest < Minitest::Test
def setup
@current_user = FakeUser.new(now)
Timecop.freeze(Time.utc(2013,02,28))
travel_to Time.utc(2013,02,28)
end
def teardown
Timecop.return
travel_back
end
def test_item_with_due_date_is_not_stale_ever

View file

@ -169,7 +169,7 @@ class TodoTest < ActiveSupport::TestCase
dates.each do |show_from_date|
# setup test case
t = @not_completed1
Timecop.travel(show_from_date - 1.day) do
travel_to show_from_date - 1.day do
t.show_from = show_from_date
t.save!
assert t.deferred?

View file

@ -34,7 +34,7 @@ module Todos
def test_due_this_month_at_start_month
# should return 1 todo
Timecop.travel(2013,9,1) do
travel_to Time.zone.local(2013,9,1) do
due_this_month = create_todo(Time.zone.now.end_of_month)
assert_equal [due_this_month], @calendar.due_this_month
end
@ -43,7 +43,7 @@ module Todos
def test_due_this_month_at_end_month
# the todo is due next week and is thus left out for todos due rest
# of month (i.e. after next week, but in this month)
Timecop.travel(2013,9,23) do
travel_to Time.zone.local(2013,9,23) do
due_this_month = create_todo(Time.zone.now.end_of_month)
assert_equal 0, @calendar.due_this_month.size
end

View file

@ -4,7 +4,7 @@ module Todos
class DoneTodosTest < ActiveSupport::TestCase
def test_completed_period
Timecop.travel(2013,1,23,12,00,00) do # wednesday at 12:00;
travel_to Time.zone.local(2013,1,23,12,00,00) do # wednesday at 12:00;
assert_equal "today", DoneTodos.completed_period(Time.zone.local(2013,1,23,9,00)) # today at 9:00
assert_equal "rest_of_week", DoneTodos.completed_period(Time.zone.local(2013,1,21)) # monday this week
assert_equal "rest_of_month", DoneTodos.completed_period(Time.zone.local(2013,1,8)) # tuestday in first week of jan
@ -30,13 +30,13 @@ module Todos
todos = users(:admin_user).todos
# When I mark a todo complete on jan 1
Timecop.travel(2013,1,1,0,0) do
travel_to Time.zone.local(2013,1,1,0,0) do
t = users(:admin_user).todos.active.first
t.complete!
end
# Then I should be in rest_of_week on jan 2
Timecop.travel(2013,1,2,0,0) do
travel_to Time.zone.local(2013,1,2,0,0) do
assert 0, DoneTodos.done_today(todos.reload, {}).count
assert 1, DoneTodos.done_rest_of_week(todos.reload, {}).count
end
@ -46,13 +46,13 @@ module Todos
todos = users(:admin_user).todos
# When I mark a todo complete on jan 1
Timecop.travel(2013,1,1,0,0) do
travel_to Time.zone.local(2013,1,1,0,0) do
t = users(:admin_user).todos.active.first
t.complete!
end
# Then I should be in rest_of_month on jan 21
Timecop.travel(2013,1,21,0,0) do
travel_to Time.zone.local(2013,1,21,0,0) do
assert 0, DoneTodos.done_today(todos.reload, {}).count
assert 0, DoneTodos.done_rest_of_week(todos.reload, {}).count
assert 1, DoneTodos.done_rest_of_month(todos.reload, {}).count

View file

@ -1,5 +1,4 @@
require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
require 'timecop'
class UserTest < ActiveSupport::TestCase
fixtures :users, :preferences, :projects, :contexts, :todos, :recurring_todos
@ -351,7 +350,7 @@ class UserTest < ActiveSupport::TestCase
assert_nil u.remember_token_expires_at
# set token on 2013-feb-28
Timecop.travel(Time.local(2013, 2, 28)) do
travel_to Time.local(2013, 2, 28) do
u.remember_me
assert_not_nil u.remember_token_expires_at
@ -359,12 +358,12 @@ class UserTest < ActiveSupport::TestCase
end
# token should be valid after 5 days
Timecop.travel(Time.local(2013, 3, 5)) do
travel_to Time.local(2013, 3, 5) do
assert u.remember_token?
end
# token should not be valid after more than 2 weeks
Timecop.travel(Time.local(2013, 3, 28)) do
travel_to Time.local(2013, 3, 28) do
assert !u.remember_token?
end
end