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 94 end
95 95  
96 96 def last_deploy_at
97   - deploys.last && deploys.last.created_at
  97 + (last_deploy = deploys.last) && last_deploy.created_at
98 98 end
99 99  
100 100  
... ...
app/models/problem.rb
... ... @@ -109,7 +109,9 @@ class Problem
109 109 def cache_app_attributes
110 110 if app
111 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 115 self.save if persisted?
114 116 end
115 117 end
... ...
spec/models/problem_spec.rb
... ... @@ -180,16 +180,16 @@ describe Problem do
180 180 before do
181 181 @app = Factory(:app)
182 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 184 end
185 185  
186 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 188 assert_equal @last_deploy, problem.last_deploy_at
189 189 end
190 190  
191 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 193 next_deploy = 5.minutes.ago.localtime.round(0)
194 194 lambda {
195 195 @deploy = Factory(:deploy, :app => @app, :created_at => next_deploy)
... ...