Commit 17c9c54fc08559c456d16abeccf60b3d9bcf27e7
Committed by
Robert Lail
1 parent
edaa7791
Exists in
master
and in
1 other branch
Added first_notice_at timestamp to Problem
Showing
2 changed files
with
19 additions
and
1 deletions
Show diff stats
app/models/problem.rb
| ... | ... | @@ -7,6 +7,7 @@ class Problem |
| 7 | 7 | include Mongoid::Timestamps |
| 8 | 8 | |
| 9 | 9 | field :last_notice_at, :type => DateTime |
| 10 | + field :first_notice_at, :type => DateTime | |
| 10 | 11 | field :last_deploy_at, :type => Time |
| 11 | 12 | field :resolved, :type => Boolean, :default => false |
| 12 | 13 | field :resolved_at, :type => Time |
| ... | ... | @@ -29,6 +30,7 @@ class Problem |
| 29 | 30 | index :app_name |
| 30 | 31 | index :message |
| 31 | 32 | index :last_notice_at |
| 33 | + index :first_notice_at | |
| 32 | 34 | index :last_deploy_at |
| 33 | 35 | index :notices_count |
| 34 | 36 | |
| ... | ... | @@ -126,7 +128,7 @@ class Problem |
| 126 | 128 | |
| 127 | 129 | def cache_notice_attributes(notice=nil) |
| 128 | 130 | notice ||= notices.first |
| 129 | - attrs = {:last_notice_at => notices.order_by([:created_at, :asc]).last.try(:created_at)} | |
| 131 | + attrs = {:last_notice_at => notices.order_by([:created_at, :asc]).last.try(:created_at), :first_notice_at => notices.order_by([:created_at, :asc]).first.try(:created_at)} | |
| 130 | 132 | attrs.merge!( |
| 131 | 133 | :message => notice.message, |
| 132 | 134 | :environment => notice.environment_name, | ... | ... |
spec/models/problem_spec.rb
| ... | ... | @@ -40,6 +40,22 @@ describe Problem do |
| 40 | 40 | end |
| 41 | 41 | end |
| 42 | 42 | |
| 43 | + context '#first_notice_at' do | |
| 44 | + it "returns the created_at timestamp of the first notice" do | |
| 45 | + err = Fabricate(:err) | |
| 46 | + problem = err.problem | |
| 47 | + problem.should_not be_nil | |
| 48 | + | |
| 49 | + problem.first_notice_at.should be_nil | |
| 50 | + | |
| 51 | + notice1 = Fabricate(:notice, :err => err) | |
| 52 | + problem.first_notice_at.should == notice1.created_at | |
| 53 | + | |
| 54 | + notice2 = Fabricate(:notice, :err => err) | |
| 55 | + problem.first_notice_at.should == notice1.created_at | |
| 56 | + end | |
| 57 | + end | |
| 58 | + | |
| 43 | 59 | |
| 44 | 60 | context '#message' do |
| 45 | 61 | it "adding a notice caches its message" do | ... | ... |