Merge pull request #347 from ChrisBr/fix_test_dates

Implements timecop to make tests independent from DateTime
This commit is contained in:
Christian Bruckmayer
2014-07-23 15:20:44 +02:00
14 changed files with 42 additions and 38 deletions

View File

@@ -127,6 +127,7 @@ group :test do
gem 'shoulda'
# Extracted from RSpec 3 stub_model and mock_model
gem 'rspec-activemodel-mocks'
gem 'timecop'
end
group :development, :test do

View File

@@ -362,6 +362,7 @@ GEM
thor (0.19.1)
thread_safe (0.3.4)
tilt (1.4.1)
timecop (0.7.1)
timers (1.1.0)
tins (1.1.0)
transitions (0.1.12)
@@ -443,6 +444,7 @@ DEPENDENCIES
shoulda
spring-commands-rspec
sqlite3
timecop
transitions
turbolinks
uglifier (>= 1.3.0)

View File

@@ -43,6 +43,9 @@ Osem::Application.configure do
config.after_initialize do
ActiveRecord::Base.logger = nil
# Set Time.now to May 1, 2014 00:01:00 AM (at this instant), but allow it to move forward
t = Time.local(2014, 05, 01, 00, 01, 00)
Timecop.travel(t)
end
end

View File

@@ -2,8 +2,8 @@
FactoryGirl.define do
factory :call_for_papers do
start_date Date.today - 1
end_date Date.today + 7
start_date { 1.day.ago }
end_date { 7.days.from_now }
description 'We call for papers'
conference
end

View File

@@ -7,10 +7,10 @@ FactoryGirl.define do
social_tag 'dps14'
timezone 'Amsterdam'
contact_email 'admin@example.com'
start_date Date.today
end_date Date.today + 6.days
registration_start_date Date.today + 3.days
registration_end_date Date.today + 5.days
start_date { Date.today }
end_date { 6.days.from_now }
registration_start_date { 3.days.from_now }
registration_end_date { 5.days.from_now }
make_conference_public true
venue
end

View File

@@ -5,7 +5,7 @@ FactoryGirl.define do
picture_file_name 'rails.png'
picture_content_type 'image/png'
picture_file_size '1024'
picture_updated_at DateTime.now
picture_updated_at { DateTime.now }
description 'Lorem Ipsum Dolor'
conference
end

View File

@@ -2,7 +2,7 @@ FactoryGirl.define do
factory :social_event do
title 'Example Social Event'
description 'Lorem Ipsum Dolsum'
date Date.today
date { Date.today }
conference
end

View File

@@ -2,7 +2,7 @@
FactoryGirl.define do
factory :target do
due_date Date.today + 14
due_date { 14.days.from_now }
target_count 100
unit Target.units[:submissions]
end

View File

@@ -5,7 +5,7 @@ FactoryGirl.define do
sequence(:name) { |n| "name#{n}" }
password 'changeme'
password_confirmation 'changeme'
confirmed_at Time.now
confirmed_at { Time.now }
biography <<-EOS
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus enim
nunc, venenatis non sapien convallis, dictum suscipit purus. Vestibulum

View File

@@ -1,6 +1,6 @@
FactoryGirl.define do
factory :vday do
day Date.today
day { Date.today }
description 'Lorem Ipsum dolsum'
conference
end

View File

