1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
This commit is contained in:
David Heinemeier Hansson 2009-12-22 17:31:29 -08:00
commit e7ef57dd0d
42 changed files with 353 additions and 384 deletions

View file

@ -13,7 +13,7 @@ gem "pg", ">= 0.8.0"
gem "mysql", ">= 2.8.1"
# AP
gem "rack", "1.0.1", :git => "git://github.com/rails/rack.git"
gem "rack", "1.1.0", :git => "git://github.com/rack/rack.git"
gem "rack-test", "0.5.3"
gem "RedCloth", ">= 4.2.2"

View file

@ -41,18 +41,3 @@ module ActionMailer
autoload :TestHelper
autoload :Utils
end
module Text
extend ActiveSupport::Autoload
autoload :Format, 'action_mailer/vendor/text_format'
end
module Net
extend ActiveSupport::Autoload
autoload :SMTP
end
require 'action_mailer/vendor/tmail'

View file

@ -1,4 +1,7 @@
require 'active_support/core_ext/class'
require 'action_mailer/part'
require 'action_mailer/vendor/text_format'
require 'action_mailer/vendor/tmail'
module ActionMailer #:nodoc:
# Action Mailer allows you to send email from your application using a mailer model and views.
@ -250,31 +253,21 @@ module ActionMailer #:nodoc:
# <tt>["text/html", "text/enriched", "text/plain"]</tt>. Items that appear first in the array have higher priority in the mail client
# and appear last in the mime encoded message. You can also pick a different order from inside a method with
# +implicit_parts_order+.
class Base
class Base < AbstractController::Base
include AdvAttrAccessor, PartContainer, Quoting, Utils
include AbstractController::Rendering
include AbstractController::LocalizedCache
include AbstractController::Layouts
include AbstractController::Helpers
helper ActionMailer::MailHelper
if Object.const_defined?(:ActionController)
include ActionController::UrlWriter
end
include ActionMailer::DeprecatedBody
private_class_method :new #:nodoc:
class_inheritable_accessor :view_paths
self.view_paths = []
attr_internal :formats
cattr_accessor :logger
@@raise_delivery_errors = true
cattr_accessor :raise_delivery_errors
@ -346,24 +339,13 @@ module ActionMailer #:nodoc:
# have multiple mailer methods share the same template.
adv_attr_accessor :template
# The mail and action_name instances referenced by this mailer.
attr_reader :mail, :action_name
# Where the response body is stored.
attr_internal :response_body
# Override the mailer name, which defaults to an inflected version of the
# mailer's class name. If you want to use a template in a non-standard
# location, you can use this to specify that location.
attr_writer :mailer_name
adv_attr_accessor :mailer_name
def mailer_name(value = nil)
if value
@mailer_name = value
else
@mailer_name || self.class.mailer_name
end
end
# Expose the internal mail
attr_reader :mail
# Alias controller_path to mailer_name so render :partial in views work.
alias :controller_path :mailer_name
@ -453,18 +435,16 @@ module ActionMailer #:nodoc:
# will be initialized according to the named method. If not, the mailer will
# remain uninitialized (useful when you only need to invoke the "receive"
# method, for instance).
def initialize(method_name=nil, *parameters) #:nodoc:
@_formats = []
@_response_body = nil
def initialize(method_name=nil, *args) #:nodoc:
super()
create!(method_name, *parameters) if method_name
process(method_name, *args) if method_name
end
# Initialize the mailer via the given +method_name+. The body will be
# Process the mailer via the given +method_name+. The body will be
# rendered and a new TMail::Mail object created.
def create!(method_name, *parameters) #:nodoc:
def process(method_name, *args) #:nodoc:
initialize_defaults(method_name)
__send__(method_name, *parameters)
super
# Create e-mail parts
create_parts
@ -473,7 +453,7 @@ module ActionMailer #:nodoc:
@subject ||= I18n.t(:subject, :scope => [:actionmailer, mailer_name, method_name],
:default => method_name.humanize)
# build the mail object itself
# Build the mail object itself
@mail = create_mail
end
@ -488,7 +468,7 @@ module ActionMailer #:nodoc:
logger.debug "\n#{mail.encoded}"
end
ActiveSupport::Notifications.instrument(:deliver_mail, :mail => @mail) do
ActiveSupport::Notifications.instrument(:deliver_mail, :mail => mail) do
begin
self.delivery_method.perform_delivery(mail) if perform_deliveries
rescue Exception => e # Net::SMTP errors or sendmail pipe errors
@ -510,23 +490,18 @@ module ActionMailer #:nodoc:
@implicit_parts_order ||= @@default_implicit_parts_order.dup
@mime_version ||= @@default_mime_version.dup if @@default_mime_version
@mailer_name ||= self.class.mailer_name
@mailer_name ||= self.class.mailer_name.dup
@template ||= method_name
@action_name = @template
@parts ||= []
@headers ||= {}
@sent_on ||= Time.now
ActiveSupport::Deprecation.silence do
super # Run deprecation hooks
end
end
def create_parts
ActiveSupport::Deprecation.silence do
super # Run deprecation hooks
end
if String === response_body
@parts.unshift Part.new(

View file

@ -1,7 +1,7 @@
require "active_support/core_ext/class"
require 'active_support/core_ext/class'
module ActionMailer
module DeliveryMethod
autoload :File, 'action_mailer/delivery_method/file'
autoload :Sendmail, 'action_mailer/delivery_method/sendmail'
autoload :Smtp, 'action_mailer/delivery_method/smtp'
@ -52,6 +52,5 @@ module ActionMailer
superclass_delegating_accessor :settings
self.settings = {}
end
end
end

View file

@ -1,8 +1,9 @@
require 'net/smtp'
module ActionMailer
module DeliveryMethod
# A delivery method implementation which sends via smtp.
class Smtp < Method
self.settings = {
:address => "localhost",
:port => 25,
@ -26,6 +27,5 @@ module ActionMailer
end
end
end
end
end

View file

@ -34,13 +34,13 @@ class TestMailer < ActionMailer::Base
def from_with_name
from "System <system@loudthinking.com>"
recipients "root@loudthinking.com"
body "Nothing to see here."
render :text => "Nothing to see here."
end
def from_without_name
from "system@loudthinking.com"
recipients "root@loudthinking.com"
body "Nothing to see here."
render :text => "Nothing to see here."
end
def cc_bcc(recipient)
@ -301,6 +301,7 @@ class TestMailer < ActionMailer::Base
render :text => "testing"
end
# This tests body calls accepeting a hash, which is deprecated.
def body_ivar(recipient)
recipients recipient
subject "Body as a local variable"
@ -1043,7 +1044,8 @@ EOF
end
def test_body_is_stored_as_an_ivar
mail = TestMailer.create_body_ivar(@recipient)
mail = nil
ActiveSupport::Deprecation.silence { mail = TestMailer.create_body_ivar(@recipient) }
assert_equal "body: foo\nbar: baz", mail.body
end

View file

@ -12,8 +12,8 @@ class TestMailer < ActionMailer::Base
@from = "system@loudthinking.com"
@sent_on = Time.local(2004, 12, 12)
@body["recipient"] = recipient
@body["welcome_url"] = url_for :host => "example.com", :controller => "welcome", :action => "greeting"
@recipient = recipient
@welcome_url = url_for :host => "example.com", :controller => "welcome", :action => "greeting"
end
class <<self

View file

@ -16,7 +16,7 @@ Gem::Specification.new do |s|
s.add_dependency('activesupport', '= 3.0.pre')
s.add_dependency('activemodel', '= 3.0.pre')
s.add_dependency('rack', '~> 1.0.1')
s.add_dependency('rack', '~> 1.1.0')
s.add_dependency('rack-test', '~> 0.5.0')
s.add_dependency('rack-mount', '~> 0.3.2')
s.add_dependency('erubis', '~> 2.6.5')

View file

@ -8,7 +8,6 @@ require 'active_support/core_ext/module/delegation'
module AbstractController
extend ActiveSupport::Autoload
deferrable do
autoload :Base
autoload :Callbacks
autoload :Helpers
@ -16,5 +15,4 @@ module AbstractController
autoload :LocalizedCache
autoload :Logger
autoload :Rendering
end
end

View file

@ -84,7 +84,7 @@ module AbstractController
#
# ==== Returns
# self
def process(action)
def process(action, *args)
@_action_name = action_name = action.to_s
unless action_name = method_for_action(action_name)
@ -93,7 +93,7 @@ module AbstractController
@_response_body = nil
process_action(action_name)
process_action(action_name, *args)
end
private
@ -113,8 +113,8 @@ module AbstractController
# Call the action. Override this in a subclass to modify the
# behavior around processing an action. This, and not #process,
# is the intended way to override action dispatching.
def process_action(method_name)
send_action(method_name)
def process_action(method_name, *args)
send_action(method_name, *args)
end
# Actually call the method associated with the action. Override

View file

@ -29,33 +29,5 @@ module AbstractController
@str.send(*args, &block)
end
end
# Override process_action in the AbstractController::Base
# to log details about the method.
def process_action(action)
result = ActiveSupport::Notifications.instrument(:process_action,
:controller => self, :action => action) do
super
end
if logger
log = DelayedLog.new do
"\n\nProcessing #{self.class.name}\##{action_name} " \
"to #{request.formats} (for #{request_origin}) " \
"[#{request.method.to_s.upcase}]"
end
logger.info(log)
end
result
end
private
# Returns the request origin with the IP and time. This needs to be cached,
# otherwise we would get different results for each time it calls.
def request_origin
@request_origin ||= "#{request.remote_ip} at #{Time.now.to_s(:db)}"
end
end
end

View file

@ -5,7 +5,6 @@ require 'active_support/ruby/shim'
module ActionController
extend ActiveSupport::Autoload
deferrable do
autoload :Base
autoload :Caching
autoload :PolymorphicRoutes
@ -21,6 +20,7 @@ module ActionController
autoload :Helpers
autoload :HideActions
autoload :Layouts
autoload :Logger
autoload :MimeResponds
autoload :RackDelegation
autoload :Compatibility
@ -45,8 +45,8 @@ module ActionController
autoload :Routing, 'action_controller/deprecated'
autoload :Integration, 'action_controller/deprecated/integration_test'
autoload :IntegrationTest, 'action_controller/deprecated/integration_test'
end
eager_autoload do
autoload :RecordIdentifier
autoload :UrlRewriter
autoload :UrlWriter, 'action_controller/url_rewriter'
@ -65,6 +65,7 @@ module ActionController
autoload :SessionOverflowError
autoload :UnknownHttpMethod
end
end
end
# All of these simply register additional autoloads

View file

@ -14,6 +14,7 @@ module ActionController
include ActionController::Layouts
include ActionController::ConditionalGet
include ActionController::RackDelegation
include ActionController::Logger
include ActionController::Benchmarking
include ActionController::Configuration
@ -89,7 +90,7 @@ module ActionController
end
if options[:status]
options[:status] = ActionDispatch::StatusCodes[options[:status]]
options[:status] = Rack::Utils.status_code(options[:status])
end
options[:update] = blk if block_given?

View file

@ -32,11 +32,13 @@ module ActionController #:nodoc:
extend ActiveSupport::Concern
extend ActiveSupport::Autoload
eager_autoload do
autoload :Actions
autoload :Fragments
autoload :Pages
autoload :Sweeper, 'action_controller/caching/sweeping'
autoload :Sweeping, 'action_controller/caching/sweeping'
end
included do
@@cache_store = nil

View file

@ -69,7 +69,7 @@ module ActionController
end
def status=(status)
@_status = ActionDispatch::StatusCodes[status]
@_status = Rack::Utils.status_code(status)
end
# :api: private

View file

@ -53,7 +53,6 @@ module ActionController #:nodoc:
log_message << " [#{complete_request_uri rescue "unknown"}]"
logger.info(log_message)
response.headers["X-Runtime"] = "%.0f" % ms
else
super
end

View file

@ -0,0 +1,34 @@
require 'abstract_controller/logger'
module ActionController
module Logger
# Override process_action in the AbstractController::Base
# to log details about the method.
def process_action(action)
result = ActiveSupport::Notifications.instrument(:process_action,
:controller => self, :action => action) do
super
end
if logger
log = AbstractController::Logger::DelayedLog.new do
"\n\nProcessing #{self.class.name}\##{action_name} " \
"to #{request.formats} (for #{request_origin}) " \
"[#{request.method.to_s.upcase}]"
end
logger.info(log)
end
result
end
private
# Returns the request origin with the IP and time. This needs to be cached,
# otherwise we would get different results for each time it calls.
def request_origin
@request_origin ||= "#{request.remote_ip} at #{Time.now.to_s(:db)}"
end
end
end

View file

@ -1,3 +1,6 @@
require 'action_dispatch/http/request'
require 'action_dispatch/http/response'
module ActionController
module RackDelegation
extend ActiveSupport::Concern

View file

@ -62,9 +62,9 @@ module ActionController
private
def _extract_redirect_to_status(options, response_status)
status = if options.is_a?(Hash) && options.key?(:status)
ActionDispatch::StatusCodes[options.delete(:status)]
Rack::Utils.status_code(options.delete(:status))
elsif response_status.key?(:status)
ActionDispatch::StatusCodes[response_status[:status]]
Rack::Utils.status_code(response_status[:status])
else
302
end

View file

@ -3,6 +3,7 @@ $LOAD_PATH << "#{File.dirname(__FILE__)}/html-scanner"
module HTML
extend ActiveSupport::Autoload
eager_autoload do
autoload :CDATA, 'html/node'
autoload :Document, 'html/document'
autoload :FullSanitizer, 'html/sanitizer'
@ -15,4 +16,5 @@ module HTML
autoload :Tokenizer, 'html/tokenizer'
autoload :Version, 'html/version'
autoload :WhiteListSanitizer, 'html/sanitizer'
end
end

View file

@ -37,10 +37,8 @@ module ActionDispatch
autoload_under 'http' do
autoload :Request
autoload :Response
autoload :StatusCodes
end
deferrable do
autoload_under 'middleware' do
autoload :Callbacks
autoload :ParamsParser
@ -71,9 +69,6 @@ module ActionDispatch
autoload :TestRequest
autoload :TestResponse
end
end
autoload :HTML, 'action_controller/vendor/html-scanner'
end
autoload :Mime, 'action_dispatch/http/mime_type'

View file

@ -18,7 +18,7 @@ module ActionDispatch
HTTP_ACCEPT HTTP_ACCEPT_CHARSET HTTP_ACCEPT_ENCODING
HTTP_ACCEPT_LANGUAGE HTTP_CACHE_CONTROL HTTP_FROM
HTTP_NEGOTIATE HTTP_PRAGMA HTTP_REFERER HTTP_USER_AGENT ].each do |env|
HTTP_NEGOTIATE HTTP_PRAGMA ].each do |env|
define_method(env.sub(/^HTTP_/n, '').downcase) do
@env[env]
end

