diff options
Diffstat (limited to 'actionpack/test/dispatch/mapper_test.rb')
-rw-r--r-- | actionpack/test/dispatch/mapper_test.rb | 77 |
1 files changed, 51 insertions, 26 deletions
diff --git a/actionpack/test/dispatch/mapper_test.rb b/actionpack/test/dispatch/mapper_test.rb index df27e41997..1596d23b1e 100644 --- a/actionpack/test/dispatch/mapper_test.rb +++ b/actionpack/test/dispatch/mapper_test.rb @@ -1,4 +1,4 @@ -require 'abstract_unit' +require "abstract_unit" module ActionDispatch module Routing @@ -50,15 +50,15 @@ module ActionDispatch fakeset = FakeSet.new mapper = Mapper.new fakeset assert_raises(ArgumentError) do - mapper.match '/', :to => 'posts#index', :as => :main + mapper.match "/", to: "posts#index", as: :main end end def test_unscoped_formatted fakeset = FakeSet.new mapper = Mapper.new fakeset - mapper.get '/foo', :to => 'posts#index', :as => :main, :format => true - assert_equal({:controller=>"posts", :action=>"index"}, + mapper.get "/foo", to: "posts#index", as: :main, format: true + assert_equal({ controller: "posts", action: "index" }, fakeset.defaults.first) assert_equal "/foo.:format", fakeset.asts.first.to_s end @@ -67,9 +67,9 @@ module ActionDispatch fakeset = FakeSet.new mapper = Mapper.new fakeset mapper.scope(format: true) do - mapper.get '/foo', :to => 'posts#index', :as => :main + mapper.get "/foo", to: "posts#index", as: :main end - assert_equal({:controller=>"posts", :action=>"index"}, + assert_equal({ controller: "posts", action: "index" }, fakeset.defaults.first) assert_equal "/foo.:format", fakeset.asts.first.to_s end @@ -78,18 +78,18 @@ module ActionDispatch fakeset = FakeSet.new mapper = Mapper.new fakeset mapper.scope(omg: :awesome) do - mapper.get '/', :to => 'posts#index', :as => :main + mapper.get "/", to: "posts#index", as: :main end - assert_equal({:omg=>:awesome, :controller=>"posts", :action=>"index"}, + assert_equal({ omg: :awesome, controller: "posts", action: "index" }, fakeset.defaults.first) assert_equal("GET", fakeset.routes.first.verb) end def test_mapping_requirements - options = { } + options = {} scope = Mapper::Scope.new({}) - ast = Journey::Parser.parse '/store/:name(*rest)' - m = Mapper::Mapping.build(scope, FakeSet.new, ast, 'foo', 'bar', nil, [:get], nil, {}, true, options) + ast = Journey::Parser.parse "/store/:name(*rest)" + m = Mapper::Mapping.build(scope, FakeSet.new, ast, "foo", "bar", nil, [:get], nil, {}, true, options) assert_equal(/.+?/, m.requirements[:rest]) end @@ -97,16 +97,28 @@ module ActionDispatch fakeset = FakeSet.new mapper = Mapper.new fakeset mapper.scope(via: :put) do - mapper.match '/', :to => 'posts#index', :as => :main + mapper.match "/", to: "posts#index", as: :main end assert_equal("PUT", fakeset.routes.first.verb) end + def test_to_scope + fakeset = FakeSet.new + mapper = Mapper.new fakeset + mapper.scope(to: "posts#index") do + mapper.get :all + mapper.post :most + end + + assert_equal "posts#index", fakeset.routes.to_a[0].defaults[:to] + assert_equal "posts#index", fakeset.routes.to_a[1].defaults[:to] + end + def test_map_slash fakeset = FakeSet.new mapper = Mapper.new fakeset - mapper.get '/', :to => 'posts#index', :as => :main - assert_equal '/', fakeset.asts.first.to_s + mapper.get "/", to: "posts#index", as: :main + assert_equal "/", fakeset.asts.first.to_s end def test_map_more_slashes @@ -114,31 +126,31 @@ module ActionDispatch mapper = Mapper.new fakeset # FIXME: is this a desired behavior? - mapper.get '/one/two/', :to => 'posts#index', :as => :main - assert_equal '/one/two(.:format)', fakeset.asts.first.to_s + mapper.get "/one/two/", to: "posts#index", as: :main + assert_equal "/one/two(.:format)", fakeset.asts.first.to_s end def test_map_wildcard fakeset = FakeSet.new mapper = Mapper.new fakeset - mapper.get '/*path', :to => 'pages#show' - assert_equal '/*path(.:format)', fakeset.asts.first.to_s + mapper.get "/*path", to: "pages#show" + assert_equal "/*path(.:format)", fakeset.asts.first.to_s assert_equal(/.+?/, fakeset.requirements.first[:path]) end def test_map_wildcard_with_other_element fakeset = FakeSet.new mapper = Mapper.new fakeset - mapper.get '/*path/foo/:bar', :to => 'pages#show' - assert_equal '/*path/foo/:bar(.:format)', fakeset.asts.first.to_s + mapper.get "/*path/foo/:bar", to: "pages#show" + assert_equal "/*path/foo/:bar(.:format)", fakeset.asts.first.to_s assert_equal(/.+?/, fakeset.requirements.first[:path]) end def test_map_wildcard_with_multiple_wildcard fakeset = FakeSet.new mapper = Mapper.new fakeset - mapper.get '/*foo/*bar', :to => 'pages#show' - assert_equal '/*foo/*bar(.:format)', fakeset.asts.first.to_s + mapper.get "/*foo/*bar", to: "pages#show" + assert_equal "/*foo/*bar(.:format)", fakeset.asts.first.to_s assert_equal(/.+?/, fakeset.requirements.first[:foo]) assert_equal(/.+?/, fakeset.requirements.first[:bar]) end @@ -146,16 +158,16 @@ module ActionDispatch def test_map_wildcard_with_format_false fakeset = FakeSet.new mapper = Mapper.new fakeset - mapper.get '/*path', :to => 'pages#show', :format => false - assert_equal '/*path', fakeset.asts.first.to_s + mapper.get "/*path", to: "pages#show", format: false + assert_equal "/*path", fakeset.asts.first.to_s assert_nil fakeset.requirements.first[:path] end def test_map_wildcard_with_format_true fakeset = FakeSet.new mapper = Mapper.new fakeset - mapper.get '/*path', :to => 'pages#show', :format => true - assert_equal '/*path.:format', fakeset.asts.first.to_s + mapper.get "/*path", to: "pages#show", format: true + assert_equal "/*path.:format", fakeset.asts.first.to_s end def test_raising_error_when_path_is_not_passed @@ -178,6 +190,19 @@ module ActionDispatch mapper.mount as: "exciting" end end + + def test_scope_does_not_destructively_mutate_default_options + fakeset = FakeSet.new + mapper = Mapper.new fakeset + + frozen = { foo: :bar }.freeze + + assert_nothing_raised do + mapper.scope(defaults: frozen) do + # pass + end + end + end end end end |