Skip to content

Commit

Permalink
Merge commit 'mainstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
lifo committed Aug 3, 2008
2 parents acd0456 + cb21db1 commit f6124c2
Show file tree
Hide file tree
Showing 103 changed files with 743 additions and 600 deletions.
Empty file modified actionmailer/README
100755 → 100644
Empty file.
Empty file modified actionmailer/Rakefile
100755 → 100644
Empty file.
Empty file modified actionmailer/lib/action_mailer.rb
100755 → 100644
Empty file.
19 changes: 15 additions & 4 deletions actionmailer/lib/action_mailer/base.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ class Base


private_class_method :new #:nodoc: private_class_method :new #:nodoc:


class_inheritable_accessor :template_root class_inheritable_accessor :view_paths
cattr_accessor :logger cattr_accessor :logger


cattr_accessor :template_extensions cattr_accessor :template_extensions
Expand Down Expand Up @@ -425,9 +425,12 @@ def register_template_extension(extension)
template_extensions << extension template_extensions << extension
end end


def template_root
self.view_paths && self.view_paths.first
end

def template_root=(root) def template_root=(root)
root = ActionView::PathSet::Path.new(root) if root.is_a?(String) self.view_paths = ActionView::Base.process_view_paths(root)
write_inheritable_attribute(:template_root, root)
end end
end end


Expand Down Expand Up @@ -541,12 +544,20 @@ def render(opts)
initialize_template_class(body).render(opts) initialize_template_class(body).render(opts)
end end


def template_root
self.class.template_root
end

def template_root=(root)
self.class.template_root = root
end

def template_path def template_path
"#{template_root}/#{mailer_name}" "#{template_root}/#{mailer_name}"
end end


def initialize_template_class(assigns) def initialize_template_class(assigns)
ActionView::Base.new(template_root, assigns, self) ActionView::Base.new(view_paths, assigns, self)
end end


def sort_parts(parts, order = []) def sort_parts(parts, order = [])
Expand Down
Empty file modified actionmailer/test/mail_service_test.rb
100755 → 100644
Empty file.
2 changes: 2 additions & 0 deletions actionpack/CHANGELOG
Original file line number Original file line Diff line number Diff line change
@@ -1,5 +1,7 @@
*Edge* *Edge*


* Added back ActionController::Base.allow_concurrency flag [Josh Peek]

* AbstractRequest.relative_url_root is no longer automatically configured by a HTTP header. It can now be set in your configuration environment with config.action_controller.relative_url_root [Josh Peek] * AbstractRequest.relative_url_root is no longer automatically configured by a HTTP header. It can now be set in your configuration environment with config.action_controller.relative_url_root [Josh Peek]


* Update Prototype to 1.6.0.2 #599 [Patrick Joyce] * Update Prototype to 1.6.0.2 #599 [Patrick Joyce]
Expand Down
Empty file modified actionpack/lib/action_controller.rb
100755 → 100644
Empty file.
44 changes: 22 additions & 22 deletions actionpack/lib/action_controller/assertions/routing_assertions.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module ActionController
module Assertions module Assertions
# Suite of assertions to test routes generated by Rails and the handling of requests made to them. # Suite of assertions to test routes generated by Rails and the handling of requests made to them.
module RoutingAssertions module RoutingAssertions
# Asserts that the routing of the given +path+ was handled correctly and that the parsed options (given in the +expected_options+ hash) # Asserts that the routing of the given +path+ was handled correctly and that the parsed options (given in the +expected_options+ hash)
# match +path+. Basically, it asserts that Rails recognizes the route given by +expected_options+. # match +path+. Basically, it asserts that Rails recognizes the route given by +expected_options+.
# #
# Pass a hash in the second argument (+path+) to specify the request method. This is useful for routes # Pass a hash in the second argument (+path+) to specify the request method. This is useful for routes
Expand All @@ -14,16 +14,16 @@ module RoutingAssertions
# #
# You can also pass in +extras+ with a hash containing URL parameters that would normally be in the query string. This can be used # 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 # 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: # 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 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. # The +message+ parameter allows you to pass in an error message that is displayed upon failure.
# #
# ==== Examples # ==== Examples
# # Check the default route (i.e., the index action) # # 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 # # Test a specific action
# assert_recognizes({:controller => 'items', :action => 'list'}, 'items/list') # assert_recognizes({:controller => 'items', :action => 'list'}, 'items/list')
Expand All @@ -44,16 +44,16 @@ def assert_recognizes(expected_options, path, extras={}, message=nil)
request_method = nil request_method = nil
end end


clean_backtrace do clean_backtrace do
ActionController::Routing::Routes.reload if ActionController::Routing::Routes.empty? ActionController::Routing::Routes.reload if ActionController::Routing::Routes.empty?
request = recognized_request_for(path, request_method) request = recognized_request_for(path, request_method)