View file

@ -60,7 +60,7 @@ module ActionDispatch # :nodoc:
end
def status=(status)
@status = ActionDispatch::StatusCodes[status]
@status = Rack::Utils.status_code(status)
end
# The response code of the request
@ -74,7 +74,7 @@ module ActionDispatch # :nodoc:
end
def message
StatusCodes::STATUS_CODES[@status]
Rack::Utils::HTTP_STATUS_CODES[@status]
end
alias_method :status_message, :message

View file

@ -1,33 +0,0 @@
require 'active_support/inflector'
module ActionDispatch
module StatusCodes #:nodoc:
STATUS_CODES = Rack::Utils::HTTP_STATUS_CODES.merge({
102 => "Processing",
207 => "Multi-Status",
226 => "IM Used",
422 => "Unprocessable Entity",
423 => "Locked",
424 => "Failed Dependency",
426 => "Upgrade Required",
507 => "Insufficient Storage",
510 => "Not Extended"
}).freeze
def self.[](status)
if status.is_a?(Symbol)
SYMBOL_TO_STATUS_CODE[status] || 500
else
status.to_i
end
end
# Provides a symbol-to-fixnum lookup for converting a symbol (like
# :created or :not_implemented) into its corresponding HTTP status
# code (like 200 or 501).
SYMBOL_TO_STATUS_CODE = STATUS_CODES.inject({}) { |hash, (code, message)|
hash[ActiveSupport::Inflector.underscore(message.gsub(/ /, "")).to_sym] = code
hash
}.freeze
end
end

