From 17c9c54fc08559c456d16abeccf60b3d9bcf27e7 Mon Sep 17 00:00:00 2001 From: Jesse Lewis Date: Wed, 22 Aug 2012 14:55:58 -0500 Subject: [PATCH] Added first_notice_at timestamp to Problem --- app/models/problem.rb | 4 +++- spec/models/problem_spec.rb | 16 ++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/app/models/problem.rb b/app/models/problem.rb index c570356..22561f4 100644 --- a/app/models/problem.rb +++ b/app/models/problem.rb @@ -7,6 +7,7 @@ class Problem include Mongoid::Timestamps field :last_notice_at, :type => DateTime + field :first_notice_at, :type => DateTime field :last_deploy_at, :type => Time field :resolved, :type => Boolean, :default => false field :resolved_at, :type => Time @@ -29,6 +30,7 @@ class Problem index :app_name index :message index :last_notice_at + index :first_notice_at index :last_deploy_at index :notices_count @@ -126,7 +128,7 @@ class Problem def cache_notice_attributes(notice=nil) notice ||= notices.first - attrs = {:last_notice_at => notices.order_by([:created_at, :asc]).last.try(:created_at)} + 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)} attrs.merge!( :message => notice.message, :environment => notice.environment_name, diff --git a/spec/models/problem_spec.rb b/spec/models/problem_spec.rb index 1bc4797..eb389f8 100644 --- a/spec/models/problem_spec.rb +++ b/spec/models/problem_spec.rb @@ -40,6 +40,22 @@ describe Problem do end end + context '#first_notice_at' do + it "returns the created_at timestamp of the first notice" do + err = Fabricate(:err) + problem = err.problem + problem.should_not be_nil + + problem.first_notice_at.should be_nil + + notice1 = Fabricate(:notice, :err => err) + problem.first_notice_at.should == notice1.created_at + + notice2 = Fabricate(:notice, :err => err) + problem.first_notice_at.should == notice1.created_at + end + end + context '#message' do it "adding a notice caches its message" do -- libgit2 0.21.2