From 3052c8d70c933e76d8d2e1fc4cc08d541733027b Mon Sep 17 00:00:00 2001 From: Jared Pace Date: Tue, 3 Aug 2010 17:51:30 -0500 Subject: [PATCH] Track the last notice time for an error --- app/models/error.rb | 4 ++++ spec/models/error_spec.rb | 13 +++++++++++++ 2 files changed, 17 insertions(+), 0 deletions(-) diff --git a/app/models/error.rb b/app/models/error.rb index a57c3a5..c1d62f5 100644 --- a/app/models/error.rb +++ b/app/models/error.rb @@ -16,4 +16,8 @@ class Error self.where(attrs).first || create(attrs) end + def last_notice_at + notices.last.try(:created_at) + end + end \ No newline at end of file diff --git a/spec/models/error_spec.rb b/spec/models/error_spec.rb index 104a38d..12cca9a 100644 --- a/spec/models/error_spec.rb +++ b/spec/models/error_spec.rb @@ -40,4 +40,17 @@ describe Error do end end + context '#last_notice_at' do + it "returns the created_at timestamp of the latest notice" do + error = Factory(:error) + error.last_notice_at.should be_nil + + notice1 = Factory(:notice, :error => error) + error.last_notice_at.should == notice1.created_at + + notice2 = Factory(:notice, :error => error) + error.last_notice_at.should == notice2.created_at + end + end + end \ No newline at end of file -- libgit2 0.21.2