err_spec.rb
2.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
require 'spec_helper'
describe Err do
context 'validations' do
it 'requires a klass' do
error = Factory.build(:err, :klass => nil)
error.should_not be_valid
error.errors[:klass].should include("can't be blank")
end
it 'requires an environment' do
error = Factory.build(:err, :environment => nil)
error.should_not be_valid
error.errors[:environment].should include("can't be blank")
end
end
context '#for' do
before do
@project = Factory(:project)
@conditions = {
:project => @project,
:klass => 'Whoops',
:message => 'Whoops: Oopsy Daisy',
:component => 'Foo',
:action => 'bar',
:environment => 'production'
}
end
it 'returns the correct error if one already exists' do
existing = Err.create(@conditions)
Err.for(@conditions).should == existing
end
it 'assigns the returned error to the given project' do
Err.for(@conditions).project.should == @project
end
it 'creates a new error if a matching one does not already exist' do
Err.where(@conditions.except(:project)).exists?.should == false
lambda {
Err.for(@conditions)
}.should change(Err,:count).by(1)
end
end
context '#last_notice_at' do
it "returns the created_at timestamp of the latest notice" do
error = Factory(:err)
error.last_notice_at.should be_nil
notice1 = Factory(:notice, :err => error)
error.last_notice_at.should == notice1.created_at
notice2 = Factory(:notice, :err => error)
error.last_notice_at.should == notice2.created_at
end
end
context "#resolved?" do
it "should start out as unresolved" do
error = Err.new
error.should_not be_resolved
error.should be_unresolved
end
it "should be able to be resolved" do
error = Factory(:err)
error.should_not be_resolved
error.resolve!
error.reload.should be_resolved
end
end
end