diff --git a/Gemfile b/Gemfile index 0de00755..d43f903d 100644 --- a/Gemfile +++ b/Gemfile @@ -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 diff --git a/Gemfile.lock b/Gemfile.lock index e5ead004..207994b4 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -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) diff --git a/config/environments/test.rb b/config/environments/test.rb index 64339b64..5fe68d99 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -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 diff --git a/spec/factories/call_for_papers.rb b/spec/factories/call_for_papers.rb index 1cf91c84..5585a361 100644 --- a/spec/factories/call_for_papers.rb +++ b/spec/factories/call_for_papers.rb @@ -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 diff --git a/spec/factories/conferences.rb b/spec/factories/conferences.rb index e4b6732f..4b7be4be 100644 --- a/spec/factories/conferences.rb +++ b/spec/factories/conferences.rb @@ -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 diff --git a/spec/factories/photos.rb b/spec/factories/photos.rb index aa9f0f96..49180a0b 100644 --- a/spec/factories/photos.rb +++ b/spec/factories/photos.rb @@ -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 diff --git a/spec/factories/social_events.rb b/spec/factories/social_events.rb index 2dd59b37..46088701 100644 --- a/spec/factories/social_events.rb +++ b/spec/factories/social_events.rb @@ -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 diff --git a/spec/factories/targets.rb b/spec/factories/targets.rb index ea9d4e9f..181a4e25 100644 --- a/spec/factories/targets.rb +++ b/spec/factories/targets.rb @@ -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 diff --git a/spec/factories/users.rb b/spec/factories/users.rb index 01c175e7..7ab2b62c 100644 --- a/spec/factories/users.rb +++ b/spec/factories/users.rb @@ -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 diff --git a/spec/factories/vdays.rb b/spec/factories/vdays.rb index 3fc4307f..08aff069 100644 --- a/spec/factories/vdays.rb +++ b/spec/factories/vdays.rb @@ -1,6 +1,6 @@ FactoryGirl.define do factory :vday do - day Date.today + day { Date.today } description 'Lorem Ipsum dolsum' conference end diff --git a/spec/features/volunteers_spec.rb b/spec/features/volunteers_spec.rb index 70f4e16b..bb82c468 100644 --- a/spec/features/volunteers_spec.rb +++ b/spec/features/volunteers_spec.rb @@ -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.') diff --git a/spec/models/conference_spec.rb b/spec/models/conference_spec.rb index 9c63e291..885ba09c 100644 --- a/spec/models/conference_spec.rb +++ b/spec/models/conference_spec.rb @@ -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 } diff --git a/spec/models/target_spec.rb b/spec/models/target_spec.rb index e57b5406..53c46ae3 100644 --- a/spec/models/target_spec.rb +++ b/spec/models/target_spec.rb @@ -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 diff --git a/spec/views/admin/callforpapers/show.html.haml_spec.rb b/spec/views/admin/callforpapers/show.html.haml_spec.rb index d04551c6..8d747e36 100644 --- a/spec/views/admin/callforpapers/show.html.haml_spec.rb +++ b/spec/views/admin/callforpapers/show.html.haml_spec.rb @@ -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