aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test/controller/base_test.rb
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2012-01-03 14:00:24 -0800
committerAaron Patterson <aaron.patterson@gmail.com>2012-01-03 14:00:24 -0800
commit63f7a61246aa570ed6891cdd225df8d67e4ecc13 (patch)
treec8641b3cf2b5f1eb941729d1c1e4f5d409e34e37 /actionpack/test/controller/base_test.rb
parente9122112facf56131d4bf0739382d9235582f8c0 (diff)
downloadrails-63f7a61246aa570ed6891cdd225df8d67e4ecc13.tar.gz
rails-63f7a61246aa570ed6891cdd225df8d67e4ecc13.tar.bz2
rails-63f7a61246aa570ed6891cdd225df8d67e4ecc13.zip
When generating routes, the last defined named route wins. This is in
contrast to route recognition where the first recognized route wins. This behavior will not exist in Rails 4.0. See: https://github.com/rails/rails/issues/4245 https://github.com/rails/rails/issues/4164
Diffstat (limited to 'actionpack/test/controller/base_test.rb')
-rw-r--r--actionpack/test/controller/base_test.rb38
1 files changed, 23 insertions, 15 deletions
diff --git a/actionpack/test/controller/base_test.rb b/actionpack/test/controller/base_test.rb
index ec8e5521c4..f2b054c849 100644
--- a/actionpack/test/controller/base_test.rb
+++ b/actionpack/test/controller/base_test.rb
@@ -197,28 +197,36 @@ class UrlOptionsTest < ActionController::TestCase
rescue_action_in_public!
end
- def test_path_generation_priority
+ ##
+ # When generating routes, the last defined named route wins. This is in
+ # contrast to route recognition where the first recognized route wins.
+ # This behavior will not exist in Rails 4.0.
+ #
+ # See:
+ #
+ # https://github.com/rails/rails/issues/4245
+ # https://github.com/rails/rails/issues/4164
+ def test_last_named_route_wins
rs = ActionDispatch::Routing::RouteSet.new
rs.draw do
- resources :models
- match 'special' => 'model#new', :as => :new_model
+ resources :purchases
+ match 'purchase/:product_id' => 'purchases#new', :as => :new_purchase
+ match 'purchase/:product_id' => 'purchases#new', :as => :correct_new_purchase
end
- url_params = {
- :action => "new",
- :controller => "model",
- :use_route => "new_model",
- :only_path => true }
-
- x = Struct.new(:rs, :params, :tc) {
+ x = Struct.new(:rs, :tc) {
include rs.named_routes.module
- public :new_model_path
+ public :correct_new_purchase_url
+ public :new_purchase_url
- def url_for(*args)
- tc.assert_equal([params], args)
- rs.url_for(*args)
+ def url_for(options)
+ options[:host] = 'example.org'
+ rs.url_for(options)
end
- }.new(rs, url_params, self)
+ }.new(rs, self)
+
+ assert_equal "http://example.org/purchase/1", x.correct_new_purchase_url(1)
+ assert_equal "http://example.org/purchase/1", x.new_purchase_url(1)
end
def test_url_for_params_priority