From 6b46e7cd506d1e0feb0b149d7394c3b095711c3d Mon Sep 17 00:00:00 2001 From: Nate Berkopec Date: Wed, 11 Oct 2017 08:29:18 -0600 Subject: [PATCH] Fix LocalJumpError in Rails controllers There were a few messups here: * The Rails controller tests never tested a "happy case" (that is, no exceptions) * The Rails controller tests didn't check to see the exception they were actually catching - so the LocalJumpError went unnoticed! * You can't `yield` from the block form of `around_action` * I'm not sure why I thought class_eval was necessary here - it isn't. Fix #773 --- lib/raven/integrations/rails/controller_transaction.rb | 10 ++++------ spec/raven/integrations/rails_spec.rb | 8 ++++++++ spec/support/test_rails_app/app.rb | 2 +- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/lib/raven/integrations/rails/controller_transaction.rb b/lib/raven/integrations/rails/controller_transaction.rb index da12a4661..23506bae0 100644 --- a/lib/raven/integrations/rails/controller_transaction.rb +++ b/lib/raven/integrations/rails/controller_transaction.rb @@ -2,12 +2,10 @@ module Raven class Rails module ControllerTransaction def self.included(base) - base.class_eval do - around_action do |controller| - Raven.context.transaction.push "#{controller.class}##{controller.action_name}" - yield - Raven.context.transaction.pop - end + base.around_action do |controller, block| + Raven.context.transaction.push "#{controller.class}##{controller.action_name}" + block.call + Raven.context.transaction.pop end end end diff --git a/spec/raven/integrations/rails_spec.rb b/spec/raven/integrations/rails_spec.rb index 1890af825..cdf21a10a 100644 --- a/spec/raven/integrations/rails_spec.rb +++ b/spec/raven/integrations/rails_spec.rb @@ -13,6 +13,13 @@ expect(TestApp.middleware).to include(Raven::Rack) end + it "doesn't do anything on a normal route" do + get "/" + + expect(response.status).to eq(200) + expect(Raven.client.transport.events.size).to eq(0) + end + it "should capture exceptions in production" do get "/exception" expect(response.status).to eq(500) @@ -25,6 +32,7 @@ event = Raven.client.transport.events.first event = JSON.parse!(event[1]) + expect(event["logentry"]["message"]).to eq("RuntimeError: An unhandled exception!") expect(event['request']['url']).to eq("http://www.example.com/exception") end diff --git a/spec/support/test_rails_app/app.rb b/spec/support/test_rails_app/app.rb index 0e73cc4d9..accd34af9 100644 --- a/spec/support/test_rails_app/app.rb +++ b/spec/support/test_rails_app/app.rb @@ -35,6 +35,6 @@ def exception end def world - render :text => "Hello World!" + render :plain => "Hello World!" end end