Permalink
Browse files

Merge branch 'master' of git@github.com:lifo/docrails

  • Loading branch information...
Colin Curtin
Colin Curtin committed Dec 21, 2008
2 parents b018743 + a0d091a commit 0e121f9ed93ebb417cc63307aaaf47f8adfd220d
Showing with 2,449 additions and 2,511 deletions.
  1. +8 −8 actionmailer/CHANGELOG
  2. +374 −374 actionpack/CHANGELOG
  3. +1 −0 actionpack/lib/action_controller.rb
  4. +0 −5 actionpack/lib/action_controller/base.rb
  5. +2 −0 actionpack/lib/action_controller/cookies.rb
  6. +26 −33 actionpack/lib/action_controller/dispatcher.rb
  7. +1 −1 actionpack/lib/action_controller/failsafe.rb
  8. +18 −11 actionpack/lib/action_controller/integration.rb
  9. +16 −0 actionpack/lib/action_controller/lock.rb
  10. +29 −5 actionpack/lib/action_controller/middleware_stack.rb
  11. +2 −7 actionpack/lib/action_controller/rack_process.rb
  12. +1 −1 actionpack/lib/action_controller/rescue.rb
  13. +1 −1 actionpack/lib/action_controller/routing/recognition_optimisation.rb
  14. +28 −1 actionpack/lib/action_controller/session/abstract_store.rb
  15. +43 −17 actionpack/lib/action_controller/session/cookie_store.rb
  16. +0 −29 actionpack/lib/action_controller/session_management.rb
  17. +13 −5 actionpack/lib/action_view/helpers/form_options_helper.rb
  18. +7 −3 actionpack/lib/action_view/template.rb
  19. +1 −24 actionpack/lib/action_view/template_handlers.rb
  20. +4 −2 actionpack/test/controller/dispatcher_test.rb
  21. +31 −0 actionpack/test/controller/integration_test.rb
  22. +3 −3 actionpack/test/controller/rack_test.rb
  23. +24 −2 actionpack/test/controller/session/cookie_store_test.rb
  24. +0 −84 actionpack/test/controller/session_fixation_test.rb
  25. +392 −392 activerecord/CHANGELOG
  26. +13 −3 activerecord/lib/active_record/association_preload.rb
  27. +33 −10 activerecord/lib/active_record/associations.rb
  28. +5 −1 activerecord/lib/active_record/associations/association_collection.rb
  29. +1 −1 activerecord/lib/active_record/base.rb
  30. +1 −1 activerecord/lib/active_record/connection_adapters/abstract/connection_specification.rb
  31. +3 −3 activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb
  32. +13 −4 activerecord/lib/active_record/connection_adapters/mysql_adapter.rb
  33. +67 −1 activerecord/test/cases/associations/eager_test.rb
  34. +3 −0 activerecord/test/cases/associations/has_many_through_associations_test.rb
  35. +16 −1 activerecord/test/cases/associations/has_one_through_associations_test.rb
  36. +4 −0 activerecord/test/cases/helper.rb
  37. +50 −0 activerecord/test/cases/repair_helper.rb
  38. +191 −160 activerecord/test/cases/validations_test.rb
  39. +6 −0 activerecord/test/fixtures/member_types.yml
  40. +3 −1 activerecord/test/fixtures/members.yml
  41. +1 −0 activerecord/test/models/member.rb
  42. +1 −0 activerecord/test/models/member_detail.rb
  43. +3 −0 activerecord/test/models/member_type.rb
  44. +5 −0 activerecord/test/schema/schema.rb
  45. +21 −21 activeresource/CHANGELOG
  46. +88 −88 activesupport/CHANGELOG
  47. +3 −3 activesupport/lib/active_support/core_ext/float/rounding.rb
  48. +195 −195 railties/CHANGELOG
  49. +6 −0 railties/doc/guides/html/finders.html
  50. +1 −1 railties/doc/guides/html/getting_started_with_rails.html
  51. +1 −1 railties/doc/guides/html/layouts_and_rendering.html
  52. +516 −954 railties/doc/guides/html/testing_rails_applications.html
  53. +31 −13 railties/doc/guides/source/finders.txt
  54. +1 −1 railties/doc/guides/source/getting_started_with_rails.txt
  55. +9 −9 railties/doc/guides/source/testing_rails_applications.txt
  56. +1 −1 railties/lib/commands/server.rb
  57. +8 −0 railties/lib/initializer.rb
  58. +2 −1 railties/lib/rails/rack.rb
  59. +31 −0 railties/lib/rails/rack/cascade.rb
  60. +35 −0 railties/lib/rails/rack/log_tailer.rb
  61. +0 −28 railties/lib/rails/rack/logger.rb
  62. +27 −0 railties/lib/rails/rack/metal.rb
  63. +8 −0 railties/lib/rails_generator/generators/components/metal/USAGE
  64. +8 −0 railties/lib/rails_generator/generators/components/metal/metal_generator.rb
  65. +12 −0 railties/lib/rails_generator/generators/components/metal/templates/metal.rb
  66. +1 −1 railties/lib/tasks/middleware.rake
View
@@ -12,7 +12,7 @@
*2.2.0 [RC1] (October 24th, 2008)*
-* Add layout functionality to mailers [Pratik]
+* Add layout functionality to mailers [Pratik Naik]
Mailer layouts behaves just like controller layouts, except layout names need to
have '_mailer' postfix for them to be automatically picked up.
@@ -24,7 +24,7 @@
* Less verbose mail logging: just recipients for :info log level; the whole email for :debug only. #8000 [iaddict, Tarmo Tänav]
-* Updated TMail to version 1.2.1 [raasdnil]
+* Updated TMail to version 1.2.1 [Mikel Lindsaar]
* Fixed that you don't have to call super in ActionMailer::TestCase#setup #10406 [jamesgolick]
@@ -36,7 +36,7 @@
*2.0.1* (December 7th, 2007)
-* Update ActionMailer so it treats ActionView the same way that ActionController does. Closes #10244 [rick]
+* Update ActionMailer so it treats ActionView the same way that ActionController does. Closes #10244 [Rick Olson]
* Pass the template_root as an array as ActionView's view_path
* Request templates with the "#{mailer_name}/#{action}" as opposed to just "#{action}"
@@ -45,11 +45,11 @@
* Update README to use new smtp settings configuration API. Closes #10060 [psq]
-* Allow ActionMailer subclasses to individually set their delivery method (so two subclasses can have different delivery methods) #10033 [zdennis]
+* Allow ActionMailer subclasses to individually set their delivery method (so two subclasses can have different delivery methods) #10033 [Zach Dennis]
-* Update TMail to v1.1.0. Use an updated version of TMail if available. [mikel]
+* Update TMail to v1.1.0. Use an updated version of TMail if available. [Mikel Lindsaar]
-* Introduce a new base test class for testing Mailers. ActionMailer::TestCase [Koz]
+* Introduce a new base test class for testing Mailers. ActionMailer::TestCase [Michael Koziarski]
* Fix silent failure of rxml templates. #9879 [jstewart]
@@ -84,7 +84,7 @@
*1.3.2* (February 5th, 2007)
-* Deprecate server_settings renaming it to smtp_settings, add sendmail_settings to allow you to override the arguments to and location of the sendmail executable. [Koz]
+* Deprecate server_settings renaming it to smtp_settings, add sendmail_settings to allow you to override the arguments to and location of the sendmail executable. [Michael Koziarski]
*1.3.1* (January 16th, 2007)
@@ -104,7 +104,7 @@
* Tighten rescue clauses. #5985 [james@grayproductions.net]
-* Automatically included ActionController::UrlWriter, such that URL generation can happen within ActionMailer controllers. [DHH]
+* Automatically included ActionController::UrlWriter, such that URL generation can happen within ActionMailer controllers. [David Heinemeier Hansson]
* Replace Reloadable with Reloadable::Deprecated. [Nicholas Seckar]
View

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -56,6 +56,7 @@ def self.load_all!
autoload :Integration, 'action_controller/integration'
autoload :IntegrationTest, 'action_controller/integration'
autoload :Layout, 'action_controller/layout'
+ autoload :Lock, 'action_controller/lock'
autoload :MiddlewareStack, 'action_controller/middleware_stack'
autoload :MimeResponds, 'action_controller/mime_responds'
autoload :PolymorphicRoutes, 'action_controller/polymorphic_routes'
@@ -1160,13 +1160,8 @@ def expires_now #:doc:
def reset_session #:doc:
request.reset_session
@_session = request.session
- #http://rails.lighthouseapp.com/projects/8994/tickets/1558-memory-problem-on-reset_session-in-around_filter#ticket-1558-1
- #MRI appears to have a GC related memory leak to do with the finalizer that is defined on CGI::Session
- ObjectSpace.undefine_finalizer(@_session)
- response.session = @_session
end
-
private
def render_for_file(template_path, status = nil, layout = nil, locals = {}) #:nodoc:
logger.info("Rendering #{template_path}" + (status ? " (#{status})" : '')) if logger
@@ -67,6 +67,8 @@ def [](name)
cookie = @cookies[name.to_s]
if cookie && cookie.respond_to?(:value)
cookie.size > 1 ? cookie.value : cookie.value[0]
+ else
+ cookie
end
end
@@ -2,8 +2,6 @@ module ActionController
# Dispatches requests to the appropriate controller and takes care of
# reloading the app after each request when Dependencies.load? is true.
class Dispatcher
- @@guard = Mutex.new
-
class << self
def define_dispatcher_callbacks(cache_classes)
unless cache_classes
@@ -46,40 +44,49 @@ def to_prepare(identifier = nil, &block)
cattr_accessor :middleware
self.middleware = MiddlewareStack.new do |middleware|
+ middleware.use "ActionController::Lock", :if => lambda {
+ !ActionController::Base.allow_concurrency
+ }
middleware.use "ActionController::Failsafe"
- middleware.use "ActionController::SessionManagement::Middleware"
+
+ ["ActionController::Session::CookieStore",
+ "ActionController::Session::MemCacheStore",
+ "ActiveRecord::SessionStore"].each do |store|
+ middleware.use(store, ActionController::Base.session_options,
+ :if => lambda {
+ if session_store = ActionController::Base.session_store
+ session_store.name == store
+ end
+ }
+ )
+ end
end
include ActiveSupport::Callbacks
define_callbacks :prepare_dispatch, :before_dispatch, :after_dispatch
- # DEPRECATE: Remove arguments
+ # DEPRECATE: Remove arguments, since they are only used by CGI
def initialize(output = $stdout, request = nil, response = nil)
- @output, @request, @response = output, request, response
+ @output = output
@app = @@middleware.build(lambda { |env| self.dup._call(env) })
end
- def dispatch_unlocked
+ def dispatch
begin
run_callbacks :before_dispatch
- handle_request
+ controller = Routing::Routes.recognize(@request)
+ controller.process(@request, @response).to_a
rescue Exception => exception
- failsafe_rescue exception
+ if controller ||= (::ApplicationController rescue Base)
+ controller.process_with_exception(@request, @response, exception).to_a
+ else
+ raise exception
+ end
ensure
run_callbacks :after_dispatch, :enumerator => :reverse_each
end
end
- def dispatch
- if ActionController::Base.allow_concurrency
- dispatch_unlocked
- else
- @@guard.synchronize do
- dispatch_unlocked
- end
- end
- end
-
# DEPRECATE: Remove CGI support
def dispatch_cgi(cgi, session_options)
CGIHandler.dispatch_cgi(self, cgi, @output)
@@ -118,22 +125,8 @@ def flush_logger
def checkin_connections
# Don't return connection (and peform implicit rollback) if this request is a part of integration test
# TODO: This callback should have direct access to env
- return if @request.key?("action_controller.test")
+ return if @request.key?("rack.test")
ActiveRecord::Base.clear_active_connections!
end
-
- protected
- def handle_request
- @controller = Routing::Routes.recognize(@request)
- @controller.process(@request, @response).out
- end
-
- def failsafe_rescue(exception)
- if @controller ||= (::ApplicationController rescue Base)
- @controller.process_with_exception(@request, @response, exception).out
- else
- raise exception
- end
- end
end
end
@@ -11,7 +11,7 @@ def call(env)
@app.call(env)
rescue Exception => exception
# Reraise exception in test environment
- if env["action_controller.test"]
+ if env["rack.test"]
raise exception
else
failsafe_response(exception)
@@ -276,6 +276,7 @@ def process(method, path, parameters = nil, headers = nil)
"SCRIPT_NAME" => "",
"REQUEST_URI" => path,
+ "PATH_INFO" => path,
"HTTP_HOST" => host,
"REMOTE_ADDR" => remote_addr,
"CONTENT_TYPE" => "application/x-www-form-urlencoded",
@@ -290,7 +291,7 @@ def process(method, path, parameters = nil, headers = nil)
"rack.multiprocess" => true,
"rack.run_once" => false,
- "action_controller.test" => true
+ "rack.test" => true
)
(headers || {}).each do |key, value|
@@ -310,16 +311,6 @@ def process(method, path, parameters = nil, headers = nil)
status, headers, body = app.call(env)
@request_count += 1
- if @controller = ActionController::Base.last_instantiation
- @request = @controller.request
- @response = @controller.response
-
- # Decorate the response with the standard behavior of the
- # TestResponse so that things like assert_response can be
- # used in integration tests.
- @response.extend(TestResponseBehavior)
- end
-
@html_document = nil
@status = status.to_i
@@ -335,6 +326,22 @@ def process(method, path, parameters = nil, headers = nil)
@body = ""
body.each { |part| @body << part }
+ if @controller = ActionController::Base.last_instantiation
+ @request = @controller.request
+ @response = @controller.response
+ else
+ # Decorate responses from Rack Middleware and Rails Metal
+ # as an AbstractResponse for the purposes of integration testing
+ @response = AbstractResponse.new
+ @response.headers = @headers.merge('Status' => status.to_s)
+ @response.body = @body
+ end
+
+ # Decorate the response with the standard behavior of the
+ # TestResponse so that things like assert_response can be
+ # used in integration tests.
+ @response.extend(TestResponseBehavior)
+
return @status
rescue MultiPartNeededException
boundary = "----------XnJLe9ZIbbGUYtzPQJ16u1"
@@ -0,0 +1,16 @@
+module ActionController
+ class Lock
+ FLAG = 'rack.multithread'.freeze
+
+ def initialize(app, lock = Mutex.new)
+ @app, @lock = app, lock
+ end
+
+ def call(env)
+ old, env[FLAG] = env[FLAG], false
+ @lock.synchronize { @app.call(env) }
+ ensure
+ env[FLAG] = old
+ end
+ end
+end
@@ -1,19 +1,39 @@
module ActionController
class MiddlewareStack < Array
class Middleware
- attr_reader :klass, :args, :block
+ attr_reader :args, :block
def initialize(klass, *args, &block)
- if klass.is_a?(Class)
- @klass = klass
+ @klass = klass
+
+ options = args.extract_options!
+ if options.has_key?(:if)
+ @conditional = options.delete(:if)
else
- @klass = klass.to_s.constantize
+ @conditional = true
end
+ args << options unless options.empty?
@args = args
@block = block
end
+ def klass
+ if @klass.is_a?(Class)
+ @klass
+ else
+ @klass.to_s.constantize
+ end
+ end
+
+ def active?
+ if @conditional.respond_to?(:call)
+ @conditional.call
+ else
+ @conditional
+ end
+ end
+
def ==(middleware)
case middleware
when Middleware
@@ -50,8 +70,12 @@ def use(*args, &block)
push(middleware)
end
+ def active
+ find_all { |middleware| middleware.active? }
+ end
+
def build(app)
- reverse.inject(app) { |a, e| e.build(a) }
+ active.reverse.inject(app) { |a, e| e.build(a) }
end
end
end
@@ -83,11 +83,7 @@ def status
@status || super
end
- def out(&block)
- # Nasty hack because CGI sessions are closed after the normal
- # prepare! statement
- set_cookies!
-
+ def to_a(&block)
@block = block
@status = headers.delete("Status")
if [204, 304].include?(status.to_i)
@@ -97,7 +93,6 @@ def out(&block)
[status, headers.to_hash, self]
end
end
- alias to_a out
def each(&callback)
if @body.respond_to?(:call)
@@ -132,7 +127,7 @@ def prepare!
convert_language!
convert_expires!
set_status!
- # set_cookies!
+ set_cookies!
end
private
@@ -104,7 +104,7 @@ def render_optional_error_file(status_code)
status = interpret_status(status_code)
path = "#{Rails.public_path}/#{status[0,3]}.html"
if File.exist?(path)
- render :file => path, :status => status
+ render :file => path, :status => status, :content_type => Mime::HTML
else
head status
end
@@ -56,7 +56,7 @@ def recognize_path(path, environment={})
result = recognize_optimized(path, environment) and return result
# Route was not recognized. Try to find out why (maybe wrong verb).
- allows = HTTP_METHODS.select { |verb| routes.find { |r| r.recognize(path, :method => verb) } }
+ allows = HTTP_METHODS.select { |verb| routes.find { |r| r.recognize(path, environment.merge(:method => verb)) } }
if environment[:method] && !HTTP_METHODS.include?(environment[:method])
raise NotImplemented.new(*allows)
Oops, something went wrong.

0 comments on commit 0e121f9

Please sign in to comment.