Commit aef9896f211acdc2d967eaf287be82461204b54a
1 parent
6eb59b4e
Exists in
master
and in
1 other branch
Add some test to try report issue #470
Add some test with notice send with empty backtrace Add some test directly in the ErrorReport model
Showing
5 changed files
with
163 additions
and
7 deletions
Show diff stats
app/models/error_report.rb
@@ -44,19 +44,30 @@ class ErrorReport | @@ -44,19 +44,30 @@ class ErrorReport | ||
44 | :user_attributes => user_attributes, | 44 | :user_attributes => user_attributes, |
45 | :framework => framework | 45 | :framework => framework |
46 | ) | 46 | ) |
47 | + error.notices << notice | ||
48 | + notice | ||
49 | + end | ||
47 | 50 | ||
48 | - err = app.find_or_create_err!( | 51 | + ## |
52 | + # Error associate to this error_report | ||
53 | + # | ||
54 | + # Can already exist or not | ||
55 | + # | ||
56 | + # @return [ Error ] | ||
57 | + def error | ||
58 | + @error ||= app.find_or_create_err!( | ||
49 | :error_class => error_class, | 59 | :error_class => error_class, |
50 | :component => component, | 60 | :component => component, |
51 | :action => action, | 61 | :action => action, |
52 | :environment => rails_env, | 62 | :environment => rails_env, |
53 | - :fingerprint => fingerprint) | ||
54 | - | ||
55 | - err.notices << notice | ||
56 | - notice | 63 | + :fingerprint => fingerprint |
64 | + ) | ||
57 | end | 65 | end |
58 | 66 | ||
59 | private | 67 | private |
68 | + | ||
69 | + | ||
70 | + | ||
60 | def fingerprint_source | 71 | def fingerprint_source |
61 | # Find the first backtrace line with a file and line number. | 72 | # Find the first backtrace line with a file and line number. |
62 | if line = backtrace.lines.detect {|l| l.number.present? && l.file.present? } | 73 | if line = backtrace.lines.detect {|l| l.number.present? && l.file.present? } |
spec/controllers/notices_controller_spec.rb
@@ -24,13 +24,13 @@ describe NoticesController do | @@ -24,13 +24,13 @@ describe NoticesController do | ||
24 | response.body.should match(%r{<url[^>]*>(.+)#{locate_path(@notice.id)}</url>}) | 24 | response.body.should match(%r{<url[^>]*>(.+)#{locate_path(@notice.id)}</url>}) |
25 | end | 25 | end |
26 | 26 | ||
27 | - it "should trnasform xml <va> tags to hashes correctly" do | 27 | + it "should transform xml <va> tags to hashes correctly" do |
28 | App.should_receive(:report_error!).with(@xml).and_return(@notice) | 28 | App.should_receive(:report_error!).with(@xml).and_return(@notice) |
29 | request.should_receive(:raw_post).and_return(@xml) | 29 | request.should_receive(:raw_post).and_return(@xml) |
30 | post :create, :format => :xml | 30 | post :create, :format => :xml |
31 | 31 | ||
32 | # XML: <var key="SCRIPT_NAME"/> | 32 | # XML: <var key="SCRIPT_NAME"/> |
33 | - @notice.env_vars.should have_key('SCRIPT_NAME') | 33 | + @notice.env_vars.should have_key('SCRIPT_NAME') |
34 | @notice.env_vars['SCRIPT_NAME'].should be_nil # blank ends up nil | 34 | @notice.env_vars['SCRIPT_NAME'].should be_nil # blank ends up nil |
35 | 35 | ||
36 | # XML representation: | 36 | # XML representation: |
spec/fixtures/hoptoad_test_notice_without_line_of_backtrace.xml
0 → 100644
@@ -0,0 +1,73 @@ | @@ -0,0 +1,73 @@ | ||
1 | +<?xml version="1.0" encoding="UTF-8"?> | ||
2 | +<notice version="2.0"> | ||
3 | + <api-key>APIKEY</api-key> | ||
4 | + <notifier> | ||
5 | + <name>Hoptoad Notifier</name> | ||
6 | + <version>2.3.2</version> | ||
7 | + <url>http://hoptoadapp.com</url> | ||
8 | + </notifier> | ||
9 | + <error> | ||
10 | + <class>HoptoadTestingException</class> | ||
11 | + <message>HoptoadTestingException: Testing hoptoad via "rake hoptoad:test". If you can see this, it works.</message> | ||
12 | + <backtrace></backtrace> | ||
13 | + </error> | ||
14 | + <request> | ||
15 | + <url>http://example.org/verify</url> | ||
16 | + <component>application</component> | ||
17 | + <action>verify</action> | ||
18 | + <params> | ||
19 | + <var key="action">verify</var> | ||
20 | + <var key="controller">application</var> | ||
21 | + </params> | ||
22 | + <cgi-data> | ||
23 | + <var key="rack.session"/> | ||
24 | + <var key="action_dispatch.request.formats">text/html</var> | ||
25 | + <var key="action_dispatch.request.parameters"> | ||
26 | + <var key="action">verify</var> | ||
27 | + <var key="controller">application</var> | ||
28 | + </var> | ||
29 | + <var key="SERVER_NAME">example.org</var> | ||
30 | + <var key="rack.url_scheme">http</var> | ||
31 | + <var key="action_dispatch.remote_ip"/> | ||
32 | + <var key="CONTENT_LENGTH">0</var> | ||
33 | + <var key="rack.errors">#<StringIO:0x103d9dec0></var> | ||
34 | + <var key="action_dispatch.request.unsigned_session_cookie"/> | ||
35 | + <var key="action_dispatch.request.query_parameters"/> | ||
36 | + <var key="HTTPS">off</var> | ||
37 | + <var key="rack.run_once">false</var> | ||
38 | + <var key="PATH_INFO">/verify</var> | ||
39 | + <var key="action_dispatch.secret_token">994f235e3372684bc736dd11842b754d2ddcffc8c2958d33a29527c3217becd6655fa4653a318bc7c34131f9baf2acc0c424ed07e48e0e5e87c6cd34d711e985</var> | ||
40 | + <var key="rack.version">11</var> | ||
41 | + <var key="SCRIPT_NAME"/> | ||
42 | + <var key="action_dispatch.request.path_parameters"> | ||
43 | + <var key="action">verify</var> | ||
44 | + <var key="controller">application</var> | ||
45 | + </var> | ||
46 | + <var key="rack.multithread">false</var> | ||
47 | + <var key="action_dispatch.parameter_filter">password</var> | ||
48 | + <var key="action_dispatch.cookies"/> | ||
49 | + <var key="action_dispatch.request.request_parameters"/> | ||
50 | + <var key="rack.multiprocess">true</var> | ||
51 | + <var key="rack.request.query_hash"/> | ||
52 | + <var key="SERVER_PORT">80</var> | ||
53 | + <var key="REQUEST_METHOD">GET</var> | ||
54 | + <var key="action_controller.instance">#<ApplicationController:0x103d2f560></var> | ||
55 | + <var key="rack.session.options"> | ||
56 | + <var key="secure">false</var> | ||
57 | + <var key="httponly">true</var> | ||
58 | + <var key="path">/</var> | ||
59 | + <var key="expire_after"/> | ||
60 | + <var key="domain"/> | ||
61 | + <var key="id"/> | ||
62 | + </var> | ||
63 | + <var key="rack.input">#<StringIO:0x103d9dc90></var> | ||
64 | + <var key="action_dispatch.request.content_type"/> | ||
65 | + <var key="rack.request.query_string"/> | ||
66 | + <var key="QUERY_STRING"/> | ||
67 | + </cgi-data> | ||
68 | + </request> | ||
69 | + <server-environment> | ||
70 | + <project-root>/path/to/sample/project</project-root> | ||
71 | + <environment-name>development</environment-name> | ||
72 | + </server-environment> | ||
73 | +</notice> |
@@ -0,0 +1,37 @@ | @@ -0,0 +1,37 @@ | ||
1 | +require 'spec_helper' | ||
2 | + | ||
3 | +describe ErrorReport do | ||
4 | + context "with notice without line of backtrace" do | ||
5 | + let(:xml){ | ||
6 | + Rails.root.join('spec','fixtures','hoptoad_test_notice_with_one_line_of_backtrace.xml').read | ||
7 | + } | ||
8 | + | ||
9 | + let(:error_report) { | ||
10 | + ErrorReport.new(xml) | ||
11 | + } | ||
12 | + | ||
13 | + let(:app) { | ||
14 | + Fabricate( | ||
15 | + :app, | ||
16 | + :api_key => 'APIKEY' | ||
17 | + ) | ||
18 | + } | ||
19 | + | ||
20 | + describe "#backtrace" do | ||
21 | + | ||
22 | + it 'should have valid backtrace' do | ||
23 | + error_report.backtrace.should be_valid | ||
24 | + end | ||
25 | + end | ||
26 | + | ||
27 | + context "#generate_notice!" do | ||
28 | + it "save a notice" do | ||
29 | + expect { | ||
30 | + error_report.generate_notice! | ||
31 | + }.to change { | ||
32 | + app.reload.problems.count | ||
33 | + }.by(1) | ||
34 | + end | ||
35 | + end | ||
36 | + end | ||
37 | +end |
@@ -0,0 +1,35 @@ | @@ -0,0 +1,35 @@ | ||
1 | +require 'spec_helper' | ||
2 | + | ||
3 | +describe "Notices management" do | ||
4 | + | ||
5 | + let(:errbit_app) { Fabricate(:app, | ||
6 | + :api_key => 'APIKEY') } | ||
7 | + | ||
8 | + describe "create a new notice" do | ||
9 | + context "with valide notice" do | ||
10 | + let(:xml) { Rails.root.join('spec','fixtures','hoptoad_test_notice.xml').read } | ||
11 | + it 'save a new notice' do | ||
12 | + expect { | ||
13 | + post '/notifier_api/v2/notices', :data => xml | ||
14 | + expect(response).to be_success | ||
15 | + }.to change { | ||
16 | + errbit_app.problems.count | ||
17 | + }.by(1) | ||
18 | + end | ||
19 | + end | ||
20 | + | ||
21 | + context "with notice with empty backtrace" do | ||
22 | + let(:xml) { Rails.root.join('spec','fixtures','hoptoad_test_notice_without_line_of_backtrace.xml').read } | ||
23 | + it 'save a new notice' do | ||
24 | + expect { | ||
25 | + post '/notifier_api/v2/notices', :data => xml | ||
26 | + expect(response).to be_success | ||
27 | + }.to change { | ||
28 | + errbit_app.problems.count | ||
29 | + }.by(1) | ||
30 | + end | ||
31 | + end | ||
32 | + | ||
33 | + end | ||
34 | + | ||
35 | +end |