diff --git a/app/models/error_report.rb b/app/models/error_report.rb
index f2773d0..eff1ead 100644
--- a/app/models/error_report.rb
+++ b/app/models/error_report.rb
@@ -44,19 +44,30 @@ class ErrorReport
:user_attributes => user_attributes,
:framework => framework
)
+ error.notices << notice
+ notice
+ end
- err = app.find_or_create_err!(
+ ##
+ # Error associate to this error_report
+ #
+ # Can already exist or not
+ #
+ # @return [ Error ]
+ def error
+ @error ||= app.find_or_create_err!(
:error_class => error_class,
:component => component,
:action => action,
:environment => rails_env,
- :fingerprint => fingerprint)
-
- err.notices << notice
- notice
+ :fingerprint => fingerprint
+ )
end
private
+
+
+
def fingerprint_source
# Find the first backtrace line with a file and line number.
if line = backtrace.lines.detect {|l| l.number.present? && l.file.present? }
diff --git a/spec/controllers/notices_controller_spec.rb b/spec/controllers/notices_controller_spec.rb
index 5a96971..b9b5daa 100644
--- a/spec/controllers/notices_controller_spec.rb
+++ b/spec/controllers/notices_controller_spec.rb
@@ -24,13 +24,13 @@ describe NoticesController do
response.body.should match(%r{]*>(.+)#{locate_path(@notice.id)}})
end
- it "should trnasform xml tags to hashes correctly" do
+ it "should transform xml tags to hashes correctly" do
App.should_receive(:report_error!).with(@xml).and_return(@notice)
request.should_receive(:raw_post).and_return(@xml)
post :create, :format => :xml
# XML:
- @notice.env_vars.should have_key('SCRIPT_NAME')
+ @notice.env_vars.should have_key('SCRIPT_NAME')
@notice.env_vars['SCRIPT_NAME'].should be_nil # blank ends up nil
# XML representation:
diff --git a/spec/fixtures/hoptoad_test_notice_without_line_of_backtrace.xml b/spec/fixtures/hoptoad_test_notice_without_line_of_backtrace.xml
new file mode 100644
index 0000000..dafecc0
--- /dev/null
+++ b/spec/fixtures/hoptoad_test_notice_without_line_of_backtrace.xml
@@ -0,0 +1,73 @@
+
+
+ APIKEY
+
+ Hoptoad Notifier
+ 2.3.2
+ http://hoptoadapp.com
+
+
+ HoptoadTestingException
+ HoptoadTestingException: Testing hoptoad via "rake hoptoad:test". If you can see this, it works.
+
+
+
+ http://example.org/verify
+ application
+ verify
+
+ verify
+ application
+
+
+
+ text/html
+
+ verify
+ application
+
+ example.org
+ http
+
+ 0
+ #<StringIO:0x103d9dec0>
+
+
+ off
+ false
+ /verify
+ 994f235e3372684bc736dd11842b754d2ddcffc8c2958d33a29527c3217becd6655fa4653a318bc7c34131f9baf2acc0c424ed07e48e0e5e87c6cd34d711e985
+ 11
+
+
+ verify
+ application
+
+ false
+ password
+
+
+ true
+
+ 80
+ GET
+ #<ApplicationController:0x103d2f560>
+
+ false
+ true
+ /
+
+
+
+
+ #<StringIO:0x103d9dc90>
+
+
+
+
+
+
+ /path/to/sample/project
+ development
+
+
diff --git a/spec/models/error_report_spec.rb b/spec/models/error_report_spec.rb
new file mode 100644
index 0000000..828de8c
--- /dev/null
+++ b/spec/models/error_report_spec.rb
@@ -0,0 +1,37 @@
+require 'spec_helper'
+
+describe ErrorReport do
+ context "with notice without line of backtrace" do
+ let(:xml){
+ Rails.root.join('spec','fixtures','hoptoad_test_notice_with_one_line_of_backtrace.xml').read
+ }
+
+ let(:error_report) {
+ ErrorReport.new(xml)
+ }
+
+ let(:app) {
+ Fabricate(
+ :app,
+ :api_key => 'APIKEY'
+ )
+ }
+
+ describe "#backtrace" do
+
+ it 'should have valid backtrace' do
+ error_report.backtrace.should be_valid
+ end
+ end
+
+ context "#generate_notice!" do
+ it "save a notice" do
+ expect {
+ error_report.generate_notice!
+ }.to change {
+ app.reload.problems.count
+ }.by(1)
+ end
+ end
+ end
+end
diff --git a/spec/requests/notices_controller_spec.rb b/spec/requests/notices_controller_spec.rb
new file mode 100644
index 0000000..5359e5d
--- /dev/null
+++ b/spec/requests/notices_controller_spec.rb
@@ -0,0 +1,35 @@
+require 'spec_helper'
+
+describe "Notices management" do
+
+ let(:errbit_app) { Fabricate(:app,
+ :api_key => 'APIKEY') }
+
+ describe "create a new notice" do
+ context "with valide notice" do
+ let(:xml) { Rails.root.join('spec','fixtures','hoptoad_test_notice.xml').read }
+ it 'save a new notice' do
+ expect {
+ post '/notifier_api/v2/notices', :data => xml
+ expect(response).to be_success
+ }.to change {
+ errbit_app.problems.count
+ }.by(1)
+ end
+ end
+
+ context "with notice with empty backtrace" do
+ let(:xml) { Rails.root.join('spec','fixtures','hoptoad_test_notice_without_line_of_backtrace.xml').read }
+ it 'save a new notice' do
+ expect {
+ post '/notifier_api/v2/notices', :data => xml
+ expect(response).to be_success
+ }.to change {
+ errbit_app.problems.count
+ }.by(1)
+ end
+ end
+
+ end
+
+end
--
libgit2 0.21.2