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.