Commit edaa779134d18f3993be830c163d0acb2aa50f99
Committed by
Robert Lail
1 parent
f6c22e88
Exists in
master
and in
1 other branch
Added resolved_at timestamp to Problem
Showing
4 changed files
with
14 additions
and
1 deletions
Show diff stats
Gemfile
| @@ -58,6 +58,7 @@ group :test do | @@ -58,6 +58,7 @@ group :test do | ||
| 58 | gem 'rspec', '~> 2.6' | 58 | gem 'rspec', '~> 2.6' |
| 59 | gem 'database_cleaner', '~> 0.6.0' | 59 | gem 'database_cleaner', '~> 0.6.0' |
| 60 | gem 'email_spec' | 60 | gem 'email_spec' |
| 61 | + gem 'timecop' | ||
| 61 | end | 62 | end |
| 62 | 63 | ||
| 63 | group :heroku do | 64 | group :heroku do |
Gemfile.lock
| @@ -260,6 +260,7 @@ GEM | @@ -260,6 +260,7 @@ GEM | ||
| 260 | rack (>= 1.0.0) | 260 | rack (>= 1.0.0) |
| 261 | thor (0.15.4) | 261 | thor (0.15.4) |
| 262 | tilt (1.3.3) | 262 | tilt (1.3.3) |
| 263 | + timecop (0.3.5) | ||
| 263 | treetop (1.4.10) | 264 | treetop (1.4.10) |
| 264 | polyglot | 265 | polyglot |
| 265 | polyglot (>= 0.3.1) | 266 | polyglot (>= 0.3.1) |
| @@ -323,6 +324,7 @@ DEPENDENCIES | @@ -323,6 +324,7 @@ DEPENDENCIES | ||
| 323 | ruby-fogbugz | 324 | ruby-fogbugz |
| 324 | therubyracer | 325 | therubyracer |
| 325 | thin | 326 | thin |
| 327 | + timecop | ||
| 326 | uglifier (>= 1.0.3) | 328 | uglifier (>= 1.0.3) |
| 327 | unicorn | 329 | unicorn |
| 328 | useragent (~> 0.3.1) | 330 | useragent (~> 0.3.1) |
app/models/problem.rb
| @@ -9,6 +9,7 @@ class Problem | @@ -9,6 +9,7 @@ class Problem | ||
| 9 | field :last_notice_at, :type => DateTime | 9 | field :last_notice_at, :type => DateTime |
| 10 | field :last_deploy_at, :type => Time | 10 | field :last_deploy_at, :type => Time |
| 11 | field :resolved, :type => Boolean, :default => false | 11 | field :resolved, :type => Boolean, :default => false |
| 12 | + field :resolved_at, :type => Time | ||
| 12 | field :issue_link, :type => String | 13 | field :issue_link, :type => String |
| 13 | field :issue_type, :type => String | 14 | field :issue_type, :type => String |
| 14 | 15 | ||
| @@ -52,7 +53,7 @@ class Problem | @@ -52,7 +53,7 @@ class Problem | ||
| 52 | end | 53 | end |
| 53 | 54 | ||
| 54 | def resolve! | 55 | def resolve! |
| 55 | - self.update_attributes!(:resolved => true, :notices_count => 0) | 56 | + self.update_attributes!(:resolved => true, :resolved_at => Time.now, :notices_count => 0) |
| 56 | end | 57 | end |
| 57 | 58 | ||
| 58 | def unresolve! | 59 | def unresolve! |
spec/models/problem_spec.rb
| @@ -87,6 +87,15 @@ describe Problem do | @@ -87,6 +87,15 @@ describe Problem do | ||
| 87 | problem.should be_resolved | 87 | problem.should be_resolved |
| 88 | end | 88 | end |
| 89 | 89 | ||
| 90 | + it "should record the time when it was resolved" do | ||
| 91 | + problem = Fabricate(:problem) | ||
| 92 | + expected_resolved_at = Time.now | ||
| 93 | + Timecop.freeze(expected_resolved_at) do | ||
| 94 | + problem.resolve! | ||
| 95 | + end | ||
| 96 | + problem.resolved_at.to_s.should == expected_resolved_at.to_s | ||
| 97 | + end | ||
| 98 | + | ||
| 90 | it "should throw an err if it's not successful" do | 99 | it "should throw an err if it's not successful" do |
| 91 | problem = Fabricate(:problem) | 100 | problem = Fabricate(:problem) |
| 92 | problem.should_not be_resolved | 101 | problem.should_not be_resolved |