Commit 0f2d7f5541624f61ac75d58017b2ed18962c55f5

Authored by Julio Monteiro
1 parent c02adfd8
Exists in master and in 1 other branch production

Added url to API

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