View file

@ -1,4 +1,5 @@
require 'active_support/json'
require 'action_dispatch/http/request'
module ActionDispatch
class ParamsParser

View file

@ -1,4 +1,5 @@
require 'rack/utils'
require 'rack/request'
module ActionDispatch
module Session

View file

@ -1,4 +1,5 @@
require "active_support/core_ext/hash/keys"
require 'active_support/core_ext/hash/keys'
require 'rack/request'
module ActionDispatch
module Session

View file

@ -1,4 +1,5 @@
require "active_support/core_ext/exception"
require 'active_support/core_ext/exception'
require 'action_dispatch/http/request'
module ActionDispatch
class ShowExceptions
@ -101,7 +102,7 @@ module ActionDispatch
end
def status_code(exception)
ActionDispatch::StatusCodes::SYMBOL_TO_STATUS_CODE[@@rescue_responses[exception.class.name]]
Rack::Utils.status_code(@@rescue_responses[exception.class.name])
end
def render(status, body)

View file

@ -1,3 +1,5 @@
require 'action_controller/vendor/html-scanner'
module ActionDispatch
module Assertions
module DomAssertions

View file

@ -28,7 +28,7 @@ module ActionDispatch
assert_block("") { true } # to count the assertion
elsif type.is_a?(Fixnum) && @response.response_code == type
assert_block("") { true } # to count the assertion
elsif type.is_a?(Symbol) && @response.response_code == ActionDispatch::StatusCodes::SYMBOL_TO_STATUS_CODE[type]
elsif type.is_a?(Symbol) && @response.response_code == Rack::Utils::SYMBOL_TO_STATUS_CODE[type]
assert_block("") { true } # to count the assertion
else
assert_block(build_message(message, "Expected response to be a <?>, but was <?>", type, @response.response_code)) { false }

