1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
rails--rails/actionpack/test/dispatch/routing/route_set_test.rb
Rafael Mendonça França 4af5899e25 Revert "Merge pull request #16966 from why-el/symbolize-path-params"
This reverts commit 9d05d6de52, reversing
changes made to 0863c9248f.

The change in the behaviour reported at #16958 doesn't exist since 4.0
and 4.1 works in the same way
2014-09-25 18:07:22 -03:00

93 lines
2.3 KiB
Ruby

require 'abstract_unit'
module ActionDispatch
module Routing
class RouteSetTest < ActiveSupport::TestCase
class SimpleApp
def initialize(response)
@response = response
end
def call(env)
[ 200, { 'Content-Type' => 'text/plain' }, [response] ]
end
end
setup do
@set = RouteSet.new
end
test "url helpers are added when route is added" do
draw do
get 'foo', to: SimpleApp.new('foo#index')
end
assert_equal '/foo', url_helpers.foo_path
assert_raises NoMethodError do
assert_equal '/bar', url_helpers.bar_path
end
draw do
get 'foo', to: SimpleApp.new('foo#index')
get 'bar', to: SimpleApp.new('bar#index')
end
assert_equal '/foo', url_helpers.foo_path
assert_equal '/bar', url_helpers.bar_path
end
test "url helpers are updated when route is updated" do
draw do
get 'bar', to: SimpleApp.new('bar#index'), as: :bar
end
assert_equal '/bar', url_helpers.bar_path
draw do
get 'baz', to: SimpleApp.new('baz#index'), as: :bar
end
assert_equal '/baz', url_helpers.bar_path
end
test "url helpers are removed when route is removed" do
draw do
get 'foo', to: SimpleApp.new('foo#index')
get 'bar', to: SimpleApp.new('bar#index')
end
assert_equal '/foo', url_helpers.foo_path
assert_equal '/bar', url_helpers.bar_path
draw do
get 'foo', to: SimpleApp.new('foo#index')
end
assert_equal '/foo', url_helpers.foo_path
assert_raises NoMethodError do
assert_equal '/bar', url_helpers.bar_path
end
end
test "explicit keys win over implicit keys" do
draw do
resources :foo do
resources :bar, to: SimpleApp.new('foo#show')
end
end
assert_equal '/foo/1/bar/2', url_helpers.foo_bar_path(1, 2)
assert_equal '/foo/1/bar/2', url_helpers.foo_bar_path(2, foo_id: 1)
end
private
def draw(&block)
@set.draw(&block)
end
def url_helpers
@set.url_helpers
end
end
end
end