Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Correctly throwing exception if controller used is not the controller…

… that should have been tested
  • Loading branch information...
commit 4f2c4b391b580060a83c75bdf3b2e863d68493c4 1 parent e5bc712
Justin Knowlden gus authored
8 lib/riot/action_controller/http_methods.rb
@@ -11,7 +11,13 @@ def get(uri, params={}, &block)
11 11 http_reset
12 12 @env = ::Rack::MockRequest.env_for(uri, {:params => params})
13 13 @env['action_dispatch.show_exceptions'] = false
14   - @app.call(@env)
  14 + returning(@app.call(@env)) do |call_response|
  15 + c = @env["action_controller.instance"]
  16 + unless c.class.controller_name == topic.controller_name
  17 + msg = "Expected #{topic.controller_name} controller, not #{c.class.controller_name}"
  18 + raise ControllerMismatch, msg
  19 + end
  20 + end
15 21 end
16 22
17 23 def post; raise Exception, "POST isn't ready yet"; end
2  test/action_controller/get_request_test.rb
@@ -7,7 +7,7 @@
7 7 end.raises(AbstractController::ActionNotFound, "The action 'blah' could not be found")
8 8
9 9 asserts("controller does not match the one under test") do
10   - get "/gremlins/2"
  10 + get "/gremlins"
11 11 end.raises(RiotRails::ActionController::ControllerMismatch, "Expected rooms controller, not gremlins")
12 12
13 13 context "for a GET request" do

0 comments on commit 4f2c4b3

Please sign in to comment.
Something went wrong with that request. Please try again.