Commit 0c5a386afd98b344e4ca15980307b1f170475160

Authored by Nathan Broadbent
1 parent 42789f67
Exists in master and in 1 other branch production

Fixed issue with different deploy environment dates not being separated for different problems

app/models/app.rb
@@ -94,7 +94,7 @@ class App @@ -94,7 +94,7 @@ class App
94 end 94 end
95 95
96 def last_deploy_at 96 def last_deploy_at
97 - deploys.last && deploys.last.created_at 97 + (last_deploy = deploys.last) && last_deploy.created_at
98 end 98 end
99 99
100 100
app/models/problem.rb
@@ -109,7 +109,9 @@ class Problem @@ -109,7 +109,9 @@ class Problem
109 def cache_app_attributes 109 def cache_app_attributes
110 if app 110 if app
111 self.app_name = app.name 111 self.app_name = app.name
112 - self.last_deploy_at = app.last_deploy_at 112 + self.last_deploy_at = if (last_deploy = app.deploys.where(:environment => self.environment).last)
  113 + last_deploy.created_at
  114 + end
113 self.save if persisted? 115 self.save if persisted?
114 end 116 end
115 end 117 end
spec/models/problem_spec.rb
@@ -180,16 +180,16 @@ describe Problem do @@ -180,16 +180,16 @@ describe Problem do
180 before do 180 before do
181 @app = Factory(:app) 181 @app = Factory(:app)
182 @last_deploy = 10.days.ago.localtime.round(0) 182 @last_deploy = 10.days.ago.localtime.round(0)
183 - deploy = Factory(:deploy, :app => @app, :created_at => @last_deploy) 183 + deploy = Factory(:deploy, :app => @app, :created_at => @last_deploy, :environment => "production")
184 end 184 end
185 185
186 it "is set when a problem is created" do 186 it "is set when a problem is created" do
187 - problem = Factory(:problem, :app => @app) 187 + problem = Factory(:problem, :app => @app, :environment => "production")
188 assert_equal @last_deploy, problem.last_deploy_at 188 assert_equal @last_deploy, problem.last_deploy_at
189 end 189 end
190 190
191 it "is updated when a deploy is created" do 191 it "is updated when a deploy is created" do
192 - problem = Factory(:problem, :app => @app) 192 + problem = Factory(:problem, :app => @app, :environment => "production")
193 next_deploy = 5.minutes.ago.localtime.round(0) 193 next_deploy = 5.minutes.ago.localtime.round(0)
194 lambda { 194 lambda {
195 @deploy = Factory(:deploy, :app => @app, :created_at => next_deploy) 195 @deploy = Factory(:deploy, :app => @app, :created_at => next_deploy)