Commit 0f2d7f5541624f61ac75d58017b2ed18962c55f5
1 parent
c02adfd8
Exists in
master
and in
1 other branch
Added url to API
Showing
3 changed files
with
9 additions
and
3 deletions
Show diff stats
app/controllers/notices_controller.rb
| ... | ... | @@ -5,8 +5,11 @@ class NoticesController < ApplicationController |
| 5 | 5 | |
| 6 | 6 | def create |
| 7 | 7 | # params[:data] if the notice came from a GET request, raw_post if it came via POST |
| 8 | - @notice = App.report_error!(params[:data] || request.raw_post) | |
| 9 | - render :xml => @notice.to_xml(:only => false, :methods => [:id]) | |
| 8 | + notice = App.report_error!(params[:data] || request.raw_post) | |
| 9 | + api_xml = notice.to_xml(:only => false, :methods => [:id]) do |xml| | |
| 10 | + xml.url locate_url(notice.id, :host => Errbit::Config.host) | |
| 11 | + end | |
| 12 | + render :xml => api_xml | |
| 10 | 13 | end |
| 11 | 14 | |
| 12 | 15 | # Redirects a notice to the problem page. Useful when using User Information at Airbrake gem. | ... | ... |
config/routes.rb
| ... | ... | @@ -4,7 +4,7 @@ Errbit::Application.routes.draw do |
| 4 | 4 | |
| 5 | 5 | # Hoptoad Notifier Routes |
| 6 | 6 | match '/notifier_api/v2/notices' => 'notices#create' |
| 7 | - match '/locate/:id' => 'notices#locate' | |
| 7 | + match '/locate/:id' => 'notices#locate', :as => :locate | |
| 8 | 8 | match '/deploys.txt' => 'deploys#create' |
| 9 | 9 | |
| 10 | 10 | resources :notices, :only => [:show] | ... | ... |
spec/controllers/notices_controller_spec.rb
| ... | ... | @@ -21,6 +21,7 @@ describe NoticesController do |
| 21 | 21 | # Same RegExp from Airbrake::Sender#send_to_airbrake (https://github.com/airbrake/airbrake/blob/master/lib/airbrake/sender.rb#L53) |
| 22 | 22 | # Inspired by https://github.com/airbrake/airbrake/blob/master/test/sender_test.rb |
| 23 | 23 | response.body.should match(%r{<id[^>]*>#{@notice.id}</id>}) |
| 24 | + response.body.should match(%r{<url[^>]*>(.+)#{locate_path(@notice.id)}</url>}) | |
| 24 | 25 | end |
| 25 | 26 | |
| 26 | 27 | it "generates a notice from xml [GET]" do |
| ... | ... | @@ -28,6 +29,7 @@ describe NoticesController do |
| 28 | 29 | get :create, :data => @xml, :format => :xml |
| 29 | 30 | response.should be_success |
| 30 | 31 | response.body.should match(%r{<id[^>]*>#{@notice.id}</id>}) |
| 32 | + response.body.should match(%r{<url[^>]*>(.+)#{locate_path(@notice.id)}</url>}) | |
| 31 | 33 | end |
| 32 | 34 | |
| 33 | 35 | it "sends a notification email" do |
| ... | ... | @@ -36,6 +38,7 @@ describe NoticesController do |
| 36 | 38 | post :create, :format => :xml |
| 37 | 39 | response.should be_success |
| 38 | 40 | response.body.should match(%r{<id[^>]*>#{@notice.id}</id>}) |
| 41 | + response.body.should match(%r{<url[^>]*>(.+)#{locate_path(@notice.id)}</url>}) | |
| 39 | 42 | email = ActionMailer::Base.deliveries.last |
| 40 | 43 | email.to.should include(@app.watchers.first.email) |
| 41 | 44 | email.subject.should include(@notice.message) | ... | ... |