From d20a52930aa80d7f219465d6fc414a68b16ef2a8 Mon Sep 17 00:00:00 2001 From: AvnerCohen Date: Wed, 31 Oct 2012 21:19:44 +0200 Subject: [PATCH] 1.9 hash syntax changes to docs --- .../lib/action_dispatch/http/mime_type.rb | 4 +- .../lib/action_dispatch/middleware/cookies.rb | 14 +-- .../middleware/session/cookie_store.rb | 4 +- .../templates/rescues/diagnostics.erb | 4 +- .../templates/rescues/routing_error.erb | 2 +- .../templates/rescues/template_error.erb | 4 +- actionpack/lib/action_dispatch/routing.rb | 48 ++++---- .../lib/action_dispatch/routing/mapper.rb | 110 +++++++++--------- .../routing/polymorphic_routes.rb | 6 +- .../action_dispatch/routing/redirection.rb | 8 +- .../lib/action_dispatch/routing/route_set.rb | 12 +- .../lib/action_dispatch/routing/url_for.rb | 30 ++--- .../testing/assertions/response.rb | 6 +- .../testing/assertions/routing.rb | 30 ++--- .../testing/assertions/selector.rb | 2 +- .../action_dispatch/testing/assertions/tag.rb | 38 +++--- .../action_dispatch/testing/integration.rb | 12 +- .../action_dispatch/testing/test_process.rb | 4 +- 18 files changed, 169 insertions(+), 169 deletions(-) diff --git a/actionpack/lib/action_dispatch/http/mime_type.rb b/actionpack/lib/action_dispatch/http/mime_type.rb index 3d560518e1..2b5d3d85bf 100644 --- a/actionpack/lib/action_dispatch/http/mime_type.rb +++ b/actionpack/lib/action_dispatch/http/mime_type.rb @@ -44,8 +44,8 @@ module Mime # # respond_to do |format| # format.html - # format.ics { render :text => post.to_ics, :mime_type => Mime::Type["text/calendar"] } - # format.xml { render :xml => @people } + # format.ics { render text: post.to_ics, mime_type: Mime::Type["text/calendar"] } + # format.xml { render xml: @people } # end # end # end diff --git a/actionpack/lib/action_dispatch/middleware/cookies.rb b/actionpack/lib/action_dispatch/middleware/cookies.rb index ba5d332d49..eaf922595a 100644 --- a/actionpack/lib/action_dispatch/middleware/cookies.rb +++ b/actionpack/lib/action_dispatch/middleware/cookies.rb @@ -24,7 +24,7 @@ module ActionDispatch # cookies[:lat_lon] = [47.68, -122.37] # # # Sets a cookie that expires in 1 hour. - # cookies[:login] = { :value => "XJ-122", :expires => 1.hour.from_now } + # cookies[:login] = { value: "XJ-122", expires: 1.hour.from_now } # # # Sets a signed cookie, which prevents users from tampering with its value. # # The cookie is signed by your app's config.secret_token value. @@ -51,12 +51,12 @@ module ActionDispatch # Please note that if you specify a :domain when setting a cookie, you must also specify the domain when deleting the cookie: # # cookies[:key] = { - # :value => 'a yummy cookie', - # :expires => 1.year.from_now, - # :domain => 'domain.com' + # value: 'a yummy cookie', + # expires: 1.year.from_now, + # domain: 'domain.com' # } # - # cookies.delete(:key, :domain => 'domain.com') + # cookies.delete(:key, domain: 'domain.com') # # The option symbols for setting cookies are: # @@ -69,8 +69,8 @@ module ActionDispatch # to :all. Make sure to specify the :domain option with # :all again when deleting keys. # - # :domain => nil # Does not sets cookie domain. (default) - # :domain => :all # Allow the cookie for the top most level + # domain: nil # Does not sets cookie domain. (default) + # domain: :all # Allow the cookie for the top most level # domain and subdomains. # # * :expires - The time at which this cookie expires, as a \Time object. diff --git a/actionpack/lib/action_dispatch/middleware/session/cookie_store.rb b/actionpack/lib/action_dispatch/middleware/session/cookie_store.rb index 019849ef95..3f28ea75ef 100644 --- a/actionpack/lib/action_dispatch/middleware/session/cookie_store.rb +++ b/actionpack/lib/action_dispatch/middleware/session/cookie_store.rb @@ -28,8 +28,8 @@ module ActionDispatch # a secret consisting of random numbers and letters and more than 30 # characters. # - # :secret => '449fe2e7daee471bffae2fd8dc02313d' - # :secret => Proc.new { User.current_user.secret_key } + # secret: '449fe2e7daee471bffae2fd8dc02313d' + # secret: Proc.new { User.current_user.secret_key } # # * :digest: The message digest algorithm used to verify session # integrity defaults to 'SHA1' but may be any digest provided by OpenSSL, diff --git a/actionpack/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb b/actionpack/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb index 4b9d3141d5..c5043c5e7b 100644 --- a/actionpack/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb +++ b/actionpack/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb @@ -6,5 +6,5 @@
<%=h @exception.message %>
-<%= render :template => "rescues/_trace" %> -<%= render :template => "rescues/_request_and_response" %> +<%= render template: "rescues/_trace" %> +<%= render template: "rescues/_request_and_response" %> diff --git a/actionpack/lib/action_dispatch/middleware/templates/rescues/routing_error.erb b/actionpack/lib/action_dispatch/middleware/templates/rescues/routing_error.erb index 8c594c1523..a357a7ba11 100644 --- a/actionpack/lib/action_dispatch/middleware/templates/rescues/routing_error.erb +++ b/actionpack/lib/action_dispatch/middleware/templates/rescues/routing_error.erb @@ -10,7 +10,7 @@

