Skip to content

Commit

Permalink
Merge pull request #8455 from frodsan/actionize
Browse files Browse the repository at this point in the history
Actionize: Use `_action` callbacks in documentation and code
  • Loading branch information
fxn committed Dec 7, 2012
2 parents 85f4956 + a53a7be commit 9cb91f9
Show file tree
Hide file tree
Showing 14 changed files with 28 additions and 28 deletions.
6 changes: 3 additions & 3 deletions actionpack/lib/abstract_controller/callbacks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def skip_action_callback(*names)
skip_after_action(*names)
skip_around_action(*names)
end

alias_method :skip_filter, :skip_action_callback

# Take callback names and an optional callback proc, normalize them,
Expand Down Expand Up @@ -91,7 +91,7 @@ def _insert_callbacks(callbacks, block = nil)
# :call-seq: prepend_before_action(names, block)
#
# Prepend a callback before actions. See _insert_callbacks for parameter details.
# Aliased as prepend_before_action.
# Aliased as prepend_before_filter.

##
# :method: skip_before_action
Expand Down Expand Up @@ -206,7 +206,7 @@ def skip_#{callback}_action(*names)
end # end
alias_method :skip_#{callback}_filter, :skip_#{callback}_action
# *_action is the same as append_*_action
alias_method :append_#{callback}_action, :#{callback}_action # alias_method :append_before_action, :before_action
alias_method :append_#{callback}_filter, :#{callback}_action # alias_method :append_before_filter, :before_action
Expand Down
4 changes: 2 additions & 2 deletions actionpack/lib/action_controller/metal/force_ssl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ module ClassMethods
# ==== Options
# * <tt>host</tt> - Redirect to a different host name
# * <tt>only</tt> - The callback should be run only for this action
# * <tt>except</tt> - The callback should be run for all actions except this action
# * <tt>except</tt> - The callback should be run for all actions except this action
# * <tt>if</tt> - A symbol naming an instance method or a proc; the callback
# will be called only when it returns a true value.
# * <tt>unless</tt> - A symbol naming an instance method or a proc; the callback
# will be called only when it returns a false value.
def force_ssl(options = {})
host = options.delete(:host)
before_filter(options) do
before_action(options) do
force_ssl_redirect(host)
end
end
Expand Down
10 changes: 5 additions & 5 deletions actionpack/lib/action_controller/metal/http_authentication.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ module HttpAuthentication
# the regular HTML interface is protected by a session approach:
#
# class ApplicationController < ActionController::Base
# before_filter :set_account, :authenticate
# before_action :set_account, :authenticate
#
# protected
# def set_account
Expand Down Expand Up @@ -68,7 +68,7 @@ module ControllerMethods

module ClassMethods
def http_basic_authenticate_with(options = {})
before_filter(options.except(:name, :password, :realm)) do
before_action(options.except(:name, :password, :realm)) do
authenticate_or_request_with_http_basic(options[:realm] || "Application") do |name, password|
name == options[:name] && password == options[:password]
end
Expand Down Expand Up @@ -124,7 +124,7 @@ def authentication_request(controller, realm)
# USERS = {"dhh" => "secret", #plain text password
# "dap" => Digest::MD5.hexdigest(["dap",REALM,"secret"].join(":"))} #ha1 digest password
#
# before_filter :authenticate, except: [:index]
# before_action :authenticate, except: [:index]
#
# def index
# render text: "Everyone can see me!"
Expand Down Expand Up @@ -317,7 +317,7 @@ def opaque(secret_key)
# class PostsController < ApplicationController
# TOKEN = "secret"
#
# before_filter :authenticate, except: [ :index ]
# before_action :authenticate, except: [ :index ]
#
# def index
# render text: "Everyone can see me!"
Expand All @@ -340,7 +340,7 @@ def opaque(secret_key)
# the regular HTML interface is protected by a session approach:
#
# class ApplicationController < ActionController::Base
# before_filter :set_account, :authenticate
# before_action :set_account, :authenticate
#
# protected
# def set_account
Expand Down
6 changes: 3 additions & 3 deletions actionpack/test/controller/http_basic_authentication_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

class HttpBasicAuthenticationTest < ActionController::TestCase
class DummyController < ActionController::Base
before_filter :authenticate, :only => :index
before_filter :authenticate_with_request, :only => :display
before_filter :authenticate_long_credentials, :only => :show
before_action :authenticate, only: :index
before_action :authenticate_with_request, only: :display
before_action :authenticate_long_credentials, only: :show

