This project is archived and is in readonly mode.

#4752 ✓resolved
August Lilleaas

Matching routes with :constraints in functional tests

Reported by August Lilleaas | June 2nd, 2010 @ 02:55 PM | in 3.0.2

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.

Comments and changes to this ticket

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>

Attachments

Pages