View file

@ -1,3 +1,5 @@
require 'action_controller/vendor/html-scanner'
#--
# Copyright (c) 2006 Assaf Arkin (http://labnotes.org)
# Under MIT and/or CC By license.

View file

@ -1,3 +1,5 @@
require 'action_controller/vendor/html-scanner'
module ActionDispatch
module Assertions
# Pair of assertions to testing elements in the HTML output of the response.

View file

@ -31,13 +31,13 @@ require 'action_pack'
module ActionView
extend ActiveSupport::Autoload
eager_autoload do
autoload :Base
autoload :Context
autoload :Template
autoload :Helpers
autoload :SafeBuffer
autoload_under "render" do
autoload :Partials
autoload :Rendering
@ -52,6 +52,7 @@ module ActionView
autoload :TemplateError, 'action_view/template/error'
autoload :TemplateHandler, 'action_view/template'
autoload :TemplateHandlers, 'action_view/template'
end
end
require 'action_view/erb/util'

View file

@ -1,3 +1,4 @@
require 'action_controller/vendor/html-scanner'
require 'action_view/helpers/tag_helper'
module ActionView

View file

@ -8,10 +8,12 @@ module ActionView
class Template
extend ActiveSupport::Autoload
eager_autoload do
autoload :Error
autoload :Handler
autoload :Handlers
autoload :Text
end
extend Template::Handlers
attr_reader :source, :identifier, :handler, :mime_type, :formats, :details

View file

@ -1125,7 +1125,7 @@ class RenderTest < ActionController::TestCase
assert !@response.headers.include?('Content-Length')
assert_response :no_content
ActionDispatch::StatusCodes::SYMBOL_TO_STATUS_CODE.each do |status, code|
Rack::Utils::SYMBOL_TO_STATUS_CODE.each do |status, code|
get :head_with_symbolic_status, :status => status.to_s
assert_equal code, @response.response_code
assert_response status
@ -1133,7 +1133,7 @@ class RenderTest < ActionController::TestCase
end
def test_head_with_integer_status
ActionDispatch::StatusCodes::STATUS_CODES.each do |code, message|
Rack::Utils::HTTP_STATUS_CODES.each do |code, message|
get :head_with_integer_status, :status => code.to_s
assert_equal message, @response.message
end

View file

@ -1,5 +1,6 @@
require 'active_support/core_ext/array/extract_options'
require 'active_support/core_ext/hash/keys'
require 'active_model/errors'
module ActiveModel
module Validations

View file

@ -35,6 +35,7 @@ require 'arel'
module ActiveRecord
extend ActiveSupport::Autoload
eager_autoload do
autoload :VERSION
autoload :ActiveRecordError, 'active_record/base'
@ -69,10 +70,12 @@ module ActiveRecord
autoload :Transactions
autoload :Types
autoload :Validations
end
module AttributeMethods
extend ActiveSupport::Autoload
eager_autoload do
autoload :BeforeTypeCast
autoload :Dirty
autoload :PrimaryKey
@ -81,37 +84,46 @@ module ActiveRecord
autoload :TimeZoneConversion
autoload :Write
end
end
module Attributes
extend ActiveSupport::Autoload
eager_autoload do
autoload :Aliasing
autoload :Store
autoload :Typecasting
end
end
module Type
extend ActiveSupport::Autoload
eager_autoload do
autoload :Number, 'active_record/types/number'
autoload :Object, 'active_record/types/object'
autoload :Serialize, 'active_record/types/serialize'
autoload :TimeWithZone, 'active_record/types/time_with_zone'
autoload :Unknown, 'active_record/types/unknown'
end
end
module Locking
extend ActiveSupport::Autoload
eager_autoload do
autoload :Optimistic
autoload :Pessimistic
end
end
module ConnectionAdapters
extend ActiveSupport::Autoload
eager_autoload do
autoload :AbstractAdapter
end
end
end
Arel::Table.engine = Arel::Sql::Engine.new(ActiveRecord::Base)

