Permalink
Browse files

Merge remote-tracking branch 'tcrayford/add_exception_to_injector_on_…

…error_redirects'
  • Loading branch information...
2 parents 1bbb315 + d720793 commit 21dcee7eedbe7a71a3ce84c8cfe40316429e35bb @garybernhardt committed Jun 11, 2012
Showing with 14 additions and 0 deletions.
  1. +5 −0 lib/raptor/injector.rb
  2. +1 −0 lib/raptor/router.rb
  3. +8 −0 spec/injector_spec.rb
@@ -61,6 +61,11 @@ def add_route_path(request, route_path)
route_path)]
Injector.new(injectables)
end
+
+ def add_exception(e)
+ injectables = @injectables + [Injectables::Fixed.new(:exception, e)]
+ Injector.new(injectables)
+ end
end
class UnknownInjectable < RuntimeError
@@ -27,6 +27,7 @@ def call(env)
route.respond_to_request(injector, request)
rescue Exception => e
Raptor.log("Looking for a redirect for #{e.inspect}")
+ injector = injector.add_exception(e)
action = route.action_for_exception(e) or raise
route_named(action).respond_to_request(injector, request)
end
@@ -80,6 +80,14 @@ def method_taking_id(id); id; end
injector_with_route_path.call(method).should == "5"
end
+ it "injects an exception after being given an exception" do
+ def method_taking_exception(exception); exception; end
+ e = RuntimeError.new
+ method = method(:method_taking_exception)
+ injector_with_exception = injector.add_exception(e)
+ injector_with_exception.call(method).should == e
+ end
+
context "custom injectables" do
before do
module WithInjectables

0 comments on commit 21dcee7

Please sign in to comment.