Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

Error on assert_recognizes when used on a route with constraint

#5005

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.

Reported by Bruno Michel · June 29th, 2010 @ 02:50 PM

State: resolved
Milestone: 3.0.2
Assigned to: Andrew White Andrew White
Importance: High

Activity

  1. archfear
    archfear

    I can verify this is happening for me on 3.0.0.beta4 as well.

    +1

    July 8th, 2010 @ 02:53 AM

  2. Andrew White
    Andrew White
    • 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.

    August 20th, 2010 @ 07:58 AM

  3. Andrew White
    Andrew White
    • 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.

    August 20th, 2010 @ 05:40 PM

  4. Repository
    Repository
    • 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 Error on assert_recognizes when used on a route with constraint state:resolved]

    Signed-off-by: José Valim jose.valim@gmail.com
    http://github.com/rails/rails/commit/7c9bf45b0dd7ad7a1d99a14566bfae...

    August 20th, 2010 @ 06:51 PM

  5. Repository
    Repository

    (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 Error on assert_recognizes when used on a route with constraint state:resolved]

    Signed-off-by: José Valim jose.valim@gmail.com
    http://github.com/rails/rails/commit/47f6d8b880ae5532a9a79303edd51d...

    August 20th, 2010 @ 06:52 PM

  6. Jeremy Kemper