From 99916f870317dca416ff401d475a559fd7d1fb40 Mon Sep 17 00:00:00 2001 From: Reid Beels Date: Fri, 30 Aug 2013 15:41:58 -0700 Subject: [PATCH] Run tests in UTC, instead of the local time zone --- config/environments/test.rb | 2 ++ spec/controllers/proposals_controller_spec.rb | 4 ++-- spec/fixtures/proposals.yml | 20 +++++++++---------- spec/helpers/time_range_helper_spec.rb | 4 ++-- spec/models/event_spec.rb | 4 ++-- spec/models/proposal_spec.rb | 13 ++++++++++-- 6 files changed, 29 insertions(+), 18 deletions(-) diff --git a/config/environments/test.rb b/config/environments/test.rb index 1e709e1d..ba956d3e 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -20,3 +20,5 @@ # The :test delivery method accumulates sent emails in the # ActionMailer::Base.deliveries array. config.action_mailer.delivery_method = :test + +config.time_zone = 'UTC' diff --git a/spec/controllers/proposals_controller_spec.rb b/spec/controllers/proposals_controller_spec.rb index 07d25abf..bc3a72e5 100644 --- a/spec/controllers/proposals_controller_spec.rb +++ b/spec/controllers/proposals_controller_spec.rb @@ -1041,8 +1041,8 @@ def assert_delete(login=nil, &block) calendar = Vpim::Icalendar.decode(response.body).first component = calendar.find{|t| t.summary == item.title} component.should_not be_nil - component.dtstart.should == item.start_time - component.dtend.should == item.end_time + component.dtstart.utc.should == item.start_time.utc + component.dtend.utc.should == item.end_time.utc component.summary.should == item.title component.description.should == (item.respond_to?(:users) ? "#{item.users.map(&:fullname).join(', ')}: #{item.excerpt}" : diff --git a/spec/fixtures/proposals.yml b/spec/fixtures/proposals.yml index 7bdc255f..17fb0bd8 100644 --- a/spec/fixtures/proposals.yml +++ b/spec/fixtures/proposals.yml @@ -104,7 +104,7 @@ postgresql_session: event_id: 2009 track: cooking submitted_at: <%= Time.now.to_s(:db) %> - start_time: <%= Time.zone.parse('2009-06-17 10:00am').to_s(:db) %> + start_time: <%= Time.parse('2009-06-17 10:00am UTC').to_s(:db) %> speaking_experience: "I know PostgreSQL stuff." audience_level: a title: "PostgreSQL Session" @@ -118,7 +118,7 @@ drizzle_session: event_id: 2009 track: cooking submitted_at: <%= Time.now.to_s(:db) %> - start_time: <%= Time.zone.parse('2009-06-17 10:00am').to_s(:db) %> + start_time: <%= Time.parse('2009-06-17 10:00am UTC').to_s(:db) %> speaking_experience: "I know Drizzle stuff." audience_level: a title: "Drizzle Session" @@ -132,7 +132,7 @@ mysql_session: event_id: 2009 track: cooking submitted_at: <%= Time.now.to_s(:db) %> - start_time: <%= Time.zone.parse('2009-06-17 11:00am').to_s(:db) %> + start_time: <%= Time.parse('2009-06-17 11:00am UTC').to_s(:db) %> speaking_experience: "I know MySQL stuff." audience_level: a title: "MySQL Session" @@ -146,7 +146,7 @@ sqlite_session: event_id: 2009 track: cooking submitted_at: <%= Time.now.to_s(:db) %> - start_time: <%= Time.zone.parse('2009-06-17 11:00am').to_s(:db) %> + start_time: <%= Time.parse('2009-06-17 11:00am UTC').to_s(:db) %> audience_level: a title: "SQLite Session" speaking_experience: "I know SQLite stuff." @@ -160,7 +160,7 @@ rakudo_session: event_id: 2009 track: cooking submitted_at: <%= Time.now.to_s(:db) %> - start_time: <%= Time.zone.parse('2009-06-17 12:00pm').to_s(:db) %> + start_time: <%= Time.parse('2009-06-17 12:00pm UTC').to_s(:db) %> speaking_experience: "I AM A PONY!!1!" audience_level: a title: "Rakudo Session" @@ -174,7 +174,7 @@ cloud_session: event_id: 2009 track: hacks submitted_at: <%= Time.now.to_s(:db) %> - start_time: <%= Time.zone.parse('2009-06-18 12:00pm').to_s(:db) %> + start_time: <%= Time.parse('2009-06-18 12:00pm UTC').to_s(:db) %> speaking_experience: "I know everything there is about stratocumulus clouds." audience_level: a title: "The Cloud is Falling!" @@ -188,7 +188,7 @@ business_session: event_id: 2009 track: hacks submitted_at: <%= Time.now.to_s(:db) %> - start_time: <%= Time.zone.parse('2009-06-18 12:00pm').to_s(:db) %> + start_time: <%= Time.parse('2009-06-18 12:00pm UTC').to_s(:db) %> speaking_experience: "I own you." audience_level: a title: "Give us money." @@ -202,7 +202,7 @@ sql_server_session: event_id: 2009 track: business submitted_at: <%= Time.now.to_s(:db) %> - start_time: <%= Time.zone.parse('2009-06-17 10:00am').to_s(:db) %> + start_time: <%= Time.parse('2009-06-17 10:00am UTC').to_s(:db) %> speaking_experience: "Microsoft owns me." audience_level: a title: "SQL Server Session" @@ -216,7 +216,7 @@ couchdb_session: event_id: 2009 track: hacks submitted_at: <%= Time.now.to_s(:db) %> - start_time: <%= Time.zone.parse('2009-06-17 10:30am').to_s(:db) %> + start_time: <%= Time.parse('2009-06-17 10:30am UTC').to_s(:db) %> speaking_experience: "I write all my code using curl." audience_level: a title: "CouchDB Session" @@ -230,7 +230,7 @@ bigtable_session: event_id: 2009 track: hacks submitted_at: <%= Time.now.to_s(:db) %> - start_time: <%= Time.zone.parse('2009-06-17 11:00am').to_s(:db) %> + start_time: <%= Time.parse('2009-06-17 11:00am UTC').to_s(:db) %> speaking_experience: "My table is bigger than yours." audience_level: a title: "BigTable Session" diff --git a/spec/helpers/time_range_helper_spec.rb b/spec/helpers/time_range_helper_spec.rb index a3fd457c..14363952 100644 --- a/spec/helpers/time_range_helper_spec.rb +++ b/spec/helpers/time_range_helper_spec.rb @@ -44,12 +44,12 @@ describe "with objects" do it "should format from objects that respond to just start_time" do - event = Proposal.new(:start_time => Time.parse('2008-04-01 13:30')) + event = Proposal.new(:start_time => Time.parse('2008-04-01 13:30 UTC')) TimeRange.new(event, :format => :text).to_s.should == "Tuesday, April 1, 2008 at 1:30pm" end it "should format from objects that respond to both start_time and end_time" do - event = Proposal.new(:start_time => Time.parse('2008-04-01 13:30'), + event = Proposal.new(:start_time => Time.parse('2008-04-01 13:30 UTC'), :session_type => stub_model(SessionType,:duration => 45)) TimeRange.new(event, :format => :text).to_s.should == "Tuesday, April 1, 2008 from 1:30 - 2:15pm" end diff --git a/spec/models/event_spec.rb b/spec/models/event_spec.rb index b15f83fc..cda49025 100644 --- a/spec/models/event_spec.rb +++ b/spec/models/event_spec.rb @@ -74,8 +74,8 @@ describe "#dates" do it "should return range between start_date and end_date" do - start_date = Date.today + 1.week - end_date = Date.today + 2.weeks + start_date = Time.now.utc.to_date + 1.week + end_date = Time.now.utc.to_date + 2.weeks event = Event.new(:start_date => start_date, :end_date => end_date) event.dates.should == (start_date..end_date).to_a diff --git a/spec/models/proposal_spec.rb b/spec/models/proposal_spec.rb index a116b77e..1e156aa9 100644 --- a/spec/models/proposal_spec.rb +++ b/spec/models/proposal_spec.rb @@ -286,9 +286,18 @@ describe "to_icalendar" do def assert_calendar_match(item, component, url_helper=nil) component.should_not be_nil - component.dtstart.to_i.should == item.start_time.to_i + + # This is hacky, but necessary because vPim doesn't actually parse + # time zone information out of iCalendar files. + # + # The files are output with the correct time zone, but seem to be + # parsed in the computer's local time, regardless of the Rails + # time zone setting. + dtstart = Time.parse(component.dtstart.strftime('%Y-%m-%d %H:%M:%S UTC')) + dtstart.to_i.should == item.start_time.to_i if item.duration - component.dtend.to_i.should == item.end_time.to_i + dtend = Time.parse(component.dtend.strftime('%Y-%m-%d %H:%M:%S UTC')) + dtend.to_i.should == item.end_time.to_i else component.dtend.should be_nil end