Commit 0e90eba37e6bd391cc44ce2ee49b32ab93af353d
1 parent
d9438486
Exists in
master
and in
1 other branch
Allow create a Problem without ErrorClass
Fix #219
Showing
3 changed files
with
26 additions
and
25 deletions
Show diff stats
app/models/problem.rb
... | ... | @@ -39,7 +39,7 @@ class Problem |
39 | 39 | has_many :errs, :inverse_of => :problem, :dependent => :destroy |
40 | 40 | has_many :comments, :inverse_of => :err, :dependent => :destroy |
41 | 41 | |
42 | - validates_presence_of :error_class, :environment | |
42 | + validates_presence_of :environment | |
43 | 43 | |
44 | 44 | before_create :cache_app_attributes |
45 | 45 | ... | ... |
spec/models/app_spec.rb
... | ... | @@ -158,31 +158,44 @@ describe App do |
158 | 158 | |
159 | 159 | |
160 | 160 | context '#find_or_create_err!' do |
161 | - before do | |
162 | - @app = Fabricate(:app) | |
163 | - @conditions = { | |
161 | + let(:app) { Fabricate(:app) } | |
162 | + let(:conditions) { { | |
164 | 163 | :error_class => 'Whoops', |
165 | 164 | :environment => 'production', |
166 | 165 | :fingerprint => 'some-finger-print' |
167 | 166 | } |
168 | - end | |
167 | + } | |
169 | 168 | |
170 | 169 | it 'returns the correct err if one already exists' do |
171 | - existing = Fabricate(:err, @conditions.merge(:problem => Fabricate(:problem, :app => @app))) | |
172 | - Err.where(@conditions).first.should == existing | |
173 | - @app.find_or_create_err!(@conditions).should == existing | |
170 | + existing = Fabricate(:err, conditions.merge(:problem => Fabricate(:problem, :app => app))) | |
171 | + Err.where(conditions).first.should == existing | |
172 | + app.find_or_create_err!(conditions).should == existing | |
174 | 173 | end |
175 | 174 | |
176 | 175 | it 'assigns the returned err to the given app' do |
177 | - @app.find_or_create_err!(@conditions).app.should == @app | |
176 | + app.find_or_create_err!(conditions).app.should == app | |
178 | 177 | end |
179 | 178 | |
180 | 179 | it 'creates a new problem if a matching one does not already exist' do |
181 | - Err.where(@conditions).first.should be_nil | |
180 | + Err.where(conditions).first.should be_nil | |
182 | 181 | lambda { |
183 | - @app.find_or_create_err!(@conditions) | |
182 | + app.find_or_create_err!(conditions) | |
184 | 183 | }.should change(Problem,:count).by(1) |
185 | 184 | end |
185 | + | |
186 | + context "without error_class" do | |
187 | + let(:conditions) { { | |
188 | + :environment => 'production', | |
189 | + :fingerprint => 'some-finger-print' | |
190 | + } | |
191 | + } | |
192 | + it 'save the err' do | |
193 | + Err.where(conditions).first.should be_nil | |
194 | + lambda { | |
195 | + app.find_or_create_err!(conditions) | |
196 | + }.should change(Problem,:count).by(1) | |
197 | + end | |
198 | + end | |
186 | 199 | end |
187 | 200 | |
188 | 201 | ... | ... |
spec/models/problem_spec.rb
1 | 1 | require 'spec_helper' |
2 | 2 | |
3 | 3 | describe Problem do |
4 | - | |
5 | - context 'validations' do | |
6 | - it 'requires a error_class' do | |
7 | - err = Fabricate.build(:problem, :error_class => nil) | |
8 | - err.should_not be_valid | |
9 | - err.errors[:error_class].should include("can't be blank") | |
10 | - end | |
11 | 4 | |
5 | + context 'validations' do | |
12 | 6 | it 'requires an environment' do |
13 | 7 | err = Fabricate.build(:problem, :environment => nil) |
14 | 8 | err.should_not be_valid |
15 | 9 | err.errors[:environment].should include("can't be blank") |
16 | 10 | end |
17 | 11 | end |
18 | - | |
12 | + | |
19 | 13 | describe "Fabrication" do |
20 | 14 | context "Fabricate(:problem)" do |
21 | 15 | it 'should have no comment' do |
... | ... | @@ -70,7 +64,6 @@ describe Problem do |
70 | 64 | end |
71 | 65 | end |
72 | 66 | |
73 | - | |
74 | 67 | context '#message' do |
75 | 68 | it "adding a notice caches its message" do |
76 | 69 | err = Fabricate(:err) |
... | ... | @@ -81,7 +74,6 @@ describe Problem do |
81 | 74 | end |
82 | 75 | end |
83 | 76 | |
84 | - | |
85 | 77 | context 'being created' do |
86 | 78 | context 'when the app has err notifications set to false' do |
87 | 79 | it 'should not send an email notification' do |
... | ... | @@ -92,7 +84,6 @@ describe Problem do |
92 | 84 | end |
93 | 85 | end |
94 | 86 | |
95 | - | |
96 | 87 | context "#resolved?" do |
97 | 88 | it "should start out as unresolved" do |
98 | 89 | problem = Problem.new |
... | ... | @@ -108,7 +99,6 @@ describe Problem do |
108 | 99 | end |
109 | 100 | end |
110 | 101 | |
111 | - | |
112 | 102 | context "resolve!" do |
113 | 103 | it "marks the problem as resolved" do |
114 | 104 | problem = Fabricate(:problem) |
... | ... | @@ -198,7 +188,6 @@ describe Problem do |
198 | 188 | end |
199 | 189 | end |
200 | 190 | |
201 | - | |
202 | 191 | context "notice counter cache" do |
203 | 192 | before do |
204 | 193 | @app = Fabricate(:app) |
... | ... | @@ -225,7 +214,6 @@ describe Problem do |
225 | 214 | end |
226 | 215 | end |
227 | 216 | |
228 | - | |
229 | 217 | context "#app_name" do |
230 | 218 | let!(:app) { Fabricate(:app) } |
231 | 219 | let!(:problem) { Fabricate(:problem, :app => app) } | ... | ... |