Permalink
Browse files

Ensure that ActionController::Rescue doesn't intercept exceptions rai…

…sed in the controller on Rails 2 for AMF calls
  • Loading branch information...
1 parent 3d415f8 commit 611b3175d558fcd36c19bf370c35114ec66ff36a @warhammerkid warhammerkid committed Nov 30, 2011
Showing with 42 additions and 5 deletions.
  1. +12 −1 lib/rubyamf/rails/rails2_bootstrap.rb
  2. +30 −4 spec/request_processor_spec.rb
@@ -19,7 +19,7 @@
ActiveRecord::Base.send(:include, RubyAMF::Rails::Model)
end
-# Hook up rendering
+# Hook up rendering and hack in our custom error handling
module ActionController #:nodoc:
class Base #:nodoc:
def render_with_amf(options = nil, extra_options ={}, &block)
@@ -33,6 +33,17 @@ def render_with_amf(options = nil, extra_options ={}, &block)
end
alias_method_chain :render, :amf
end
+
+ module Rescue #:nodoc:
+ protected
+ # Re-raise the exception so that RubyAMF gets it if it's an AMF call. Otherwise
+ # RubyAMF doesn't know that the call failed and a "success" response is sent.
+ def rescue_action_with_amf(exception)
+ raise exception if respond_to?(:is_amf?) && is_amf?
+ rescue_action_without_amf exception
+ end
+ alias_method_chain :rescue_action, :amf
+ end
end
# Add middleware
@@ -20,6 +20,14 @@ def params_test
def scope_test
render :amf => {:prop_a => "asdf"}, :mapping_scope => :test_scope
end
+
+ def raise_test
+ raise "exception raised"
+ end
+
+ def fault_test
+ render :amf => FaultObject.new("exception raised")
+ end
end
end
@@ -56,15 +64,17 @@ def scope_test
it "should return an exception if the controller doesn't exist" do
env = RubyAMF::Test.create_call 3, "Kernel.exec", "puts 'Muhahaha!'"
@app.call(env)
- env['rubyamf.response'].messages[0].data.should be_a(RocketAMF::Values::ErrorMessage)
- env['rubyamf.response'].messages[0].data.faultString.should == "Service KernelController does not exist"
+ err = env['rubyamf.response'].messages[0].data
+ err.should be_a(RocketAMF::Values::ErrorMessage)
+ err.faultString.should == "Service KernelController does not exist"
end
it "should return an exception if the controller doesn't respond to the action" do
env = RubyAMF::Test.create_call 3, "AmfTestController.non_existant"
@app.call(env)
- env['rubyamf.response'].messages[0].data.should be_a(RocketAMF::Values::ErrorMessage)
- env['rubyamf.response'].messages[0].data.faultString.should == "Service AmfTestController does not respond to non_existant"
+ err = env['rubyamf.response'].messages[0].data
+ err.should be_a(RocketAMF::Values::ErrorMessage)
+ err.faultString.should == "Service AmfTestController does not respond to non_existant"
end
it "shouldn't populate params hash if disabled" do
@@ -90,4 +100,20 @@ def scope_test
@app.call(env)
env['rubyamf.response'].mapping_scope.should == :test_scope
end
+
+ it "should catch and handle raised exceptions" do
+ env = RubyAMF::Test.create_call 3, "AmfTestController.raise_test"
+ @app.call(env)
+ err = env['rubyamf.response'].messages[0].data
+ err.should be_a(RocketAMF::Values::ErrorMessage)
+ err.faultString.should == "exception raised"
+ end
+
+ it "should catch and handle returned FaultObjects" do
+ env = RubyAMF::Test.create_call 3, "AmfTestController.fault_test"
+ @app.call(env)
+ err = env['rubyamf.response'].messages[0].data
+ err.should be_a(RocketAMF::Values::ErrorMessage)
+ err.faultString.should == "exception raised"
+ end
end

0 comments on commit 611b317

Please sign in to comment.