<% end %> -<%= render :template => "rescues/_trace" %> +<%= render template: "rescues/_trace" %>

Routes diff --git a/actionpack/lib/action_dispatch/middleware/templates/rescues/template_error.erb b/actionpack/lib/action_dispatch/middleware/templates/rescues/template_error.erb index c658559be9..a1b377f68c 100644 --- a/actionpack/lib/action_dispatch/middleware/templates/rescues/template_error.erb +++ b/actionpack/lib/action_dispatch/middleware/templates/rescues/template_error.erb @@ -13,5 +13,5 @@

<%=h @exception.sub_template_message %>

-<%= render :template => "rescues/_trace" %> -<%= render :template => "rescues/_request_and_response" %> +<%= render template: "rescues/_trace" %> +<%= render template: "rescues/_request_and_response" %> diff --git a/actionpack/lib/action_dispatch/routing.rb b/actionpack/lib/action_dispatch/routing.rb index 29090882a5..4417cb841a 100644 --- a/actionpack/lib/action_dispatch/routing.rb +++ b/actionpack/lib/action_dispatch/routing.rb @@ -61,7 +61,7 @@ module ActionDispatch # directory by using +scope+. +scope+ takes additional options which # apply to all enclosed routes. # - # scope :path => "/cpanel", :as => 'admin' do + # scope path: "/cpanel", as: 'admin' do # resources :posts, :comments # end # @@ -78,22 +78,22 @@ module ActionDispatch # Example: # # # In routes.rb - # match '/login' => 'accounts#login', :as => 'login' + # match '/login' => 'accounts#login', as: 'login' # # # With render, redirect_to, tests, etc. # redirect_to login_url # # Arguments can be passed as well. # - # redirect_to show_item_path(:id => 25) + # redirect_to show_item_path(id: 25) # # Use root as a shorthand to name a route for the root path "/". # # # In routes.rb - # root :to => 'blogs#index' + # root to: 'blogs#index' # # # would recognize http://www.example.com/ as - # params = { :controller => 'blogs', :action => 'index' } + # params = { controller: 'blogs', action: 'index' } # # # and provide these named routes # root_url # => 'http://www.example.com/' @@ -110,43 +110,43 @@ module ActionDispatch # end # # # provides named routes for show, delete, and edit - # link_to @article.title, show_path(:id => @article.id) + # link_to @article.title, show_path(id: @article.id) # # == Pretty URLs # # Routes can generate pretty URLs. For example: # - # match '/articles/:year/:month/:day' => 'articles#find_by_id', :constraints => { - # :year => /\d{4}/, - # :month => /\d{1,2}/, - # :day => /\d{1,2}/ + # match '/articles/:year/:month/:day' => 'articles#find_by_id', constraints: { + # year: /\d{4}/, + # month: /\d{1,2}/, + # day: /\d{1,2}/ # } # # Using the route above, the URL "http://localhost:3000/articles/2005/11/06" # maps to # - # params = {:year => '2005', :month => '11', :day => '06'} + # params = {year: '2005', month: '11', day: '06'} # # == Regular Expressions and parameters # You can specify a regular expression to define a format for a parameter. # # controller 'geocode' do - # match 'geocode/:postalcode' => :show, :constraints => { - # :postalcode => /\d{5}(-\d{4})?/ + # match 'geocode/:postalcode' => :show, constraints: { + # postalcode: /\d{5}(-\d{4})?/ # } # # Constraints can include the 'ignorecase' and 'extended syntax' regular # expression modifiers: # # controller 'geocode' do - # match 'geocode/:postalcode' => :show, :constraints => { - # :postalcode => /hx\d\d\s\d[a-z]{2}/i + # match 'geocode/:postalcode' => :show, constraints: { + # postalcode: /hx\d\d\s\d[a-z]{2}/i # } # end # # controller 'geocode' do - # match 'geocode/:postalcode' => :show, :constraints => { - # :postalcode => /# Postcode format + # match 'geocode/:postalcode' => :show, constraints: { + # postalcode: /# Postcode format # \d{5} #Prefix # (-\d{4})? #Suffix # /x @@ -172,9 +172,9 @@ module ActionDispatch # Suppose you get an incoming request for /blog/edit/22, you'll end # up with: # - # params = { :controller => 'blog', - # :action => 'edit', - # :id => '22' + # params = { controller: 'blog', + # action: 'edit', + # id: '22' # } # # By not relying on default routes, you improve the security of your @@ -193,8 +193,8 @@ module ActionDispatch # # Examples: # - # match 'post/:id' => 'posts#show', :via => :get - # match 'post/:id' => 'posts#create_comment', :via => :post + # match 'post/:id' => 'posts#show', via: :get + # match 'post/:id' => 'posts#create_comment', via: :post # # Now, if you POST to /posts/:id, it will route to the create_comment action. A GET on the same # URL will route to the show action. @@ -249,7 +249,7 @@ module ActionDispatch # === +assert_routing+ # # def test_movie_route_properly_splits - # opts = {:controller => "plugin", :action => "checkout", :id => "2"} + # opts = {controller: "plugin", action: "checkout", id: "2"} # assert_routing "plugin/checkout/2", opts # end # @@ -258,7 +258,7 @@ module ActionDispatch # === +assert_recognizes+ # # def test_route_has_options - # opts = {:controller => "plugin", :action => "show", :id => "12"} + # opts = {controller: "plugin", action: "show", id: "12"} # assert_recognizes opts, "/plugins/show/12" # end # diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb index c5cf413c8f..e337e30766 100644 --- a/actionpack/lib/action_dispatch/routing/mapper.rb +++ b/actionpack/lib/action_dispatch/routing/mapper.rb @@ -121,7 +121,7 @@ module ActionDispatch # Add a default constraint for :controller path segments that matches namespaced # controllers with default routes like :controller/:action/:id(.:format), e.g: # GET /admin/products/show/1 - # => { :controller => 'admin/products', :action => 'show', :id => '1' } + # => { controller: 'admin/products', action: 'show', id: '1' } @options[:controller] ||= /.+?/ end @@ -272,7 +272,7 @@ module ActionDispatch module Base # You can specify what Rails should route "/" to with the root method: # - # root :to => 'pages#main' + # root to: 'pages#main' # # For options, see +match+, as +root+ uses it internally. # @@ -309,8 +309,8 @@ module ActionDispatch # +:controller+ should be set in options or hash shorthand. Examples: # # match 'photos/:id' => 'photos#show' - # match 'photos/:id', :to => 'photos#show' - # match 'photos/:id', :controller => 'photos', :action => 'show' + # match 'photos/:id', to: 'photos#show' + # match 'photos/:id', controller: 'photos', action: 'show' # # A pattern can also point to a +Rack+ endpoint i.e. anything that # responds to +call+: @@ -336,7 +336,7 @@ module ActionDispatch # [:module] # The namespace for :controller. # - # match 'path' => 'c#a', :module => 'sekret', :controller => 'posts' + # match 'path' => 'c#a', module: 'sekret', controller: 'posts' # #=> Sekret::PostsController # # See Scoping#namespace for its scope equivalent. @@ -347,16 +347,16 @@ module ActionDispatch # [:via] # Allowed HTTP verb(s) for route. # - # match 'path' => 'c#a', :via => :get - # match 'path' => 'c#a', :via => [:get, :post] + # match 'path' => 'c#a', via: :get + # match 'path' => 'c#a', via: [:get, :post] # # [:to] # Points to a +Rack+ endpoint. Can be an object that responds to # +call+ or a string representing a controller's action. # - # match 'path', :to => 'controller#action' - # match 'path', :to => lambda { |env| [200, {}, "Success!"] } - # match 'path', :to => RackApp + # match 'path', to: 'controller#action' + # match 'path', to: lambda { |env| [200, {}, "Success!"] } + # match 'path', to: RackApp # # [:on] # Shorthand for wrapping routes in a specific RESTful context. Valid @@ -364,14 +364,14 @@ module ActionDispatch # resource(s) block. For example: # # resource :bar do - # match 'foo' => 'c#a', :on => :member, :via => [:get, :post] + # match 'foo' => 'c#a', on: :member, via: [:get, :post] # end # # Is equivalent to: # # resource :bar do # member do - # match 'foo' => 'c#a', :via => [:get, :post] + # match 'foo' => 'c#a', via: [:get, :post] # end # end # @@ -379,12 +379,12 @@ module ActionDispatch # Constrains parameters with a hash of regular expressions or an # object that responds to matches? # - # match 'path/:id', :constraints => { :id => /[A-Z]\d{5}/ } + # match 'path/:id', constraints: { id: /[A-Z]\d{5}/ } # # class Blacklist # def matches?(request) request.remote_ip == '1.2.3.4' end # end - # match 'path' => 'c#a', :constraints => Blacklist.new + # match 'path' => 'c#a', constraints: Blacklist.new # # See Scoping#constraints for more examples with its scope # equivalent. @@ -393,7 +393,7 @@ module ActionDispatch # Sets defaults for parameters # # # Sets params[:format] to 'jpg' by default - # match 'path' => 'c#a', :defaults => { :format => 'jpg' } + # match 'path' => 'c#a', defaults: { format: 'jpg' } # # See Scoping#defaults for its scope equivalent. # @@ -402,7 +402,7 @@ module ActionDispatch # false, the pattern matches any request prefixed with the given path. # # # Matches any request starting with 'path' - # match 'path' => 'c#a', :anchor => false + # match 'path' => 'c#a', anchor: false # # [:format] # Allows you to specify the default value for optional +format+ @@ -412,7 +412,7 @@ module ActionDispatch # Mount a Rack-based application to be used within the application. # - # mount SomeRackApp, :at => "some_route" + # mount SomeRackApp, at: "some_route" # # Alternatively: # @@ -425,7 +425,7 @@ module ActionDispatch # the helper is either +some_rack_app_path+ or +some_rack_app_url+. # To customize this helper's name, use the +:as+ option: # - # mount(SomeRackApp => "some_route", :as => "exciting") + # mount(SomeRackApp => "some_route", as: "exciting") # # This will generate the +exciting_path+ and +exciting_url+ helpers # which can be used to navigate to this mounted app. @@ -503,7 +503,7 @@ module ActionDispatch # Define a route that only recognizes HTTP GET. # For supported arguments, see Base#match. # - # get 'bacon', :to => 'food#bacon' + # get 'bacon', to: 'food#bacon' def get(*args, &block) map_method(:get, args, &block) end @@ -511,7 +511,7 @@ module ActionDispatch # Define a route that only recognizes HTTP POST. # For supported arguments, see Base#match. # - # post 'bacon', :to => 'food#bacon' + # post 'bacon', to: 'food#bacon' def post(*args, &block) map_method(:post, args, &block) end @@ -519,7 +519,7 @@ module ActionDispatch # Define a route that only recognizes HTTP PATCH. # For supported arguments, see Base#match. # - # patch 'bacon', :to => 'food#bacon' + # patch 'bacon', to: 'food#bacon' def patch(*args, &block) map_method(:patch, args, &block) end @@ -527,7 +527,7 @@ module ActionDispatch # Define a route that only recognizes HTTP PUT. # For supported arguments, see Base#match. # - # put 'bacon', :to => 'food#bacon' + # put 'bacon', to: 'food#bacon' def put(*args, &block) map_method(:put, args, &block) end @@ -535,7 +535,7 @@ module ActionDispatch # Define a route that only recognizes HTTP DELETE. # For supported arguments, see Base#match. # - # delete 'broccoli', :to => 'food#broccoli' + # delete 'broccoli', to: 'food#broccoli' def delete(*args, &block) map_method(:delete, args, &block) end @@ -574,13 +574,13 @@ module ActionDispatch # If you want to route /posts (without the prefix /admin) to # Admin::PostsController, you could use # - # scope :module => "admin" do + # scope module: "admin" do # resources :posts # end # # or, for a single case # - # resources :posts, :module => "admin" + # resources :posts, module: "admin" # # If you want to route /admin/posts to +PostsController+ # (without the Admin:: module prefix), you could use @@ -591,7 +591,7 @@ module ActionDispatch # # or, for a single case # - # resources :posts, :path => "/admin/posts" + # resources :posts, path: "/admin/posts" # # In each of these cases, the named routes remain the same as if you did # not use scope. In the last case, the following paths map to @@ -609,7 +609,7 @@ module ActionDispatch # # Take the following route definition as an example: # - # scope :path => ":account_id", :as => "account" do + # scope path: ":account_id", as: "account" do # resources :projects # end # @@ -624,17 +624,17 @@ module ActionDispatch # === Examples # # # route /posts (without the prefix /admin) to Admin::PostsController - # scope :module => "admin" do + # scope module: "admin" do # resources :posts # end # # # prefix the posts resource's requests with '/admin' - # scope :path => "/admin" do + # scope path: "/admin" do # resources :posts # end # # # prefix the routing helper name: +sekret_posts_path+ instead of +posts_path+ - # scope :as => "sekret" do + # scope as: "sekret" do # resources :posts # end def scope(*args) @@ -680,7 +680,7 @@ module ActionDispatch # Scopes routes to a specific controller # # controller "food" do - # match "bacon", :action => "bacon" + # match "bacon", action: "bacon" # end def controller(controller, options={}) options[:controller] = controller @@ -714,17 +714,17 @@ module ActionDispatch # === Examples # # # accessible through /sekret/posts rather than /admin/posts - # namespace :admin, :path => "sekret" do + # namespace :admin, path: "sekret" do # resources :posts # end # # # maps to Sekret::PostsController rather than Admin::PostsController - # namespace :admin, :module => "sekret" do + # namespace :admin, module: "sekret" do # resources :posts # end # # # generates +sekret_posts_path+ rather than +admin_posts_path+ - # namespace :admin, :as => "sekret" do + # namespace :admin, as: "sekret" do # resources :posts # end def namespace(path, options = {}) @@ -738,7 +738,7 @@ module ActionDispatch # Allows you to constrain the nested routes based on a set of rules. # For instance, in order to change the routes to allow for a dot character in the +id+ parameter: # - # constraints(:id => /\d+\.\d+/) do + # constraints(id: /\d+\.\d+/) do # resources :posts # end # @@ -748,7 +748,7 @@ module ActionDispatch # You may use this to also restrict other parameters: # # resources :posts do - # constraints(:post_id => /\d+\.\d+/) do + # constraints(post_id: /\d+\.\d+/) do # resources :comments # end # end @@ -757,7 +757,7 @@ module ActionDispatch # # Routes can also be constrained to an IP or a certain range of IP addresses: # - # constraints(:ip => /192\.168\.\d+\.\d+/) do + # constraints(ip: /192\.168\.\d+\.\d+/) do # resources :posts # end # @@ -794,8 +794,8 @@ module ActionDispatch end # Allows you to set default parameters for a route, such as this: - # defaults :id => 'home' do - # match 'scoped_pages/(:id)', :to => 'pages#show' + # defaults id: 'home' do + # match 'scoped_pages/(:id)', to: 'pages#show' # end # Using this, the +:id+ parameter here will default to 'home'. def defaults(defaults = {}) @@ -902,7 +902,7 @@ module ActionDispatch # use dots as part of the +:id+ parameter add a constraint which # overrides this restriction, e.g: # - # resources :articles, :id => /[^\/]+/ + # resources :articles, id: /[^\/]+/ # # This allows any character other than a slash as part of your +:id+. # @@ -1112,43 +1112,43 @@ module ActionDispatch # Allows you to change the segment component of the +edit+ and +new+ actions. # Actions not specified are not changed. # - # resources :posts, :path_names => { :new => "brand_new" } + # resources :posts, path_names: { new: "brand_new" } # # The above example will now change /posts/new to /posts/brand_new # # [:path] # Allows you to change the path prefix for the resource. # - # resources :posts, :path => 'postings' + # resources :posts, path: 'postings' # # The resource and all segments will now route to /postings instead of /posts # # [:only] # Only generate routes for the given actions. # - # resources :cows, :only => :show - # resources :cows, :only => [:show, :index] + # resources :cows, only: :show + # resources :cows, only: [:show, :index] # # [:except] # Generate all routes except for the given actions. # - # resources :cows, :except => :show - # resources :cows, :except => [:show, :index] + # resources :cows, except: :show + # resources :cows, except: [:show, :index] # # [:shallow] # Generates shallow routes for nested resource(s). When placed on a parent resource, # generates shallow routes for all nested resources. # - # resources :posts, :shallow => true do + # resources :posts, shallow: true do # resources :comments # end # # Is the same as: # # resources :posts do - # resources :comments, :except => [:show, :edit, :update, :destroy] + # resources :comments, except: [:show, :edit, :update, :destroy] # end - # resources :comments, :only => [:show, :edit, :update, :destroy] + # resources :comments, only: [:show, :edit, :update, :destroy] # # This allows URLs for resources that otherwise would be deeply nested such # as a comment on a blog post like /posts/a-long-permalink/comments/1234 @@ -1157,9 +1157,9 @@ module ActionDispatch # [:shallow_path] # Prefixes nested shallow routes with the specified path. # - # scope :shallow_path => "sekret" do + # scope shallow_path: "sekret" do # resources :posts do - # resources :comments, :shallow => true + # resources :comments, shallow: true # end # end # @@ -1176,9 +1176,9 @@ module ActionDispatch # [:shallow_prefix] # Prefixes nested shallow route names with specified prefix. # - # scope :shallow_prefix => "sekret" do + # scope shallow_prefix: "sekret" do # resources :posts do - # resources :comments, :shallow => true + # resources :comments, shallow: true # end # end # @@ -1199,10 +1199,10 @@ module ActionDispatch # === Examples # # # routes call Admin::PostsController - # resources :posts, :module => "admin" + # resources :posts, module: "admin" # # # resource actions are at /admin/posts. - # resources :posts, :path => "admin/posts" + # resources :posts, path: "admin/posts" def resources(*resources, &block) options = resources.extract_options!.dup diff --git a/actionpack/lib/action_dispatch/routing/polymorphic_routes.rb b/actionpack/lib/action_dispatch/routing/polymorphic_routes.rb index 3d7b8878b8..497ac3d545 100644 --- a/actionpack/lib/action_dispatch/routing/polymorphic_routes.rb +++ b/actionpack/lib/action_dispatch/routing/polymorphic_routes.rb @@ -34,7 +34,7 @@ module ActionDispatch # == Prefixed polymorphic helpers # # In addition to polymorphic_url and polymorphic_path methods, a - # number of prefixed helpers are available as a shorthand to :action => "..." + # number of prefixed helpers are available as a shorthand to action: "..." # in options. Those are: # # * edit_polymorphic_url, edit_polymorphic_path @@ -43,7 +43,7 @@ module ActionDispatch # Example usage: # # edit_polymorphic_path(@post) # => "/posts/1/edit" - # polymorphic_path(@post, :format => :pdf) # => "/posts/1.pdf" + # polymorphic_path(@post, format: :pdf) # => "/posts/1.pdf" # # == Usage with mounted engines # @@ -132,7 +132,7 @@ module ActionDispatch end # Returns the path component of a URL for the given record. It uses - # polymorphic_url with :routing_type => :path. + # polymorphic_url with routing_type: :path. def polymorphic_path(record_or_hash_or_array, options = {}) polymorphic_url(record_or_hash_or_array, options.merge(:routing_type => :path)) end diff --git a/actionpack/lib/action_dispatch/routing/redirection.rb b/actionpack/lib/action_dispatch/routing/redirection.rb index 205ff44b1c..1ed5eb1dff 100644 --- a/actionpack/lib/action_dispatch/routing/redirection.rb +++ b/actionpack/lib/action_dispatch/routing/redirection.rb @@ -102,7 +102,7 @@ module ActionDispatch # # You can also use interpolation in the supplied redirect argument: # - # match 'docs/:article', :to => redirect('/wiki/%{article}') + # match 'docs/:article', to: redirect('/wiki/%{article}') # # Alternatively you can use one of the other syntaxes: # @@ -111,7 +111,7 @@ module ActionDispatch # params, depending of how many arguments your block accepts. A string is required as a # return value. # - # match 'jokes/:number', :to => redirect { |params, request| + # match 'jokes/:number', to: redirect { |params, request| # path = (params[:number].to_i.even? ? "wheres-the-beef" : "i-love-lamp") # "http://#{request.host_with_port}/#{path}" # } @@ -122,8 +122,8 @@ module ActionDispatch # The options version of redirect allows you to supply only the parts of the url which need # to change, it also supports interpolation of the path similar to the first example. # - # match 'stores/:name', :to => redirect(:subdomain => 'stores', :path => '/%{name}') - # match 'stores/:name(*all)', :to => redirect(:subdomain => 'stores', :path => '/%{name}%{all}') + # match 'stores/:name', to: redirect(subdomain: 'stores', path: '/%{name}') + # match 'stores/:name(*all)', to: redirect(subdomain: 'stores', path: '/%{name}%{all}') # # Finally, an object which responds to call can be supplied to redirect, allowing you to reuse # common redirect routes. The call method must accept two arguments, params and request, and return diff --git a/actionpack/lib/action_dispatch/routing/route_set.rb b/actionpack/lib/action_dispatch/routing/route_set.rb index 060d0bfa2f..61071d1228 100644 --- a/actionpack/lib/action_dispatch/routing/route_set.rb +++ b/actionpack/lib/action_dispatch/routing/route_set.rb @@ -176,11 +176,11 @@ module ActionDispatch # # Instead of: # - # foo_url(:bar => bar, :baz => baz, :bang => bang) + # foo_url(bar: bar, baz: baz, bang: bang) # # Also allow options hash, so you can do: # - # foo_url(bar, baz, bang, :sort_by => 'baz') + # foo_url(bar, baz, bang, sort_by: 'baz') # def define_url_helper(route, name, options) @module.module_eval <<-END_EVAL, __FILE__, __LINE__ + 1 @@ -471,7 +471,7 @@ module ActionDispatch # If an explicit :controller was given, always make :action explicit # too, so that action expiry works as expected for things like # - # generate({:controller => 'content'}, {:controller => 'content', :action => 'show'}) + # generate({controller: 'content'}, {controller: 'content', action: 'show'}) # # (the above is from the unit tests). In the above case, because the # controller was explicitly given, but no action, the action is implied to @@ -500,7 +500,7 @@ module ActionDispatch use_recall_for(:id) end - # if the current controller is "foo/bar/baz" and :controller => "baz/bat" + # if the current controller is "foo/bar/baz" and controller: "baz/bat" # is specified, the controller becomes "foo/baz/bat" def use_relative_controller! if !named_route && different_controller? && !controller.start_with?("/") @@ -516,8 +516,8 @@ module ActionDispatch @options[:controller] = controller.sub(%r{^/}, '') if controller end - # This handles the case of :action => nil being explicitly passed. - # It is identical to :action => "index" + # This handles the case of action: nil being explicitly passed. + # It is identical to action: "index" def handle_nil_action! if options.has_key?(:action) && options[:action].nil? options[:action] = 'index' diff --git a/actionpack/lib/action_dispatch/routing/url_for.rb b/actionpack/lib/action_dispatch/routing/url_for.rb index d4cd537048..76311c423a 100644 --- a/actionpack/lib/action_dispatch/routing/url_for.rb +++ b/actionpack/lib/action_dispatch/routing/url_for.rb @@ -18,8 +18,8 @@ module ActionDispatch # of parameters. For example, you've probably had the chance to write code # like this in one of your views: # - # <%= link_to('Click here', :controller => 'users', - # :action => 'new', :message => 'Welcome!') %> + # <%= link_to('Click here', controller: 'users', + # action: 'new', message: 'Welcome!') %> # # => "/users/new?message=Welcome%21" # # link_to, and all other functions that require URL generation functionality, @@ -28,22 +28,22 @@ module ActionDispatch # the same path as the above example by using the following code: # # include UrlFor - # url_for(:controller => 'users', - # :action => 'new', - # :message => 'Welcome!', - # :only_path => true) + # url_for(controller: 'users', + # action: 'new', + # message: 'Welcome!', + # only_path: true) # # => "/users/new?message=Welcome%21" # - # Notice the :only_path => true part. This is because UrlFor has no + # Notice the only_path: true part. This is because UrlFor has no # information about the website hostname that your Rails app is serving. So if you # want to include the hostname as well, then you must also pass the :host # argument: # # include UrlFor - # url_for(:controller => 'users', - # :action => 'new', - # :message => 'Welcome!', - # :host => 'www.example.com') + # url_for(controller: 'users', + # action: 'new', + # message: 'Welcome!', + # host: 'www.example.com') # # => "http://www.example.com/users/new?message=Welcome%21" # # By default, all controllers and views have access to a special version of url_for, @@ -134,13 +134,13 @@ module ActionDispatch # Any other key (:controller, :action, etc.) given to # +url_for+ is forwarded to the Routes module. # - # url_for :controller => 'tasks', :action => 'testing', :host => 'somehost.org', :port => '8080' + # url_for controller: 'tasks', action: 'testing', host: 'somehost.org', port: '8080' # # => 'http://somehost.org:8080/tasks/testing' - # url_for :controller => 'tasks', :action => 'testing', :host => 'somehost.org', :anchor => 'ok', :only_path => true + # url_for controller: 'tasks', action: 'testing', host: 'somehost.org', anchor: 'ok', only_path: true # # => '/tasks/testing#ok' - # url_for :controller => 'tasks', :action => 'testing', :trailing_slash => true + # url_for controller: 'tasks', action: 'testing', trailing_slash: true # # => 'http://somehost.org/tasks/testing/' - # url_for :controller => 'tasks', :action => 'testing', :host => 'somehost.org', :number => '33' + # url_for controller: 'tasks', action: 'testing', host: 'somehost.org', number: '33' # # => 'http://somehost.org/tasks/testing?number=33' def url_for(options = nil) case options diff --git a/actionpack/lib/action_dispatch/testing/assertions/response.rb b/actionpack/lib/action_dispatch/testing/assertions/response.rb index b15e0446de..44ed0ac1f3 100644 --- a/actionpack/lib/action_dispatch/testing/assertions/response.rb +++ b/actionpack/lib/action_dispatch/testing/assertions/response.rb @@ -35,11 +35,11 @@ module ActionDispatch end # Assert that the redirection options passed in match those of the redirect called in the latest action. - # This match can be partial, such that assert_redirected_to(:controller => "weblog") will also - # match the redirection of redirect_to(:controller => "weblog", :action => "show") and so on. + # This match can be partial, such that assert_redirected_to(controller: "weblog") will also + # match the redirection of redirect_to(controller: "weblog", action: "show") and so on. # # # assert that the redirection was to the "index" action on the WeblogController - # assert_redirected_to :controller => "weblog", :action => "index" + # assert_redirected_to controller: "weblog", action: "index" # # # assert that the redirection was to the named route login_url # assert_redirected_to login_url diff --git a/actionpack/lib/action_dispatch/testing/assertions/routing.rb b/actionpack/lib/action_dispatch/testing/assertions/routing.rb index 9de545b3c5..305bafc0c5 100644 --- a/actionpack/lib/action_dispatch/testing/assertions/routing.rb +++ b/actionpack/lib/action_dispatch/testing/assertions/routing.rb @@ -15,28 +15,28 @@ module ActionDispatch # and a :method containing the required HTTP verb. # # # assert that POSTing to /items will call the create action on ItemsController - # assert_recognizes({:controller => 'items', :action => 'create'}, {:path => 'items', :method => :post}) + # assert_recognizes({controller: 'items', action: 'create'}, {path: 'items', method: :post}) # # You can also pass in +extras+ with a hash containing URL parameters that would normally be in the query string. This can be used # to assert that values in the query string string will end up in the params hash correctly. To test query strings you must use the # extras argument, appending the query string on the path directly will not work. For example: # # # assert that a path of '/items/list/1?view=print' returns the correct options - # assert_recognizes({:controller => 'items', :action => 'list', :id => '1', :view => 'print'}, 'items/list/1', { :view => "print" }) + # assert_recognizes({controller: 'items', action: 'list', id: '1', view: 'print'}, 'items/list/1', { view: "print" }) # # The +message+ parameter allows you to pass in an error message that is displayed upon failure. # # # Check the default route (i.e., the index action) - # assert_recognizes({:controller => 'items', :action => 'index'}, 'items') + # assert_recognizes({controller: 'items', action: 'index'}, 'items') # # # Test a specific action - # assert_recognizes({:controller => 'items', :action => 'list'}, 'items/list') + # assert_recognizes({controller: 'items', action: 'list'}, 'items/list') # # # Test an action with a parameter - # assert_recognizes({:controller => 'items', :action => 'destroy', :id => '1'}, 'items/destroy/1') + # assert_recognizes({controller: 'items', action: 'destroy', id: '1'}, 'items/destroy/1') # # # Test a custom route - # assert_recognizes({:controller => 'items', :action => 'show', :id => '1'}, 'view/item1') + # assert_recognizes({controller: 'items', action: 'show', id: '1'}, 'view/item1') def assert_recognizes(expected_options, path, extras={}, message=nil) request = recognized_request_for(path, extras) @@ -57,16 +57,16 @@ module ActionDispatch # The +defaults+ parameter is unused. # # # Asserts that the default action is generated for a route with no action - # assert_generates "/items", :controller => "items", :action => "index" + # assert_generates "/items", controller: "items", action: "index" # # # Tests that the list action is properly routed - # assert_generates "/items/list", :controller => "items", :action => "list" + # assert_generates "/items/list", controller: "items", action: "list" # # # Tests the generation of a route with a parameter - # assert_generates "/items/list/1", { :controller => "items", :action => "list", :id => "1" } + # assert_generates "/items/list/1", { controller: "items", action: "list", id: "1" } # # # Asserts that the generated route gives us our custom route - # assert_generates "changesets/12", { :controller => 'scm', :action => 'show_diff', :revision => "12" } + # assert_generates "changesets/12", { controller: 'scm', action: 'show_diff', revision: "12" } def assert_generates(expected_path, options, defaults={}, extras = {}, message=nil) if expected_path =~ %r{://} fail_on(URI::InvalidURIError) do @@ -97,19 +97,19 @@ module ActionDispatch # +message+ parameter allows you to specify a custom error message to display upon failure. # # # Assert a basic route: a controller with the default action (index) - # assert_routing '/home', :controller => 'home', :action => 'index' + # assert_routing '/home', controller: 'home', action: 'index' # # # Test a route generated with a specific controller, action, and parameter (id) - # assert_routing '/entries/show/23', :controller => 'entries', :action => 'show', :id => 23 + # assert_routing '/entries/show/23', controller: 'entries', action: 'show', id: 23 # # # Assert a basic route (controller + default action), with an error message if it fails - # assert_routing '/store', { :controller => 'store', :action => 'index' }, {}, {}, 'Route for store index not generated properly' + # assert_routing '/store', { controller: 'store', action: 'index' }, {}, {}, 'Route for store index not generated properly' # # # Tests a route, providing a defaults hash - # assert_routing 'controller/action/9', {:id => "9", :item => "square"}, {:controller => "controller", :action => "action"}, {}, {:item => "square"} + # assert_routing 'controller/action/9', {id: "9", item: "square"}, {controller: "controller", action: "action"}, {}, {item: "square"} # # # Tests a route with a HTTP method - # assert_routing({ :method => 'put', :path => '/product/321' }, { :controller => "product", :action => "update", :id => "321" }) + # assert_routing({ method: 'put', path: '/product/321' }, { controller: "product", action: "update", id: "321" }) def assert_routing(path, options, defaults={}, extras={}, message=nil) assert_recognizes(options, path, extras, message) diff --git a/actionpack/lib/action_dispatch/testing/assertions/selector.rb b/actionpack/lib/action_dispatch/testing/assertions/selector.rb index 9388d44eef..2207a43afc 100644 --- a/actionpack/lib/action_dispatch/testing/assertions/selector.rb +++ b/actionpack/lib/action_dispatch/testing/assertions/selector.rb @@ -167,7 +167,7 @@ module ActionDispatch # assert_select "title", "Welcome" # # # Page title is "Welcome" and there is only one title element - # assert_select "title", {:count => 1, :text => "Welcome"}, + # assert_select "title", {count: 1, text: "Welcome"}, # "Wrong title or more than one title element" # # # Page contains no forms diff --git a/actionpack/lib/action_dispatch/testing/assertions/tag.rb b/actionpack/lib/action_dispatch/testing/assertions/tag.rb index 2e38266aba..e5fe30ba82 100644 --- a/actionpack/lib/action_dispatch/testing/assertions/tag.rb +++ b/actionpack/lib/action_dispatch/testing/assertions/tag.rb @@ -49,44 +49,44 @@ module ActionDispatch # * if the condition is +false+ or +nil+, the value must be +nil+. # # # Assert that there is a "span" tag - # assert_tag :tag => "span" + # assert_tag tag: "span" # # # Assert that there is a "span" tag with id="x" - # assert_tag :tag => "span", :attributes => { :id => "x" } + # assert_tag tag: "span", attributes: { id: "x" } # # # Assert that there is a "span" tag using the short-hand # assert_tag :span # # # Assert that there is a "span" tag with id="x" using the short-hand - # assert_tag :span, :attributes => { :id => "x" } + # assert_tag :span, attributes: { id: "x" } # # # Assert that there is a "span" inside of a "div" - # assert_tag :tag => "span", :parent => { :tag => "div" } + # assert_tag tag: "span", parent: { tag: "div" } # # # Assert that there is a "span" somewhere inside a table - # assert_tag :tag => "span", :ancestor => { :tag => "table" } + # assert_tag tag: "span", ancestor: { tag: "table" } # # # Assert that there is a "span" with at least one "em" child - # assert_tag :tag => "span", :child => { :tag => "em" } + # assert_tag tag: "span", child: { tag: "em" } # # # Assert that there is a "span" containing a (possibly nested) # # "strong" tag. - # assert_tag :tag => "span", :descendant => { :tag => "strong" } + # assert_tag tag: "span", descendant: { tag: "strong" } # # # Assert that there is a "span" containing between 2 and 4 "em" tags # # as immediate children - # assert_tag :tag => "span", - # :children => { :count => 2..4, :only => { :tag => "em" } } + # assert_tag tag: "span", + # children: { count: 2..4, only: { tag: "em" } } # # # Get funky: assert that there is a "div", with an "ul" ancestor # # and an "li" parent (with "class" = "enum"), and containing a # # "span" descendant that contains text matching /hello world/ - # assert_tag :tag => "div", - # :ancestor => { :tag => "ul" }, - # :parent => { :tag => "li", - # :attributes => { :class => "enum" } }, - # :descendant => { :tag => "span", - # :child => /hello world/ } + # assert_tag tag: "div", + # ancestor: { tag: "ul" }, + # parent: { tag: "li", + # attributes: { class: "enum" } }, + # descendant: { tag: "span", + # child: /hello world/ } # # Please note: +assert_tag+ and +assert_no_tag+ only work # with well-formed XHTML. They recognize a few tags as implicitly self-closing @@ -103,15 +103,15 @@ module ActionDispatch # exist. (See +assert_tag+ for a full discussion of the syntax.) # # # Assert that there is not a "div" containing a "p" - # assert_no_tag :tag => "div", :descendant => { :tag => "p" } + # assert_no_tag tag: "div", descendant: { tag: "p" } # # # Assert that an unordered list is empty - # assert_no_tag :tag => "ul", :descendant => { :tag => "li" } + # assert_no_tag tag: "ul", descendant: { tag: "li" } # # # Assert that there is not a "p" tag with between 1 to 3 "img" tags # # as immediate children - # assert_no_tag :tag => "p", - # :children => { :count => 1..3, :only => { :tag => "img" } } + # assert_no_tag tag: "p", + # children: { count: 1..3, only: { tag: "img" } } def assert_no_tag(*opts) opts = opts.size > 1 ? opts.last.merge({ :tag => opts.first.to_s }) : opts.first tag = find_tag(opts) diff --git a/actionpack/lib/action_dispatch/testing/integration.rb b/actionpack/lib/action_dispatch/testing/integration.rb index 4bd7b69642..2928263163 100644 --- a/actionpack/lib/action_dispatch/testing/integration.rb +++ b/actionpack/lib/action_dispatch/testing/integration.rb @@ -429,8 +429,8 @@ module ActionDispatch # assert_equal 200, status # # # post the login and follow through to the home page - # post "/login", :username => people(:jamis).username, - # :password => people(:jamis).password + # post "/login", username: people(:jamis).username, + # password: people(:jamis).password # follow_redirect! # assert_equal 200, status # assert_equal "/home", path @@ -463,13 +463,13 @@ module ActionDispatch # module CustomAssertions # def enter(room) # # reference a named route, for maximum internal consistency! - # get(room_url(:id => room.id)) + # get(room_url(id: room.id)) # assert(...) # ... # end # # def speak(room, message) - # xml_http_request "/say/#{room.id}", :message => message + # xml_http_request "/say/#{room.id}", message: message # assert(...) # ... # end @@ -479,8 +479,8 @@ module ActionDispatch # open_session do |sess| # sess.extend(CustomAssertions) # who = people(who) - # sess.post "/login", :username => who.username, - # :password => who.password + # sess.post "/login", username: who.username, + # password: who.password # assert(...) # end # end diff --git a/actionpack/lib/action_dispatch/testing/test_process.rb b/actionpack/lib/action_dispatch/testing/test_process.rb index 3a6d081721..9ad5a1bc1d 100644 --- a/actionpack/lib/action_dispatch/testing/test_process.rb +++ b/actionpack/lib/action_dispatch/testing/test_process.rb @@ -28,12 +28,12 @@ module ActionDispatch # Shortcut for Rack::Test::UploadedFile.new(ActionController::TestCase.fixture_path + path, type): # - # post :change_avatar, :avatar => fixture_file_upload('/files/spongebob.png', 'image/png') + # post :change_avatar, avatar: fixture_file_upload('/files/spongebob.png', 'image/png') # # To upload binary files on Windows, pass :binary as the last parameter. # This will not affect other platforms: # - # post :change_avatar, :avatar => fixture_file_upload('/files/spongebob.png', 'image/png', :binary) + # post :change_avatar, avatar: fixture_file_upload('/files/spongebob.png', 'image/png', :binary) def fixture_file_upload(path, mime_type = nil, binary = false) fixture_path = self.class.fixture_path if self.class.respond_to?(:fixture_path) Rack::Test::UploadedFile.new("#{fixture_path}#{path}", mime_type, binary)