Commit cf1668265c287deba85b41c7938d7a21b466eb2d
1 parent
5ac87c8d
Exists in
master
and in
1 other branch
Extract test from spec/model/app to spec/model/error_report
Some test on spec/model/app are too specific to spec/model/error_report move to this spec
Showing
3 changed files
with
86 additions
and
84 deletions
Show diff stats
app/models/app.rb
... | ... | @@ -81,7 +81,10 @@ class App |
81 | 81 | end |
82 | 82 | |
83 | 83 | def find_or_create_err!(attrs) |
84 | - Err.where(:fingerprint => attrs[:fingerprint]).first || problems.create!.errs.create!(attrs) | |
84 | + Err.where( | |
85 | + :fingerprint => attrs[:fingerprint] | |
86 | + ).first || | |
87 | + problems.create!.errs.create!(attrs) | |
85 | 88 | end |
86 | 89 | |
87 | 90 | # Mongoid Bug: find(id) on association proxies returns an Enumerator | ... | ... |
spec/models/app_spec.rb
... | ... | @@ -195,76 +195,6 @@ describe App do |
195 | 195 | ErrorReport.any_instance.stub(:fingerprint).and_return('fingerprintdigest') |
196 | 196 | end |
197 | 197 | |
198 | - it 'finds the correct app' do | |
199 | - @notice = App.report_error!(@xml) | |
200 | - @notice.err.app.should == @app | |
201 | - end | |
202 | - | |
203 | - it 'finds the correct err for the notice' do | |
204 | - App.should_receive(:find_by_api_key!).and_return(@app) | |
205 | - @app.should_receive(:find_or_create_err!).with({ | |
206 | - :error_class => 'HoptoadTestingException', | |
207 | - :component => 'application', | |
208 | - :action => 'verify', | |
209 | - :environment => 'development', | |
210 | - :fingerprint => 'fingerprintdigest' | |
211 | - }).and_return(err = Fabricate(:err)) | |
212 | - err.notices.stub(:create!) | |
213 | - @notice = App.report_error!(@xml) | |
214 | - end | |
215 | - | |
216 | - it 'marks the err as unresolved if it was previously resolved' do | |
217 | - App.should_receive(:find_by_api_key!).and_return(@app) | |
218 | - @app.should_receive(:find_or_create_err!).with({ | |
219 | - :error_class => 'HoptoadTestingException', | |
220 | - :component => 'application', | |
221 | - :action => 'verify', | |
222 | - :environment => 'development', | |
223 | - :fingerprint => 'fingerprintdigest' | |
224 | - }).and_return(err = Fabricate(:err, :problem => Fabricate(:problem, :resolved => true))) | |
225 | - err.should be_resolved | |
226 | - @notice = App.report_error!(@xml) | |
227 | - @notice.err.should == err | |
228 | - @notice.err.should_not be_resolved | |
229 | - end | |
230 | - | |
231 | - it 'should create a new notice' do | |
232 | - @notice = App.report_error!(@xml) | |
233 | - @notice.should be_persisted | |
234 | - end | |
235 | - | |
236 | - it 'assigns an err to the notice' do | |
237 | - @notice = App.report_error!(@xml) | |
238 | - @notice.err.should be_a(Err) | |
239 | - end | |
240 | - | |
241 | - it 'captures the err message' do | |
242 | - @notice = App.report_error!(@xml) | |
243 | - @notice.message.should == 'HoptoadTestingException: Testing hoptoad via "rake hoptoad:test". If you can see this, it works.' | |
244 | - end | |
245 | - | |
246 | - it 'captures the backtrace' do | |
247 | - @notice = App.report_error!(@xml) | |
248 | - @notice.backtrace_lines.size.should == 73 | |
249 | - @notice.backtrace_lines.last['file'].should == '[GEM_ROOT]/bin/rake' | |
250 | - end | |
251 | - | |
252 | - it 'captures the server_environment' do | |
253 | - @notice = App.report_error!(@xml) | |
254 | - @notice.server_environment['environment-name'].should == 'development' | |
255 | - end | |
256 | - | |
257 | - it 'captures the request' do | |
258 | - @notice = App.report_error!(@xml) | |
259 | - @notice.request['url'].should == 'http://example.org/verify' | |
260 | - @notice.request['params']['controller'].should == 'application' | |
261 | - end | |
262 | - | |
263 | - it 'captures the notifier' do | |
264 | - @notice = App.report_error!(@xml) | |
265 | - @notice.notifier['name'].should == 'Hoptoad Notifier' | |
266 | - end | |
267 | - | |
268 | 198 | it "should handle params without 'request' section" do |
269 | 199 | xml = Rails.root.join('spec','fixtures','hoptoad_test_notice_without_request_section.xml').read |
270 | 200 | lambda { App.report_error!(xml) }.should_not raise_error |
... | ... | @@ -276,18 +206,6 @@ describe App do |
276 | 206 | @notice.backtrace_lines.length.should == 1 |
277 | 207 | end |
278 | 208 | |
279 | - it 'captures the current_user' do | |
280 | - @notice = App.report_error!(@xml) | |
281 | - @notice.user_attributes['id'].should == '123' | |
282 | - @notice.user_attributes['name'].should == 'Mr. Bean' | |
283 | - @notice.user_attributes['email'].should == 'mr.bean@example.com' | |
284 | - @notice.user_attributes['username'].should == 'mrbean' | |
285 | - end | |
286 | - | |
287 | - it 'captures the framework' do | |
288 | - @notice = App.report_error!(@xml) | |
289 | - @notice.framework.should == 'Rails: 3.2.11' | |
290 | - end | |
291 | 209 | |
292 | 210 | end |
293 | 211 | ... | ... |
spec/models/error_report_spec.rb
... | ... | @@ -3,7 +3,7 @@ require 'spec_helper' |
3 | 3 | describe ErrorReport do |
4 | 4 | context "with notice without line of backtrace" do |
5 | 5 | let(:xml){ |
6 | - Rails.root.join('spec','fixtures','hoptoad_test_notice_with_one_line_of_backtrace.xml').read | |
6 | + Rails.root.join('spec','fixtures','hoptoad_test_notice.xml').read | |
7 | 7 | } |
8 | 8 | |
9 | 9 | let(:error_report) { |
... | ... | @@ -17,6 +17,12 @@ describe ErrorReport do |
17 | 17 | ) |
18 | 18 | } |
19 | 19 | |
20 | + describe "#app" do | |
21 | + it 'find the good app' do | |
22 | + expect(error_report.app).to eq app | |
23 | + end | |
24 | + end | |
25 | + | |
20 | 26 | describe "#backtrace" do |
21 | 27 | |
22 | 28 | it 'should have valid backtrace' do |
... | ... | @@ -32,6 +38,41 @@ describe ErrorReport do |
32 | 38 | app.reload.problems.count |
33 | 39 | }.by(1) |
34 | 40 | end |
41 | + describe "notice create" do | |
42 | + before { error_report.generate_notice! } | |
43 | + subject { error_report.notice } | |
44 | + its(:message) { 'HoptoadTestingException: Testing hoptoad via "rake hoptoad:test". If you can see this, it works.' } | |
45 | + its(:framework) { should == 'Rails: 3.2.11' } | |
46 | + | |
47 | + it 'has complete backtrace' do | |
48 | + subject.backtrace_lines.size.should == 73 | |
49 | + subject.backtrace_lines.last['file'].should == '[GEM_ROOT]/bin/rake' | |
50 | + end | |
51 | + it 'has server_environement' do | |
52 | + subject.server_environment['environment-name'].should == 'development' | |
53 | + end | |
54 | + | |
55 | + it 'has request' do | |
56 | + subject.request['url'].should == 'http://example.org/verify' | |
57 | + subject.request['params']['controller'].should == 'application' | |
58 | + end | |
59 | + | |
60 | + it 'has notifier' do | |
61 | + subject.notifier['name'].should == 'Hoptoad Notifier' | |
62 | + end | |
63 | + | |
64 | + it 'get user_attributes' do | |
65 | + subject.user_attributes['id'].should == '123' | |
66 | + subject.user_attributes['name'].should == 'Mr. Bean' | |
67 | + subject.user_attributes['email'].should == 'mr.bean@example.com' | |
68 | + subject.user_attributes['username'].should == 'mrbean' | |
69 | + end | |
70 | + end | |
71 | + | |
72 | + it 'save a notice assignes to err' do | |
73 | + error_report.generate_notice! | |
74 | + error_report.notice.err.should be_a(Err) | |
75 | + end | |
35 | 76 | |
36 | 77 | it 'memoize the notice' do |
37 | 78 | expect { |
... | ... | @@ -41,6 +82,46 @@ describe ErrorReport do |
41 | 82 | Notice.count |
42 | 83 | }.by(1) |
43 | 84 | end |
85 | + | |
86 | + it 'find the correct err for the notice' do | |
87 | + Fabricate( | |
88 | + :err, { | |
89 | + :fingerprint => 'eeb6cc484167899c061e7859008c4b23bae0851c', | |
90 | + :problem => Fabricate(:problem, :resolved => true) | |
91 | + } | |
92 | + ) | |
93 | + expect { | |
94 | + error_report.generate_notice! | |
95 | + }.to change { | |
96 | + error_report.error.resolved? | |
97 | + }.from(true).to(false) | |
98 | + end | |
99 | + | |
100 | + context "with xml without request section" do | |
101 | + let(:xml){ | |
102 | + Rails.root.join('spec','fixtures','hoptoad_test_notice_without_request_section.xml').read | |
103 | + } | |
104 | + it "save a notice" do | |
105 | + expect { | |
106 | + error_report.generate_notice! | |
107 | + }.to change { | |
108 | + app.reload.problems.count | |
109 | + }.by(1) | |
110 | + end | |
111 | + end | |
112 | + | |
113 | + context "with xml with only a single line of backtrace" do | |
114 | + let(:xml){ | |
115 | + Rails.root.join('spec','fixtures','hoptoad_test_notice_with_one_line_of_backtrace.xml').read | |
116 | + } | |
117 | + it "save a notice" do | |
118 | + expect { | |
119 | + error_report.generate_notice! | |
120 | + }.to change { | |
121 | + app.reload.problems.count | |
122 | + }.by(1) | |
123 | + end | |
124 | + end | |
44 | 125 | end |
45 | 126 | |
46 | 127 | describe "#valid?" do | ... | ... |