Skip to content
This repository
Browse code

Replace assert with rspec matcher so we can see output. A few more Ti…

…me.zone fixes
  • Loading branch information...
commit d1c56566ef57fdb1449c4b301252e5de17b52b8f 1 parent 6326569
Damian Martinez porcupie authored
3  app/controllers/application_controller.rb
@@ -2,6 +2,7 @@ module ActiveSupport
2 2 class TimeWithZone
3 3 def zone=(new_zone = ::Time.zone)
4 4 # Reinitialize with the new zone and the local time
  5 + # FIXME: ::Time has no .get_zone ?
5 6 initialize(nil, ::Time.__send__(:get_zone, new_zone), time)
6 7 end
7 8 end
@@ -34,7 +35,7 @@ def force_ssl
34 35
35 36 def set_tz_offset(attr)
36 37 if params[attr] && params[attr][:starts_at]
37   - params[attr][:timezone_offset] = DateTime.parse(params[attr][:starts_at]).utc_offset
  38 + params[attr][:timezone_offset] = Time.zone.parse(params[attr][:starts_at]).utc_offset
38 39 end
39 40 end
40 41 end
4 app/models/call_list.rb
@@ -59,7 +59,7 @@ def notification_users
59 59 [owners, escalations].compact.flatten.uniq
60 60 end
61 61
62   - def in_business_hours?(now = Time.now)
  62 + def in_business_hours?(now = Time.zone.now)
63 63 return false if business_hours.nil? or business_hours.empty?
64 64
65 65 now = now.in_time_zone(business_time_zone)
@@ -122,7 +122,7 @@ def gen_oncall_assignments(start_date = nil, w = AppConfig.oncall_assignments_ge
122 122 raise "Need to enable automatic oncall assignments feature" unless oncall_assignments_gen && oncall_assignments_gen.enable == true
123 123 raise "No available oncall candidate" if oncall_candidates.blank?
124 124
125   - start_date ||= oncall_assignments_gen.last_gen || Time.now.utc
  125 + start_date ||= oncall_assignments_gen.last_gen || Time.zone.now.utc
126 126 end_date = Ringring::OncallAssignmentsGenerator::next_oncall_cycle(start_date, oncall_assignments_gen.cycle_day)
127 127 end_date = end_date.change(:hour => oncall_assignments_gen.cycle_time.hour, :min => oncall_assignments_gen.cycle_time.min)
128 128 #end_date -= oncall_assignments_gen.timezone_offset if end_date.utc_offset == 0
2  app/models/user.rb
@@ -61,7 +61,7 @@ def old_sms_email
61 61 end
62 62
63 63 def on_vacation?
64   - now = Time.now
  64 + now = Time.zone.now
65 65 vacations.each do |vacation|
66 66 return true if vacation.starts_at <= now && now <= vacation.ends_at
67 67 end
12 spec/models/call_list_spec.rb
@@ -167,18 +167,18 @@
167 167 it "correctly determines if in business hour for UTC time" do
168 168 call_list = CallList.make!(:business_time_zone => 'UTC', :twilio_list_id => (rand(2132)).to_i)
169 169 (0..6).each do |wday|
170   - call_list.business_hours.create(:wday => wday, :start_time => Time.parse("8:00 AM +0000"),
171   - :end_time => Time.parse("8:00 PM +0000"))
  170 + call_list.business_hours.create(:wday => wday, :start_time => Time.zone.parse("8:00 AM +0000"),
  171 + :end_time => Time.zone.parse("8:00 PM +0000"))
172 172 end
173   - call_list.in_business_hours?(Time.parse("9:00 AM +0000")).should be_true
  173 + call_list.in_business_hours?(Time.zone.parse("9:00 AM +0000")).should be_true
174 174 end
175 175 it "correctly determines if in business hour for non UTC time" do
176 176 call_list = CallList.make!(:business_time_zone => 'Arizona', :twilio_list_id => (rand(2132)).to_i)
177 177 (0..6).each do |wday|
178   - call_list.business_hours.create(:wday => wday, :start_time => Time.parse("8:00 AM -0700"),
179   - :end_time => Time.parse("8:00 PM -0700"))
  178 + call_list.business_hours.create(:wday => wday, :start_time => Time.zone.parse("8:00 AM -0700"),
  179 + :end_time => Time.zone.parse("8:00 PM -0700"))
180 180 end
181   - call_list.in_business_hours?(Time.parse("9:00 AM -0700")).should be_true
  181 + call_list.in_business_hours?(Time.zone.parse("9:00 AM -0700")).should be_true
182 182 end
183 183 end
184 184
4 spec/requests/call_lists_spec.rb
@@ -72,8 +72,8 @@
72 72
73 73 # No longer valid since business time has its own time zone now
74 74 actual_time = CallList.find(call_list_id).business_hours.first.start_time.in_time_zone('Mountain Time (US & Canada)')
75   - utc_time = Time.parse('9:15 UTC')
76   - assert actual_time == utc_time - actual_time.utc_offset
  75 + utc_time = Time.zone.parse('9:15 UTC')
  76 + actual_time.should == utc_time - actual_time.utc_offset
77 77 end
78 78 end
79 79

0 comments on commit d1c5656

Please sign in to comment.
Something went wrong with that request. Please try again.