diff --git a/app/controllers/notices_controller.rb b/app/controllers/notices_controller.rb
index ebf5f41..0942ea6 100644
--- a/app/controllers/notices_controller.rb
+++ b/app/controllers/notices_controller.rb
@@ -1,13 +1,10 @@
class NoticesController < ApplicationController
- respond_to :xml
-
skip_before_filter :authenticate_user!, :only => :create
def create
# params[:data] if the notice came from a GET request, raw_post if it came via POST
@notice = App.report_error!(params[:data] || request.raw_post)
- respond_with @notice
+ render :xml => @notice
end
-
end
diff --git a/app/models/notice.rb b/app/models/notice.rb
index 1e5fa92..15357ad 100644
--- a/app/models/notice.rb
+++ b/app/models/notice.rb
@@ -1,5 +1,6 @@
require 'hoptoad'
require 'recurse'
+require 'builder'
class Notice
include Mongoid::Document
@@ -35,6 +36,15 @@ class Notice
delegate :app, :problem, :to => :err
+ def to_xml(options = {})
+ options[:indent] ||= 2
+ xml = options[:builder] ||= ::Builder::XmlMarkup.new(:indent => options[:indent])
+ xml.instruct! unless options[:skip_instruct]
+ xml.notice do
+ xml.id self.id
+ end
+ end
+
def user_agent
agent_string = env_vars['HTTP_USER_AGENT']
agent_string.blank? ? nil : UserAgent.parse(agent_string)
diff --git a/spec/controllers/notices_controller_spec.rb b/spec/controllers/notices_controller_spec.rb
index 7aef7be..488e33a 100644
--- a/spec/controllers/notices_controller_spec.rb
+++ b/spec/controllers/notices_controller_spec.rb
@@ -17,16 +17,25 @@ describe NoticesController do
App.should_receive(:report_error!).with(@xml).and_return(@notice)
request.should_receive(:raw_post).and_return(@xml)
post :create
+ response.should be_success
+ # Same RegExp from Airbrake::UserInformer#replacement (https://github.com/airbrake/airbrake/blob/master/lib/airbrake/user_informer.rb#L8)
+ # Inspired by https://github.com/airbrake/airbrake/blob/master/test/sender_test.rb
+ response.body.should match(%r{]*>#{@notice.id}})
end
it "generates a notice from xml [GET]" do
App.should_receive(:report_error!).with(@xml).and_return(@notice)
get :create, {:data => @xml}
+ response.should be_success
+ response.body.should match(%r{]*>#{@notice.id}})
end
it "sends a notification email" do
+ App.should_receive(:report_error!).with(@xml).and_return(@notice)
request.should_receive(:raw_post).and_return(@xml)
post :create
+ response.should be_success
+ response.body.should match(%r{]*>#{@notice.id}})
email = ActionMailer::Base.deliveries.last
email.to.should include(@app.watchers.first.email)
email.subject.should include(@notice.message)
--
libgit2 0.21.2