expected_options = expected_options.clone expected_options = expected_options.clone
extras.each_key { |key| expected_options.delete key } unless extras.nil? extras.each_key { |key| expected_options.delete key } unless extras.nil?

expected_options.stringify_keys! expected_options.stringify_keys!
routing_diff = expected_options.diff(request.path_parameters) routing_diff = expected_options.diff(request.path_parameters)
msg = build_message(message, "The recognized options <?> did not match <?>, difference: <?>", msg = build_message(message, "The recognized options <?> did not match <?>, difference: <?>",
request.path_parameters, expected_options, expected_options.diff(request.path_parameters)) request.path_parameters, expected_options, expected_options.diff(request.path_parameters))
assert_block(msg) { request.path_parameters == expected_options } assert_block(msg) { request.path_parameters == expected_options }
end end
Expand All @@ -64,7 +64,7 @@ def assert_recognizes(expected_options, path, extras={}, message=nil)
# a query string. The +message+ parameter allows you to specify a custom error message for assertion failures. # a query string. The +message+ parameter allows you to specify a custom error message for assertion failures.
# #
# The +defaults+ parameter is unused. # The +defaults+ parameter is unused.
# #
# ==== Examples # ==== Examples
# # Asserts that the default action is generated for a route with no action # # 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")
Expand All @@ -73,34 +73,34 @@ def assert_recognizes(expected_options, path, extras={}, message=nil)
# 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 # # 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 # # 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) def assert_generates(expected_path, options, defaults={}, extras = {}, message=nil)
clean_backtrace do clean_backtrace do
expected_path = "/#{expected_path}" unless expected_path[0] == ?/ expected_path = "/#{expected_path}" unless expected_path[0] == ?/
# Load routes.rb if it hasn't been loaded. # Load routes.rb if it hasn't been loaded.
ActionController::Routing::Routes.reload if ActionController::Routing::Routes.empty? ActionController::Routing::Routes.reload if ActionController::Routing::Routes.empty?

generated_path, extra_keys = ActionController::Routing::Routes.generate_extras(options, defaults) generated_path, extra_keys = ActionController::Routing::Routes.generate_extras(options, defaults)
found_extras = options.reject {|k, v| ! extra_keys.include? k} found_extras = options.reject {|k, v| ! extra_keys.include? k}


msg = build_message(message, "found extras <?>, not <?>", found_extras, extras) msg = build_message(message, "found extras <?>, not <?>", found_extras, extras)
assert_block(msg) { found_extras == extras } assert_block(msg) { found_extras == extras }

msg = build_message(message, "The generated path <?> did not match <?>", generated_path, msg = build_message(message, "The generated path <?> did not match <?>", generated_path,
expected_path) expected_path)
assert_block(msg) { expected_path == generated_path } assert_block(msg) { expected_path == generated_path }
end end
end end


# Asserts that path and options match both ways; in other words, it verifies that <tt>path</tt> generates # Asserts that path and options match both ways; in other words, it verifies that <tt>path</tt> generates
# <tt>options</tt> and then that <tt>options</tt> generates <tt>path</tt>. This essentially combines +assert_recognizes+ # <tt>options</tt> and then that <tt>options</tt> generates <tt>path</tt>. This essentially combines +assert_recognizes+
# and +assert_generates+ into one step. # and +assert_generates+ into one step.
# #
# The +extras+ hash allows you to specify options that would normally be provided as a query string to the action. The # The +extras+ hash allows you to specify options that would normally be provided as a query string to the action. The
# +message+ parameter allows you to specify a custom error message to display upon failure. # +message+ parameter allows you to specify a custom error message to display upon failure.
# #
# ==== Examples # ==== Examples
# # Assert a basic route: a controller with the default action (index) # # Assert a basic route: a controller with the default action (index)
Expand All @@ -119,12 +119,12 @@ def assert_generates(expected_path, options, defaults={}, extras = {}, message=n
# 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) def assert_routing(path, options, defaults={}, extras={}, message=nil)
assert_recognizes(options, path, extras, message) assert_recognizes(options, path, extras, message)

controller, default_controller = options[:controller], defaults[:controller] controller, default_controller = options[:controller], defaults[:controller]
if controller && controller.include?(?/) && default_controller && default_controller.include?(?/) if controller && controller.include?(?/) && default_controller && default_controller.include?(?/)
options[:controller] = "/#{controller}" options[:controller] = "/#{controller}"
end end

assert_generates(path.is_a?(Hash) ? path[:path] : path, options, defaults, extras, message) assert_generates(path.is_a?(Hash) ? path[:path] : path, options, defaults, extras, message)
end end


Expand Down
26 changes: 16 additions & 10 deletions actionpack/lib/action_controller/assertions/selector_assertions.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -407,6 +407,7 @@ def assert_select_rjs(*args, &block)


if rjs_type == :insert if rjs_type == :insert
arg = args.shift arg = args.shift
position = arg
insertion = "insert_#{arg}".to_sym insertion = "insert_#{arg}".to_sym
raise ArgumentError, "Unknown RJS insertion type #{arg}" unless RJS_STATEMENTS[insertion] raise ArgumentError, "Unknown RJS insertion type #{arg}" unless RJS_STATEMENTS[insertion]
statement = "(#{RJS_STATEMENTS[insertion]})" statement = "(#{RJS_STATEMENTS[insertion]})"
Expand All @@ -418,6 +419,7 @@ def assert_select_rjs(*args, &block)
else else
statement = "#{RJS_STATEMENTS[:any]}" statement = "#{RJS_STATEMENTS[:any]}"
end end
position ||= Regexp.new(RJS_INSERTIONS.join('|'))


# Next argument we're looking for is the element identifier. If missing, we pick # Next argument we're looking for is the element identifier. If missing, we pick
# any element. # any element.
Expand All @@ -434,9 +436,14 @@ def assert_select_rjs(*args, &block)
Regexp.new("\\$\\(\"#{id}\"\\)#{statement}\\(#{RJS_PATTERN_HTML}\\)", Regexp::MULTILINE) Regexp.new("\\$\\(\"#{id}\"\\)#{statement}\\(#{RJS_PATTERN_HTML}\\)", Regexp::MULTILINE)
when :remove, :show, :hide, :toggle when :remove, :show, :hide, :toggle
Regexp.new("#{statement}\\(\"#{id}\"\\)") Regexp.new("#{statement}\\(\"#{id}\"\\)")
else when :replace, :replace_html
Regexp.new("#{statement}\\(\"#{id}\", #{RJS_PATTERN_HTML}\\)", Regexp::MULTILINE) Regexp.new("#{statement}\\(\"#{id}\", #{RJS_PATTERN_HTML}\\)")
end when :insert, :insert_html
Regexp.new("Element.insert\\(\\\"#{id}\\\", \\{ #{position}: #{RJS_PATTERN_HTML} \\}\\);")
else
Regexp.union(Regexp.new("#{statement}\\(\"#{id}\", #{RJS_PATTERN_HTML}\\)"),
Regexp.new("Element.insert\\(\\\"#{id}\\\", \\{ #{position}: #{RJS_PATTERN_HTML} \\}\\);"))
end


# Duplicate the body since the next step involves destroying it. # Duplicate the body since the next step involves destroying it.
matches = nil matches = nil
Expand All @@ -445,7 +452,7 @@ def assert_select_rjs(*args, &block)
matches = @response.body.match(pattern) matches = @response.body.match(pattern)
else else
@response.body.gsub(pattern) do |match| @response.body.gsub(pattern) do |match|
html = unescape_rjs($2) html = unescape_rjs(match)
matches ||= [] matches ||= []
matches.concat HTML::Document.new(html).root.children.select { |n| n.tag? } matches.concat HTML::Document.new(html).root.children.select { |n| n.tag? }
"" ""
Expand Down Expand Up @@ -585,17 +592,16 @@ def assert_select_email(&block)
:hide => /Element\.hide/, :hide => /Element\.hide/,
:toggle => /Element\.toggle/ :toggle => /Element\.toggle/
} }
RJS_STATEMENTS[:any] = Regexp.new("(#{RJS_STATEMENTS.values.join('|')})")
RJS_PATTERN_HTML = /"((\\"|[^"])*)"/
RJS_INSERTIONS = [:top, :bottom, :before, :after] RJS_INSERTIONS = [:top, :bottom, :before, :after]
RJS_INSERTIONS.each do |insertion| RJS_INSERTIONS.each do |insertion|
RJS_STATEMENTS["insert_#{insertion}".to_sym] = Regexp.new(Regexp.quote("new Insertion.#{insertion.to_s.camelize}")) RJS_STATEMENTS["insert_#{insertion}".to_sym] = /Element.insert\(\"([^\"]*)\", \{ #{insertion.to_s.downcase}: #{RJS_PATTERN_HTML} \}\);/
end end
RJS_STATEMENTS[:any] = Regexp.new("(#{RJS_STATEMENTS.values.join('|')})")
RJS_STATEMENTS[:insert_html] = Regexp.new(RJS_INSERTIONS.collect do |insertion| RJS_STATEMENTS[:insert_html] = Regexp.new(RJS_INSERTIONS.collect do |insertion|
Regexp.quote("new Insertion.#{insertion.to_s.camelize}") /Element.insert\(\"([^\"]*)\", \{ #{insertion.to_s.downcase}: #{RJS_PATTERN_HTML} \}\);/
end.join('|')) end.join('|'))
RJS_PATTERN_HTML = /"((\\"|[^"])*)"/ RJS_PATTERN_EVERYTHING = Regexp.new("#{RJS_STATEMENTS[:any]}\\(\"([^\"]*)\", #{RJS_PATTERN_HTML}\\)", Regexp::MULTILINE)
RJS_PATTERN_EVERYTHING = Regexp.new("#{RJS_STATEMENTS[:any]}\\(\"([^\"]*)\", #{RJS_PATTERN_HTML}\\)",
Regexp::MULTILINE)
RJS_PATTERN_UNICODE_ESCAPED_CHAR = /\\u([0-9a-zA-Z]{4})/ RJS_PATTERN_UNICODE_ESCAPED_CHAR = /\\u([0-9a-zA-Z]{4})/
end end


Expand Down
17 changes: 15 additions & 2 deletions actionpack/lib/action_controller/base.rb
100755 → 100644
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -283,6 +283,14 @@ class Base
@@debug_routes = true @@debug_routes = true
cattr_accessor :debug_routes cattr_accessor :debug_routes


# Indicates 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

@@guard = Monitor.new

# Modern REST web services often need to submit complex data to the web application. # Modern REST web services often need to submit complex data to the web application.
# The <tt>@@param_parsers</tt> hash lets you register handlers which will process the HTTP body and add parameters to the # The <tt>@@param_parsers</tt> hash lets you register handlers which will process the HTTP body and add parameters to the
# <tt>params</tt> hash. These handlers are invoked for POST and PUT requests. # <tt>params</tt> hash. These handlers are invoked for POST and PUT requests.
Expand Down Expand Up @@ -537,7 +545,12 @@ def process(request, response, method = :perform_action, *arguments) #:nodoc:
forget_variables_added_to_assigns forget_variables_added_to_assigns


log_processing log_processing
send(method, *arguments)
if @@allow_concurrency
send(method, *arguments)
else
@@guard.synchronize { send(method, *arguments) }
end


assign_default_content_type_and_charset assign_default_content_type_and_charset
response.prepare! unless component_request? response.prepare! unless component_request?
Expand Down Expand Up @@ -1195,7 +1208,7 @@ def perform_action
elsif template_exists? && template_public? elsif template_exists? && template_public?
default_render default_render
else else
raise UnknownAction, "No action responded to #{action_name}", caller raise UnknownAction, "No action responded to #{action_name}. Actions: #{action_methods.to_a.sort.to_sentence}", caller
end end
end end


Expand Down
18 changes: 7 additions & 11 deletions actionpack/lib/action_controller/dispatcher.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ module ActionController
# Dispatches requests to the appropriate controller and takes care of # Dispatches requests to the appropriate controller and takes care of
# reloading the app after each request when Dependencies.load? is true. # reloading the app after each request when Dependencies.load? is true.
class Dispatcher class Dispatcher
@@guard = Mutex.new

class << self class << self
def define_dispatcher_callbacks(cache_classes) def define_dispatcher_callbacks(cache_classes)
unless cache_classes unless cache_classes
Expand Down Expand Up @@ -101,15 +99,13 @@ def initialize(output = $stdout, request = nil, response = nil)
end end


def dispatch def dispatch
@@guard.synchronize do begin
begin run_callbacks :before_dispatch
run_callbacks :before_dispatch handle_request
handle_request rescue Exception => exception
rescue Exception => exception failsafe_rescue exception
failsafe_rescue exception ensure
ensure run_callbacks :after_dispatch, :enumerator => :reverse_each
run_callbacks :after_dispatch, :enumerator => :reverse_each
end
end end
end end


Expand Down
2 changes: 1 addition & 1 deletion actionpack/lib/action_controller/integration.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ def copy_session_variables! #:nodoc:
# Delegate unhandled messages to the current session instance. # Delegate unhandled messages to the current session instance.
def method_missing(sym, *args, &block) def method_missing(sym, *args, &block)
reset! unless @integration_session reset! unless @integration_session
returning @integration_session.send!(sym, *args, &block) do returning @integration_session.__send__(sym, *args, &block) do
copy_session_variables! copy_session_variables!
end end
end end
Expand Down
Empty file modified actionpack/lib/action_controller/request.rb
100755 → 100644
Empty file.
Empty file modified actionpack/lib/action_controller/request_profiler.rb
100755 → 100644
Empty file.
Empty file modified actionpack/lib/action_controller/response.rb
100755 → 100644
Empty file.
Loading

0 comments on commit f6124c2

Please sign in to comment.