diff options
author | Xavier Noria <fxn@hashref.com> | 2016-08-06 19:35:13 +0200 |
---|---|---|
committer | Xavier Noria <fxn@hashref.com> | 2016-08-06 19:35:13 +0200 |
commit | 5b6eb1d58b48fada298215b2cccda89f993890c3 (patch) | |
tree | a48010fd8c35588540f50df257a76347091aca12 /actionpack/test/controller | |
parent | 12a70404cd164008879e63cc320356e6afee3adc (diff) | |
download | rails-5b6eb1d58b48fada298215b2cccda89f993890c3.tar.gz rails-5b6eb1d58b48fada298215b2cccda89f993890c3.tar.bz2 rails-5b6eb1d58b48fada298215b2cccda89f993890c3.zip |
modernizes hash syntax in actionpack
Diffstat (limited to 'actionpack/test/controller')
44 files changed, 1303 insertions, 1303 deletions
diff --git a/actionpack/test/controller/action_pack_assertions_test.rb b/actionpack/test/controller/action_pack_assertions_test.rb index 7b7f3d1de6..ab3db80119 100644 --- a/actionpack/test/controller/action_pack_assertions_test.rb +++ b/actionpack/test/controller/action_pack_assertions_test.rb @@ -5,25 +5,25 @@ class ActionPackAssertionsController < ActionController::Base def nothing() head :ok end - def hello_xml_world() render :template => "test/hello_xml_world"; end + def hello_xml_world() render template: "test/hello_xml_world"; end def hello_xml_world_pdf self.content_type = "application/pdf" - render :template => "test/hello_xml_world" + render template: "test/hello_xml_world" end def hello_xml_world_pdf_header response.headers["Content-Type"] = "application/pdf; charset=utf-8" - render :template => "test/hello_xml_world" + render template: "test/hello_xml_world" end def redirect_internal() redirect_to "/nothing"; end - def redirect_to_action() redirect_to :action => "flash_me", :id => 1, :params => { "panda" => "fun" }; end + def redirect_to_action() redirect_to action: "flash_me", id: 1, params: { "panda" => "fun" }; end - def redirect_to_controller() redirect_to :controller => "elsewhere", :action => "flash_me"; end + def redirect_to_controller() redirect_to controller: "elsewhere", action: "flash_me"; end - def redirect_to_controller_with_symbol() redirect_to :controller => :elsewhere, :action => :flash_me; end + def redirect_to_controller_with_symbol() redirect_to controller: :elsewhere, action: :flash_me; end def redirect_to_path() redirect_to "/some/path" end @@ -53,7 +53,7 @@ class ActionPackAssertionsController < ActionController::Base def assign_this @howdy = "ho" - render :inline => "Mr. Henke" + render inline: "Mr. Henke" end def render_based_on_parameters @@ -84,11 +84,11 @@ class ActionPackAssertionsController < ActionController::Base end def render_file_absolute_path - render :file => File.expand_path("../../../README.rdoc", __FILE__) + render file: File.expand_path("../../../README.rdoc", __FILE__) end def render_file_relative_path - render :file => "README.rdoc" + render file: "README.rdoc" end end @@ -116,15 +116,15 @@ module Admin end def redirect_to_absolute_controller - redirect_to :controller => "/content" + redirect_to controller: "/content" end def redirect_to_fellow_controller - redirect_to :controller => "user" + redirect_to controller: "user" end def redirect_to_top_level_named_route - redirect_to top_level_url(:id => "foo") + redirect_to top_level_url(id: "foo") end end end @@ -167,7 +167,7 @@ class ActionPackAssertionsControllerTest < ActionController::TestCase def test_string_constraint with_routing do |set| set.draw do - get "photos", :to => "action_pack_assertions#nothing", :constraints => {:subdomain => "admin"} + get "photos", to: "action_pack_assertions#nothing", constraints: {subdomain: "admin"} end end end @@ -175,8 +175,8 @@ class ActionPackAssertionsControllerTest < ActionController::TestCase def test_assert_redirect_to_named_route_failure with_routing do |set| set.draw do - get "route_one", :to => "action_pack_assertions#nothing", :as => :route_one - get "route_two", :to => "action_pack_assertions#nothing", :id => "two", :as => :route_two + get "route_one", to: "action_pack_assertions#nothing", as: :route_one + get "route_two", to: "action_pack_assertions#nothing", id: "two", as: :route_two ActiveSupport::Deprecation.silence do get ":controller/:action" @@ -190,7 +190,7 @@ class ActionPackAssertionsControllerTest < ActionController::TestCase assert_redirected_to %r(^http://test.host/route_two) end assert_raise(ActiveSupport::TestCase::Assertion) do - assert_redirected_to :controller => "action_pack_assertions", :action => "nothing", :id => "two" + assert_redirected_to controller: "action_pack_assertions", action: "nothing", id: "two" end assert_raise(ActiveSupport::TestCase::Assertion) do assert_redirected_to route_two_url @@ -203,7 +203,7 @@ class ActionPackAssertionsControllerTest < ActionController::TestCase with_routing do |set| set.draw do - get "admin/inner_module", :to => "admin/inner_module#index", :as => :admin_inner_module + get "admin/inner_module", to: "admin/inner_module#index", as: :admin_inner_module ActiveSupport::Deprecation.silence do get ":controller/:action" @@ -220,7 +220,7 @@ class ActionPackAssertionsControllerTest < ActionController::TestCase with_routing do |set| set.draw do - get "/action_pack_assertions/:id", :to => "action_pack_assertions#index", :as => :top_level + get "/action_pack_assertions/:id", to: "action_pack_assertions#index", as: :top_level ActiveSupport::Deprecation.silence do get ":controller/:action" @@ -239,7 +239,7 @@ class ActionPackAssertionsControllerTest < ActionController::TestCase with_routing do |set| set.draw do # this controller exists in the admin namespace as well which is the only difference from previous test - get "/user/:id", :to => "user#index", :as => :top_level + get "/user/:id", to: "user#index", as: :top_level ActiveSupport::Deprecation.silence do get ":controller/:action" @@ -376,13 +376,13 @@ class ActionPackAssertionsControllerTest < ActionController::TestCase def test_assert_redirection_fails_with_incorrect_controller process :redirect_to_controller assert_raise(ActiveSupport::TestCase::Assertion) do - assert_redirected_to :controller => "action_pack_assertions", :action => "flash_me" + assert_redirected_to controller: "action_pack_assertions", action: "flash_me" end end def test_assert_redirection_with_extra_controller_option get :redirect_to_action - assert_redirected_to :controller => "action_pack_assertions", :action => "flash_me", :id => 1, :params => { :panda => "fun" } + assert_redirected_to controller: "action_pack_assertions", action: "flash_me", id: 1, params: { panda: "fun" } end def test_redirected_to_url_leading_slash @@ -410,21 +410,21 @@ class ActionPackAssertionsControllerTest < ActionController::TestCase def test_assert_redirection_with_symbol process :redirect_to_controller_with_symbol assert_nothing_raised { - assert_redirected_to :controller => "elsewhere", :action => "flash_me" + assert_redirected_to controller: "elsewhere", action: "flash_me" } process :redirect_to_controller_with_symbol assert_nothing_raised { - assert_redirected_to :controller => :elsewhere, :action => :flash_me + assert_redirected_to controller: :elsewhere, action: :flash_me } end def test_redirected_to_with_nested_controller @controller = Admin::InnerModuleController.new get :redirect_to_absolute_controller - assert_redirected_to :controller => "/content" + assert_redirected_to controller: "/content" get :redirect_to_fellow_controller - assert_redirected_to :controller => "admin/user" + assert_redirected_to controller: "admin/user" end def test_assert_response_uses_exception_message diff --git a/actionpack/test/controller/base_test.rb b/actionpack/test/controller/base_test.rb index feb806c953..ec6441fe61 100644 --- a/actionpack/test/controller/base_test.rb +++ b/actionpack/test/controller/base_test.rb @@ -19,11 +19,11 @@ end class DefaultUrlOptionsController < ActionController::Base def from_view - render :inline => "<%= #{params[:route]} %>" + render inline: "<%= #{params[:route]} %>" end def default_url_options - { :host => "www.override.com", :action => "new", :locale => "en" } + { host: "www.override.com", action: "new", locale: "en" } end end @@ -39,11 +39,11 @@ end class UrlOptionsController < ActionController::Base def from_view - render :inline => "<%= #{params[:route]} %>" + render inline: "<%= #{params[:route]} %>" end def url_options - super.merge(:host => "www.override.com") + super.merge(host: "www.override.com") end end @@ -162,10 +162,10 @@ class UrlOptionsTest < ActionController::TestCase end options = { - :action => "home", - :controller => "pages", - :only_path => true, - :params => { "token" => "secret" } + action: "home", + controller: "pages", + only_path: true, + params: { "token" => "secret" } } assert_equal "/home?token=secret", rs.url_for(options) @@ -174,7 +174,7 @@ class UrlOptionsTest < ActionController::TestCase def test_url_options_override with_routing do |set| set.draw do - get "from_view", :to => "url_options#from_view", :as => :from_view + get "from_view", to: "url_options#from_view", as: :from_view ActiveSupport::Deprecation.silence do get ":controller/:action" @@ -185,7 +185,7 @@ class UrlOptionsTest < ActionController::TestCase assert_equal "http://www.override.com/from_view", @response.body assert_equal "http://www.override.com/from_view", @controller.send(:from_view_url) - assert_equal "http://www.override.com/default_url_options/index", @controller.url_for(:controller => "default_url_options") + assert_equal "http://www.override.com/default_url_options/index", @controller.url_for(controller: "default_url_options") end end @@ -211,7 +211,7 @@ class DefaultUrlOptionsTest < ActionController::TestCase def test_default_url_options_override with_routing do |set| set.draw do - get "from_view", :to => "default_url_options#from_view", :as => :from_view + get "from_view", to: "default_url_options#from_view", as: :from_view ActiveSupport::Deprecation.silence do get ":controller/:action" @@ -222,7 +222,7 @@ class DefaultUrlOptionsTest < ActionController::TestCase assert_equal "http://www.override.com/from_view?locale=en", @response.body assert_equal "http://www.override.com/from_view?locale=en", @controller.send(:from_view_url) - assert_equal "http://www.override.com/default_url_options/new?locale=en", @controller.url_for(:controller => "default_url_options") + assert_equal "http://www.override.com/default_url_options/new?locale=en", @controller.url_for(controller: "default_url_options") end end @@ -243,14 +243,14 @@ class DefaultUrlOptionsTest < ActionController::TestCase assert_equal "/en/descriptions/1", @response.body assert_equal "/en/descriptions", @controller.send(:descriptions_path) assert_equal "/pl/descriptions", @controller.send(:descriptions_path, "pl") - assert_equal "/pl/descriptions", @controller.send(:descriptions_path, :locale => "pl") + assert_equal "/pl/descriptions", @controller.send(:descriptions_path, locale: "pl") assert_equal "/pl/descriptions.xml", @controller.send(:descriptions_path, "pl", "xml") - assert_equal "/en/descriptions.xml", @controller.send(:descriptions_path, :format => "xml") + assert_equal "/en/descriptions.xml", @controller.send(:descriptions_path, format: "xml") assert_equal "/en/descriptions/1", @controller.send(:description_path, 1) assert_equal "/pl/descriptions/1", @controller.send(:description_path, "pl", 1) - assert_equal "/pl/descriptions/1", @controller.send(:description_path, 1, :locale => "pl") + assert_equal "/pl/descriptions/1", @controller.send(:description_path, 1, locale: "pl") assert_equal "/pl/descriptions/1.xml", @controller.send(:description_path, "pl", 1, "xml") - assert_equal "/en/descriptions/1.xml", @controller.send(:description_path, 1, :format => "xml") + assert_equal "/en/descriptions/1.xml", @controller.send(:description_path, 1, format: "xml") end end end diff --git a/actionpack/test/controller/caching_test.rb b/actionpack/test/controller/caching_test.rb index b302994fe3..5ee0d33c01 100644 --- a/actionpack/test/controller/caching_test.rb +++ b/actionpack/test/controller/caching_test.rb @@ -49,7 +49,7 @@ class FragmentCachingTest < ActionController::TestCase @controller = FragmentCachingTestController.new @controller.perform_caching = true @controller.cache_store = @store - @params = {:controller => "posts", :action => "index"} + @params = {controller: "posts", action: "index"} @controller.params = @params @controller.request = @request @controller.response = @response @@ -58,7 +58,7 @@ class FragmentCachingTest < ActionController::TestCase def test_fragment_cache_key assert_equal "views/what a key", @controller.fragment_cache_key("what a key") assert_equal "views/test.host/fragment_caching_test/some_action", - @controller.fragment_cache_key(:controller => "fragment_caching_test",:action => "some_action") + @controller.fragment_cache_key(controller: "fragment_caching_test",action: "some_action") end def test_read_fragment_with_caching_enabled diff --git a/actionpack/test/controller/content_type_test.rb b/actionpack/test/controller/content_type_test.rb index 467abb00f9..47bc8c4983 100644 --- a/actionpack/test/controller/content_type_test.rb +++ b/actionpack/test/controller/content_type_test.rb @@ -14,7 +14,7 @@ class OldContentTypeController < ActionController::Base # :ported: def render_content_type_from_render - render body: "hello world!", :content_type => Mime[:rss] + render body: "hello world!", content_type: Mime[:rss] end # :ported: @@ -37,7 +37,7 @@ class OldContentTypeController < ActionController::Base def render_change_for_builder response.content_type = Mime[:html] - render :action => "render_default_for_builder" + render action: "render_default_for_builder" end def render_default_content_types_for_respond_to diff --git a/actionpack/test/controller/default_url_options_with_before_action_test.rb b/actionpack/test/controller/default_url_options_with_before_action_test.rb index 0c49c87807..386a0883c5 100644 --- a/actionpack/test/controller/default_url_options_with_before_action_test.rb +++ b/actionpack/test/controller/default_url_options_with_before_action_test.rb @@ -10,11 +10,11 @@ class ControllerWithBeforeActionAndDefaultUrlOptions < ActionController::Base end def redirect - redirect_to :action => "target" + redirect_to action: "target" end def default_url_options - {:locale => "de"} + {locale: "de"} end end diff --git a/actionpack/test/controller/filters_test.rb b/actionpack/test/controller/filters_test.rb index 089c841956..0ddf825864 100644 --- a/actionpack/test/controller/filters_test.rb +++ b/actionpack/test/controller/filters_test.rb @@ -21,7 +21,7 @@ class FilterTest < ActionController::TestCase after_action :clean_up def show - render :inline => "ran action" + render inline: "ran action" end private @@ -37,7 +37,7 @@ class FilterTest < ActionController::TestCase end class ChangingTheRequirementsController < TestController - before_action :ensure_login, :except => [:go_wild] + before_action :ensure_login, except: [:go_wild] def go_wild render plain: "gobble" @@ -72,14 +72,14 @@ class FilterTest < ActionController::TestCase def show @ran_action = true - render :inline => "ran action" + render inline: "ran action" end private def before_action_rendering @ran_filter ||= [] @ran_filter << "before_action_rendering" - render :inline => "something else" + render inline: "something else" end def unreached_after_action @@ -102,19 +102,19 @@ class FilterTest < ActionController::TestCase def show @ran_action = true - render :inline => "ran show action" + render inline: "ran show action" end def target_of_redirection @ran_target_of_redirection = true - render :inline => "ran target_of_redirection action" + render inline: "ran target_of_redirection action" end private def before_action_redirects @ran_filter ||= [] @ran_filter << "before_action_redirects" - redirect_to(:action => "target_of_redirection") + redirect_to(action: "target_of_redirection") end def unreached_after_action @@ -133,15 +133,15 @@ class FilterTest < ActionController::TestCase class ConditionalFilterController < ActionController::Base def show - render :inline => "ran action" + render inline: "ran action" end def another_action - render :inline => "ran action" + render inline: "ran action" end def show_without_action - render :inline => "ran action without action" + render inline: "ran action without action" end private @@ -157,28 +157,28 @@ class FilterTest < ActionController::TestCase end class ConditionalCollectionFilterController < ConditionalFilterController - before_action :ensure_login, :except => [ :show_without_action, :another_action ] + before_action :ensure_login, except: [ :show_without_action, :another_action ] end class OnlyConditionSymController < ConditionalFilterController - before_action :ensure_login, :only => :show + before_action :ensure_login, only: :show end class ExceptConditionSymController < ConditionalFilterController - before_action :ensure_login, :except => :show_without_action + before_action :ensure_login, except: :show_without_action end class BeforeAndAfterConditionController < ConditionalFilterController - before_action :ensure_login, :only => :show - after_action :clean_up_tmp, :only => :show + before_action :ensure_login, only: :show + after_action :clean_up_tmp, only: :show end class OnlyConditionProcController < ConditionalFilterController - before_action(:only => :show) {|c| c.instance_variable_set(:"@ran_proc_action", true) } + before_action(only: :show) {|c| c.instance_variable_set(:"@ran_proc_action", true) } end class ExceptConditionProcController < ConditionalFilterController - before_action(:except => :show_without_action) {|c| c.instance_variable_set(:"@ran_proc_action", true) } + before_action(except: :show_without_action) {|c| c.instance_variable_set(:"@ran_proc_action", true) } end class ConditionalClassFilter @@ -186,24 +186,24 @@ class FilterTest < ActionController::TestCase end class OnlyConditionClassController < ConditionalFilterController - before_action ConditionalClassFilter, :only => :show + before_action ConditionalClassFilter, only: :show end class ExceptConditionClassController < ConditionalFilterController - before_action ConditionalClassFilter, :except => :show_without_action + before_action ConditionalClassFilter, except: :show_without_action end class AnomolousYetValidConditionController < ConditionalFilterController - before_action(ConditionalClassFilter, :ensure_login, Proc.new {|c| c.instance_variable_set(:"@ran_proc_action1", true)}, :except => :show_without_action) { |c| c.instance_variable_set(:"@ran_proc_action2", true)} + before_action(ConditionalClassFilter, :ensure_login, Proc.new {|c| c.instance_variable_set(:"@ran_proc_action1", true)}, except: :show_without_action) { |c| c.instance_variable_set(:"@ran_proc_action2", true)} end class OnlyConditionalOptionsFilter < ConditionalFilterController - before_action :ensure_login, :only => :index, :if => Proc.new {|c| c.instance_variable_set(:"@ran_conditional_index_proc", true) } + before_action :ensure_login, only: :index, if: Proc.new {|c| c.instance_variable_set(:"@ran_conditional_index_proc", true) } end class ConditionalOptionsFilter < ConditionalFilterController - before_action :ensure_login, :if => Proc.new { |c| true } - before_action :clean_up_tmp, :if => Proc.new { |c| false } + before_action :ensure_login, if: Proc.new { |c| true } + before_action :clean_up_tmp, if: Proc.new { |c| false } end class ConditionalOptionsSkipFilter < ConditionalFilterController @@ -255,7 +255,7 @@ class FilterTest < ActionController::TestCase class SkippingAndLimitedController < TestController skip_before_action :ensure_login - before_action :ensure_login, :only => :index + before_action :ensure_login, only: :index def index render plain: "ok" @@ -283,17 +283,17 @@ class FilterTest < ActionController::TestCase end class ConditionalSkippingController < TestController - skip_before_action :ensure_login, :only => [ :login ] - skip_after_action :clean_up, :only => [ :login ] + skip_before_action :ensure_login, only: [ :login ] + skip_after_action :clean_up, only: [ :login ] - before_action :find_user, :only => [ :change_password ] + before_action :find_user, only: [ :change_password ] def login - render :inline => "ran action" + render inline: "ran action" end def change_password - render :inline => "ran action" + render inline: "ran action" end protected @@ -304,8 +304,8 @@ class FilterTest < ActionController::TestCase end class ConditionalParentOfConditionalSkippingController < ConditionalFilterController - before_action :conditional_in_parent_before, :only => [:show, :another_action] - after_action :conditional_in_parent_after, :only => [:show, :another_action] + before_action :conditional_in_parent_before, only: [:show, :another_action] + after_action :conditional_in_parent_after, only: [:show, :another_action] private @@ -321,12 +321,12 @@ class FilterTest < ActionController::TestCase end class ChildOfConditionalParentController < ConditionalParentOfConditionalSkippingController - skip_before_action :conditional_in_parent_before, :only => :another_action - skip_after_action :conditional_in_parent_after, :only => :another_action + skip_before_action :conditional_in_parent_before, only: :another_action + skip_after_action :conditional_in_parent_after, only: :another_action end class AnotherChildOfConditionalParentController < ConditionalParentOfConditionalSkippingController - skip_before_action :conditional_in_parent_before, :only => :show + skip_before_action :conditional_in_parent_before, only: :show end class ProcController < PrependingController @@ -418,7 +418,7 @@ class FilterTest < ActionController::TestCase class OutOfOrder < StandardError; end before_action :first - before_action :second, :only => :foo + before_action :second, only: :foo def foo render plain: "foo" @@ -501,7 +501,7 @@ class FilterTest < ActionController::TestCase after_action :action_three def index - render :inline => "index" + render inline: "index" end private @@ -526,8 +526,8 @@ class FilterTest < ActionController::TestCase end class ImplicitActionsController < ActionController::Base - before_action :find_only, :only => :edit - before_action :find_except, :except => :edit + before_action :find_only, only: :edit + before_action :find_except, except: :edit private @@ -859,14 +859,14 @@ class PostsController < ActionController::Base private def default_action - render :inline => "#{action_name} called" + render inline: "#{action_name} called" end end class ControllerWithSymbolAsFilter < PostsController - around_action :raise_before, :only => :raises_before - around_action :raise_after, :only => :raises_after - around_action :without_exception, :only => :no_raise + around_action :raise_before, only: :raises_before + around_action :raise_after, only: :raises_after + around_action :without_exception, only: :no_raise private def raise_before @@ -898,7 +898,7 @@ class ControllerWithFilterClass < PostsController end end - around_action YieldingFilter, :only => :raises_after + around_action YieldingFilter, only: :raises_after end class ControllerWithFilterInstance < PostsController @@ -909,11 +909,11 @@ class ControllerWithFilterInstance < PostsController end end - around_action YieldingFilter.new, :only => :raises_after + around_action YieldingFilter.new, only: :raises_after end class ControllerWithProcFilter < PostsController - around_action(:only => :no_raise) do |c,b| + around_action(only: :no_raise) do |c,b| c.instance_variable_set(:"@before", true) b.call c.instance_variable_set(:"@after", true) @@ -921,7 +921,7 @@ class ControllerWithProcFilter < PostsController end class ControllerWithNestedFilters < ControllerWithSymbolAsFilter - around_action :raise_before, :raise_after, :without_exception, :only => :raises_both + around_action :raise_before, :raise_after, :without_exception, only: :raises_both end class ControllerWithAllTypesOfFilters < PostsController diff --git a/actionpack/test/controller/flash_test.rb b/actionpack/test/controller/flash_test.rb index 6397407217..4e046b2fc8 100644 --- a/actionpack/test/controller/flash_test.rb +++ b/actionpack/test/controller/flash_test.rb @@ -5,7 +5,7 @@ class FlashTest < ActionController::TestCase class TestController < ActionController::Base def set_flash flash["that"] = "hello" - render :inline => "hello" + render inline: "hello" end def set_flash_now @@ -14,32 +14,32 @@ class FlashTest < ActionController::TestCase flash.now["foo"] ||= "err" @flashy = flash.now["that"] @flash_copy = {}.update flash - render :inline => "hello" + render inline: "hello" end def attempt_to_use_flash_now @flash_copy = {}.update flash @flashy = flash["that"] - render :inline => "hello" + render inline: "hello" end def use_flash @flash_copy = {}.update flash @flashy = flash["that"] - render :inline => "hello" + render inline: "hello" end def use_flash_and_keep_it @flash_copy = {}.update flash @flashy = flash["that"] flash.keep - render :inline => "hello" + render inline: "hello" end def use_flash_and_update_it flash.update("this" => "hello again") @flash_copy = {}.update flash - render :inline => "hello" + render inline: "hello" end def use_flash_after_reset_session @@ -49,7 +49,7 @@ class FlashTest < ActionController::TestCase @flashy_that_reset = flash["that"] flash["this"] = "good-bye" @flashy_this = flash["this"] - render :inline => "hello" + render inline: "hello" end # methods for test_sweep_after_halted_action_chain @@ -66,34 +66,34 @@ class FlashTest < ActionController::TestCase def halt_and_redir flash["foo"] = "bar" - redirect_to :action => "std_action" + redirect_to action: "std_action" @flash_copy = {}.update(flash) end def redirect_with_alert - redirect_to "/nowhere", :alert => "Beware the nowheres!" + redirect_to "/nowhere", alert: "Beware the nowheres!" end def redirect_with_notice - redirect_to "/somewhere", :notice => "Good luck in the somewheres!" + redirect_to "/somewhere", notice: "Good luck in the somewheres!" end def render_with_flash_now_alert flash.now.alert = "Beware the nowheres now!" - render :inline => "hello" + render inline: "hello" end def render_with_flash_now_notice flash.now.notice = "Good luck in the somewheres now!" - render :inline => "hello" + render inline: "hello" end def redirect_with_other_flashes - redirect_to "/wonderland", :flash => { :joyride => "Horses!" } + redirect_to "/wonderland", flash: { joyride: "Horses!" } end def redirect_with_foo_flash - redirect_to "/wonderland", :foo => "for great justice" + redirect_to "/wonderland", foo: "for great justice" end end @@ -172,7 +172,7 @@ class FlashTest < ActionController::TestCase def test_keep_and_discard_return_values flash = ActionDispatch::Flash::FlashHash.new - flash.update(:foo => :foo_indeed, :bar => :bar_indeed) + flash.update(foo: :foo_indeed, bar: :bar_indeed) assert_equal(:foo_indeed, flash.discard(:foo)) # valid key passed assert_nil flash.discard(:unknown) # non existent key passed @@ -256,7 +256,7 @@ class FlashIntegrationTest < ActionDispatch::IntegrationTest end def use_flash - render :inline => "flash: #{flash["that"]}" + render inline: "flash: #{flash["that"]}" end def set_bar @@ -324,12 +324,12 @@ class FlashIntegrationTest < ActionDispatch::IntegrationTest with_routing do |set| set.draw do ActiveSupport::Deprecation.silence do - get ":action", :to => FlashIntegrationTest::TestController + get ":action", to: FlashIntegrationTest::TestController end end @app = self.class.build_app(set) do |middleware| - middleware.use ActionDispatch::Session::CookieStore, :key => SessionKey + middleware.use ActionDispatch::Session::CookieStore, key: SessionKey middleware.use ActionDispatch::Flash middleware.delete ActionDispatch::ShowExceptions end diff --git a/actionpack/test/controller/force_ssl_test.rb b/actionpack/test/controller/force_ssl_test.rb index 5c51f9e29b..8d5e3ce2fe 100644 --- a/actionpack/test/controller/force_ssl_test.rb +++ b/actionpack/test/controller/force_ssl_test.rb @@ -15,15 +15,15 @@ class ForceSSLControllerLevel < ForceSSLController end class ForceSSLCustomOptions < ForceSSLController - force_ssl :host => "secure.example.com", :only => :redirect_host - force_ssl :port => 8443, :only => :redirect_port - force_ssl :subdomain => "secure", :only => :redirect_subdomain - force_ssl :domain => "secure.com", :only => :redirect_domain - force_ssl :path => "/foo", :only => :redirect_path - force_ssl :status => :found, :only => :redirect_status - force_ssl :flash => { :message => "Foo, Bar!" }, :only => :redirect_flash - force_ssl :alert => "Foo, Bar!", :only => :redirect_alert - force_ssl :notice => "Foo, Bar!", :only => :redirect_notice + force_ssl host: "secure.example.com", only: :redirect_host + force_ssl port: 8443, only: :redirect_port + force_ssl subdomain: "secure", only: :redirect_subdomain + force_ssl domain: "secure.com", only: :redirect_domain + force_ssl path: "/foo", only: :redirect_path + force_ssl status: :found, only: :redirect_status + force_ssl flash: { message: "Foo, Bar!" }, only: :redirect_flash + force_ssl alert: "Foo, Bar!", only: :redirect_alert + force_ssl notice: "Foo, Bar!", only: :redirect_notice def force_ssl_action render plain: action_name @@ -53,15 +53,15 @@ class ForceSSLCustomOptions < ForceSSLController end class ForceSSLOnlyAction < ForceSSLController - force_ssl :only => :cheeseburger + force_ssl only: :cheeseburger end class ForceSSLExceptAction < ForceSSLController - force_ssl :except => :banana + force_ssl except: :banana end class ForceSSLIfCondition < ForceSSLController - force_ssl :if => :use_force_ssl? + force_ssl if: :use_force_ssl? def use_force_ssl? action_name == "cheeseburger" @@ -69,7 +69,7 @@ class ForceSSLIfCondition < ForceSSLController end class ForceSSLFlash < ForceSSLController - force_ssl :except => [:banana, :set_flash, :use_flash] + force_ssl except: [:banana, :set_flash, :use_flash] def set_flash flash["that"] = "hello" @@ -79,7 +79,7 @@ class ForceSSLFlash < ForceSSLController def use_flash @flash_copy = {}.update flash @flashy = flash["that"] - render :inline => "hello" + render inline: "hello" end end @@ -251,8 +251,8 @@ class ForceSSLDuplicateRoutesTest < ActionController::TestCase def test_force_ssl_redirects_to_same_path with_routing do |set| set.draw do - get "/foo", :to => "force_ssl_controller_level#banana" - get "/bar", :to => "force_ssl_controller_level#banana" + get "/foo", to: "force_ssl_controller_level#banana" + get "/bar", to: "force_ssl_controller_level#banana" end @request.env["PATH_INFO"] = "/bar" @@ -270,7 +270,7 @@ class ForceSSLFormatTest < ActionController::TestCase def test_force_ssl_redirects_to_same_format with_routing do |set| set.draw do - get "/foo", :to => "force_ssl_controller_level#banana" + get "/foo", to: "force_ssl_controller_level#banana" end get :banana, format: :json @@ -287,8 +287,8 @@ class ForceSSLOptionalSegmentsTest < ActionController::TestCase with_routing do |set| set.draw do scope "(:locale)" do - defaults :locale => "en" do - get "/foo", :to => "force_ssl_controller_level#banana" + defaults locale: "en" do + get "/foo", to: "force_ssl_controller_level#banana" end end end diff --git a/actionpack/test/controller/helper_test.rb b/actionpack/test/controller/helper_test.rb index a8d8d5d798..d18e19f961 100644 --- a/actionpack/test/controller/helper_test.rb +++ b/actionpack/test/controller/helper_test.rb @@ -5,13 +5,13 @@ ActionController::Base.helpers_path = File.expand_path("../../fixtures/helpers", module Fun class GamesController < ActionController::Base def render_hello_world - render :inline => "hello: <%= stratego %>" + render inline: "hello: <%= stratego %>" end end class PdfController < ActionController::Base def test - render :inline => "test: <%= foobar %>" + render inline: "test: <%= foobar %>" end end end @@ -35,11 +35,11 @@ class JustMeController < ActionController::Base clear_helpers def flash - render :inline => "<h1><%= notice %></h1>" + render inline: "<h1><%= notice %></h1>" end def lib - render :inline => "<%= useful_function %>" + render inline: "<%= useful_function %>" end end @@ -56,7 +56,7 @@ class HelpersPathsController < ActionController::Base helper :all def index - render :inline => "<%= conflicting_helper %>" + render inline: "<%= conflicting_helper %>" end end @@ -251,7 +251,7 @@ end class IsolatedHelpersTest < ActionController::TestCase class A < ActionController::Base def index - render :inline => "<%= shout %>" + render inline: "<%= shout %>" end end @@ -259,7 +259,7 @@ class IsolatedHelpersTest < ActionController::TestCase helper { def shout; "B" end } def index - render :inline => "<%= shout %>" + render inline: "<%= shout %>" end end @@ -267,7 +267,7 @@ class IsolatedHelpersTest < ActionController::TestCase helper { def shout; "C" end } def index - render :inline => "<%= shout %>" + render inline: "<%= shout %>" end end diff --git a/actionpack/test/controller/http_basic_authentication_test.rb b/actionpack/test/controller/http_basic_authentication_test.rb index 26947dd2d2..c980d0ed35 100644 --- a/actionpack/test/controller/http_basic_authentication_test.rb +++ b/actionpack/test/controller/http_basic_authentication_test.rb @@ -7,7 +7,7 @@ class HttpBasicAuthenticationTest < ActionController::TestCase before_action :authenticate_long_credentials, only: :show before_action :auth_with_special_chars, only: :special_creds - http_basic_authenticate_with :name => "David", :password => "Goliath", :only => :search + http_basic_authenticate_with name: "David", password: "Goliath", only: :search def index render plain: "Hello Secret" diff --git a/actionpack/test/controller/http_digest_authentication_test.rb b/actionpack/test/controller/http_digest_authentication_test.rb index 75ae288d4c..854ec62774 100644 --- a/actionpack/test/controller/http_digest_authentication_test.rb +++ b/actionpack/test/controller/http_digest_authentication_test.rb @@ -51,7 +51,7 @@ class HttpDigestAuthenticationTest < ActionController::TestCase AUTH_HEADERS.each do |header| test "successful authentication with #{header.downcase}" do - @request.env[header] = encode_credentials(:username => "lifo", :password => "world") + @request.env[header] = encode_credentials(username: "lifo", password: "world") get :index assert_response :success @@ -61,7 +61,7 @@ class HttpDigestAuthenticationTest < ActionController::TestCase AUTH_HEADERS.each do |header| test "unsuccessful authentication with #{header.downcase}" do - @request.env[header] = encode_credentials(:username => "h4x0r", :password => "world") + @request.env[header] = encode_credentials(username: "h4x0r", password: "world") get :index assert_response :unauthorized @@ -79,7 +79,7 @@ class HttpDigestAuthenticationTest < ActionController::TestCase end test "authentication request with nil credentials" do - @request.env["HTTP_AUTHORIZATION"] = encode_credentials(:username => nil, :password => nil) + @request.env["HTTP_AUTHORIZATION"] = encode_credentials(username: nil, password: nil) get :index assert_response :unauthorized @@ -88,7 +88,7 @@ class HttpDigestAuthenticationTest < ActionController::TestCase end test "authentication request with invalid password" do - @request.env["HTTP_AUTHORIZATION"] = encode_credentials(:username => "pretty", :password => "foo") + @request.env["HTTP_AUTHORIZATION"] = encode_credentials(username: "pretty", password: "foo") get :display assert_response :unauthorized @@ -96,7 +96,7 @@ class HttpDigestAuthenticationTest < ActionController::TestCase end test "authentication request with invalid nonce" do - @request.env["HTTP_AUTHORIZATION"] = encode_credentials(:username => "pretty", :password => "please", :nonce => "xxyyzz") + @request.env["HTTP_AUTHORIZATION"] = encode_credentials(username: "pretty", password: "please", nonce: "xxyyzz") get :display assert_response :unauthorized @@ -104,7 +104,7 @@ class HttpDigestAuthenticationTest < ActionController::TestCase end test "authentication request with invalid opaque" do - @request.env["HTTP_AUTHORIZATION"] = encode_credentials(:username => "pretty", :password => "foo", :opaque => "xxyyzz") + @request.env["HTTP_AUTHORIZATION"] = encode_credentials(username: "pretty", password: "foo", opaque: "xxyyzz") get :display assert_response :unauthorized @@ -112,7 +112,7 @@ class HttpDigestAuthenticationTest < ActionController::TestCase end test "authentication request with invalid realm" do - @request.env["HTTP_AUTHORIZATION"] = encode_credentials(:username => "pretty", :password => "foo", :realm => "NotSecret") + @request.env["HTTP_AUTHORIZATION"] = encode_credentials(username: "pretty", password: "foo", realm: "NotSecret") get :display assert_response :unauthorized @@ -120,7 +120,7 @@ class HttpDigestAuthenticationTest < ActionController::TestCase end test "authentication request with valid credential" do - @request.env["HTTP_AUTHORIZATION"] = encode_credentials(:username => "pretty", :password => "please") + @request.env["HTTP_AUTHORIZATION"] = encode_credentials(username: "pretty", password: "please") get :display assert_response :success @@ -128,7 +128,7 @@ class HttpDigestAuthenticationTest < ActionController::TestCase end test "authentication request with valid credential and nil session" do - @request.env["HTTP_AUTHORIZATION"] = encode_credentials(:username => "pretty", :password => "please") + @request.env["HTTP_AUTHORIZATION"] = encode_credentials(username: "pretty", password: "please") get :display @@ -137,7 +137,7 @@ class HttpDigestAuthenticationTest < ActionController::TestCase end test "authentication request with request-uri that doesn't match credentials digest-uri" do - @request.env["HTTP_AUTHORIZATION"] = encode_credentials(:username => "pretty", :password => "please") + @request.env["HTTP_AUTHORIZATION"] = encode_credentials(username: "pretty", password: "please") @request.env["PATH_INFO"] = "/proxied/uri" get :display @@ -146,7 +146,7 @@ class HttpDigestAuthenticationTest < ActionController::TestCase end test "authentication request with absolute request uri (as in webrick)" do - @request.env["HTTP_AUTHORIZATION"] = encode_credentials(:username => "pretty", :password => "please") + @request.env["HTTP_AUTHORIZATION"] = encode_credentials(username: "pretty", password: "please") @request.env["SERVER_NAME"] = "test.host" @request.env["PATH_INFO"] = "/http_digest_authentication_test/dummy_digest" @@ -157,8 +157,8 @@ class HttpDigestAuthenticationTest < ActionController::TestCase end test "authentication request with absolute uri in credentials (as in IE)" do - @request.env["HTTP_AUTHORIZATION"] = encode_credentials(:url => "http://test.host/http_digest_authentication_test/dummy_digest", - :username => "pretty", :password => "please") + @request.env["HTTP_AUTHORIZATION"] = encode_credentials(url: "http://test.host/http_digest_authentication_test/dummy_digest", + username: "pretty", password: "please") get :display @@ -167,8 +167,8 @@ class HttpDigestAuthenticationTest < ActionController::TestCase end test "authentication request with absolute uri in both request and credentials (as in Webrick with IE)" do - @request.env["HTTP_AUTHORIZATION"] = encode_credentials(:url => "http://test.host/http_digest_authentication_test/dummy_digest", - :username => "pretty", :password => "please") + @request.env["HTTP_AUTHORIZATION"] = encode_credentials(url: "http://test.host/http_digest_authentication_test/dummy_digest", + username: "pretty", password: "please") @request.env["SERVER_NAME"] = "test.host" @request.env["PATH_INFO"] = "/http_digest_authentication_test/dummy_digest" @@ -179,9 +179,9 @@ class HttpDigestAuthenticationTest < ActionController::TestCase end test "authentication request with password stored as ha1 digest hash" do - @request.env["HTTP_AUTHORIZATION"] = encode_credentials(:username => "dhh", - :password => ::Digest::MD5::hexdigest(["dhh","SuperSecret","secret"].join(":")), - :password_is_ha1 => true) + @request.env["HTTP_AUTHORIZATION"] = encode_credentials(username: "dhh", + password: ::Digest::MD5::hexdigest(["dhh","SuperSecret","secret"].join(":")), + password_is_ha1: true) get :display assert_response :success @@ -189,7 +189,7 @@ class HttpDigestAuthenticationTest < ActionController::TestCase end test "authentication request with _method" do - @request.env["HTTP_AUTHORIZATION"] = encode_credentials(:username => "pretty", :password => "please", :method => :post) + @request.env["HTTP_AUTHORIZATION"] = encode_credentials(username: "pretty", password: "please", method: :post) @request.env["rack.methodoverride.original_method"] = "POST" put :display @@ -198,13 +198,13 @@ class HttpDigestAuthenticationTest < ActionController::TestCase end test "validate_digest_response should fail with nil returning password_procedure" do - @request.env["HTTP_AUTHORIZATION"] = encode_credentials(:username => nil, :password => nil) + @request.env["HTTP_AUTHORIZATION"] = encode_credentials(username: nil, password: nil) assert !ActionController::HttpAuthentication::Digest.validate_digest_response(@request, "SuperSecret"){nil} end test "authentication request with request-uri ending in '/'" do @request.env["PATH_INFO"] = "/http_digest_authentication_test/dummy_digest/" - @request.env["HTTP_AUTHORIZATION"] = encode_credentials(:username => "pretty", :password => "please") + @request.env["HTTP_AUTHORIZATION"] = encode_credentials(username: "pretty", password: "please") # simulate normalizing PATH_INFO @request.env["PATH_INFO"] = "/http_digest_authentication_test/dummy_digest" @@ -216,7 +216,7 @@ class HttpDigestAuthenticationTest < ActionController::TestCase test "authentication request with request-uri ending in '?'" do @request.env["PATH_INFO"] = "/http_digest_authentication_test/dummy_digest/?" - @request.env["HTTP_AUTHORIZATION"] = encode_credentials(:username => "pretty", :password => "please") + @request.env["HTTP_AUTHORIZATION"] = encode_credentials(username: "pretty", password: "please") # simulate normalizing PATH_INFO @request.env["PATH_INFO"] = "/http_digest_authentication_test/dummy_digest" @@ -228,8 +228,8 @@ class HttpDigestAuthenticationTest < ActionController::TestCase test "authentication request with absolute uri in credentials (as in IE) ending with /" do @request.env["PATH_INFO"] = "/http_digest_authentication_test/dummy_digest/" - @request.env["HTTP_AUTHORIZATION"] = encode_credentials(:uri => "http://test.host/http_digest_authentication_test/dummy_digest/", - :username => "pretty", :password => "please") + @request.env["HTTP_AUTHORIZATION"] = encode_credentials(uri: "http://test.host/http_digest_authentication_test/dummy_digest/", + username: "pretty", password: "please") # simulate normalizing PATH_INFO @request.env["PATH_INFO"] = "/http_digest_authentication_test/dummy_digest" @@ -250,7 +250,7 @@ class HttpDigestAuthenticationTest < ActionController::TestCase private def encode_credentials(options) - options.reverse_merge!(:nc => "00000001", :cnonce => "0a4f113b", :password_is_ha1 => false) + options.reverse_merge!(nc: "00000001", cnonce: "0a4f113b", password_is_ha1: false) password = options.delete(:password) # Perform unauthenticated request to retrieve digest parameters to use on subsequent request @@ -269,7 +269,7 @@ class HttpDigestAuthenticationTest < ActionController::TestCase credentials.merge!(options) path_info = @request.env["PATH_INFO"].to_s uri = options[:uri] || path_info - credentials.merge!(:uri => uri) + credentials.merge!(uri: uri) @request.env["ORIGINAL_FULLPATH"] = path_info ActionController::HttpAuthentication::Digest.encode_credentials(method, credentials, password, options[:password_is_ha1]) end diff --git a/actionpack/test/controller/http_token_authentication_test.rb b/actionpack/test/controller/http_token_authentication_test.rb index b741aeb160..206fe18eda 100644 --- a/actionpack/test/controller/http_token_authentication_test.rb +++ b/actionpack/test/controller/http_token_authentication_test.rb @@ -54,7 +54,7 @@ class HttpTokenAuthenticationTest < ActionController::TestCase assert_equal "Hello Secret", @response.body, "Authentication failed for request header #{header}" end test "successful authentication with #{header.downcase} and long credentials" do - @request.env[header] = encode_credentials("1234567890123456789012345678901234567890", :algorithm => "test") + @request.env[header] = encode_credentials("1234567890123456789012345678901234567890", algorithm: "test") get :show assert_response :success diff --git a/actionpack/test/controller/integration_test.rb b/actionpack/test/controller/integration_test.rb index 25a8eb479c..8cda95337c 100644 --- a/actionpack/test/controller/integration_test.rb +++ b/actionpack/test/controller/integration_test.rb @@ -32,7 +32,7 @@ class SessionTest < ActiveSupport::TestCase end def test_request_via_redirect_uses_given_method - path = "/somepath"; args = {:id => "1"}; headers = {"X-Test-Header" => "testvalue"} + path = "/somepath"; args = {id: "1"}; headers = {"X-Test-Header" => "testvalue"} assert_called_with @session, :process, [:put, path, params: args, headers: headers] do @session.stub :redirect?, false do assert_deprecated { @session.request_via_redirect(:put, path, params: args, headers: headers) } @@ -50,7 +50,7 @@ class SessionTest < ActiveSupport::TestCase end def test_request_via_redirect_follows_redirects - path = "/somepath"; args = {:id => "1"}; headers = {"X-Test-Header" => "testvalue"} + path = "/somepath"; args = {id: "1"}; headers = {"X-Test-Header" => "testvalue"} value_series = [true, true, false] assert_called @session, :follow_redirect!, times: 2 do @session.stub :redirect?, ->{ value_series.shift } do @@ -60,7 +60,7 @@ class SessionTest < ActiveSupport::TestCase end def test_request_via_redirect_returns_status - path = "/somepath"; args = {:id => "1"}; headers = {"X-Test-Header" => "testvalue"} + path = "/somepath"; args = {id: "1"}; headers = {"X-Test-Header" => "testvalue"} @session.stub :redirect?, false do @session.stub :status, 200 do assert_deprecated do @@ -403,9 +403,9 @@ class IntegrationProcessTest < ActionDispatch::IntegrationTest respond_to do |format| format.html { render plain: "OK", status: 200 } format.js { render plain: "JS OK", status: 200 } - format.xml { render :xml => "<root></root>", :status => 200 } - format.rss { render :xml => "<root></root>", :status => 200 } - format.atom { render :xml => "<root></root>", :status => 200 } + format.xml { render xml: "<root></root>", status: 200 } + format.rss { render xml: "<root></root>", status: 200 } + format.atom { render xml: "<root></root>", status: 200 } end end @@ -660,7 +660,7 @@ class IntegrationProcessTest < ActionDispatch::IntegrationTest end def test_generate_url_with_controller - assert_equal "http://www.example.com/foo", url_for(:controller => "foo") + assert_equal "http://www.example.com/foo", url_for(controller: "foo") end def test_port_via_host! @@ -747,8 +747,8 @@ class IntegrationProcessTest < ActionDispatch::IntegrationTest get "moved" => redirect("/method") ActiveSupport::Deprecation.silence do - match ":action", :to => controller, :via => [:get, :post], :as => :action - get "get/:action", :to => controller, :as => :get_action + match ":action", to: controller, via: [:get, :post], as: :action + get "get/:action", to: controller, as: :get_action end end @@ -792,7 +792,7 @@ class MetalIntegrationTest < ActionDispatch::IntegrationTest end def test_generate_url_without_controller - assert_equal "http://www.example.com/foo", url_for(:controller => "foo") + assert_equal "http://www.example.com/foo", url_for(controller: "foo") end def test_pass_headers @@ -859,7 +859,7 @@ class ApplicationIntegrationTest < ActionDispatch::IntegrationTest end routes.draw do - get "baz", :to => "application_integration_test/test#index", :as => :baz + get "baz", to: "application_integration_test/test#index", as: :baz end def self.call(*) @@ -867,14 +867,14 @@ class ApplicationIntegrationTest < ActionDispatch::IntegrationTest end routes.draw do - get "", :to => "application_integration_test/test#index", :as => :empty_string + get "", to: "application_integration_test/test#index", as: :empty_string - get "foo", :to => "application_integration_test/test#index", :as => :foo - get "bar", :to => "application_integration_test/test#index", :as => :bar + get "foo", to: "application_integration_test/test#index", as: :foo + get "bar", to: "application_integration_test/test#index", as: :bar mount MountedApp => "/mounted", :as => "mounted" get "fooz" => proc { |env| [ 200, {"X-Cascade" => "pass"}, [ "omg" ] ] }, :anchor => false - get "fooz", :to => "application_integration_test/test#index" + get "fooz", to: "application_integration_test/test#index" end def app @@ -942,7 +942,7 @@ class EnvironmentFilterIntegrationTest < ActionDispatch::IntegrationTest end routes.draw do - match "/post", :to => "environment_filter_integration_test/test#post", :via => :post + match "/post", to: "environment_filter_integration_test/test#post", via: :post end def app @@ -975,7 +975,7 @@ class UrlOptionsIntegrationTest < ActionDispatch::IntegrationTest class BarController < ActionController::Base def default_url_options - { :host => "bar.com" } + { host: "bar.com" } end def index @@ -996,9 +996,9 @@ class UrlOptionsIntegrationTest < ActionDispatch::IntegrationTest end routes.draw do - default_url_options :host => "foo.com" + default_url_options host: "foo.com" - scope :module => "url_options_integration_test" do + scope module: "url_options_integration_test" do get "/foo" => "foo#index", :as => :foos get "/foo/:id" => "foo#show", :as => :foo get "/foo/:id/edit" => "foo#edit", :as => :edit_foo @@ -1038,7 +1038,7 @@ class UrlOptionsIntegrationTest < ActionDispatch::IntegrationTest test "current request path parameters are recalled" do get "/foo/1" assert_response :success - assert_equal "/foo/1/edit", url_for(:action => "edit", :only_path => true) + assert_equal "/foo/1/edit", url_for(action: "edit", only_path: true) end end diff --git a/actionpack/test/controller/live_stream_test.rb b/actionpack/test/controller/live_stream_test.rb index 17dff9542a..6d0bc8244b 100644 --- a/actionpack/test/controller/live_stream_test.rb +++ b/actionpack/test/controller/live_stream_test.rb @@ -307,7 +307,7 @@ module ActionController @controller.error_latch = Concurrent::CountDownLatch.new capture_log_output do |output| - get :overfill_buffer_and_die, :format => "plain" + get :overfill_buffer_and_die, format: "plain" t = Thread.new(response) { |resp| resp.await_commit diff --git a/actionpack/test/controller/log_subscriber_test.rb b/actionpack/test/controller/log_subscriber_test.rb index d853d97f94..dfc0edea69 100644 --- a/actionpack/test/controller/log_subscriber_test.rb +++ b/actionpack/test/controller/log_subscriber_test.rb @@ -4,7 +4,7 @@ require "action_controller/log_subscriber" module Another class LogSubscribersController < ActionController::Base - wrap_parameters :person, :include => :name, :format => :json + wrap_parameters :person, include: :name, format: :json class SpecialException < Exception end @@ -31,7 +31,7 @@ module Another end def data_sender - send_data "cool data", :filename => "file.txt" + send_data "cool data", filename: "file.txt" end def file_sender @@ -39,27 +39,27 @@ module Another end def with_fragment_cache - render :inline => "<%= cache('foo'){ 'bar' } %>" + render inline: "<%= cache('foo'){ 'bar' } %>" end def with_fragment_cache_and_percent_in_key - render :inline => "<%= cache('foo%bar'){ 'Contains % sign in key' } %>" + render inline: "<%= cache('foo%bar'){ 'Contains % sign in key' } %>" end def with_fragment_cache_if_with_true_condition - render :inline => "<%= cache_if(true, 'foo') { 'bar' } %>" + render inline: "<%= cache_if(true, 'foo') { 'bar' } %>" end def with_fragment_cache_if_with_false_condition - render :inline => "<%= cache_if(false, 'foo') { 'bar' } %>" + render inline: "<%= cache_if(false, 'foo') { 'bar' } %>" end def with_fragment_cache_unless_with_false_condition - render :inline => "<%= cache_unless(false, 'foo') { 'bar' } %>" + render inline: "<%= cache_unless(false, 'foo') { 'bar' } %>" end def with_fragment_cache_unless_with_true_condition - render :inline => "<%= cache_unless(true, 'foo') { 'bar' } %>" + render inline: "<%= cache_unless(true, 'foo') { 'bar' } %>" end def with_exception diff --git a/actionpack/test/controller/mime/respond_to_test.rb b/actionpack/test/controller/mime/respond_to_test.rb index ef2d89e1c0..385158b17c 100644 --- a/actionpack/test/controller/mime/respond_to_test.rb +++ b/actionpack/test/controller/mime/respond_to_test.rb @@ -46,7 +46,7 @@ class RespondToController < ActionController::Base def json_xml_or_html respond_to do |type| type.json { render body: "JSON" } - type.xml { render :xml => "XML" } + type.xml { render xml: "XML" } type.html { render body: "HTML" } end end @@ -146,7 +146,7 @@ class RespondToController < ActionController::Base def json_with_callback respond_to do |type| - type.json { render :json => "JS", :callback => "alert" } + type.json { render json: "JS", callback: "alert" } end end @@ -163,8 +163,8 @@ class RespondToController < ActionController::Base request.format = "iphone" if request.env["HTTP_ACCEPT"] == "text/iphone" respond_to do |type| - type.html { @type = "Firefox"; render :action => "iphone_with_html_response_type" } - type.iphone { @type = "iPhone" ; render :action => "iphone_with_html_response_type" } + type.html { @type = "Firefox"; render action: "iphone_with_html_response_type" } + type.iphone { @type = "iPhone" ; render action: "iphone_with_html_response_type" } end end diff --git a/actionpack/test/controller/new_base/content_type_test.rb b/actionpack/test/controller/new_base/content_type_test.rb index 15b899e282..85089bafe2 100644 --- a/actionpack/test/controller/new_base/content_type_test.rb +++ b/actionpack/test/controller/new_base/content_type_test.rb @@ -44,7 +44,7 @@ module ContentType with_routing do |set| set.draw do ActiveSupport::Deprecation.silence do - get ":controller", :action => "index" + get ":controller", action: "index" end end diff --git a/actionpack/test/controller/new_base/middleware_test.rb b/actionpack/test/controller/new_base/middleware_test.rb index 827eb9f31b..0493291c03 100644 --- a/actionpack/test/controller/new_base/middleware_test.rb +++ b/actionpack/test/controller/new_base/middleware_test.rb @@ -56,8 +56,8 @@ module MiddlewareTest end class ActionsController < ActionController::Metal - use MyMiddleware, :only => :show - middleware.insert_before MyMiddleware, ExclaimerMiddleware, :except => :index + use MyMiddleware, only: :show + middleware.insert_before MyMiddleware, ExclaimerMiddleware, except: :index def index self.response_body = "index" diff --git a/actionpack/test/controller/new_base/render_action_test.rb b/actionpack/test/controller/new_base/render_action_test.rb index e42fea3656..b92f86da58 100644 --- a/actionpack/test/controller/new_base/render_action_test.rb +++ b/actionpack/test/controller/new_base/render_action_test.rb @@ -8,7 +8,7 @@ module RenderAction )] def hello_world - render :action => "hello_world" + render action: "hello_world" end def hello_world_as_string @@ -16,7 +16,7 @@ module RenderAction end def hello_world_as_string_with_options - render "hello_world", :status => 404 + render "hello_world", status: 404 end def hello_world_as_symbol @@ -24,23 +24,23 @@ module RenderAction end def hello_world_with_symbol - render :action => :hello_world + render action: :hello_world end def hello_world_with_layout - render :action => "hello_world", :layout => true + render action: "hello_world", layout: true end def hello_world_with_layout_false - render :action => "hello_world", :layout => false + render action: "hello_world", layout: false end def hello_world_with_layout_nil - render :action => "hello_world", :layout => nil + render action: "hello_world", layout: nil end def hello_world_with_custom_layout - render :action => "hello_world", :layout => "greetings" + render action: "hello_world", layout: "greetings" end end @@ -127,27 +127,27 @@ module RenderActionWithApplicationLayout )] def hello_world - render :action => "hello_world" + render action: "hello_world" end def hello_world_with_layout - render :action => "hello_world", :layout => true + render action: "hello_world", layout: true end def hello_world_with_layout_false - render :action => "hello_world", :layout => false + render action: "hello_world", layout: false end def hello_world_with_layout_nil - render :action => "hello_world", :layout => nil + render action: "hello_world", layout: nil end def hello_world_with_custom_layout - render :action => "hello_world", :layout => "greetings" + render action: "hello_world", layout: "greetings" end def with_builder_and_layout - render :action => "hello", :layout => "builder" + render action: "hello", layout: "builder" end end @@ -207,23 +207,23 @@ module RenderActionWithControllerLayout )] def hello_world - render :action => "hello_world" + render action: "hello_world" end def hello_world_with_layout - render :action => "hello_world", :layout => true + render action: "hello_world", layout: true end def hello_world_with_layout_false - render :action => "hello_world", :layout => false + render action: "hello_world", layout: false end def hello_world_with_layout_nil - render :action => "hello_world", :layout => nil + render action: "hello_world", layout: nil end def hello_world_with_custom_layout - render :action => "hello_world", :layout => "greetings" + render action: "hello_world", layout: "greetings" end end @@ -267,19 +267,19 @@ module RenderActionWithBothLayouts })] def hello_world - render :action => "hello_world" + render action: "hello_world" end def hello_world_with_layout - render :action => "hello_world", :layout => true + render action: "hello_world", layout: true end def hello_world_with_layout_false - render :action => "hello_world", :layout => false + render action: "hello_world", layout: false end def hello_world_with_layout_nil - render :action => "hello_world", :layout => nil + render action: "hello_world", layout: nil end end diff --git a/actionpack/test/controller/new_base/render_context_test.rb b/actionpack/test/controller/new_base/render_context_test.rb index 1220349658..5df25d136c 100644 --- a/actionpack/test/controller/new_base/render_context_test.rb +++ b/actionpack/test/controller/new_base/render_context_test.rb @@ -18,12 +18,12 @@ module RenderContext def hello_world @value = "Hello" - render :action => "hello_world", :layout => false + render action: "hello_world", layout: false end def with_layout @value = "Hello" - render :action => "hello_world", :layout => "basic" + render action: "hello_world", layout: "basic" end protected diff --git a/actionpack/test/controller/new_base/render_file_test.rb b/actionpack/test/controller/new_base/render_file_test.rb index b6ba202854..9618157657 100644 --- a/actionpack/test/controller/new_base/render_file_test.rb +++ b/actionpack/test/controller/new_base/render_file_test.rb @@ -5,32 +5,32 @@ module RenderFile self.view_paths = File.dirname(__FILE__) def index - render :file => File.join(File.dirname(__FILE__), *%w[.. .. fixtures test hello_world]) + render file: File.join(File.dirname(__FILE__), *%w[.. .. fixtures test hello_world]) end def with_instance_variables @secret = "in the sauce" - render :file => File.join(File.dirname(__FILE__), "../../fixtures/test/render_file_with_ivar") + render file: File.join(File.dirname(__FILE__), "../../fixtures/test/render_file_with_ivar") end def relative_path @secret = "in the sauce" - render :file => "../../fixtures/test/render_file_with_ivar" + render file: "../../fixtures/test/render_file_with_ivar" end def relative_path_with_dot @secret = "in the sauce" - render :file => "../../fixtures/test/dot.directory/render_file_with_ivar" + render file: "../../fixtures/test/dot.directory/render_file_with_ivar" end def pathname @secret = "in the sauce" - render :file => Pathname.new(File.dirname(__FILE__)).join(*%w[.. .. fixtures test dot.directory render_file_with_ivar]) + render file: Pathname.new(File.dirname(__FILE__)).join(*%w[.. .. fixtures test dot.directory render_file_with_ivar]) end def with_locals path = File.join(File.dirname(__FILE__), "../../fixtures/test/render_file_with_locals") - render :file => path, :locals => {:secret => "in the sauce"} + render file: path, locals: {secret: "in the sauce"} end end diff --git a/actionpack/test/controller/new_base/render_layout_test.rb b/actionpack/test/controller/new_base/render_layout_test.rb index 3b2220729e..b94406d3d3 100644 --- a/actionpack/test/controller/new_base/render_layout_test.rb +++ b/actionpack/test/controller/new_base/render_layout_test.rb @@ -10,15 +10,15 @@ module ControllerLayouts )] def index - render :template => "basic" + render template: "basic" end def override - render :template => "basic", :layout => "override" + render template: "basic", layout: "override" end def layout_false - render :layout => false + render layout: false end def builder_override @@ -32,7 +32,7 @@ module ControllerLayouts )] def index - render :template => "basic" + render template: "basic" end end @@ -76,7 +76,7 @@ module ControllerLayouts )] def explicit - render :layout => "application" + render layout: "application" end end diff --git a/actionpack/test/controller/new_base/render_partial_test.rb b/actionpack/test/controller/new_base/render_partial_test.rb index 0438773b06..68455582f1 100644 --- a/actionpack/test/controller/new_base/render_partial_test.rb +++ b/actionpack/test/controller/new_base/render_partial_test.rb @@ -16,12 +16,12 @@ module RenderPartial )] def html_with_json_inside_json - render :action => "with_json" + render action: "with_json" end def changing @test_unchanged = "hello" - render :action => "basic" + render action: "basic" end def overridden diff --git a/actionpack/test/controller/new_base/render_streaming_test.rb b/actionpack/test/controller/new_base/render_streaming_test.rb index 97fc3b41e0..5cd8f82323 100644 --- a/actionpack/test/controller/new_base/render_streaming_test.rb +++ b/actionpack/test/controller/new_base/render_streaming_test.rb @@ -12,32 +12,32 @@ module RenderStreaming layout "application" def hello_world - render :stream => true + render stream: true end def layout_exception - render :action => "hello_world", :stream => true, :layout => "boom" + render action: "hello_world", stream: true, layout: "boom" end def template_exception - render :action => "boom", :stream => true + render action: "boom", stream: true end def skip - render :action => "hello_world", :stream => false + render action: "hello_world", stream: false end def explicit - render :action => "hello_world", :stream => true + render action: "hello_world", stream: true end def no_layout - render :action => "hello_world", :stream => true, :layout => false + render action: "hello_world", stream: true, layout: false end def explicit_cache headers["Cache-Control"] = "private" - render :action => "hello_world", :stream => true + render action: "hello_world", stream: true end end diff --git a/actionpack/test/controller/new_base/render_template_test.rb b/actionpack/test/controller/new_base/render_template_test.rb index 777143bef1..13e4bbc1ea 100644 --- a/actionpack/test/controller/new_base/render_template_test.rb +++ b/actionpack/test/controller/new_base/render_template_test.rb @@ -18,11 +18,11 @@ module RenderTemplate )] def index - render :template => "test/basic" + render template: "test/basic" end def html_with_json_inside_json - render :template => "test/with_json" + render template: "test/with_json" end def index_without_key @@ -30,11 +30,11 @@ module RenderTemplate end def in_top_directory - render :template => "shared" + render template: "shared" end def in_top_directory_with_slash - render :template => "/shared" + render template: "/shared" end def in_top_directory_with_slash_without_key @@ -42,27 +42,27 @@ module RenderTemplate end def with_locals - render :template => "locals", :locals => { :secret => "area51" } + render template: "locals", locals: { secret: "area51" } end def with_locals_without_key - render "locals", :locals => { :secret => "area51" } + render "locals", locals: { secret: "area51" } end def builder_template - render :template => "xml_template" + render template: "xml_template" end def with_raw - render :template => "with_raw" + render template: "with_raw" end def with_implicit_raw - render :template => "with_implicit_raw" + render template: "with_implicit_raw" end def with_error - render :template => "test/with_error" + render template: "test/with_error" end private @@ -154,30 +154,30 @@ module RenderTemplate )] def index - render :template => "test/basic" + render template: "test/basic" end def with_layout - render :template => "test/basic", :layout => true + render template: "test/basic", layout: true end def with_layout_false - render :template => "test/basic", :layout => false + render template: "test/basic", layout: false end def with_layout_nil - render :template => "test/basic", :layout => nil + render template: "test/basic", layout: nil end def with_custom_layout - render :template => "test/basic", :layout => "greetings" + render template: "test/basic", layout: "greetings" end end class TestWithLayout < Rack::TestCase test "rendering with implicit layout" do with_routing do |set| - set.draw { ActiveSupport::Deprecation.silence { get ":controller", :action => :index } } + set.draw { ActiveSupport::Deprecation.silence { get ":controller", action: :index } } get "/render_template/with_layout" @@ -223,7 +223,7 @@ module RenderTemplate )] def with_forward_slash - render :template => "/test/basic" + render template: "/test/basic" end end diff --git a/actionpack/test/controller/new_base/render_test.rb b/actionpack/test/controller/new_base/render_test.rb index 494f70abb7..57006b2da0 100644 --- a/actionpack/test/controller/new_base/render_test.rb +++ b/actionpack/test/controller/new_base/render_test.rb @@ -18,11 +18,11 @@ module Render end def access_request - render :action => "access_request" + render action: "access_request" end def render_action_name - render :action => "access_action_name" + render action: "access_action_name" end def overridden_with_own_view_paths_appended @@ -58,7 +58,7 @@ module Render with_routing do |set| set.draw do ActiveSupport::Deprecation.silence do - get ":controller", :action => "index" + get ":controller", action: "index" end end @@ -73,7 +73,7 @@ module Render with_routing do |set| set.draw do ActiveSupport::Deprecation.silence do - get ":controller", :action => "index" + get ":controller", action: "index" end end diff --git a/actionpack/test/controller/parameters/nested_parameters_permit_test.rb b/actionpack/test/controller/parameters/nested_parameters_permit_test.rb index 34c2e49fb6..f3c1caee61 100644 --- a/actionpack/test/controller/parameters/nested_parameters_permit_test.rb +++ b/actionpack/test/controller/parameters/nested_parameters_permit_test.rb @@ -134,9 +134,9 @@ class NestedParametersPermitTest < ActiveSupport::TestCase params = ActionController::Parameters.new({ book: { authors_attributes: { - :'0' => { name: "William Shakespeare", age_of_death: "52" }, - :'1' => { name: "Unattributed Assistant" }, - :'2' => { name: %w(injected names) } + '0': { name: "William Shakespeare", age_of_death: "52" }, + '1': { name: "Unattributed Assistant" }, + '2': { name: %w(injected names) } } } }) @@ -155,8 +155,8 @@ class NestedParametersPermitTest < ActiveSupport::TestCase params = ActionController::Parameters.new({ book: { authors_attributes: { - :'-1' => { name: "William Shakespeare", age_of_death: "52" }, - :'-2' => { name: "Unattributed Assistant" } + '-1': { name: "William Shakespeare", age_of_death: "52" }, + '-2': { name: "Unattributed Assistant" } } } }) @@ -179,7 +179,7 @@ class NestedParametersPermitTest < ActiveSupport::TestCase } } }) - params = params.require(:product).permit(:properties => ["0"]) + params = params.require(:product).permit(properties: ["0"]) assert_not_nil params[:properties]["0"] assert_nil params[:properties]["1"] assert_equal "prop0", params[:properties]["0"] diff --git a/actionpack/test/controller/params_wrapper_test.rb b/actionpack/test/controller/params_wrapper_test.rb index d74e24437a..c1f1f33dc0 100644 --- a/actionpack/test/controller/params_wrapper_test.rb +++ b/actionpack/test/controller/params_wrapper_test.rb @@ -4,7 +4,7 @@ module Admin; class User; end; end module ParamsWrapperTestHelp def with_default_wrapper_options(&block) - @controller.class._set_wrapper_options({:format => [:json]}) + @controller.class._set_wrapper_options({format: [:json]}) @controller.class.inherited(@controller.class) yield end @@ -84,7 +84,7 @@ class ParamsWrapperTest < ActionController::TestCase def test_specify_include_option with_default_wrapper_options do - UsersController.wrap_parameters :include => :username + UsersController.wrap_parameters include: :username @request.env["CONTENT_TYPE"] = "application/json" post :parse, params: { "username" => "sikachu", "title" => "Developer" } @@ -94,7 +94,7 @@ class ParamsWrapperTest < ActionController::TestCase def test_specify_exclude_option with_default_wrapper_options do - UsersController.wrap_parameters :exclude => :title + UsersController.wrap_parameters exclude: :title @request.env["CONTENT_TYPE"] = "application/json" post :parse, params: { "username" => "sikachu", "title" => "Developer" } @@ -104,7 +104,7 @@ class ParamsWrapperTest < ActionController::TestCase def test_specify_both_wrapper_name_and_include_option with_default_wrapper_options do - UsersController.wrap_parameters :person, :include => :username + UsersController.wrap_parameters :person, include: :username @request.env["CONTENT_TYPE"] = "application/json" post :parse, params: { "username" => "sikachu", "title" => "Developer" } @@ -131,7 +131,7 @@ class ParamsWrapperTest < ActionController::TestCase def test_specify_format with_default_wrapper_options do - UsersController.wrap_parameters :format => :xml + UsersController.wrap_parameters format: :xml @request.env["CONTENT_TYPE"] = "application/xml" post :parse, params: { "username" => "sikachu", "title" => "Developer" } @@ -310,7 +310,7 @@ class AnonymousControllerParamsWrapperTest < ActionController::TestCase def test_does_wrap_params_if_name_provided with_default_wrapper_options do - @controller.class.wrap_parameters(:name => "guest") + @controller.class.wrap_parameters(name: "guest") @request.env["CONTENT_TYPE"] = "application/json" post :parse, params: { "username" => "sikachu" } assert_parameters({ "username" => "sikachu", "guest" => { "username" => "sikachu" }}) diff --git a/actionpack/test/controller/redirect_test.rb b/actionpack/test/controller/redirect_test.rb index ac165a9b32..9ce647d26e 100644 --- a/actionpack/test/controller/redirect_test.rb +++ b/actionpack/test/controller/redirect_test.rb @@ -25,39 +25,39 @@ class RedirectController < ActionController::Base def location; render plain: "called location"; end def simple_redirect - redirect_to :action => "hello_world" + redirect_to action: "hello_world" end def redirect_with_status - redirect_to({:action => "hello_world", :status => 301}) + redirect_to({action: "hello_world", status: 301}) end def redirect_with_status_hash - redirect_to({:action => "hello_world"}, {:status => 301}) + redirect_to({action: "hello_world"}, {status: 301}) end def redirect_with_protocol - redirect_to :action => "hello_world", :protocol => "https" + redirect_to action: "hello_world", protocol: "https" end def url_redirect_with_status - redirect_to("http://www.example.com", :status => :moved_permanently) + redirect_to("http://www.example.com", status: :moved_permanently) end def url_redirect_with_status_hash - redirect_to("http://www.example.com", {:status => 301}) + redirect_to("http://www.example.com", {status: 301}) end def relative_url_redirect_with_status - redirect_to("/things/stuff", :status => :found) + redirect_to("/things/stuff", status: :found) end def relative_url_redirect_with_status_hash - redirect_to("/things/stuff", {:status => 301}) + redirect_to("/things/stuff", {status: 301}) end def redirect_to_back_with_status - redirect_to :back, :status => 307 + redirect_to :back, status: 307 end def redirect_back_with_status @@ -65,11 +65,11 @@ class RedirectController < ActionController::Base end def host_redirect - redirect_to :action => "other_host", :only_path => false, :host => "other.test.host" + redirect_to action: "other_host", only_path: false, host: "other.test.host" end def module_redirect - redirect_to :controller => "module_test/module_redirect", :action => "hello_world" + redirect_to controller: "module_test/module_redirect", action: "hello_world" end def redirect_to_url @@ -118,7 +118,7 @@ class RedirectController < ActionController::Base end def redirect_to_with_block_and_options - redirect_to proc { {:action => "hello_world"} } + redirect_to proc { {action: "hello_world"} } end def redirect_with_header_break @@ -133,7 +133,7 @@ class RedirectController < ActionController::Base protected def dashbord_url(id, message) - url_for :action => "dashboard", :params => { "id" => id, "message" => message } + url_for action: "dashboard", params: { "id" => id, "message" => message } end end @@ -220,7 +220,7 @@ class RedirectTest < ActionController::TestCase def test_simple_redirect_using_options get :host_redirect assert_response :redirect - assert_redirected_to :action => "other_host", :only_path => false, :host => "other.test.host" + assert_redirected_to action: "other_host", only_path: false, host: "other.test.host" end def test_module_redirect @@ -232,7 +232,7 @@ class RedirectTest < ActionController::TestCase def test_module_redirect_using_options get :module_redirect assert_response :redirect - assert_redirected_to :controller => "module_test/module_redirect", :action => "hello_world" + assert_redirected_to controller: "module_test/module_redirect", action: "hello_world" end def test_redirect_to_url @@ -364,7 +364,7 @@ end module ModuleTest class ModuleRedirectController < ::RedirectController def module_redirect - redirect_to :controller => "/redirect", :action => "hello_world" + redirect_to controller: "/redirect", action: "hello_world" end end @@ -380,7 +380,7 @@ module ModuleTest def test_simple_redirect_using_options get :host_redirect assert_response :redirect - assert_redirected_to :action => "other_host", :only_path => false, :host => "other.test.host" + assert_redirected_to action: "other_host", only_path: false, host: "other.test.host" end def test_module_redirect @@ -392,7 +392,7 @@ module ModuleTest def test_module_redirect_using_options get :module_redirect assert_response :redirect - assert_redirected_to :controller => "/redirect", :action => "hello_world" + assert_redirected_to controller: "/redirect", action: "hello_world" end end end diff --git a/actionpack/test/controller/render_js_test.rb b/actionpack/test/controller/render_js_test.rb index e65492e2de..290218d4a2 100644 --- a/actionpack/test/controller/render_js_test.rb +++ b/actionpack/test/controller/render_js_test.rb @@ -11,11 +11,11 @@ class RenderJSTest < ActionController::TestCase end def render_vanilla_js_hello - render :js => "alert('hello')" + render js: "alert('hello')" end def show_partial - render :partial => "partial" + render partial: "partial" end end diff --git a/actionpack/test/controller/render_json_test.rb b/actionpack/test/controller/render_json_test.rb index 07839ce91f..69fbf59905 100644 --- a/actionpack/test/controller/render_json_test.rb +++ b/actionpack/test/controller/render_json_test.rb @@ -6,13 +6,13 @@ require "pathname" class RenderJsonTest < ActionController::TestCase class JsonRenderable def as_json(options={}) - hash = { :a => :b, :c => :d, :e => :f } + hash = { a: :b, c: :d, e: :f } hash.except!(*options[:except]) if options[:except] hash end def to_json(options = {}) - super :except => [:c, :e] + super except: [:c, :e] end end @@ -24,7 +24,7 @@ class RenderJsonTest < ActionController::TestCase end def render_json_nil - render :json => nil + render json: nil end def render_json_render_to_string @@ -32,35 +32,35 @@ class RenderJsonTest < ActionController::TestCase end def render_json_hello_world - render :json => ActiveSupport::JSON.encode(:hello => "world") + render json: ActiveSupport::JSON.encode(hello: "world") end def render_json_hello_world_with_status - render :json => ActiveSupport::JSON.encode(:hello => "world"), :status => 401 + render json: ActiveSupport::JSON.encode(hello: "world"), status: 401 end def render_json_hello_world_with_callback - render :json => ActiveSupport::JSON.encode(:hello => "world"), :callback => "alert" + render json: ActiveSupport::JSON.encode(hello: "world"), callback: "alert" end def render_json_with_custom_content_type - render :json => ActiveSupport::JSON.encode(:hello => "world"), :content_type => "text/javascript" + render json: ActiveSupport::JSON.encode(hello: "world"), content_type: "text/javascript" end def render_symbol_json - render :json => ActiveSupport::JSON.encode(:hello => "world") + render json: ActiveSupport::JSON.encode(hello: "world") end def render_json_with_render_to_string - render :json => {:hello => render_to_string(:partial => "partial")} + render json: {hello: render_to_string(partial: "partial")} end def render_json_with_extra_options - render :json => JsonRenderable.new, :except => [:c, :e] + render json: JsonRenderable.new, except: [:c, :e] end def render_json_without_options - render :json => JsonRenderable.new + render json: JsonRenderable.new end end diff --git a/actionpack/test/controller/render_test.rb b/actionpack/test/controller/render_test.rb index 528c5c8dee..399c500094 100644 --- a/actionpack/test/controller/render_test.rb +++ b/actionpack/test/controller/render_test.rb @@ -71,8 +71,8 @@ class TestController < ActionController::Base end def conditional_hello - if stale?(:last_modified => Time.now.utc.beginning_of_day, :etag => [:foo, 123]) - render :action => "hello_world" + if stale?(last_modified: Time.now.utc.beginning_of_day, etag: [:foo, 123]) + render action: "hello_world" end end @@ -80,7 +80,7 @@ class TestController < ActionController::Base record = Struct.new(:updated_at, :cache_key).new(Time.now.utc.beginning_of_day, "foo/123") if stale?(record) - render :action => "hello_world" + render action: "hello_world" end end @@ -121,43 +121,43 @@ class TestController < ActionController::Base def conditional_hello_with_expires_in expires_in 60.1.seconds - render :action => "hello_world" + render action: "hello_world" end def conditional_hello_with_expires_in_with_public - expires_in 1.minute, :public => true - render :action => "hello_world" + expires_in 1.minute, public: true + render action: "hello_world" end def conditional_hello_with_expires_in_with_must_revalidate - expires_in 1.minute, :must_revalidate => true - render :action => "hello_world" + expires_in 1.minute, must_revalidate: true + render action: "hello_world" end def conditional_hello_with_expires_in_with_public_and_must_revalidate - expires_in 1.minute, :public => true, :must_revalidate => true - render :action => "hello_world" + expires_in 1.minute, public: true, must_revalidate: true + render action: "hello_world" end def conditional_hello_with_expires_in_with_public_with_more_keys expires_in 1.minute, :public => true, "s-maxage" => 5.hours - render :action => "hello_world" + render action: "hello_world" end def conditional_hello_with_expires_in_with_public_with_more_keys_old_syntax expires_in 1.minute, :public => true, :private => nil, "s-maxage" => 5.hours - render :action => "hello_world" + render action: "hello_world" end def conditional_hello_with_expires_now expires_now - render :action => "hello_world" + render action: "hello_world" end def conditional_hello_with_cache_control_headers response.headers["Cache-Control"] = "no-transform" expires_now - render :action => "hello_world" + render action: "hello_world" end def respond_with_empty_body @@ -165,12 +165,12 @@ class TestController < ActionController::Base end def conditional_hello_with_bangs - render :action => "hello_world" + render action: "hello_world" end - before_action :handle_last_modified_and_etags, :only=>:conditional_hello_with_bangs + before_action :handle_last_modified_and_etags, only: :conditional_hello_with_bangs def handle_last_modified_and_etags - fresh_when(:last_modified => Time.now.utc.beginning_of_day, :etag => [ :foo, 123 ]) + fresh_when(last_modified: Time.now.utc.beginning_of_day, etag: [ :foo, 123 ]) end def head_with_status_hash @@ -186,19 +186,19 @@ class TestController < ActionController::Base end def head_created_with_application_json_content_type - head :created, :content_type => "application/json" + head :created, content_type: "application/json" end def head_ok_with_image_png_content_type - head :ok, :content_type => "image/png" + head :ok, content_type: "image/png" end def head_with_location_header - head :ok, :location => "/foo" + head :ok, location: "/foo" end def head_with_location_object - head :ok, :location => Customer.new("david", 1) + head :ok, location: Customer.new("david", 1) end def head_with_symbolic_status @@ -214,7 +214,7 @@ class TestController < ActionController::Base end def head_with_custom_header - head :ok, :x_custom_header => "something" + head :ok, x_custom_header: "something" end def head_with_www_authenticate_header @@ -222,7 +222,7 @@ class TestController < ActionController::Base end def head_with_status_code_first - head :forbidden, :x_custom_header => "something" + head :forbidden, x_custom_header: "something" end def head_and_return @@ -285,7 +285,7 @@ class MetalTestController < ActionController::Metal include ActionController::Rendering def accessing_logger_in_template - render :inline => "<%= logger.class %>" + render inline: "<%= logger.class %>" end end diff --git a/actionpack/test/controller/render_xml_test.rb b/actionpack/test/controller/render_xml_test.rb index a79700d618..24866d7d6a 100644 --- a/actionpack/test/controller/render_xml_test.rb +++ b/actionpack/test/controller/render_xml_test.rb @@ -18,27 +18,27 @@ class RenderXmlTest < ActionController::TestCase end def render_with_location - render :xml => "<hello/>", :location => "http://example.com", :status => 201 + render xml: "<hello/>", location: "http://example.com", status: 201 end def render_with_object_location customer = Customer.new("Some guy", 1) - render :xml => "<customer/>", :location => customer, :status => :created + render xml: "<customer/>", location: customer, status: :created end def render_with_to_xml - render :xml => XmlRenderable.new + render xml: XmlRenderable.new end def formatted_xml_erb end def render_xml_with_custom_content_type - render :xml => "<blah/>", :content_type => "application/atomsvc+xml" + render xml: "<blah/>", content_type: "application/atomsvc+xml" end def render_xml_with_custom_options - render :xml => XmlRenderable.new, :root => "i-am-THE-xml" + render xml: XmlRenderable.new, root: "i-am-THE-xml" end end diff --git a/actionpack/test/controller/renderers_test.rb b/actionpack/test/controller/renderers_test.rb index b9e4b03804..78d5105794 100644 --- a/actionpack/test/controller/renderers_test.rb +++ b/actionpack/test/controller/renderers_test.rb @@ -11,13 +11,13 @@ class RenderersTest < ActionController::TestCase end class JsonRenderable def as_json(options={}) - hash = { :a => :b, :c => :d, :e => :f } + hash = { a: :b, c: :d, e: :f } hash.except!(*options[:except]) if options[:except] hash end def to_json(options = {}) - super :except => [:c, :e] + super except: [:c, :e] end end class CsvRenderable @@ -28,7 +28,7 @@ class RenderersTest < ActionController::TestCase class TestController < ActionController::Base def render_simon_says - render :simon => "foo" + render simon: "foo" end def respond_to_mime diff --git a/actionpack/test/controller/request_forgery_protection_test.rb b/actionpack/test/controller/request_forgery_protection_test.rb index 7ce8dfa8df..a0e92c1a4a 100644 --- a/actionpack/test/controller/request_forgery_protection_test.rb +++ b/actionpack/test/controller/request_forgery_protection_test.rb @@ -4,11 +4,11 @@ require "active_support/log_subscriber/test_helper" # common controller actions module RequestForgeryProtectionActions def index - render :inline => "<%= form_tag('/') {} %>" + render inline: "<%= form_tag('/') {} %>" end def show_button - render :inline => "<%= button_to('New', '/') %>" + render inline: "<%= button_to('New', '/') %>" end def unsafe @@ -16,23 +16,23 @@ module RequestForgeryProtectionActions end def meta - render :inline => "<%= csrf_meta_tags %>" + render inline: "<%= csrf_meta_tags %>" end def form_for_remote - render :inline => "<%= form_for(:some_resource, :remote => true ) {} %>" + render inline: "<%= form_for(:some_resource, :remote => true ) {} %>" end def form_for_remote_with_token - render :inline => "<%= form_for(:some_resource, :remote => true, :authenticity_token => true ) {} %>" + render inline: "<%= form_for(:some_resource, :remote => true, :authenticity_token => true ) {} %>" end def form_for_with_token - render :inline => "<%= form_for(:some_resource, :authenticity_token => true ) {} %>" + render inline: "<%= form_for(:some_resource, :authenticity_token => true ) {} %>" end def form_for_remote_with_external_token - render :inline => "<%= form_for(:some_resource, :remote => true, :authenticity_token => 'external_token') {} %>" + render inline: "<%= form_for(:some_resource, :remote => true, :authenticity_token => 'external_token') {} %>" end def same_origin_js @@ -58,16 +58,16 @@ end # sample controllers class RequestForgeryProtectionControllerUsingResetSession < ActionController::Base include RequestForgeryProtectionActions - protect_from_forgery :only => %w(index meta same_origin_js negotiate_same_origin), :with => :reset_session + protect_from_forgery only: %w(index meta same_origin_js negotiate_same_origin), with: :reset_session end class RequestForgeryProtectionControllerUsingException < ActionController::Base include RequestForgeryProtectionActions - protect_from_forgery :only => %w(index meta same_origin_js negotiate_same_origin), :with => :exception + protect_from_forgery only: %w(index meta same_origin_js negotiate_same_origin), with: :exception end class RequestForgeryProtectionControllerUsingNullSession < ActionController::Base - protect_from_forgery :with => :null_session + protect_from_forgery with: :null_session def signed cookies.signed[:foo] = "bar" @@ -114,11 +114,11 @@ class FreeCookieController < RequestForgeryProtectionControllerUsingResetSession self.allow_forgery_protection = false def index - render :inline => "<%= form_tag('/') {} %>" + render inline: "<%= form_tag('/') {} %>" end def show_button - render :inline => "<%= button_to('New', '/') %>" + render inline: "<%= button_to('New', '/') %>" end end @@ -129,7 +129,7 @@ class CustomAuthenticityParamController < RequestForgeryProtectionControllerUsin end class PerFormTokensController < ActionController::Base - protect_from_forgery :with => :exception + protect_from_forgery with: :exception self.per_form_csrf_tokens = true def index diff --git a/actionpack/test/controller/rescue_test.rb b/actionpack/test/controller/rescue_test.rb index 7ff2ba5bb6..5b1363d5e1 100644 --- a/actionpack/test/controller/rescue_test.rb +++ b/actionpack/test/controller/rescue_test.rb @@ -34,14 +34,14 @@ class RescueController < ActionController::Base # We use a fully-qualified name in some strings, and a relative constant # name in some other to test correct handling of both cases. - rescue_from NotAuthorized, :with => :deny_access - rescue_from "RescueController::NotAuthorizedToRescueAsString", :with => :deny_access + rescue_from NotAuthorized, with: :deny_access + rescue_from "RescueController::NotAuthorizedToRescueAsString", with: :deny_access - rescue_from RecordInvalid, :with => :show_errors - rescue_from "RescueController::RecordInvalidToRescueAsString", :with => :show_errors + rescue_from RecordInvalid, with: :show_errors + rescue_from "RescueController::RecordInvalidToRescueAsString", with: :show_errors - rescue_from NotAllowed, :with => proc { head :forbidden } - rescue_from "RescueController::NotAllowedToRescueAsString", :with => proc { head :forbidden } + rescue_from NotAllowed, with: proc { head :forbidden } + rescue_from "RescueController::NotAllowedToRescueAsString", with: proc { head :forbidden } rescue_from InvalidRequest, with: proc { |exception| render plain: exception.message } rescue_from "InvalidRequestToRescueAsString", with: proc { |exception| render plain: exception.message } @@ -170,9 +170,9 @@ class ExceptionInheritanceRescueController < ActionController::Base class GrandchildException < ChildException end - rescue_from ChildException, :with => lambda { head :ok } - rescue_from ParentException, :with => lambda { head :created } - rescue_from GrandchildException, :with => lambda { head :no_content } + rescue_from ChildException, with: lambda { head :ok } + rescue_from ParentException, with: lambda { head :created } + rescue_from GrandchildException, with: lambda { head :no_content } def raise_parent_exception raise ParentException @@ -206,7 +206,7 @@ class ControllerInheritanceRescueController < ExceptionInheritanceRescueControll class SecondExceptionInChildController < StandardError end - rescue_from FirstExceptionInChildController, "SecondExceptionInChildController", :with => lambda { head :gone } + rescue_from FirstExceptionInChildController, "SecondExceptionInChildController", with: lambda { head :gone } def raise_first_exception_in_child_controller raise FirstExceptionInChildController @@ -314,7 +314,7 @@ class RescueTest < ActionDispatch::IntegrationTest "invalid" end end - rescue_from RecordInvalid, :with => :show_errors + rescue_from RecordInvalid, with: :show_errors def foo render plain: "foo" @@ -353,9 +353,9 @@ class RescueTest < ActionDispatch::IntegrationTest def with_test_routing with_routing do |set| set.draw do - get "foo", :to => ::RescueTest::TestController.action(:foo) - get "invalid", :to => ::RescueTest::TestController.action(:invalid) - get "b00m", :to => ::RescueTest::TestController.action(:b00m) + get "foo", to: ::RescueTest::TestController.action(:foo) + get "invalid", to: ::RescueTest::TestController.action(:invalid) + get "b00m", to: ::RescueTest::TestController.action(:b00m) end yield end diff --git a/actionpack/test/controller/resources_test.rb b/actionpack/test/controller/resources_test.rb index c549aa0dec..2514991d7d 100644 --- a/actionpack/test/controller/resources_test.rb +++ b/actionpack/test/controller/resources_test.rb @@ -26,43 +26,43 @@ class ResourcesTest < ActionController::TestCase end def test_override_paths_for_member_and_collection_methods - collection_methods = { :rss => :get, :reorder => :post, :csv => :post } - member_methods = { :rss => :get, :atom => :get, :upload => :post, :fix => :post } - path_names = {:new => "nuevo", :rss => "canal", :fix => "corrigir" } + collection_methods = { rss: :get, reorder: :post, csv: :post } + member_methods = { rss: :get, atom: :get, upload: :post, fix: :post } + path_names = {new: "nuevo", rss: "canal", fix: "corrigir" } with_restful_routing :messages, - :collection => collection_methods, - :member => member_methods, - :path_names => path_names do + collection: collection_methods, + member: member_methods, + path_names: path_names do assert_restful_routes_for :messages, - :collection => collection_methods, - :member => member_methods, - :path_names => path_names do |options| + collection: collection_methods, + member: member_methods, + path_names: path_names do |options| member_methods.each do |action, method| - assert_recognizes(options.merge(:action => action.to_s, :id => "1"), - :path => "/messages/1/#{path_names[action] || action}", - :method => method) + assert_recognizes(options.merge(action: action.to_s, id: "1"), + path: "/messages/1/#{path_names[action] || action}", + method: method) end collection_methods.each do |action, method| - assert_recognizes(options.merge(:action => action.to_s), - :path => "/messages/#{path_names[action] || action}", - :method => method) + assert_recognizes(options.merge(action: action.to_s), + path: "/messages/#{path_names[action] || action}", + method: method) end end assert_restful_named_routes_for :messages, - :collection => collection_methods, - :member => member_methods, - :path_names => path_names do |options| + collection: collection_methods, + member: member_methods, + path_names: path_names do |options| collection_methods.each_key do |action| - assert_named_route "/messages/#{path_names[action] || action}", "#{action}_messages_path", :action => action + assert_named_route "/messages/#{path_names[action] || action}", "#{action}_messages_path", action: action end member_methods.each_key do |action| - assert_named_route "/messages/1/#{path_names[action] || action}", "#{action}_message_path", :action => action, :id => "1" + assert_named_route "/messages/1/#{path_names[action] || action}", "#{action}_message_path", action: action, id: "1" end end @@ -77,69 +77,69 @@ class ResourcesTest < ActionController::TestCase end def test_multiple_resources_with_options - expected_options = {:controller => "threads", :action => "index"} + expected_options = {controller: "threads", action: "index"} with_restful_routing :messages, :comments, expected_options.slice(:controller) do - assert_recognizes(expected_options, :path => "comments") - assert_recognizes(expected_options, :path => "messages") + assert_recognizes(expected_options, path: "comments") + assert_recognizes(expected_options, path: "messages") end end def test_with_custom_conditions - with_restful_routing :messages, :conditions => { :subdomain => "app" } do - assert @routes.recognize_path("/messages", :method => :get, :subdomain => "app") + with_restful_routing :messages, conditions: { subdomain: "app" } do + assert @routes.recognize_path("/messages", method: :get, subdomain: "app") end end def test_irregular_id_with_no_constraints_should_raise_error - expected_options = {:controller => "messages", :action => "show", :id => "1.1.1"} + expected_options = {controller: "messages", action: "show", id: "1.1.1"} with_restful_routing :messages do assert_raise(Assertion) do - assert_recognizes(expected_options, :path => "messages/1.1.1", :method => :get) + assert_recognizes(expected_options, path: "messages/1.1.1", method: :get) end end end def test_irregular_id_with_constraints_should_pass - expected_options = {:controller => "messages", :action => "show", :id => "1.1.1"} + expected_options = {controller: "messages", action: "show", id: "1.1.1"} - with_restful_routing(:messages, :constraints => {:id => /[0-9]\.[0-9]\.[0-9]/}) do - assert_recognizes(expected_options, :path => "messages/1.1.1", :method => :get) + with_restful_routing(:messages, constraints: {id: /[0-9]\.[0-9]\.[0-9]/}) do + assert_recognizes(expected_options, path: "messages/1.1.1", method: :get) end end def test_with_path_prefix_constraints - expected_options = {:controller => "messages", :action => "show", :thread_id => "1.1.1", :id => "1"} - with_restful_routing :messages, :path_prefix => "/thread/:thread_id", :constraints => {:thread_id => /[0-9]\.[0-9]\.[0-9]/} do - assert_recognizes(expected_options, :path => "thread/1.1.1/messages/1", :method => :get) + expected_options = {controller: "messages", action: "show", thread_id: "1.1.1", id: "1"} + with_restful_routing :messages, path_prefix: "/thread/:thread_id", constraints: {thread_id: /[0-9]\.[0-9]\.[0-9]/} do + assert_recognizes(expected_options, path: "thread/1.1.1/messages/1", method: :get) end end def test_irregular_id_constraints_should_get_passed_to_member_actions - expected_options = {:controller => "messages", :action => "custom", :id => "1.1.1"} + expected_options = {controller: "messages", action: "custom", id: "1.1.1"} - with_restful_routing(:messages, :member => {:custom => :get}, :constraints => {:id => /[0-9]\.[0-9]\.[0-9]/}) do - assert_recognizes(expected_options, :path => "messages/1.1.1/custom", :method => :get) + with_restful_routing(:messages, member: {custom: :get}, constraints: {id: /[0-9]\.[0-9]\.[0-9]/}) do + assert_recognizes(expected_options, path: "messages/1.1.1/custom", method: :get) end end def test_with_path_prefix - with_restful_routing :messages, :path_prefix => "/thread/:thread_id" do - assert_simply_restful_for :messages, :path_prefix => "thread/5/", :options => { :thread_id => "5" } + with_restful_routing :messages, path_prefix: "/thread/:thread_id" do + assert_simply_restful_for :messages, path_prefix: "thread/5/", options: { thread_id: "5" } end end def test_multiple_with_path_prefix - with_restful_routing :messages, :comments, :path_prefix => "/thread/:thread_id" do - assert_simply_restful_for :messages, :path_prefix => "thread/5/", :options => { :thread_id => "5" } - assert_simply_restful_for :comments, :path_prefix => "thread/5/", :options => { :thread_id => "5" } + with_restful_routing :messages, :comments, path_prefix: "/thread/:thread_id" do + assert_simply_restful_for :messages, path_prefix: "thread/5/", options: { thread_id: "5" } + assert_simply_restful_for :comments, path_prefix: "thread/5/", options: { thread_id: "5" } end end def test_with_name_prefix - with_restful_routing :messages, :as => "post_messages" do - assert_simply_restful_for :messages, :name_prefix => "post_" + with_restful_routing :messages, as: "post_messages" do + assert_simply_restful_for :messages, name_prefix: "post_" end end @@ -149,23 +149,23 @@ class ResourcesTest < ActionController::TestCase with_routing do |set| set.draw do resources :messages do - get :a, :on => :collection - put :b, :on => :collection - post :c, :on => :collection - delete :d, :on => :collection - patch :e, :on => :collection + get :a, on: :collection + put :b, on: :collection + post :c, on: :collection + delete :d, on: :collection + patch :e, on: :collection end end assert_restful_routes_for :messages do |options| actions.each do |action, method| - assert_recognizes(options.merge(:action => action), :path => "/messages/#{action}", :method => method) + assert_recognizes(options.merge(action: action), path: "/messages/#{action}", method: method) end end assert_restful_named_routes_for :messages do actions.each_key do |action| - assert_named_route "/messages/#{action}", "#{action}_messages_path", :action => action + assert_named_route "/messages/#{action}", "#{action}_messages_path", action: action end end end @@ -177,25 +177,25 @@ class ResourcesTest < ActionController::TestCase with_routing do |set| set.draw do scope "/threads/:thread_id" do - resources :messages, :as => "thread_messages" do - get :a, :on => :collection - put :b, :on => :collection - post :c, :on => :collection - delete :d, :on => :collection - patch :e, :on => :collection + resources :messages, as: "thread_messages" do + get :a, on: :collection + put :b, on: :collection + post :c, on: :collection + delete :d, on: :collection + patch :e, on: :collection end end end - assert_restful_routes_for :messages, :path_prefix => "threads/1/", :name_prefix => "thread_", :options => { :thread_id => "1" } do |options| + assert_restful_routes_for :messages, path_prefix: "threads/1/", name_prefix: "thread_", options: { thread_id: "1" } do |options| actions.each do |action, method| - assert_recognizes(options.merge(:action => action), :path => "/threads/1/messages/#{action}", :method => method) + assert_recognizes(options.merge(action: action), path: "/threads/1/messages/#{action}", method: method) end end - assert_restful_named_routes_for :messages, :path_prefix => "threads/1/", :name_prefix => "thread_", :options => { :thread_id => "1" } do + assert_restful_named_routes_for :messages, path_prefix: "threads/1/", name_prefix: "thread_", options: { thread_id: "1" } do actions.each_key do |action| - assert_named_route "/threads/1/messages/#{action}", "#{action}_thread_messages_path", :action => action + assert_named_route "/threads/1/messages/#{action}", "#{action}_thread_messages_path", action: action end end end @@ -207,22 +207,22 @@ class ResourcesTest < ActionController::TestCase with_routing do |set| set.draw do scope "/threads/:thread_id" do - resources :messages, :as => "thread_messages" do - get :a, :on => :collection - get :a, :on => :member + resources :messages, as: "thread_messages" do + get :a, on: :collection + get :a, on: :member end end end - assert_restful_routes_for :messages, :path_prefix => "threads/1/", :name_prefix => "thread_", :options => { :thread_id => "1" } do |options| + assert_restful_routes_for :messages, path_prefix: "threads/1/", name_prefix: "thread_", options: { thread_id: "1" } do |options| actions.each do |action, method| - assert_recognizes(options.merge(:action => action), :path => "/threads/1/messages/#{action}", :method => method) + assert_recognizes(options.merge(action: action), path: "/threads/1/messages/#{action}", method: method) end end - assert_restful_named_routes_for :messages, :path_prefix => "threads/1/", :name_prefix => "thread_", :options => { :thread_id => "1" } do + assert_restful_named_routes_for :messages, path_prefix: "threads/1/", name_prefix: "thread_", options: { thread_id: "1" } do actions.each_key do |action| - assert_named_route "/threads/1/messages/#{action}", "#{action}_thread_messages_path", :action => action + assert_named_route "/threads/1/messages/#{action}", "#{action}_thread_messages_path", action: action end end end @@ -234,25 +234,25 @@ class ResourcesTest < ActionController::TestCase with_routing do |set| set.draw do scope "/threads/:thread_id" do - resources :messages, :as => "thread_messages" do - get :a, :on => :collection - put :b, :on => :collection - post :c, :on => :collection - delete :d, :on => :collection - patch :e, :on => :collection + resources :messages, as: "thread_messages" do + get :a, on: :collection + put :b, on: :collection + post :c, on: :collection + delete :d, on: :collection + patch :e, on: :collection end end end - assert_restful_routes_for :messages, :path_prefix => "threads/1/", :name_prefix => "thread_", :options => { :thread_id => "1" } do |options| + assert_restful_routes_for :messages, path_prefix: "threads/1/", name_prefix: "thread_", options: { thread_id: "1" } do |options| actions.each do |action, method| - assert_recognizes(options.merge(:action => action, :format => "xml"), :path => "/threads/1/messages/#{action}.xml", :method => method) + assert_recognizes(options.merge(action: action, format: "xml"), path: "/threads/1/messages/#{action}.xml", method: method) end end - assert_restful_named_routes_for :messages, :path_prefix => "threads/1/", :name_prefix => "thread_", :options => { :thread_id => "1" } do + assert_restful_named_routes_for :messages, path_prefix: "threads/1/", name_prefix: "thread_", options: { thread_id: "1" } do actions.each_key do |action| - assert_named_route "/threads/1/messages/#{action}.xml", "#{action}_thread_messages_path", :action => action, :format => "xml" + assert_named_route "/threads/1/messages/#{action}.xml", "#{action}_thread_messages_path", action: action, format: "xml" end end end @@ -260,11 +260,11 @@ class ResourcesTest < ActionController::TestCase def test_with_member_action [:patch, :put, :post].each do |method| - with_restful_routing :messages, :member => { :mark => method } do - mark_options = {:action => "mark", :id => "1"} + with_restful_routing :messages, member: { mark: method } do + mark_options = {action: "mark", id: "1"} mark_path = "/messages/1/mark" assert_restful_routes_for :messages do |options| - assert_recognizes(options.merge(mark_options), :path => mark_path, :method => method) + assert_recognizes(options.merge(mark_options), path: mark_path, method: method) end assert_restful_named_routes_for :messages do @@ -275,24 +275,24 @@ class ResourcesTest < ActionController::TestCase end def test_with_member_action_and_requirement - expected_options = {:controller => "messages", :action => "mark", :id => "1.1.1"} + expected_options = {controller: "messages", action: "mark", id: "1.1.1"} - with_restful_routing(:messages, :constraints => {:id => /[0-9]\.[0-9]\.[0-9]/}, :member => { :mark => :get }) do - assert_recognizes(expected_options, :path => "messages/1.1.1/mark", :method => :get) + with_restful_routing(:messages, constraints: {id: /[0-9]\.[0-9]\.[0-9]/}, member: { mark: :get }) do + assert_recognizes(expected_options, path: "messages/1.1.1/mark", method: :get) end end def test_member_when_override_paths_for_default_restful_actions_with [:patch, :put, :post].each do |method| - with_restful_routing :messages, :member => { :mark => method }, :path_names => {:new => "nuevo"} do - mark_options = {:action => "mark", :id => "1", :controller => "messages"} + with_restful_routing :messages, member: { mark: method }, path_names: {new: "nuevo"} do + mark_options = {action: "mark", id: "1", controller: "messages"} mark_path = "/messages/1/mark" - assert_restful_routes_for :messages, :path_names => {:new => "nuevo"} do |options| - assert_recognizes(options.merge(mark_options), :path => mark_path, :method => method) + assert_restful_routes_for :messages, path_names: {new: "nuevo"} do |options| + assert_recognizes(options.merge(mark_options), path: mark_path, method: method) end - assert_restful_named_routes_for :messages, :path_names => {:new => "nuevo"} do + assert_restful_named_routes_for :messages, path_names: {new: "nuevo"} do assert_named_route mark_path, :mark_message_path, mark_options end end @@ -305,17 +305,17 @@ class ResourcesTest < ActionController::TestCase set.draw do resources :messages do member do - match :mark , :via => method - match :unmark, :via => method + match :mark , via: method + match :unmark, via: method end end end %w(mark unmark).each do |action| - action_options = {:action => action, :id => "1"} + action_options = {action: action, id: "1"} action_path = "/messages/1/#{action}" assert_restful_routes_for :messages do |options| - assert_recognizes(options.merge(action_options), :path => action_path, :method => method) + assert_recognizes(options.merge(action_options), path: action_path, method: method) end assert_restful_named_routes_for :messages do @@ -331,21 +331,21 @@ class ResourcesTest < ActionController::TestCase set.draw do resources :messages do collection do - match :search, :via => [:post, :get] + match :search, via: [:post, :get] end member do - match :toggle, :via => [:post, :get] + match :toggle, via: [:post, :get] end end end assert_restful_routes_for :messages do |options| [:get, :post].each do |method| - assert_recognizes(options.merge(:action => "search"), :path => "/messages/search", :method => method) + assert_recognizes(options.merge(action: "search"), path: "/messages/search", method: method) end [:get, :post].each do |method| - assert_recognizes(options.merge(:action => "toggle", :id => "1"), :path => "/messages/1/toggle", :method => method) + assert_recognizes(options.merge(action: "toggle", id: "1"), path: "/messages/1/toggle", method: method) end end end @@ -355,14 +355,14 @@ class ResourcesTest < ActionController::TestCase with_routing do |set| set.draw do resources :messages do - post :preview, :on => :new + post :preview, on: :new end end - preview_options = {:action => "preview"} + preview_options = {action: "preview"} preview_path = "/messages/new/preview" assert_restful_routes_for :messages do |options| - assert_recognizes(options.merge(preview_options), :path => preview_path, :method => :post) + assert_recognizes(options.merge(preview_options), path: preview_path, method: :post) end assert_restful_named_routes_for :messages do @@ -375,19 +375,19 @@ class ResourcesTest < ActionController::TestCase with_routing do |set| set.draw do scope("/threads/:thread_id") do - resources :messages, :as => "thread_messages" do - post :preview, :on => :new + resources :messages, as: "thread_messages" do + post :preview, on: :new end end end - preview_options = {:action => "preview", :thread_id => "1"} + preview_options = {action: "preview", thread_id: "1"} preview_path = "/threads/1/messages/new/preview" - assert_restful_routes_for :messages, :path_prefix => "threads/1/", :name_prefix => "thread_", :options => { :thread_id => "1" } do |options| - assert_recognizes(options.merge(preview_options), :path => preview_path, :method => :post) + assert_restful_routes_for :messages, path_prefix: "threads/1/", name_prefix: "thread_", options: { thread_id: "1" } do |options| + assert_recognizes(options.merge(preview_options), path: preview_path, method: :post) end - assert_restful_named_routes_for :messages, :path_prefix => "threads/1/", :name_prefix => "thread_", :options => { :thread_id => "1" } do + assert_restful_named_routes_for :messages, path_prefix: "threads/1/", name_prefix: "thread_", options: { thread_id: "1" } do assert_named_route preview_path, :preview_new_thread_message_path, preview_options end end @@ -397,19 +397,19 @@ class ResourcesTest < ActionController::TestCase with_routing do |set| set.draw do scope("/threads/:thread_id") do - resources :messages, :as => "thread_messages" do - post :preview, :on => :new + resources :messages, as: "thread_messages" do + post :preview, on: :new end end end - preview_options = {:action => "preview", :thread_id => "1", :format => "xml"} + preview_options = {action: "preview", thread_id: "1", format: "xml"} preview_path = "/threads/1/messages/new/preview.xml" - assert_restful_routes_for :messages, :path_prefix => "threads/1/", :name_prefix => "thread_", :options => { :thread_id => "1" } do |options| - assert_recognizes(options.merge(preview_options), :path => preview_path, :method => :post) + assert_restful_routes_for :messages, path_prefix: "threads/1/", name_prefix: "thread_", options: { thread_id: "1" } do |options| + assert_recognizes(options.merge(preview_options), path: preview_path, method: :post) end - assert_restful_named_routes_for :messages, :path_prefix => "threads/1/", :name_prefix => "thread_", :options => { :thread_id => "1" } do + assert_restful_named_routes_for :messages, path_prefix: "threads/1/", name_prefix: "thread_", options: { thread_id: "1" } do assert_named_route preview_path, :preview_new_thread_message_path, preview_options end end @@ -418,9 +418,9 @@ class ResourcesTest < ActionController::TestCase def test_override_new_method with_restful_routing :messages do assert_restful_routes_for :messages do |options| - assert_recognizes(options.merge(:action => "new"), :path => "/messages/new", :method => :get) + assert_recognizes(options.merge(action: "new"), path: "/messages/new", method: :get) assert_raise(ActionController::RoutingError) do - @routes.recognize_path("/messages/new", :method => :post) + @routes.recognize_path("/messages/new", method: :post) end end end @@ -428,13 +428,13 @@ class ResourcesTest < ActionController::TestCase with_routing do |set| set.draw do resources :messages do - match :new, :via => [:post, :get], :on => :new + match :new, via: [:post, :get], on: :new end end assert_restful_routes_for :messages do |options| - assert_recognizes(options.merge(:action => "new"), :path => "/messages/new", :method => :post) - assert_recognizes(options.merge(:action => "new"), :path => "/messages/new", :method => :get) + assert_recognizes(options.merge(action: "new"), path: "/messages/new", method: :post) + assert_recognizes(options.merge(action: "new"), path: "/messages/new", method: :get) end end end @@ -451,20 +451,20 @@ class ResourcesTest < ActionController::TestCase assert_simply_restful_for :threads assert_simply_restful_for :messages, - :name_prefix => "thread_", - :path_prefix => "threads/1/", - :options => { :thread_id => "1" } + name_prefix: "thread_", + path_prefix: "threads/1/", + options: { thread_id: "1" } assert_simply_restful_for :comments, - :name_prefix => "thread_message_", - :path_prefix => "threads/1/messages/2/", - :options => { :thread_id => "1", :message_id => "2" } + name_prefix: "thread_message_", + path_prefix: "threads/1/messages/2/", + options: { thread_id: "1", message_id: "2" } end end def test_shallow_nested_restful_routes with_routing do |set| set.draw do - resources :threads, :shallow => true do + resources :threads, shallow: true do resources :messages do resources :comments end @@ -472,17 +472,17 @@ class ResourcesTest < ActionController::TestCase end assert_simply_restful_for :threads, - :shallow => true + shallow: true assert_simply_restful_for :messages, - :name_prefix => "thread_", - :path_prefix => "threads/1/", - :shallow => true, - :options => { :thread_id => "1" } + name_prefix: "thread_", + path_prefix: "threads/1/", + shallow: true, + options: { thread_id: "1" } assert_simply_restful_for :comments, - :name_prefix => "message_", - :path_prefix => "messages/2/", - :shallow => true, - :options => { :message_id => "2" } + name_prefix: "message_", + path_prefix: "messages/2/", + shallow: true, + options: { message_id: "2" } end end @@ -491,7 +491,7 @@ class ResourcesTest < ActionController::TestCase set.draw do namespace :backoffice do namespace :admin do - resources :products, :shallow => true do + resources :products, shallow: true do resources :images end end @@ -499,18 +499,18 @@ class ResourcesTest < ActionController::TestCase end assert_simply_restful_for :products, - :controller => "backoffice/admin/products", - :namespace => "backoffice/admin/", - :name_prefix => "backoffice_admin_", - :path_prefix => "backoffice/admin/", - :shallow => true + controller: "backoffice/admin/products", + namespace: "backoffice/admin/", + name_prefix: "backoffice_admin_", + path_prefix: "backoffice/admin/", + shallow: true assert_simply_restful_for :images, - :controller => "backoffice/admin/images", - :namespace => "backoffice/admin/", - :name_prefix => "backoffice_admin_product_", - :path_prefix => "backoffice/admin/products/1/", - :shallow => true, - :options => { :product_id => "1" } + controller: "backoffice/admin/images", + namespace: "backoffice/admin/", + name_prefix: "backoffice_admin_product_", + path_prefix: "backoffice/admin/products/1/", + shallow: true, + options: { product_id: "1" } end end @@ -542,13 +542,13 @@ class ResourcesTest < ActionController::TestCase def test_should_create_nested_singleton_resource_routes with_routing do |set| set.draw do - resource :admin, :controller => "admin" do + resource :admin, controller: "admin" do resource :account end end - assert_singleton_restful_for :admin, :controller => "admin" - assert_singleton_restful_for :account, :name_prefix => "admin_", :path_prefix => "admin/" + assert_singleton_restful_for :admin, controller: "admin" + assert_singleton_restful_for :account, name_prefix: "admin_", path_prefix: "admin/" end end @@ -557,14 +557,14 @@ class ResourcesTest < ActionController::TestCase with_routing do |set| set.draw do resource :account do - match :reset, :on => :member, :via => method + match :reset, on: :member, via: method end end - reset_options = {:action => "reset"} + reset_options = {action: "reset"} reset_path = "/account/reset" assert_singleton_routes_for :account do |options| - assert_recognizes(options.merge(reset_options), :path => reset_path, :method => method) + assert_recognizes(options.merge(reset_options), path: reset_path, method: method) end assert_singleton_named_routes_for :account do @@ -579,16 +579,16 @@ class ResourcesTest < ActionController::TestCase with_routing do |set| set.draw do resource :account do - match :reset, :on => :member, :via => method - match :disable, :on => :member, :via => method + match :reset, on: :member, via: method + match :disable, on: :member, via: method end end %w(reset disable).each do |action| - action_options = {:action => action} + action_options = {action: action} action_path = "/account/#{action}" assert_singleton_routes_for :account do |options| - assert_recognizes(options.merge(action_options), :path => action_path, :method => method) + assert_recognizes(options.merge(action_options), path: action_path, method: method) end assert_singleton_named_routes_for :account do @@ -608,7 +608,7 @@ class ResourcesTest < ActionController::TestCase end assert_singleton_restful_for :account - assert_simply_restful_for :messages, :name_prefix => "account_", :path_prefix => "account/" + assert_simply_restful_for :messages, name_prefix: "account_", path_prefix: "account/" end end @@ -622,8 +622,8 @@ class ResourcesTest < ActionController::TestCase end end - assert_singleton_restful_for :account, :path_prefix => "7/", :options => { :site_id => "7" } - assert_simply_restful_for :messages, :name_prefix => "account_", :path_prefix => "7/account/", :options => { :site_id => "7" } + assert_singleton_restful_for :account, path_prefix: "7/", options: { site_id: "7" } + assert_simply_restful_for :messages, name_prefix: "account_", path_prefix: "7/account/", options: { site_id: "7" } end end @@ -631,31 +631,31 @@ class ResourcesTest < ActionController::TestCase with_routing do |set| set.draw do resources :threads do - resource :admin, :controller => "admin" + resource :admin, controller: "admin" end end assert_simply_restful_for :threads - assert_singleton_restful_for :admin, :controller => "admin", :name_prefix => "thread_", :path_prefix => "threads/5/", :options => { :thread_id => "5" } + assert_singleton_restful_for :admin, controller: "admin", name_prefix: "thread_", path_prefix: "threads/5/", options: { thread_id: "5" } end end def test_should_not_allow_delete_or_patch_or_put_on_collection_path controller_name = :messages with_restful_routing controller_name do - options = { :controller => controller_name.to_s } + options = { controller: controller_name.to_s } collection_path = "/#{controller_name}" assert_raise(Assertion) do - assert_recognizes(options.merge(:action => "update"), :path => collection_path, :method => :patch) + assert_recognizes(options.merge(action: "update"), path: collection_path, method: :patch) end assert_raise(Assertion) do - assert_recognizes(options.merge(:action => "update"), :path => collection_path, :method => :put) + assert_recognizes(options.merge(action: "update"), path: collection_path, method: :put) end assert_raise(Assertion) do - assert_recognizes(options.merge(:action => "destroy"), :path => collection_path, :method => :delete) + assert_recognizes(options.merge(action: "destroy"), path: collection_path, method: :delete) end end end @@ -664,14 +664,14 @@ class ResourcesTest < ActionController::TestCase with_routing do |set| set.draw do scope "/threads/:thread_id" do - resources :messages, :as => "thread_messages" do - get :search, :on => :collection - get :preview, :on => :new + resources :messages, as: "thread_messages" do + get :search, on: :collection + get :preview, on: :new end end end - assert_simply_restful_for :messages, :name_prefix => "thread_", :path_prefix => "threads/1/", :options => { :thread_id => "1" } + assert_simply_restful_for :messages, name_prefix: "thread_", path_prefix: "threads/1/", options: { thread_id: "1" } assert_named_route "/threads/1/messages/search", "search_thread_messages_path", {} assert_named_route "/threads/1/messages/new", "new_thread_message_path", {} assert_named_route "/threads/1/messages/new/preview", "preview_new_thread_message_path", {} @@ -682,13 +682,13 @@ class ResourcesTest < ActionController::TestCase with_routing do |set| set.draw do scope "/admin" do - resource :account, :as => :admin_account do - get :login, :on => :member - get :preview, :on => :new + resource :account, as: :admin_account do + get :login, on: :member + get :preview, on: :new end end end - assert_singleton_restful_for :account, :name_prefix => "admin_", :path_prefix => "admin/" + assert_singleton_restful_for :account, name_prefix: "admin_", path_prefix: "admin/" assert_named_route "/admin/account/login", "login_admin_account_path", {} assert_named_route "/admin/account/new", "new_admin_account_path", {} assert_named_route "/admin/account/new/preview", "preview_new_admin_account_path", {} @@ -703,7 +703,7 @@ class ResourcesTest < ActionController::TestCase end end - assert_simply_restful_for :products, :controller => "backoffice/products", :name_prefix => "backoffice_", :path_prefix => "backoffice/" + assert_simply_restful_for :products, controller: "backoffice/products", name_prefix: "backoffice_", path_prefix: "backoffice/" end end @@ -717,19 +717,19 @@ class ResourcesTest < ActionController::TestCase end end - assert_simply_restful_for :products, :controller => "backoffice/admin/products", :name_prefix => "backoffice_admin_", :path_prefix => "backoffice/admin/" + assert_simply_restful_for :products, controller: "backoffice/admin/products", name_prefix: "backoffice_admin_", path_prefix: "backoffice/admin/" end end def test_resources_using_namespace with_routing do |set| set.draw do - namespace :backoffice, :path => nil, :as => nil do + namespace :backoffice, path: nil, as: nil do resources :products end end - assert_simply_restful_for :products, :controller => "backoffice/products" + assert_simply_restful_for :products, controller: "backoffice/products" end end @@ -743,7 +743,7 @@ class ResourcesTest < ActionController::TestCase end end - assert_simply_restful_for :images, :controller => "backoffice/images", :name_prefix => "backoffice_product_", :path_prefix => "backoffice/products/1/", :options => {:product_id => "1"} + assert_simply_restful_for :images, controller: "backoffice/images", name_prefix: "backoffice_product_", path_prefix: "backoffice/products/1/", options: {product_id: "1"} end end @@ -759,24 +759,24 @@ class ResourcesTest < ActionController::TestCase end end - assert_simply_restful_for :images, :controller => "backoffice/admin/images", :name_prefix => "backoffice_admin_product_", :path_prefix => "backoffice/admin/products/1/", :options => {:product_id => "1"} + assert_simply_restful_for :images, controller: "backoffice/admin/images", name_prefix: "backoffice_admin_product_", path_prefix: "backoffice/admin/products/1/", options: {product_id: "1"} end end def test_with_path_segment with_restful_routing :messages do assert_simply_restful_for :messages - assert_recognizes({:controller => "messages", :action => "index"}, "/messages") - assert_recognizes({:controller => "messages", :action => "index"}, "/messages/") + assert_recognizes({controller: "messages", action: "index"}, "/messages") + assert_recognizes({controller: "messages", action: "index"}, "/messages/") end with_routing do |set| set.draw do - resources :messages, :path => "reviews" + resources :messages, path: "reviews" end - assert_simply_restful_for :messages, :as => "reviews" - assert_recognizes({:controller => "messages", :action => "index"}, "/reviews") - assert_recognizes({:controller => "messages", :action => "index"}, "/reviews/") + assert_simply_restful_for :messages, as: "reviews" + assert_recognizes({controller: "messages", action: "index"}, "/reviews") + assert_recognizes({controller: "messages", action: "index"}, "/reviews/") end end @@ -784,82 +784,82 @@ class ResourcesTest < ActionController::TestCase with_routing do |set| set.draw do resources :products do - resources :product_reviews, :path => "reviews", :controller => "messages" + resources :product_reviews, path: "reviews", controller: "messages" end resources :tutors do - resources :tutor_reviews, :path => "reviews", :controller => "comments" + resources :tutor_reviews, path: "reviews", controller: "comments" end end - assert_simply_restful_for :product_reviews, :controller=>"messages", :as => "reviews", :name_prefix => "product_", :path_prefix => "products/1/", :options => {:product_id => "1"} - assert_simply_restful_for :tutor_reviews,:controller=>"comments", :as => "reviews", :name_prefix => "tutor_", :path_prefix => "tutors/1/", :options => {:tutor_id => "1"} + assert_simply_restful_for :product_reviews, controller: "messages", as: "reviews", name_prefix: "product_", path_prefix: "products/1/", options: {product_id: "1"} + assert_simply_restful_for :tutor_reviews,controller: "comments", as: "reviews", name_prefix: "tutor_", path_prefix: "tutors/1/", options: {tutor_id: "1"} end end def test_with_path_segment_path_prefix_constraints - expected_options = {:controller => "messages", :action => "show", :thread_id => "1.1.1", :id => "1"} + expected_options = {controller: "messages", action: "show", thread_id: "1.1.1", id: "1"} with_routing do |set| set.draw do - scope "/thread/:thread_id", :constraints => { :thread_id => /[0-9]\.[0-9]\.[0-9]/ } do - resources :messages, :path => "comments" + scope "/thread/:thread_id", constraints: { thread_id: /[0-9]\.[0-9]\.[0-9]/ } do + resources :messages, path: "comments" end end - assert_recognizes(expected_options, :path => "thread/1.1.1/comments/1", :method => :get) + assert_recognizes(expected_options, path: "thread/1.1.1/comments/1", method: :get) end end def test_resource_has_only_show_action with_routing do |set| set.draw do - resources :products, :only => :show + resources :products, only: :show end - assert_resource_allowed_routes("products", {}, { :id => "1" }, :show, [:index, :new, :create, :edit, :update, :destroy]) - assert_resource_allowed_routes("products", { :format => "xml" }, { :id => "1" }, :show, [:index, :new, :create, :edit, :update, :destroy]) + assert_resource_allowed_routes("products", {}, { id: "1" }, :show, [:index, :new, :create, :edit, :update, :destroy]) + assert_resource_allowed_routes("products", { format: "xml" }, { id: "1" }, :show, [:index, :new, :create, :edit, :update, :destroy]) end end def test_singleton_resource_has_only_show_action with_routing do |set| set.draw do - resource :account, :only => :show + resource :account, only: :show end assert_singleton_resource_allowed_routes("accounts", {}, :show, [:index, :new, :create, :edit, :update, :destroy]) - assert_singleton_resource_allowed_routes("accounts", { :format => "xml" }, :show, [:index, :new, :create, :edit, :update, :destroy]) + assert_singleton_resource_allowed_routes("accounts", { format: "xml" }, :show, [:index, :new, :create, :edit, :update, :destroy]) end end def test_resource_does_not_have_destroy_action with_routing do |set| set.draw do - resources :products, :except => :destroy + resources :products, except: :destroy end - assert_resource_allowed_routes("products", {}, { :id => "1" }, [:index, :new, :create, :show, :edit, :update], :destroy) - assert_resource_allowed_routes("products", { :format => "xml" }, { :id => "1" }, [:index, :new, :create, :show, :edit, :update], :destroy) + assert_resource_allowed_routes("products", {}, { id: "1" }, [:index, :new, :create, :show, :edit, :update], :destroy) + assert_resource_allowed_routes("products", { format: "xml" }, { id: "1" }, [:index, :new, :create, :show, :edit, :update], :destroy) end end def test_singleton_resource_does_not_have_destroy_action with_routing do |set| set.draw do - resource :account, :except => :destroy + resource :account, except: :destroy end assert_singleton_resource_allowed_routes("accounts", {}, [:new, :create, :show, :edit, :update], :destroy) - assert_singleton_resource_allowed_routes("accounts", { :format => "xml" }, [:new, :create, :show, :edit, :update], :destroy) + assert_singleton_resource_allowed_routes("accounts", { format: "xml" }, [:new, :create, :show, :edit, :update], :destroy) end end def test_resource_has_only_create_action_and_named_route with_routing do |set| set.draw do - resources :products, :only => :create + resources :products, only: :create end - assert_resource_allowed_routes("products", {}, { :id => "1" }, :create, [:index, :new, :show, :edit, :update, :destroy]) - assert_resource_allowed_routes("products", { :format => "xml" }, { :id => "1" }, :create, [:index, :new, :show, :edit, :update, :destroy]) + assert_resource_allowed_routes("products", {}, { id: "1" }, :create, [:index, :new, :show, :edit, :update, :destroy]) + assert_resource_allowed_routes("products", { format: "xml" }, { id: "1" }, :create, [:index, :new, :show, :edit, :update, :destroy]) assert_not_nil set.named_routes[:products] end @@ -868,11 +868,11 @@ class ResourcesTest < ActionController::TestCase def test_resource_has_only_update_action_and_named_route with_routing do |set| set.draw do - resources :products, :only => :update + resources :products, only: :update end - assert_resource_allowed_routes("products", {}, { :id => "1" }, :update, [:index, :new, :create, :show, :edit, :destroy]) - assert_resource_allowed_routes("products", { :format => "xml" }, { :id => "1" }, :update, [:index, :new, :create, :show, :edit, :destroy]) + assert_resource_allowed_routes("products", {}, { id: "1" }, :update, [:index, :new, :create, :show, :edit, :destroy]) + assert_resource_allowed_routes("products", { format: "xml" }, { id: "1" }, :update, [:index, :new, :create, :show, :edit, :destroy]) assert_not_nil set.named_routes[:product] end @@ -881,11 +881,11 @@ class ResourcesTest < ActionController::TestCase def test_resource_has_only_destroy_action_and_named_route with_routing do |set| set.draw do - resources :products, :only => :destroy + resources :products, only: :destroy end - assert_resource_allowed_routes("products", {}, { :id => "1" }, :destroy, [:index, :new, :create, :show, :edit, :update]) - assert_resource_allowed_routes("products", { :format => "xml" }, { :id => "1" }, :destroy, [:index, :new, :create, :show, :edit, :update]) + assert_resource_allowed_routes("products", {}, { id: "1" }, :destroy, [:index, :new, :create, :show, :edit, :update]) + assert_resource_allowed_routes("products", { format: "xml" }, { id: "1" }, :destroy, [:index, :new, :create, :show, :edit, :update]) assert_not_nil set.named_routes[:product] end @@ -894,11 +894,11 @@ class ResourcesTest < ActionController::TestCase def test_singleton_resource_has_only_create_action_and_named_route with_routing do |set| set.draw do - resource :account, :only => :create + resource :account, only: :create end assert_singleton_resource_allowed_routes("accounts", {}, :create, [:new, :show, :edit, :update, :destroy]) - assert_singleton_resource_allowed_routes("accounts", { :format => "xml" }, :create, [:new, :show, :edit, :update, :destroy]) + assert_singleton_resource_allowed_routes("accounts", { format: "xml" }, :create, [:new, :show, :edit, :update, :destroy]) assert_not_nil set.named_routes[:account] end @@ -907,11 +907,11 @@ class ResourcesTest < ActionController::TestCase def test_singleton_resource_has_only_update_action_and_named_route with_routing do |set| set.draw do - resource :account, :only => :update + resource :account, only: :update end assert_singleton_resource_allowed_routes("accounts", {}, :update, [:new, :create, :show, :edit, :destroy]) - assert_singleton_resource_allowed_routes("accounts", { :format => "xml" }, :update, [:new, :create, :show, :edit, :destroy]) + assert_singleton_resource_allowed_routes("accounts", { format: "xml" }, :update, [:new, :create, :show, :edit, :destroy]) assert_not_nil set.named_routes[:account] end @@ -920,11 +920,11 @@ class ResourcesTest < ActionController::TestCase def test_singleton_resource_has_only_destroy_action_and_named_route with_routing do |set| set.draw do - resource :account, :only => :destroy + resource :account, only: :destroy end assert_singleton_resource_allowed_routes("accounts", {}, :destroy, [:new, :create, :show, :edit, :update]) - assert_singleton_resource_allowed_routes("accounts", { :format => "xml" }, :destroy, [:new, :create, :show, :edit, :update]) + assert_singleton_resource_allowed_routes("accounts", { format: "xml" }, :destroy, [:new, :create, :show, :edit, :update]) assert_not_nil set.named_routes[:account] end @@ -933,39 +933,39 @@ class ResourcesTest < ActionController::TestCase def test_resource_has_only_collection_action with_routing do |set| set.draw do - resources :products, :only => [] do - get :sale, :on => :collection + resources :products, only: [] do + get :sale, on: :collection end end - assert_resource_allowed_routes("products", {}, { :id => "1" }, [], [:index, :new, :create, :show, :edit, :update, :destroy]) - assert_resource_allowed_routes("products", { :format => "xml" }, { :id => "1" }, [], [:index, :new, :create, :show, :edit, :update, :destroy]) + assert_resource_allowed_routes("products", {}, { id: "1" }, [], [:index, :new, :create, :show, :edit, :update, :destroy]) + assert_resource_allowed_routes("products", { format: "xml" }, { id: "1" }, [], [:index, :new, :create, :show, :edit, :update, :destroy]) - assert_recognizes({ :controller => "products", :action => "sale" }, :path => "products/sale", :method => :get) - assert_recognizes({ :controller => "products", :action => "sale", :format => "xml" }, :path => "products/sale.xml", :method => :get) + assert_recognizes({ controller: "products", action: "sale" }, path: "products/sale", method: :get) + assert_recognizes({ controller: "products", action: "sale", format: "xml" }, path: "products/sale.xml", method: :get) end end def test_resource_has_only_member_action with_routing do |set| set.draw do - resources :products, :only => [] do - get :preview, :on => :member + resources :products, only: [] do + get :preview, on: :member end end - assert_resource_allowed_routes("products", {}, { :id => "1" }, [], [:index, :new, :create, :show, :edit, :update, :destroy]) - assert_resource_allowed_routes("products", { :format => "xml" }, { :id => "1" }, [], [:index, :new, :create, :show, :edit, :update, :destroy]) + assert_resource_allowed_routes("products", {}, { id: "1" }, [], [:index, :new, :create, :show, :edit, :update, :destroy]) + assert_resource_allowed_routes("products", { format: "xml" }, { id: "1" }, [], [:index, :new, :create, :show, :edit, :update, :destroy]) - assert_recognizes({ :controller => "products", :action => "preview", :id => "1" }, :path => "products/1/preview", :method => :get) - assert_recognizes({ :controller => "products", :action => "preview", :id => "1", :format => "xml" }, :path => "products/1/preview.xml", :method => :get) + assert_recognizes({ controller: "products", action: "preview", id: "1" }, path: "products/1/preview", method: :get) + assert_recognizes({ controller: "products", action: "preview", id: "1", format: "xml" }, path: "products/1/preview.xml", method: :get) end end def test_singleton_resource_has_only_member_action with_routing do |set| set.draw do - resource :account, :only => [] do + resource :account, only: [] do member do get :signup end @@ -973,80 +973,80 @@ class ResourcesTest < ActionController::TestCase end assert_singleton_resource_allowed_routes("accounts", {}, [], [:new, :create, :show, :edit, :update, :destroy]) - assert_singleton_resource_allowed_routes("accounts", { :format => "xml" }, [], [:new, :create, :show, :edit, :update, :destroy]) + assert_singleton_resource_allowed_routes("accounts", { format: "xml" }, [], [:new, :create, :show, :edit, :update, :destroy]) - assert_recognizes({ :controller => "accounts", :action => "signup" }, :path => "account/signup", :method => :get) - assert_recognizes({ :controller => "accounts", :action => "signup", :format => "xml" }, :path => "account/signup.xml", :method => :get) + assert_recognizes({ controller: "accounts", action: "signup" }, path: "account/signup", method: :get) + assert_recognizes({ controller: "accounts", action: "signup", format: "xml" }, path: "account/signup.xml", method: :get) end end def test_nested_resource_has_only_show_and_member_action with_routing do |set| set.draw do - resources :products, :only => [:index, :show] do - resources :images, :only => :show do - get :thumbnail, :on => :member + resources :products, only: [:index, :show] do + resources :images, only: :show do + get :thumbnail, on: :member end end end - assert_resource_allowed_routes("images", { :product_id => "1" }, { :id => "2" }, :show, [:index, :new, :create, :edit, :update, :destroy], "products/1/images") - assert_resource_allowed_routes("images", { :product_id => "1", :format => "xml" }, { :id => "2" }, :show, [:index, :new, :create, :edit, :update, :destroy], "products/1/images") + assert_resource_allowed_routes("images", { product_id: "1" }, { id: "2" }, :show, [:index, :new, :create, :edit, :update, :destroy], "products/1/images") + assert_resource_allowed_routes("images", { product_id: "1", format: "xml" }, { id: "2" }, :show, [:index, :new, :create, :edit, :update, :destroy], "products/1/images") - assert_recognizes({ :controller => "images", :action => "thumbnail", :product_id => "1", :id => "2" }, :path => "products/1/images/2/thumbnail", :method => :get) - assert_recognizes({ :controller => "images", :action => "thumbnail", :product_id => "1", :id => "2", :format => "jpg" }, :path => "products/1/images/2/thumbnail.jpg", :method => :get) + assert_recognizes({ controller: "images", action: "thumbnail", product_id: "1", id: "2" }, path: "products/1/images/2/thumbnail", method: :get) + assert_recognizes({ controller: "images", action: "thumbnail", product_id: "1", id: "2", format: "jpg" }, path: "products/1/images/2/thumbnail.jpg", method: :get) end end def test_nested_resource_does_not_inherit_only_option with_routing do |set| set.draw do - resources :products, :only => :show do - resources :images, :except => :destroy + resources :products, only: :show do + resources :images, except: :destroy end end - assert_resource_allowed_routes("images", { :product_id => "1" }, { :id => "2" }, [:index, :new, :create, :show, :edit, :update], :destroy, "products/1/images") - assert_resource_allowed_routes("images", { :product_id => "1", :format => "xml" }, { :id => "2" }, [:index, :new, :create, :show, :edit, :update], :destroy, "products/1/images") + assert_resource_allowed_routes("images", { product_id: "1" }, { id: "2" }, [:index, :new, :create, :show, :edit, :update], :destroy, "products/1/images") + assert_resource_allowed_routes("images", { product_id: "1", format: "xml" }, { id: "2" }, [:index, :new, :create, :show, :edit, :update], :destroy, "products/1/images") end end def test_nested_resource_does_not_inherit_only_option_by_default with_routing do |set| set.draw do - resources :products, :only => :show do + resources :products, only: :show do resources :images end end - assert_resource_allowed_routes("images", { :product_id => "1" }, { :id => "2" }, [:index, :new, :create, :show, :edit, :update, :destroy], [], "products/1/images") - assert_resource_allowed_routes("images", { :product_id => "1", :format => "xml" }, { :id => "2" }, [:index, :new, :create, :show, :edit, :update, :destroy], [], "products/1/images") + assert_resource_allowed_routes("images", { product_id: "1" }, { id: "2" }, [:index, :new, :create, :show, :edit, :update, :destroy], [], "products/1/images") + assert_resource_allowed_routes("images", { product_id: "1", format: "xml" }, { id: "2" }, [:index, :new, :create, :show, :edit, :update, :destroy], [], "products/1/images") end end def test_nested_resource_does_not_inherit_except_option with_routing do |set| set.draw do - resources :products, :except => :show do - resources :images, :only => :destroy + resources :products, except: :show do + resources :images, only: :destroy end end - assert_resource_allowed_routes("images", { :product_id => "1" }, { :id => "2" }, :destroy, [:index, :new, :create, :show, :edit, :update], "products/1/images") - assert_resource_allowed_routes("images", { :product_id => "1", :format => "xml" }, { :id => "2" }, :destroy, [:index, :new, :create, :show, :edit, :update], "products/1/images") + assert_resource_allowed_routes("images", { product_id: "1" }, { id: "2" }, :destroy, [:index, :new, :create, :show, :edit, :update], "products/1/images") + assert_resource_allowed_routes("images", { product_id: "1", format: "xml" }, { id: "2" }, :destroy, [:index, :new, :create, :show, :edit, :update], "products/1/images") end end def test_nested_resource_does_not_inherit_except_option_by_default with_routing do |set| set.draw do - resources :products, :except => :show do + resources :products, except: :show do resources :images end end - assert_resource_allowed_routes("images", { :product_id => "1" }, { :id => "2" }, [:index, :new, :create, :show, :edit, :update, :destroy], [], "products/1/images") - assert_resource_allowed_routes("images", { :product_id => "1", :format => "xml" }, { :id => "2" }, [:index, :new, :create, :show, :edit, :update, :destroy], [], "products/1/images") + assert_resource_allowed_routes("images", { product_id: "1" }, { id: "2" }, [:index, :new, :create, :show, :edit, :update, :destroy], [], "products/1/images") + assert_resource_allowed_routes("images", { product_id: "1", format: "xml" }, { id: "2" }, [:index, :new, :create, :show, :edit, :update, :destroy], [], "products/1/images") end end @@ -1056,8 +1056,8 @@ class ResourcesTest < ActionController::TestCase resource :product end - assert_routing "/product", :controller => "products", :action => "show" - assert set.recognize_path("/product", :method => :get) + assert_routing "/product", controller: "products", action: "show" + assert set.recognize_path("/product", method: :get) end end @@ -1169,34 +1169,34 @@ class ResourcesTest < ActionController::TestCase formatted_edit_member_path = "#{member_path}/#{edit_action}.xml" with_options(route_options) do |controller| - controller.assert_routing collection_path, :action => "index" - controller.assert_routing new_path, :action => "new" - controller.assert_routing "#{collection_path}.xml", :action => "index", :format => "xml" - controller.assert_routing "#{new_path}.xml", :action => "new", :format => "xml" + controller.assert_routing collection_path, action: "index" + controller.assert_routing new_path, action: "new" + controller.assert_routing "#{collection_path}.xml", action: "index", format: "xml" + controller.assert_routing "#{new_path}.xml", action: "new", format: "xml" end with_options(options[:shallow_options]) do |controller| - controller.assert_routing member_path, :action => "show", :id => "1" - controller.assert_routing edit_member_path, :action => "edit", :id => "1" - controller.assert_routing "#{member_path}.xml", :action => "show", :id => "1", :format => "xml" - controller.assert_routing formatted_edit_member_path, :action => "edit", :id => "1", :format => "xml" - end - - assert_recognizes(route_options.merge(:action => "index"), :path => collection_path, :method => :get) - assert_recognizes(route_options.merge(:action => "new"), :path => new_path, :method => :get) - assert_recognizes(route_options.merge(:action => "create"), :path => collection_path, :method => :post) - assert_recognizes(options[:shallow_options].merge(:action => "show", :id => "1"), :path => member_path, :method => :get) - assert_recognizes(options[:shallow_options].merge(:action => "edit", :id => "1"), :path => edit_member_path, :method => :get) - assert_recognizes(options[:shallow_options].merge(:action => "update", :id => "1"), :path => member_path, :method => :put) - assert_recognizes(options[:shallow_options].merge(:action => "destroy", :id => "1"), :path => member_path, :method => :delete) - - assert_recognizes(route_options.merge(:action => "index", :format => "xml"), :path => "#{collection_path}.xml", :method => :get) - assert_recognizes(route_options.merge(:action => "new", :format => "xml"), :path => "#{new_path}.xml", :method => :get) - assert_recognizes(route_options.merge(:action => "create", :format => "xml"), :path => "#{collection_path}.xml", :method => :post) - assert_recognizes(options[:shallow_options].merge(:action => "show", :id => "1", :format => "xml"), :path => "#{member_path}.xml", :method => :get) - assert_recognizes(options[:shallow_options].merge(:action => "edit", :id => "1", :format => "xml"), :path => formatted_edit_member_path, :method => :get) - assert_recognizes(options[:shallow_options].merge(:action => "update", :id => "1", :format => "xml"), :path => "#{member_path}.xml", :method => :put) - assert_recognizes(options[:shallow_options].merge(:action => "destroy", :id => "1", :format => "xml"), :path => "#{member_path}.xml", :method => :delete) + controller.assert_routing member_path, action: "show", id: "1" + controller.assert_routing edit_member_path, action: "edit", id: "1" + controller.assert_routing "#{member_path}.xml", action: "show", id: "1", format: "xml" + controller.assert_routing formatted_edit_member_path, action: "edit", id: "1", format: "xml" + end + + assert_recognizes(route_options.merge(action: "index"), path: collection_path, method: :get) + assert_recognizes(route_options.merge(action: "new"), path: new_path, method: :get) + assert_recognizes(route_options.merge(action: "create"), path: collection_path, method: :post) + assert_recognizes(options[:shallow_options].merge(action: "show", id: "1"), path: member_path, method: :get) + assert_recognizes(options[:shallow_options].merge(action: "edit", id: "1"), path: edit_member_path, method: :get) + assert_recognizes(options[:shallow_options].merge(action: "update", id: "1"), path: member_path, method: :put) + assert_recognizes(options[:shallow_options].merge(action: "destroy", id: "1"), path: member_path, method: :delete) + + assert_recognizes(route_options.merge(action: "index", format: "xml"), path: "#{collection_path}.xml", method: :get) + assert_recognizes(route_options.merge(action: "new", format: "xml"), path: "#{new_path}.xml", method: :get) + assert_recognizes(route_options.merge(action: "create", format: "xml"), path: "#{collection_path}.xml", method: :post) + assert_recognizes(options[:shallow_options].merge(action: "show", id: "1", format: "xml"), path: "#{member_path}.xml", method: :get) + assert_recognizes(options[:shallow_options].merge(action: "edit", id: "1", format: "xml"), path: formatted_edit_member_path, method: :get) + assert_recognizes(options[:shallow_options].merge(action: "update", id: "1", format: "xml"), path: "#{member_path}.xml", method: :put) + assert_recognizes(options[:shallow_options].merge(action: "destroy", id: "1", format: "xml"), path: "#{member_path}.xml", method: :delete) yield route_options if block_given? end @@ -1238,14 +1238,14 @@ class ResourcesTest < ActionController::TestCase end assert_named_route "#{full_path}", "#{name_prefix}#{controller_name}_path", route_options - assert_named_route "#{full_path}.xml", "#{name_prefix}#{controller_name}_path", route_options.merge(:format => "xml") - assert_named_route "#{shallow_path}/1", "#{shallow_prefix}#{singular_name}_path", options[:shallow_options].merge(:id => "1") - assert_named_route "#{shallow_path}/1.xml", "#{shallow_prefix}#{singular_name}_path", options[:shallow_options].merge(:id => "1", :format => "xml") + assert_named_route "#{full_path}.xml", "#{name_prefix}#{controller_name}_path", route_options.merge(format: "xml") + assert_named_route "#{shallow_path}/1", "#{shallow_prefix}#{singular_name}_path", options[:shallow_options].merge(id: "1") + assert_named_route "#{shallow_path}/1.xml", "#{shallow_prefix}#{singular_name}_path", options[:shallow_options].merge(id: "1", format: "xml") assert_named_route "#{full_path}/#{new_action}", "new_#{name_prefix}#{singular_name}_path", route_options - assert_named_route "#{full_path}/#{new_action}.xml", "new_#{name_prefix}#{singular_name}_path", route_options.merge(:format => "xml") - assert_named_route "#{shallow_path}/1/#{edit_action}", "edit_#{shallow_prefix}#{singular_name}_path", options[:shallow_options].merge(:id => "1") - assert_named_route "#{shallow_path}/1/#{edit_action}.xml", "edit_#{shallow_prefix}#{singular_name}_path", options[:shallow_options].merge(:id => "1", :format => "xml") + assert_named_route "#{full_path}/#{new_action}.xml", "new_#{name_prefix}#{singular_name}_path", route_options.merge(format: "xml") + assert_named_route "#{shallow_path}/1/#{edit_action}", "edit_#{shallow_prefix}#{singular_name}_path", options[:shallow_options].merge(id: "1") + assert_named_route "#{shallow_path}/1/#{edit_action}.xml", "edit_#{shallow_prefix}#{singular_name}_path", options[:shallow_options].merge(id: "1", format: "xml") yield route_options if block_given? end @@ -1260,27 +1260,27 @@ class ResourcesTest < ActionController::TestCase formatted_edit_path = "#{full_path}/edit.xml" with_options route_options do |controller| - controller.assert_routing full_path, :action => "show" - controller.assert_routing new_path, :action => "new" - controller.assert_routing edit_path, :action => "edit" - controller.assert_routing "#{full_path}.xml", :action => "show", :format => "xml" - controller.assert_routing "#{new_path}.xml", :action => "new", :format => "xml" - controller.assert_routing formatted_edit_path, :action => "edit", :format => "xml" - end - - assert_recognizes(route_options.merge(:action => "show"), :path => full_path, :method => :get) - assert_recognizes(route_options.merge(:action => "new"), :path => new_path, :method => :get) - assert_recognizes(route_options.merge(:action => "edit"), :path => edit_path, :method => :get) - assert_recognizes(route_options.merge(:action => "create"), :path => full_path, :method => :post) - assert_recognizes(route_options.merge(:action => "update"), :path => full_path, :method => :put) - assert_recognizes(route_options.merge(:action => "destroy"), :path => full_path, :method => :delete) - - assert_recognizes(route_options.merge(:action => "show", :format => "xml"), :path => "#{full_path}.xml", :method => :get) - assert_recognizes(route_options.merge(:action => "new", :format => "xml"), :path => "#{new_path}.xml", :method => :get) - assert_recognizes(route_options.merge(:action => "edit", :format => "xml"), :path => formatted_edit_path, :method => :get) - assert_recognizes(route_options.merge(:action => "create", :format => "xml"), :path => "#{full_path}.xml", :method => :post) - assert_recognizes(route_options.merge(:action => "update", :format => "xml"), :path => "#{full_path}.xml", :method => :put) - assert_recognizes(route_options.merge(:action => "destroy", :format => "xml"), :path => "#{full_path}.xml", :method => :delete) + controller.assert_routing full_path, action: "show" + controller.assert_routing new_path, action: "new" + controller.assert_routing edit_path, action: "edit" + controller.assert_routing "#{full_path}.xml", action: "show", format: "xml" + controller.assert_routing "#{new_path}.xml", action: "new", format: "xml" + controller.assert_routing formatted_edit_path, action: "edit", format: "xml" + end + + assert_recognizes(route_options.merge(action: "show"), path: full_path, method: :get) + assert_recognizes(route_options.merge(action: "new"), path: new_path, method: :get) + assert_recognizes(route_options.merge(action: "edit"), path: edit_path, method: :get) + assert_recognizes(route_options.merge(action: "create"), path: full_path, method: :post) + assert_recognizes(route_options.merge(action: "update"), path: full_path, method: :put) + assert_recognizes(route_options.merge(action: "destroy"), path: full_path, method: :delete) + + assert_recognizes(route_options.merge(action: "show", format: "xml"), path: "#{full_path}.xml", method: :get) + assert_recognizes(route_options.merge(action: "new", format: "xml"), path: "#{new_path}.xml", method: :get) + assert_recognizes(route_options.merge(action: "edit", format: "xml"), path: formatted_edit_path, method: :get) + assert_recognizes(route_options.merge(action: "create", format: "xml"), path: "#{full_path}.xml", method: :post) + assert_recognizes(route_options.merge(action: "update", format: "xml"), path: "#{full_path}.xml", method: :put) + assert_recognizes(route_options.merge(action: "destroy", format: "xml"), path: "#{full_path}.xml", method: :delete) yield route_options if block_given? end @@ -1297,12 +1297,12 @@ class ResourcesTest < ActionController::TestCase name_prefix = options[:name_prefix] assert_named_route "#{full_path}", "#{name_prefix}#{singleton_name}_path", route_options - assert_named_route "#{full_path}.xml", "#{name_prefix}#{singleton_name}_path", route_options.merge(:format => "xml") + assert_named_route "#{full_path}.xml", "#{name_prefix}#{singleton_name}_path", route_options.merge(format: "xml") assert_named_route "#{full_path}/new", "new_#{name_prefix}#{singleton_name}_path", route_options - assert_named_route "#{full_path}/new.xml", "new_#{name_prefix}#{singleton_name}_path", route_options.merge(:format => "xml") + assert_named_route "#{full_path}/new.xml", "new_#{name_prefix}#{singleton_name}_path", route_options.merge(format: "xml") assert_named_route "#{full_path}/edit", "edit_#{name_prefix}#{singleton_name}_path", route_options - assert_named_route "#{full_path}/edit.xml", "edit_#{name_prefix}#{singleton_name}_path", route_options.merge(:format => "xml") + assert_named_route "#{full_path}/edit.xml", "edit_#{name_prefix}#{singleton_name}_path", route_options.merge(format: "xml") end def assert_named_route(expected, route, options) @@ -1321,7 +1321,7 @@ class ResourcesTest < ActionController::TestCase def assert_resource_allowed_routes(controller, options, shallow_options, allowed, not_allowed, path = controller) shallow_path = "#{path}/#{shallow_options[:id]}" format = options[:format] && ".#{options[:format]}" - options.merge!(:controller => controller) + options.merge!(controller: controller) shallow_options.merge!(options) assert_whether_allowed(allowed, not_allowed, options, "index", "#{path}#{format}", :get) @@ -1335,7 +1335,7 @@ class ResourcesTest < ActionController::TestCase def assert_singleton_resource_allowed_routes(controller, options, allowed, not_allowed, path = controller.singularize) format = options[:format] && ".#{options[:format]}" - options.merge!(:controller => controller) + options.merge!(controller: controller) assert_whether_allowed(allowed, not_allowed, options, "new", "#{path}/new#{format}", :get) assert_whether_allowed(allowed, not_allowed, options, "create", "#{path}#{format}", :post) @@ -1347,8 +1347,8 @@ class ResourcesTest < ActionController::TestCase def assert_whether_allowed(allowed, not_allowed, options, action, path, method) action = action.to_sym - options = options.merge(:action => action.to_s) - path_options = { :path => path, :method => method } + options = options.merge(action: action.to_s) + path_options = { path: path, method: method } if Array(allowed).include?(action) assert_recognizes options, path_options diff --git a/actionpack/test/controller/routing_test.rb b/actionpack/test/controller/routing_test.rb index f8a3d7cd5b..7d506c1976 100644 --- a/actionpack/test/controller/routing_test.rb +++ b/actionpack/test/controller/routing_test.rb @@ -30,28 +30,28 @@ class UriReservedCharactersRoutingTest < ActiveSupport::TestCase def test_route_generation_escapes_unsafe_path_characters assert_equal "/content/act#{@escaped}ion/var#{@escaped}iable/add#{@escaped}itional-1/add#{@escaped}itional-2", url_for(@set, { - :controller => "content", - :action => "act#{@segment}ion", - :variable => "var#{@segment}iable", - :additional => ["add#{@segment}itional-1", "add#{@segment}itional-2"] + controller: "content", + action: "act#{@segment}ion", + variable: "var#{@segment}iable", + additional: ["add#{@segment}itional-1", "add#{@segment}itional-2"] }) end def test_route_recognition_unescapes_path_components - options = { :controller => "content", - :action => "act#{@segment}ion", - :variable => "var#{@segment}iable", - :additional => "add#{@segment}itional-1/add#{@segment}itional-2" } + options = { controller: "content", + action: "act#{@segment}ion", + variable: "var#{@segment}iable", + additional: "add#{@segment}itional-1/add#{@segment}itional-2" } assert_equal options, @set.recognize_path("/content/act#{@escaped}ion/var#{@escaped}iable/add#{@escaped}itional-1/add#{@escaped}itional-2") end def test_route_generation_allows_passing_non_string_values_to_generated_helper assert_equal "/content/action/variable/1/2", url_for(@set, { - :controller => "content", - :action => "action", - :variable => "variable", - :additional => [1, 2] + controller: "content", + action: "action", + variable: "variable", + additional: [1, 2] }) end end @@ -86,7 +86,7 @@ class LegacyRouteSetTests < ActiveSupport::TestCase def test_symbols_with_dashes rs.draw do - get "/:artist/:song-omg", :to => lambda { |env| + get "/:artist/:song-omg", to: lambda { |env| resp = ActiveSupport::JSON.encode ActionDispatch::Request.new(env).path_parameters [200, {}, [resp]] } @@ -98,7 +98,7 @@ class LegacyRouteSetTests < ActiveSupport::TestCase def test_id_with_dash rs.draw do - get "/journey/:id", :to => lambda { |env| + get "/journey/:id", to: lambda { |env| resp = ActiveSupport::JSON.encode ActionDispatch::Request.new(env).path_parameters [200, {}, [resp]] } @@ -110,7 +110,7 @@ class LegacyRouteSetTests < ActiveSupport::TestCase def test_dash_with_custom_regexp rs.draw do - get "/:artist/:song-omg", :constraints => { :song => /\d+/ }, :to => lambda { |env| + get "/:artist/:song-omg", constraints: { song: /\d+/ }, to: lambda { |env| resp = ActiveSupport::JSON.encode ActionDispatch::Request.new(env).path_parameters [200, {}, [resp]] } @@ -123,7 +123,7 @@ class LegacyRouteSetTests < ActiveSupport::TestCase def test_pre_dash rs.draw do - get "/:artist/omg-:song", :to => lambda { |env| + get "/:artist/omg-:song", to: lambda { |env| resp = ActiveSupport::JSON.encode ActionDispatch::Request.new(env).path_parameters [200, {}, [resp]] } @@ -135,7 +135,7 @@ class LegacyRouteSetTests < ActiveSupport::TestCase def test_pre_dash_with_custom_regexp rs.draw do - get "/:artist/omg-:song", :constraints => { :song => /\d+/ }, :to => lambda { |env| + get "/:artist/omg-:song", constraints: { song: /\d+/ }, to: lambda { |env| resp = ActiveSupport::JSON.encode ActionDispatch::Request.new(env).path_parameters [200, {}, [resp]] } @@ -148,10 +148,10 @@ class LegacyRouteSetTests < ActiveSupport::TestCase def test_star_paths_are_greedy rs.draw do - get "/*path", :to => lambda { |env| + get "/*path", to: lambda { |env| x = env["action_dispatch.request.path_parameters"][:path] [200, {}, [x]] - }, :format => false + }, format: false end u = URI("http://example.org/foo/bar.html") @@ -160,7 +160,7 @@ class LegacyRouteSetTests < ActiveSupport::TestCase def test_star_paths_are_greedy_but_not_too_much rs.draw do - get "/*path", :to => lambda { |env| + get "/*path", to: lambda { |env| x = ActiveSupport::JSON.encode env["action_dispatch.request.path_parameters"] [200, {}, [x]] } @@ -173,10 +173,10 @@ class LegacyRouteSetTests < ActiveSupport::TestCase def test_optional_star_paths_are_greedy rs.draw do - get "/(*filters)", :to => lambda { |env| + get "/(*filters)", to: lambda { |env| x = env["action_dispatch.request.path_parameters"][:filters] [200, {}, [x]] - }, :format => false + }, format: false end u = URI("http://example.org/ne_27.065938,-80.6092/sw_25.489856,-82.542794") @@ -185,7 +185,7 @@ class LegacyRouteSetTests < ActiveSupport::TestCase def test_optional_star_paths_are_greedy_but_not_too_much rs.draw do - get "/(*filters)", :to => lambda { |env| + get "/(*filters)", to: lambda { |env| x = ActiveSupport::JSON.encode env["action_dispatch.request.path_parameters"] [200, {}, [x]] } @@ -199,11 +199,11 @@ class LegacyRouteSetTests < ActiveSupport::TestCase def test_regexp_precidence rs.draw do - get "/whois/:domain", :constraints => { - :domain => /\w+\.[\w\.]+/ }, - :to => lambda { |env| [200, {}, %w{regexp}] } + get "/whois/:domain", constraints: { + domain: /\w+\.[\w\.]+/ }, + to: lambda { |env| [200, {}, %w{regexp}] } - get "/whois/:id", :to => lambda { |env| [200, {}, %w{id}] } + get "/whois/:id", to: lambda { |env| [200, {}, %w{id}] } end assert_equal "regexp", get(URI("http://example.org/whois/example.org")) @@ -218,10 +218,10 @@ class LegacyRouteSetTests < ActiveSupport::TestCase } rs.draw do - get "/", :constraints => subdomain.new, - :to => lambda { |env| [200, {}, %w{default}] } - get "/", :constraints => { :subdomain => "clients" }, - :to => lambda { |env| [200, {}, %w{clients}] } + get "/", constraints: subdomain.new, + to: lambda { |env| [200, {}, %w{default}] } + get "/", constraints: { subdomain: "clients" }, + to: lambda { |env| [200, {}, %w{clients}] } end assert_equal "default", get(URI("http://www.example.org/")) @@ -230,13 +230,13 @@ class LegacyRouteSetTests < ActiveSupport::TestCase def test_lambda_constraints rs.draw do - get "/", :constraints => lambda { |req| + get "/", constraints: lambda { |req| req.subdomain.present? and req.subdomain != "clients" }, - :to => lambda { |env| [200, {}, %w{default}] } + to: lambda { |env| [200, {}, %w{default}] } - get "/", :constraints => lambda { |req| + get "/", constraints: lambda { |req| req.subdomain.present? && req.subdomain == "clients" }, - :to => lambda { |env| [200, {}, %w{clients}] } + to: lambda { |env| [200, {}, %w{clients}] } end assert_equal "default", get(URI("http://www.example.org/")) @@ -246,8 +246,8 @@ class LegacyRouteSetTests < ActiveSupport::TestCase def test_scoped_lambda scope_called = false rs.draw do - scope "/foo", :constraints => lambda { |req| scope_called = true } do - get "/", :to => lambda { |env| [200, {}, %w{default}] } + scope "/foo", constraints: lambda { |req| scope_called = true } do + get "/", to: lambda { |env| [200, {}, %w{default}] } end end @@ -259,9 +259,9 @@ class LegacyRouteSetTests < ActiveSupport::TestCase inner_called = false rs.draw do - scope "/foo", :constraints => lambda { |req| flunk "should not be called" } do - get "/", :constraints => lambda { |req| inner_called = true }, - :to => lambda { |env| [200, {}, %w{default}] } + scope "/foo", constraints: lambda { |req| flunk "should not be called" } do + get "/", constraints: lambda { |req| inner_called = true }, + to: lambda { |env| [200, {}, %w{default}] } end end @@ -271,8 +271,8 @@ class LegacyRouteSetTests < ActiveSupport::TestCase def test_empty_string_match rs.draw do - get "/:username", :constraints => { :username => /[^\/]+/ }, - :to => lambda { |e| [200, {}, ["foo"]] } + get "/:username", constraints: { username: /[^\/]+/ }, + to: lambda { |e| [200, {}, ["foo"]] } end assert_equal "Not Found", get(URI("http://example.org/")) assert_equal "foo", get(URI("http://example.org/hello")) @@ -281,14 +281,14 @@ class LegacyRouteSetTests < ActiveSupport::TestCase def test_non_greedy_glob_regexp params = nil rs.draw do - get "/posts/:id(/*filters)", :constraints => { :filters => /.+?/ }, - :to => lambda { |e| + get "/posts/:id(/*filters)", constraints: { filters: /.+?/ }, + to: lambda { |e| params = e["action_dispatch.request.path_parameters"] [200, {}, ["foo"]] } end assert_equal "foo", get(URI("http://example.org/posts/1/foo.js")) - assert_equal({:id=>"1", :filters=>"foo", :format=>"js"}, params) + assert_equal({id: "1", filters: "foo", format: "js"}, params) end def test_specific_controller_action_failure @@ -297,30 +297,30 @@ class LegacyRouteSetTests < ActiveSupport::TestCase end assert_raises(ActionController::UrlGenerationError) do - url_for(rs, :controller => "omg", :action => "lol") + url_for(rs, controller: "omg", action: "lol") end end def test_default_setup rs.draw { ActiveSupport::Deprecation.silence { get "/:controller(/:action(/:id))" } } - assert_equal({:controller => "content", :action => "index"}, rs.recognize_path("/content")) - assert_equal({:controller => "content", :action => "list"}, rs.recognize_path("/content/list")) - assert_equal({:controller => "content", :action => "show", :id => "10"}, rs.recognize_path("/content/show/10")) + assert_equal({controller: "content", action: "index"}, rs.recognize_path("/content")) + assert_equal({controller: "content", action: "list"}, rs.recognize_path("/content/list")) + assert_equal({controller: "content", action: "show", id: "10"}, rs.recognize_path("/content/show/10")) - assert_equal({:controller => "admin/user", :action => "show", :id => "10"}, rs.recognize_path("/admin/user/show/10")) + assert_equal({controller: "admin/user", action: "show", id: "10"}, rs.recognize_path("/admin/user/show/10")) - assert_equal "/admin/user/show/10", url_for(rs, { :controller => "admin/user", :action => "show", :id => 10 }) + assert_equal "/admin/user/show/10", url_for(rs, { controller: "admin/user", action: "show", id: 10 }) get URI("http://test.host/admin/user/list/10") - assert_equal({ :controller => "admin/user", :action => "list", :id => "10" }, + assert_equal({ controller: "admin/user", action: "list", id: "10" }, controller.request.path_parameters) - assert_equal "/admin/user/show", controller.url_for({ :action => "show", :only_path => true }) - assert_equal "/admin/user/list/10", controller.url_for({:only_path => true}) + assert_equal "/admin/user/show", controller.url_for({ action: "show", only_path: true }) + assert_equal "/admin/user/list/10", controller.url_for({only_path: true}) - assert_equal "/admin/stuff", controller.url_for({ :controller => "stuff", :only_path => true }) - assert_equal "/stuff", controller.url_for({ :controller => "/stuff", :only_path => true }) + assert_equal "/admin/stuff", controller.url_for({ controller: "stuff", only_path: true }) + assert_equal "/stuff", controller.url_for({ controller: "/stuff", only_path: true }) end def test_route_with_colon_first @@ -348,28 +348,28 @@ class LegacyRouteSetTests < ActiveSupport::TestCase def test_route_with_regexp_for_controller rs.draw do ActiveSupport::Deprecation.silence do - get ":controller/:admintoken(/:action(/:id))", :controller => /admin\/.+/ + get ":controller/:admintoken(/:action(/:id))", controller: /admin\/.+/ get "/:controller(/:action(/:id))" end end - assert_equal({:controller => "admin/user", :admintoken => "foo", :action => "index"}, + assert_equal({controller: "admin/user", admintoken: "foo", action: "index"}, rs.recognize_path("/admin/user/foo")) - assert_equal({:controller => "content", :action => "foo"}, + assert_equal({controller: "content", action: "foo"}, rs.recognize_path("/content/foo")) - assert_equal "/admin/user/foo", url_for(rs, { :controller => "admin/user", :admintoken => "foo", :action => "index" }) - assert_equal "/content/foo", url_for(rs, { :controller => "content", :action => "foo" }) + assert_equal "/admin/user/foo", url_for(rs, { controller: "admin/user", admintoken: "foo", action: "index" }) + assert_equal "/content/foo", url_for(rs, { controller: "content", action: "foo" }) end def test_route_with_regexp_and_captures_for_controller rs.draw do ActiveSupport::Deprecation.silence do - get "/:controller(/:action(/:id))", :controller => /admin\/(accounts|users)/ + get "/:controller(/:action(/:id))", controller: /admin\/(accounts|users)/ end end - assert_equal({:controller => "admin/accounts", :action => "index"}, rs.recognize_path("/admin/accounts")) - assert_equal({:controller => "admin/users", :action => "index"}, rs.recognize_path("/admin/users")) + assert_equal({controller: "admin/accounts", action: "index"}, rs.recognize_path("/admin/accounts")) + assert_equal({controller: "admin/users", action: "index"}, rs.recognize_path("/admin/users")) assert_raise(ActionController::RoutingError) { rs.recognize_path("/admin/products") } end @@ -377,30 +377,30 @@ class LegacyRouteSetTests < ActiveSupport::TestCase rs.draw do ActiveSupport::Deprecation.silence do get ":controller/:action/:file", - :controller => /admin|user/, - :action => /upload|download/, - :defaults => {:file => nil}, - :constraints => {:file => %r{[^/]+(\.[^/]+)?}} + controller: /admin|user/, + action: /upload|download/, + defaults: {file: nil}, + constraints: {file: %r{[^/]+(\.[^/]+)?}} end end # Without a file extension assert_equal "/user/download/file", - url_for(rs, { :controller => "user", :action => "download", :file => "file" }) + url_for(rs, { controller: "user", action: "download", file: "file" }) - assert_equal({:controller => "user", :action => "download", :file => "file"}, + assert_equal({controller: "user", action: "download", file: "file"}, rs.recognize_path("/user/download/file")) # Now, let's try a file with an extension, really a dot (.) assert_equal "/user/download/file.jpg", - url_for(rs, { :controller => "user", :action => "download", :file => "file.jpg" }) + url_for(rs, { controller: "user", action: "download", file: "file.jpg" }) - assert_equal({:controller => "user", :action => "download", :file => "file.jpg"}, + assert_equal({controller: "user", action: "download", file: "file.jpg"}, rs.recognize_path("/user/download/file.jpg")) end def test_basic_named_route rs.draw do - root :to => "content#list", :as => "home" + root to: "content#list", as: "home" end assert_equal("http://test.host/", setup_for_named_route.send(:home_url)) end @@ -411,7 +411,7 @@ class LegacyRouteSetTests < ActiveSupport::TestCase end assert_equal("http://test.host/page/new%20stuff", - setup_for_named_route.send(:page_url, :title => "new stuff")) + setup_for_named_route.send(:page_url, title: "new stuff")) end def test_named_route_with_default @@ -420,7 +420,7 @@ class LegacyRouteSetTests < ActiveSupport::TestCase end assert_equal("http://test.host/page/AboutRails", - setup_for_named_route.send(:page_url, :title => "AboutRails")) + setup_for_named_route.send(:page_url, title: "AboutRails")) end def test_named_route_with_path_prefix @@ -469,14 +469,14 @@ class LegacyRouteSetTests < ActiveSupport::TestCase def test_named_route_without_hash rs.draw do ActiveSupport::Deprecation.silence do - get ":controller/:action/:id", :as => "normal" + get ":controller/:action/:id", as: "normal" end end end def test_named_route_root rs.draw do - root :to => "hello#index" + root to: "hello#index" end routes = setup_for_named_route assert_equal("http://test.host/", routes.send(:root_url)) @@ -531,7 +531,7 @@ class LegacyRouteSetTests < ActiveSupport::TestCase routes = setup_for_named_route assert_equal "http://test.host/page/2005/6/10/hi", - routes.send(:article_url, :title => "hi", :day => 10, :year => 2005, :month => 6) + routes.send(:article_url, title: "hi", day: 10, year: 2005, month: 6) end def test_changing_controller @@ -540,7 +540,7 @@ class LegacyRouteSetTests < ActiveSupport::TestCase get URI("http://test.host/admin/user/index/10") assert_equal "/admin/stuff/show/10", - controller.url_for({:controller => "stuff", :action => "show", :id => 10, :only_path => true}) + controller.url_for({controller: "stuff", action: "show", id: 10, only_path: true}) end def test_paths_escaped @@ -583,10 +583,10 @@ class LegacyRouteSetTests < ActiveSupport::TestCase def test_should_list_options_diff_when_routing_constraints_dont_match rs.draw do - get "post/:id" => "post#show", :constraints => { :id => /\d+/ }, :as => "post" + get "post/:id" => "post#show", :constraints => { id: /\d+/ }, :as => "post" end assert_raise(ActionController::UrlGenerationError) do - url_for(rs, { :controller => "post", :action => "show", :bad_param => "foo", :use_route => "post" }) + url_for(rs, { controller: "post", action: "show", bad_param: "foo", use_route: "post" }) end end @@ -596,7 +596,7 @@ class LegacyRouteSetTests < ActiveSupport::TestCase end assert_equal "/pages/boo", - url_for(rs, { :controller => "content", :action => "show_file", :path => %w(pages boo) }) + url_for(rs, { controller: "content", action: "show_file", path: %w(pages boo) }) end def test_dynamic_recall_paths_allowed @@ -605,11 +605,11 @@ class LegacyRouteSetTests < ActiveSupport::TestCase end get URI("http://test.host/pages/boo") - assert_equal({:controller=>"content", :action=>"show_file", :path=>"pages/boo"}, + assert_equal({controller: "content", action: "show_file", path: "pages/boo"}, controller.request.path_parameters) assert_equal "/pages/boo", - controller.url_for(:only_path => true) + controller.url_for(only_path: true) end def test_backwards @@ -621,9 +621,9 @@ class LegacyRouteSetTests < ActiveSupport::TestCase end get URI("http://test.host/pages/show") - assert_equal "/page/20", controller.url_for({ :id => 20, :only_path => true }) - assert_equal "/page/20", url_for(rs, { :controller => "pages", :id => 20, :action => "show" }) - assert_equal "/pages/boo", url_for(rs, { :controller => "pages", :action => "boo" }) + assert_equal "/page/20", controller.url_for({ id: 20, only_path: true }) + assert_equal "/page/20", url_for(rs, { controller: "pages", id: 20, action: "show" }) + assert_equal "/pages/boo", url_for(rs, { controller: "pages", action: "boo" }) end def test_route_with_integer_default @@ -635,14 +635,14 @@ class LegacyRouteSetTests < ActiveSupport::TestCase end end - assert_equal "/page", url_for(rs, { :controller => "content", :action => "show_page" }) - assert_equal "/page", url_for(rs, { :controller => "content", :action => "show_page", :id => 1 }) - assert_equal "/page", url_for(rs, { :controller => "content", :action => "show_page", :id => "1" }) - assert_equal "/page/10", url_for(rs, { :controller => "content", :action => "show_page", :id => 10 }) + assert_equal "/page", url_for(rs, { controller: "content", action: "show_page" }) + assert_equal "/page", url_for(rs, { controller: "content", action: "show_page", id: 1 }) + assert_equal "/page", url_for(rs, { controller: "content", action: "show_page", id: "1" }) + assert_equal "/page/10", url_for(rs, { controller: "content", action: "show_page", id: 10 }) - assert_equal({:controller => "content", :action => "show_page", :id => 1 }, rs.recognize_path("/page")) - assert_equal({:controller => "content", :action => "show_page", :id => "1"}, rs.recognize_path("/page/1")) - assert_equal({:controller => "content", :action => "show_page", :id => "10"}, rs.recognize_path("/page/10")) + assert_equal({controller: "content", action: "show_page", id: 1 }, rs.recognize_path("/page")) + assert_equal({controller: "content", action: "show_page", id: "1"}, rs.recognize_path("/page/1")) + assert_equal({controller: "content", action: "show_page", id: "10"}, rs.recognize_path("/page/10")) end # For newer revision @@ -655,40 +655,40 @@ class LegacyRouteSetTests < ActiveSupport::TestCase end end - assert_equal "/page/foo", url_for(rs, { :controller => "content", :action => "show_page", :id => "foo" }) - assert_equal({ :controller => "content", :action => "show_page", :id => "foo" }, rs.recognize_path("/page/foo")) + assert_equal "/page/foo", url_for(rs, { controller: "content", action: "show_page", id: "foo" }) + assert_equal({ controller: "content", action: "show_page", id: "foo" }, rs.recognize_path("/page/foo")) token = "\321\202\320\265\320\272\321\201\321\202" # 'text' in Russian token.force_encoding(Encoding::BINARY) escaped_token = CGI::escape(token) - assert_equal "/page/" + escaped_token, url_for(rs, { :controller => "content", :action => "show_page", :id => token }) - assert_equal({ :controller => "content", :action => "show_page", :id => token }, rs.recognize_path("/page/#{escaped_token}")) + assert_equal "/page/" + escaped_token, url_for(rs, { controller: "content", action: "show_page", id: token }) + assert_equal({ controller: "content", action: "show_page", id: token }, rs.recognize_path("/page/#{escaped_token}")) end def test_action_expiry rs.draw { ActiveSupport::Deprecation.silence { get ":controller(/:action(/:id))" } } get URI("http://test.host/content/show") - assert_equal "/content", controller.url_for(:controller => "content", :only_path => true) + assert_equal "/content", controller.url_for(controller: "content", only_path: true) end def test_requirement_should_prevent_optional_id rs.draw do - get "post/:id" => "post#show", :constraints => {:id => /\d+/}, :as => "post" + get "post/:id" => "post#show", :constraints => {id: /\d+/}, :as => "post" end - assert_equal "/post/10", url_for(rs, { :controller => "post", :action => "show", :id => 10 }) + assert_equal "/post/10", url_for(rs, { controller: "post", action: "show", id: 10 }) assert_raise(ActionController::UrlGenerationError) do - url_for(rs, { :controller => "post", :action => "show" }) + url_for(rs, { controller: "post", action: "show" }) end end def test_both_requirement_and_optional rs.draw do get("test(/:year)" => "post#show", :as => "blog", - :defaults => { :year => nil }, - :constraints => { :year => /\d{4}/ } + :defaults => { year: nil }, + :constraints => { year: /\d{4}/ } ) ActiveSupport::Deprecation.silence do @@ -696,8 +696,8 @@ class LegacyRouteSetTests < ActiveSupport::TestCase end end - assert_equal "/test", url_for(rs, { :controller => "post", :action => "show" }) - assert_equal "/test", url_for(rs, { :controller => "post", :action => "show", :year => nil }) + assert_equal "/test", url_for(rs, { controller: "post", action: "show" }) + assert_equal "/test", url_for(rs, { controller: "post", action: "show", year: nil }) assert_equal("http://test.host/test", setup_for_named_route.send(:blog_url)) end @@ -712,42 +712,42 @@ class LegacyRouteSetTests < ActiveSupport::TestCase end assert_equal "/pages/2005", - url_for(rs, { :controller => "content", :action => "list_pages", :year => 2005 }) + url_for(rs, { controller: "content", action: "list_pages", year: 2005 }) assert_equal "/pages/2005/6", - url_for(rs, { :controller => "content", :action => "list_pages", :year => 2005, :month => 6 }) + url_for(rs, { controller: "content", action: "list_pages", year: 2005, month: 6 }) assert_equal "/pages/2005/6/12", - url_for(rs, { :controller => "content", :action => "list_pages", :year => 2005, :month => 6, :day => 12 }) + url_for(rs, { controller: "content", action: "list_pages", year: 2005, month: 6, day: 12 }) get URI("http://test.host/pages/2005/6/12") - assert_equal({ :controller => "content", :action => "list_pages", :year => "2005", :month => "6", :day => "12" }, + assert_equal({ controller: "content", action: "list_pages", year: "2005", month: "6", day: "12" }, controller.request.path_parameters) assert_equal "/pages/2005/6/4", - controller.url_for({ :day => 4, :only_path => true }) + controller.url_for({ day: 4, only_path: true }) assert_equal "/pages/2005/6", - controller.url_for({ :day => nil, :only_path => true }) + controller.url_for({ day: nil, only_path: true }) assert_equal "/pages/2005", - controller.url_for({ :day => nil, :month => nil, :only_path => true }) + controller.url_for({ day: nil, month: nil, only_path: true }) end def test_root_url_generation_with_controller_and_action rs.draw do - root :to => "content#index" + root to: "content#index" end - assert_equal "/", url_for(rs, { :controller => "content", :action => "index" }) - assert_equal "/", url_for(rs, { :controller => "content" }) + assert_equal "/", url_for(rs, { controller: "content", action: "index" }) + assert_equal "/", url_for(rs, { controller: "content" }) end def test_named_root_url_generation_with_controller_and_action rs.draw do - root :to => "content#index", :as => "home" + root to: "content#index", as: "home" end - assert_equal "/", url_for(rs, { :controller => "content", :action => "index" }) - assert_equal "/", url_for(rs, { :controller => "content" }) + assert_equal "/", url_for(rs, { controller: "content", action: "index" }) + assert_equal "/", url_for(rs, { controller: "content" }) assert_equal("http://test.host/", setup_for_named_route.send(:home_url)) end @@ -761,8 +761,8 @@ class LegacyRouteSetTests < ActiveSupport::TestCase end end - assert_equal "/categories", url_for(rs, { :controller => "content", :action => "categories" }) - assert_equal "/content/hi", url_for(rs, { :controller => "content", :action => "hi" }) + assert_equal "/categories", url_for(rs, { controller: "content", action: "categories" }) + assert_equal "/content/hi", url_for(rs, { controller: "content", action: "hi" }) end def test_named_routes_array @@ -781,10 +781,10 @@ class LegacyRouteSetTests < ActiveSupport::TestCase end assert_equal "/journal", url_for(rs, { - :controller => "content", - :action => "list_journal", - :date => nil, - :user_id => nil + controller: "content", + action: "list_journal", + date: nil, + user_id: nil }) end @@ -797,7 +797,7 @@ class LegacyRouteSetTests < ActiveSupport::TestCase %w(GET PATCH POST PUT DELETE).each do |request_method| define_method("test_request_method_recognized_with_#{request_method}") do setup_request_method_routes_for(request_method.downcase) - params = rs.recognize_path("/match", :method => request_method) + params = rs.recognize_path("/match", method: request_method) assert_equal request_method.downcase, params[:action] end end @@ -808,10 +808,10 @@ class LegacyRouteSetTests < ActiveSupport::TestCase put "/match" => "books#not_get_or_post" end - params = rs.recognize_path("/match", :method => :post) + params = rs.recognize_path("/match", method: :post) assert_equal "get_or_post", params[:action] - params = rs.recognize_path("/match", :method => :put) + params = rs.recognize_path("/match", method: :put) assert_equal "not_get_or_post", params[:action] end @@ -851,14 +851,14 @@ class LegacyRouteSetTests < ActiveSupport::TestCase end end - assert_equal "/books/7/edit", url_for(rs, { :controller => "subpath_books", :id => 7, :action => "edit" }) - assert_equal "/items/15/complete", url_for(rs, { :controller => "subpath_books", :id => 15, :action => "complete" }) - assert_equal "/posts/new/preview", url_for(rs, { :controller => "subpath_books", :action => "preview" }) + assert_equal "/books/7/edit", url_for(rs, { controller: "subpath_books", id: 7, action: "edit" }) + assert_equal "/items/15/complete", url_for(rs, { controller: "subpath_books", id: 15, action: "complete" }) + assert_equal "/posts/new/preview", url_for(rs, { controller: "subpath_books", action: "preview" }) end def test_failed_constraints_raises_exception_with_violated_constraints rs.draw do - get "foos/:id" => "foos#show", :as => "foo_with_requirement", :constraints => { :id => /\d+/ } + get "foos/:id" => "foos#show", :as => "foo_with_requirement", :constraints => { id: /\d+/ } end assert_raise(ActionController::UrlGenerationError) do @@ -933,14 +933,14 @@ class RouteSetTest < ActiveSupport::TestCase def test_generate_extras set.draw { ActiveSupport::Deprecation.silence { get ":controller/(:action(/:id))" } } - path, extras = set.generate_extras(:controller => "foo", :action => "bar", :id => 15, :this => "hello", :that => "world") + path, extras = set.generate_extras(controller: "foo", action: "bar", id: 15, this: "hello", that: "world") assert_equal "/foo/bar/15", path assert_equal %w(that this), extras.map(&:to_s).sort end def test_extra_keys set.draw { ActiveSupport::Deprecation.silence { get ":controller/:action/:id" } } - extras = set.extra_keys(:controller => "foo", :action => "bar", :id => 15, :this => "hello", :that => "world") + extras = set.extra_keys(controller: "foo", action: "bar", id: 15, this: "hello", that: "world") assert_equal %w(that this), extras.map(&:to_s).sort end @@ -951,7 +951,7 @@ class RouteSetTest < ActiveSupport::TestCase get ":controller/:action/:id" end end - path, extras = set.generate_extras(:controller => "foo", :action => "bar", :id => 15, :this => "hello", :that => "world") + path, extras = set.generate_extras(controller: "foo", action: "bar", id: 15, this: "hello", that: "world") assert_equal "/foo/bar/15", path assert_equal %w(that this), extras.map(&:to_s).sort end @@ -964,7 +964,7 @@ class RouteSetTest < ActiveSupport::TestCase end end assert_equal "/foo/bar/15?this=hello", - url_for(set, { :controller => "foo", :action => "bar", :id => 15, :this => "hello" }) + url_for(set, { controller: "foo", action: "bar", id: 15, this: "hello" }) end def test_extra_keys_not_first @@ -974,7 +974,7 @@ class RouteSetTest < ActiveSupport::TestCase get ":controller/:action/:id" end end - extras = set.extra_keys(:controller => "foo", :action => "bar", :id => 15, :this => "hello", :that => "world") + extras = set.extra_keys(controller: "foo", action: "bar", id: 15, this: "hello", that: "world") assert_equal %w(that this), extras.map(&:to_s).sort end @@ -991,7 +991,7 @@ class RouteSetTest < ActiveSupport::TestCase set.draw do get "/users/index" => "users#index" end - set.recognize_path("/users/index", :method => :get) + set.recognize_path("/users/index", method: :get) assert_equal 1, set.routes.size end @@ -1028,8 +1028,8 @@ class RouteSetTest < ActiveSupport::TestCase def test_named_route_url_method controller = setup_named_route_test - assert_equal "http://test.host/people/5", controller.send(:show_url, :id => 5) - assert_equal "/people/5", controller.send(:show_path, :id => 5) + assert_equal "http://test.host/people/5", controller.send(:show_url, id: 5) + assert_equal "/people/5", controller.send(:show_path, id: 5) assert_equal "http://test.host/people", controller.send(:index_url) assert_equal "/people", controller.send(:index_path) @@ -1041,23 +1041,23 @@ class RouteSetTest < ActiveSupport::TestCase def test_named_route_url_method_with_anchor controller = setup_named_route_test - assert_equal "http://test.host/people/5#location", controller.send(:show_url, :id => 5, :anchor => "location") - assert_equal "/people/5#location", controller.send(:show_path, :id => 5, :anchor => "location") + assert_equal "http://test.host/people/5#location", controller.send(:show_url, id: 5, anchor: "location") + assert_equal "/people/5#location", controller.send(:show_path, id: 5, anchor: "location") - assert_equal "http://test.host/people#location", controller.send(:index_url, :anchor => "location") - assert_equal "/people#location", controller.send(:index_path, :anchor => "location") + assert_equal "http://test.host/people#location", controller.send(:index_url, anchor: "location") + assert_equal "/people#location", controller.send(:index_path, anchor: "location") - assert_equal "http://test.host/admin/users#location", controller.send(:users_url, :anchor => "location") - assert_equal "/admin/users#location", controller.send(:users_path, :anchor => "location") + assert_equal "http://test.host/admin/users#location", controller.send(:users_url, anchor: "location") + assert_equal "/admin/users#location", controller.send(:users_path, anchor: "location") assert_equal "http://test.host/people/go/7/hello/joe/5#location", - controller.send(:multi_url, 7, "hello", 5, :anchor => "location") + controller.send(:multi_url, 7, "hello", 5, anchor: "location") assert_equal "http://test.host/people/go/7/hello/joe/5?baz=bar#location", - controller.send(:multi_url, 7, "hello", 5, :baz => "bar", :anchor => "location") + controller.send(:multi_url, 7, "hello", 5, baz: "bar", anchor: "location") assert_equal "http://test.host/people?baz=bar#location", - controller.send(:index_url, :baz => "bar", :anchor => "location") + controller.send(:index_url, baz: "bar", anchor: "location") assert_equal "http://test.host/people", controller.send(:index_url, anchor: nil) assert_equal "http://test.host/people", controller.send(:index_url, anchor: false) @@ -1065,17 +1065,17 @@ class RouteSetTest < ActiveSupport::TestCase def test_named_route_url_method_with_port controller = setup_named_route_test - assert_equal "http://test.host:8080/people/5", controller.send(:show_url, 5, :port=>8080) + assert_equal "http://test.host:8080/people/5", controller.send(:show_url, 5, port: 8080) end def test_named_route_url_method_with_host controller = setup_named_route_test - assert_equal "http://some.example.com/people/5", controller.send(:show_url, 5, :host=>"some.example.com") + assert_equal "http://some.example.com/people/5", controller.send(:show_url, 5, host: "some.example.com") end def test_named_route_url_method_with_protocol controller = setup_named_route_test - assert_equal "https://test.host/people/5", controller.send(:show_url, 5, :protocol => "https") + assert_equal "https://test.host/people/5", controller.send(:show_url, 5, protocol: "https") end def test_named_route_url_method_with_ordered_parameters @@ -1087,7 +1087,7 @@ class RouteSetTest < ActiveSupport::TestCase def test_named_route_url_method_with_ordered_parameters_and_hash controller = setup_named_route_test assert_equal "http://test.host/people/go/7/hello/joe/5?baz=bar", - controller.send(:multi_url, 7, "hello", 5, :baz => "bar") + controller.send(:multi_url, 7, "hello", 5, baz: "bar") end def test_named_route_url_method_with_ordered_parameters_and_empty_hash @@ -1099,7 +1099,7 @@ class RouteSetTest < ActiveSupport::TestCase def test_named_route_url_method_with_no_positional_arguments controller = setup_named_route_test assert_equal "http://test.host/people?baz=bar", - controller.send(:index_url, :baz => "bar") + controller.send(:index_url, baz: "bar") end def test_draw_default_route @@ -1111,11 +1111,11 @@ class RouteSetTest < ActiveSupport::TestCase assert_equal 1, set.routes.size - assert_equal "/users/show/10", url_for(set, { :controller => "users", :action => "show", :id => 10 }) - assert_equal "/users/index/10", url_for(set, { :controller => "users", :id => 10 }) + assert_equal "/users/show/10", url_for(set, { controller: "users", action: "show", id: 10 }) + assert_equal "/users/index/10", url_for(set, { controller: "users", id: 10 }) - assert_equal({:controller => "users", :action => "index", :id => "10"}, set.recognize_path("/users/index/10")) - assert_equal({:controller => "users", :action => "index", :id => "10"}, set.recognize_path("/users/index/10/")) + assert_equal({controller: "users", action: "index", id: "10"}, set.recognize_path("/users/index/10")) + assert_equal({controller: "users", action: "index", id: "10"}, set.recognize_path("/users/index/10/")) end def test_route_with_parameter_shell @@ -1127,18 +1127,18 @@ class RouteSetTest < ActiveSupport::TestCase end end - assert_equal({:controller => "pages", :action => "index"}, request_path_params("/pages")) - assert_equal({:controller => "pages", :action => "index"}, request_path_params("/pages/index")) - assert_equal({:controller => "pages", :action => "list"}, request_path_params("/pages/list")) + assert_equal({controller: "pages", action: "index"}, request_path_params("/pages")) + assert_equal({controller: "pages", action: "index"}, request_path_params("/pages/index")) + assert_equal({controller: "pages", action: "list"}, request_path_params("/pages/list")) - assert_equal({:controller => "pages", :action => "show", :id => "10"}, request_path_params("/pages/show/10")) - assert_equal({:controller => "pages", :action => "show", :id => "10"}, request_path_params("/page/10")) + assert_equal({controller: "pages", action: "show", id: "10"}, request_path_params("/pages/show/10")) + assert_equal({controller: "pages", action: "show", id: "10"}, request_path_params("/page/10")) end def test_route_constraints_on_request_object_with_anchors_are_valid assert_nothing_raised do set.draw do - get "page/:id" => "pages#show", :constraints => { :host => /^foo$/ } + get "page/:id" => "pages#show", :constraints => { host: /^foo$/ } end end end @@ -1192,8 +1192,8 @@ class RouteSetTest < ActiveSupport::TestCase get "page/:id" => "pages#show", :id => /[a-zA-Z0-9\+]+/ end - assert_equal({:controller => "pages", :action => "show", :id => "10"}, request_path_params("/page/10")) - assert_equal({:controller => "pages", :action => "show", :id => "hello+world"}, request_path_params("/page/hello+world")) + assert_equal({controller: "pages", action: "show", id: "10"}, request_path_params("/page/10")) + assert_equal({controller: "pages", action: "show", id: "hello+world"}, request_path_params("/page/hello+world")) end def test_recognize_with_http_methods @@ -1206,54 +1206,54 @@ class RouteSetTest < ActiveSupport::TestCase delete "/people/:id" => "people#destroy" end - params = request_path_params("/people", :method => :get) + params = request_path_params("/people", method: :get) assert_equal("index", params[:action]) - params = request_path_params("/people", :method => :post) + params = request_path_params("/people", method: :post) assert_equal("create", params[:action]) - params = request_path_params("/people/5", :method => :put) + params = request_path_params("/people/5", method: :put) assert_equal("update", params[:action]) - params = request_path_params("/people/5", :method => :patch) + params = request_path_params("/people/5", method: :patch) assert_equal("update", params[:action]) assert_raise(ActionController::UnknownHttpMethod) { - request_path_params("/people", :method => :bacon) + request_path_params("/people", method: :bacon) } - params = request_path_params("/people/5", :method => :get) + params = request_path_params("/people/5", method: :get) assert_equal("show", params[:action]) assert_equal("5", params[:id]) - params = request_path_params("/people/5", :method => :put) + params = request_path_params("/people/5", method: :put) assert_equal("update", params[:action]) assert_equal("5", params[:id]) - params = request_path_params("/people/5", :method => :patch) + params = request_path_params("/people/5", method: :patch) assert_equal("update", params[:action]) assert_equal("5", params[:id]) - params = request_path_params("/people/5", :method => :delete) + params = request_path_params("/people/5", method: :delete) assert_equal("destroy", params[:action]) assert_equal("5", params[:id]) assert_raise(ActionController::RoutingError) { - request_path_params("/people/5", :method => :post) + request_path_params("/people/5", method: :post) } end def test_recognize_with_alias_in_conditions set.draw do match "/people" => "people#index", :as => "people", :via => :get - root :to => "people#index" + root to: "people#index" end - params = request_path_params("/people", :method => :get) + params = request_path_params("/people", method: :get) assert_equal("people", params[:controller]) assert_equal("index", params[:action]) - params = request_path_params("/", :method => :get) + params = request_path_params("/", method: :get) assert_equal("people", params[:controller]) assert_equal("index", params[:action]) end @@ -1264,7 +1264,7 @@ class RouteSetTest < ActiveSupport::TestCase :year => /\d{4}/, :day => /\d{1,2}/, :month => /\d{1,2}/ end - params = request_path_params("/articles/2005/11/05/a-very-interesting-article", :method => :get) + params = request_path_params("/articles/2005/11/05/a-very-interesting-article", method: :get) assert_equal("permalink", params[:action]) assert_equal("2005", params[:year]) assert_equal("11", params[:month]) @@ -1291,17 +1291,17 @@ class RouteSetTest < ActiveSupport::TestCase get "people/:id(.:format)" => "people#show" end - params = request_path_params("/people/5", :method => :get) + params = request_path_params("/people/5", method: :get) assert_equal("show", params[:action]) assert_equal("5", params[:id]) - params = request_path_params("/people/5", :method => :put) + params = request_path_params("/people/5", method: :put) assert_equal("update", params[:action]) - params = request_path_params("/people/5", :method => :patch) + params = request_path_params("/people/5", method: :patch) assert_equal("update", params[:action]) - params = request_path_params("/people/5.png", :method => :get) + params = request_path_params("/people/5.png", method: :get) assert_equal("show", params[:action]) assert_equal("5", params[:id]) assert_equal("png", params[:format]) @@ -1309,18 +1309,18 @@ class RouteSetTest < ActiveSupport::TestCase def test_generate_with_default_action set.draw do - get "/people", :controller => "people", :action => "index" - get "/people/list", :controller => "people", :action => "list" + get "/people", controller: "people", action: "index" + get "/people/list", controller: "people", action: "list" end - url = url_for(set, { :controller => "people", :action => "list" }) + url = url_for(set, { controller: "people", action: "list" }) assert_equal "/people/list", url end def test_root_map - set.draw { root :to => "people#index" } + set.draw { root to: "people#index" } - params = request_path_params("", :method => :get) + params = request_path_params("", method: :get) assert_equal("people", params[:controller]) assert_equal("index", params[:action]) end @@ -1334,7 +1334,7 @@ class RouteSetTest < ActiveSupport::TestCase end - params = request_path_params("/api/inventory", :method => :get) + params = request_path_params("/api/inventory", method: :get) assert_equal("api/products", params[:controller]) assert_equal("inventory", params[:action]) end @@ -1342,35 +1342,35 @@ class RouteSetTest < ActiveSupport::TestCase def test_namespaced_root_map set.draw do namespace "api" do - root :to => "products#index" + root to: "products#index" end end - params = request_path_params("/api", :method => :get) + params = request_path_params("/api", method: :get) assert_equal("api/products", params[:controller]) assert_equal("index", params[:action]) end def test_namespace_with_path_prefix set.draw do - scope :module => "api", :path => "prefix" do + scope module: "api", path: "prefix" do get "inventory" => "products#inventory" end end - params = request_path_params("/prefix/inventory", :method => :get) + params = request_path_params("/prefix/inventory", method: :get) assert_equal("api/products", params[:controller]) assert_equal("inventory", params[:action]) end def test_namespace_with_blank_path_prefix set.draw do - scope :module => "api", :path => "" do + scope module: "api", path: "" do get "inventory" => "products#inventory" end end - params = request_path_params("/inventory", :method => :get) + params = request_path_params("/inventory", method: :get) assert_equal("api/products", params[:controller]) assert_equal("inventory", params[:action]) end @@ -1386,7 +1386,7 @@ class RouteSetTest < ActiveSupport::TestCase get URI("http://test.host/people/7/show") - assert_equal "/people/7/destroy", controller.url_for(:action => "destroy", :only_path => true) + assert_equal "/people/7/destroy", controller.url_for(action: "destroy", only_path: true) end def test_use_static_path_when_possible @@ -1402,15 +1402,15 @@ class RouteSetTest < ActiveSupport::TestCase get URI("http://test.host/welcom/get/7") - assert_equal "/about", controller.url_for(:controller => "welcome", - :action => "about", - :only_path => true) + assert_equal "/about", controller.url_for(controller: "welcome", + action: "about", + only_path: true) end def test_generate set.draw { ActiveSupport::Deprecation.silence { get ":controller/:action/:id" } } - args = { :controller => "foo", :action => "bar", :id => "7", :x => "y" } + args = { controller: "foo", action: "bar", id: "7", x: "y" } assert_equal "/foo/bar/7?x=y", url_for(set, args) assert_equal ["/foo/bar/7", [:x]], set.generate_extras(args) assert_equal [:x], set.extra_keys(args) @@ -1425,7 +1425,7 @@ class RouteSetTest < ActiveSupport::TestCase end end - args = { :controller => "foo", :action => "bar", :id => "7", :x => "y" } + args = { controller: "foo", action: "bar", id: "7", x: "y" } assert_equal "/my/foo/bar/7?x=y", url_for(set, args) end @@ -1438,7 +1438,7 @@ class RouteSetTest < ActiveSupport::TestCase end end - args = { :controller => "foo", :action => "bar", :id => "7", :x => "y" } + args = { controller: "foo", action: "bar", id: "7", x: "y" } assert_equal "/foo/bar/7?x=y", url_for(set, args) end @@ -1453,14 +1453,14 @@ class RouteSetTest < ActiveSupport::TestCase end end - assert_equal({ :controller => "connection/manage", - :action => "index", }, request_path_params("/connection/manage")) + assert_equal({ controller: "connection/manage", + action: "index", }, request_path_params("/connection/manage")) - url = controller.url_for({ :controller => "connection", :only_path => true }) + url = controller.url_for({ controller: "connection", only_path: true }) assert_equal "/connection/connection", url - url = controller.url_for({ :use_route => "family_connection", - :controller => "connection", :only_path => true }) + url = controller.url_for({ use_route: "family_connection", + controller: "connection", only_path: true }) assert_equal "/connection", url end @@ -1475,9 +1475,9 @@ class RouteSetTest < ActiveSupport::TestCase get URI("http://test.host/books/show/10") - assert_equal "/books", controller.url_for(:controller => "books", - :only_path => true, - :action => "index") + assert_equal "/books", controller.url_for(controller: "books", + only_path: true, + action: "index") end def test_query_params_will_be_shown_when_recalled @@ -1494,7 +1494,7 @@ class RouteSetTest < ActiveSupport::TestCase get URI("http://test.host/weblog/show/1") assert_equal "/weblog/edit?parameter=1", controller.url_for( - {:action => "edit", :parameter => 1, :only_path => true}) + {action: "edit", parameter: 1, only_path: true}) end def test_format_is_not_inherit @@ -1503,14 +1503,14 @@ class RouteSetTest < ActiveSupport::TestCase end get URI("http://test.host/posts.xml") - assert_equal({:controller => "posts", :action => "index", :format => "xml"}, + assert_equal({controller: "posts", action: "index", format: "xml"}, controller.request.path_parameters) assert_equal "/posts", controller.url_for( - {:controller => "posts", :only_path => true}) + {controller: "posts", only_path: true}) assert_equal "/posts.xml", controller.url_for( - {:controller => "posts", :format => "xml", :only_path => true}) + {controller: "posts", format: "xml", only_path: true}) end def test_expiry_determination_should_consider_values_with_to_param @@ -1521,11 +1521,11 @@ class RouteSetTest < ActiveSupport::TestCase get URI("http://test.host/projects/1/weblog/show") assert_equal( - { :controller => "weblog", :action => "show", :project_id => "1" }, + { controller: "weblog", action: "show", project_id: "1" }, controller.request.path_parameters) assert_equal "/projects/1/weblog/show", - controller.url_for({ :action => "show", :project_id => 1, :only_path => true }) + controller.url_for({ action: "show", project_id: 1, only_path: true }) end def test_named_route_in_nested_resource @@ -1537,7 +1537,7 @@ class RouteSetTest < ActiveSupport::TestCase end end - params = set.recognize_path("/projects/1/milestones", :method => :get) + params = set.recognize_path("/projects/1/milestones", method: :get) assert_equal("milestones", params[:controller]) assert_equal("index", params[:action]) end @@ -1546,7 +1546,7 @@ class RouteSetTest < ActiveSupport::TestCase assert_nothing_raised do set.draw do namespace :admin do - root :to => "home#index" + root to: "home#index" end end end @@ -1556,7 +1556,7 @@ class RouteSetTest < ActiveSupport::TestCase assert_nothing_raised do set.draw do namespace "admin" do - root :to => "home#index" + root to: "home#index" end end end @@ -1566,7 +1566,7 @@ class RouteSetTest < ActiveSupport::TestCase assert_raise ArgumentError do set.draw do get "page/:name" => "pages#show", - :constraints => { :name => /(david|jamis)/m } + :constraints => { name: /(david|jamis)/m } end end end @@ -1575,13 +1575,13 @@ class RouteSetTest < ActiveSupport::TestCase assert_nothing_raised do set.draw do get "page/:name" => "pages#show", - :constraints => { :name => /(david|jamis)/i } + :constraints => { name: /(david|jamis)/i } end end assert_nothing_raised do set.draw do get "page/:name" => "pages#show", - :constraints => { :name => / # Desperately overcommented regexp + :constraints => { name: / # Desperately overcommented regexp ( #Either david #The Creator | #Or @@ -1599,7 +1599,7 @@ class RouteSetTest < ActiveSupport::TestCase return true } end - assert_equal({:controller => "pages", :action => "show", :name => "mypage"}, + assert_equal({controller: "pages", action: "show", name: "mypage"}, set.recognize_path("http://subdomain.example.org/page/mypage")) assert_equal(name_param, "mypage") end @@ -1607,42 +1607,42 @@ class RouteSetTest < ActiveSupport::TestCase def test_route_requirement_recognize_with_ignore_case set.draw do get "page/:name" => "pages#show", - :constraints => {:name => /(david|jamis)/i} + :constraints => {name: /(david|jamis)/i} end - assert_equal({:controller => "pages", :action => "show", :name => "jamis"}, set.recognize_path("/page/jamis")) + assert_equal({controller: "pages", action: "show", name: "jamis"}, set.recognize_path("/page/jamis")) assert_raise ActionController::RoutingError do set.recognize_path("/page/davidjamis") end - assert_equal({:controller => "pages", :action => "show", :name => "DAVID"}, set.recognize_path("/page/DAVID")) + assert_equal({controller: "pages", action: "show", name: "DAVID"}, set.recognize_path("/page/DAVID")) end def test_route_requirement_generate_with_ignore_case set.draw do get "page/:name" => "pages#show", - :constraints => {:name => /(david|jamis)/i} + :constraints => {name: /(david|jamis)/i} end - url = url_for(set, { :controller => "pages", :action => "show", :name => "david" }) + url = url_for(set, { controller: "pages", action: "show", name: "david" }) assert_equal "/page/david", url assert_raise(ActionController::UrlGenerationError) do - url_for(set, { :controller => "pages", :action => "show", :name => "davidjamis" }) + url_for(set, { controller: "pages", action: "show", name: "davidjamis" }) end - url = url_for(set, { :controller => "pages", :action => "show", :name => "JAMIS" }) + url = url_for(set, { controller: "pages", action: "show", name: "JAMIS" }) assert_equal "/page/JAMIS", url end def test_route_requirement_recognize_with_extended_syntax set.draw do get "page/:name" => "pages#show", - :constraints => {:name => / # Desperately overcommented regexp + :constraints => {name: / # Desperately overcommented regexp ( #Either david #The Creator | #Or jamis #The Deployer )/x} end - assert_equal({:controller => "pages", :action => "show", :name => "jamis"}, set.recognize_path("/page/jamis")) - assert_equal({:controller => "pages", :action => "show", :name => "david"}, set.recognize_path("/page/david")) + assert_equal({controller: "pages", action: "show", name: "jamis"}, set.recognize_path("/page/jamis")) + assert_equal({controller: "pages", action: "show", name: "david"}, set.recognize_path("/page/david")) assert_raise ActionController::RoutingError do set.recognize_path("/page/david #The Creator") end @@ -1654,7 +1654,7 @@ class RouteSetTest < ActiveSupport::TestCase def test_route_requirement_with_xi_modifiers set.draw do get "page/:name" => "pages#show", - :constraints => {:name => / # Desperately overcommented regexp + :constraints => {name: / # Desperately overcommented regexp ( #Either david #The Creator | #Or @@ -1662,20 +1662,20 @@ class RouteSetTest < ActiveSupport::TestCase )/xi} end - assert_equal({:controller => "pages", :action => "show", :name => "JAMIS"}, + assert_equal({controller: "pages", action: "show", name: "JAMIS"}, set.recognize_path("/page/JAMIS")) assert_equal "/page/JAMIS", - url_for(set, { :controller => "pages", :action => "show", :name => "JAMIS" }) + url_for(set, { controller: "pages", action: "show", name: "JAMIS" }) end def test_routes_with_symbols set.draw do - get "unnamed", :controller => :pages, :action => :show, :name => :as_symbol - get "named" , :controller => :pages, :action => :show, :name => :as_symbol, :as => :named + get "unnamed", controller: :pages, action: :show, name: :as_symbol + get "named" , controller: :pages, action: :show, name: :as_symbol, as: :named end - assert_equal({:controller => "pages", :action => "show", :name => :as_symbol}, set.recognize_path("/unnamed")) - assert_equal({:controller => "pages", :action => "show", :name => :as_symbol}, set.recognize_path("/named")) + assert_equal({controller: "pages", action: "show", name: :as_symbol}, set.recognize_path("/unnamed")) + assert_equal({controller: "pages", action: "show", name: :as_symbol}, set.recognize_path("/named")) end def test_regexp_chunk_should_add_question_mark_for_optionals @@ -1684,70 +1684,70 @@ class RouteSetTest < ActiveSupport::TestCase get "/hello" => "bar#index" end - assert_equal "/", url_for(set, { :controller => "foo" }) - assert_equal "/hello", url_for(set, { :controller => "bar" }) + assert_equal "/", url_for(set, { controller: "foo" }) + assert_equal "/hello", url_for(set, { controller: "bar" }) - assert_equal({:controller => "foo", :action => "index"}, set.recognize_path("/")) - assert_equal({:controller => "bar", :action => "index"}, set.recognize_path("/hello")) + assert_equal({controller: "foo", action: "index"}, set.recognize_path("/")) + assert_equal({controller: "bar", action: "index"}, set.recognize_path("/hello")) end def test_assign_route_options_with_anchor_chars set.draw do ActiveSupport::Deprecation.silence do - get "/cars/:action/:person/:car/", :controller => "cars" + get "/cars/:action/:person/:car/", controller: "cars" end end - assert_equal "/cars/buy/1/2", url_for(set, { :controller => "cars", :action => "buy", :person => "1", :car => "2" }) + assert_equal "/cars/buy/1/2", url_for(set, { controller: "cars", action: "buy", person: "1", car: "2" }) - assert_equal({:controller => "cars", :action => "buy", :person => "1", :car => "2"}, set.recognize_path("/cars/buy/1/2")) + assert_equal({controller: "cars", action: "buy", person: "1", car: "2"}, set.recognize_path("/cars/buy/1/2")) end def test_segmentation_of_dot_path set.draw do ActiveSupport::Deprecation.silence do - get "/books/:action.rss", :controller => "books" + get "/books/:action.rss", controller: "books" end end - assert_equal "/books/list.rss", url_for(set, { :controller => "books", :action => "list" }) + assert_equal "/books/list.rss", url_for(set, { controller: "books", action: "list" }) - assert_equal({:controller => "books", :action => "list"}, set.recognize_path("/books/list.rss")) + assert_equal({controller: "books", action: "list"}, set.recognize_path("/books/list.rss")) end def test_segmentation_of_dynamic_dot_path set.draw do ActiveSupport::Deprecation.silence do - get "/books(/:action(.:format))", :controller => "books" + get "/books(/:action(.:format))", controller: "books" end end - assert_equal "/books/list.rss", url_for(set, { :controller => "books", :action => "list", :format => "rss" }) - assert_equal "/books/list.xml", url_for(set, { :controller => "books", :action => "list", :format => "xml" }) - assert_equal "/books/list", url_for(set, { :controller => "books", :action => "list" }) - assert_equal "/books", url_for(set, { :controller => "books", :action => "index" }) + assert_equal "/books/list.rss", url_for(set, { controller: "books", action: "list", format: "rss" }) + assert_equal "/books/list.xml", url_for(set, { controller: "books", action: "list", format: "xml" }) + assert_equal "/books/list", url_for(set, { controller: "books", action: "list" }) + assert_equal "/books", url_for(set, { controller: "books", action: "index" }) - assert_equal({:controller => "books", :action => "list", :format => "rss"}, set.recognize_path("/books/list.rss")) - assert_equal({:controller => "books", :action => "list", :format => "xml"}, set.recognize_path("/books/list.xml")) - assert_equal({:controller => "books", :action => "list"}, set.recognize_path("/books/list")) - assert_equal({:controller => "books", :action => "index"}, set.recognize_path("/books")) + assert_equal({controller: "books", action: "list", format: "rss"}, set.recognize_path("/books/list.rss")) + assert_equal({controller: "books", action: "list", format: "xml"}, set.recognize_path("/books/list.xml")) + assert_equal({controller: "books", action: "list"}, set.recognize_path("/books/list")) + assert_equal({controller: "books", action: "index"}, set.recognize_path("/books")) end def test_slashes_are_implied set.draw { ActiveSupport::Deprecation.silence { get("/:controller(/:action(/:id))") } } - assert_equal "/content", url_for(set, { :controller => "content", :action => "index" }) - assert_equal "/content/list", url_for(set, { :controller => "content", :action => "list" }) - assert_equal "/content/show/1", url_for(set, { :controller => "content", :action => "show", :id => "1" }) + assert_equal "/content", url_for(set, { controller: "content", action: "index" }) + assert_equal "/content/list", url_for(set, { controller: "content", action: "list" }) + assert_equal "/content/show/1", url_for(set, { controller: "content", action: "show", id: "1" }) - assert_equal({:controller => "content", :action => "index"}, set.recognize_path("/content")) - assert_equal({:controller => "content", :action => "index"}, set.recognize_path("/content/index")) - assert_equal({:controller => "content", :action => "list"}, set.recognize_path("/content/list")) - assert_equal({:controller => "content", :action => "show", :id => "1"}, set.recognize_path("/content/show/1")) + assert_equal({controller: "content", action: "index"}, set.recognize_path("/content")) + assert_equal({controller: "content", action: "index"}, set.recognize_path("/content/index")) + assert_equal({controller: "content", action: "list"}, set.recognize_path("/content/list")) + assert_equal({controller: "content", action: "show", id: "1"}, set.recognize_path("/content/show/1")) end def test_default_route_recognition - expected = {:controller => "pages", :action => "show", :id => "10"} + expected = {controller: "pages", action: "show", id: "10"} assert_equal expected, default_route_set.recognize_path("/pages/show/10") assert_equal expected, default_route_set.recognize_path("/pages/show/10/") @@ -1767,19 +1767,19 @@ class RouteSetTest < ActiveSupport::TestCase end def test_default_route_should_omit_default_action - assert_equal "/accounts", url_for(default_route_set, { :controller => "accounts", :action => "index" }) + assert_equal "/accounts", url_for(default_route_set, { controller: "accounts", action: "index" }) end def test_default_route_should_include_default_action_when_id_present - assert_equal "/accounts/index/20", url_for(default_route_set, { :controller => "accounts", :action => "index", :id => "20" }) + assert_equal "/accounts/index/20", url_for(default_route_set, { controller: "accounts", action: "index", id: "20" }) end def test_default_route_should_work_with_action_but_no_id - assert_equal "/accounts/list_all", url_for(default_route_set, { :controller => "accounts", :action => "list_all" }) + assert_equal "/accounts/list_all", url_for(default_route_set, { controller: "accounts", action: "list_all" }) end def test_default_route_should_uri_escape_pluses - expected = { :controller => "pages", :action => "show", :id => "hello world" } + expected = { controller: "pages", action: "show", id: "hello world" } assert_equal expected, default_route_set.recognize_path("/pages/show/hello%20world") assert_equal "/pages/show/hello%20world", url_for(default_route_set, expected) @@ -1790,31 +1790,31 @@ class RouteSetTest < ActiveSupport::TestCase end def test_build_empty_query_string - assert_uri_equal "/foo", url_for(default_route_set, { :controller => "foo" }) + assert_uri_equal "/foo", url_for(default_route_set, { controller: "foo" }) end def test_build_query_string_with_nil_value - assert_uri_equal "/foo", url_for(default_route_set, { :controller => "foo", :x => nil }) + assert_uri_equal "/foo", url_for(default_route_set, { controller: "foo", x: nil }) end def test_simple_build_query_string - assert_uri_equal "/foo?x=1&y=2", url_for(default_route_set, { :controller => "foo", :x => "1", :y => "2" }) + assert_uri_equal "/foo?x=1&y=2", url_for(default_route_set, { controller: "foo", x: "1", y: "2" }) end def test_convert_ints_build_query_string - assert_uri_equal "/foo?x=1&y=2", url_for(default_route_set, { :controller => "foo", :x => 1, :y => 2 }) + assert_uri_equal "/foo?x=1&y=2", url_for(default_route_set, { controller: "foo", x: 1, y: 2 }) end def test_escape_spaces_build_query_string - assert_uri_equal "/foo?x=hello+world&y=goodbye+world", url_for(default_route_set, { :controller => "foo", :x => "hello world", :y => "goodbye world" }) + assert_uri_equal "/foo?x=hello+world&y=goodbye+world", url_for(default_route_set, { controller: "foo", x: "hello world", y: "goodbye world" }) end def test_expand_array_build_query_string - assert_uri_equal "/foo?x%5B%5D=1&x%5B%5D=2", url_for(default_route_set, { :controller => "foo", :x => [1, 2] }) + assert_uri_equal "/foo?x%5B%5D=1&x%5B%5D=2", url_for(default_route_set, { controller: "foo", x: [1, 2] }) end def test_escape_spaces_build_query_string_selected_keys - assert_uri_equal "/foo?x=hello+world", url_for(default_route_set, { :controller => "foo", :x => "hello world" }) + assert_uri_equal "/foo?x=hello+world", url_for(default_route_set, { controller: "foo", x: "hello world" }) end def test_generate_with_default_params @@ -1822,15 +1822,15 @@ class RouteSetTest < ActiveSupport::TestCase get "dummy/page/:page" => "dummy#show" get "dummy/dots/page.:page" => "dummy#dots" get "ibocorp(/:page)" => "ibocorp#show", - :constraints => { :page => /\d+/ }, - :defaults => { :page => 1 } + :constraints => { page: /\d+/ }, + :defaults => { page: 1 } ActiveSupport::Deprecation.silence do get ":controller/:action/:id" end end - assert_equal "/ibocorp", url_for(set, { :controller => "ibocorp", :action => "show", :page => 1 }) + assert_equal "/ibocorp", url_for(set, { controller: "ibocorp", action: "show", page: 1 }) end include ActionDispatch::RoutingVerbs @@ -1841,21 +1841,21 @@ class RouteSetTest < ActiveSupport::TestCase @set = make_set false set.draw do - get "blog/", :controller => "blog", :action => "index" + get "blog/", controller: "blog", action: "index" get "blog(/:year(/:month(/:day)))", - :controller => "blog", - :action => "show_date", - :constraints => { :year => /(19|20)\d\d/, :month => /[01]?\d/, :day => /[0-3]?\d/ }, - :day => nil, :month => nil + controller: "blog", + action: "show_date", + constraints: { year: /(19|20)\d\d/, month: /[01]?\d/, day: /[0-3]?\d/ }, + day: nil, month: nil - get "blog/show/:id", :controller => "blog", :action => "show", :id => /\d+/ + get "blog/show/:id", controller: "blog", action: "show", id: /\d+/ ActiveSupport::Deprecation.silence do get "blog/:controller/:action(/:id)" end - get "*anything", :controller => "blog", :action => "unknown_request" + get "*anything", controller: "blog", action: "unknown_request" end recognize_path = ->(path) { @@ -1863,24 +1863,24 @@ class RouteSetTest < ActiveSupport::TestCase controller.request.path_parameters } - assert_equal({:controller => "blog", :action => "index"}, recognize_path.("/blog")) - assert_equal({:controller => "blog", :action => "show", :id => "123"}, recognize_path.("/blog/show/123")) - assert_equal({:controller => "blog", :action => "show_date", :year => "2004", :day => nil, :month => nil }, recognize_path.("/blog/2004")) - assert_equal({:controller => "blog", :action => "show_date", :year => "2004", :month => "12", :day => nil }, recognize_path.("/blog/2004/12")) - assert_equal({:controller => "blog", :action => "show_date", :year => "2004", :month => "12", :day => "25"}, recognize_path.("/blog/2004/12/25")) - assert_equal({:controller => "articles", :action => "edit", :id => "123"}, recognize_path.("/blog/articles/edit/123")) - assert_equal({:controller => "articles", :action => "show_stats"}, recognize_path.("/blog/articles/show_stats")) - assert_equal({:controller => "blog", :action => "unknown_request", :anything => "blog/wibble"}, recognize_path.("/blog/wibble")) - assert_equal({:controller => "blog", :action => "unknown_request", :anything => "junk"}, recognize_path.("/junk")) + assert_equal({controller: "blog", action: "index"}, recognize_path.("/blog")) + assert_equal({controller: "blog", action: "show", id: "123"}, recognize_path.("/blog/show/123")) + assert_equal({controller: "blog", action: "show_date", year: "2004", day: nil, month: nil }, recognize_path.("/blog/2004")) + assert_equal({controller: "blog", action: "show_date", year: "2004", month: "12", day: nil }, recognize_path.("/blog/2004/12")) + assert_equal({controller: "blog", action: "show_date", year: "2004", month: "12", day: "25"}, recognize_path.("/blog/2004/12/25")) + assert_equal({controller: "articles", action: "edit", id: "123"}, recognize_path.("/blog/articles/edit/123")) + assert_equal({controller: "articles", action: "show_stats"}, recognize_path.("/blog/articles/show_stats")) + assert_equal({controller: "blog", action: "unknown_request", anything: "blog/wibble"}, recognize_path.("/blog/wibble")) + assert_equal({controller: "blog", action: "unknown_request", anything: "junk"}, recognize_path.("/junk")) get URI("http://example.org/blog/2006/07/28") - assert_equal({:controller => "blog", :action => "show_date", :year => "2006", :month => "07", :day => "28"}, controller.request.path_parameters) - assert_equal("/blog/2006/07/25", controller.url_for({ :day => 25, :only_path => true })) - assert_equal("/blog/2005", controller.url_for({ :year => 2005, :only_path => true })) - assert_equal("/blog/show/123", controller.url_for({ :action => "show" , :id => 123, :only_path => true })) - assert_equal("/blog/2006", controller.url_for({ :year => 2006, :only_path => true })) - assert_equal("/blog/2006", controller.url_for({ :year => 2006, :month => nil, :only_path => true })) + assert_equal({controller: "blog", action: "show_date", year: "2006", month: "07", day: "28"}, controller.request.path_parameters) + assert_equal("/blog/2006/07/25", controller.url_for({ day: 25, only_path: true })) + assert_equal("/blog/2005", controller.url_for({ year: 2005, only_path: true })) + assert_equal("/blog/show/123", controller.url_for({ action: "show" , id: 123, only_path: true })) + assert_equal("/blog/2006", controller.url_for({ year: 2006, only_path: true })) + assert_equal("/blog/2006", controller.url_for({ year: 2006, month: nil, only_path: true })) end private @@ -1906,27 +1906,27 @@ class RackMountIntegrationTests < ActiveSupport::TestCase end namespace "api" do - root :to => "users#index" + root to: "users#index" end get "/blog(/:year(/:month(/:day)))" => "posts#show_date", :constraints => { - :year => /(19|20)\d\d/, - :month => /[01]?\d/, - :day => /[0-3]?\d/ + year: /(19|20)\d\d/, + month: /[01]?\d/, + day: /[0-3]?\d/ }, :day => nil, :month => nil - get "archive/:year", :controller => "archive", :action => "index", - :defaults => { :year => nil }, - :constraints => { :year => /\d{4}/ }, - :as => "blog" + get "archive/:year", controller: "archive", action: "index", + defaults: { year: nil }, + constraints: { year: /\d{4}/ }, + as: "blog" resources :people get "legacy/people" => "people#index", :legacy => "true" - get "symbols", :controller => :symbols, :action => :show, :name => :as_symbol + get "symbols", controller: :symbols, action: :show, name: :as_symbol get "id_default(/:id)" => "foo#id_default", :id => 1 match "get_or_post" => "foo#get_or_post", :via => [:get, :post] get "optional/:optional" => "posts#index" @@ -1935,7 +1935,7 @@ class RackMountIntegrationTests < ActiveSupport::TestCase get "ignorecase/geocode/:postalcode" => "geocode#show", :postalcode => /hx\d\d-\d[a-z]{2}/i get "extended/geocode/:postalcode" => "geocode#show",:constraints => { - :postalcode => /# Postcode format + postalcode: /# Postcode format \d{5} #Prefix (-\d{4})? #Suffix /x @@ -1945,19 +1945,19 @@ class RackMountIntegrationTests < ActiveSupport::TestCase ActiveSupport::Deprecation.silence do get "comment/:id(/:action)" => "comments#show" - get "ws/:controller(/:action(/:id))", :ws => true + get "ws/:controller(/:action(/:id))", ws: true get "account(/:action)" => "account#subscription" get "pages/:page_id/:controller(/:action(/:id))" - get ":controller/ping", :action => "ping" + get ":controller/ping", action: "ping" end - get "こんにちは/世界", :controller => "news", :action => "index" + get "こんにちは/世界", controller: "news", action: "index" ActiveSupport::Deprecation.silence do - match ":controller(/:action(/:id))(.:format)", :via => :all + match ":controller(/:action(/:id))(.:format)", via: :all end - root :to => "news#index" + root to: "news#index" } attr_reader :routes @@ -1969,118 +1969,118 @@ class RackMountIntegrationTests < ActiveSupport::TestCase end def test_recognize_path - assert_equal({:controller => "admin/users", :action => "index"}, @routes.recognize_path("/admin/users", :method => :get)) - assert_equal({:controller => "admin/users", :action => "create"}, @routes.recognize_path("/admin/users", :method => :post)) - assert_equal({:controller => "admin/users", :action => "new"}, @routes.recognize_path("/admin/users/new", :method => :get)) - assert_equal({:controller => "admin/users", :action => "show", :id => "1"}, @routes.recognize_path("/admin/users/1", :method => :get)) - assert_equal({:controller => "admin/users", :action => "update", :id => "1"}, @routes.recognize_path("/admin/users/1", :method => :put)) - assert_equal({:controller => "admin/users", :action => "destroy", :id => "1"}, @routes.recognize_path("/admin/users/1", :method => :delete)) - assert_equal({:controller => "admin/users", :action => "edit", :id => "1"}, @routes.recognize_path("/admin/users/1/edit", :method => :get)) - - assert_equal({:controller => "admin/posts", :action => "index"}, @routes.recognize_path("/admin/posts", :method => :get)) - assert_equal({:controller => "admin/posts", :action => "new"}, @routes.recognize_path("/admin/posts/new", :method => :get)) - - assert_equal({:controller => "api/users", :action => "index"}, @routes.recognize_path("/api", :method => :get)) - assert_equal({:controller => "api/users", :action => "index"}, @routes.recognize_path("/api/", :method => :get)) - - assert_equal({:controller => "posts", :action => "show_date", :year => "2009", :month => nil, :day => nil }, @routes.recognize_path("/blog/2009", :method => :get)) - assert_equal({:controller => "posts", :action => "show_date", :year => "2009", :month => "01", :day => nil }, @routes.recognize_path("/blog/2009/01", :method => :get)) - assert_equal({:controller => "posts", :action => "show_date", :year => "2009", :month => "01", :day => "01"}, @routes.recognize_path("/blog/2009/01/01", :method => :get)) - - assert_equal({:controller => "archive", :action => "index", :year => "2010"}, @routes.recognize_path("/archive/2010")) - assert_equal({:controller => "archive", :action => "index"}, @routes.recognize_path("/archive")) - - assert_equal({:controller => "people", :action => "index"}, @routes.recognize_path("/people", :method => :get)) - assert_equal({:controller => "people", :action => "index", :format => "xml"}, @routes.recognize_path("/people.xml", :method => :get)) - assert_equal({:controller => "people", :action => "create"}, @routes.recognize_path("/people", :method => :post)) - assert_equal({:controller => "people", :action => "new"}, @routes.recognize_path("/people/new", :method => :get)) - assert_equal({:controller => "people", :action => "show", :id => "1"}, @routes.recognize_path("/people/1", :method => :get)) - assert_equal({:controller => "people", :action => "show", :id => "1", :format => "xml"}, @routes.recognize_path("/people/1.xml", :method => :get)) - assert_equal({:controller => "people", :action => "update", :id => "1"}, @routes.recognize_path("/people/1", :method => :put)) - assert_equal({:controller => "people", :action => "destroy", :id => "1"}, @routes.recognize_path("/people/1", :method => :delete)) - assert_equal({:controller => "people", :action => "edit", :id => "1"}, @routes.recognize_path("/people/1/edit", :method => :get)) - assert_equal({:controller => "people", :action => "edit", :id => "1", :format => "xml"}, @routes.recognize_path("/people/1/edit.xml", :method => :get)) - - assert_equal({:controller => "symbols", :action => "show", :name => :as_symbol}, @routes.recognize_path("/symbols")) - assert_equal({:controller => "foo", :action => "id_default", :id => "1"}, @routes.recognize_path("/id_default/1")) - assert_equal({:controller => "foo", :action => "id_default", :id => "2"}, @routes.recognize_path("/id_default/2")) - assert_equal({:controller => "foo", :action => "id_default", :id => 1 }, @routes.recognize_path("/id_default")) - assert_equal({:controller => "foo", :action => "get_or_post"}, @routes.recognize_path("/get_or_post", :method => :get)) - assert_equal({:controller => "foo", :action => "get_or_post"}, @routes.recognize_path("/get_or_post", :method => :post)) - assert_raise(ActionController::RoutingError) { @routes.recognize_path("/get_or_post", :method => :put) } - assert_raise(ActionController::RoutingError) { @routes.recognize_path("/get_or_post", :method => :delete) } - - assert_equal({:controller => "posts", :action => "index", :optional => "bar"}, @routes.recognize_path("/optional/bar")) + assert_equal({controller: "admin/users", action: "index"}, @routes.recognize_path("/admin/users", method: :get)) + assert_equal({controller: "admin/users", action: "create"}, @routes.recognize_path("/admin/users", method: :post)) + assert_equal({controller: "admin/users", action: "new"}, @routes.recognize_path("/admin/users/new", method: :get)) + assert_equal({controller: "admin/users", action: "show", id: "1"}, @routes.recognize_path("/admin/users/1", method: :get)) + assert_equal({controller: "admin/users", action: "update", id: "1"}, @routes.recognize_path("/admin/users/1", method: :put)) + assert_equal({controller: "admin/users", action: "destroy", id: "1"}, @routes.recognize_path("/admin/users/1", method: :delete)) + assert_equal({controller: "admin/users", action: "edit", id: "1"}, @routes.recognize_path("/admin/users/1/edit", method: :get)) + + assert_equal({controller: "admin/posts", action: "index"}, @routes.recognize_path("/admin/posts", method: :get)) + assert_equal({controller: "admin/posts", action: "new"}, @routes.recognize_path("/admin/posts/new", method: :get)) + + assert_equal({controller: "api/users", action: "index"}, @routes.recognize_path("/api", method: :get)) + assert_equal({controller: "api/users", action: "index"}, @routes.recognize_path("/api/", method: :get)) + + assert_equal({controller: "posts", action: "show_date", year: "2009", month: nil, day: nil }, @routes.recognize_path("/blog/2009", method: :get)) + assert_equal({controller: "posts", action: "show_date", year: "2009", month: "01", day: nil }, @routes.recognize_path("/blog/2009/01", method: :get)) + assert_equal({controller: "posts", action: "show_date", year: "2009", month: "01", day: "01"}, @routes.recognize_path("/blog/2009/01/01", method: :get)) + + assert_equal({controller: "archive", action: "index", year: "2010"}, @routes.recognize_path("/archive/2010")) + assert_equal({controller: "archive", action: "index"}, @routes.recognize_path("/archive")) + + assert_equal({controller: "people", action: "index"}, @routes.recognize_path("/people", method: :get)) + assert_equal({controller: "people", action: "index", format: "xml"}, @routes.recognize_path("/people.xml", method: :get)) + assert_equal({controller: "people", action: "create"}, @routes.recognize_path("/people", method: :post)) + assert_equal({controller: "people", action: "new"}, @routes.recognize_path("/people/new", method: :get)) + assert_equal({controller: "people", action: "show", id: "1"}, @routes.recognize_path("/people/1", method: :get)) + assert_equal({controller: "people", action: "show", id: "1", format: "xml"}, @routes.recognize_path("/people/1.xml", method: :get)) + assert_equal({controller: "people", action: "update", id: "1"}, @routes.recognize_path("/people/1", method: :put)) + assert_equal({controller: "people", action: "destroy", id: "1"}, @routes.recognize_path("/people/1", method: :delete)) + assert_equal({controller: "people", action: "edit", id: "1"}, @routes.recognize_path("/people/1/edit", method: :get)) + assert_equal({controller: "people", action: "edit", id: "1", format: "xml"}, @routes.recognize_path("/people/1/edit.xml", method: :get)) + + assert_equal({controller: "symbols", action: "show", name: :as_symbol}, @routes.recognize_path("/symbols")) + assert_equal({controller: "foo", action: "id_default", id: "1"}, @routes.recognize_path("/id_default/1")) + assert_equal({controller: "foo", action: "id_default", id: "2"}, @routes.recognize_path("/id_default/2")) + assert_equal({controller: "foo", action: "id_default", id: 1 }, @routes.recognize_path("/id_default")) + assert_equal({controller: "foo", action: "get_or_post"}, @routes.recognize_path("/get_or_post", method: :get)) + assert_equal({controller: "foo", action: "get_or_post"}, @routes.recognize_path("/get_or_post", method: :post)) + assert_raise(ActionController::RoutingError) { @routes.recognize_path("/get_or_post", method: :put) } + assert_raise(ActionController::RoutingError) { @routes.recognize_path("/get_or_post", method: :delete) } + + assert_equal({controller: "posts", action: "index", optional: "bar"}, @routes.recognize_path("/optional/bar")) assert_raise(ActionController::RoutingError) { @routes.recognize_path("/optional") } - assert_equal({:controller => "posts", :action => "show", :id => "1", :ws => true}, @routes.recognize_path("/ws/posts/show/1", :method => :get)) - assert_equal({:controller => "posts", :action => "list", :ws => true}, @routes.recognize_path("/ws/posts/list", :method => :get)) - assert_equal({:controller => "posts", :action => "index", :ws => true}, @routes.recognize_path("/ws/posts", :method => :get)) + assert_equal({controller: "posts", action: "show", id: "1", ws: true}, @routes.recognize_path("/ws/posts/show/1", method: :get)) + assert_equal({controller: "posts", action: "list", ws: true}, @routes.recognize_path("/ws/posts/list", method: :get)) + assert_equal({controller: "posts", action: "index", ws: true}, @routes.recognize_path("/ws/posts", method: :get)) - assert_equal({:controller => "account", :action => "subscription"}, @routes.recognize_path("/account", :method => :get)) - assert_equal({:controller => "account", :action => "subscription"}, @routes.recognize_path("/account/subscription", :method => :get)) - assert_equal({:controller => "account", :action => "billing"}, @routes.recognize_path("/account/billing", :method => :get)) + assert_equal({controller: "account", action: "subscription"}, @routes.recognize_path("/account", method: :get)) + assert_equal({controller: "account", action: "subscription"}, @routes.recognize_path("/account/subscription", method: :get)) + assert_equal({controller: "account", action: "billing"}, @routes.recognize_path("/account/billing", method: :get)) - assert_equal({:page_id => "1", :controller => "notes", :action => "index"}, @routes.recognize_path("/pages/1/notes", :method => :get)) - assert_equal({:page_id => "1", :controller => "notes", :action => "list"}, @routes.recognize_path("/pages/1/notes/list", :method => :get)) - assert_equal({:page_id => "1", :controller => "notes", :action => "show", :id => "2"}, @routes.recognize_path("/pages/1/notes/show/2", :method => :get)) + assert_equal({page_id: "1", controller: "notes", action: "index"}, @routes.recognize_path("/pages/1/notes", method: :get)) + assert_equal({page_id: "1", controller: "notes", action: "list"}, @routes.recognize_path("/pages/1/notes/list", method: :get)) + assert_equal({page_id: "1", controller: "notes", action: "show", id: "2"}, @routes.recognize_path("/pages/1/notes/show/2", method: :get)) - assert_equal({:controller => "posts", :action => "ping"}, @routes.recognize_path("/posts/ping", :method => :get)) - assert_equal({:controller => "posts", :action => "index"}, @routes.recognize_path("/posts", :method => :get)) - assert_equal({:controller => "posts", :action => "index"}, @routes.recognize_path("/posts/index", :method => :get)) - assert_equal({:controller => "posts", :action => "show"}, @routes.recognize_path("/posts/show", :method => :get)) - assert_equal({:controller => "posts", :action => "show", :id => "1"}, @routes.recognize_path("/posts/show/1", :method => :get)) - assert_equal({:controller => "posts", :action => "create"}, @routes.recognize_path("/posts/create", :method => :post)) + assert_equal({controller: "posts", action: "ping"}, @routes.recognize_path("/posts/ping", method: :get)) + assert_equal({controller: "posts", action: "index"}, @routes.recognize_path("/posts", method: :get)) + assert_equal({controller: "posts", action: "index"}, @routes.recognize_path("/posts/index", method: :get)) + assert_equal({controller: "posts", action: "show"}, @routes.recognize_path("/posts/show", method: :get)) + assert_equal({controller: "posts", action: "show", id: "1"}, @routes.recognize_path("/posts/show/1", method: :get)) + assert_equal({controller: "posts", action: "create"}, @routes.recognize_path("/posts/create", method: :post)) - assert_equal({:controller => "geocode", :action => "show", :postalcode => "hx12-1az"}, @routes.recognize_path("/ignorecase/geocode/hx12-1az")) - assert_equal({:controller => "geocode", :action => "show", :postalcode => "hx12-1AZ"}, @routes.recognize_path("/ignorecase/geocode/hx12-1AZ")) - assert_equal({:controller => "geocode", :action => "show", :postalcode => "12345-1234"}, @routes.recognize_path("/extended/geocode/12345-1234")) - assert_equal({:controller => "geocode", :action => "show", :postalcode => "12345"}, @routes.recognize_path("/extended/geocode/12345")) + assert_equal({controller: "geocode", action: "show", postalcode: "hx12-1az"}, @routes.recognize_path("/ignorecase/geocode/hx12-1az")) + assert_equal({controller: "geocode", action: "show", postalcode: "hx12-1AZ"}, @routes.recognize_path("/ignorecase/geocode/hx12-1AZ")) + assert_equal({controller: "geocode", action: "show", postalcode: "12345-1234"}, @routes.recognize_path("/extended/geocode/12345-1234")) + assert_equal({controller: "geocode", action: "show", postalcode: "12345"}, @routes.recognize_path("/extended/geocode/12345")) - assert_equal({:controller => "news", :action => "index" }, @routes.recognize_path("/", :method => :get)) - assert_equal({:controller => "news", :action => "index", :format => "rss"}, @routes.recognize_path("/news.rss", :method => :get)) + assert_equal({controller: "news", action: "index" }, @routes.recognize_path("/", method: :get)) + assert_equal({controller: "news", action: "index", format: "rss"}, @routes.recognize_path("/news.rss", method: :get)) - assert_raise(ActionController::RoutingError) { @routes.recognize_path("/none", :method => :get) } + assert_raise(ActionController::RoutingError) { @routes.recognize_path("/none", method: :get) } end def test_generate_extras - assert_equal ["/people", []], @routes.generate_extras(:controller => "people") - assert_equal ["/people", [:foo]], @routes.generate_extras(:controller => "people", :foo => "bar") - assert_equal ["/people", []], @routes.generate_extras(:controller => "people", :action => "index") - assert_equal ["/people", [:foo]], @routes.generate_extras(:controller => "people", :action => "index", :foo => "bar") - assert_equal ["/people/new", []], @routes.generate_extras(:controller => "people", :action => "new") - assert_equal ["/people/new", [:foo]], @routes.generate_extras(:controller => "people", :action => "new", :foo => "bar") - assert_equal ["/people/1", []], @routes.generate_extras(:controller => "people", :action => "show", :id => "1") - assert_equal ["/people/1", [:bar, :foo]], sort_extras!(@routes.generate_extras(:controller => "people", :action => "show", :id => "1", :foo => "2", :bar => "3")) - assert_equal ["/people", [:person]], @routes.generate_extras(:controller => "people", :action => "create", :person => { :first_name => "Josh", :last_name => "Peek" }) - assert_equal ["/people", [:people]], @routes.generate_extras(:controller => "people", :action => "create", :people => ["Josh", "Dave"]) - - assert_equal ["/posts/show/1", []], @routes.generate_extras(:controller => "posts", :action => "show", :id => "1") - assert_equal ["/posts/show/1", [:bar, :foo]], sort_extras!(@routes.generate_extras(:controller => "posts", :action => "show", :id => "1", :foo => "2", :bar => "3")) - assert_equal ["/posts", []], @routes.generate_extras(:controller => "posts", :action => "index") - assert_equal ["/posts", [:foo]], @routes.generate_extras(:controller => "posts", :action => "index", :foo => "bar") + assert_equal ["/people", []], @routes.generate_extras(controller: "people") + assert_equal ["/people", [:foo]], @routes.generate_extras(controller: "people", foo: "bar") + assert_equal ["/people", []], @routes.generate_extras(controller: "people", action: "index") + assert_equal ["/people", [:foo]], @routes.generate_extras(controller: "people", action: "index", foo: "bar") + assert_equal ["/people/new", []], @routes.generate_extras(controller: "people", action: "new") + assert_equal ["/people/new", [:foo]], @routes.generate_extras(controller: "people", action: "new", foo: "bar") + assert_equal ["/people/1", []], @routes.generate_extras(controller: "people", action: "show", id: "1") + assert_equal ["/people/1", [:bar, :foo]], sort_extras!(@routes.generate_extras(controller: "people", action: "show", id: "1", foo: "2", bar: "3")) + assert_equal ["/people", [:person]], @routes.generate_extras(controller: "people", action: "create", person: { first_name: "Josh", last_name: "Peek" }) + assert_equal ["/people", [:people]], @routes.generate_extras(controller: "people", action: "create", people: ["Josh", "Dave"]) + + assert_equal ["/posts/show/1", []], @routes.generate_extras(controller: "posts", action: "show", id: "1") + assert_equal ["/posts/show/1", [:bar, :foo]], sort_extras!(@routes.generate_extras(controller: "posts", action: "show", id: "1", foo: "2", bar: "3")) + assert_equal ["/posts", []], @routes.generate_extras(controller: "posts", action: "index") + assert_equal ["/posts", [:foo]], @routes.generate_extras(controller: "posts", action: "index", foo: "bar") end def test_extras - params = {:controller => "people"} + params = {controller: "people"} assert_equal [], @routes.extra_keys(params) - assert_equal({:controller => "people", :action => "index"}, params) + assert_equal({controller: "people", action: "index"}, params) - params = {:controller => "people", :foo => "bar"} + params = {controller: "people", foo: "bar"} assert_equal [:foo], @routes.extra_keys(params) - assert_equal({:controller => "people", :action => "index", :foo => "bar"}, params) + assert_equal({controller: "people", action: "index", foo: "bar"}, params) - params = {:controller => "people", :action => "create", :person => { :name => "Josh"}} + params = {controller: "people", action: "create", person: { name: "Josh"}} assert_equal [:person], @routes.extra_keys(params) - assert_equal({:controller => "people", :action => "create", :person => { :name => "Josh"}}, params) + assert_equal({controller: "people", action: "create", person: { name: "Josh"}}, params) end def test_unicode_path - assert_equal({:controller => "news", :action => "index"}, @routes.recognize_path(URI.parser.escape("こんにちは/世界"), :method => :get)) + assert_equal({controller: "news", action: "index"}, @routes.recognize_path(URI.parser.escape("こんにちは/世界"), method: :get)) end def test_downcased_unicode_path - assert_equal({:controller => "news", :action => "index"}, @routes.recognize_path(URI.parser.escape("こんにちは/世界").downcase, :method => :get)) + assert_equal({controller: "news", action: "index"}, @routes.recognize_path(URI.parser.escape("こんにちは/世界").downcase, method: :get)) end private diff --git a/actionpack/test/controller/send_file_test.rb b/actionpack/test/controller/send_file_test.rb index 4d201c7290..e78478b16c 100644 --- a/actionpack/test/controller/send_file_test.rb +++ b/actionpack/test/controller/send_file_test.rb @@ -28,9 +28,9 @@ class SendFileController < ActionController::Base def test_send_file_headers_bang options = { - :type => Mime[:png], - :disposition => "disposition", - :filename => "filename" + type: Mime[:png], + disposition: "disposition", + filename: "filename" } send_data "foo", options @@ -38,32 +38,32 @@ class SendFileController < ActionController::Base def test_send_file_headers_with_disposition_as_a_symbol options = { - :type => Mime[:png], - :disposition => :disposition, - :filename => "filename" + type: Mime[:png], + disposition: :disposition, + filename: "filename" } send_data "foo", options end def test_send_file_headers_with_mime_lookup_with_symbol - options = { :type => :png } + options = { type: :png } send_data "foo", options end def test_send_file_headers_with_bad_symbol - options = { :type => :this_type_is_not_registered } + options = { type: :this_type_is_not_registered } send_data "foo", options end def test_send_file_headers_with_nil_content_type - options = { :type => nil } + options = { type: nil } send_data "foo", options end def test_send_file_headers_guess_type_from_extension - options = { :filename => params[:filename] } + options = { filename: params[:filename] } send_data "foo", options end @@ -84,7 +84,7 @@ class SendFileTest < ActionController::TestCase end def test_file_nostream - @controller.options = { :stream => false } + @controller.options = { stream: false } response = nil assert_nothing_raised { response = process("file") } assert_not_nil response @@ -109,7 +109,7 @@ class SendFileTest < ActionController::TestCase end def test_file_url_based_filename - @controller.options = { :url_based_filename => true } + @controller.options = { url_based_filename: true } response = nil assert_nothing_raised { response = process("file") } assert_not_nil response @@ -193,7 +193,7 @@ class SendFileTest < ActionController::TestCase end def test_send_file_without_content_disposition_header - @controller.options = {:disposition => nil} + @controller.options = {disposition: nil} process("data") assert_nil @controller.headers["Content-Disposition"] end @@ -209,19 +209,19 @@ class SendFileTest < ActionController::TestCase %w(file data).each do |method| define_method "test_send_#{method}_status" do - @controller.options = { :stream => false, :status => 500 } + @controller.options = { stream: false, status: 500 } assert_not_nil process(method) assert_equal 500, @response.status end define_method "test_send_#{method}_content_type" do - @controller.options = { :stream => false, :content_type => "application/x-ruby" } + @controller.options = { stream: false, content_type: "application/x-ruby" } assert_nothing_raised { assert_not_nil process(method) } assert_equal "application/x-ruby", @response.content_type end define_method "test_default_send_#{method}_status" do - @controller.options = { :stream => false } + @controller.options = { stream: false } assert_nothing_raised { assert_not_nil process(method) } assert_equal 200, @response.status end @@ -229,7 +229,7 @@ class SendFileTest < ActionController::TestCase def test_send_file_with_action_controller_live @controller = SendFileWithActionControllerLive.new - @controller.options = { :content_type => "application/x-ruby" } + @controller.options = { content_type: "application/x-ruby" } response = process("file") assert_equal 200, response.status diff --git a/actionpack/test/controller/show_exceptions_test.rb b/actionpack/test/controller/show_exceptions_test.rb index 5144c8b775..9b93afd303 100644 --- a/actionpack/test/controller/show_exceptions_test.rb +++ b/actionpack/test/controller/show_exceptions_test.rb @@ -75,7 +75,7 @@ module ShowExceptions get "/", headers: { "HTTP_ACCEPT" => "application/json" } assert_response :internal_server_error assert_equal "application/json", response.content_type.to_s - assert_equal({ :status => 500, :error => "Internal Server Error" }.to_json, response.body) + assert_equal({ status: 500, error: "Internal Server Error" }.to_json, response.body) end def test_render_xml_exception @@ -83,7 +83,7 @@ module ShowExceptions get "/", headers: { "HTTP_ACCEPT" => "application/xml" } assert_response :internal_server_error assert_equal "application/xml", response.content_type.to_s - assert_equal({ :status => 500, :error => "Internal Server Error" }.to_xml, response.body) + assert_equal({ status: 500, error: "Internal Server Error" }.to_xml, response.body) end def test_render_fallback_exception diff --git a/actionpack/test/controller/url_for_integration_test.rb b/actionpack/test/controller/url_for_integration_test.rb index 5e1ad5eb1d..fc746add9b 100644 --- a/actionpack/test/controller/url_for_integration_test.rb +++ b/actionpack/test/controller/url_for_integration_test.rb @@ -15,27 +15,27 @@ module ActionPack end namespace "api" do - root :to => "users#index" + root to: "users#index" end get "/blog(/:year(/:month(/:day)))" => "posts#show_date", :constraints => { - :year => /(19|20)\d\d/, - :month => /[01]?\d/, - :day => /[0-3]?\d/ + year: /(19|20)\d\d/, + month: /[01]?\d/, + day: /[0-3]?\d/ }, :day => nil, :month => nil - get "archive/:year", :controller => "archive", :action => "index", - :defaults => { :year => nil }, - :constraints => { :year => /\d{4}/ }, - :as => "blog" + get "archive/:year", controller: "archive", action: "index", + defaults: { year: nil }, + constraints: { year: /\d{4}/ }, + as: "blog" resources :people #match 'legacy/people' => "people#index", :legacy => "true" - get "symbols", :controller => :symbols, :action => :show, :name => :as_symbol + get "symbols", controller: :symbols, action: :show, name: :as_symbol get "id_default(/:id)" => "foo#id_default", :id => 1 match "get_or_post" => "foo#get_or_post", :via => [:get, :post] get "optional/:optional" => "posts#index" @@ -44,7 +44,7 @@ module ActionPack get "ignorecase/geocode/:postalcode" => "geocode#show", :postalcode => /hx\d\d-\d[a-z]{2}/i get "extended/geocode/:postalcode" => "geocode#show",:constraints => { - :postalcode => /# Postcode format + postalcode: /# Postcode format \d{5} #Prefix (-\d{4})? #Suffix /x @@ -54,14 +54,14 @@ module ActionPack ActiveSupport::Deprecation.silence { get "comment/:id(/:action)" => "comments#show" - get "ws/:controller(/:action(/:id))", :ws => true + get "ws/:controller(/:action(/:id))", ws: true get "account(/:action)" => "account#subscription" get "pages/:page_id/:controller(/:action(/:id))" - get ":controller/ping", :action => "ping" + get ":controller/ping", action: "ping" get ":controller(/:action(/:id))(.:format)" } - root :to => "news#index" + root to: "news#index" } attr_reader :routes @@ -73,104 +73,104 @@ module ActionPack end [ - ["/admin/users",[ { :use_route => "admin_users" }]], - ["/admin/users",[ { :controller => "admin/users" }]], - ["/admin/users",[ { :controller => "admin/users", :action => "index" }]], - ["/admin/users",[ { :action => "index" }, { :controller => "admin/users", :action => "index" }, "/admin/users"]], - ["/admin/users",[ { :controller => "users", :action => "index" }, { :controller => "admin/accounts", :action => "show", :id => "1" }, "/admin/accounts/show/1"]], - ["/people",[ { :controller => "/people", :action => "index" }, {:controller=>"admin/accounts", :action=>"foo", :id=>"bar"}, "/admin/accounts/foo/bar"]], - - ["/admin/posts",[ { :controller => "admin/posts" }]], - ["/admin/posts/new",[ { :controller => "admin/posts", :action => "new" }]], - - ["/blog/2009",[ { :controller => "posts", :action => "show_date", :year => 2009 }]], - ["/blog/2009/1",[ { :controller => "posts", :action => "show_date", :year => 2009, :month => 1 }]], - ["/blog/2009/1/1",[ { :controller => "posts", :action => "show_date", :year => 2009, :month => 1, :day => 1 }]], - - ["/archive/2010",[ { :controller => "archive", :action => "index", :year => "2010" }]], - ["/archive",[ { :controller => "archive", :action => "index" }]], - ["/archive?year=january",[ { :controller => "archive", :action => "index", :year => "january" }]], - - ["/people",[ { :controller => "people", :action => "index" }]], - ["/people",[ { :action => "index" }, { :controller => "people", :action => "index" }, "/people"]], - ["/people",[ { :action => "index" }, { :controller => "people", :action => "show", :id => "1" }, "/people/show/1"]], - ["/people",[ { :controller => "people", :action => "index" }, { :controller => "people", :action => "show", :id => "1" }, "/people/show/1"]], - ["/people",[ {}, { :controller => "people", :action => "index" }, "/people"]], - ["/people/1",[ { :controller => "people", :action => "show" }, { :controller => "people", :action => "show", :id => "1" }, "/people/show/1"]], - ["/people/new",[ { :use_route => "new_person" }]], - ["/people/new",[ { :controller => "people", :action => "new" }]], - ["/people/1",[ { :use_route => "person", :id => "1" }]], - ["/people/1",[ { :controller => "people", :action => "show", :id => "1" }]], - ["/people/1.xml",[ { :controller => "people", :action => "show", :id => "1", :format => "xml" }]], - ["/people/1",[ { :controller => "people", :action => "show", :id => 1 }]], - ["/people/1",[ { :controller => "people", :action => "show", :id => Model.new("1") }]], - ["/people/1",[ { :action => "show", :id => "1" }, { :controller => "people", :action => "index" }, "/people"]], - ["/people/1",[ { :action => "show", :id => 1 }, { :controller => "people", :action => "show", :id => "1" }, "/people/show/1"]], - ["/people",[ { :controller => "people", :action => "index" }, { :controller => "people", :action => "show", :id => "1" }, "/people/show/1"]], - ["/people/1",[ {}, { :controller => "people", :action => "show", :id => "1" }, "/people/show/1"]], - ["/people/1",[ { :controller => "people", :action => "show" }, { :controller => "people", :action => "index", :id => "1" }, "/people/index/1"]], - ["/people/1/edit",[ { :controller => "people", :action => "edit", :id => "1" }]], - ["/people/1/edit.xml",[ { :controller => "people", :action => "edit", :id => "1", :format => "xml" }]], - ["/people/1/edit",[ { :use_route => "edit_person", :id => "1" }]], - ["/people/1?legacy=true",[ { :controller => "people", :action => "show", :id => "1", :legacy => "true" }]], - ["/people?legacy=true",[ { :controller => "people", :action => "index", :legacy => "true" }]], - - ["/id_default/2",[ { :controller => "foo", :action => "id_default", :id => "2" }]], - ["/id_default",[ { :controller => "foo", :action => "id_default", :id => "1" }]], - ["/id_default",[ { :controller => "foo", :action => "id_default", :id => 1 }]], - ["/id_default",[ { :controller => "foo", :action => "id_default" }]], - ["/optional/bar",[ { :controller => "posts", :action => "index", :optional => "bar" }]], - ["/posts",[ { :controller => "posts", :action => "index" }]], - - ["/project",[ { :controller => "project", :action => "index" }]], - ["/projects/1",[ { :controller => "project", :action => "index", :project_id => "1" }]], - ["/projects/1",[ { :controller => "project", :action => "index"}, {:project_id => "1", :controller => "project", :action => "index" }, "/projects/1"]], - ["/projects/1",[ { :use_route => "project", :controller => "project", :action => "index", :project_id => "1" }]], - ["/projects/1",[ { :use_route => "project", :controller => "project", :action => "index" }, { :controller => "project", :action => "index", :project_id => "1" }, "/projects/1"]], - - ["/clients",[ { :controller => "projects", :action => "index" }]], - ["/clients?project_id=1",[ { :controller => "projects", :action => "index", :project_id => "1" }]], - ["/clients",[ { :controller => "projects", :action => "index" }, { :project_id => "1", :controller => "project", :action => "index" }, "/projects/1"]], - - ["/comment/20",[ { :id => 20 }, { :controller => "comments", :action => "show" }, "/comments/show"]], - ["/comment/20",[ { :controller => "comments", :id => 20, :action => "show" }]], - ["/comments/boo",[ { :controller => "comments", :action => "boo" }]], - - ["/ws/posts/show/1",[ { :controller => "posts", :action => "show", :id => "1", :ws => true }]], - ["/ws/posts",[ { :controller => "posts", :action => "index", :ws => true }]], - - ["/account",[ { :controller => "account", :action => "subscription" }]], - ["/account/billing",[ { :controller => "account", :action => "billing" }]], - - ["/pages/1/notes/show/1",[ { :page_id => "1", :controller => "notes", :action => "show", :id => "1" }]], - ["/pages/1/notes/list",[ { :page_id => "1", :controller => "notes", :action => "list" }]], - ["/pages/1/notes",[ { :page_id => "1", :controller => "notes", :action => "index" }]], - ["/pages/1/notes",[ { :page_id => "1", :controller => "notes" }]], - ["/notes",[ { :page_id => nil, :controller => "notes" }]], - ["/notes",[ { :controller => "notes" }]], - ["/notes/print",[ { :controller => "notes", :action => "print" }]], - ["/notes/print",[ {}, { :controller => "notes", :action => "print" }, "/notes/print"]], - - ["/notes/index/1",[ { :controller => "notes" }, { :controller => "notes", :action => "index", :id => "1" }, "/notes/index/1"]], - ["/notes/index/1",[ { :controller => "notes" }, { :controller => "notes", :id => "1", :action => "index" }, "/notes/index/1"]], - ["/notes/index/1",[ { :action => "index" }, { :controller => "notes", :id => "1", :action => "index" }, "/notes/index/1"]], - ["/notes/index/1",[ {}, { :controller => "notes", :id => "1", :action => "index" }, "/notes/index/1"]], - ["/notes/show/1",[ {}, { :controller => "notes", :action => "show", :id => "1" }, "/notes/show/1"]], - ["/posts",[ { :controller => "posts" }, { :controller => "notes", :action => "show", :id => "1" }, "/notes/show/1"]], - ["/notes/list",[ { :action => "list" }, { :controller => "notes", :action => "show", :id => "1" }, "/notes/show/1"]], - - ["/posts/ping",[ { :controller => "posts", :action => "ping" }]], - ["/posts/show/1",[ { :controller => "posts", :action => "show", :id => "1" }]], - ["/posts/show/1",[ { :controller => "posts", :action => "show", :id => "1", :format => "" }]], - ["/posts",[ { :controller => "posts" }]], - ["/posts",[ { :controller => "posts", :action => "index" }]], - ["/posts/create",[ { :action => "create" }, {:day=>nil, :month=>nil, :controller=>"posts", :action=>"show_date"}, "/blog"]], - ["/posts?foo=bar",[ { :controller => "posts", :foo => "bar" }]], - ["/posts?foo%5B%5D=bar&foo%5B%5D=baz", [{ :controller => "posts", :foo => ["bar", "baz"] }]], - ["/posts?page=2", [{ :controller => "posts", :page => 2 }]], - ["/posts?q%5Bfoo%5D%5Ba%5D=b", [{ :controller => "posts", :q => { :foo => { :a => "b"}} }]], - - ["/news.rss", [{ :controller => "news", :action => "index", :format => "rss" }]], + ["/admin/users",[ { use_route: "admin_users" }]], + ["/admin/users",[ { controller: "admin/users" }]], + ["/admin/users",[ { controller: "admin/users", action: "index" }]], + ["/admin/users",[ { action: "index" }, { controller: "admin/users", action: "index" }, "/admin/users"]], + ["/admin/users",[ { controller: "users", action: "index" }, { controller: "admin/accounts", action: "show", id: "1" }, "/admin/accounts/show/1"]], + ["/people",[ { controller: "/people", action: "index" }, {controller: "admin/accounts", action: "foo", id: "bar"}, "/admin/accounts/foo/bar"]], + + ["/admin/posts",[ { controller: "admin/posts" }]], + ["/admin/posts/new",[ { controller: "admin/posts", action: "new" }]], + + ["/blog/2009",[ { controller: "posts", action: "show_date", year: 2009 }]], + ["/blog/2009/1",[ { controller: "posts", action: "show_date", year: 2009, month: 1 }]], + ["/blog/2009/1/1",[ { controller: "posts", action: "show_date", year: 2009, month: 1, day: 1 }]], + + ["/archive/2010",[ { controller: "archive", action: "index", year: "2010" }]], + ["/archive",[ { controller: "archive", action: "index" }]], + ["/archive?year=january",[ { controller: "archive", action: "index", year: "january" }]], + + ["/people",[ { controller: "people", action: "index" }]], + ["/people",[ { action: "index" }, { controller: "people", action: "index" }, "/people"]], + ["/people",[ { action: "index" }, { controller: "people", action: "show", id: "1" }, "/people/show/1"]], + ["/people",[ { controller: "people", action: "index" }, { controller: "people", action: "show", id: "1" }, "/people/show/1"]], + ["/people",[ {}, { controller: "people", action: "index" }, "/people"]], + ["/people/1",[ { controller: "people", action: "show" }, { controller: "people", action: "show", id: "1" }, "/people/show/1"]], + ["/people/new",[ { use_route: "new_person" }]], + ["/people/new",[ { controller: "people", action: "new" }]], + ["/people/1",[ { use_route: "person", id: "1" }]], + ["/people/1",[ { controller: "people", action: "show", id: "1" }]], + ["/people/1.xml",[ { controller: "people", action: "show", id: "1", format: "xml" }]], + ["/people/1",[ { controller: "people", action: "show", id: 1 }]], + ["/people/1",[ { controller: "people", action: "show", id: Model.new("1") }]], + ["/people/1",[ { action: "show", id: "1" }, { controller: "people", action: "index" }, "/people"]], + ["/people/1",[ { action: "show", id: 1 }, { controller: "people", action: "show", id: "1" }, "/people/show/1"]], + ["/people",[ { controller: "people", action: "index" }, { controller: "people", action: "show", id: "1" }, "/people/show/1"]], + ["/people/1",[ {}, { controller: "people", action: "show", id: "1" }, "/people/show/1"]], + ["/people/1",[ { controller: "people", action: "show" }, { controller: "people", action: "index", id: "1" }, "/people/index/1"]], + ["/people/1/edit",[ { controller: "people", action: "edit", id: "1" }]], + ["/people/1/edit.xml",[ { controller: "people", action: "edit", id: "1", format: "xml" }]], + ["/people/1/edit",[ { use_route: "edit_person", id: "1" }]], + ["/people/1?legacy=true",[ { controller: "people", action: "show", id: "1", legacy: "true" }]], + ["/people?legacy=true",[ { controller: "people", action: "index", legacy: "true" }]], + + ["/id_default/2",[ { controller: "foo", action: "id_default", id: "2" }]], + ["/id_default",[ { controller: "foo", action: "id_default", id: "1" }]], + ["/id_default",[ { controller: "foo", action: "id_default", id: 1 }]], + ["/id_default",[ { controller: "foo", action: "id_default" }]], + ["/optional/bar",[ { controller: "posts", action: "index", optional: "bar" }]], + ["/posts",[ { controller: "posts", action: "index" }]], + + ["/project",[ { controller: "project", action: "index" }]], + ["/projects/1",[ { controller: "project", action: "index", project_id: "1" }]], + ["/projects/1",[ { controller: "project", action: "index"}, {project_id: "1", controller: "project", action: "index" }, "/projects/1"]], + ["/projects/1",[ { use_route: "project", controller: "project", action: "index", project_id: "1" }]], + ["/projects/1",[ { use_route: "project", controller: "project", action: "index" }, { controller: "project", action: "index", project_id: "1" }, "/projects/1"]], + + ["/clients",[ { controller: "projects", action: "index" }]], + ["/clients?project_id=1",[ { controller: "projects", action: "index", project_id: "1" }]], + ["/clients",[ { controller: "projects", action: "index" }, { project_id: "1", controller: "project", action: "index" }, "/projects/1"]], + + ["/comment/20",[ { id: 20 }, { controller: "comments", action: "show" }, "/comments/show"]], + ["/comment/20",[ { controller: "comments", id: 20, action: "show" }]], + ["/comments/boo",[ { controller: "comments", action: "boo" }]], + + ["/ws/posts/show/1",[ { controller: "posts", action: "show", id: "1", ws: true }]], + ["/ws/posts",[ { controller: "posts", action: "index", ws: true }]], + + ["/account",[ { controller: "account", action: "subscription" }]], + ["/account/billing",[ { controller: "account", action: "billing" }]], + + ["/pages/1/notes/show/1",[ { page_id: "1", controller: "notes", action: "show", id: "1" }]], + ["/pages/1/notes/list",[ { page_id: "1", controller: "notes", action: "list" }]], + ["/pages/1/notes",[ { page_id: "1", controller: "notes", action: "index" }]], + ["/pages/1/notes",[ { page_id: "1", controller: "notes" }]], + ["/notes",[ { page_id: nil, controller: "notes" }]], + ["/notes",[ { controller: "notes" }]], + ["/notes/print",[ { controller: "notes", action: "print" }]], + ["/notes/print",[ {}, { controller: "notes", action: "print" }, "/notes/print"]], + + ["/notes/index/1",[ { controller: "notes" }, { controller: "notes", action: "index", id: "1" }, "/notes/index/1"]], + ["/notes/index/1",[ { controller: "notes" }, { controller: "notes", id: "1", action: "index" }, "/notes/index/1"]], + ["/notes/index/1",[ { action: "index" }, { controller: "notes", id: "1", action: "index" }, "/notes/index/1"]], + ["/notes/index/1",[ {}, { controller: "notes", id: "1", action: "index" }, "/notes/index/1"]], + ["/notes/show/1",[ {}, { controller: "notes", action: "show", id: "1" }, "/notes/show/1"]], + ["/posts",[ { controller: "posts" }, { controller: "notes", action: "show", id: "1" }, "/notes/show/1"]], + ["/notes/list",[ { action: "list" }, { controller: "notes", action: "show", id: "1" }, "/notes/show/1"]], + + ["/posts/ping",[ { controller: "posts", action: "ping" }]], + ["/posts/show/1",[ { controller: "posts", action: "show", id: "1" }]], + ["/posts/show/1",[ { controller: "posts", action: "show", id: "1", format: "" }]], + ["/posts",[ { controller: "posts" }]], + ["/posts",[ { controller: "posts", action: "index" }]], + ["/posts/create",[ { action: "create" }, {day: nil, month: nil, controller: "posts", action: "show_date"}, "/blog"]], + ["/posts?foo=bar",[ { controller: "posts", foo: "bar" }]], + ["/posts?foo%5B%5D=bar&foo%5B%5D=baz", [{ controller: "posts", foo: ["bar", "baz"] }]], + ["/posts?page=2", [{ controller: "posts", page: 2 }]], + ["/posts?q%5Bfoo%5D%5Ba%5D=b", [{ controller: "posts", q: { foo: { a: "b"}} }]], + + ["/news.rss", [{ controller: "news", action: "index", format: "rss" }]], ].each_with_index do |(url, params), i| if params.length > 1 hash, path_params, route = *params diff --git a/actionpack/test/controller/url_for_test.rb b/actionpack/test/controller/url_for_test.rb index 7c8e5675b6..6b0dd0ac88 100644 --- a/actionpack/test/controller/url_for_test.rb +++ b/actionpack/test/controller/url_for_test.rb @@ -21,17 +21,17 @@ module AbstractController klass = Class.new { include ActionDispatch::Routing::RouteSet.new.tap { |r| r.draw { - get "/foo/(:bar/(:baz))/:zot", :as => "fun", - :controller => :articles, - :action => :index + get "/foo/(:bar/(:baz))/:zot", as: "fun", + controller: :articles, + action: :index } }.url_helpers self.default_url_options[:host] = "example.com" } - path = klass.new.fun_path({:controller => :articles, - :baz => "baz", - :zot => "zot"}) + path = klass.new.fun_path({controller: :articles, + baz: "baz", + zot: "zot"}) # :bar key isn't provided assert_equal "/foo/zot", path end @@ -50,13 +50,13 @@ module AbstractController def test_exception_is_thrown_without_host assert_raise ArgumentError do - W.new.url_for :controller => "c", :action => "a", :id => "i" + W.new.url_for controller: "c", action: "a", id: "i" end end def test_anchor assert_equal("/c/a#anchor", - W.new.url_for(:only_path => true, :controller => "c", :action => "a", :anchor => "anchor") + W.new.url_for(only_path: true, controller: "c", action: "a", anchor: "anchor") ) end @@ -76,40 +76,40 @@ module AbstractController def test_anchor_should_call_to_param assert_equal("/c/a#anchor", - W.new.url_for(:only_path => true, :controller => "c", :action => "a", :anchor => Struct.new(:to_param).new("anchor")) + W.new.url_for(only_path: true, controller: "c", action: "a", anchor: Struct.new(:to_param).new("anchor")) ) end def test_anchor_should_escape_unsafe_pchar assert_equal("/c/a#%23anchor", - W.new.url_for(:only_path => true, :controller => "c", :action => "a", :anchor => Struct.new(:to_param).new("#anchor")) + W.new.url_for(only_path: true, controller: "c", action: "a", anchor: Struct.new(:to_param).new("#anchor")) ) end def test_anchor_should_not_escape_safe_pchar assert_equal("/c/a#name=user&email=user@domain.com", - W.new.url_for(:only_path => true, :controller => "c", :action => "a", :anchor => Struct.new(:to_param).new("name=user&email=user@domain.com")) + W.new.url_for(only_path: true, controller: "c", action: "a", anchor: Struct.new(:to_param).new("name=user&email=user@domain.com")) ) end def test_default_host add_host! assert_equal("http://www.basecamphq.com/c/a/i", - W.new.url_for(:controller => "c", :action => "a", :id => "i") + W.new.url_for(controller: "c", action: "a", id: "i") ) end def test_host_may_be_overridden add_host! assert_equal("http://37signals.basecamphq.com/c/a/i", - W.new.url_for(:host => "37signals.basecamphq.com", :controller => "c", :action => "a", :id => "i") + W.new.url_for(host: "37signals.basecamphq.com", controller: "c", action: "a", id: "i") ) end def test_subdomain_may_be_changed add_host! assert_equal("http://api.basecamphq.com/c/a/i", - W.new.url_for(:subdomain => "api", :controller => "c", :action => "a", :id => "i") + W.new.url_for(subdomain: "api", controller: "c", action: "a", id: "i") ) end @@ -117,56 +117,56 @@ module AbstractController model = Class.new { def self.to_param; "api"; end } add_host! assert_equal("http://api.basecamphq.com/c/a/i", - W.new.url_for(:subdomain => model, :controller => "c", :action => "a", :id => "i") + W.new.url_for(subdomain: model, controller: "c", action: "a", id: "i") ) end def test_subdomain_may_be_removed add_host! assert_equal("http://basecamphq.com/c/a/i", - W.new.url_for(:subdomain => false, :controller => "c", :action => "a", :id => "i") + W.new.url_for(subdomain: false, controller: "c", action: "a", id: "i") ) end def test_subdomain_may_be_removed_with_blank_string W.default_url_options[:host] = "api.basecamphq.com" assert_equal("http://basecamphq.com/c/a/i", - W.new.url_for(:subdomain => "", :controller => "c", :action => "a", :id => "i") + W.new.url_for(subdomain: "", controller: "c", action: "a", id: "i") ) end def test_multiple_subdomains_may_be_removed W.default_url_options[:host] = "mobile.www.api.basecamphq.com" assert_equal("http://basecamphq.com/c/a/i", - W.new.url_for(:subdomain => false, :controller => "c", :action => "a", :id => "i") + W.new.url_for(subdomain: false, controller: "c", action: "a", id: "i") ) end def test_subdomain_may_be_accepted_with_numeric_host add_numeric_host! assert_equal("http://127.0.0.1/c/a/i", - W.new.url_for(:subdomain => "api", :controller => "c", :action => "a", :id => "i") + W.new.url_for(subdomain: "api", controller: "c", action: "a", id: "i") ) end def test_domain_may_be_changed add_host! assert_equal("http://www.37signals.com/c/a/i", - W.new.url_for(:domain => "37signals.com", :controller => "c", :action => "a", :id => "i") + W.new.url_for(domain: "37signals.com", controller: "c", action: "a", id: "i") ) end def test_tld_length_may_be_changed add_host! assert_equal("http://mobile.www.basecamphq.com/c/a/i", - W.new.url_for(:subdomain => "mobile", :tld_length => 2, :controller => "c", :action => "a", :id => "i") + W.new.url_for(subdomain: "mobile", tld_length: 2, controller: "c", action: "a", id: "i") ) end def test_port add_host! assert_equal("http://www.basecamphq.com:3000/c/a/i", - W.new.url_for(:controller => "c", :action => "a", :id => "i", :port => 3000) + W.new.url_for(controller: "c", action: "a", id: "i", port: 3000) ) end @@ -174,37 +174,37 @@ module AbstractController add_host! add_port! assert_equal("http://www.basecamphq.com:3000/c/a/i", - W.new.url_for(:controller => "c", :action => "a", :id => "i") + W.new.url_for(controller: "c", action: "a", id: "i") ) end def test_protocol add_host! assert_equal("https://www.basecamphq.com/c/a/i", - W.new.url_for(:controller => "c", :action => "a", :id => "i", :protocol => "https") + W.new.url_for(controller: "c", action: "a", id: "i", protocol: "https") ) end def test_protocol_with_and_without_separators add_host! assert_equal("https://www.basecamphq.com/c/a/i", - W.new.url_for(:controller => "c", :action => "a", :id => "i", :protocol => "https") + W.new.url_for(controller: "c", action: "a", id: "i", protocol: "https") ) assert_equal("https://www.basecamphq.com/c/a/i", - W.new.url_for(:controller => "c", :action => "a", :id => "i", :protocol => "https:") + W.new.url_for(controller: "c", action: "a", id: "i", protocol: "https:") ) assert_equal("https://www.basecamphq.com/c/a/i", - W.new.url_for(:controller => "c", :action => "a", :id => "i", :protocol => "https://") + W.new.url_for(controller: "c", action: "a", id: "i", protocol: "https://") ) end def test_without_protocol add_host! assert_equal("//www.basecamphq.com/c/a/i", - W.new.url_for(:controller => "c", :action => "a", :id => "i", :protocol => "//") + W.new.url_for(controller: "c", action: "a", id: "i", protocol: "//") ) assert_equal("//www.basecamphq.com/c/a/i", - W.new.url_for(:controller => "c", :action => "a", :id => "i", :protocol => false) + W.new.url_for(controller: "c", action: "a", id: "i", protocol: false) ) end @@ -213,42 +213,42 @@ module AbstractController add_port! assert_equal("//www.basecamphq.com:3000/c/a/i", - W.new.url_for(:controller => "c", :action => "a", :id => "i", :protocol => "//") + W.new.url_for(controller: "c", action: "a", id: "i", protocol: "//") ) assert_equal("//www.basecamphq.com:3000/c/a/i", - W.new.url_for(:controller => "c", :action => "a", :id => "i", :protocol => false) + W.new.url_for(controller: "c", action: "a", id: "i", protocol: false) ) end def test_trailing_slash add_host! - options = {:controller => "foo", :trailing_slash => true, :action => "bar", :id => "33"} + options = {controller: "foo", trailing_slash: true, action: "bar", id: "33"} assert_equal("http://www.basecamphq.com/foo/bar/33/", W.new.url_for(options) ) end def test_trailing_slash_with_protocol add_host! - options = { :trailing_slash => true,:protocol => "https", :controller => "foo", :action => "bar", :id => "33"} + options = { trailing_slash: true,protocol: "https", controller: "foo", action: "bar", id: "33"} assert_equal("https://www.basecamphq.com/foo/bar/33/", W.new.url_for(options) ) - assert_equal "https://www.basecamphq.com/foo/bar/33/?query=string", W.new.url_for(options.merge({:query => "string"})) + assert_equal "https://www.basecamphq.com/foo/bar/33/?query=string", W.new.url_for(options.merge({query: "string"})) end def test_trailing_slash_with_only_path - options = {:controller => "foo", :trailing_slash => true} - assert_equal "/foo/", W.new.url_for(options.merge({:only_path => true})) - options.update({:action => "bar", :id => "33"}) - assert_equal "/foo/bar/33/", W.new.url_for(options.merge({:only_path => true})) - assert_equal "/foo/bar/33/?query=string", W.new.url_for(options.merge({:query => "string",:only_path => true})) + options = {controller: "foo", trailing_slash: true} + assert_equal "/foo/", W.new.url_for(options.merge({only_path: true})) + options.update({action: "bar", id: "33"}) + assert_equal "/foo/bar/33/", W.new.url_for(options.merge({only_path: true})) + assert_equal "/foo/bar/33/?query=string", W.new.url_for(options.merge({query: "string",only_path: true})) end def test_trailing_slash_with_anchor - options = {:trailing_slash => true, :controller => "foo", :action => "bar", :id => "33", :only_path => true, :anchor=> "chapter7"} + options = {trailing_slash: true, controller: "foo", action: "bar", id: "33", only_path: true, anchor: "chapter7"} assert_equal "/foo/bar/33/#chapter7", W.new.url_for(options) - assert_equal "/foo/bar/33/?query=string#chapter7", W.new.url_for(options.merge({:query => "string"})) + assert_equal "/foo/bar/33/?query=string#chapter7", W.new.url_for(options.merge({query: "string"})) end def test_trailing_slash_with_params - url = W.new.url_for(:trailing_slash => true, :only_path => true, :controller => "cont", :action => "act", :p1 => "cafe", :p2 => "link") + url = W.new.url_for(trailing_slash: true, only_path: true, controller: "cont", action: "act", p1: "cafe", p2: "link") params = extract_params(url) assert_equal({p1: "cafe"}.to_query, params[0]) assert_equal({p2: "link"}.to_query, params[1]) @@ -257,7 +257,7 @@ module AbstractController def test_relative_url_root_is_respected add_host! assert_equal("https://www.basecamphq.com/subdir/c/a/i", - W.new.url_for(:controller => "c", :action => "a", :id => "i", :protocol => "https", :script_name => "/subdir") + W.new.url_for(controller: "c", action: "a", id: "i", protocol: "https", script_name: "/subdir") ) end @@ -271,15 +271,15 @@ module AbstractController } add_host!(w) assert_equal("https://www.basecamphq.com/subdir/c/a/i", - w.new.url_for(:controller => "c", :action => "a", :id => "i", :protocol => "https") + w.new.url_for(controller: "c", action: "a", id: "i", protocol: "https") ) end def test_named_routes with_routing do |set| set.draw do - get "this/is/verbose", :to => "home#index", :as => :no_args - get "home/sweet/home/:user", :to => "home#index", :as => :home + get "this/is/verbose", to: "home#index", as: :no_args + get "home/sweet/home/:user", to: "home#index", as: :home end # We need to create a new class in order to install the new named route. @@ -288,39 +288,39 @@ module AbstractController controller = kls.new assert controller.respond_to?(:home_url) assert_equal "http://www.basecamphq.com/home/sweet/home/again", - controller.send(:home_url, :host => "www.basecamphq.com", :user => "again") + controller.send(:home_url, host: "www.basecamphq.com", user: "again") - assert_equal("/home/sweet/home/alabama", controller.send(:home_path, :user => "alabama", :host => "unused")) - assert_equal("http://www.basecamphq.com/home/sweet/home/alabama", controller.send(:home_url, :user => "alabama", :host => "www.basecamphq.com")) - assert_equal("http://www.basecamphq.com/this/is/verbose", controller.send(:no_args_url, :host=>"www.basecamphq.com")) + assert_equal("/home/sweet/home/alabama", controller.send(:home_path, user: "alabama", host: "unused")) + assert_equal("http://www.basecamphq.com/home/sweet/home/alabama", controller.send(:home_url, user: "alabama", host: "www.basecamphq.com")) + assert_equal("http://www.basecamphq.com/this/is/verbose", controller.send(:no_args_url, host: "www.basecamphq.com")) end end def test_relative_url_root_is_respected_for_named_routes with_routing do |set| set.draw do - get "/home/sweet/home/:user", :to => "home#index", :as => :home + get "/home/sweet/home/:user", to: "home#index", as: :home end kls = Class.new { include set.url_helpers } controller = kls.new assert_equal "http://www.basecamphq.com/subdir/home/sweet/home/again", - controller.send(:home_url, :host => "www.basecamphq.com", :user => "again", :script_name => "/subdir") + controller.send(:home_url, host: "www.basecamphq.com", user: "again", script_name: "/subdir") end end def test_using_nil_script_name_properly_concats_with_original_script_name add_host! assert_equal("https://www.basecamphq.com/subdir/c/a/i", - W.new.url_for(:controller => "c", :action => "a", :id => "i", :protocol => "https", :script_name => nil, :original_script_name => "/subdir") + W.new.url_for(controller: "c", action: "a", id: "i", protocol: "https", script_name: nil, original_script_name: "/subdir") ) end def test_only_path with_routing do |set| set.draw do - get "home/sweet/home/:user", :to => "home#index", :as => :home + get "home/sweet/home/:user", to: "home#index", as: :home ActiveSupport::Deprecation.silence do get ":controller/:action/:id" @@ -332,42 +332,42 @@ module AbstractController controller = kls.new assert_respond_to controller, :home_url assert_equal "/brave/new/world", - controller.url_for(:controller => "brave", :action => "new", :id => "world", :only_path => true) + controller.url_for(controller: "brave", action: "new", id: "world", only_path: true) - assert_equal("/home/sweet/home/alabama", controller.home_path(:user => "alabama", :host => "unused")) + assert_equal("/home/sweet/home/alabama", controller.home_path(user: "alabama", host: "unused")) assert_equal("/home/sweet/home/alabama", controller.home_path("alabama")) end end def test_one_parameter assert_equal("/c/a?param=val", - W.new.url_for(:only_path => true, :controller => "c", :action => "a", :param => "val") + W.new.url_for(only_path: true, controller: "c", action: "a", param: "val") ) end def test_two_parameters - url = W.new.url_for(:only_path => true, :controller => "c", :action => "a", :p1 => "X1", :p2 => "Y2") + url = W.new.url_for(only_path: true, controller: "c", action: "a", p1: "X1", p2: "Y2") params = extract_params(url) assert_equal({p1: "X1"}.to_query, params[0]) assert_equal({p2: "Y2"}.to_query, params[1]) end def test_hash_parameter - url = W.new.url_for(:only_path => true, :controller => "c", :action => "a", :query => {:name => "Bob", :category => "prof"}) + url = W.new.url_for(only_path: true, controller: "c", action: "a", query: {name: "Bob", category: "prof"}) params = extract_params(url) assert_equal({"query[category]" => "prof"}.to_query, params[0]) assert_equal({"query[name]" => "Bob"}.to_query, params[1]) end def test_array_parameter - url = W.new.url_for(:only_path => true, :controller => "c", :action => "a", :query => ["Bob", "prof"]) + url = W.new.url_for(only_path: true, controller: "c", action: "a", query: ["Bob", "prof"]) params = extract_params(url) assert_equal({"query[]" => "Bob"}.to_query, params[0]) assert_equal({"query[]" => "prof"}.to_query, params[1]) end def test_hash_recursive_parameters - url = W.new.url_for(:only_path => true, :controller => "c", :action => "a", :query => {:person => {:name => "Bob", :position => "prof"}, :hobby => "piercing"}) + url = W.new.url_for(only_path: true, controller: "c", action: "a", query: {person: {name: "Bob", position: "prof"}, hobby: "piercing"}) params = extract_params(url) assert_equal({"query[hobby]" => "piercing"}.to_query, params[0]) assert_equal({"query[person][name]" => "Bob" }.to_query, params[1]) @@ -375,7 +375,7 @@ module AbstractController end def test_hash_recursive_and_array_parameters - url = W.new.url_for(:only_path => true, :controller => "c", :action => "a", :id => 101, :query => {:person => {:name => "Bob", :position => ["prof", "art director"]}, :hobby => "piercing"}) + url = W.new.url_for(only_path: true, controller: "c", action: "a", id: 101, query: {person: {name: "Bob", position: ["prof", "art director"]}, hobby: "piercing"}) assert_match(%r(^/c/a/101), url) params = extract_params(url) assert_equal({"query[hobby]" => "piercing" }.to_query, params[0]) @@ -387,19 +387,19 @@ module AbstractController def test_url_action_controller_parameters add_host! assert_raise(ArgumentError) do - W.new.url_for(ActionController::Parameters.new(:controller => "c", :action => "a", protocol: "javascript", f: "%0Aeval(name)")) + W.new.url_for(ActionController::Parameters.new(controller: "c", action: "a", protocol: "javascript", f: "%0Aeval(name)")) end end def test_path_generation_for_symbol_parameter_keys - assert_generates("/image", :controller=> :image) + assert_generates("/image", controller: :image) end def test_named_routes_with_nil_keys with_routing do |set| set.draw do - get "posts.:format", :to => "posts#index", :as => :posts - get "/", :to => "posts#index", :as => :main + get "posts.:format", to: "posts#index", as: :posts + get "/", to: "posts#index", as: :main end # We need to create a new class in order to install the new named route. @@ -407,7 +407,7 @@ module AbstractController kls.default_url_options[:host] = "www.basecamphq.com" controller = kls.new - params = {:action => :index, :controller => :posts, :format => :xml} + params = {action: :index, controller: :posts, format: :xml} assert_equal("http://www.basecamphq.com/posts.xml", controller.send(:url_for, params)) params[:format] = nil assert_equal("http://www.basecamphq.com/", controller.send(:url_for, params)) @@ -442,11 +442,11 @@ module AbstractController end def test_url_params_with_nil_to_param_are_not_in_url - assert_equal("/c/a", W.new.url_for(:only_path => true, :controller => "c", :action => "a", :id => Struct.new(:to_param).new(nil))) + assert_equal("/c/a", W.new.url_for(only_path: true, controller: "c", action: "a", id: Struct.new(:to_param).new(nil))) end def test_false_url_params_are_included_in_query - assert_equal("/c/a?show=false", W.new.url_for(:only_path => true, :controller => "c", :action => "a", :show => false)) + assert_equal("/c/a?show=false", W.new.url_for(only_path: true, controller: "c", action: "a", show: false)) end def test_url_generation_with_array_and_hash diff --git a/actionpack/test/controller/url_rewriter_test.rb b/actionpack/test/controller/url_rewriter_test.rb index 9709e8b430..5f481c1edb 100644 --- a/actionpack/test/controller/url_rewriter_test.rb +++ b/actionpack/test/controller/url_rewriter_test.rb @@ -5,8 +5,8 @@ class UrlRewriterTests < ActionController::TestCase class Rewriter def initialize(request) @options = { - :host => request.host_with_port, - :protocol => request.protocol + host: request.host_with_port, + protocol: request.protocol } end @@ -29,62 +29,62 @@ class UrlRewriterTests < ActionController::TestCase def test_port assert_equal("http://test.host:1271/c/a/i", - @rewriter.rewrite(@routes, :controller => "c", :action => "a", :id => "i", :port => 1271) + @rewriter.rewrite(@routes, controller: "c", action: "a", id: "i", port: 1271) ) end def test_protocol_with_and_without_separator assert_equal("https://test.host/c/a/i", - @rewriter.rewrite(@routes, :protocol => "https", :controller => "c", :action => "a", :id => "i") + @rewriter.rewrite(@routes, protocol: "https", controller: "c", action: "a", id: "i") ) assert_equal("https://test.host/c/a/i", - @rewriter.rewrite(@routes, :protocol => "https://", :controller => "c", :action => "a", :id => "i") + @rewriter.rewrite(@routes, protocol: "https://", controller: "c", action: "a", id: "i") ) end def test_user_name_and_password assert_equal( "http://david:secret@test.host/c/a/i", - @rewriter.rewrite(@routes, :user => "david", :password => "secret", :controller => "c", :action => "a", :id => "i") + @rewriter.rewrite(@routes, user: "david", password: "secret", controller: "c", action: "a", id: "i") ) end def test_user_name_and_password_with_escape_codes assert_equal( "http://openid.aol.com%2Fnextangler:one+two%3F@test.host/c/a/i", - @rewriter.rewrite(@routes, :user => "openid.aol.com/nextangler", :password => "one two?", :controller => "c", :action => "a", :id => "i") + @rewriter.rewrite(@routes, user: "openid.aol.com/nextangler", password: "one two?", controller: "c", action: "a", id: "i") ) end def test_anchor assert_equal( "http://test.host/c/a/i#anchor", - @rewriter.rewrite(@routes, :controller => "c", :action => "a", :id => "i", :anchor => "anchor") + @rewriter.rewrite(@routes, controller: "c", action: "a", id: "i", anchor: "anchor") ) end def test_anchor_should_call_to_param assert_equal( "http://test.host/c/a/i#anchor", - @rewriter.rewrite(@routes, :controller => "c", :action => "a", :id => "i", :anchor => Struct.new(:to_param).new("anchor")) + @rewriter.rewrite(@routes, controller: "c", action: "a", id: "i", anchor: Struct.new(:to_param).new("anchor")) ) end def test_anchor_should_be_uri_escaped assert_equal( "http://test.host/c/a/i#anc/hor", - @rewriter.rewrite(@routes, :controller => "c", :action => "a", :id => "i", :anchor => Struct.new(:to_param).new("anc/hor")) + @rewriter.rewrite(@routes, controller: "c", action: "a", id: "i", anchor: Struct.new(:to_param).new("anc/hor")) ) end def test_trailing_slash - options = {:controller => "foo", :action => "bar", :id => "3", :only_path => true} + options = {controller: "foo", action: "bar", id: "3", only_path: true} assert_equal "/foo/bar/3", @rewriter.rewrite(@routes, options) - assert_equal "/foo/bar/3?query=string", @rewriter.rewrite(@routes, options.merge({:query => "string"})) - options.update({:trailing_slash => true}) + assert_equal "/foo/bar/3?query=string", @rewriter.rewrite(@routes, options.merge({query: "string"})) + options.update({trailing_slash: true}) assert_equal "/foo/bar/3/", @rewriter.rewrite(@routes, options) - options.update({:query => "string"}) + options.update({query: "string"}) assert_equal "/foo/bar/3/?query=string", @rewriter.rewrite(@routes, options) end end diff --git a/actionpack/test/controller/webservice_test.rb b/actionpack/test/controller/webservice_test.rb index cc8dd0779b..671009c090 100644 --- a/actionpack/test/controller/webservice_test.rb +++ b/actionpack/test/controller/webservice_test.rb @@ -125,7 +125,7 @@ class WebServiceTest < ActionDispatch::IntegrationTest def with_test_route_set with_routing do |set| set.draw do - match "/", :to => "web_service_test/test#assign_parameters", :via => :all + match "/", to: "web_service_test/test#assign_parameters", via: :all end yield end |