Commit 8cd0c6cd458bc639fc3af542725ed9876cf7434b

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

[#227] Page to redirect from notice ID to problem page, so we can now use the ID…

… shown at 500.html inside monitored app.
app/controllers/notices_controller.rb
@@ -6,5 +6,11 @@ class NoticesController < ApplicationController @@ -6,5 +6,11 @@ class NoticesController < ApplicationController
6 @notice = App.report_error!(params[:data] || request.raw_post) 6 @notice = App.report_error!(params[:data] || request.raw_post)
7 render :xml => @notice 7 render :xml => @notice
8 end 8 end
  9 +
  10 + # Redirects a notice to the problem page. Useful when using User Information at Airbrake gem.
  11 + def locate
  12 + problem = Notice.find(params[:id]).problem
  13 + redirect_to app_err_path(problem.app, problem)
  14 + end
9 end 15 end
10 16
config/routes.rb
@@ -4,6 +4,7 @@ Errbit::Application.routes.draw do @@ -4,6 +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 '/deploys.txt' => 'deploys#create' 8 match '/deploys.txt' => 'deploys#create'
8 9
9 resources :notices, :only => [:show] 10 resources :notices, :only => [:show]
spec/controllers/notices_controller_spec.rb
1 require 'spec_helper' 1 require 'spec_helper'
2 2
3 describe NoticesController do 3 describe NoticesController do
  4 + it_requires_authentication :for => { :locate => :get }
  5 +
  6 + let(:app) { Fabricate(:app) }
4 7
5 context 'notices API' do 8 context 'notices API' do
6 before do 9 before do
@@ -44,5 +47,21 @@ describe NoticesController do @@ -44,5 +47,21 @@ describe NoticesController do
44 end 47 end
45 end 48 end
46 49
  50 + describe "GET /locate/:id" do
  51 + context 'when logged in as an admin' do
  52 + before(:each) do
  53 + @user = Fabricate(:admin)
  54 + sign_in @user
  55 + end
  56 +
  57 + it "should locate notice and redirect to problem" do
  58 + problem = Fabricate(:problem, :app => app, :environment => "production")
  59 + notice = Fabricate(:notice, :err => Fabricate(:err, :problem => problem))
  60 + get :locate, :id => notice.id
  61 + response.should redirect_to(app_err_path(problem.app, problem))
  62 + end
  63 + end
  64 + end
  65 +
47 end 66 end
48 67