Commit 3052c8d70c933e76d8d2e1fc4cc08d541733027b
1 parent
d4e46b3d
Exists in
master
and in
1 other branch
Track the last notice time for an error
Showing
2 changed files
with
17 additions
and
0 deletions
Show diff stats
app/models/error.rb
| @@ -16,4 +16,8 @@ class Error | @@ -16,4 +16,8 @@ class Error | ||
| 16 | self.where(attrs).first || create(attrs) | 16 | self.where(attrs).first || create(attrs) |
| 17 | end | 17 | end |
| 18 | 18 | ||
| 19 | + def last_notice_at | ||
| 20 | + notices.last.try(:created_at) | ||
| 21 | + end | ||
| 22 | + | ||
| 19 | end | 23 | end |
| 20 | \ No newline at end of file | 24 | \ No newline at end of file |
spec/models/error_spec.rb
| @@ -40,4 +40,17 @@ describe Error do | @@ -40,4 +40,17 @@ describe Error do | ||
| 40 | end | 40 | end |
| 41 | end | 41 | end |
| 42 | 42 | ||
| 43 | + context '#last_notice_at' do | ||
| 44 | + it "returns the created_at timestamp of the latest notice" do | ||
| 45 | + error = Factory(:error) | ||
| 46 | + error.last_notice_at.should be_nil | ||
| 47 | + | ||
| 48 | + notice1 = Factory(:notice, :error => error) | ||
| 49 | + error.last_notice_at.should == notice1.created_at | ||
| 50 | + | ||
| 51 | + notice2 = Factory(:notice, :error => error) | ||
| 52 | + error.last_notice_at.should == notice2.created_at | ||
| 53 | + end | ||
| 54 | + end | ||
| 55 | + | ||
| 43 | end | 56 | end |
| 44 | \ No newline at end of file | 57 | \ No newline at end of file |