Commit 029ed1f6f59f9b4eb1165c6fd68a4a95704910ca
1 parent
483bfce2
Exists in
master
and in
1 other branch
[#227] Err creating now returns a XML with Err's ID (called "error code" by Airb…
…rake gem), so now Errbit is compatible with the user informer feature.
Showing
3 changed files
with
20 additions
and
4 deletions
Show diff stats
app/controllers/notices_controller.rb
1 | 1 | class NoticesController < ApplicationController |
2 | - respond_to :xml | |
3 | - | |
4 | 2 | skip_before_filter :authenticate_user!, :only => :create |
5 | 3 | |
6 | 4 | def create |
7 | 5 | # params[:data] if the notice came from a GET request, raw_post if it came via POST |
8 | 6 | @notice = App.report_error!(params[:data] || request.raw_post) |
9 | - respond_with @notice | |
7 | + render :xml => @notice | |
10 | 8 | end |
11 | - | |
12 | 9 | end |
13 | 10 | ... | ... |
app/models/notice.rb
1 | 1 | require 'hoptoad' |
2 | 2 | require 'recurse' |
3 | +require 'builder' | |
3 | 4 | |
4 | 5 | class Notice |
5 | 6 | include Mongoid::Document |
... | ... | @@ -35,6 +36,15 @@ class Notice |
35 | 36 | |
36 | 37 | delegate :app, :problem, :to => :err |
37 | 38 | |
39 | + def to_xml(options = {}) | |
40 | + options[:indent] ||= 2 | |
41 | + xml = options[:builder] ||= ::Builder::XmlMarkup.new(:indent => options[:indent]) | |
42 | + xml.instruct! unless options[:skip_instruct] | |
43 | + xml.notice do | |
44 | + xml.id self.id | |
45 | + end | |
46 | + end | |
47 | + | |
38 | 48 | def user_agent |
39 | 49 | agent_string = env_vars['HTTP_USER_AGENT'] |
40 | 50 | agent_string.blank? ? nil : UserAgent.parse(agent_string) | ... | ... |
spec/controllers/notices_controller_spec.rb
... | ... | @@ -17,16 +17,25 @@ describe NoticesController do |
17 | 17 | App.should_receive(:report_error!).with(@xml).and_return(@notice) |
18 | 18 | request.should_receive(:raw_post).and_return(@xml) |
19 | 19 | post :create |
20 | + response.should be_success | |
21 | + # Same RegExp from Airbrake::UserInformer#replacement (https://github.com/airbrake/airbrake/blob/master/lib/airbrake/user_informer.rb#L8) | |
22 | + # Inspired by https://github.com/airbrake/airbrake/blob/master/test/sender_test.rb | |
23 | + response.body.should match(%r{<id[^>]*>#{@notice.id}</id>}) | |
20 | 24 | end |
21 | 25 | |
22 | 26 | it "generates a notice from xml [GET]" do |
23 | 27 | App.should_receive(:report_error!).with(@xml).and_return(@notice) |
24 | 28 | get :create, {:data => @xml} |
29 | + response.should be_success | |
30 | + response.body.should match(%r{<id[^>]*>#{@notice.id}</id>}) | |
25 | 31 | end |
26 | 32 | |
27 | 33 | it "sends a notification email" do |
34 | + App.should_receive(:report_error!).with(@xml).and_return(@notice) | |
28 | 35 | request.should_receive(:raw_post).and_return(@xml) |
29 | 36 | post :create |
37 | + response.should be_success | |
38 | + response.body.should match(%r{<id[^>]*>#{@notice.id}</id>}) | |
30 | 39 | email = ActionMailer::Base.deliveries.last |
31 | 40 | email.to.should include(@app.watchers.first.email) |
32 | 41 | email.subject.should include(@notice.message) | ... | ... |