This project is archived and is in readonly mode.
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
-
August Lilleaas June 2nd, 2010 @ 02:58 PM
- Tag set to actionpack rails3
-
epochwolf June 2nd, 2010 @ 03:03 PM
- Tag changed from actionpack rails3 to actionpack, rails3
-
Andrew White June 28th, 2010 @ 01:43 PM
- Assigned user set to Andrew White
- State changed from new to resolved
- Milestone cleared.
- Importance changed from to Medium
Fixed by this commit:
http://github.com/rails/rails/commit/e717631a8481935e8ac1eeb2445da3...
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>