Commit 0e90eba37e6bd391cc44ce2ee49b32ab93af353d

Authored by Cyril Mougel
1 parent d9438486
Exists in master and in 1 other branch production

Allow create a Problem without ErrorClass

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