-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Adding routes using with_routing has no effect and results in ActionController::RoutingError #817
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I believe it has something to do with the fact that Here's a slight variation on the above test that seems to confirm that theory, since the example that failed before passes in this case: describe SubclassController do
def skip_routing
method = ActionDispatch::Assertions::RoutingAssertions.instance_method(:with_routing).bind(self)
method.call do |map|
map.draw do
# I've tried both of these versions:
match ':controller/:action'
#get 'subclass/:action' => 'subclass'
end
yield
end
end
# Now *this* fails. Why?
specify do
skip_routing do
expect(get: '/subclass/test').to route_to("subclass#test")
end
end
# Now this passes!
specify do
skip_routing do
get :test
response.body.should == 'ok'
end
end
end So it resolves the previous failure, but now the
|
Currently I'm working around this by just drawing the routes directly with Rails.application.routes.draw: describe SubclassController do
before do
Rails.application.routes.draw do
get 'subclass/:action' => 'subclass'
end
end
# http://pivotallabs.com/adding-routes-for-tests-specs-with-rails-3/
after do
Rails.application.reload_routes!
end
specify do
expect(get: '/subclass/test').to route_to("subclass#test")
end
specify do
get :test
response.body.should == 'ok'
end
end
# With this in my config/routes.rb:
# root to: "home#index"
describe HomeController do
# Without the after hook in the previous example group, this would fail, because routes.draw
# erases all previously defined routes.
specify do
expect(get: '/').to route_to("home#index")
end
end The problem with that, though, is that it erases all previously defined routes, which causes examples in other example groups to fail! The workaround seems to be to reload the routes from your Any ideas how to fix this? |
Here's some debugging notes from trying to confirm whether In my test file, before the call to When I step into the call to
which seems strange and I don't really understand what's going on, but apparently some kind of delegation. Those variables are still the same at this point. The next step shows where it gets
When I inspect
but I worry about what might happen with that as the receiver instead of whatever The next step takes me here:
Within this call to
Now Because
I'm guessing that is the problem (or part of it), but don't know how to fix it... because I don't understand all that delegation through |
I don't have much to add technically, but we are also running into this issue in all of our tests that make use of |
/cc @alindeman |
@TylerRick, @brianatwhistle while the specs are thin wrappers around Would using specify do
routes.draw { get ':controller/:action' }
expect(get: '/subclass/test').to route_to("subclass#test")
end
specify do
routes.draw { get ':controller/:action' }
get :test
expect(response.body).to eq 'ok'
end |
Having the same issue with 2.14. Got it resolved using Anonymous controllers instead: |
observing this problem as well. |
This seems to still be an issue in |
Just ran into this problem as well. On rspec-rails-3.3.3 |
@cupakromer is this still valid? |
Closing in favour of #1652 |
I expected all of these examples to pass:
But one of them fails:
How can I get it to recognize the route added with
with_routing
?The text was updated successfully, but these errors were encountered: