Skip to content

Commit

Permalink
Merge commit 'core/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
rick committed May 6, 2008
2 parents eacb5cf + 3cffe92 commit 0052938
Show file tree
Hide file tree
Showing 163 changed files with 2,333 additions and 1,150 deletions.
12 changes: 6 additions & 6 deletions actionmailer/lib/action_mailer/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -198,31 +198,31 @@ module ActionMailer #:nodoc:
#
# These options are specified on the class level, like <tt>ActionMailer::Base.template_root = "/my/templates"</tt>
#
# * <tt>template_root</tt> - template root determines the base from which template references will be made.
# * <tt>template_root</tt> - Determines the base from which template references will be made.
#
# * <tt>logger</tt> - the logger is used for generating information on the mailing run if available.
# Can be set to nil for no logging. Compatible with both Ruby's own Logger and Log4r loggers.
#
# * <tt>smtp_settings</tt> - Allows detailed configuration for :smtp delivery method:
# * <tt>smtp_settings</tt> - Allows detailed configuration for <tt>:smtp</tt> delivery method:
# * <tt>:address</tt> Allows you to use a remote mail server. Just change it from its default "localhost" setting.
# * <tt>:port</tt> On the off chance that your mail server doesn't run on port 25, you can change it.
# * <tt>:domain</tt> If you need to specify a HELO domain, you can do it here.
# * <tt>:user_name</tt> If your mail server requires authentication, set the username in this setting.
# * <tt>:password</tt> If your mail server requires authentication, set the password in this setting.
# * <tt>:authentication</tt> If your mail server requires authentication, you need to specify the authentication type here.
# This is a symbol and one of :plain, :login, :cram_md5
# This is a symbol and one of <tt>:plain</tt>, <tt>:login</tt>, <tt>:cram_md5</tt>
#
# * <tt>sendmail_settings</tt> - Allows you to override options for the :sendmail delivery method
# * <tt>sendmail_settings</tt> - Allows you to override options for the <tt>:sendmail</tt> delivery method
# * <tt>:location</tt> The location of the sendmail executable, defaults to "/usr/sbin/sendmail"
# * <tt>:arguments</tt> The command line arguments
# * <tt>raise_delivery_errors</tt> - whether or not errors should be raised if the email fails to be delivered.
#
# * <tt>delivery_method</tt> - Defines a delivery method. Possible values are :smtp (default), :sendmail, and :test.
# * <tt>delivery_method</tt> - Defines a delivery method. Possible values are <tt>:smtp</tt> (default), <tt>:sendmail</tt>, and <tt>:test</tt>.
#
# * <tt>perform_deliveries</tt> - Determines whether deliver_* methods are actually carried out. By default they are,
# but this can be turned off to help functional testing.
#
# * <tt>deliveries</tt> - Keeps an array of all the emails sent out through the Action Mailer with delivery_method :test. Most useful
# * <tt>deliveries</tt> - Keeps an array of all the emails sent out through the Action Mailer with <tt>delivery_method :test</tt>. Most useful
# for unit and functional testing.
#
# * <tt>default_charset</tt> - The default charset used for the body and to encode the subject. Defaults to UTF-8. You can also
Expand Down
4 changes: 4 additions & 0 deletions actionpack/CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
*SVN*

* Fixed that TextHelper#text_field would corrypt when raw HTML was used as the value (mchenryc, Kevin Glowacz) [#80]

* Added ActionController::TestCase#rescue_action_in_public! to control whether the action under test should use the regular rescue_action path instead of simply raising the exception inline (great for error testing) [DHH]

* Reduce number of instance variables being copied from controller to view. [Pratik]

* select_datetime and select_time default to Time.zone.now when config.time_zone is set [Geoff Buesing]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,12 +263,15 @@ def assert_select(*args, &block)
if match_with = equals[:text]
matches.delete_if do |match|
text = ""
text.force_encoding(match_with.encoding) if text.respond_to?(:force_encoding)
stack = match.children.reverse
while node = stack.pop
if node.tag?
stack.concat node.children.reverse
else
text << node.content
content = node.content
content.force_encoding(match_with.encoding) if content.respond_to?(:force_encoding)
text << content
end
end
text.strip! unless NO_STRIP.include?(match.name)
Expand Down
24 changes: 13 additions & 11 deletions actionpack/lib/action_controller/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -277,9 +277,10 @@ class Base
@@debug_routes = true
cattr_accessor :debug_routes

