Skip to content

Commit

Permalink
Fix LocalJumpError in Rails controllers
Browse files Browse the repository at this point in the history
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
  • Loading branch information
nateberkopec committed Oct 11, 2017
1 parent ef62382 commit 6b46e7c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
10 changes: 4 additions & 6 deletions lib/raven/integrations/rails/controller_transaction.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions spec/raven/integrations/rails_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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:https://www.example.com/exception")
end

Expand Down
2 changes: 1 addition & 1 deletion spec/support/test_rails_app/app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@ def exception
end

def world
render :text => "Hello World!"
render :plain => "Hello World!"
end
end

0 comments on commit 6b46e7c

Please sign in to comment.