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.

Matching routes with :constraints in functional tests

#4752

There is a problem of getting routes with :constraints matched with get, post etc. in functional tests.

# config/routes.rb
TestTest::Application.routes.draw do |map|
  resources :users do
    scope :constraints => {:user_id => /[a-z0-9]+/i} do
      resource :license
    end
  end
end

# test/functional/licenses_controller_test.rb
require 'test_helper'

class LicensesControllerTest < ActionController::TestCase
  test "stuff" do
    matched_params = TestTest::Application.routes.recognize_path("/users/123abc/license")
    p matched_params
    # => {:controller=>"licenses", :user_id=>"123abc", :action=>"show"}

    begin
      TestTest::Application.routes.generate(matched_params)
    rescue => e
      p e
      # => #<ActionController::RoutingError: No route matches {:action=>"show", :user_id=>"123abc", :controller=>"licenses"}>
    end
    
    get :show, :user_id => "123abc"
    # => ActionController::RoutingError: No route matches {:controller=>"licenses", :action=>"show", :user_id=>"123abc"}
  end
end

If the :constraints are removed, the test will pass.

The routes match when running the app, so it seems like it is a functional test issue.

This also only occurs in 1.8.7 - the test above runs fine in 1.9.x.

Pushed an example Rails application you can git clone to easily replicate the issue yourself: http://github.com/augustl/Rails-3-functional-test-problem

Attached is a passing test case that also tries to replicate the issue, but that test actually passes.

Reported by August Lilleaas · June 2nd, 2010 @ 02:55 PM

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

Activity

  1. August Lilleaas
    August Lilleaas
    • Tag set to actionpack rails3

    June 2nd, 2010 @ 02:58 PM

  2. epochwolf
    epochwolf
    • Tag changed from actionpack rails3 to actionpack, rails3

    June 2nd, 2010 @ 03:03 PM

  3. Andrew White
    Andrew White
    • Assigned user set to Andrew White
    • State changed from new to resolved
    • Milestone cleared.
    • Importance changed from to Medium

    June 28th, 2010 @ 01:43 PM

  4. Jeremy Kemper