@@ -18,17 +18,17 @@ feature Conference do
click_link 'Add vday'
expect(page.all('div.nested-fields').count == 1).to be true
page.
find('div.nested-fields:nth-of-type(1) select:nth-of-type(1)').
set("#{Date.today.strftime('%Y')}")
find('div.nested-fields:nth-of-type(1) select:nth-of-type(1)').
select("#{Date.today.strftime('%Y')}")
page.
find('div.nested-fields:nth-of-type(1) select:nth-of-type(2)').
set("#{Date.today.strftime('%B')}")
find('div.nested-fields:nth-of-type(1) select:nth-of-type(2)').
select("#{Date.today.strftime('%B')}")
page.
find('div.nested-fields:nth-of-type(1) select:nth-of-type(3)').
set("#{Date.today.strftime('%-d')}")
find('div.nested-fields:nth-of-type(1) select:nth-of-type(3)').
select("#{Date.today.strftime('%-d')}")
page.
find('div.nested-fields:nth-of-type(1) div:nth-of-type(1) textarea').
set('Example Person')
find('div.nested-fields:nth-of-type(1) div:nth-of-type(1) textarea').
set('Example Person')
click_button 'Update Conference'
expect(flash).
to eq('Volunteering options were successfully updated.')
@@ -64,17 +64,17 @@ feature Conference do
click_link 'Add vday'
expect(page.all('div.nested-fields').count == 1).to be true
page.
find('div.nested-fields:nth-of-type(1) select:nth-of-type(1)').
set("#{Date.today.strftime('%Y')}")
find('div.nested-fields:nth-of-type(1) select:nth-of-type(1)').
select("#{Date.today.strftime('%Y')}")
page.
find('div.nested-fields:nth-of-type(1) select:nth-of-type(2)').
set("#{Date.today.strftime('%B')}")
find('div.nested-fields:nth-of-type(1) select:nth-of-type(2)').
select("#{Date.today.strftime('%B')}")
page.
find('div.nested-fields:nth-of-type(1) select:nth-of-type(3)').
set("#{Date.today.strftime('%-d')}")
find('div.nested-fields:nth-of-type(1) select:nth-of-type(3)').
select("#{Date.today.strftime('%-d')}")
page.
find('div.nested-fields:nth-of-type(1) div:nth-of-type(1) textarea').
set('Example Person')
find('div.nested-fields:nth-of-type(1) div:nth-of-type(1) textarea').
set('Example Person')
click_button 'Update Conference'
expect(flash).
to eq('Volunteering options were successfully updated.')

View File

@@ -717,6 +717,7 @@ describe Conference do
it 'returns the last two past conferences if there are no pending conferences' do
subject.start_date = Time.now - 10.days
subject.end_date = Time.now - 5.days
subject.save
c = create(:conference,
short_title: 'c', start_date: Time.now - 1.year,
end_date: Time.now - 360.days)
@@ -901,9 +902,9 @@ describe Conference do
let!(:admin_role) { create(:admin_role) }
it 'self#event_distribution calculates correct values with user' do
create(:user, last_sign_in_at: Time.now - 3.months) # active
create(:user, last_sign_in_at: Date.today - 3.months) # active
create(:user, confirmed_at: nil) # unconfirmed
create(:user, last_sign_in_at: Time.now - 1.year - 1.day) # dead
create(:user, last_sign_in_at: Date.today - 1.year - 1.day) # dead
result = {}
result['Active'] = { 'color' => 'green', 'value' => 1 }
result['Unconfirmed'] = { 'color' => 'red', 'value' => 1 }
@@ -913,7 +914,7 @@ describe Conference do
end
it 'self#event_distribution calculates correct with only active user' do
create(:user, last_sign_in_at: Time.now - 3.months) # active
create(:user, last_sign_in_at: Date.today - 3.months) # active
result = {}
result['Active'] = { 'color' => 'green', 'value' => 1 }

View File

@@ -97,7 +97,7 @@ describe Target do
target = build(:target, target_count: 10, unit: Target.units[:registrations])
conference.targets = [target]
result = "10 Registrations by #{Date.today + 14}"
result = "10 Registrations by #{14.days.from_now.to_date}"
expect(target.to_s).to eq(result)
end

View File

@@ -3,15 +3,12 @@ require 'spec_helper'
describe 'admin/callforpapers/show' do
it 'renders callforpapers details' do
@conference = create(:conference)
assign :conference, @conference
assign :cfp, stub_model(CallForPapers, start_date: Date.today,
end_date: Date.today + 7.days,
description: 'Lorem Ipsum Dolsum')
assign :conference, create(:conference)
assign :cfp, create(:call_for_papers)
render
expect(rendered).to include(Date.today.strftime('%Y-%m-%d'))
expect(rendered).to include(1.day.ago.strftime('%Y-%m-%d'))
expect(rendered).to include(7.days.from_now.strftime('%Y-%m-%d'))
expect(rendered).to include('Lorem Ipsum Dolsum')
expect(rendered).to include('We call for papers')
end
end