http_basic_authenticate_with :name => "David", :password => "Goliath", :only => :search

Expand Down
4 changes: 2 additions & 2 deletions actionpack/test/controller/http_digest_authentication_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

class HttpDigestAuthenticationTest < ActionController::TestCase
class DummyDigestController < ActionController::Base
before_filter :authenticate, :only => :index
before_filter :authenticate_with_request, :only => :display
before_action :authenticate, only: :index
before_action :authenticate_with_request, only: :display

USERS = { 'lifo' => 'world', 'pretty' => 'please',
'dhh' => ::Digest::MD5::hexdigest(["dhh","SuperSecret","secret"].join(":"))}
Expand Down
6 changes: 3 additions & 3 deletions actionpack/test/controller/http_token_authentication_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

class HttpTokenAuthenticationTest < ActionController::TestCase
class DummyController < ActionController::Base
before_filter :authenticate, :only => :index
before_filter :authenticate_with_request, :only => :display
before_filter :authenticate_long_credentials, :only => :show
before_action :authenticate, only: :index
before_action :authenticate_with_request, only: :display
before_action :authenticate_long_credentials, only: :show

def index
render :text => "Hello Secret"
Expand Down
2 changes: 1 addition & 1 deletion actionpack/test/controller/log_subscriber_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class SpecialException < Exception
head :status => 406
end

before_filter :redirector, :only => :never_executed
before_action :redirector, only: :never_executed

def never_executed
end
Expand Down
2 changes: 1 addition & 1 deletion actionpack/test/controller/mime_responds_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1139,7 +1139,7 @@ class AbstractPostController < ActionController::Base

# For testing layouts which are set automatically
class PostController < AbstractPostController
around_filter :with_iphone
around_action :with_iphone

def index
respond_to(:html, :iphone, :js)
Expand Down
2 changes: 1 addition & 1 deletion actionpack/test/controller/new_base/base_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Tests the controller dispatching happy path
module Dispatching
class SimpleController < ActionController::Base
before_filter :authenticate
before_action :authenticate

def index
render :text => "success"
Expand Down
2 changes: 1 addition & 1 deletion actionpack/test/controller/new_base/render_context_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class BasicController < ActionController::Base
include ActionView::Context

# 2) Call _prepare_context that will do the required initialization
before_filter :_prepare_context
before_action :_prepare_context

def hello_world
@value = "Hello"
Expand Down
6 changes: 3 additions & 3 deletions actionpack/test/controller/render_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def fresh
class TestController < ActionController::Base
protect_from_forgery

before_filter :set_variable_for_layout
before_action :set_variable_for_layout

class LabellingFormBuilder < ActionView::Helpers::FormBuilder
end
Expand Down Expand Up @@ -137,7 +137,7 @@ def conditional_hello_with_cache_control_headers
def conditional_hello_with_bangs
render :action => 'hello_world'
end
before_filter :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 ])
Expand Down Expand Up @@ -710,7 +710,7 @@ def render_call_to_partial_with_layout_in_main_layout_and_within_content_for_lay
render :action => "calling_partial_with_layout", :layout => "layouts/partial_with_layout"
end

before_filter :only => :render_with_filters do
before_action only: :render_with_filters do
request.format = :xml
end

Expand Down
2 changes: 1 addition & 1 deletion actionpack/test/controller/rescue_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class ResourceUnavailableToRescueAsString < StandardError
render :text => 'io error'
end

before_filter(:only => :before_filter_raises) { raise 'umm nice' }
before_action(only: :before_filter_raises) { raise 'umm nice' }

def before_filter_raises
end
Expand Down
2 changes: 1 addition & 1 deletion actionpack/test/controller/show_exceptions_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class ShowExceptionsController < ActionController::Base
use ActionDispatch::ShowExceptions, ActionDispatch::PublicExceptions.new("#{FIXTURE_LOAD_PATH}/public")
use ActionDispatch::DebugExceptions

before_filter :only => :another_boom do
before_action only: :another_boom do
request.env["action_dispatch.show_detailed_exceptions"] = true
end

Expand Down
2 changes: 1 addition & 1 deletion actionpack/test/controller/view_paths_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class ViewLoadPathsTest < ActionController::TestCase
class TestController < ActionController::Base
def self.controller_path() "test" end

before_filter :add_view_path, :only => :hello_world_at_request_time
before_action :add_view_path, only: :hello_world_at_request_time

def hello_world() end
def hello_world_at_request_time() render(:action => 'hello_world') end
Expand Down

0 comments on commit 9cb91f9

Please sign in to comment.