Commit 126757c55717b2e3f41034c7e7f5ee40182bd963

Authored by Laust Rud Jacobsen
1 parent b76bf20a
Exists in master and in 1 other branch production

Rubocop: always use Time.zone.now, this fixes interesting time inconsistencies

.rubocop_todo.yml
... ... @@ -50,19 +50,6 @@ Rails/Output:
50 50 - 'app/interactors/problem_recacher.rb'
51 51 - 'db/seeds.rb'
52 52  
53   -# Offense count: 14
54   -# Configuration parameters: EnforcedStyle, SupportedStyles.
55   -Rails/TimeZone:
56   - Exclude:
57   - - 'app/models/problem.rb'
58   - - 'lib/tasks/errbit/demo.rake'
59   - - 'spec/controllers/api/v1/notices_controller_spec.rb'
60   - - 'spec/controllers/problems_controller_spec.rb'
61   - - 'spec/models/error_report_spec.rb'
62   - - 'spec/models/problem_spec.rb'
63   - - 'spec/views/apps/index.html.haml_spec.rb'
64   - - 'spec/views/users/show.html.haml_spec.rb'
65   -
66 53 # Offense count: 12
67 54 # Configuration parameters: Include.
68 55 Rails/Validation:
... ...
app/models/problem.rb
... ... @@ -13,8 +13,8 @@ class Problem
13 13 }.freeze
14 14  
15 15  
16   - field :last_notice_at, :type => ActiveSupport::TimeWithZone, :default => Proc.new { Time.now }
17   - field :first_notice_at, :type => ActiveSupport::TimeWithZone, :default => Proc.new { Time.now }
  16 + field :last_notice_at, :type => ActiveSupport::TimeWithZone, :default => Proc.new { Time.zone.now }
  17 + field :first_notice_at, :type => ActiveSupport::TimeWithZone, :default => Proc.new { Time.zone.now }
18 18 field :last_deploy_at, :type => Time
19 19 field :resolved, :type => Boolean, :default => false
20 20 field :resolved_at, :type => Time
... ... @@ -173,7 +173,7 @@ class Problem
173 173 end
174 174  
175 175 def resolve!
176   - self.update_attributes!(:resolved => true, :resolved_at => Time.now)
  176 + self.update_attributes!(:resolved => true, :resolved_at => Time.zone.now)
177 177 end
178 178  
179 179 def unresolve!
... ...
lib/tasks/errbit/demo.rake
... ... @@ -3,7 +3,7 @@ namespace :errbit do
3 3 task :demo => :environment do
4 4 require 'fabrication'
5 5  
6   - app = Fabricate(:app, :name => "Demo App #{Time.now.strftime("%N")}")
  6 + app = Fabricate(:app, :name => "Demo App #{Time.zone.now.strftime("%N")}")
7 7  
8 8 # Report a number of errors for the application
9 9 app.problems.delete_all
... ...
spec/controllers/api/v1/notices_controller_spec.rb
... ... @@ -6,10 +6,10 @@ describe Api::V1::NoticesController, type: 'controller' do
6 6  
7 7 describe "GET /api/v1/notices" do
8 8 before do
9   - Fabricate(:notice, :created_at => Time.new(2012, 8, 01))
10   - Fabricate(:notice, :created_at => Time.new(2012, 8, 01))
11   - Fabricate(:notice, :created_at => Time.new(2012, 8, 21))
12   - Fabricate(:notice, :created_at => Time.new(2012, 8, 30))
  9 + Fabricate(:notice, :created_at => Time.zone.parse('2012-08-01'))
  10 + Fabricate(:notice, :created_at => Time.zone.parse('2012-08-01'))
  11 + Fabricate(:notice, :created_at => Time.zone.parse('2012-08-21'))
  12 + Fabricate(:notice, :created_at => Time.zone.parse('2012-08-30'))
13 13 end
14 14  
15 15 it "should return JSON if JSON is requested" do
... ...
spec/controllers/problems_controller_spec.rb
... ... @@ -139,7 +139,7 @@ describe ProblemsController, type: 'controller' do
139 139 context 'pagination' do
140 140 let!(:notices) do
141 141 3.times.reduce([]) do |coll, i|
142   - coll << Fabricate(:notice, :err => err, :created_at => (Time.now + i))
  142 + coll << Fabricate(:notice, :err => err, :created_at => (i.seconds.from_now))
143 143 end
144 144 end
145 145  
... ...
spec/models/error_report_spec.rb
... ... @@ -156,7 +156,7 @@ describe ErrorReport do
156 156 error_report.generate_notice!
157 157 problem = error_report.problem
158 158 problem.update(
159   - resolved_at: Time.now,
  159 + resolved_at: Time.zone.now,
160 160 resolved: true
161 161 )
162 162  
... ...
spec/models/problem_spec.rb
... ... @@ -236,7 +236,7 @@ describe Problem, type: &#39;model&#39; do
236 236 context "#last_deploy_at" do
237 237 before do
238 238 @app = Fabricate(:app)
239   - @last_deploy = Time.at(10.days.ago.localtime.to_i)
  239 + @last_deploy = 10.days.ago
240 240 Fabricate(:deploy, :app => @app, :created_at => @last_deploy, :environment => "production")
241 241 end
242 242  
... ... @@ -247,11 +247,13 @@ describe Problem, type: &#39;model&#39; do
247 247  
248 248 it "is updated when a deploy is created" do
249 249 problem = Fabricate(:problem, :app => @app, :environment => "production")
250   - next_deploy = Time.at(5.minutes.ago.localtime.to_i)
  250 + next_deploy = 5.minutes.ago
251 251 expect {
252 252 @deploy = Fabricate(:deploy, :app => @app, :created_at => next_deploy)
253 253 problem.reload
254   - }.to change(problem, :last_deploy_at).from(@last_deploy).to(next_deploy)
  254 + }.to change { problem.last_deploy_at.iso8601 }.
  255 + from(@last_deploy.iso8601).
  256 + to(next_deploy.iso8601)
255 257 end
256 258 end
257 259  
... ...
spec/views/apps/index.html.haml_spec.rb
1 1 describe "apps/index.html.haml", type: 'view' do
2 2 before do
3   - app = stub_model(App, :deploys => [stub_model(Deploy, :created_at => Time.now, :revision => "123456789abcdef")])
  3 + app = stub_model(App, :deploys => [stub_model(Deploy, :created_at => Time.zone.now, :revision => "123456789abcdef")])
4 4 allow(view).to receive(:apps).and_return([app])
5 5 allow(controller).to receive(:current_user).and_return(stub_model(User))
6 6 end
... ...
spec/views/users/show.html.haml_spec.rb
1 1 describe 'users/show.html.haml', type: 'view' do
2 2 let(:user) do
3   - stub_model(User, :created_at => Time.now, :email => "test@example.com")
  3 + stub_model(User, :created_at => Time.zone.now, :email => "test@example.com")
4 4 end
5 5  
6 6 before do
... ...