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,19 +50,6 @@ Rails/Output:
50 - 'app/interactors/problem_recacher.rb' 50 - 'app/interactors/problem_recacher.rb'
51 - 'db/seeds.rb' 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 # Offense count: 12 53 # Offense count: 12
67 # Configuration parameters: Include. 54 # Configuration parameters: Include.
68 Rails/Validation: 55 Rails/Validation:
app/models/problem.rb
@@ -13,8 +13,8 @@ class Problem @@ -13,8 +13,8 @@ class Problem
13 }.freeze 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 field :last_deploy_at, :type => Time 18 field :last_deploy_at, :type => Time
19 field :resolved, :type => Boolean, :default => false 19 field :resolved, :type => Boolean, :default => false
20 field :resolved_at, :type => Time 20 field :resolved_at, :type => Time
@@ -173,7 +173,7 @@ class Problem @@ -173,7 +173,7 @@ class Problem
173 end 173 end
174 174
175 def resolve! 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 end 177 end
178 178
179 def unresolve! 179 def unresolve!
lib/tasks/errbit/demo.rake
@@ -3,7 +3,7 @@ namespace :errbit do @@ -3,7 +3,7 @@ namespace :errbit do
3 task :demo => :environment do 3 task :demo => :environment do
4 require 'fabrication' 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 # Report a number of errors for the application 8 # Report a number of errors for the application
9 app.problems.delete_all 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,10 +6,10 @@ describe Api::V1::NoticesController, type: 'controller' do
6 6
7 describe "GET /api/v1/notices" do 7 describe "GET /api/v1/notices" do
8 before do 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 end 13 end
14 14
15 it "should return JSON if JSON is requested" do 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,7 +139,7 @@ describe ProblemsController, type: 'controller' do
139 context 'pagination' do 139 context 'pagination' do
140 let!(:notices) do 140 let!(:notices) do
141 3.times.reduce([]) do |coll, i| 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 end 143 end
144 end 144 end
145 145
spec/models/error_report_spec.rb
@@ -156,7 +156,7 @@ describe ErrorReport do @@ -156,7 +156,7 @@ describe ErrorReport do
156 error_report.generate_notice! 156 error_report.generate_notice!
157 problem = error_report.problem 157 problem = error_report.problem
158 problem.update( 158 problem.update(
159 - resolved_at: Time.now, 159 + resolved_at: Time.zone.now,
160 resolved: true 160 resolved: true
161 ) 161 )
162 162
spec/models/problem_spec.rb
@@ -236,7 +236,7 @@ describe Problem, type: &#39;model&#39; do @@ -236,7 +236,7 @@ describe Problem, type: &#39;model&#39; do
236 context "#last_deploy_at" do 236 context "#last_deploy_at" do
237 before do 237 before do
238 @app = Fabricate(:app) 238 @app = Fabricate(:app)
239 - @last_deploy = Time.at(10.days.ago.localtime.to_i) 239 + @last_deploy = 10.days.ago
240 Fabricate(:deploy, :app => @app, :created_at => @last_deploy, :environment => "production") 240 Fabricate(:deploy, :app => @app, :created_at => @last_deploy, :environment => "production")
241 end 241 end
242 242
@@ -247,11 +247,13 @@ describe Problem, type: &#39;model&#39; do @@ -247,11 +247,13 @@ describe Problem, type: &#39;model&#39; do
247 247
248 it "is updated when a deploy is created" do 248 it "is updated when a deploy is created" do
249 problem = Fabricate(:problem, :app => @app, :environment => "production") 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 expect { 251 expect {
252 @deploy = Fabricate(:deploy, :app => @app, :created_at => next_deploy) 252 @deploy = Fabricate(:deploy, :app => @app, :created_at => next_deploy)
253 problem.reload 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 end 257 end
256 end 258 end
257 259
spec/views/apps/index.html.haml_spec.rb
1 describe "apps/index.html.haml", type: 'view' do 1 describe "apps/index.html.haml", type: 'view' do
2 before do 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 allow(view).to receive(:apps).and_return([app]) 4 allow(view).to receive(:apps).and_return([app])
5 allow(controller).to receive(:current_user).and_return(stub_model(User)) 5 allow(controller).to receive(:current_user).and_return(stub_model(User))
6 end 6 end
spec/views/users/show.html.haml_spec.rb
1 describe 'users/show.html.haml', type: 'view' do 1 describe 'users/show.html.haml', type: 'view' do
2 let(:user) do 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 end 4 end
5 5
6 before do 6 before do