# Controls whether the application is thread-safe, so multi-threaded servers like WEBrick know whether to apply a mutex
# around the performance of each action. Action Pack and Active Record are by default thread-safe, but many applications
# may not be. Turned off by default.
# Indicates to Mongrel or Webrick whether to allow concurrent action
# processing. Your controller actions and any other code they call must
# also behave well when called from concurrent threads. Turned off by
# default.
@@allow_concurrency = false
cattr_accessor :allow_concurrency

Expand Down Expand Up @@ -331,7 +332,8 @@ class Base
@@resources_path_names = { :new => 'new', :edit => 'edit' }
cattr_accessor :resources_path_names

# Sets the token parameter name for RequestForgery. Calling #protect_from_forgery sets it to :authenticity_token by default
# Sets the token parameter name for RequestForgery. Calling +protect_from_forgery+
# sets it to <tt>:authenticity_token</tt> by default.
cattr_accessor :request_forgery_protection_token

# Indicates whether or not optimise the generated named
Expand Down Expand Up @@ -530,9 +532,9 @@ def process(request, response, method = :perform_action, *arguments) #:nodoc:

# Returns a URL that has been rewritten according to the options hash and the defined Routes.
# (For doing a complete redirect, use redirect_to).
#  
#
# <tt>url_for</tt> is used to:
#  
#
# All keys given to url_for are forwarded to the Route module, save for the following:
# * <tt>:anchor</tt> -- specifies the anchor name to be appended to the path. For example,
# <tt>url_for :controller => 'posts', :action => 'show', :id => 10, :anchor => 'comments'</tt>
Expand All @@ -543,8 +545,8 @@ def process(request, response, method = :perform_action, *arguments) #:nodoc:
# * <tt>:host</tt> -- overrides the default (current) host if provided.
# * <tt>:protocol</tt> -- overrides the default (current) protocol if provided.
# * <tt>:port</tt> -- optionally specify the port to connect to.
# * <tt>:user</tt> -- Inline HTTP authentication (only plucked out if :password is also present).
# * <tt>:password</tt> -- Inline HTTP authentication (only plucked out if :user is also present).
# * <tt>:user</tt> -- Inline HTTP authentication (only plucked out if <tt>:password</tt> is also present).
# * <tt>:password</tt> -- Inline HTTP authentication (only plucked out if <tt>:user</tt> is also present).
# * <tt>:skip_relative_url_root</tt> -- if true, the url is not constructed using the relative_url_root of the request so the path
# will include the web server relative installation directory.
#
Expand Down Expand Up @@ -597,7 +599,7 @@ def process(request, response, method = :perform_action, *arguments) #:nodoc:
# url_for :controller => 'posts', :action => nil
#
# If you explicitly want to create a URL that's almost the same as the current URL, you can do so using the
# :overwrite_params options. Say for your posts you have different views for showing and printing them.
# <tt>:overwrite_params</tt> options. Say for your posts you have different views for showing and printing them.
# Then, in the show view, you get the URL for the print view like this
#
# url_for :overwrite_params => { :action => 'print' }
Expand Down Expand Up @@ -768,7 +770,7 @@ def append_view_path(path)
# # placed in "app/views/layouts/special.r(html|xml)"
# render :text => "Hi there!", :layout => "special"
#
# The :text option can also accept a Proc object, which can be used to manually control the page generation. This should
# The <tt>:text</tt> option can also accept a Proc object, which can be used to manually control the page generation. This should
# generally be avoided, as it violates the separation between code and content, and because almost everything that can be
# done with this method can also be done more cleanly using one of the other rendering methods, most notably templates.
#
Expand Down Expand Up @@ -822,7 +824,7 @@ def append_view_path(path)
#
# === Rendering with status and location headers
#
# All renders take the :status and :location options and turn them into headers. They can even be used together:
# All renders take the <tt>:status</tt> and <tt>:location</tt> options and turn them into headers. They can even be used together:
#
# render :xml => post.to_xml, :status => :created, :location => post_url(post)
def render(options = nil, extra_options = {}, &block) #:doc:
Expand Down
50 changes: 31 additions & 19 deletions actionpack/lib/action_controller/cookies.rb
Original file line number Diff line number Diff line change
@@ -1,31 +1,38 @@
module ActionController #:nodoc:
# Cookies are read and written through ActionController#cookies. The cookies being read are what were received along with the request,
# the cookies being written are what will be sent out with the response. Cookies are read by value (so you won't get the cookie object
# itself back -- just the value it holds). Examples for writing:
# Cookies are read and written through ActionController#cookies.
#
# cookies[:user_name] = "david" # => Will set a simple session cookie
# The cookies being read are the ones received along with the request, the cookies
# being written will be sent out with the response. Reading a cookie does not get
# the cookie object itself back, just the value it holds.
#
# Examples for writing:
#
# # Sets a simple session cookie.
# cookies[:user_name] = "david"
#
# # Sets a cookie that expires in 1 hour.
# cookies[:login] = { :value => "XJ-122", :expires => 1.hour.from_now }
# # => Will set a cookie that expires in 1 hour
#
# Examples for reading:
#
# cookies[:user_name] # => "david"
# cookies.size # => 2
# cookies.size # => 2
#
# Example for deleting:
#
# cookies.delete :user_name
#
# All the option symbols for setting cookies are:
# The option symbols for setting cookies are:
#
# * <tt>value</tt> - the cookie's value or list of values (as an array).
# * <tt>path</tt> - the path for which this cookie applies. Defaults to the root of the application.
# * <tt>domain</tt> - the domain for which this cookie applies.
# * <tt>expires</tt> - the time at which this cookie expires, as a +Time+ object.
# * <tt>secure</tt> - whether this cookie is a secure cookie or not (default to false).
# Secure cookies are only transmitted to HTTPS servers.
# * <tt>http_only</tt> - whether this cookie is accessible via scripting or only HTTP (defaults to false).

