This project is archived and is in readonly mode.
Error on assert_recognizes when used on a route with constraint
Reported by Bruno Michel | June 29th, 2010 @ 02:50 PM | in 3.0.2
Hi,
I've tried to use assert_recognizes
to test a route
with a constraint on it, but it generates an error.
The route is:
constraints :subdomain => "api" do
get "/news(.:format)" => "news#index", :as => "news_index"
end
The assertion :
assert_recognizes({:controller => 'news', :action => 'index'}, {:method => :get, :path => 'news'})
The backtrace:
undefined method `subdomain' for #<Rack::Request:0xb60b8b1c>
# /home/bruno/.rvm/gems/ruby-1.8.7-p299/gems/rack-mount-0.6.6/lib/rack/mount/code_generation.rb:65:in `optimized_each'
# /home/bruno/.rvm/gems/ruby-1.8.7-p299/gems/rack-mount-0.6.6/lib/rack/mount/code_generation.rb:88:in `recognize'
# /home/bruno/.rvm/gems/ruby-1.8.7-p299/gems/actionpack-3.0.0.beta4/lib/action_dispatch/routing/route_set.rb:471:in `recognize_path'
# /home/bruno/.rvm/gems/ruby-1.8.7-p299/gems/actionpack-3.0.0.beta4/lib/action_dispatch/testing/assertions/routing.rb:189:in `recognized_request_for'
# /home/bruno/.rvm/gems/ruby-1.8.7-p299/gems/actionpack-3.0.0.beta4/lib/action_dispatch/testing/assertions/routing.rb:50:in `assert_recognizes
The error is on Rails-3.0.0.beta4 and on rails-master.
Comments and changes to this ticket
-
Andrew White August 20th, 2010 @ 07:58 AM
- Milestone cleared.
- State changed from new to open
- Assigned user set to Andrew White
- Importance changed from to Low
The problem stems from the fact that subdomain is defined in ActionDispatch::Request and the test session uses Rack::Request. Unfortunately it's not as simple as switching the class in ActionDispatch::IntegrationTest because it delegates the session creation to Rack::Test and there doesn't seem to be a way to override the request class from outside Rack::Test.
-
Andrew White August 20th, 2010 @ 05:40 PM
- Importance changed from Low to High
The attached patch adds support for passing full urls into assert_recognizes so that constraints like subdomain, etc. can be tested in functional tests as well as integration tests.
-
Repository August 20th, 2010 @ 06:51 PM
- State changed from open to resolved
(from [7c9bf45b0dd7ad7a1d99a14566bfaeadc77b4665]) Support routing constraints in functional tests
Extend assert_recognizes and assert_generates to support passing
full urls as the path argument. This allows testing of routing
constraints such as subdomain and host within functional tests.[#5005 state:resolved]
Signed-off-by: José Valim jose.valim@gmail.com
http://github.com/rails/rails/commit/7c9bf45b0dd7ad7a1d99a14566bfae... -
Repository August 20th, 2010 @ 06:52 PM
(from [47f6d8b880ae5532a9a79303edd51d43dcb3bf07]) Support routing constraints in functional tests
Extend assert_recognizes and assert_generates to support passing
full urls as the path argument. This allows testing of routing
constraints such as subdomain and host within functional tests.[#5005 state:resolved]
Signed-off-by: José Valim jose.valim@gmail.com
http://github.com/rails/rails/commit/47f6d8b880ae5532a9a79303edd51d...
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
<h2 style="font-size: 14px">Tickets have moved to Github</h2>
The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>
People watching this ticket
Attachments
Referenced by
- 5260 routing assertions do not support constraints Duplicate of #5005
- 5005 Error on assert_recognizes when used on a route with constraint [#5005 state:resolved]
- 5005 Error on assert_recognizes when used on a route with constraint [#5005 state:resolved]