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 | |
parent | 12a70404cd164008879e63cc320356e6afee3adc (diff) | |
download | rails-5b6eb1d58b48fada298215b2cccda89f993890c3.tar.gz rails-5b6eb1d58b48fada298215b2cccda89f993890c3.tar.bz2 rails-5b6eb1d58b48fada298215b2cccda89f993890c3.zip |
modernizes hash syntax in actionpack
Diffstat (limited to 'actionpack')
95 files changed, 2062 insertions, 2062 deletions
diff --git a/actionpack/Rakefile b/actionpack/Rakefile index b8e62bf428..4bbbcfe9ff 100644 --- a/actionpack/Rakefile +++ b/actionpack/Rakefile @@ -3,7 +3,7 @@ require "rake/testtask" test_files = Dir.glob("test/**/*_test.rb") desc "Default Task" -task :default => :test +task default: :test task :package diff --git a/actionpack/lib/abstract_controller/callbacks.rb b/actionpack/lib/abstract_controller/callbacks.rb index 0a5c39dac6..873e88fcd5 100644 --- a/actionpack/lib/abstract_controller/callbacks.rb +++ b/actionpack/lib/abstract_controller/callbacks.rb @@ -194,7 +194,7 @@ module AbstractController define_method "prepend_#{callback}_action" do |*names, &blk| _insert_callbacks(names, blk) do |name, options| - set_callback(:process_action, callback, name, options.merge(:prepend => true)) + set_callback(:process_action, callback, name, options.merge(prepend: true)) end end diff --git a/actionpack/lib/action_controller/metal.rb b/actionpack/lib/action_controller/metal.rb index 197aaa90c7..32ad746769 100644 --- a/actionpack/lib/action_controller/metal.rb +++ b/actionpack/lib/action_controller/metal.rb @@ -145,9 +145,9 @@ module ActionController end attr_internal :response, :request - delegate :session, :to => "@_request" + delegate :session, to: "@_request" delegate :headers, :status=, :location=, :content_type=, - :status, :location, :content_type, :to => "@_response" + :status, :location, :content_type, to: "@_response" def initialize @_request = nil diff --git a/actionpack/lib/action_controller/metal/conditional_get.rb b/actionpack/lib/action_controller/metal/conditional_get.rb index abc102f30c..eee17082b7 100644 --- a/actionpack/lib/action_controller/metal/conditional_get.rb +++ b/actionpack/lib/action_controller/metal/conditional_get.rb @@ -232,9 +232,9 @@ module ActionController # The method will also ensure an HTTP Date header for client compatibility. def expires_in(seconds, options = {}) response.cache_control.merge!( - :max_age => seconds, - :public => options.delete(:public), - :must_revalidate => options.delete(:must_revalidate) + max_age: seconds, + public: options.delete(:public), + must_revalidate: options.delete(:must_revalidate) ) options.delete(:private) @@ -245,7 +245,7 @@ module ActionController # Sets an HTTP 1.1 Cache-Control header of <tt>no-cache</tt> so no caching should # occur by the browser or intermediate caches (like caching proxy servers). def expires_now - response.cache_control.replace(:no_cache => true) + response.cache_control.replace(no_cache: true) end # Cache or yield the block. The cache is supposed to never expire. diff --git a/actionpack/lib/action_controller/metal/exceptions.rb b/actionpack/lib/action_controller/metal/exceptions.rb index 364af20b55..56a4b085e2 100644 --- a/actionpack/lib/action_controller/metal/exceptions.rb +++ b/actionpack/lib/action_controller/metal/exceptions.rb @@ -35,7 +35,7 @@ module ActionController class MethodNotAllowed < ActionControllerError #:nodoc: def initialize(*allowed_methods) - super("Only #{allowed_methods.to_sentence(:locale => :en)} requests are allowed.") + super("Only #{allowed_methods.to_sentence(locale: :en)} requests are allowed.") end end diff --git a/actionpack/lib/action_controller/metal/force_ssl.rb b/actionpack/lib/action_controller/metal/force_ssl.rb index ff250b7094..b8976497a4 100644 --- a/actionpack/lib/action_controller/metal/force_ssl.rb +++ b/actionpack/lib/action_controller/metal/force_ssl.rb @@ -76,10 +76,10 @@ module ActionController def force_ssl_redirect(host_or_options = nil) unless request.ssl? options = { - :protocol => "https://", - :host => request.host, - :path => request.fullpath, - :status => :moved_permanently + protocol: "https://", + host: request.host, + path: request.fullpath, + status: :moved_permanently } if host_or_options.is_a?(Hash) diff --git a/actionpack/lib/action_controller/metal/instrumentation.rb b/actionpack/lib/action_controller/metal/instrumentation.rb index bb802524b4..6a8129e88b 100644 --- a/actionpack/lib/action_controller/metal/instrumentation.rb +++ b/actionpack/lib/action_controller/metal/instrumentation.rb @@ -16,13 +16,13 @@ module ActionController def process_action(*args) raw_payload = { - :controller => self.class.name, - :action => self.action_name, - :params => request.filtered_parameters, - :headers => request.headers, - :format => request.format.ref, - :method => request.request_method, - :path => request.fullpath + controller: self.class.name, + action: self.action_name, + params: request.filtered_parameters, + headers: request.headers, + format: request.format.ref, + method: request.request_method, + path: request.fullpath } ActiveSupport::Notifications.instrument("start_processing.action_controller", raw_payload.dup) @@ -48,7 +48,7 @@ module ActionController def send_file(path, options={}) ActiveSupport::Notifications.instrument("send_file.action_controller", - options.merge(:path => path)) do + options.merge(path: path)) do super end end @@ -72,7 +72,7 @@ module ActionController # A hook invoked every time a before callback is halted. def halted_callback_hook(filter) - ActiveSupport::Notifications.instrument("halted_callback.action_controller", :filter => filter) + ActiveSupport::Notifications.instrument("halted_callback.action_controller", filter: filter) end # A hook which allows you to clean up any time, wrongly taken into account in diff --git a/actionpack/lib/action_controller/metal/params_wrapper.rb b/actionpack/lib/action_controller/metal/params_wrapper.rb index 4cfea386e6..e52a3cd211 100644 --- a/actionpack/lib/action_controller/metal/params_wrapper.rb +++ b/actionpack/lib/action_controller/metal/params_wrapper.rb @@ -198,9 +198,9 @@ module ActionController when Hash options = name_or_model_or_options when false - options = options.merge(:format => []) + options = options.merge(format: []) when Symbol, String - options = options.merge(:name => name_or_model_or_options) + options = options.merge(name: name_or_model_or_options) else model = name_or_model_or_options end diff --git a/actionpack/lib/action_controller/metal/url_for.rb b/actionpack/lib/action_controller/metal/url_for.rb index dbf7241a14..9f3cc099d6 100644 --- a/actionpack/lib/action_controller/metal/url_for.rb +++ b/actionpack/lib/action_controller/metal/url_for.rb @@ -27,10 +27,10 @@ module ActionController def url_options @_url_options ||= { - :host => request.host, - :port => request.optional_port, - :protocol => request.protocol, - :_recall => request.path_parameters + host: request.host, + port: request.optional_port, + protocol: request.protocol, + _recall: request.path_parameters }.merge!(super).freeze if (same_origin = _routes.equal?(request.routes)) || diff --git a/actionpack/lib/action_controller/railtie.rb b/actionpack/lib/action_controller/railtie.rb index 28b20052b5..6513a556ee 100644 --- a/actionpack/lib/action_controller/railtie.rb +++ b/actionpack/lib/action_controller/railtie.rb @@ -11,7 +11,7 @@ module ActionController config.eager_load_namespaces << ActionController - initializer "action_controller.assets_config", :group => :all do |app| + initializer "action_controller.assets_config", group: :all do |app| app.config.action_controller.assets_dir ||= app.config.paths["public"].first end diff --git a/actionpack/lib/action_dispatch/http/parameters.rb b/actionpack/lib/action_dispatch/http/parameters.rb index 0aae14c9dd..4850ca4404 100644 --- a/actionpack/lib/action_dispatch/http/parameters.rb +++ b/actionpack/lib/action_dispatch/http/parameters.rb @@ -8,7 +8,7 @@ module ActionDispatch DEFAULT_PARSERS = { Mime[:json].symbol => -> (raw_post) { data = ActiveSupport::JSON.decode(raw_post) - data.is_a?(Hash) ? data : {:_json => data} + data.is_a?(Hash) ? data : {_json: data} } } diff --git a/actionpack/lib/action_dispatch/http/response.rb b/actionpack/lib/action_dispatch/http/response.rb index 2b4e43d175..6483bb3804 100644 --- a/actionpack/lib/action_dispatch/http/response.rb +++ b/actionpack/lib/action_dispatch/http/response.rb @@ -67,7 +67,7 @@ module ActionDispatch # :nodoc: alias_method :headers, :header - delegate :[], :[]=, :to => :@header + delegate :[], :[]=, to: :@header def each(&block) sending! diff --git a/actionpack/lib/action_dispatch/journey/route.rb b/actionpack/lib/action_dispatch/journey/route.rb index ad33c9d30b..14f617ea3f 100644 --- a/actionpack/lib/action_dispatch/journey/route.rb +++ b/actionpack/lib/action_dispatch/journey/route.rb @@ -32,7 +32,7 @@ module ActionDispatch def self.verb; ""; end end - VERB_TO_CLASS = VERBS.each_with_object({ :all => All }) do |verb, hash| + VERB_TO_CLASS = VERBS.each_with_object({ all: All }) do |verb, hash| klass = const_get verb hash[verb] = klass hash[verb.downcase] = klass diff --git a/actionpack/lib/action_dispatch/middleware/cookies.rb b/actionpack/lib/action_dispatch/middleware/cookies.rb index d5bb0032b5..ddae0c5a8e 100644 --- a/actionpack/lib/action_dispatch/middleware/cookies.rb +++ b/actionpack/lib/action_dispatch/middleware/cookies.rb @@ -367,7 +367,7 @@ module ActionDispatch value = options[:value] else value = options - options = { :value => value } + options = { value: value } end handle_options(options) diff --git a/actionpack/lib/action_dispatch/middleware/public_exceptions.rb b/actionpack/lib/action_dispatch/middleware/public_exceptions.rb index e82fe73c1a..5f356daba8 100644 --- a/actionpack/lib/action_dispatch/middleware/public_exceptions.rb +++ b/actionpack/lib/action_dispatch/middleware/public_exceptions.rb @@ -20,7 +20,7 @@ module ActionDispatch request = ActionDispatch::Request.new(env) status = request.path_info[1..-1].to_i content_type = request.formats.first - body = { :status => status, :error => Rack::Utils::HTTP_STATUS_CODES.fetch(status, Rack::Utils::HTTP_STATUS_CODES[500]) } + body = { status: status, error: Rack::Utils::HTTP_STATUS_CODES.fetch(status, Rack::Utils::HTTP_STATUS_CODES[500]) } render(status, content_type, body) end diff --git a/actionpack/lib/action_dispatch/middleware/session/cache_store.rb b/actionpack/lib/action_dispatch/middleware/session/cache_store.rb index d21b70083e..d99c2fd411 100644 --- a/actionpack/lib/action_dispatch/middleware/session/cache_store.rb +++ b/actionpack/lib/action_dispatch/middleware/session/cache_store.rb @@ -29,7 +29,7 @@ module ActionDispatch def write_session(env, sid, session, options) key = cache_key(sid) if session - @cache.write(key, session, :expires_in => options[:expire_after]) + @cache.write(key, session, expires_in: options[:expire_after]) else @cache.delete(key) end diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb index 76429958b3..405a8f229c 100644 --- a/actionpack/lib/action_dispatch/routing/mapper.rb +++ b/actionpack/lib/action_dispatch/routing/mapper.rb @@ -614,7 +614,7 @@ module ActionDispatch target_as = name_for_action(options[:as], path) options[:via] ||= :all - match(path, options.merge(:to => app, :anchor => false, :format => false)) + match(path, options.merge(to: app, anchor: false, format: false)) define_generate_prefix(app, target_as) if rails_app self @@ -985,7 +985,7 @@ module ActionDispatch # resources :iphones # end def constraints(constraints = {}) - scope(:constraints => constraints) { yield } + scope(constraints: constraints) { yield } end # Allows you to set default parameters for a route, such as this: @@ -1801,7 +1801,7 @@ to this: end def resource_scope(resource) #:nodoc: - @scope = @scope.new(:scope_level_resource => resource) + @scope = @scope.new(scope_level_resource: resource) controller(resource.resource_scope) { yield } ensure @@ -1809,7 +1809,7 @@ to this: end def nested_options #:nodoc: - options = { :as => parent_resource.member_name } + options = { as: parent_resource.member_name } options[:constraints] = { parent_resource.nested_param => param_constraint } if param_constraint? @@ -1836,8 +1836,8 @@ to this: end def shallow_scope #:nodoc: - scope = { :as => @scope[:shallow_prefix], - :path => @scope[:shallow_path] } + scope = { as: @scope[:shallow_prefix], + path: @scope[:shallow_path] } @scope = @scope.new scope yield @@ -2122,7 +2122,7 @@ to this: def initialize(set) #:nodoc: @set = set - @scope = Scope.new({ :path_names => @set.resources_path_names }) + @scope = Scope.new({ path_names: @set.resources_path_names }) @concerns = {} end diff --git a/actionpack/lib/action_dispatch/routing/polymorphic_routes.rb b/actionpack/lib/action_dispatch/routing/polymorphic_routes.rb index 0b5041b231..a0874d6be3 100644 --- a/actionpack/lib/action_dispatch/routing/polymorphic_routes.rb +++ b/actionpack/lib/action_dispatch/routing/polymorphic_routes.rb @@ -150,11 +150,11 @@ module ActionDispatch private def polymorphic_url_for_action(action, record_or_hash, options) - polymorphic_url(record_or_hash, options.merge(:action => action)) + polymorphic_url(record_or_hash, options.merge(action: action)) end def polymorphic_path_for_action(action, record_or_hash, options) - polymorphic_path(record_or_hash, options.merge(:action => action)) + polymorphic_path(record_or_hash, options.merge(action: action)) end class HelperMethodBuilder # :nodoc: diff --git a/actionpack/lib/action_dispatch/routing/redirection.rb b/actionpack/lib/action_dispatch/routing/redirection.rb index c3a661a210..25784cfd70 100644 --- a/actionpack/lib/action_dispatch/routing/redirection.rb +++ b/actionpack/lib/action_dispatch/routing/redirection.rb @@ -103,11 +103,11 @@ module ActionDispatch def path(params, request) url_options = { - :protocol => request.protocol, - :host => request.host, - :port => request.optional_port, - :path => request.path, - :params => request.query_parameters + protocol: request.protocol, + host: request.host, + port: request.optional_port, + path: request.path, + params: request.query_parameters }.merge! options if !params.empty? && url_options[:path].match(/%\{\w*\}/) diff --git a/actionpack/lib/action_dispatch/routing/route_set.rb b/actionpack/lib/action_dispatch/routing/route_set.rb index f5b817bf90..9b2bb754c2 100644 --- a/actionpack/lib/action_dispatch/routing/route_set.rb +++ b/actionpack/lib/action_dispatch/routing/route_set.rb @@ -310,7 +310,7 @@ module ActionDispatch alias :routes :set def self.default_resources_path_names - { :new => "new", :edit => "edit" } + { new: "new", edit: "edit" } end def self.new_with_config(config) @@ -731,7 +731,7 @@ module ActionDispatch extras = environment[:extras] || {} begin - env = Rack::MockRequest.env_for(path, {:method => method}) + env = Rack::MockRequest.env_for(path, {method: method}) rescue URI::InvalidURIError => e raise ActionController::RoutingError, e.message end diff --git a/actionpack/lib/action_dispatch/testing/assertions/routing.rb b/actionpack/lib/action_dispatch/testing/assertions/routing.rb index de88cd1ffd..27736ec0eb 100644 --- a/actionpack/lib/action_dispatch/testing/assertions/routing.rb +++ b/actionpack/lib/action_dispatch/testing/assertions/routing.rb @@ -202,7 +202,7 @@ module ActionDispatch request.request_method = method if method params = fail_on(ActionController::RoutingError, msg) do - @routes.recognize_path(path, { :method => method, :extras => extras }) + @routes.recognize_path(path, { method: method, extras: extras }) end request.path_parameters = params.with_indifferent_access diff --git a/actionpack/lib/action_dispatch/testing/integration.rb b/actionpack/lib/action_dispatch/testing/integration.rb index c12c316798..ea7e39b2e6 100644 --- a/actionpack/lib/action_dispatch/testing/integration.rb +++ b/actionpack/lib/action_dispatch/testing/integration.rb @@ -182,11 +182,11 @@ module ActionDispatch include TestProcess, RequestHelpers, Assertions %w( status status_message headers body redirect? ).each do |method| - delegate method, :to => :response, :allow_nil => true + delegate method, to: :response, allow_nil: true end %w( path ).each do |method| - delegate method, :to => :request, :allow_nil => true + delegate method, to: :request, allow_nil: true end # The hostname used in the last request. @@ -237,7 +237,7 @@ module ActionDispatch url_options.reverse_merge!(@app.routes.default_url_options) end - url_options.reverse_merge!(:host => host, :protocol => https? ? "https" : "http") + url_options.reverse_merge!(host: host, protocol: https? ? "https" : "http") end end diff --git a/actionpack/test/abstract/callbacks_test.rb b/actionpack/test/abstract/callbacks_test.rb index 63fbf72225..14d73e8372 100644 --- a/actionpack/test/abstract/callbacks_test.rb +++ b/actionpack/test/abstract/callbacks_test.rb @@ -114,8 +114,8 @@ module AbstractController end class CallbacksWithConditions < ControllerWithCallbacks - before_action :list, :only => :index - before_action :authenticate, :except => :index + before_action :list, only: :index + before_action :authenticate, except: :index def index self.response_body = @list.join(", ") @@ -202,7 +202,7 @@ module AbstractController end class ChangedConditions < Callback2 - before_action :first, :only => :index + before_action :first, only: :index def not_index @text ||= nil diff --git a/actionpack/test/abstract_unit.rb b/actionpack/test/abstract_unit.rb index 7be4f3b4e9..075ebd3974 100644 --- a/actionpack/test/abstract_unit.rb +++ b/actionpack/test/abstract_unit.rb @@ -310,7 +310,7 @@ end module RoutingTestHelpers def url_for(set, options) route_name = options.delete :use_route - set.url_for options.merge(:only_path => true), route_name + set.url_for options.merge(only_path: true), route_name end def make_set(strict = true) 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 diff --git a/actionpack/test/dispatch/cookies_test.rb b/actionpack/test/dispatch/cookies_test.rb index eb15772133..06a54591b8 100644 --- a/actionpack/test/dispatch/cookies_test.rb +++ b/actionpack/test/dispatch/cookies_test.rb @@ -100,7 +100,7 @@ class CookiesTest < ActionController::TestCase end def authenticate_for_fourteen_days_with_symbols - cookies[:user_name] = { :value => "david", :expires => Time.utc(2005, 10, 10,5) } + cookies[:user_name] = { value: "david", expires: Time.utc(2005, 10, 10,5) } head :ok end @@ -123,17 +123,17 @@ class CookiesTest < ActionController::TestCase alias delete_cookie logout def delete_cookie_with_path - cookies.delete("user_name", :path => "/beaten") + cookies.delete("user_name", path: "/beaten") head :ok end def authenticate_with_http_only - cookies["user_name"] = { :value => "david", :httponly => true } + cookies["user_name"] = { value: "david", httponly: true } head :ok end def authenticate_with_secure - cookies["user_name"] = { :value => "david", :secure => true } + cookies["user_name"] = { value: "david", secure: true } head :ok end @@ -205,47 +205,47 @@ class CookiesTest < ActionController::TestCase def delete_and_set_cookie cookies.delete :user_name - cookies[:user_name] = { :value => "david", :expires => Time.utc(2005, 10, 10,5) } + cookies[:user_name] = { value: "david", expires: Time.utc(2005, 10, 10,5) } head :ok end def set_cookie_with_domain - cookies[:user_name] = {:value => "rizwanreza", :domain => :all} + cookies[:user_name] = {value: "rizwanreza", domain: :all} head :ok end def set_cookie_with_domain_all_as_string - cookies[:user_name] = {:value => "rizwanreza", :domain => "all"} + cookies[:user_name] = {value: "rizwanreza", domain: "all"} head :ok end def delete_cookie_with_domain - cookies.delete(:user_name, :domain => :all) + cookies.delete(:user_name, domain: :all) head :ok end def delete_cookie_with_domain_all_as_string - cookies.delete(:user_name, :domain => "all") + cookies.delete(:user_name, domain: "all") head :ok end def set_cookie_with_domain_and_tld - cookies[:user_name] = {:value => "rizwanreza", :domain => :all, :tld_length => 2} + cookies[:user_name] = {value: "rizwanreza", domain: :all, tld_length: 2} head :ok end def delete_cookie_with_domain_and_tld - cookies.delete(:user_name, :domain => :all, :tld_length => 2) + cookies.delete(:user_name, domain: :all, tld_length: 2) head :ok end def set_cookie_with_domains - cookies[:user_name] = {:value => "rizwanreza", :domain => %w(example1.com example2.com .example3.com)} + cookies[:user_name] = {value: "rizwanreza", domain: %w(example1.com example2.com .example3.com)} head :ok end def delete_cookie_with_domains - cookies.delete(:user_name, :domain => %w(example1.com example2.com .example3.com)) + cookies.delete(:user_name, domain: %w(example1.com example2.com .example3.com)) head :ok end @@ -393,8 +393,8 @@ class CookiesTest < ActionController::TestCase def test_deleted_cookie_predicate_with_mismatching_options cookies[:user_name] = "Joe" - cookies.delete("user_name", :path => "/path") - assert_equal false, cookies.deleted?("user_name", :path => "/different") + cookies.delete("user_name", path: "/path") + assert_equal false, cookies.deleted?("user_name", path: "/different") end def test_cookies_persist_throughout_request diff --git a/actionpack/test/dispatch/mapper_test.rb b/actionpack/test/dispatch/mapper_test.rb index 3c3bb17072..8d2699fef6 100644 --- a/actionpack/test/dispatch/mapper_test.rb +++ b/actionpack/test/dispatch/mapper_test.rb @@ -50,15 +50,15 @@ module ActionDispatch fakeset = FakeSet.new mapper = Mapper.new fakeset assert_raises(ArgumentError) do - mapper.match "/", :to => "posts#index", :as => :main + mapper.match "/", to: "posts#index", as: :main end end def test_unscoped_formatted fakeset = FakeSet.new mapper = Mapper.new fakeset - mapper.get "/foo", :to => "posts#index", :as => :main, :format => true - assert_equal({:controller=>"posts", :action=>"index"}, + mapper.get "/foo", to: "posts#index", as: :main, format: true + assert_equal({controller: "posts", action: "index"}, fakeset.defaults.first) assert_equal "/foo.:format", fakeset.asts.first.to_s end @@ -67,9 +67,9 @@ module ActionDispatch fakeset = FakeSet.new mapper = Mapper.new fakeset mapper.scope(format: true) do - mapper.get "/foo", :to => "posts#index", :as => :main + mapper.get "/foo", to: "posts#index", as: :main end - assert_equal({:controller=>"posts", :action=>"index"}, + assert_equal({controller: "posts", action: "index"}, fakeset.defaults.first) assert_equal "/foo.:format", fakeset.asts.first.to_s end @@ -78,9 +78,9 @@ module ActionDispatch fakeset = FakeSet.new mapper = Mapper.new fakeset mapper.scope(omg: :awesome) do - mapper.get "/", :to => "posts#index", :as => :main + mapper.get "/", to: "posts#index", as: :main end - assert_equal({:omg=>:awesome, :controller=>"posts", :action=>"index"}, + assert_equal({omg: :awesome, controller: "posts", action: "index"}, fakeset.defaults.first) assert_equal("GET", fakeset.routes.first.verb) end @@ -97,7 +97,7 @@ module ActionDispatch fakeset = FakeSet.new mapper = Mapper.new fakeset mapper.scope(via: :put) do - mapper.match "/", :to => "posts#index", :as => :main + mapper.match "/", to: "posts#index", as: :main end assert_equal("PUT", fakeset.routes.first.verb) end @@ -117,7 +117,7 @@ module ActionDispatch def test_map_slash fakeset = FakeSet.new mapper = Mapper.new fakeset - mapper.get "/", :to => "posts#index", :as => :main + mapper.get "/", to: "posts#index", as: :main assert_equal "/", fakeset.asts.first.to_s end @@ -126,14 +126,14 @@ module ActionDispatch mapper = Mapper.new fakeset # FIXME: is this a desired behavior? - mapper.get "/one/two/", :to => "posts#index", :as => :main + mapper.get "/one/two/", to: "posts#index", as: :main assert_equal "/one/two(.:format)", fakeset.asts.first.to_s end def test_map_wildcard fakeset = FakeSet.new mapper = Mapper.new fakeset - mapper.get "/*path", :to => "pages#show" + mapper.get "/*path", to: "pages#show" assert_equal "/*path(.:format)", fakeset.asts.first.to_s assert_equal(/.+?/, fakeset.requirements.first[:path]) end @@ -141,7 +141,7 @@ module ActionDispatch def test_map_wildcard_with_other_element fakeset = FakeSet.new mapper = Mapper.new fakeset - mapper.get "/*path/foo/:bar", :to => "pages#show" + mapper.get "/*path/foo/:bar", to: "pages#show" assert_equal "/*path/foo/:bar(.:format)", fakeset.asts.first.to_s assert_equal(/.+?/, fakeset.requirements.first[:path]) end @@ -149,7 +149,7 @@ module ActionDispatch def test_map_wildcard_with_multiple_wildcard fakeset = FakeSet.new mapper = Mapper.new fakeset - mapper.get "/*foo/*bar", :to => "pages#show" + mapper.get "/*foo/*bar", to: "pages#show" assert_equal "/*foo/*bar(.:format)", fakeset.asts.first.to_s assert_equal(/.+?/, fakeset.requirements.first[:foo]) assert_equal(/.+?/, fakeset.requirements.first[:bar]) @@ -158,7 +158,7 @@ module ActionDispatch def test_map_wildcard_with_format_false fakeset = FakeSet.new mapper = Mapper.new fakeset - mapper.get "/*path", :to => "pages#show", :format => false + mapper.get "/*path", to: "pages#show", format: false assert_equal "/*path", fakeset.asts.first.to_s assert_nil fakeset.requirements.first[:path] end @@ -166,7 +166,7 @@ module ActionDispatch def test_map_wildcard_with_format_true fakeset = FakeSet.new mapper = Mapper.new fakeset - mapper.get "/*path", :to => "pages#show", :format => true + mapper.get "/*path", to: "pages#show", format: true assert_equal "/*path.:format", fakeset.asts.first.to_s end diff --git a/actionpack/test/dispatch/middleware_stack_test.rb b/actionpack/test/dispatch/middleware_stack_test.rb index a906ddc80f..b00488edd5 100644 --- a/actionpack/test/dispatch/middleware_stack_test.rb +++ b/actionpack/test/dispatch/middleware_stack_test.rb @@ -59,10 +59,10 @@ class MiddlewareStackTest < ActiveSupport::TestCase test "use should push middleware class with arguments onto the stack" do assert_difference "@stack.size" do - @stack.use BazMiddleware, true, :foo => "bar" + @stack.use BazMiddleware, true, foo: "bar" end assert_equal BazMiddleware, @stack.last.klass - assert_equal([true, {:foo => "bar"}], @stack.last.args) + assert_equal([true, {foo: "bar"}], @stack.last.args) end test "use should push middleware class with block arguments onto the stack" do diff --git a/actionpack/test/dispatch/mount_test.rb b/actionpack/test/dispatch/mount_test.rb index f4956526fc..179b65b236 100644 --- a/actionpack/test/dispatch/mount_test.rb +++ b/actionpack/test/dispatch/mount_test.rb @@ -24,21 +24,21 @@ class TestRoutingMount < ActionDispatch::IntegrationTest [200, {"Content-Type" => "text/html"}, ["#{env["SCRIPT_NAME"]} -- #{env["PATH_INFO"]}"]] } - mount SprocketsApp, :at => "/sprockets" + mount SprocketsApp, at: "/sprockets" mount SprocketsApp => "/shorthand" - mount SinatraLikeApp, :at => "/fakeengine", :as => :fake - mount SinatraLikeApp, :at => "/getfake", :via => :get + mount SinatraLikeApp, at: "/fakeengine", as: :fake + mount SinatraLikeApp, at: "/getfake", via: :get scope "/its_a" do - mount SprocketsApp, :at => "/sprocket" + mount SprocketsApp, at: "/sprocket" end resources :users do - mount AppWithRoutes, :at => "/fakeengine", :as => :fake_mounted_at_resource + mount AppWithRoutes, at: "/fakeengine", as: :fake_mounted_at_resource end - mount SprocketsApp, :at => "/", :via => :get + mount SprocketsApp, at: "/", via: :get end APP = RoutedRackApp.new Router diff --git a/actionpack/test/dispatch/prefix_generation_test.rb b/actionpack/test/dispatch/prefix_generation_test.rb index ef2dc170f5..ea11a943f2 100644 --- a/actionpack/test/dispatch/prefix_generation_test.rb +++ b/actionpack/test/dispatch/prefix_generation_test.rb @@ -26,42 +26,42 @@ module TestGenerationPrefix class BlogEngine < Rails::Engine routes.draw do - get "/posts/:id", :to => "inside_engine_generating#show", :as => :post - get "/posts", :to => "inside_engine_generating#index", :as => :posts - get "/url_to_application", :to => "inside_engine_generating#url_to_application" - get "/polymorphic_path_for_engine", :to => "inside_engine_generating#polymorphic_path_for_engine" - get "/conflicting_url", :to => "inside_engine_generating#conflicting" - get "/foo", :to => "never#invoked", :as => :named_helper_that_should_be_invoked_only_in_respond_to_test - - get "/relative_path_root", :to => redirect("") - get "/relative_path_redirect", :to => redirect("foo") - get "/relative_option_root", :to => redirect(:path => "") - get "/relative_option_redirect", :to => redirect(:path => "foo") - get "/relative_custom_root", :to => redirect { |params, request| "" } - get "/relative_custom_redirect", :to => redirect { |params, request| "foo" } - - get "/absolute_path_root", :to => redirect("/") - get "/absolute_path_redirect", :to => redirect("/foo") - get "/absolute_option_root", :to => redirect(:path => "/") - get "/absolute_option_redirect", :to => redirect(:path => "/foo") - get "/absolute_custom_root", :to => redirect { |params, request| "/" } - get "/absolute_custom_redirect", :to => redirect { |params, request| "/foo" } + get "/posts/:id", to: "inside_engine_generating#show", as: :post + get "/posts", to: "inside_engine_generating#index", as: :posts + get "/url_to_application", to: "inside_engine_generating#url_to_application" + get "/polymorphic_path_for_engine", to: "inside_engine_generating#polymorphic_path_for_engine" + get "/conflicting_url", to: "inside_engine_generating#conflicting" + get "/foo", to: "never#invoked", as: :named_helper_that_should_be_invoked_only_in_respond_to_test + + get "/relative_path_root", to: redirect("") + get "/relative_path_redirect", to: redirect("foo") + get "/relative_option_root", to: redirect(path: "") + get "/relative_option_redirect", to: redirect(path: "foo") + get "/relative_custom_root", to: redirect { |params, request| "" } + get "/relative_custom_redirect", to: redirect { |params, request| "foo" } + + get "/absolute_path_root", to: redirect("/") + get "/absolute_path_redirect", to: redirect("/foo") + get "/absolute_option_root", to: redirect(path: "/") + get "/absolute_option_redirect", to: redirect(path: "/foo") + get "/absolute_custom_root", to: redirect { |params, request| "/" } + get "/absolute_custom_redirect", to: redirect { |params, request| "/foo" } end end class RailsApplication < Rails::Engine routes.draw do - scope "/:omg", :omg => "awesome" do + scope "/:omg", omg: "awesome" do mount BlogEngine => "/blog", :as => "blog_engine" end - get "/posts/:id", :to => "outside_engine_generating#post", :as => :post - get "/generate", :to => "outside_engine_generating#index" - get "/polymorphic_path_for_app", :to => "outside_engine_generating#polymorphic_path_for_app" - get "/polymorphic_path_for_engine", :to => "outside_engine_generating#polymorphic_path_for_engine" - get "/polymorphic_with_url_for", :to => "outside_engine_generating#polymorphic_with_url_for" - get "/conflicting_url", :to => "outside_engine_generating#conflicting" - get "/ivar_usage", :to => "outside_engine_generating#ivar_usage" - root :to => "outside_engine_generating#index" + get "/posts/:id", to: "outside_engine_generating#post", as: :post + get "/generate", to: "outside_engine_generating#index" + get "/polymorphic_path_for_app", to: "outside_engine_generating#polymorphic_path_for_app" + get "/polymorphic_path_for_engine", to: "outside_engine_generating#polymorphic_path_for_engine" + get "/polymorphic_with_url_for", to: "outside_engine_generating#polymorphic_with_url_for" + get "/conflicting_url", to: "outside_engine_generating#conflicting" + get "/ivar_usage", to: "outside_engine_generating#ivar_usage" + root to: "outside_engine_generating#index" end end @@ -81,9 +81,9 @@ module TestGenerationPrefix end def url_to_application - path = main_app.url_for(:controller => "outside_engine_generating", - :action => "index", - :only_path => true) + path = main_app.url_for(controller: "outside_engine_generating", + action: "index", + only_path: true) render plain: path end @@ -238,7 +238,7 @@ module TestGenerationPrefix end test "[APP] generating engine's route includes default_url_options[:script_name]" do - RailsApplication.routes.default_url_options = {:script_name => "/something"} + RailsApplication.routes.default_url_options = {script_name: "/something"} get "/generate" assert_equal "/something/awesome/blog/posts/1", last_response.body end @@ -269,16 +269,16 @@ module TestGenerationPrefix end test "[OBJECT] generating engine's route includes prefix" do - assert_equal "/awesome/blog/posts/1", engine_object.post_path(:id => 1) + assert_equal "/awesome/blog/posts/1", engine_object.post_path(id: 1) end test "[OBJECT] generating engine's route includes dynamic prefix" do - assert_equal "/pure-awesomeness/blog/posts/3", engine_object.post_path(:id => 3, :omg => "pure-awesomeness") + assert_equal "/pure-awesomeness/blog/posts/3", engine_object.post_path(id: 3, omg: "pure-awesomeness") end test "[OBJECT] generating engine's route includes default_url_options[:script_name]" do - RailsApplication.routes.default_url_options = {:script_name => "/something"} - assert_equal "/something/pure-awesomeness/blog/posts/3", engine_object.post_path(:id => 3, :omg => "pure-awesomeness") + RailsApplication.routes.default_url_options = {script_name: "/something"} + assert_equal "/something/pure-awesomeness/blog/posts/3", engine_object.post_path(id: 3, omg: "pure-awesomeness") end test "[OBJECT] generating application's route" do @@ -286,7 +286,7 @@ module TestGenerationPrefix end test "[OBJECT] generating application's route includes default_url_options[:script_name]" do - RailsApplication.routes.default_url_options = {:script_name => "/something"} + RailsApplication.routes.default_url_options = {script_name: "/something"} assert_equal "/something/", app_object.root_path end @@ -296,11 +296,11 @@ module TestGenerationPrefix end test "[OBJECT] generating engine's route with url_for" do - path = engine_object.url_for(:controller => "inside_engine_generating", - :action => "show", - :only_path => true, - :omg => "omg", - :id => 1) + path = engine_object.url_for(controller: "inside_engine_generating", + action: "show", + only_path: true, + omg: "omg", + id: 1) assert_equal "/omg/blog/posts/1", path end @@ -308,7 +308,7 @@ module TestGenerationPrefix path = engine_object.posts_path assert_equal "/awesome/blog/posts", path - path = engine_object.posts_url(:host => "example.com") + path = engine_object.posts_url(host: "example.com") assert_equal "http://example.com/awesome/blog/posts", path end @@ -316,7 +316,7 @@ module TestGenerationPrefix path = engine_object.polymorphic_path(Post.new) assert_equal "/awesome/blog/posts/1", path - path = engine_object.polymorphic_url(Post.new, :host => "www.example.com") + path = engine_object.polymorphic_url(Post.new, host: "www.example.com") assert_equal "http://www.example.com/awesome/blog/posts/1", path end @@ -340,21 +340,21 @@ module TestGenerationPrefix @routes ||= begin routes = ActionDispatch::Routing::RouteSet.new routes.draw do - get "/posts/:id", :to => "posts#show", :as => :post - - get "/relative_path_root", :to => redirect("") - get "/relative_path_redirect", :to => redirect("foo") - get "/relative_option_root", :to => redirect(:path => "") - get "/relative_option_redirect", :to => redirect(:path => "foo") - get "/relative_custom_root", :to => redirect { |params, request| "" } - get "/relative_custom_redirect", :to => redirect { |params, request| "foo" } - - get "/absolute_path_root", :to => redirect("/") - get "/absolute_path_redirect", :to => redirect("/foo") - get "/absolute_option_root", :to => redirect(:path => "/") - get "/absolute_option_redirect", :to => redirect(:path => "/foo") - get "/absolute_custom_root", :to => redirect { |params, request| "/" } - get "/absolute_custom_redirect", :to => redirect { |params, request| "/foo" } + get "/posts/:id", to: "posts#show", as: :post + + get "/relative_path_root", to: redirect("") + get "/relative_path_redirect", to: redirect("foo") + get "/relative_option_root", to: redirect(path: "") + get "/relative_option_redirect", to: redirect(path: "foo") + get "/relative_custom_root", to: redirect { |params, request| "" } + get "/relative_custom_redirect", to: redirect { |params, request| "foo" } + + get "/absolute_path_root", to: redirect("/") + get "/absolute_path_redirect", to: redirect("/foo") + get "/absolute_option_root", to: redirect(path: "/") + get "/absolute_option_redirect", to: redirect(path: "/foo") + get "/absolute_custom_root", to: redirect { |params, request| "/" } + get "/absolute_custom_redirect", to: redirect { |params, request| "/foo" } end routes diff --git a/actionpack/test/dispatch/rack_cache_test.rb b/actionpack/test/dispatch/rack_cache_test.rb index c3c03c7df2..e421cbdbce 100644 --- a/actionpack/test/dispatch/rack_cache_test.rb +++ b/actionpack/test/dispatch/rack_cache_test.rb @@ -12,7 +12,7 @@ class RackCacheMetaStoreTest < ActiveSupport::TestCase end test "stuff is deep duped" do - @store.write(:foo, { :bar => :original }) + @store.write(:foo, { bar: :original }) hash = @store.read(:foo) hash[:bar] = :changed hash = @store.read(:foo) diff --git a/actionpack/test/dispatch/reloader_test.rb b/actionpack/test/dispatch/reloader_test.rb index 0ad51af364..5dd3414958 100644 --- a/actionpack/test/dispatch/reloader_test.rb +++ b/actionpack/test/dispatch/reloader_test.rb @@ -166,7 +166,7 @@ class ReloaderTest < ActiveSupport::TestCase i = 10 assert_deprecated do Reloader.to_prepare { i += 1 } - Reloader.to_prepare(:prepend => true) { i = 0 } + Reloader.to_prepare(prepend: true) { i = 0 } end assert_deprecated do diff --git a/actionpack/test/dispatch/request/json_params_parsing_test.rb b/actionpack/test/dispatch/request/json_params_parsing_test.rb index 039888b895..20e16dc0c2 100644 --- a/actionpack/test/dispatch/request/json_params_parsing_test.rb +++ b/actionpack/test/dispatch/request/json_params_parsing_test.rb @@ -104,7 +104,7 @@ class JsonParamsParsingTest < ActionDispatch::IntegrationTest with_routing do |set| set.draw do ActiveSupport::Deprecation.silence do - post ":action", :to => ::JsonParamsParsingTest::TestController + post ":action", to: ::JsonParamsParsingTest::TestController end end yield @@ -114,7 +114,7 @@ end class RootLessJSONParamsParsingTest < ActionDispatch::IntegrationTest class UsersController < ActionController::Base - wrap_parameters :format => :json + wrap_parameters format: :json class << self attr_accessor :last_request_parameters, :last_parameters @@ -194,7 +194,7 @@ class RootLessJSONParamsParsingTest < ActionDispatch::IntegrationTest with_routing do |set| set.draw do ActiveSupport::Deprecation.silence do - post ":action", :to => controller + post ":action", to: controller end end yield diff --git a/actionpack/test/dispatch/request/multipart_params_parsing_test.rb b/actionpack/test/dispatch/request/multipart_params_parsing_test.rb index 67cd9ab85d..2714b7f50b 100644 --- a/actionpack/test/dispatch/request/multipart_params_parsing_test.rb +++ b/actionpack/test/dispatch/request/multipart_params_parsing_test.rb @@ -143,7 +143,7 @@ class MultipartParamsParsingTest < ActionDispatch::IntegrationTest test "uploads and reads binary file" do with_test_routing do fixture = FIXTURE_PATH + "/mona_lisa.jpg" - params = { :uploaded_data => fixture_file_upload(fixture, "image/jpg") } + params = { uploaded_data: fixture_file_upload(fixture, "image/jpg") } post "/read", params: params end end @@ -191,7 +191,7 @@ class MultipartParamsParsingTest < ActionDispatch::IntegrationTest with_routing do |set| set.draw do ActiveSupport::Deprecation.silence do - post ":action", :controller => "multipart_params_parsing_test/test" + post ":action", controller: "multipart_params_parsing_test/test" end end yield diff --git a/actionpack/test/dispatch/request/query_string_parsing_test.rb b/actionpack/test/dispatch/request/query_string_parsing_test.rb index 4f8d4ccd34..6763dbf243 100644 --- a/actionpack/test/dispatch/request/query_string_parsing_test.rb +++ b/actionpack/test/dispatch/request/query_string_parsing_test.rb @@ -145,7 +145,7 @@ class QueryStringParsingTest < ActionDispatch::IntegrationTest with_routing do |set| set.draw do ActiveSupport::Deprecation.silence do - get ":action", :to => ::QueryStringParsingTest::TestController + get ":action", to: ::QueryStringParsingTest::TestController end end @@ -159,7 +159,7 @@ class QueryStringParsingTest < ActionDispatch::IntegrationTest with_routing do |set| set.draw do ActiveSupport::Deprecation.silence do - get ":action", :to => ::QueryStringParsingTest::TestController + get ":action", to: ::QueryStringParsingTest::TestController end end @app = self.class.build_app(set) do |middleware| diff --git a/actionpack/test/dispatch/request/session_test.rb b/actionpack/test/dispatch/request/session_test.rb index 2f0042df29..b599fe5437 100644 --- a/actionpack/test/dispatch/request/session_test.rb +++ b/actionpack/test/dispatch/request/session_test.rb @@ -74,7 +74,7 @@ module ActionDispatch s = Session.create(store, req, {}) s["rails"] = "ftw" - s.update(:rails => "awesome") + s.update(rails: "awesome") assert_equal(["rails"], s.keys) assert_equal("awesome", s["rails"]) diff --git a/actionpack/test/dispatch/request_id_test.rb b/actionpack/test/dispatch/request_id_test.rb index 39d999aa82..d64ee7607d 100644 --- a/actionpack/test/dispatch/request_id_test.rb +++ b/actionpack/test/dispatch/request_id_test.rb @@ -56,7 +56,7 @@ class RequestIdResponseTest < ActionDispatch::IntegrationTest def with_test_route_set with_routing do |set| set.draw do - get "/", :to => ::RequestIdResponseTest::TestController.action(:index) + get "/", to: ::RequestIdResponseTest::TestController.action(:index) end @app = self.class.build_app(set) do |middleware| diff --git a/actionpack/test/dispatch/request_test.rb b/actionpack/test/dispatch/request_test.rb index ab1f10ae0d..0cac971daa 100644 --- a/actionpack/test/dispatch/request_test.rb +++ b/actionpack/test/dispatch/request_test.rb @@ -34,28 +34,28 @@ end class RequestUrlFor < BaseRequestTest test "url_for class method" do - e = assert_raise(ArgumentError) { url_for(:host => nil) } + e = assert_raise(ArgumentError) { url_for(host: nil) } assert_match(/Please provide the :host parameter/, e.message) - assert_equal "/books", url_for(:only_path => true, :path => "/books") + assert_equal "/books", url_for(only_path: true, path: "/books") assert_equal "http://www.example.com/books/?q=code", url_for(trailing_slash: true, path: "/books?q=code") assert_equal "http://www.example.com/books/?spareslashes=////", url_for(trailing_slash: true, path: "/books?spareslashes=////") assert_equal "http://www.example.com", url_for - assert_equal "http://api.example.com", url_for(:subdomain => "api") - assert_equal "http://example.com", url_for(:subdomain => false) - assert_equal "http://www.ror.com", url_for(:domain => "ror.com") - assert_equal "http://api.ror.co.uk", url_for(:host => "www.ror.co.uk", :subdomain => "api", :tld_length => 2) - assert_equal "http://www.example.com:8080", url_for(:port => 8080) - assert_equal "https://www.example.com", url_for(:protocol => "https") - assert_equal "http://www.example.com/docs", url_for(:path => "/docs") - assert_equal "http://www.example.com#signup", url_for(:anchor => "signup") - assert_equal "http://www.example.com/", url_for(:trailing_slash => true) - assert_equal "http://dhh:supersecret@www.example.com", url_for(:user => "dhh", :password => "supersecret") - assert_equal "http://www.example.com?search=books", url_for(:params => { :search => "books" }) - assert_equal "http://www.example.com?params=", url_for(:params => "") - assert_equal "http://www.example.com?params=1", url_for(:params => 1) + assert_equal "http://api.example.com", url_for(subdomain: "api") + assert_equal "http://example.com", url_for(subdomain: false) + assert_equal "http://www.ror.com", url_for(domain: "ror.com") + assert_equal "http://api.ror.co.uk", url_for(host: "www.ror.co.uk", subdomain: "api", tld_length: 2) + assert_equal "http://www.example.com:8080", url_for(port: 8080) + assert_equal "https://www.example.com", url_for(protocol: "https") + assert_equal "http://www.example.com/docs", url_for(path: "/docs") + assert_equal "http://www.example.com#signup", url_for(anchor: "signup") + assert_equal "http://www.example.com/", url_for(trailing_slash: true) + assert_equal "http://dhh:supersecret@www.example.com", url_for(user: "dhh", password: "supersecret") + assert_equal "http://www.example.com?search=books", url_for(params: { search: "books" }) + assert_equal "http://www.example.com?params=", url_for(params: "") + assert_equal "http://www.example.com?params=1", url_for(params: 1) end end diff --git a/actionpack/test/dispatch/response_test.rb b/actionpack/test/dispatch/response_test.rb index 24a17ca740..1efcd9e97f 100644 --- a/actionpack/test/dispatch/response_test.rb +++ b/actionpack/test/dispatch/response_test.rb @@ -221,23 +221,23 @@ class ResponseTest < ActiveSupport::TestCase end test "cookies" do - @response.set_cookie("user_name", :value => "david", :path => "/") + @response.set_cookie("user_name", value: "david", path: "/") _status, headers, _body = @response.to_a assert_equal "user_name=david; path=/", headers["Set-Cookie"] assert_equal({"user_name" => "david"}, @response.cookies) end test "multiple cookies" do - @response.set_cookie("user_name", :value => "david", :path => "/") - @response.set_cookie("login", :value => "foo&bar", :path => "/", :expires => Time.utc(2005, 10, 10,5)) + @response.set_cookie("user_name", value: "david", path: "/") + @response.set_cookie("login", value: "foo&bar", path: "/", expires: Time.utc(2005, 10, 10,5)) _status, headers, _body = @response.to_a assert_equal "user_name=david; path=/\nlogin=foo%26bar; path=/; expires=Mon, 10 Oct 2005 05:00:00 -0000", headers["Set-Cookie"] assert_equal({"login" => "foo&bar", "user_name" => "david"}, @response.cookies) end test "delete cookies" do - @response.set_cookie("user_name", :value => "david", :path => "/") - @response.set_cookie("login", :value => "foo&bar", :path => "/", :expires => Time.utc(2005, 10, 10,5)) + @response.set_cookie("user_name", value: "david", path: "/") + @response.set_cookie("login", value: "foo&bar", path: "/", expires: Time.utc(2005, 10, 10,5)) @response.delete_cookie("login") assert_equal({"user_name" => "david", "login" => nil}, @response.cookies) end @@ -254,7 +254,7 @@ class ResponseTest < ActiveSupport::TestCase assert resp.weak_etag? assert_not resp.strong_etag? assert_equal('W/"202cb962ac59075b964b07152d234b70"', resp.etag) - assert_equal({:public => true}, resp.cache_control) + assert_equal({public: true}, resp.cache_control) assert_equal("public", resp.headers["Cache-Control"]) assert_equal('W/"202cb962ac59075b964b07152d234b70"', resp.headers["ETag"]) @@ -461,7 +461,7 @@ class ResponseIntegrationTest < ActionDispatch::IntegrationTest assert_equal('W/"202cb962ac59075b964b07152d234b70"', @response.headers["ETag"]) assert_equal('W/"202cb962ac59075b964b07152d234b70"', @response.etag) - assert_equal({:public => true}, @response.cache_control) + assert_equal({public: true}, @response.cache_control) end test "response cache control from rackish app" do @@ -478,7 +478,7 @@ class ResponseIntegrationTest < ActionDispatch::IntegrationTest assert_equal('W/"202cb962ac59075b964b07152d234b70"', @response.headers["ETag"]) assert_equal('W/"202cb962ac59075b964b07152d234b70"', @response.etag) - assert_equal({:public => true}, @response.cache_control) + assert_equal({public: true}, @response.cache_control) end test "response charset and content type from railsish app" do diff --git a/actionpack/test/dispatch/routing/inspector_test.rb b/actionpack/test/dispatch/routing/inspector_test.rb index 4686b53cab..07d0a8aefd 100644 --- a/actionpack/test/dispatch/routing/inspector_test.rb +++ b/actionpack/test/dispatch/routing/inspector_test.rb @@ -30,11 +30,11 @@ module ActionDispatch end end engine.routes.draw do - get "/cart", :to => "cart#show" + get "/cart", to: "cart#show" end output = draw do - get "/custom/assets", :to => "custom_assets#show" + get "/custom/assets", to: "custom_assets#show" mount engine => "/blog", :as => "blog" end @@ -71,7 +71,7 @@ module ActionDispatch def test_cart_inspect output = draw do - get "/cart", :to => "cart#show" + get "/cart", to: "cart#show" end assert_equal [ @@ -93,7 +93,7 @@ module ActionDispatch def test_inspect_shows_custom_assets output = draw do - get "/custom/assets", :to => "custom_assets#show" + get "/custom/assets", to: "custom_assets#show" end assert_equal [ @@ -122,7 +122,7 @@ module ActionDispatch def test_inspect_routes_shows_root_route output = draw do - root :to => "pages#main" + root to: "pages#main" end assert_equal [ @@ -160,7 +160,7 @@ module ActionDispatch def test_inspect_routes_shows_controller_and_action_route_with_constraints output = draw do ActiveSupport::Deprecation.silence do - get ":controller(/:action(/:id))", :id => /\d+/ + get ":controller(/:action(/:id))", id: /\d+/ end end @@ -172,7 +172,7 @@ module ActionDispatch def test_rails_routes_shows_route_with_defaults output = draw do - get "photos/:id" => "photos#show", :defaults => {:format => "jpg"} + get "photos/:id" => "photos#show", :defaults => {format: "jpg"} end assert_equal [ @@ -256,7 +256,7 @@ module ActionDispatch end output = draw do - scope :constraint => constraint.new do + scope constraint: constraint.new do mount MountedRackApp => "/foo" end end @@ -289,7 +289,7 @@ module ActionDispatch def test_redirect output = draw do - get "/foo" => redirect("/foo/bar"), :constraints => { :subdomain => "admin" } + get "/foo" => redirect("/foo/bar"), :constraints => { subdomain: "admin" } get "/bar" => redirect(path: "/foo/bar", status: 307) get "/foobar" => redirect{ "/foo/bar" } end diff --git a/actionpack/test/dispatch/routing/ipv6_redirect_test.rb b/actionpack/test/dispatch/routing/ipv6_redirect_test.rb index 866b492bad..b227aca658 100644 --- a/actionpack/test/dispatch/routing/ipv6_redirect_test.rb +++ b/actionpack/test/dispatch/routing/ipv6_redirect_test.rb @@ -7,17 +7,17 @@ class IPv6IntegrationTest < ActionDispatch::IntegrationTest class ::BadRouteRequestController < ActionController::Base include Routes.url_helpers def index - render :text => foo_path + render text: foo_path end def foo - redirect_to :action => :index + redirect_to action: :index end end Routes.draw do - get "/", :to => "bad_route_request#index", :as => :index - get "/foo", :to => "bad_route_request#foo", :as => :foo + get "/", to: "bad_route_request#index", as: :index + get "/foo", to: "bad_route_request#foo", as: :foo end def _routes diff --git a/actionpack/test/dispatch/routing_assertions_test.rb b/actionpack/test/dispatch/routing_assertions_test.rb index 640d339c34..1e77c7311e 100644 --- a/actionpack/test/dispatch/routing_assertions_test.rb +++ b/actionpack/test/dispatch/routing_assertions_test.rb @@ -12,119 +12,119 @@ class RoutingAssertionsTest < ActionController::TestCase @routes.draw do resources :articles - scope "secure", :constraints => { :protocol => "https://" } do - resources :articles, :controller => "secure_articles" + scope "secure", constraints: { protocol: "https://" } do + resources :articles, controller: "secure_articles" end - scope "block", :constraints => lambda { |r| r.ssl? } do - resources :articles, :controller => "block_articles" + scope "block", constraints: lambda { |r| r.ssl? } do + resources :articles, controller: "block_articles" end - scope "query", :constraints => lambda { |r| r.params[:use_query] == "true" } do - resources :articles, :controller => "query_articles" + scope "query", constraints: lambda { |r| r.params[:use_query] == "true" } do + resources :articles, controller: "query_articles" end end end def test_assert_generates - assert_generates("/articles", { :controller => "articles", :action => "index" }) - assert_generates("/articles/1", { :controller => "articles", :action => "show", :id => "1" }) + assert_generates("/articles", { controller: "articles", action: "index" }) + assert_generates("/articles/1", { controller: "articles", action: "show", id: "1" }) end def test_assert_generates_with_defaults - assert_generates("/articles/1/edit", { :controller => "articles", :action => "edit" }, { :id => "1" }) + assert_generates("/articles/1/edit", { controller: "articles", action: "edit" }, { id: "1" }) end def test_assert_generates_with_extras - assert_generates("/articles", { :controller => "articles", :action => "index", :page => "1" }, {}, { :page => "1" }) + assert_generates("/articles", { controller: "articles", action: "index", page: "1" }, {}, { page: "1" }) end def test_assert_recognizes - assert_recognizes({ :controller => "articles", :action => "index" }, "/articles") - assert_recognizes({ :controller => "articles", :action => "show", :id => "1" }, "/articles/1") + assert_recognizes({ controller: "articles", action: "index" }, "/articles") + assert_recognizes({ controller: "articles", action: "show", id: "1" }, "/articles/1") end def test_assert_recognizes_with_extras - assert_recognizes({ :controller => "articles", :action => "index", :page => "1" }, "/articles", { :page => "1" }) + assert_recognizes({ controller: "articles", action: "index", page: "1" }, "/articles", { page: "1" }) end def test_assert_recognizes_with_method - assert_recognizes({ :controller => "articles", :action => "create" }, { :path => "/articles", :method => :post }) - assert_recognizes({ :controller => "articles", :action => "update", :id => "1" }, { :path => "/articles/1", :method => :put }) + assert_recognizes({ controller: "articles", action: "create" }, { path: "/articles", method: :post }) + assert_recognizes({ controller: "articles", action: "update", id: "1" }, { path: "/articles/1", method: :put }) end def test_assert_recognizes_with_hash_constraint assert_raise(Assertion) do - assert_recognizes({ :controller => "secure_articles", :action => "index" }, "http://test.host/secure/articles") + assert_recognizes({ controller: "secure_articles", action: "index" }, "http://test.host/secure/articles") end - assert_recognizes({ :controller => "secure_articles", :action => "index", :protocol => "https://" }, "https://test.host/secure/articles") + assert_recognizes({ controller: "secure_articles", action: "index", protocol: "https://" }, "https://test.host/secure/articles") end def test_assert_recognizes_with_block_constraint assert_raise(Assertion) do - assert_recognizes({ :controller => "block_articles", :action => "index" }, "http://test.host/block/articles") + assert_recognizes({ controller: "block_articles", action: "index" }, "http://test.host/block/articles") end - assert_recognizes({ :controller => "block_articles", :action => "index" }, "https://test.host/block/articles") + assert_recognizes({ controller: "block_articles", action: "index" }, "https://test.host/block/articles") end def test_assert_recognizes_with_query_constraint assert_raise(Assertion) do - assert_recognizes({ :controller => "query_articles", :action => "index", :use_query => "false" }, "/query/articles", { :use_query => "false" }) + assert_recognizes({ controller: "query_articles", action: "index", use_query: "false" }, "/query/articles", { use_query: "false" }) end - assert_recognizes({ :controller => "query_articles", :action => "index", :use_query => "true" }, "/query/articles", { :use_query => "true" }) + assert_recognizes({ controller: "query_articles", action: "index", use_query: "true" }, "/query/articles", { use_query: "true" }) end def test_assert_recognizes_raises_message err = assert_raise(Assertion) do - assert_recognizes({ :controller => "secure_articles", :action => "index" }, "http://test.host/secure/articles", {}, "This is a really bad msg") + assert_recognizes({ controller: "secure_articles", action: "index" }, "http://test.host/secure/articles", {}, "This is a really bad msg") end assert_match err.message, "This is a really bad msg" end def test_assert_routing - assert_routing("/articles", :controller => "articles", :action => "index") + assert_routing("/articles", controller: "articles", action: "index") end def test_assert_routing_raises_message err = assert_raise(Assertion) do - assert_routing("/thisIsNotARoute", { :controller => "articles", :action => "edit", :id => "1" }, { :id => "1" }, {}, "This is a really bad msg") + assert_routing("/thisIsNotARoute", { controller: "articles", action: "edit", id: "1" }, { id: "1" }, {}, "This is a really bad msg") end assert_match err.message, "This is a really bad msg" end def test_assert_routing_with_defaults - assert_routing("/articles/1/edit", { :controller => "articles", :action => "edit", :id => "1" }, { :id => "1" }) + assert_routing("/articles/1/edit", { controller: "articles", action: "edit", id: "1" }, { id: "1" }) end def test_assert_routing_with_extras - assert_routing("/articles", { :controller => "articles", :action => "index", :page => "1" }, { }, { :page => "1" }) + assert_routing("/articles", { controller: "articles", action: "index", page: "1" }, { }, { page: "1" }) end def test_assert_routing_with_hash_constraint assert_raise(Assertion) do - assert_routing("http://test.host/secure/articles", { :controller => "secure_articles", :action => "index" }) + assert_routing("http://test.host/secure/articles", { controller: "secure_articles", action: "index" }) end - assert_routing("https://test.host/secure/articles", { :controller => "secure_articles", :action => "index", :protocol => "https://" }) + assert_routing("https://test.host/secure/articles", { controller: "secure_articles", action: "index", protocol: "https://" }) end def test_assert_routing_with_block_constraint assert_raise(Assertion) do - assert_routing("http://test.host/block/articles", { :controller => "block_articles", :action => "index" }) + assert_routing("http://test.host/block/articles", { controller: "block_articles", action: "index" }) end - assert_routing("https://test.host/block/articles", { :controller => "block_articles", :action => "index" }) + assert_routing("https://test.host/block/articles", { controller: "block_articles", action: "index" }) end def test_with_routing with_routing do |routes| routes.draw do - resources :articles, :path => "artikel" + resources :articles, path: "artikel" end - assert_routing("/artikel", :controller => "articles", :action => "index") + assert_routing("/artikel", controller: "articles", action: "index") assert_raise(Assertion) do - assert_routing("/articles", { :controller => "articles", :action => "index" }) + assert_routing("/articles", { controller: "articles", action: "index" }) end end end diff --git a/actionpack/test/dispatch/routing_test.rb b/actionpack/test/dispatch/routing_test.rb index 362bce8351..6994c7e897 100644 --- a/actionpack/test/dispatch/routing_test.rb +++ b/actionpack/test/dispatch/routing_test.rb @@ -36,12 +36,12 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest assert_equal "sessions#destroy", @response.body assert_equal "/logout", logout_path - assert_equal "/logout", url_for(:controller => "sessions", :action => "destroy", :only_path => true) + assert_equal "/logout", url_for(controller: "sessions", action: "destroy", only_path: true) end def test_login draw do - default_url_options :host => "rubyonrails.org" + default_url_options host: "rubyonrails.org" controller :sessions do get "login" => :new @@ -56,16 +56,16 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest post "/login" assert_equal "sessions#create", @response.body - assert_equal "/login", url_for(:controller => "sessions", :action => "create", :only_path => true) - assert_equal "/login", url_for(:controller => "sessions", :action => "new", :only_path => true) + assert_equal "/login", url_for(controller: "sessions", action: "create", only_path: true) + assert_equal "/login", url_for(controller: "sessions", action: "new", only_path: true) - assert_equal "http://rubyonrails.org/login", url_for(:controller => "sessions", :action => "create") + assert_equal "http://rubyonrails.org/login", url_for(controller: "sessions", action: "create") assert_equal "http://rubyonrails.org/login", login_url end def test_login_redirect draw do - get "account/login", :to => redirect("/login") + get "account/login", to: redirect("/login") end get "/account/login" @@ -85,8 +85,8 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest def test_namespace_redirect draw do namespace :private do - root :to => redirect("/private/index") - get "index", :to => "private#index" + root to: redirect("/private/index") + get "index", to: "private#index" end end @@ -236,7 +236,7 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest def test_redirect_modulo draw do - get "account/modulo/:name", :to => redirect("/%{name}s") + get "account/modulo/:name", to: redirect("/%{name}s") end get "/account/modulo/name" @@ -245,7 +245,7 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest def test_redirect_proc draw do - get "account/proc/:name", :to => redirect {|params, req| "/#{params[:name].pluralize}" } + get "account/proc/:name", to: redirect {|params, req| "/#{params[:name].pluralize}" } end get "/account/proc/person" @@ -263,7 +263,7 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest def test_redirect_hash_with_subdomain draw do - get "mobile", :to => redirect(:subdomain => "mobile") + get "mobile", to: redirect(subdomain: "mobile") end get "/mobile" @@ -272,7 +272,7 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest def test_redirect_hash_with_domain_and_path draw do - get "documentation", :to => redirect(:domain => "example-documentation.com", :path => "") + get "documentation", to: redirect(domain: "example-documentation.com", path: "") end get "/documentation" @@ -281,7 +281,7 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest def test_redirect_hash_with_path draw do - get "new_documentation", :to => redirect(:path => "/documentation/new") + get "new_documentation", to: redirect(path: "/documentation/new") end get "/new_documentation" @@ -290,7 +290,7 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest def test_redirect_hash_with_host draw do - get "super_new_documentation", :to => redirect(:host => "super-docs.com") + get "super_new_documentation", to: redirect(host: "super-docs.com") end get "/super_new_documentation?section=top" @@ -299,7 +299,7 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest def test_redirect_hash_path_substitution draw do - get "stores/:name", :to => redirect(:subdomain => "stores", :path => "/%{name}") + get "stores/:name", to: redirect(subdomain: "stores", path: "/%{name}") end get "/stores/iernest" @@ -308,7 +308,7 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest def test_redirect_hash_path_substitution_with_catch_all draw do - get "stores/:name(*rest)", :to => redirect(:subdomain => "stores", :path => "/%{name}%{rest}") + get "stores/:name(*rest)", to: redirect(subdomain: "stores", path: "/%{name}%{rest}") end get "/stores/iernest/products" @@ -317,7 +317,7 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest def test_redirect_class draw do - get "youtube_favorites/:youtube_id/:name", :to => redirect(YoutubeFavoritesRedirector) + get "youtube_favorites/:youtube_id/:name", to: redirect(YoutubeFavoritesRedirector) end get "/youtube_favorites/oHg5SJYRHA0/rick-rolld" @@ -326,7 +326,7 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest def test_openid draw do - match "openid/login", :via => [:get, :post], :to => "openid#login" + match "openid/login", via: [:get, :post], to: "openid#login" end get "/openid/login" @@ -338,11 +338,11 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest def test_bookmarks draw do - scope "bookmark", :controller => "bookmarks", :as => :bookmark do - get :new, :path => "build" - post :create, :path => "create", :as => "" + scope "bookmark", controller: "bookmarks", as: :bookmark do + get :new, path: "build" + post :create, path: "create", as: "" put :update - get :remove, :action => :destroy, :as => :remove + get :remove, action: :destroy, as: :remove end end @@ -366,13 +366,13 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest def test_pagemarks tc = self draw do - scope "pagemark", :controller => "pagemarks", :as => :pagemark do + scope "pagemark", controller: "pagemarks", as: :pagemark do tc.assert_deprecated do - get "new", :path => "build" + get "new", path: "build" end - post "create", :as => "" + post "create", as: "" put "update" - get "remove", :action => :destroy, :as => :remove + get "remove", action: :destroy, as: :remove tc.assert_deprecated do get action: :show, as: :show end @@ -402,7 +402,7 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest def test_admin draw do - constraints(:ip => /192\.168\.1\.\d\d\d/) do + constraints(ip: /192\.168\.1\.\d\d\d/) do get "admin" => "queenbee#index" end @@ -436,8 +436,8 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest draw do controller(:global) do get "global/hide_notice" - get "global/export", :action => :export, :as => :export_request - get "/export/:id/:file", :action => :export, :as => :export_download, :constraints => { :file => /.*/ } + get "global/export", action: :export, as: :export_request + get "/export/:id/:file", action: :export, as: :export_download, constraints: { file: /.*/ } ActiveSupport::Deprecation.silence do get "global/:action" @@ -459,13 +459,13 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest assert_equal "/global/export", export_request_path assert_equal "/global/hide_notice", global_hide_notice_path - assert_equal "/export/123/foo.txt", export_download_path(:id => 123, :file => "foo.txt") + assert_equal "/export/123/foo.txt", export_download_path(id: 123, file: "foo.txt") end def test_local draw do ActiveSupport::Deprecation.silence do - get "/local/:action", :controller => "local" + get "/local/:action", controller: "local" end end @@ -480,7 +480,7 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest end # without dup, additional (and possibly unwanted) values will be present in the options (eg. :host) - original_options = {:controller => "projects", :action => "status"} + original_options = {controller: "projects", action: "status"} options = original_options.dup url_for options @@ -495,7 +495,7 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest end controller = "/projects" - options = {:controller => controller, :action => "status", :only_path => true} + options = {controller: controller, action: "status", only_path: true} url = url_for(options) assert_equal "/projects/status", url @@ -506,11 +506,11 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest def test_named_route_with_no_side_effects draw do resources :customers do - get "profile", :on => :member + get "profile", on: :member end end - original_options = { :host => "test.host" } + original_options = { host: "test.host" } options = original_options.dup profile_customer_url("customer_model", options) @@ -524,13 +524,13 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest get "/projects/status(.:format)" end - assert_equal "/projects/status", url_for(:controller => "projects", :action => "status", :only_path => true) - assert_equal "/projects/status.json", url_for(:controller => "projects", :action => "status", :format => "json", :only_path => true) + assert_equal "/projects/status", url_for(controller: "projects", action: "status", only_path: true) + assert_equal "/projects/status.json", url_for(controller: "projects", action: "status", format: "json", only_path: true) end def test_projects draw do - resources :projects, :controller => :project + resources :projects, controller: :project end get "/projects" @@ -542,7 +542,7 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest get "/projects.xml" assert_equal "project#index", @response.body - assert_equal "/projects.xml", projects_path(:format => "xml") + assert_equal "/projects.xml", projects_path(format: "xml") get "/projects/new" assert_equal "project#new", @response.body @@ -550,19 +550,19 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest get "/projects/new.xml" assert_equal "project#new", @response.body - assert_equal "/projects/new.xml", new_project_path(:format => "xml") + assert_equal "/projects/new.xml", new_project_path(format: "xml") get "/projects/1" assert_equal "project#show", @response.body - assert_equal "/projects/1", project_path(:id => "1") + assert_equal "/projects/1", project_path(id: "1") get "/projects/1.xml" assert_equal "project#show", @response.body - assert_equal "/projects/1.xml", project_path(:id => "1", :format => "xml") + assert_equal "/projects/1.xml", project_path(id: "1", format: "xml") get "/projects/1/edit" assert_equal "project#edit", @response.body - assert_equal "/projects/1/edit", edit_project_path(:id => "1") + assert_equal "/projects/1/edit", edit_project_path(id: "1") end def test_projects_for_api_app @@ -601,8 +601,8 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest def test_projects_with_post_action_and_new_path_on_collection draw do - resources :projects, :controller => :project do - post "new", :action => "new", :on => :collection, :as => :new + resources :projects, controller: :project do + post "new", action: "new", on: :collection, as: :new end end @@ -613,22 +613,22 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest def test_projects_involvements draw do - resources :projects, :controller => :project do + resources :projects, controller: :project do resources :involvements, :attachments end end get "/projects/1/involvements" assert_equal "involvements#index", @response.body - assert_equal "/projects/1/involvements", project_involvements_path(:project_id => "1") + assert_equal "/projects/1/involvements", project_involvements_path(project_id: "1") get "/projects/1/involvements/new" assert_equal "involvements#new", @response.body - assert_equal "/projects/1/involvements/new", new_project_involvement_path(:project_id => "1") + assert_equal "/projects/1/involvements/new", new_project_involvement_path(project_id: "1") get "/projects/1/involvements/1" assert_equal "involvements#show", @response.body - assert_equal "/projects/1/involvements/1", project_involvement_path(:project_id => "1", :id => "1") + assert_equal "/projects/1/involvements/1", project_involvement_path(project_id: "1", id: "1") put "/projects/1/involvements/1" assert_equal "involvements#update", @response.body @@ -638,66 +638,66 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest get "/projects/1/involvements/1/edit" assert_equal "involvements#edit", @response.body - assert_equal "/projects/1/involvements/1/edit", edit_project_involvement_path(:project_id => "1", :id => "1") + assert_equal "/projects/1/involvements/1/edit", edit_project_involvement_path(project_id: "1", id: "1") end def test_projects_attachments draw do - resources :projects, :controller => :project do + resources :projects, controller: :project do resources :involvements, :attachments end end get "/projects/1/attachments" assert_equal "attachments#index", @response.body - assert_equal "/projects/1/attachments", project_attachments_path(:project_id => "1") + assert_equal "/projects/1/attachments", project_attachments_path(project_id: "1") end def test_projects_participants draw do - resources :projects, :controller => :project do + resources :projects, controller: :project do resources :participants do - put :update_all, :on => :collection + put :update_all, on: :collection end end end get "/projects/1/participants" assert_equal "participants#index", @response.body - assert_equal "/projects/1/participants", project_participants_path(:project_id => "1") + assert_equal "/projects/1/participants", project_participants_path(project_id: "1") put "/projects/1/participants/update_all" assert_equal "participants#update_all", @response.body - assert_equal "/projects/1/participants/update_all", update_all_project_participants_path(:project_id => "1") + assert_equal "/projects/1/participants/update_all", update_all_project_participants_path(project_id: "1") end def test_projects_companies draw do - resources :projects, :controller => :project do + resources :projects, controller: :project do resources :companies do resources :people - resource :avatar, :controller => :avatar + resource :avatar, controller: :avatar end end end get "/projects/1/companies" assert_equal "companies#index", @response.body - assert_equal "/projects/1/companies", project_companies_path(:project_id => "1") + assert_equal "/projects/1/companies", project_companies_path(project_id: "1") get "/projects/1/companies/1/people" assert_equal "people#index", @response.body - assert_equal "/projects/1/companies/1/people", project_company_people_path(:project_id => "1", :company_id => "1") + assert_equal "/projects/1/companies/1/people", project_company_people_path(project_id: "1", company_id: "1") get "/projects/1/companies/1/avatar" assert_equal "avatar#show", @response.body - assert_equal "/projects/1/companies/1/avatar", project_company_avatar_path(:project_id => "1", :company_id => "1") + assert_equal "/projects/1/companies/1/avatar", project_company_avatar_path(project_id: "1", company_id: "1") end def test_project_manager draw do resources :projects do - resource :manager, :as => :super_manager do + resource :manager, as: :super_manager do post :fire end end @@ -705,37 +705,37 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest get "/projects/1/manager" assert_equal "managers#show", @response.body - assert_equal "/projects/1/manager", project_super_manager_path(:project_id => "1") + assert_equal "/projects/1/manager", project_super_manager_path(project_id: "1") get "/projects/1/manager/new" assert_equal "managers#new", @response.body - assert_equal "/projects/1/manager/new", new_project_super_manager_path(:project_id => "1") + assert_equal "/projects/1/manager/new", new_project_super_manager_path(project_id: "1") post "/projects/1/manager/fire" assert_equal "managers#fire", @response.body - assert_equal "/projects/1/manager/fire", fire_project_super_manager_path(:project_id => "1") + assert_equal "/projects/1/manager/fire", fire_project_super_manager_path(project_id: "1") end def test_project_images draw do resources :projects do - resources :images, :as => :funny_images do - post :revise, :on => :member + resources :images, as: :funny_images do + post :revise, on: :member end end end get "/projects/1/images" assert_equal "images#index", @response.body - assert_equal "/projects/1/images", project_funny_images_path(:project_id => "1") + assert_equal "/projects/1/images", project_funny_images_path(project_id: "1") get "/projects/1/images/new" assert_equal "images#new", @response.body - assert_equal "/projects/1/images/new", new_project_funny_image_path(:project_id => "1") + assert_equal "/projects/1/images/new", new_project_funny_image_path(project_id: "1") post "/projects/1/images/1/revise" assert_equal "images#revise", @response.body - assert_equal "/projects/1/images/1/revise", revise_project_funny_image_path(:project_id => "1", :id => "1") + assert_equal "/projects/1/images/1/revise", revise_project_funny_image_path(project_id: "1", id: "1") end def test_projects_people @@ -758,35 +758,35 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest get "/projects/1/people" assert_equal "people#index", @response.body - assert_equal "/projects/1/people", project_people_path(:project_id => "1") + assert_equal "/projects/1/people", project_people_path(project_id: "1") get "/projects/1/people/1" assert_equal "people#show", @response.body - assert_equal "/projects/1/people/1", project_person_path(:project_id => "1", :id => "1") + assert_equal "/projects/1/people/1", project_person_path(project_id: "1", id: "1") get "/projects/1/people/1/7a2dec8/avatar" assert_equal "avatars#show", @response.body - assert_equal "/projects/1/people/1/7a2dec8/avatar", project_person_avatar_path(:project_id => "1", :person_id => "1", :access_token => "7a2dec8") + assert_equal "/projects/1/people/1/7a2dec8/avatar", project_person_avatar_path(project_id: "1", person_id: "1", access_token: "7a2dec8") put "/projects/1/people/1/accessible_projects" assert_equal "people#accessible_projects", @response.body - assert_equal "/projects/1/people/1/accessible_projects", accessible_projects_project_person_path(:project_id => "1", :id => "1") + assert_equal "/projects/1/people/1/accessible_projects", accessible_projects_project_person_path(project_id: "1", id: "1") post "/projects/1/people/1/resend" assert_equal "people#resend", @response.body - assert_equal "/projects/1/people/1/resend", resend_project_person_path(:project_id => "1", :id => "1") + assert_equal "/projects/1/people/1/resend", resend_project_person_path(project_id: "1", id: "1") post "/projects/1/people/1/generate_new_password" assert_equal "people#generate_new_password", @response.body - assert_equal "/projects/1/people/1/generate_new_password", generate_new_password_project_person_path(:project_id => "1", :id => "1") + assert_equal "/projects/1/people/1/generate_new_password", generate_new_password_project_person_path(project_id: "1", id: "1") end def test_projects_with_resources_path_names draw do - resources_path_names :correlation_indexes => "info_about_correlation_indexes" + resources_path_names correlation_indexes: "info_about_correlation_indexes" resources :projects do - get :correlation_indexes, :on => :collection + get :correlation_indexes, on: :collection end end @@ -799,13 +799,13 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest draw do resources :projects do resources :posts do - get :archive, :toggle_view, :on => :collection - post :preview, :on => :member + get :archive, :toggle_view, on: :collection + post :preview, on: :member resource :subscription resources :comments do - post :preview, :on => :collection + post :preview, on: :collection end end end @@ -813,39 +813,39 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest get "/projects/1/posts" assert_equal "posts#index", @response.body - assert_equal "/projects/1/posts", project_posts_path(:project_id => "1") + assert_equal "/projects/1/posts", project_posts_path(project_id: "1") get "/projects/1/posts/archive" assert_equal "posts#archive", @response.body - assert_equal "/projects/1/posts/archive", archive_project_posts_path(:project_id => "1") + assert_equal "/projects/1/posts/archive", archive_project_posts_path(project_id: "1") get "/projects/1/posts/toggle_view" assert_equal "posts#toggle_view", @response.body - assert_equal "/projects/1/posts/toggle_view", toggle_view_project_posts_path(:project_id => "1") + assert_equal "/projects/1/posts/toggle_view", toggle_view_project_posts_path(project_id: "1") post "/projects/1/posts/1/preview" assert_equal "posts#preview", @response.body - assert_equal "/projects/1/posts/1/preview", preview_project_post_path(:project_id => "1", :id => "1") + assert_equal "/projects/1/posts/1/preview", preview_project_post_path(project_id: "1", id: "1") get "/projects/1/posts/1/subscription" assert_equal "subscriptions#show", @response.body - assert_equal "/projects/1/posts/1/subscription", project_post_subscription_path(:project_id => "1", :post_id => "1") + assert_equal "/projects/1/posts/1/subscription", project_post_subscription_path(project_id: "1", post_id: "1") get "/projects/1/posts/1/comments" assert_equal "comments#index", @response.body - assert_equal "/projects/1/posts/1/comments", project_post_comments_path(:project_id => "1", :post_id => "1") + assert_equal "/projects/1/posts/1/comments", project_post_comments_path(project_id: "1", post_id: "1") post "/projects/1/posts/1/comments/preview" assert_equal "comments#preview", @response.body - assert_equal "/projects/1/posts/1/comments/preview", preview_project_post_comments_path(:project_id => "1", :post_id => "1") + assert_equal "/projects/1/posts/1/comments/preview", preview_project_post_comments_path(project_id: "1", post_id: "1") end def test_replies draw do resources :replies do member do - put :answer, :action => :mark_as_answer - delete :answer, :action => :unmark_as_answer + put :answer, action: :mark_as_answer + delete :answer, action: :unmark_as_answer end end end @@ -859,8 +859,8 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest def test_resource_routes_with_only_and_except draw do - resources :posts, :only => [:index, :show] do - resources :comments, :except => :destroy + resources :posts, only: [:index, :show] do + resources :comments, except: :destroy end end @@ -870,11 +870,11 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest get "/posts/1" assert_equal "posts#show", @response.body - assert_equal "/posts/1", post_path(:id => 1) + assert_equal "/posts/1", post_path(id: 1) get "/posts/1/comments" assert_equal "comments#index", @response.body - assert_equal "/posts/1/comments", post_comments_path(:post_id => 1) + assert_equal "/posts/1/comments", post_comments_path(post_id: 1) post "/posts" assert_equal "pass", @response.headers["X-Cascade"] @@ -888,9 +888,9 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest def test_resource_routes_only_create_update_destroy draw do - resource :past, :only => :destroy - resource :present, :only => :update - resource :future, :only => :create + resource :past, only: :destroy + resource :present, only: :update + resource :future, only: :create end delete "/past" @@ -912,8 +912,8 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest def test_resources_routes_only_create_update_destroy draw do - resources :relationships, :only => [:create, :destroy] - resources :friendships, :only => [:update] + resources :relationships, only: [:create, :destroy] + resources :friendships, only: [:update] end post "/relationships" @@ -940,13 +940,13 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest get "/posts/rails-rocks" assert_equal "posts#show", @response.body - assert_equal "/posts/rails-rocks", post_path(:id => "rails-rocks") + assert_equal "/posts/rails-rocks", post_path(id: "rails-rocks") end def test_resources_for_uncountable_names draw do resources :sheep do - get "_it", :on => :member + get "_it", on: :member end end @@ -958,23 +958,23 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest end def test_resource_does_not_modify_passed_options - options = {:id => /.+?/, :format => /json|xml/} + options = {id: /.+?/, format: /json|xml/} draw { resource :user, options } - assert_equal({:id => /.+?/, :format => /json|xml/}, options) + assert_equal({id: /.+?/, format: /json|xml/}, options) end def test_resources_does_not_modify_passed_options - options = {:id => /.+?/, :format => /json|xml/} + options = {id: /.+?/, format: /json|xml/} draw { resources :users, options } - assert_equal({:id => /.+?/, :format => /json|xml/}, options) + assert_equal({id: /.+?/, format: /json|xml/}, options) end def test_path_names draw do - scope "pt", :as => "pt" do - resources :projects, :path_names => { :edit => "editar", :new => "novo" }, :path => "projetos" - resource :admin, :path_names => { :new => "novo", :activate => "ativar" }, :path => "administrador" do - put :activate, :on => :member + scope "pt", as: "pt" do + resources :projects, path_names: { edit: "editar", new: "novo" }, path: "projetos" + resource :admin, path_names: { new: "novo", activate: "ativar" }, path: "administrador" do + put :activate, on: :member end end end @@ -1002,10 +1002,10 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest def test_path_option_override draw do - scope "pt", :as => "pt" do - resources :projects, :path_names => { :new => "novo" }, :path => "projetos" do - put :close, :on => :member, :path => "fechar" - get :open, :on => :new, :path => "abrir" + scope "pt", as: "pt" do + resources :projects, path_names: { new: "novo" }, path: "projetos" do + put :close, on: :member, path: "fechar" + get :open, on: :new, path: "abrir" end end end @@ -1030,30 +1030,30 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest def test_update_person_route draw do - get "people/:id/update", :to => "people#update", :as => :update_person + get "people/:id/update", to: "people#update", as: :update_person end get "/people/1/update" assert_equal "people#update", @response.body - assert_equal "/people/1/update", update_person_path(:id => 1) + assert_equal "/people/1/update", update_person_path(id: 1) end def test_update_project_person draw do - get "/projects/:project_id/people/:id/update", :to => "people#update", :as => :update_project_person + get "/projects/:project_id/people/:id/update", to: "people#update", as: :update_project_person end get "/projects/1/people/2/update" assert_equal "people#update", @response.body - assert_equal "/projects/1/people/2/update", update_project_person_path(:project_id => 1, :id => 2) + assert_equal "/projects/1/people/2/update", update_project_person_path(project_id: 1, id: 2) end def test_forum_products draw do namespace :forum do - resources :products, :path => "" do + resources :products, path: "" do resources :questions end end @@ -1065,26 +1065,26 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest get "/forum/basecamp" assert_equal "forum/products#show", @response.body - assert_equal "/forum/basecamp", forum_product_path(:id => "basecamp") + assert_equal "/forum/basecamp", forum_product_path(id: "basecamp") get "/forum/basecamp/questions" assert_equal "forum/questions#index", @response.body - assert_equal "/forum/basecamp/questions", forum_product_questions_path(:product_id => "basecamp") + assert_equal "/forum/basecamp/questions", forum_product_questions_path(product_id: "basecamp") get "/forum/basecamp/questions/1" assert_equal "forum/questions#show", @response.body - assert_equal "/forum/basecamp/questions/1", forum_product_question_path(:product_id => "basecamp", :id => 1) + assert_equal "/forum/basecamp/questions/1", forum_product_question_path(product_id: "basecamp", id: 1) end def test_articles_perma draw do - get "articles/:year/:month/:day/:title", :to => "articles#show", :as => :article + get "articles/:year/:month/:day/:title", to: "articles#show", as: :article end get "/articles/2009/08/18/rails-3" assert_equal "articles#show", @response.body - assert_equal "/articles/2009/8/18/rails-3", article_path(:year => 2009, :month => 8, :day => 18, :title => "rails-3") + assert_equal "/articles/2009/8/18/rails-3", article_path(year: 2009, month: 8, day: 18, title: "rails-3") end def test_account_namespace @@ -1145,8 +1145,8 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest def test_namespace_with_options draw do - namespace :users, :path => "usuarios" do - root :to => "home#index" + namespace :users, path: "usuarios" do + root to: "home#index" end end @@ -1300,9 +1300,9 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest def test_articles_with_id draw do controller :articles do - scope "/articles", :as => "article" do - scope :path => "/:title", :title => /[a-z]+/, :as => :with_title do - get "/:id", :action => :with_id, :as => "" + scope "/articles", as: "article" do + scope path: "/:title", title: /[a-z]+/, as: :with_title do + get "/:id", action: :with_id, as: "" end end end @@ -1314,12 +1314,12 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest get "/articles/123/1" assert_equal "pass", @response.headers["X-Cascade"] - assert_equal "/articles/rails/1", article_with_title_path(:title => "rails", :id => 1) + assert_equal "/articles/rails/1", article_with_title_path(title: "rails", id: 1) end def test_access_token_rooms draw do - scope ":access_token", :constraints => { :access_token => /\w{5,5}/ } do + scope ":access_token", constraints: { access_token: /\w{5,5}/ } do resources :rooms end end @@ -1336,7 +1336,7 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest def test_root draw do - root :to => "projects#index" + root to: "projects#index" end assert_equal "/", root_path @@ -1346,24 +1346,24 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest def test_scoped_root draw do - scope "(:locale)", :locale => /en|pl/ do - root :to => "projects#index" + scope "(:locale)", locale: /en|pl/ do + root to: "projects#index" end end - assert_equal "/en", root_path(:locale => "en") + assert_equal "/en", root_path(locale: "en") get "/en" assert_equal "projects#index", @response.body end def test_scoped_root_as_name draw do - scope "(:locale)", :locale => /en|pl/ do - root :to => "projects#index", :as => "projects" + scope "(:locale)", locale: /en|pl/ do + root to: "projects#index", as: "projects" end end - assert_equal "/en", projects_path(:locale => "en") + assert_equal "/en", projects_path(locale: "en") assert_equal "/", projects_path get "/en" assert_equal "projects#index", @response.body @@ -1432,7 +1432,7 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest def test_match_with_many_paths_containing_a_slash draw do - get "get/first", "get/second", "get/third", :to => "get#show" + get "get/first", "get/second", "get/third", to: "get#show" end get "/get/first" @@ -1561,7 +1561,7 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest draw do namespace :account do ActiveSupport::Deprecation.silence do - get ":action/callback", :action => /twitter|github/, :controller => "callbacks", :as => :callback + get ":action/callback", action: /twitter|github/, controller: "callbacks", as: :callback end end end @@ -1596,7 +1596,7 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest def test_redirect_with_complete_url_and_status draw do - get "account/google" => redirect("http://www.google.com/", :status => 302) + get "account/google" => redirect("http://www.google.com/", status: 302) end get "/account/google" @@ -1605,7 +1605,7 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest def test_redirect_with_port draw do - get "account/login", :to => redirect("/login") + get "account/login", to: redirect("/login") end previous_host, self.host = self.host, "www.example.com:3000" @@ -1619,7 +1619,7 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest def test_normalize_namespaced_matches draw do namespace :account do - get "description", :action => :description, :as => "description" + get "description", action: :description, as: "description" end end @@ -1632,7 +1632,7 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest def test_namespaced_roots draw do namespace :account do - root :to => "account#index" + root to: "account#index" end end @@ -1643,8 +1643,8 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest def test_optional_scoped_root draw do - scope "(:locale)", :locale => /en|pl/ do - root :to => "projects#index" + scope "(:locale)", locale: /en|pl/ do + root to: "projects#index" end end @@ -1655,7 +1655,7 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest def test_optional_scoped_path draw do - scope "(:locale)", :locale => /en|pl/ do + scope "(:locale)", locale: /en|pl/ do resources :descriptions end end @@ -1681,7 +1681,7 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest def test_nested_optional_scoped_path draw do namespace :admin do - scope "(:locale)", :locale => /en|pl/ do + scope "(:locale)", locale: /en|pl/ do resources :descriptions end end @@ -1707,7 +1707,7 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest def test_nested_optional_path_shorthand draw do - scope "(:locale)", :locale => /en|pl/ do + scope "(:locale)", locale: /en|pl/ do get "registrations/new" end end @@ -1721,11 +1721,11 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest def test_default_string_params draw do - get "inline_pages/(:id)", :to => "pages#show", :id => "home" - get "default_pages/(:id)", :to => "pages#show", :defaults => { :id => "home" } + get "inline_pages/(:id)", to: "pages#show", id: "home" + get "default_pages/(:id)", to: "pages#show", defaults: { id: "home" } - defaults :id => "home" do - get "scoped_pages/(:id)", :to => "pages#show" + defaults id: "home" do + get "scoped_pages/(:id)", to: "pages#show" end end @@ -1779,13 +1779,13 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest def test_resource_constraints draw do - resources :products, :constraints => { :id => /\d{4}/ } do - root :to => "products#root" - get :favorite, :on => :collection + resources :products, constraints: { id: /\d{4}/ } do + root to: "products#root" + get :favorite, on: :collection resources :images end - resource :dashboard, :constraints => { :ip => /192\.168\.1\.\d{1,3}/ } + resource :dashboard, constraints: { ip: /192\.168\.1\.\d{1,3}/ } end get "/products/1" @@ -1813,7 +1813,7 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest def test_root_works_in_the_resources_scope draw do resources :products do - root :to => "products#root" + root to: "products#root" end end @@ -1824,7 +1824,7 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest def test_module_scope draw do - resource :token, :module => :api + resource :token, module: :api end get "/token" @@ -1834,7 +1834,7 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest def test_path_scope draw do - scope :path => "api" do + scope path: "api" do resource :me get "/" => "mes#index" end @@ -1850,7 +1850,7 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest def test_symbol_scope draw do - scope :path => "api" do + scope path: "api" do scope :v2 do resource :me, as: "v2_me" get "/" => "mes#index" @@ -1884,13 +1884,13 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest assert_equal "foo#bar", @response.body assert_equal "http://www.example.com/whatever/foo/bar/1", - url_for(:controller => "foo", :action => "bar", :id => 1) + url_for(controller: "foo", action: "bar", id: 1) end def test_url_generator_for_namespaced_generic_route draw do ActiveSupport::Deprecation.silence do - get "whatever/:controller(/:action(/:id))", :id => /\d+/ + get "whatever/:controller(/:action(/:id))", id: /\d+/ end end @@ -1901,10 +1901,10 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest assert_equal "foo/bar#show", @response.body assert_equal "http://www.example.com/whatever/foo/bar/show", - url_for(:controller => "foo/bar", :action => "show") + url_for(controller: "foo/bar", action: "show") assert_equal "http://www.example.com/whatever/foo/bar/show/1", - url_for(:controller => "foo/bar", :action => "show", :id => "1") + url_for(controller: "foo/bar", action: "show", id: "1") end def test_resource_new_actions @@ -1915,16 +1915,16 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest end end - scope "pt", :as => "pt" do - resources :projects, :path_names => { :new => "novo" }, :path => "projetos" do - post :preview, :on => :new + scope "pt", as: "pt" do + resources :projects, path_names: { new: "novo" }, path: "projetos" do + post :preview, on: :new end - resource :admin, :path_names => { :new => "novo" }, :path => "administrador" do - post :preview, :on => :new + resource :admin, path_names: { new: "novo" }, path: "administrador" do + post :preview, on: :new end - resources :products, :path_names => { :new => "novo" } do + resources :products, path_names: { new: "novo" } do new do post :preview end @@ -1962,7 +1962,7 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest def test_resource_merges_options_from_scope draw do - scope :only => :show do + scope only: :show do resource :account end end @@ -1975,7 +1975,7 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest def test_resources_merges_options_from_scope draw do - scope :only => [:index, :show] do + scope only: [:index, :show] do resources :products do resources :images end @@ -2004,7 +2004,7 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest end end - resources :threads, :shallow => true do + resources :threads, shallow: true do resource :owner resources :messages do resources :comments do @@ -2026,39 +2026,39 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest get "/api/teams/1" assert_equal "api/teams#show", @response.body - assert_equal "/api/teams/1", api_team_path(:id => "1") + assert_equal "/api/teams/1", api_team_path(id: "1") get "/api/teams/1/edit" assert_equal "api/teams#edit", @response.body - assert_equal "/api/teams/1/edit", edit_api_team_path(:id => "1") + assert_equal "/api/teams/1/edit", edit_api_team_path(id: "1") get "/api/teams/1/players" assert_equal "api/players#index", @response.body - assert_equal "/api/teams/1/players", api_team_players_path(:team_id => "1") + assert_equal "/api/teams/1/players", api_team_players_path(team_id: "1") get "/api/teams/1/players/new" assert_equal "api/players#new", @response.body - assert_equal "/api/teams/1/players/new", new_api_team_player_path(:team_id => "1") + assert_equal "/api/teams/1/players/new", new_api_team_player_path(team_id: "1") get "/api/players/2" assert_equal "api/players#show", @response.body - assert_equal "/api/players/2", api_player_path(:id => "2") + assert_equal "/api/players/2", api_player_path(id: "2") get "/api/players/2/edit" assert_equal "api/players#edit", @response.body - assert_equal "/api/players/2/edit", edit_api_player_path(:id => "2") + assert_equal "/api/players/2/edit", edit_api_player_path(id: "2") get "/api/teams/1/captain" assert_equal "api/captains#show", @response.body - assert_equal "/api/teams/1/captain", api_team_captain_path(:team_id => "1") + assert_equal "/api/teams/1/captain", api_team_captain_path(team_id: "1") get "/api/teams/1/captain/new" assert_equal "api/captains#new", @response.body - assert_equal "/api/teams/1/captain/new", new_api_team_captain_path(:team_id => "1") + assert_equal "/api/teams/1/captain/new", new_api_team_captain_path(team_id: "1") get "/api/teams/1/captain/edit" assert_equal "api/captains#edit", @response.body - assert_equal "/api/teams/1/captain/edit", edit_api_team_captain_path(:team_id => "1") + assert_equal "/api/teams/1/captain/edit", edit_api_team_captain_path(team_id: "1") get "/threads" assert_equal "threads#index", @response.body @@ -2070,51 +2070,51 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest get "/threads/1" assert_equal "threads#show", @response.body - assert_equal "/threads/1", thread_path(:id => "1") + assert_equal "/threads/1", thread_path(id: "1") get "/threads/1/edit" assert_equal "threads#edit", @response.body - assert_equal "/threads/1/edit", edit_thread_path(:id => "1") + assert_equal "/threads/1/edit", edit_thread_path(id: "1") get "/threads/1/owner" assert_equal "owners#show", @response.body - assert_equal "/threads/1/owner", thread_owner_path(:thread_id => "1") + assert_equal "/threads/1/owner", thread_owner_path(thread_id: "1") get "/threads/1/messages" assert_equal "messages#index", @response.body - assert_equal "/threads/1/messages", thread_messages_path(:thread_id => "1") + assert_equal "/threads/1/messages", thread_messages_path(thread_id: "1") get "/threads/1/messages/new" assert_equal "messages#new", @response.body - assert_equal "/threads/1/messages/new", new_thread_message_path(:thread_id => "1") + assert_equal "/threads/1/messages/new", new_thread_message_path(thread_id: "1") get "/messages/2" assert_equal "messages#show", @response.body - assert_equal "/messages/2", message_path(:id => "2") + assert_equal "/messages/2", message_path(id: "2") get "/messages/2/edit" assert_equal "messages#edit", @response.body - assert_equal "/messages/2/edit", edit_message_path(:id => "2") + assert_equal "/messages/2/edit", edit_message_path(id: "2") get "/messages/2/comments" assert_equal "comments#index", @response.body - assert_equal "/messages/2/comments", message_comments_path(:message_id => "2") + assert_equal "/messages/2/comments", message_comments_path(message_id: "2") get "/messages/2/comments/new" assert_equal "comments#new", @response.body - assert_equal "/messages/2/comments/new", new_message_comment_path(:message_id => "2") + assert_equal "/messages/2/comments/new", new_message_comment_path(message_id: "2") get "/comments/3" assert_equal "comments#show", @response.body - assert_equal "/comments/3", comment_path(:id => "3") + assert_equal "/comments/3", comment_path(id: "3") get "/comments/3/edit" assert_equal "comments#edit", @response.body - assert_equal "/comments/3/edit", edit_comment_path(:id => "3") + assert_equal "/comments/3/edit", edit_comment_path(id: "3") post "/comments/3/preview" assert_equal "comments#preview", @response.body - assert_equal "/comments/3/preview", preview_comment_path(:id => "3") + assert_equal "/comments/3/preview", preview_comment_path(id: "3") end def test_shallow_nested_resources_inside_resource @@ -2167,8 +2167,8 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest assert_equal "/comments/1", comment_path("1") assert_equal "/blogs/new", new_blog_path - assert_equal "/blogs/1/posts/new", new_blog_post_path(:blog_id => 1) - assert_equal "/blogs/1/posts/2/comments/new", new_blog_post_comment_path(:blog_id => 1, :post_id => 2) + assert_equal "/blogs/1/posts/new", new_blog_post_path(blog_id: 1) + assert_equal "/blogs/1/posts/2/comments/new", new_blog_post_comment_path(blog_id: 1, post_id: 2) end def test_direct_children_of_shallow_resources @@ -2206,23 +2206,23 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest get "/hello/notes/1/trackbacks" assert_equal "trackbacks#index", @response.body - assert_equal "/hello/notes/1/trackbacks", note_trackbacks_path(:note_id => 1) + assert_equal "/hello/notes/1/trackbacks", note_trackbacks_path(note_id: 1) get "/hello/notes/1/edit" assert_equal "notes#edit", @response.body - assert_equal "/hello/notes/1/edit", edit_note_path(:id => "1") + assert_equal "/hello/notes/1/edit", edit_note_path(id: "1") get "/hello/notes/1/trackbacks/new" assert_equal "trackbacks#new", @response.body - assert_equal "/hello/notes/1/trackbacks/new", new_note_trackback_path(:note_id => 1) + assert_equal "/hello/notes/1/trackbacks/new", new_note_trackback_path(note_id: 1) get "/hello/trackbacks/1" assert_equal "trackbacks#show", @response.body - assert_equal "/hello/trackbacks/1", trackback_path(:id => "1") + assert_equal "/hello/trackbacks/1", trackback_path(id: "1") get "/hello/trackbacks/1/edit" assert_equal "trackbacks#edit", @response.body - assert_equal "/hello/trackbacks/1/edit", edit_trackback_path(:id => "1") + assert_equal "/hello/trackbacks/1/edit", edit_trackback_path(id: "1") put "/hello/trackbacks/1" assert_equal "trackbacks#update", @response.body @@ -2245,7 +2245,7 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest get "/hello/notes/1" assert_equal "notes#show", @response.body - assert_equal "/hello/notes/1", note_path(:id => 1) + assert_equal "/hello/notes/1", note_path(id: 1) put "/hello/notes/1" assert_equal "notes#update", @response.body @@ -2257,7 +2257,7 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest def test_shallow_option_nested_resources_within_scope draw do scope "/hello" do - resources :notes, :shallow => true do + resources :notes, shallow: true do resources :trackbacks end end @@ -2265,23 +2265,23 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest get "/hello/notes/1/trackbacks" assert_equal "trackbacks#index", @response.body - assert_equal "/hello/notes/1/trackbacks", note_trackbacks_path(:note_id => 1) + assert_equal "/hello/notes/1/trackbacks", note_trackbacks_path(note_id: 1) get "/hello/notes/1/edit" assert_equal "notes#edit", @response.body - assert_equal "/hello/notes/1/edit", edit_note_path(:id => "1") + assert_equal "/hello/notes/1/edit", edit_note_path(id: "1") get "/hello/notes/1/trackbacks/new" assert_equal "trackbacks#new", @response.body - assert_equal "/hello/notes/1/trackbacks/new", new_note_trackback_path(:note_id => 1) + assert_equal "/hello/notes/1/trackbacks/new", new_note_trackback_path(note_id: 1) get "/hello/trackbacks/1" assert_equal "trackbacks#show", @response.body - assert_equal "/hello/trackbacks/1", trackback_path(:id => "1") + assert_equal "/hello/trackbacks/1", trackback_path(id: "1") get "/hello/trackbacks/1/edit" assert_equal "trackbacks#edit", @response.body - assert_equal "/hello/trackbacks/1/edit", edit_trackback_path(:id => "1") + assert_equal "/hello/trackbacks/1/edit", edit_trackback_path(id: "1") put "/hello/trackbacks/1" assert_equal "trackbacks#update", @response.body @@ -2304,7 +2304,7 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest get "/hello/notes/1" assert_equal "notes#show", @response.body - assert_equal "/hello/notes/1", note_path(:id => 1) + assert_equal "/hello/notes/1", note_path(id: 1) put "/hello/notes/1" assert_equal "notes#update", @response.body @@ -2316,8 +2316,8 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest def test_custom_resource_routes_are_scoped draw do resources :customers do - get :recent, :on => :collection - get "profile", :on => :member + get :recent, on: :collection + get "profile", on: :member get "secret/profile" => "customers#secret", :on => :member post "preview" => "customers#preview", :as => :another_preview, :on => :new resource :avatar do @@ -2325,11 +2325,11 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest end resources :invoices do get "outstanding" => "invoices#outstanding", :on => :collection - get "overdue", :action => :overdue, :on => :collection + get "overdue", action: :overdue, on: :collection get "print" => "invoices#print", :as => :print, :on => :member post "preview" => "invoices#preview", :as => :preview, :on => :new end - resources :notes, :shallow => true do + resources :notes, shallow: true do get "preview" => "notes#preview", :as => :preview, :on => :new get "print" => "notes#print", :as => :print, :on => :member end @@ -2345,17 +2345,17 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest end assert_equal "/customers/recent", recent_customers_path - assert_equal "/customers/1/profile", profile_customer_path(:id => "1") - assert_equal "/customers/1/secret/profile", secret_profile_customer_path(:id => "1") + assert_equal "/customers/1/profile", profile_customer_path(id: "1") + assert_equal "/customers/1/secret/profile", secret_profile_customer_path(id: "1") assert_equal "/customers/new/preview", another_preview_new_customer_path - assert_equal "/customers/1/avatar/thumbnail.jpg", thumbnail_customer_avatar_path(:customer_id => "1", :format => :jpg) - assert_equal "/customers/1/invoices/outstanding", outstanding_customer_invoices_path(:customer_id => "1") - assert_equal "/customers/1/invoices/2/print", print_customer_invoice_path(:customer_id => "1", :id => "2") - assert_equal "/customers/1/invoices/new/preview", preview_new_customer_invoice_path(:customer_id => "1") - assert_equal "/customers/1/notes/new/preview", preview_new_customer_note_path(:customer_id => "1") - assert_equal "/notes/1/print", print_note_path(:id => "1") + assert_equal "/customers/1/avatar/thumbnail.jpg", thumbnail_customer_avatar_path(customer_id: "1", format: :jpg) + assert_equal "/customers/1/invoices/outstanding", outstanding_customer_invoices_path(customer_id: "1") + assert_equal "/customers/1/invoices/2/print", print_customer_invoice_path(customer_id: "1", id: "2") + assert_equal "/customers/1/invoices/new/preview", preview_new_customer_invoice_path(customer_id: "1") + assert_equal "/customers/1/notes/new/preview", preview_new_customer_note_path(customer_id: "1") + assert_equal "/notes/1/print", print_note_path(id: "1") assert_equal "/api/customers/recent", recent_api_customers_path - assert_equal "/api/customers/1/profile", profile_api_customer_path(:id => "1") + assert_equal "/api/customers/1/profile", profile_api_customer_path(id: "1") assert_equal "/api/customers/new/preview", preview_new_api_customer_path get "/customers/1/invoices/overdue" @@ -2367,8 +2367,8 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest def test_shallow_nested_routes_ignore_module draw do - scope :module => :api do - resources :errors, :shallow => true do + scope module: :api do + resources :errors, shallow: true do resources :notices end end @@ -2376,47 +2376,47 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest get "/errors/1/notices" assert_equal "api/notices#index", @response.body - assert_equal "/errors/1/notices", error_notices_path(:error_id => "1") + assert_equal "/errors/1/notices", error_notices_path(error_id: "1") get "/notices/1" assert_equal "api/notices#show", @response.body - assert_equal "/notices/1", notice_path(:id => "1") + assert_equal "/notices/1", notice_path(id: "1") end def test_non_greedy_regexp draw do namespace :api do - scope(":version", :version => /.+/) do - resources :users, :id => /.+?/, :format => /json|xml/ + scope(":version", version: /.+/) do + resources :users, id: /.+?/, format: /json|xml/ end end end get "/api/1.0/users" assert_equal "api/users#index", @response.body - assert_equal "/api/1.0/users", api_users_path(:version => "1.0") + assert_equal "/api/1.0/users", api_users_path(version: "1.0") get "/api/1.0/users.json" assert_equal "api/users#index", @response.body assert_equal true, @request.format.json? - assert_equal "/api/1.0/users.json", api_users_path(:version => "1.0", :format => :json) + assert_equal "/api/1.0/users.json", api_users_path(version: "1.0", format: :json) get "/api/1.0/users/first.last" assert_equal "api/users#show", @response.body assert_equal "first.last", @request.params[:id] - assert_equal "/api/1.0/users/first.last", api_user_path(:version => "1.0", :id => "first.last") + assert_equal "/api/1.0/users/first.last", api_user_path(version: "1.0", id: "first.last") get "/api/1.0/users/first.last.xml" assert_equal "api/users#show", @response.body assert_equal "first.last", @request.params[:id] assert_equal true, @request.format.xml? - assert_equal "/api/1.0/users/first.last.xml", api_user_path(:version => "1.0", :id => "first.last", :format => :xml) + assert_equal "/api/1.0/users/first.last.xml", api_user_path(version: "1.0", id: "first.last", format: :xml) end def test_match_without_via assert_raises(ArgumentError) do draw do - match "/foo/bar", :to => "files#show" + match "/foo/bar", to: "files#show" end end end @@ -2424,14 +2424,14 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest def test_match_with_empty_via assert_raises(ArgumentError) do draw do - match "/foo/bar", :to => "files#show", :via => [] + match "/foo/bar", to: "files#show", via: [] end end end def test_glob_parameter_accepts_regexp draw do - get "/:locale/*file.:format", :to => "files#show", :file => /path\/to\/existing\/file/ + get "/:locale/*file.:format", to: "files#show", file: /path\/to\/existing\/file/ end get "/en/path/to/existing/file.html" @@ -2455,12 +2455,12 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest get "/bob/followers" assert_equal "followers#index", @response.body assert_equal "http://www.example.com/bob/followers", - url_for(:controller => "followers", :action => "index", :username => "bob") + url_for(controller: "followers", action: "index", username: "bob") get "/followers" assert_equal "followers#index", @response.body assert_equal "http://www.example.com/followers", - url_for(:controller => "followers", :action => "index", :username => nil) + url_for(controller: "followers", action: "index", username: nil) end def test_url_generator_for_optional_suffix_static_and_dynamic_segment @@ -2471,12 +2471,12 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest get "/groups/user/bob" assert_equal "groups#index", @response.body assert_equal "http://www.example.com/groups/user/bob", - url_for(:controller => "groups", :action => "index", :username => "bob") + url_for(controller: "groups", action: "index", username: "bob") get "/groups" assert_equal "groups#index", @response.body assert_equal "http://www.example.com/groups", - url_for(:controller => "groups", :action => "index", :username => nil) + url_for(controller: "groups", action: "index", username: nil) end def test_url_generator_for_optional_prefix_static_and_dynamic_segment @@ -2487,12 +2487,12 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest get "/user/bob/photos" assert_equal "photos#index", @response.body assert_equal "http://www.example.com/user/bob/photos", - url_for(:controller => "photos", :action => "index", :username => "bob") + url_for(controller: "photos", action: "index", username: "bob") get "/photos" assert_equal "photos#index", @response.body assert_equal "http://www.example.com/photos", - url_for(:controller => "photos", :action => "index", :username => nil) + url_for(controller: "photos", action: "index", username: nil) end def test_url_recognition_for_optional_static_segments @@ -2531,8 +2531,8 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest def test_router_removes_invalid_conditions draw do - scope :constraints => { :id => /\d+/ } do - get "/tickets", :to => "tickets#index", :as => :tickets + scope constraints: { id: /\d+/ } do + get "/tickets", to: "tickets#index", as: :tickets end end @@ -2543,7 +2543,7 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest def test_constraints_are_merged_from_scope draw do - scope :constraints => { :id => /\d{4}/ } do + scope constraints: { id: /\d{4}/ } do resources :movies do resources :reviews resource :trailer @@ -2553,40 +2553,40 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest get "/movies/0001" assert_equal "movies#show", @response.body - assert_equal "/movies/0001", movie_path(:id => "0001") + assert_equal "/movies/0001", movie_path(id: "0001") get "/movies/00001" assert_equal "Not Found", @response.body - assert_raises(ActionController::UrlGenerationError){ movie_path(:id => "00001") } + assert_raises(ActionController::UrlGenerationError){ movie_path(id: "00001") } get "/movies/0001/reviews" assert_equal "reviews#index", @response.body - assert_equal "/movies/0001/reviews", movie_reviews_path(:movie_id => "0001") + assert_equal "/movies/0001/reviews", movie_reviews_path(movie_id: "0001") get "/movies/00001/reviews" assert_equal "Not Found", @response.body - assert_raises(ActionController::UrlGenerationError){ movie_reviews_path(:movie_id => "00001") } + assert_raises(ActionController::UrlGenerationError){ movie_reviews_path(movie_id: "00001") } get "/movies/0001/reviews/0001" assert_equal "reviews#show", @response.body - assert_equal "/movies/0001/reviews/0001", movie_review_path(:movie_id => "0001", :id => "0001") + assert_equal "/movies/0001/reviews/0001", movie_review_path(movie_id: "0001", id: "0001") get "/movies/00001/reviews/0001" assert_equal "Not Found", @response.body - assert_raises(ActionController::UrlGenerationError){ movie_path(:movie_id => "00001", :id => "00001") } + assert_raises(ActionController::UrlGenerationError){ movie_path(movie_id: "00001", id: "00001") } get "/movies/0001/trailer" assert_equal "trailers#show", @response.body - assert_equal "/movies/0001/trailer", movie_trailer_path(:movie_id => "0001") + assert_equal "/movies/0001/trailer", movie_trailer_path(movie_id: "0001") get "/movies/00001/trailer" assert_equal "Not Found", @response.body - assert_raises(ActionController::UrlGenerationError){ movie_trailer_path(:movie_id => "00001") } + assert_raises(ActionController::UrlGenerationError){ movie_trailer_path(movie_id: "00001") } end def test_only_should_be_read_from_scope draw do - scope :only => [:index, :show] do + scope only: [:index, :show] do namespace :only do resources :clubs do resources :players @@ -2602,28 +2602,28 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest get "/only/clubs/1/edit" assert_equal "Not Found", @response.body - assert_raise(NoMethodError) { edit_only_club_path(:id => "1") } + assert_raise(NoMethodError) { edit_only_club_path(id: "1") } get "/only/clubs/1/players" assert_equal "only/players#index", @response.body - assert_equal "/only/clubs/1/players", only_club_players_path(:club_id => "1") + assert_equal "/only/clubs/1/players", only_club_players_path(club_id: "1") get "/only/clubs/1/players/2/edit" assert_equal "Not Found", @response.body - assert_raise(NoMethodError) { edit_only_club_player_path(:club_id => "1", :id => "2") } + assert_raise(NoMethodError) { edit_only_club_player_path(club_id: "1", id: "2") } get "/only/clubs/1/chairman" assert_equal "only/chairmen#show", @response.body - assert_equal "/only/clubs/1/chairman", only_club_chairman_path(:club_id => "1") + assert_equal "/only/clubs/1/chairman", only_club_chairman_path(club_id: "1") get "/only/clubs/1/chairman/edit" assert_equal "Not Found", @response.body - assert_raise(NoMethodError) { edit_only_club_chairman_path(:club_id => "1") } + assert_raise(NoMethodError) { edit_only_club_chairman_path(club_id: "1") } end def test_except_should_be_read_from_scope draw do - scope :except => [:new, :create, :edit, :update, :destroy] do + scope except: [:new, :create, :edit, :update, :destroy] do namespace :except do resources :clubs do resources :players @@ -2639,30 +2639,30 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest get "/except/clubs/1/edit" assert_equal "Not Found", @response.body - assert_raise(NoMethodError) { edit_except_club_path(:id => "1") } + assert_raise(NoMethodError) { edit_except_club_path(id: "1") } get "/except/clubs/1/players" assert_equal "except/players#index", @response.body - assert_equal "/except/clubs/1/players", except_club_players_path(:club_id => "1") + assert_equal "/except/clubs/1/players", except_club_players_path(club_id: "1") get "/except/clubs/1/players/2/edit" assert_equal "Not Found", @response.body - assert_raise(NoMethodError) { edit_except_club_player_path(:club_id => "1", :id => "2") } + assert_raise(NoMethodError) { edit_except_club_player_path(club_id: "1", id: "2") } get "/except/clubs/1/chairman" assert_equal "except/chairmen#show", @response.body - assert_equal "/except/clubs/1/chairman", except_club_chairman_path(:club_id => "1") + assert_equal "/except/clubs/1/chairman", except_club_chairman_path(club_id: "1") get "/except/clubs/1/chairman/edit" assert_equal "Not Found", @response.body - assert_raise(NoMethodError) { edit_except_club_chairman_path(:club_id => "1") } + assert_raise(NoMethodError) { edit_except_club_chairman_path(club_id: "1") } end def test_only_option_should_override_scope draw do - scope :only => :show do + scope only: :show do namespace :only do - resources :sectors, :only => :index + resources :sectors, only: :index end end end @@ -2673,14 +2673,14 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest get "/only/sectors/1" assert_equal "Not Found", @response.body - assert_raise(NoMethodError) { only_sector_path(:id => "1") } + assert_raise(NoMethodError) { only_sector_path(id: "1") } end def test_only_option_should_not_inherit draw do - scope :only => :show do + scope only: :show do namespace :only do - resources :sectors, :only => :index do + resources :sectors, only: :index do resources :companies resource :leader end @@ -2690,18 +2690,18 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest get "/only/sectors/1/companies/2" assert_equal "only/companies#show", @response.body - assert_equal "/only/sectors/1/companies/2", only_sector_company_path(:sector_id => "1", :id => "2") + assert_equal "/only/sectors/1/companies/2", only_sector_company_path(sector_id: "1", id: "2") get "/only/sectors/1/leader" assert_equal "only/leaders#show", @response.body - assert_equal "/only/sectors/1/leader", only_sector_leader_path(:sector_id => "1") + assert_equal "/only/sectors/1/leader", only_sector_leader_path(sector_id: "1") end def test_except_option_should_override_scope draw do - scope :except => :index do + scope except: :index do namespace :except do - resources :sectors, :except => [:show, :update, :destroy] + resources :sectors, except: [:show, :update, :destroy] end end end @@ -2712,14 +2712,14 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest get "/except/sectors/1" assert_equal "Not Found", @response.body - assert_raise(NoMethodError) { except_sector_path(:id => "1") } + assert_raise(NoMethodError) { except_sector_path(id: "1") } end def test_except_option_should_not_inherit draw do - scope :except => :index do + scope except: :index do namespace :except do - resources :sectors, :except => [:show, :update, :destroy] do + resources :sectors, except: [:show, :update, :destroy] do resources :companies resource :leader end @@ -2729,19 +2729,19 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest get "/except/sectors/1/companies/2" assert_equal "except/companies#show", @response.body - assert_equal "/except/sectors/1/companies/2", except_sector_company_path(:sector_id => "1", :id => "2") + assert_equal "/except/sectors/1/companies/2", except_sector_company_path(sector_id: "1", id: "2") get "/except/sectors/1/leader" assert_equal "except/leaders#show", @response.body - assert_equal "/except/sectors/1/leader", except_sector_leader_path(:sector_id => "1") + assert_equal "/except/sectors/1/leader", except_sector_leader_path(sector_id: "1") end def test_except_option_should_override_scoped_only draw do - scope :only => :show do + scope only: :show do namespace :only do - resources :sectors, :only => :index do - resources :managers, :except => [:show, :update, :destroy] + resources :sectors, only: :index do + resources :managers, except: [:show, :update, :destroy] end end end @@ -2749,19 +2749,19 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest get "/only/sectors/1/managers" assert_equal "only/managers#index", @response.body - assert_equal "/only/sectors/1/managers", only_sector_managers_path(:sector_id => "1") + assert_equal "/only/sectors/1/managers", only_sector_managers_path(sector_id: "1") get "/only/sectors/1/managers/2" assert_equal "Not Found", @response.body - assert_raise(NoMethodError) { only_sector_manager_path(:sector_id => "1", :id => "2") } + assert_raise(NoMethodError) { only_sector_manager_path(sector_id: "1", id: "2") } end def test_only_option_should_override_scoped_except draw do - scope :except => :index do + scope except: :index do namespace :except do - resources :sectors, :except => [:show, :update, :destroy] do - resources :managers, :only => :index + resources :sectors, except: [:show, :update, :destroy] do + resources :managers, only: :index end end end @@ -2769,20 +2769,20 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest get "/except/sectors/1/managers" assert_equal "except/managers#index", @response.body - assert_equal "/except/sectors/1/managers", except_sector_managers_path(:sector_id => "1") + assert_equal "/except/sectors/1/managers", except_sector_managers_path(sector_id: "1") get "/except/sectors/1/managers/2" assert_equal "Not Found", @response.body - assert_raise(NoMethodError) { except_sector_manager_path(:sector_id => "1", :id => "2") } + assert_raise(NoMethodError) { except_sector_manager_path(sector_id: "1", id: "2") } end def test_only_scope_should_override_parent_scope draw do - scope :only => :show do + scope only: :show do namespace :only do - resources :sectors, :only => :index do + resources :sectors, only: :index do resources :companies do - scope :only => :index do + scope only: :index do resources :divisions end end @@ -2793,20 +2793,20 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest get "/only/sectors/1/companies/2/divisions" assert_equal "only/divisions#index", @response.body - assert_equal "/only/sectors/1/companies/2/divisions", only_sector_company_divisions_path(:sector_id => "1", :company_id => "2") + assert_equal "/only/sectors/1/companies/2/divisions", only_sector_company_divisions_path(sector_id: "1", company_id: "2") get "/only/sectors/1/companies/2/divisions/3" assert_equal "Not Found", @response.body - assert_raise(NoMethodError) { only_sector_company_division_path(:sector_id => "1", :company_id => "2", :id => "3") } + assert_raise(NoMethodError) { only_sector_company_division_path(sector_id: "1", company_id: "2", id: "3") } end def test_except_scope_should_override_parent_scope draw do - scope :except => :index do + scope except: :index do namespace :except do - resources :sectors, :except => [:show, :update, :destroy] do + resources :sectors, except: [:show, :update, :destroy] do resources :companies do - scope :except => [:show, :update, :destroy] do + scope except: [:show, :update, :destroy] do resources :divisions end end @@ -2817,20 +2817,20 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest get "/except/sectors/1/companies/2/divisions" assert_equal "except/divisions#index", @response.body - assert_equal "/except/sectors/1/companies/2/divisions", except_sector_company_divisions_path(:sector_id => "1", :company_id => "2") + assert_equal "/except/sectors/1/companies/2/divisions", except_sector_company_divisions_path(sector_id: "1", company_id: "2") get "/except/sectors/1/companies/2/divisions/3" assert_equal "Not Found", @response.body - assert_raise(NoMethodError) { except_sector_company_division_path(:sector_id => "1", :company_id => "2", :id => "3") } + assert_raise(NoMethodError) { except_sector_company_division_path(sector_id: "1", company_id: "2", id: "3") } end def test_except_scope_should_override_parent_only_scope draw do - scope :only => :show do + scope only: :show do namespace :only do - resources :sectors, :only => :index do + resources :sectors, only: :index do resources :companies do - scope :except => [:show, :update, :destroy] do + scope except: [:show, :update, :destroy] do resources :departments end end @@ -2841,20 +2841,20 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest get "/only/sectors/1/companies/2/departments" assert_equal "only/departments#index", @response.body - assert_equal "/only/sectors/1/companies/2/departments", only_sector_company_departments_path(:sector_id => "1", :company_id => "2") + assert_equal "/only/sectors/1/companies/2/departments", only_sector_company_departments_path(sector_id: "1", company_id: "2") get "/only/sectors/1/companies/2/departments/3" assert_equal "Not Found", @response.body - assert_raise(NoMethodError) { only_sector_company_department_path(:sector_id => "1", :company_id => "2", :id => "3") } + assert_raise(NoMethodError) { only_sector_company_department_path(sector_id: "1", company_id: "2", id: "3") } end def test_only_scope_should_override_parent_except_scope draw do - scope :except => :index do + scope except: :index do namespace :except do - resources :sectors, :except => [:show, :update, :destroy] do + resources :sectors, except: [:show, :update, :destroy] do resources :companies do - scope :only => :index do + scope only: :index do resources :departments end end @@ -2865,11 +2865,11 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest get "/except/sectors/1/companies/2/departments" assert_equal "except/departments#index", @response.body - assert_equal "/except/sectors/1/companies/2/departments", except_sector_company_departments_path(:sector_id => "1", :company_id => "2") + assert_equal "/except/sectors/1/companies/2/departments", except_sector_company_departments_path(sector_id: "1", company_id: "2") get "/except/sectors/1/companies/2/departments/3" assert_equal "Not Found", @response.body - assert_raise(NoMethodError) { except_sector_company_department_path(:sector_id => "1", :company_id => "2", :id => "3") } + assert_raise(NoMethodError) { except_sector_company_department_path(sector_id: "1", company_id: "2", id: "3") } end def test_resources_are_not_pluralized @@ -2892,11 +2892,11 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest get "/transport/taxis/1" assert_equal "transport/taxis#show", @response.body - assert_equal "/transport/taxis/1", transport_taxi_path(:id => "1") + assert_equal "/transport/taxis/1", transport_taxi_path(id: "1") get "/transport/taxis/1/edit" assert_equal "transport/taxis#edit", @response.body - assert_equal "/transport/taxis/1/edit", edit_transport_taxi_path(:id => "1") + assert_equal "/transport/taxis/1/edit", edit_transport_taxi_path(id: "1") put "/transport/taxis/1" assert_equal "transport/taxis#update", @response.body @@ -2936,46 +2936,46 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest def test_greedy_resource_id_regexp_doesnt_match_edit_and_custom_action draw do - resources :sections, :id => /.+/ do - get :preview, :on => :member + resources :sections, id: /.+/ do + get :preview, on: :member end end get "/sections/1/edit" assert_equal "sections#edit", @response.body - assert_equal "/sections/1/edit", edit_section_path(:id => "1") + assert_equal "/sections/1/edit", edit_section_path(id: "1") get "/sections/1/preview" assert_equal "sections#preview", @response.body - assert_equal "/sections/1/preview", preview_section_path(:id => "1") + assert_equal "/sections/1/preview", preview_section_path(id: "1") end def test_resource_constraints_are_pushed_to_scope draw do namespace :wiki do - resources :articles, :id => /[^\/]+/ do - resources :comments, :only => [:create, :new] + resources :articles, id: /[^\/]+/ do + resources :comments, only: [:create, :new] end end end get "/wiki/articles/Ruby_on_Rails_3.0" assert_equal "wiki/articles#show", @response.body - assert_equal "/wiki/articles/Ruby_on_Rails_3.0", wiki_article_path(:id => "Ruby_on_Rails_3.0") + assert_equal "/wiki/articles/Ruby_on_Rails_3.0", wiki_article_path(id: "Ruby_on_Rails_3.0") get "/wiki/articles/Ruby_on_Rails_3.0/comments/new" assert_equal "wiki/comments#new", @response.body - assert_equal "/wiki/articles/Ruby_on_Rails_3.0/comments/new", new_wiki_article_comment_path(:article_id => "Ruby_on_Rails_3.0") + assert_equal "/wiki/articles/Ruby_on_Rails_3.0/comments/new", new_wiki_article_comment_path(article_id: "Ruby_on_Rails_3.0") post "/wiki/articles/Ruby_on_Rails_3.0/comments" assert_equal "wiki/comments#create", @response.body - assert_equal "/wiki/articles/Ruby_on_Rails_3.0/comments", wiki_article_comments_path(:article_id => "Ruby_on_Rails_3.0") + assert_equal "/wiki/articles/Ruby_on_Rails_3.0/comments", wiki_article_comments_path(article_id: "Ruby_on_Rails_3.0") end def test_resources_path_can_be_a_symbol draw do - resources :wiki_pages, :path => :pages - resource :wiki_account, :path => :my_account + resources :wiki_pages, path: :pages + resource :wiki_account, path: :my_account end get "/pages" @@ -2984,7 +2984,7 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest get "/pages/Ruby_on_Rails" assert_equal "wiki_pages#show", @response.body - assert_equal "/pages/Ruby_on_Rails", wiki_page_path(:id => "Ruby_on_Rails") + assert_equal "/pages/Ruby_on_Rails", wiki_page_path(id: "Ruby_on_Rails") get "/my_account" assert_equal "wiki_accounts#show", @response.body @@ -2993,7 +2993,7 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest def test_redirect_https draw do - get "secure", :to => redirect("/secure/login") + get "secure", to: redirect("/secure/login") end with_https do @@ -3004,12 +3004,12 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest def test_path_parameters_is_not_stale draw do - scope "/countries/:country", :constraints => lambda { |params, req| %w(all France).include?(params[:country]) } do - get "/", :to => "countries#index" - get "/cities", :to => "countries#cities" + scope "/countries/:country", constraints: lambda { |params, req| %w(all France).include?(params[:country]) } do + get "/", to: "countries#index" + get "/cities", to: "countries#cities" end - get "/countries/:country/(*other)", :to => redirect{ |params, req| params[:other] ? "/countries/all/#{params[:other]}" : "/countries/all" } + get "/countries/:country/(*other)", to: redirect{ |params, req| params[:other] ? "/countries/all/#{params[:other]}" : "/countries/all" } end get "/countries/France" @@ -3028,9 +3028,9 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest def test_constraints_block_not_carried_to_following_routes draw do scope "/italians" do - get "/writers", :to => "italians#writers", :constraints => ::TestRoutingMapper::IpRestrictor - get "/sculptors", :to => "italians#sculptors" - get "/painters/:painter", :to => "italians#painters", :constraints => {:painter => /michelangelo/} + get "/writers", to: "italians#writers", constraints: ::TestRoutingMapper::IpRestrictor + get "/sculptors", to: "italians#sculptors" + get "/painters/:painter", to: "italians#painters", constraints: {painter: /michelangelo/} end end @@ -3051,12 +3051,12 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest draw do resources :customers do resources :invoices do - get "aged/:months", :on => :collection, :action => :aged, :as => :aged + get "aged/:months", on: :collection, action: :aged, as: :aged end - get "inactive", :on => :collection - post "deactivate", :on => :member - get "old", :on => :collection, :as => :stale + get "inactive", on: :collection + post "deactivate", on: :member + get "old", on: :collection, as: :stale end end @@ -3066,7 +3066,7 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest post "/customers/1/deactivate" assert_equal "customers#deactivate", @response.body - assert_equal "/customers/1/deactivate", deactivate_customer_path(:id => "1") + assert_equal "/customers/1/deactivate", deactivate_customer_path(id: "1") get "/customers/old" assert_equal "customers#old", @response.body @@ -3074,7 +3074,7 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest get "/customers/1/invoices/aged/3" assert_equal "invoices#aged", @response.body - assert_equal "/customers/1/invoices/aged/3", aged_customer_invoices_path(:customer_id => "1", :months => "3") + assert_equal "/customers/1/invoices/aged/3", aged_customer_invoices_path(customer_id: "1", months: "3") end def test_route_defined_in_resources_scope_level @@ -3086,41 +3086,41 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest get "/customers/1/export" assert_equal "customers#export", @response.body - assert_equal "/customers/1/export", customer_export_path(:customer_id => "1") + assert_equal "/customers/1/export", customer_export_path(customer_id: "1") end def test_named_character_classes_in_regexp_constraints draw do get "/purchases/:token/:filename", - :to => "purchases#fetch", - :token => /[[:alnum:]]{10}/, - :filename => /(.+)/, - :as => :purchase + to: "purchases#fetch", + token: /[[:alnum:]]{10}/, + filename: /(.+)/, + as: :purchase end get "/purchases/315004be7e/Ruby_on_Rails_3.pdf" assert_equal "purchases#fetch", @response.body - assert_equal "/purchases/315004be7e/Ruby_on_Rails_3.pdf", purchase_path(:token => "315004be7e", :filename => "Ruby_on_Rails_3.pdf") + assert_equal "/purchases/315004be7e/Ruby_on_Rails_3.pdf", purchase_path(token: "315004be7e", filename: "Ruby_on_Rails_3.pdf") end def test_nested_resource_constraints draw do - resources :lists, :id => /([A-Za-z0-9]{25})|default/ do - resources :todos, :id => /\d+/ + resources :lists, id: /([A-Za-z0-9]{25})|default/ do + resources :todos, id: /\d+/ end end get "/lists/01234012340123401234fffff" assert_equal "lists#show", @response.body - assert_equal "/lists/01234012340123401234fffff", list_path(:id => "01234012340123401234fffff") + assert_equal "/lists/01234012340123401234fffff", list_path(id: "01234012340123401234fffff") get "/lists/01234012340123401234fffff/todos/1" assert_equal "todos#show", @response.body - assert_equal "/lists/01234012340123401234fffff/todos/1", list_todo_path(:list_id => "01234012340123401234fffff", :id => "1") + assert_equal "/lists/01234012340123401234fffff/todos/1", list_todo_path(list_id: "01234012340123401234fffff", id: "1") get "/lists/2/todos/1" assert_equal "Not Found", @response.body - assert_raises(ActionController::UrlGenerationError){ list_todo_path(:list_id => "2", :id => "1") } + assert_raises(ActionController::UrlGenerationError){ list_todo_path(list_id: "2", id: "1") } end def test_redirect_argument_error @@ -3143,10 +3143,10 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest def test_explicitly_avoiding_the_named_route draw do - scope :as => "routes" do - get "/c/:id", :as => :collision, :to => "collision#show" - get "/collision", :to => "collision#show" - get "/no_collision", :to => "collision#show", :as => nil + scope as: "routes" do + get "/c/:id", as: :collision, to: "collision#show" + get "/collision", to: "collision#show" + get "/no_collision", to: "collision#show", as: nil end end @@ -3155,49 +3155,49 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest def test_controller_name_with_leading_slash_raise_error assert_raise(ArgumentError) do - draw { get "/feeds/:service", :to => "/feeds#show" } + draw { get "/feeds/:service", to: "/feeds#show" } end assert_raise(ArgumentError) do - draw { get "/feeds/:service", :controller => "/feeds", :action => "show" } + draw { get "/feeds/:service", controller: "/feeds", action: "show" } end assert_raise(ArgumentError) do - draw { get "/api/feeds/:service", :to => "/api/feeds#show" } + draw { get "/api/feeds/:service", to: "/api/feeds#show" } end assert_raise(ArgumentError) do - draw { resources :feeds, :controller => "/feeds" } + draw { resources :feeds, controller: "/feeds" } end end def test_invalid_route_name_raises_error assert_raise(ArgumentError) do - draw { get "/products", :to => "products#index", :as => "products " } + draw { get "/products", to: "products#index", as: "products " } end assert_raise(ArgumentError) do - draw { get "/products", :to => "products#index", :as => " products" } + draw { get "/products", to: "products#index", as: " products" } end assert_raise(ArgumentError) do - draw { get "/products", :to => "products#index", :as => "products!" } + draw { get "/products", to: "products#index", as: "products!" } end assert_raise(ArgumentError) do - draw { get "/products", :to => "products#index", :as => "products index" } + draw { get "/products", to: "products#index", as: "products index" } end assert_raise(ArgumentError) do - draw { get "/products", :to => "products#index", :as => "1products" } + draw { get "/products", to: "products#index", as: "1products" } end end def test_duplicate_route_name_raises_error assert_raise(ArgumentError) do draw do - get "/collision", :to => "collision#show", :as => "collision" - get "/duplicate", :to => "duplicate#show", :as => "collision" + get "/collision", to: "collision#show", as: "collision" + get "/duplicate", to: "duplicate#show", as: "collision" end end end @@ -3206,15 +3206,15 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest assert_raise(ArgumentError) do draw do resources :collisions - get "/collision", :to => "collision#show", :as => "collision" + get "/collision", to: "collision#show", as: "collision" end end end def test_nested_route_in_nested_resource draw do - resources :posts, :only => [:index, :show] do - resources :comments, :except => :destroy do + resources :posts, only: [:index, :show] do + resources :comments, except: :destroy do get "views" => "comments#views", :as => :views end end @@ -3222,27 +3222,27 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest get "/posts/1/comments/2/views" assert_equal "comments#views", @response.body - assert_equal "/posts/1/comments/2/views", post_comment_views_path(:post_id => "1", :comment_id => "2") + assert_equal "/posts/1/comments/2/views", post_comment_views_path(post_id: "1", comment_id: "2") end def test_root_in_deeply_nested_scope draw do - resources :posts, :only => [:index, :show] do + resources :posts, only: [:index, :show] do namespace :admin do - root :to => "index#index" + root to: "index#index" end end end get "/posts/1/admin" assert_equal "admin/index#index", @response.body - assert_equal "/posts/1/admin", post_admin_root_path(:post_id => "1") + assert_equal "/posts/1/admin", post_admin_root_path(post_id: "1") end def test_custom_param draw do - resources :profiles, :param => :username do - get :details, :on => :member + resources :profiles, param: :username do + get :details, on: :member resources :messages end end @@ -3261,8 +3261,8 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest def test_custom_param_constraint draw do - resources :profiles, :param => :username, :username => /[a-z]+/ do - get :details, :on => :member + resources :profiles, param: :username, username: /[a-z]+/ do + get :details, on: :member resources :messages end end @@ -3280,8 +3280,8 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest def test_shallow_custom_param draw do resources :orders do - constraints :download => /[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}/ do - resources :downloads, :param => :download, :shallow => true + constraints download: /[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}/ do + resources :downloads, param: :download, shallow: true end end end @@ -3616,7 +3616,7 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest def test_passing_action_parameters_to_url_helpers_raises_error_if_parameters_are_not_permitted draw do - root :to => "projects#index" + root to: "projects#index" end params = ActionController::Parameters.new(id: "1") @@ -3627,7 +3627,7 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest def test_passing_action_parameters_to_url_helpers_is_allowed_if_parameters_are_permitted draw do - root :to => "projects#index" + root to: "projects#index" end params = ActionController::Parameters.new(id: "1") params.permit! @@ -3736,7 +3736,7 @@ class TestAltApp < ActionDispatch::IntegrationTest end }.new AltRoutes.draw do - get "/" => TestAltApp::XHeader.new, :constraints => {:x_header => /HEADER/} + get "/" => TestAltApp::XHeader.new, :constraints => {x_header: /HEADER/} get "/" => TestAltApp::AltApp.new end @@ -3816,7 +3816,7 @@ class TestNamespaceWithControllerOption < ActionDispatch::IntegrationTest def test_missing_controller ex = assert_raises(ArgumentError) { draw do - get "/foo/bar", :action => :index + get "/foo/bar", action: :index end } assert_match(/Missing :controller/, ex.message) @@ -3825,7 +3825,7 @@ class TestNamespaceWithControllerOption < ActionDispatch::IntegrationTest def test_missing_controller_with_to ex = assert_raises(ArgumentError) { draw do - get "/foo/bar", :to => "foo" + get "/foo/bar", to: "foo" end } assert_match(/Missing :controller/, ex.message) @@ -3834,7 +3834,7 @@ class TestNamespaceWithControllerOption < ActionDispatch::IntegrationTest def test_missing_action_on_hash ex = assert_raises(ArgumentError) { draw do - get "/foo/bar", :to => "foo#" + get "/foo/bar", to: "foo#" end } assert_match(/Missing :action/, ex.message) @@ -3843,7 +3843,7 @@ class TestNamespaceWithControllerOption < ActionDispatch::IntegrationTest def test_valid_controller_options_inside_namespace draw do namespace :admin do - resources :storage_files, :controller => "storage_files" + resources :storage_files, controller: "storage_files" end end @@ -3853,7 +3853,7 @@ class TestNamespaceWithControllerOption < ActionDispatch::IntegrationTest def test_resources_with_valid_namespaced_controller_option draw do - resources :storage_files, :controller => "admin/storage_files" + resources :storage_files, controller: "admin/storage_files" end get "/storage_files" @@ -3864,7 +3864,7 @@ class TestNamespaceWithControllerOption < ActionDispatch::IntegrationTest e = assert_raise(ArgumentError) do draw do namespace :admin do - resources :storage_files, :controller => "StorageFiles" + resources :storage_files, controller: "StorageFiles" end end end @@ -3875,7 +3875,7 @@ class TestNamespaceWithControllerOption < ActionDispatch::IntegrationTest def test_warn_with_ruby_constant_syntax_namespaced_controller_option e = assert_raise(ArgumentError) do draw do - resources :storage_files, :controller => "Admin::StorageFiles" + resources :storage_files, controller: "Admin::StorageFiles" end end @@ -3885,7 +3885,7 @@ class TestNamespaceWithControllerOption < ActionDispatch::IntegrationTest def test_warn_with_ruby_constant_syntax_no_colons e = assert_raise(ArgumentError) do draw do - resources :storage_files, :controller => "Admin" + resources :storage_files, controller: "Admin" end end @@ -3903,7 +3903,7 @@ class TestDefaultScope < ActionDispatch::IntegrationTest end DefaultScopeRoutes = ActionDispatch::Routing::RouteSet.new - DefaultScopeRoutes.default_scope = {:module => :blog} + DefaultScopeRoutes.default_scope = {module: :blog} DefaultScopeRoutes.draw do resources :posts end @@ -3978,7 +3978,7 @@ class TestUriPathEscaping < ActionDispatch::IntegrationTest def app; APP end test "escapes slash in generated path segment" do - assert_equal "/a%20b%2Fc+d", segment_path(:segment => "a b/c+d") + assert_equal "/a%20b%2Fc+d", segment_path(segment: "a b/c+d") end test "unescapes recognized path segment" do @@ -3987,7 +3987,7 @@ class TestUriPathEscaping < ActionDispatch::IntegrationTest end test "does not escape slash in generated path splat" do - assert_equal "/a%20b/c+d", splat_path(:splat => "a b/c+d") + assert_equal "/a%20b/c+d", splat_path(splat: "a b/c+d") end test "unescapes recognized path splat" do @@ -4033,7 +4033,7 @@ class TestMultipleNestedController < ActionDispatch::IntegrationTest include Routes.url_helpers def index - render :inline => "<%= url_for :controller => '/pooh', :action => 'index' %>" + render inline: "<%= url_for :controller => '/pooh', :action => 'index' %>" end end end @@ -4080,7 +4080,7 @@ class TestRedirectInterpolation < ActionDispatch::IntegrationTest ok = lambda { |env| [200, { "Content-Type" => "text/plain" }, []] } get "/foo/:id" => redirect("/foo/bar/%{id}") - get "/bar/:id" => redirect(:path => "/foo/bar/%{id}") + get "/bar/:id" => redirect(path: "/foo/bar/%{id}") get "/baz/:id" => redirect("/baz?id=%{id}&foo=?&bar=1#id-%{id}") get "/foo/bar/:id" => ok get "/baz" => ok @@ -4254,7 +4254,7 @@ class TestNamedRouteUrlHelpers < ActionDispatch::IntegrationTest Routes = ActionDispatch::Routing::RouteSet.new.tap do |app| app.draw do - scope :module => "test_named_route_url_helpers" do + scope module: "test_named_route_url_helpers" do get "/categories/:id" => "categories#show", :as => :category get "/products/:id" => "products#show", :as => :product end @@ -4280,19 +4280,19 @@ class TestUrlConstraints < ActionDispatch::IntegrationTest app.draw do ok = lambda { |env| [200, { "Content-Type" => "text/plain" }, []] } - constraints :subdomain => "admin" do + constraints subdomain: "admin" do get "/" => ok, :as => :admin_root end - scope :constraints => { :protocol => "https://" } do + scope constraints: { protocol: "https://" } do get "/" => ok, :as => :secure_root end - get "/" => ok, :as => :alternate_root, :constraints => { :port => 8080 } + get "/" => ok, :as => :alternate_root, :constraints => { port: 8080 } - get "/search" => ok, :constraints => { :subdomain => false } + get "/search" => ok, :constraints => { subdomain: false } - get "/logs" => ok, :constraints => { :subdomain => true } + get "/logs" => ok, :constraints => { subdomain: true } end end @@ -4350,14 +4350,14 @@ class TestInvalidUrls < ActionDispatch::IntegrationTest test "invalid UTF-8 encoding returns a 400 Bad Request" do with_routing do |set| set.draw do - get "/bar/:id", :to => redirect("/foo/show/%{id}") - get "/foo/show(/:id)", :to => "test_invalid_urls/foo#show" + get "/bar/:id", to: redirect("/foo/show/%{id}") + get "/foo/show(/:id)", to: "test_invalid_urls/foo#show" ok = lambda { |env| [200, { "Content-Type" => "text/plain" }, []] } get "/foobar/:id", to: ok ActiveSupport::Deprecation.silence do - get "/foo(/:action(/:id))", :controller => "test_invalid_urls/foo" + get "/foo(/:action(/:id))", controller: "test_invalid_urls/foo" get "/:controller(/:action(/:id))" end end @@ -4384,7 +4384,7 @@ class TestOptionalRootSegments < ActionDispatch::IntegrationTest stub_controllers do |routes| Routes = routes Routes.draw do - get "/(page/:page)", :to => "pages#index", :as => :root + get "/(page/:page)", to: "pages#index", as: :root end end @@ -4404,7 +4404,7 @@ class TestOptionalRootSegments < ActionDispatch::IntegrationTest assert_equal "pages#index", @response.body assert_equal "1", @request.params[:page] assert_equal "/page/1", root_path("1") - assert_equal "/page/1", root_path(:page => "1") + assert_equal "/page/1", root_path(page: "1") end end @@ -4413,10 +4413,10 @@ class TestPortConstraints < ActionDispatch::IntegrationTest app.draw do ok = lambda { |env| [200, { "Content-Type" => "text/plain" }, []] } - get "/integer", to: ok, constraints: { :port => 8080 } - get "/string", to: ok, constraints: { :port => "8080" } - get "/array", to: ok, constraints: { :port => [8080] } - get "/regexp", to: ok, constraints: { :port => /8080/ } + get "/integer", to: ok, constraints: { port: 8080 } + get "/string", to: ok, constraints: { port: "8080" } + get "/array", to: ok, constraints: { port: [8080] } + get "/regexp", to: ok, constraints: { port: /8080/ } end end @@ -4581,7 +4581,7 @@ class TestRackAppRouteGeneration < ActionDispatch::IntegrationTest end assert_raise(ActionController::UrlGenerationError) do - assert_equal "/de/account?controller=products", url_for(controller: "products", action: "index", :locale => "de", only_path: true) + assert_equal "/de/account?controller=products", url_for(controller: "products", action: "index", locale: "de", only_path: true) end end end @@ -4608,7 +4608,7 @@ class TestRedirectRouteGeneration < ActionDispatch::IntegrationTest end assert_raise(ActionController::UrlGenerationError) do - assert_equal "/de/account?controller=products", url_for(controller: "products", action: "index", :locale => "de", only_path: true) + assert_equal "/de/account?controller=products", url_for(controller: "products", action: "index", locale: "de", only_path: true) end end end diff --git a/actionpack/test/dispatch/session/cache_store_test.rb b/actionpack/test/dispatch/session/cache_store_test.rb index 96793b3280..5252d93850 100644 --- a/actionpack/test/dispatch/session/cache_store_test.rb +++ b/actionpack/test/dispatch/session/cache_store_test.rb @@ -165,13 +165,13 @@ class CacheStoreTest < ActionDispatch::IntegrationTest with_routing do |set| set.draw do ActiveSupport::Deprecation.silence do - get ":action", :to => ::CacheStoreTest::TestController + get ":action", to: ::CacheStoreTest::TestController end end @app = self.class.build_app(set) do |middleware| @cache = ActiveSupport::Cache::MemoryStore.new - middleware.use ActionDispatch::Session::CacheStore, :key => "_session_id", :cache => @cache + middleware.use ActionDispatch::Session::CacheStore, key: "_session_id", cache: @cache middleware.delete ActionDispatch::ShowExceptions end diff --git a/actionpack/test/dispatch/session/cookie_store_test.rb b/actionpack/test/dispatch/session/cookie_store_test.rb index c741f486ea..1dbaa2ab00 100644 --- a/actionpack/test/dispatch/session/cookie_store_test.rb +++ b/actionpack/test/dispatch/session/cookie_store_test.rb @@ -7,8 +7,8 @@ class CookieStoreTest < ActionDispatch::IntegrationTest SessionSecret = "b3c631c314c0bbca50c1b2843150fe33" Generator = ActiveSupport::LegacyKeyGenerator.new(SessionSecret) - Verifier = ActiveSupport::MessageVerifier.new(SessionSecret, :digest => "SHA1") - SignedBar = Verifier.generate(:foo => "bar", :session_id => SecureRandom.hex(16)) + Verifier = ActiveSupport::MessageVerifier.new(SessionSecret, digest: "SHA1") + SignedBar = Verifier.generate(foo: "bar", session_id: SecureRandom.hex(16)) class TestController < ActionController::Base def no_session_access @@ -105,7 +105,7 @@ class CookieStoreTest < ActionDispatch::IntegrationTest end def test_does_not_set_secure_cookies_over_http - with_test_route_set(:secure => true) do + with_test_route_set(secure: true) do get "/set_session_value" assert_response :success assert_equal nil, headers["Set-Cookie"] @@ -124,7 +124,7 @@ class CookieStoreTest < ActionDispatch::IntegrationTest end def test_does_set_secure_cookies_over_https - with_test_route_set(:secure => true) do + with_test_route_set(secure: true) do get "/set_session_value", headers: { "HTTPS" => "on" } assert_response :success assert_equal "_myapp_session=#{response.body}; path=/; secure; HttpOnly", @@ -271,7 +271,7 @@ class CookieStoreTest < ActionDispatch::IntegrationTest end def test_session_store_with_expire_after - with_test_route_set(:expire_after => 5.hours) do + with_test_route_set(expire_after: 5.hours) do # First request accesses the session time = Time.local(2008, 4, 24) cookie_body = nil @@ -304,7 +304,7 @@ class CookieStoreTest < ActionDispatch::IntegrationTest end def test_session_store_with_explicit_domain - with_test_route_set(:domain => "example.es") do + with_test_route_set(domain: "example.es") do get "/set_session_value" assert_match(/domain=example\.es/, headers["Set-Cookie"]) headers["Set-Cookie"] @@ -319,14 +319,14 @@ class CookieStoreTest < ActionDispatch::IntegrationTest end def test_session_store_with_nil_domain - with_test_route_set(:domain => nil) do + with_test_route_set(domain: nil) do get "/set_session_value" assert_no_match(/domain\=/, headers["Set-Cookie"]) end end def test_session_store_with_all_domains - with_test_route_set(:domain => :all) do + with_test_route_set(domain: :all) do get "/set_session_value" assert_match(/domain=\.example\.com/, headers["Set-Cookie"]) end @@ -346,11 +346,11 @@ class CookieStoreTest < ActionDispatch::IntegrationTest with_routing do |set| set.draw do ActiveSupport::Deprecation.silence do - get ":action", :to => ::CookieStoreTest::TestController + get ":action", to: ::CookieStoreTest::TestController end end - options = { :key => SessionKey }.merge!(options) + options = { key: SessionKey }.merge!(options) @app = self.class.build_app(set) do |middleware| middleware.use ActionDispatch::Session::CookieStore, options diff --git a/actionpack/test/dispatch/session/mem_cache_store_test.rb b/actionpack/test/dispatch/session/mem_cache_store_test.rb index 40594ed61d..c2d0719b4e 100644 --- a/actionpack/test/dispatch/session/mem_cache_store_test.rb +++ b/actionpack/test/dispatch/session/mem_cache_store_test.rb @@ -188,12 +188,12 @@ class MemCacheStoreTest < ActionDispatch::IntegrationTest with_routing do |set| set.draw do ActiveSupport::Deprecation.silence do - get ":action", :to => ::MemCacheStoreTest::TestController + get ":action", to: ::MemCacheStoreTest::TestController end end @app = self.class.build_app(set) do |middleware| - middleware.use ActionDispatch::Session::MemCacheStore, :key => "_session_id", :namespace => "mem_cache_store_test:#{SecureRandom.hex(10)}" + middleware.use ActionDispatch::Session::MemCacheStore, key: "_session_id", namespace: "mem_cache_store_test:#{SecureRandom.hex(10)}" middleware.delete ActionDispatch::ShowExceptions end diff --git a/actionpack/test/dispatch/test_request_test.rb b/actionpack/test/dispatch/test_request_test.rb index a27c07389b..9beab1ee07 100644 --- a/actionpack/test/dispatch/test_request_test.rb +++ b/actionpack/test/dispatch/test_request_test.rb @@ -49,7 +49,7 @@ class TestRequestTest < ActiveSupport::TestCase req.cookie_jar.clear assert_cookies({}, req.cookie_jar) - req.cookie_jar.update(:user_name => "david") + req.cookie_jar.update(user_name: "david") assert_cookies({"user_name" => "david"}, req.cookie_jar) end diff --git a/actionpack/test/dispatch/uploaded_file_test.rb b/actionpack/test/dispatch/uploaded_file_test.rb index 63d8cda9a0..60d0246a68 100644 --- a/actionpack/test/dispatch/uploaded_file_test.rb +++ b/actionpack/test/dispatch/uploaded_file_test.rb @@ -9,81 +9,81 @@ module ActionDispatch end def test_original_filename - uf = Http::UploadedFile.new(:filename => "foo", :tempfile => Object.new) + uf = Http::UploadedFile.new(filename: "foo", tempfile: Object.new) assert_equal "foo", uf.original_filename end def test_filename_should_be_in_utf_8 - uf = Http::UploadedFile.new(:filename => "foo", :tempfile => Object.new) + uf = Http::UploadedFile.new(filename: "foo", tempfile: Object.new) assert_equal "UTF-8", uf.original_filename.encoding.to_s end def test_filename_should_always_be_in_utf_8 - uf = Http::UploadedFile.new(:filename => "foo".encode(Encoding::SHIFT_JIS), - :tempfile => Object.new) + uf = Http::UploadedFile.new(filename: "foo".encode(Encoding::SHIFT_JIS), + tempfile: Object.new) assert_equal "UTF-8", uf.original_filename.encoding.to_s end def test_content_type - uf = Http::UploadedFile.new(:type => "foo", :tempfile => Object.new) + uf = Http::UploadedFile.new(type: "foo", tempfile: Object.new) assert_equal "foo", uf.content_type end def test_headers - uf = Http::UploadedFile.new(:head => "foo", :tempfile => Object.new) + uf = Http::UploadedFile.new(head: "foo", tempfile: Object.new) assert_equal "foo", uf.headers end def test_tempfile - uf = Http::UploadedFile.new(:tempfile => "foo") + uf = Http::UploadedFile.new(tempfile: "foo") assert_equal "foo", uf.tempfile end def test_to_io_returns_the_tempfile tf = Object.new - uf = Http::UploadedFile.new(:tempfile => tf) + uf = Http::UploadedFile.new(tempfile: tf) assert_equal tf, uf.to_io end def test_delegates_path_to_tempfile tf = Class.new { def path; "thunderhorse" end } - uf = Http::UploadedFile.new(:tempfile => tf.new) + uf = Http::UploadedFile.new(tempfile: tf.new) assert_equal "thunderhorse", uf.path end def test_delegates_open_to_tempfile tf = Class.new { def open; "thunderhorse" end } - uf = Http::UploadedFile.new(:tempfile => tf.new) + uf = Http::UploadedFile.new(tempfile: tf.new) assert_equal "thunderhorse", uf.open end def test_delegates_close_to_tempfile tf = Class.new { def close(unlink_now=false); "thunderhorse" end } - uf = Http::UploadedFile.new(:tempfile => tf.new) + uf = Http::UploadedFile.new(tempfile: tf.new) assert_equal "thunderhorse", uf.close end def test_close_accepts_parameter tf = Class.new { def close(unlink_now=false); "thunderhorse: #{unlink_now}" end } - uf = Http::UploadedFile.new(:tempfile => tf.new) + uf = Http::UploadedFile.new(tempfile: tf.new) assert_equal "thunderhorse: true", uf.close(true) end def test_delegates_read_to_tempfile tf = Class.new { def read(length=nil, buffer=nil); "thunderhorse" end } - uf = Http::UploadedFile.new(:tempfile => tf.new) + uf = Http::UploadedFile.new(tempfile: tf.new) assert_equal "thunderhorse", uf.read end def test_delegates_read_to_tempfile_with_params tf = Class.new { def read(length=nil, buffer=nil); [length, buffer] end } - uf = Http::UploadedFile.new(:tempfile => tf.new) + uf = Http::UploadedFile.new(tempfile: tf.new) assert_equal %w{ thunder horse }, uf.read(*%w{ thunder horse }) end def test_delegate_respects_respond_to? tf = Class.new { def read; yield end; private :read } - uf = Http::UploadedFile.new(:tempfile => tf.new) + uf = Http::UploadedFile.new(tempfile: tf.new) assert_raises(NoMethodError) do uf.read end @@ -91,13 +91,13 @@ module ActionDispatch def test_delegate_eof_to_tempfile tf = Class.new { def eof?; true end; } - uf = Http::UploadedFile.new(:tempfile => tf.new) + uf = Http::UploadedFile.new(tempfile: tf.new) assert uf.eof? end def test_respond_to? tf = Class.new { def read; yield end } - uf = Http::UploadedFile.new(:tempfile => tf.new) + uf = Http::UploadedFile.new(tempfile: tf.new) assert uf.respond_to?(:headers), "responds to headers" assert uf.respond_to?(:read), "responds to read" end diff --git a/actionpack/test/dispatch/url_generation_test.rb b/actionpack/test/dispatch/url_generation_test.rb index 50cd4ef800..b5a792b456 100644 --- a/actionpack/test/dispatch/url_generation_test.rb +++ b/actionpack/test/dispatch/url_generation_test.rb @@ -13,7 +13,7 @@ module TestUrlGeneration end Routes.draw do - get "/foo", :to => "my_route_generating#index", :as => :foo + get "/foo", to: "my_route_generating#index", as: :foo resources :bars @@ -35,7 +35,7 @@ module TestUrlGeneration end test "accepting a :script_name option" do - assert_equal "/bar/foo", foo_path(:script_name => "/bar") + assert_equal "/bar/foo", foo_path(script_name: "/bar") end test "the request's SCRIPT_NAME takes precedence over the route" do @@ -50,7 +50,7 @@ module TestUrlGeneration test "handling http protocol with https set" do https! - assert_equal "http://www.example.com/foo", foo_url(:protocol => "http") + assert_equal "http://www.example.com/foo", foo_url(protocol: "http") end test "extracting protocol from host when protocol not present" do diff --git a/actionpack/test/journey/path/pattern_test.rb b/actionpack/test/journey/path/pattern_test.rb index 7b013cbbc6..224ab689fc 100644 --- a/actionpack/test/journey/path/pattern_test.rb +++ b/actionpack/test/journey/path/pattern_test.rb @@ -23,7 +23,7 @@ module ActionDispatch define_method(:"test_to_regexp_#{path}") do path = Pattern.build( path, - { :controller => /.+/ }, + { controller: /.+/ }, SEPARATORS, true ) @@ -47,7 +47,7 @@ module ActionDispatch define_method(:"test_to_non_anchored_regexp_#{path}") do path = Pattern.build( path, - { :controller => /.+/ }, + { controller: /.+/ }, SEPARATORS, false ) @@ -70,7 +70,7 @@ module ActionDispatch define_method(:"test_names_#{path}") do path = Pattern.build( path, - { :controller => /.+/ }, + { controller: /.+/ }, SEPARATORS, true ) @@ -81,7 +81,7 @@ module ActionDispatch def test_to_regexp_with_extended_group path = Pattern.build( "/page/:name", - { :name => / + { name: / #ROFL (tender|love #MAO @@ -108,7 +108,7 @@ module ActionDispatch def test_to_regexp_match_non_optional path = Pattern.build( "/:name", - { :name => /\d+/ }, + { name: /\d+/ }, SEPARATORS, true ) @@ -119,7 +119,7 @@ module ActionDispatch def test_to_regexp_with_group path = Pattern.build( "/page/:name", - { :name => /(tender|love)/ }, + { name: /(tender|love)/ }, SEPARATORS, true ) @@ -129,7 +129,7 @@ module ActionDispatch end def test_ast_sets_regular_expressions - requirements = { :name => /(tender|love)/, :value => /./ } + requirements = { name: /(tender|love)/, value: /./ } path = Pattern.build( "/page/:name/:value", requirements, @@ -147,7 +147,7 @@ module ActionDispatch def test_match_data_with_group path = Pattern.build( "/page/:name", - { :name => /(tender|love)/ }, + { name: /(tender|love)/ }, SEPARATORS, true ) @@ -159,7 +159,7 @@ module ActionDispatch def test_match_data_with_multi_group path = Pattern.build( "/page/:name/:id", - { :name => /t(((ender|love)))()/ }, + { name: /t(((ender|love)))()/ }, SEPARATORS, true ) @@ -174,7 +174,7 @@ module ActionDispatch z = /\d+/ path = Pattern.build( "/page/*foo", - { :foo => z }, + { foo: z }, SEPARATORS, true ) @@ -184,7 +184,7 @@ module ActionDispatch def test_insensitive_regexp_with_group path = Pattern.build( "/page/:name/aaron", - { :name => /(tender|love)/i }, + { name: /(tender|love)/i }, SEPARATORS, true ) diff --git a/actionpack/test/journey/route_test.rb b/actionpack/test/journey/route_test.rb index 7e03259827..5364f9de81 100644 --- a/actionpack/test/journey/route_test.rb +++ b/actionpack/test/journey/route_test.rb @@ -34,63 +34,63 @@ module ActionDispatch def test_ip_address path = Path::Pattern.from_string "/messages/:id(.:format)" - route = Route.build("name", nil, path, {:ip => "192.168.1.1"}, [], - { :controller => "foo", :action => "bar" }) + route = Route.build("name", nil, path, {ip: "192.168.1.1"}, [], + { controller: "foo", action: "bar" }) assert_equal "192.168.1.1", route.ip end def test_default_ip path = Path::Pattern.from_string "/messages/:id(.:format)" route = Route.build("name", nil, path, {}, [], - { :controller => "foo", :action => "bar" }) + { controller: "foo", action: "bar" }) assert_equal(//, route.ip) end def test_format_with_star path = Path::Pattern.from_string "/:controller/*extra" route = Route.build("name", nil, path, {}, [], - { :controller => "foo", :action => "bar" }) + { controller: "foo", action: "bar" }) assert_equal "/foo/himom", route.format({ - :controller => "foo", - :extra => "himom", + controller: "foo", + extra: "himom", }) end def test_connects_all_match path = Path::Pattern.from_string "/:controller(/:action(/:id(.:format)))" - route = Route.build("name", nil, path, {:action => "bar"}, [], { :controller => "foo" }) + route = Route.build("name", nil, path, {action: "bar"}, [], { controller: "foo" }) assert_equal "/foo/bar/10", route.format({ - :controller => "foo", - :action => "bar", - :id => 10 + controller: "foo", + action: "bar", + id: 10 }) end def test_extras_are_not_included_if_optional path = Path::Pattern.from_string "/page/:id(/:action)" - route = Route.build("name", nil, path, { }, [], { :action => "show" }) + route = Route.build("name", nil, path, { }, [], { action: "show" }) - assert_equal "/page/10", route.format({ :id => 10 }) + assert_equal "/page/10", route.format({ id: 10 }) end def test_extras_are_not_included_if_optional_with_parameter path = Path::Pattern.from_string "(/sections/:section)/pages/:id" - route = Route.build("name", nil, path, { }, [], { :action => "show" }) + route = Route.build("name", nil, path, { }, [], { action: "show" }) - assert_equal "/pages/10", route.format({:id => 10}) + assert_equal "/pages/10", route.format({id: 10}) end def test_extras_are_not_included_if_optional_parameter_is_nil path = Path::Pattern.from_string "(/sections/:section)/pages/:id" - route = Route.build("name", nil, path, { }, [], { :action => "show" }) + route = Route.build("name", nil, path, { }, [], { action: "show" }) - assert_equal "/pages/10", route.format({:id => 10, :section => nil}) + assert_equal "/pages/10", route.format({id: 10, section: nil}) end def test_score constraints = {} - defaults = {:controller=>"pages", :action=>"show"} + defaults = {controller: "pages", action: "show"} path = Path::Pattern.from_string "/page/:id(/:action)(.:format)" specific = Route.build "name", nil, path, constraints, [:controller, :action], defaults @@ -98,7 +98,7 @@ module ActionDispatch path = Path::Pattern.from_string "/:controller(/:action(/:id))(.:format)" generic = Route.build "name", nil, path, constraints, [], {} - knowledge = {:id=>20, :controller=>"pages", :action=>"show"} + knowledge = {id: 20, controller: "pages", action: "show"} routes = [specific, generic] diff --git a/actionpack/test/journey/router_test.rb b/actionpack/test/journey/router_test.rb index fb595e8bea..97d3bc9845 100644 --- a/actionpack/test/journey/router_test.rb +++ b/actionpack/test/journey/router_test.rb @@ -38,7 +38,7 @@ module ActionDispatch end def test_regexp_first_precedence - get "/whois/:domain", :domain => /\w+\.[\w\.]+/, to: "foo#bar" + get "/whois/:domain", domain: /\w+\.[\w\.]+/, to: "foo#bar" get "/whois/:id(.:format)", to: "foo#baz" env = rails_env "PATH_INFO" => "/whois/example.com" @@ -55,40 +55,40 @@ module ActionDispatch end def test_required_parts_verified_are_anchored - get "/foo/:id", :id => /\d/, anchor: false, to: "foo#bar" + get "/foo/:id", id: /\d/, anchor: false, to: "foo#bar" assert_raises(ActionController::UrlGenerationError) do - @formatter.generate(nil, { :controller => "foo", :action => "bar", :id => "10" }, { }) + @formatter.generate(nil, { controller: "foo", action: "bar", id: "10" }, { }) end end def test_required_parts_are_verified_when_building - get "/foo/:id", :id => /\d+/, anchor: false, to: "foo#bar" + get "/foo/:id", id: /\d+/, anchor: false, to: "foo#bar" - path, _ = @formatter.generate(nil, { :controller => "foo", :action => "bar", :id => "10" }, { }) + path, _ = @formatter.generate(nil, { controller: "foo", action: "bar", id: "10" }, { }) assert_equal "/foo/10", path assert_raises(ActionController::UrlGenerationError) do - @formatter.generate(nil, { :id => "aa" }, { }) + @formatter.generate(nil, { id: "aa" }, { }) end end def test_only_required_parts_are_verified - get "/foo(/:id)", :id => /\d/, :to => "foo#bar" + get "/foo(/:id)", id: /\d/, to: "foo#bar" - path, _ = @formatter.generate(nil, { :controller => "foo", :action => "bar", :id => "10" }, { }) + path, _ = @formatter.generate(nil, { controller: "foo", action: "bar", id: "10" }, { }) assert_equal "/foo/10", path - path, _ = @formatter.generate(nil, { :controller => "foo", :action => "bar" }, { }) + path, _ = @formatter.generate(nil, { controller: "foo", action: "bar" }, { }) assert_equal "/foo", path - path, _ = @formatter.generate(nil, { :controller => "foo", :action => "bar", :id => "aa" }, { }) + path, _ = @formatter.generate(nil, { controller: "foo", action: "bar", id: "aa" }, { }) assert_equal "/foo/aa", path end def test_knows_what_parts_are_missing_from_named_route route_name = "gorby_thunderhorse" - get "/foo/:id", :as => route_name, :id => /\d+/, :to => "foo#bar" + get "/foo/:id", as: route_name, id: /\d+/, to: "foo#bar" error = assert_raises(ActionController::UrlGenerationError) do @formatter.generate(route_name, { }, { }) @@ -117,7 +117,7 @@ module ActionDispatch def test_clear_trailing_slash_from_script_name_on_root_unanchored_routes app = lambda { |env| [200, {}, ["success!"]] } - get "/weblog", :to => app + get "/weblog", to: app env = rack_env("SCRIPT_NAME" => "", "PATH_INFO" => "/weblog") resp = route_set.call env @@ -130,12 +130,12 @@ module ActionDispatch env = rails_env "PATH_INFO" => "/foo/10" router.recognize(env) do |r, params| - assert_equal({:id => "10", :controller => "foo", :action => "bar"}, params) + assert_equal({id: "10", controller: "foo", action: "bar"}, params) end env = rails_env "PATH_INFO" => "/foo" router.recognize(env) do |r, params| - assert_equal({:id => nil, :controller => "foo", :action => "bar"}, params) + assert_equal({id: nil, controller: "foo", action: "bar"}, params) end end @@ -184,14 +184,14 @@ module ActionDispatch def test_required_part_in_recall get "/messages/:a/:b", to: "foo#bar" - path, _ = @formatter.generate(nil, { :controller => "foo", :action => "bar", :a => "a" }, { :b => "b" }) + path, _ = @formatter.generate(nil, { controller: "foo", action: "bar", a: "a" }, { b: "b" }) assert_equal "/messages/a/b", path end def test_splat_in_recall get "/*path", to: "foo#bar" - path, _ = @formatter.generate(nil, { :controller => "foo", :action => "bar" }, { :path => "b" }) + path, _ = @formatter.generate(nil, { controller: "foo", action: "bar" }, { path: "b" }) assert_equal "/b", path end @@ -199,15 +199,15 @@ module ActionDispatch get "/messages/:action(/:id(.:format))", to: "foo#bar" get "/messages/:id(.:format)", to: "bar#baz" - path, _ = @formatter.generate(nil, { :controller => "foo", :id => 10 }, { :action => "index" }) + path, _ = @formatter.generate(nil, { controller: "foo", id: 10 }, { action: "index" }) assert_equal "/messages/index/10", path end def test_nil_path_parts_are_ignored get "/:controller(/:action(.:format))", to: "tasks#lol" - params = { :controller => "tasks", :format => nil } - extras = { :action => "lol" } + params = { controller: "tasks", format: nil } + extras = { action: "lol" } path, _ = @formatter.generate(nil, params, extras) assert_equal "/tasks", path @@ -242,17 +242,17 @@ module ActionDispatch get "/:controller(/:action)", to: "foo#bar" path, params = @formatter.generate( - nil, {:id=>1, :controller=>"tasks", :action=>"show"}, {}) + nil, {id: 1, controller: "tasks", action: "show"}, {}) assert_equal "/tasks/show", path - assert_equal({:id => 1}, params) + assert_equal({id: 1}, params) end def test_generate_escapes get "/:controller(/:action)", to: "foo#bar" path, _ = @formatter.generate(nil, - { :controller => "tasks", - :action => "a/b c+d", + { controller: "tasks", + action: "a/b c+d", }, {}) assert_equal "/tasks/a%2Fb%20c+d", path end @@ -261,8 +261,8 @@ module ActionDispatch get "/:controller(/:action)", to: "foo#bar" path, _ = @formatter.generate( - nil, { :controller => "admin/tasks", - :action => "a/b c+d", + nil, { controller: "admin/tasks", + action: "a/b c+d", }, {}) assert_equal "/admin/tasks/a%2Fb%20c+d", path end @@ -271,22 +271,22 @@ module ActionDispatch get "/:controller(/:action)", to: "foo#bar" path, params = @formatter.generate( - nil, { :id => 1, - :controller => "tasks", - :action => "show", - :relative_url_root => nil + nil, { id: 1, + controller: "tasks", + action: "show", + relative_url_root: nil }, {}) assert_equal "/tasks/show", path - assert_equal({:id => 1, :relative_url_root => nil}, params) + assert_equal({id: 1, relative_url_root: nil}, params) end def test_generate_missing_keys_no_matches_different_format_keys get "/:controller/:action/:name", to: "foo#bar" primarty_parameters = { - :id => 1, - :controller => "tasks", - :action => "show", - :relative_url_root => nil + id: 1, + controller: "tasks", + action: "show", + relative_url_root: nil } redirection_parameters = { "action"=>"show", @@ -311,8 +311,8 @@ module ActionDispatch path, params = @formatter.generate( nil, - {:controller =>"tasks", :id => 10}, - {:action =>"index"}) + {controller: "tasks", id: 10}, + {action: "index"}) assert_equal "/tasks/index/10", path assert_equal({}, params) end @@ -322,16 +322,16 @@ module ActionDispatch path, params = @formatter.generate( "tasks", - {:controller=>"tasks"}, - {:controller=>"tasks", :action=>"index"}) + {controller: "tasks"}, + {controller: "tasks", action: "index"}) assert_equal "/tasks", path assert_equal({}, params) end { - "/content" => { :controller => "content" }, - "/content/list" => { :controller => "content", :action => "list" }, - "/content/show/10" => { :controller => "content", :action => "show", :id => "10" }, + "/content" => { controller: "content" }, + "/content/list" => { controller: "content", action: "list" }, + "/content/show/10" => { controller: "content", action: "show", id: "10" }, }.each do |request_path, expected| define_method("test_recognize_#{expected.keys.map(&:to_s).join('_')}") do get "/:controller(/:action(/:id))", to: "foo#bar" @@ -342,7 +342,7 @@ module ActionDispatch router.recognize(env) do |r, params| assert_equal route, r - assert_equal({ :action => "bar" }.merge(expected), params) + assert_equal({ action: "bar" }.merge(expected), params) called = true end @@ -351,8 +351,8 @@ module ActionDispatch end { - :segment => ["/a%2Fb%20c+d/splat", { :segment => "a/b c+d", :splat => "splat" }], - :splat => ["/segment/a/b%20c+d", { :segment => "segment", :splat => "a/b c+d" }] + segment: ["/a%2Fb%20c+d/splat", { segment: "a/b c+d", splat: "splat" }], + splat: ["/segment/a/b%20c+d", { segment: "segment", splat: "a/b c+d" }] }.each do |name, (request_path, expected)| define_method("test_recognize_#{name}") do get "/:segment/*splat", to: "foo#bar" @@ -363,7 +363,7 @@ module ActionDispatch router.recognize(env) do |r, params| assert_equal route, r - assert_equal(expected.merge(:controller=>"foo", :action=>"bar"), params) + assert_equal(expected.merge(controller: "foo", action: "bar"), params) called = true end @@ -372,15 +372,15 @@ module ActionDispatch end def test_namespaced_controller - get "/:controller(/:action(/:id))", { :controller => /.+?/ } + get "/:controller(/:action(/:id))", { controller: /.+?/ } route = @routes.first env = rails_env "PATH_INFO" => "/admin/users/show/10" called = false expected = { - :controller => "admin/users", - :action => "show", - :id => "10" + controller: "admin/users", + action: "show", + id: "10" } router.recognize(env) do |r, params| @@ -396,7 +396,7 @@ module ActionDispatch route = @routes.first env = rails_env "PATH_INFO" => "/books/list.rss" - expected = { :controller => "books", :action => "list", :format => "rss" } + expected = { controller: "books", action: "list", format: "rss" } called = false router.recognize(env) do |r, params| assert_equal route, r |