# * <tt>:value</tt> - The cookie's value or list of values (as an array).
# * <tt>:path</tt> - The path for which this cookie applies. Defaults to the root
# of the application.
# * <tt>:domain</tt> - The domain for which this cookie applies.
# * <tt>:expires</tt> - The time at which this cookie expires, as a Time object.
# * <tt>:secure</tt> - Whether this cookie is a only transmitted to HTTPS servers.
# Default is +false+.
# * <tt>:http_only</tt> - Whether this cookie is accessible via scripting or
# only HTTP. Defaults to +false+.
module Cookies
def self.included(base)
base.helper_method :cookies
Expand All @@ -45,15 +52,16 @@ def initialize(controller)
update(@cookies)
end

# Returns the value of the cookie by +name+ -- or nil if no such cookie exists. You set new cookies using cookies[]=
# (for simple name/value cookies without options).
# Returns the value of the cookie by +name+, or +nil+ if no such cookie exists.
def [](name)
cookie = @cookies[name.to_s]
if cookie && cookie.respond_to?(:value)
cookie.size > 1 ? cookie.value : cookie.value[0]
end
end

# Sets the cookie named +name+. The second argument may be the very cookie
# value, or a hash of options as documented above.
def []=(name, options)
if options.is_a?(Hash)
options = options.inject({}) { |options, pair| options[pair.first.to_s] = pair.last; options }
Expand All @@ -66,14 +74,18 @@ def []=(name, options)
end

# Removes the cookie on the client machine by setting the value to an empty string
# and setting its expiration date into the past. Like []=, you can pass in an options
# hash to delete cookies with extra data such as a +path+.
# and setting its expiration date into the past. Like <tt>[]=</tt>, you can pass in
# an options hash to delete cookies with extra data such as a <tt>:path</tt>.
def delete(name, options = {})
options.stringify_keys!
set_cookie(options.merge("name" => name.to_s, "value" => "", "expires" => Time.at(0)))
end

private
# Builds a CGI::Cookie object and adds the cookie to the response headers.
#
# The path of the cookie defaults to "/" if there's none in +options+, and
# everything is passed to the CGI::Cookie constructor.
def set_cookie(options) #:doc:
options["path"] = "/" unless options["path"]
cookie = CGI::Cookie.new(options)
Expand Down
9 changes: 5 additions & 4 deletions actionpack/lib/action_controller/filters.rb
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,8 @@ def self.included(base)
# end
#
# To use a filter object with around_filter, pass an object responding
# to :filter or both :before and :after. With a filter method, yield to
# the block as above:
# to <tt>:filter</tt> or both <tt>:before</tt> and <tt>:after</tt>. With a
# filter method, yield to the block as above:
#
# around_filter BenchmarkingFilter
#
Expand Down Expand Up @@ -191,8 +191,9 @@ def self.included(base)
# == Filter conditions
#
# Filters may be limited to specific actions by declaring the actions to
# include or exclude. Both options accept single actions (:only => :index)
# or arrays of actions (:except => [:foo, :bar]).
# include or exclude. Both options accept single actions
# (<tt>:only => :index</tt>) or arrays of actions
# (<tt>:except => [:foo, :bar]</tt>).
#
# class Journal < ActionController::Base
# # Require authentication for edit and delete.
Expand Down
12 changes: 10 additions & 2 deletions actionpack/lib/action_controller/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,19 @@ def helper(*args, &block)
# Declare a controller method as a helper. For example, the following
# makes the +current_user+ controller method available to the view:
# class ApplicationController < ActionController::Base
# helper_method :current_user
# helper_method :current_user, :logged_in?
#
# def current_user
# @current_user ||= User.find(session[:user])
# @current_user ||= User.find_by_id(session[:user])
# end
#
# def logged_in?
# current_user != nil
# end
# end
#
# In a view:
# <% if logged_in? -%>Welcome, <%= current_user.name %><% end -%>
def helper_method(*methods)
methods.flatten.each do |method|
master_helper_module.module_eval <<-end_eval
Expand Down
9 changes: 6 additions & 3 deletions actionpack/lib/action_controller/mime_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,11 @@ def parse(accept_header)
# keep track of creation order to keep the subsequent sort stable
list = []
accept_header.split(/,/).each_with_index do |header, index|
params = header.split(/;\s*q=/)
list << AcceptItem.new(index, *params) unless params.empty?
params, q = header.split(/;\s*q=/)
if params
params.strip!
list << AcceptItem.new(index, params, q) unless params.empty?
end
end
list.sort!