View file

@ -13,6 +13,9 @@ require 'set'
require 'uri'
require 'active_resource/exceptions'
require 'active_resource/connection'
require 'active_resource/formats'
require 'active_resource/schema'
module ActiveResource
# ActiveResource::Base is the main class for mapping RESTful resources as models in a Rails application.

View file

@ -39,6 +39,8 @@ require "active_support/dependencies/autoload"
module ActiveSupport
extend ActiveSupport::Autoload
# TODO: Narrow this list down
eager_autoload do
autoload :BacktraceCleaner
autoload :Base64
autoload :BasicObject
@ -64,6 +66,7 @@ module ActiveSupport
autoload :SecureRandom
autoload :StringInquirer
autoload :XmlMini
end
end
require 'active_support/vendor'

View file

@ -5,13 +5,13 @@ module ActiveSupport
@@autoloads = {}
@@under_path = nil
@@at_path = nil
@@autoload_defer = false
@@eager_autoload = false
def autoload(const_name, path = @@at_path)
full = [self.name, @@under_path, const_name.to_s, path].compact.join("::")
location = path || Inflector.underscore(full)
unless @@autoload_defer
if @@eager_autoload
@@autoloads[const_name] = location
end
super const_name, location
@ -31,11 +31,11 @@ module ActiveSupport
@@at_path = old_path
end
def deferrable
old_defer, @@autoload_defer = @@autoload_defer, true
def eager_autoload
old_eager, @@eager_autoload = @@eager_autoload, true
yield
ensure
@@autoload_defer = old_defer
@@eager_autoload = old_eager
end
def self.eager_autoload!

View file

@ -208,6 +208,7 @@ module Rails
initializer :initialize_middleware_stack do
if config.frameworks.include?(:action_controller)
config.middleware.use(::Rack::Lock, :if => lambda { ActionController::Base.allow_concurrency })
config.middleware.use(::Rack::Runtime)
config.middleware.use(ActionDispatch::ShowExceptions, lambda { ActionController::Base.consider_all_requests_local })
config.middleware.use(ActionDispatch::Callbacks, lambda { ActionController::Dispatcher.prepare_each_request })
config.middleware.use(lambda { ActionController::Base.session_store }, lambda { ActionController::Base.session_options })