Expand Down Expand Up @@ -145,7 +148,7 @@ def ===(list)
end

def ==(mime_type)
return false unless mime_type
return false if mime_type.blank?
(@synonyms + [ self ]).any? do |synonym|
synonym.to_s == mime_type.to_s || synonym.to_sym == mime_type.to_sym
end
Expand Down
2 changes: 1 addition & 1 deletion actionpack/lib/action_controller/polymorphic_routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ module ActionController
# * <tt>url_for</tt>, so you can use it with a record as the argument, e.g.
# <tt>url_for(@article)</tt>;
# * ActionView::Helpers::FormHelper uses <tt>polymorphic_path</tt>, so you can write
# <tt>form_for(@article)</tt> without having to specify :url parameter for the form
# <tt>form_for(@article)</tt> without having to specify <tt>:url</tt> parameter for the form
# action;
# * <tt>redirect_to</tt> (which, in fact, uses <tt>url_for</tt>) so you can write
# <tt>redirect_to(post)</tt> in your controllers;
Expand Down
18 changes: 9 additions & 9 deletions actionpack/lib/action_controller/request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class AbstractRequest
# such as { 'RAILS_ENV' => 'production' }.
attr_reader :env

# The true HTTP request method as a lowercase symbol, such as :get.
# The true HTTP request method as a lowercase symbol, such as <tt>:get</tt>.
# UnknownHttpMethod is raised for invalid methods not listed in ACCEPTED_HTTP_METHODS.
def request_method
@request_method ||= begin
Expand All @@ -28,35 +28,35 @@ def request_method
end
end

# The HTTP request method as a lowercase symbol, such as :get.
# Note, HEAD is returned as :get since the two are functionally
# The HTTP request method as a lowercase symbol, such as <tt>:get</tt>.
# Note, HEAD is returned as <tt>:get</tt> since the two are functionally
# equivalent from the application's perspective.
def method
request_method == :head ? :get : request_method
end

# Is this a GET (or HEAD) request? Equivalent to request.method == :get
# Is this a GET (or HEAD) request? Equivalent to <tt>request.method == :get</tt>.
def get?
method == :get
end

# Is this a POST request? Equivalent to request.method == :post
# Is this a POST request? Equivalent to <tt>request.method == :post</tt>.
def post?
request_method == :post
end

# Is this a PUT request? Equivalent to request.method == :put
# Is this a PUT request? Equivalent to <tt>request.method == :put</tt>.
def put?
request_method == :put
end

# Is this a DELETE request? Equivalent to request.method == :delete
# Is this a DELETE request? Equivalent to <tt>request.method == :delete</tt>.
def delete?
request_method == :delete
end

# Is this a HEAD request? request.method sees HEAD as :get, so check the
# HTTP method directly.
# Is this a HEAD request? <tt>request.method</tt> sees HEAD as <tt>:get</tt>,
# so check the HTTP method directly.
def head?
request_method == :head
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ def verifiable_request_format?
request.format.html? || request.format.js?
end

# Sets the token value for the current session. Pass a :secret option in #protect_from_forgery to add a custom salt to the hash.
# Sets the token value for the current session. Pass a <tt>:secret</tt> option
# in +protect_from_forgery+ to add a custom salt to the hash.
def form_authenticity_token
@form_authenticity_token ||= if request_forgery_protection_options[:secret]
authenticity_token_from_session_id
Expand Down
Loading

0 comments on commit 0052938

Please sign in to comment.