aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack
diff options
context:
space:
mode:
Diffstat (limited to 'actionpack')
-rw-r--r--actionpack/actionpack.gemspec2
-rw-r--r--actionpack/lib/abstract_controller.rb25
-rw-r--r--actionpack/lib/abstract_controller/rendering_controller.rb2
-rw-r--r--actionpack/lib/action_controller.rb116
-rw-r--r--actionpack/lib/action_controller/base.rb18
-rw-r--r--actionpack/lib/action_controller/caching.rb7
-rw-r--r--actionpack/lib/action_controller/deprecated/integration_test.rb2
-rw-r--r--actionpack/lib/action_controller/metal/compatibility.rb2
-rw-r--r--actionpack/lib/action_controller/metal/exceptions.rb11
-rw-r--r--actionpack/lib/action_controller/metal/flash.rb24
-rw-r--r--actionpack/lib/action_controller/metal/helpers.rb2
-rw-r--r--actionpack/lib/action_controller/metal/render_options.rb101
-rw-r--r--actionpack/lib/action_controller/metal/rescue.rb (renamed from actionpack/lib/action_controller/metal/rescuable.rb)0
-rw-r--r--actionpack/lib/action_controller/metal/responder.rb9
-rw-r--r--actionpack/lib/action_controller/test_case.rb (renamed from actionpack/lib/action_controller/testing/test_case.rb)3
-rw-r--r--actionpack/lib/action_controller/vendor/html-scanner.rb2
-rw-r--r--actionpack/lib/action_dispatch.rb41
-rw-r--r--actionpack/lib/action_dispatch/http/status_codes.rb17
-rw-r--r--actionpack/lib/action_dispatch/middleware/show_exceptions.rb8
-rw-r--r--actionpack/lib/action_dispatch/routing/mapper.rb614
-rw-r--r--actionpack/lib/action_dispatch/routing/route_set.rb104
-rw-r--r--actionpack/lib/action_dispatch/test_case.rb6
-rw-r--r--actionpack/lib/action_dispatch/testing/assertions/routing.rb6
-rw-r--r--actionpack/lib/action_dispatch/testing/performance_test.rb24
-rw-r--r--actionpack/lib/action_view.rb30
-rw-r--r--actionpack/lib/action_view/base.rb2
-rw-r--r--actionpack/lib/action_view/paths.rb2
-rw-r--r--actionpack/lib/action_view/template.rb (renamed from actionpack/lib/action_view/template/template.rb)15
-rw-r--r--actionpack/lib/action_view/template/error.rb156
-rw-r--r--actionpack/lib/action_view/template/handler.rb47
-rw-r--r--actionpack/lib/action_view/template/handlers.rb96
-rw-r--r--actionpack/lib/action_view/template/handlers/builder.rb4
-rw-r--r--actionpack/lib/action_view/template/handlers/erb.rb4
-rw-r--r--actionpack/lib/action_view/template/handlers/rjs.rb4
-rw-r--r--actionpack/lib/action_view/template/resolver.rb6
-rw-r--r--actionpack/lib/action_view/template/text.rb70
-rw-r--r--actionpack/lib/action_view/test_case.rb2
-rw-r--r--actionpack/test/abstract/layouts_test.rb26
-rw-r--r--actionpack/test/abstract/render_test.rb2
-rw-r--r--actionpack/test/abstract_unit.rb2
-rw-r--r--actionpack/test/activerecord/active_record_store_test.rb2
-rw-r--r--actionpack/test/controller/action_pack_assertions_test.rb22
-rw-r--r--actionpack/test/controller/base_test.rb6
-rw-r--r--actionpack/test/controller/caching_test.rb7
-rw-r--r--actionpack/test/controller/helper_test.rb2
-rw-r--r--actionpack/test/controller/layout_test.rb2
-rw-r--r--actionpack/test/controller/mime_responds_test.rb50
-rw-r--r--actionpack/test/controller/redirect_test.rb4
-rw-r--r--actionpack/test/controller/render_other_test.rb14
-rw-r--r--actionpack/test/controller/render_test.rb30
-rw-r--r--actionpack/test/controller/render_xml_test.rb4
-rw-r--r--actionpack/test/controller/resources_test.rb8
-rw-r--r--actionpack/test/controller/routing_test.rb221
-rw-r--r--actionpack/test/controller/test_test.rb17
-rw-r--r--actionpack/test/controller/url_rewriter_test.rb10
-rw-r--r--actionpack/test/controller/webservice_test.rb4
-rw-r--r--actionpack/test/dispatch/request/multipart_params_parsing_test.rb2
-rw-r--r--actionpack/test/dispatch/routing_test.rb91
-rw-r--r--actionpack/test/template/atom_feed_helper_test.rb12
-rw-r--r--actionpack/test/template/render_test.rb8
-rw-r--r--actionpack/test/template/test_case_test.rb4
-rw-r--r--actionpack/test/template/url_helper_test.rb8
62 files changed, 1070 insertions, 1072 deletions
diff --git a/actionpack/actionpack.gemspec b/actionpack/actionpack.gemspec
index e191a12997..23d478fd44 100644
--- a/actionpack/actionpack.gemspec
+++ b/actionpack/actionpack.gemspec
@@ -18,7 +18,7 @@ Gem::Specification.new do |s|
s.add_dependency('activemodel', '= 3.0.pre')
s.add_dependency('rack', '~> 1.0.1')
s.add_dependency('rack-test', '~> 0.5.0')
- s.add_dependency('rack-mount', '~> 0.3.0')
+ s.add_dependency('rack-mount', '~> 0.3.2')
s.add_dependency('erubis', '~> 2.6.5')
s.require_path = 'lib'
diff --git a/actionpack/lib/abstract_controller.rb b/actionpack/lib/abstract_controller.rb
index 1a6c4278c9..688a2fe31c 100644
--- a/actionpack/lib/abstract_controller.rb
+++ b/actionpack/lib/abstract_controller.rb
@@ -2,15 +2,20 @@ require "active_support/core_ext/module/attr_internal"
require "active_support/core_ext/module/delegation"
module AbstractController
- autoload :Base, "abstract_controller/base"
- autoload :Callbacks, "abstract_controller/callbacks"
- autoload :Helpers, "abstract_controller/helpers"
- autoload :Layouts, "abstract_controller/layouts"
- autoload :LocalizedCache, "abstract_controller/localized_cache"
- autoload :Logger, "abstract_controller/logger"
- autoload :RenderingController, "abstract_controller/rendering_controller"
+ extend ActiveSupport::Autoload
+
+ autoload :Base
+ autoload :Callbacks
+ autoload :Helpers
+ autoload :Layouts
+ autoload :LocalizedCache
+ autoload :Logger
+ autoload :RenderingController
+
# === Exceptions
- autoload :ActionNotFound, "abstract_controller/exceptions"
- autoload :DoubleRenderError, "abstract_controller/exceptions"
- autoload :Error, "abstract_controller/exceptions"
+ autoload_at "abstract_controller/exceptions" do
+ autoload :ActionNotFound
+ autoload :DoubleRenderError
+ autoload :Error
+ end
end
diff --git a/actionpack/lib/abstract_controller/rendering_controller.rb b/actionpack/lib/abstract_controller/rendering_controller.rb
index 7054b9cf26..777e515d60 100644
--- a/actionpack/lib/abstract_controller/rendering_controller.rb
+++ b/actionpack/lib/abstract_controller/rendering_controller.rb
@@ -115,7 +115,7 @@ module AbstractController
# _partial<TrueClass, FalseClass>:: Whether or not the file to look up is a partial
def _determine_template(options)
if options.key?(:text)
- options[:_template] = ActionView::TextTemplate.new(options[:text], format_for_text)
+ options[:_template] = ActionView::Template::Text.new(options[:text], format_for_text)
elsif options.key?(:inline)
handler = ActionView::Template.handler_class_for_extension(options[:type] || "erb")
template = ActionView::Template.new(options[:inline], "inline #{options[:inline].inspect}", handler, {})
diff --git a/actionpack/lib/action_controller.rb b/actionpack/lib/action_controller.rb
index 03a40e4fce..f830223058 100644
--- a/actionpack/lib/action_controller.rb
+++ b/actionpack/lib/action_controller.rb
@@ -1,66 +1,72 @@
+require "active_support"
+
module ActionController
- autoload :Base, "action_controller/base"
- autoload :Benchmarking, "action_controller/metal/benchmarking"
- autoload :ConditionalGet, "action_controller/metal/conditional_get"
- autoload :Configuration, "action_controller/metal/configuration"
- autoload :Head, "action_controller/metal/head"
- autoload :Helpers, "action_controller/metal/helpers"
- autoload :HideActions, "action_controller/metal/hide_actions"
- autoload :Layouts, "action_controller/metal/layouts"
- autoload :Metal, "action_controller/metal"
- autoload :Middleware, "action_controller/middleware"
- autoload :RackConvenience, "action_controller/metal/rack_convenience"
- autoload :Rails2Compatibility, "action_controller/metal/compatibility"
- autoload :Redirector, "action_controller/metal/redirector"
- autoload :RenderingController, "action_controller/metal/rendering_controller"
- autoload :RenderOptions, "action_controller/metal/render_options"
- autoload :Rescue, "action_controller/metal/rescuable"
- autoload :Responder, "action_controller/metal/responder"
- autoload :Session, "action_controller/metal/session"
- autoload :Testing, "action_controller/metal/testing"
- autoload :UrlFor, "action_controller/metal/url_for"
+ extend ActiveSupport::Autoload
- autoload :Caching, 'action_controller/caching'
- autoload :Dispatcher, 'action_controller/dispatch/dispatcher'
- autoload :Integration, 'action_controller/deprecated/integration_test'
- autoload :IntegrationTest, 'action_controller/deprecated/integration_test'
- autoload :MimeResponds, 'action_controller/metal/mime_responds'
- autoload :PerformanceTest, 'action_controller/deprecated/performance_test'
- autoload :PolymorphicRoutes, 'action_controller/polymorphic_routes'
- autoload :RecordIdentifier, 'action_controller/record_identifier'
- autoload :Routing, 'action_controller/deprecated'
- autoload :SessionManagement, 'action_controller/metal/session_management'
- autoload :TestCase, 'action_controller/testing/test_case'
- autoload :TestProcess, 'action_controller/testing/process'
- autoload :UrlRewriter, 'action_controller/url_rewriter'
- autoload :UrlWriter, 'action_controller/url_rewriter'
+ autoload :Base
+ autoload :Caching
+ autoload :PolymorphicRoutes
+ autoload :RecordIdentifier
+ autoload :UrlRewriter
+ autoload :Translation
+ autoload :Metal
+ autoload :Middleware
- autoload :Verification, 'action_controller/metal/verification'
- autoload :Flash, 'action_controller/metal/flash'
- autoload :RequestForgeryProtection, 'action_controller/metal/request_forgery_protection'
- autoload :Streaming, 'action_controller/metal/streaming'
- autoload :HttpAuthentication, 'action_controller/metal/http_authentication'
- autoload :FilterParameterLogging, 'action_controller/metal/filter_parameter_logging'
- autoload :Translation, 'action_controller/translation'
- autoload :Cookies, 'action_controller/metal/cookies'
+ autoload_under "metal" do
+ autoload :Benchmarking
+ autoload :ConditionalGet
+ autoload :Configuration
+ autoload :Head
+ autoload :Helpers
+ autoload :HideActions
+ autoload :Layouts
+ autoload :MimeResponds
+ autoload :RackConvenience
+ autoload :Compatibility
+ autoload :Redirector
+ autoload :RenderingController
+ autoload :RenderOptions
+ autoload :Rescue
+ autoload :Responder
+ autoload :Session
+ autoload :SessionManagement
+ autoload :UrlFor
+ autoload :Verification
+ autoload :Flash
+ autoload :RequestForgeryProtection
+ autoload :Streaming
+ autoload :HttpAuthentication
+ autoload :FilterParameterLogging
+ autoload :Cookies
+ end
- autoload :ActionControllerError, 'action_controller/metal/exceptions'
- autoload :RenderError, 'action_controller/metal/exceptions'
- autoload :RoutingError, 'action_controller/metal/exceptions'
- autoload :MethodNotAllowed, 'action_controller/metal/exceptions'
- autoload :NotImplemented, 'action_controller/metal/exceptions'
- autoload :UnknownController, 'action_controller/metal/exceptions'
- autoload :MissingFile, 'action_controller/metal/exceptions'
- autoload :RenderError, 'action_controller/metal/exceptions'
- autoload :SessionOverflowError, 'action_controller/metal/exceptions'
- autoload :UnknownHttpMethod, 'action_controller/metal/exceptions'
-end
+ autoload :Dispatcher, 'action_controller/dispatch/dispatcher'
+ autoload :PerformanceTest, 'action_controller/deprecated/performance_test'
+ autoload :Routing, 'action_controller/deprecated'
+ autoload :Integration, 'action_controller/deprecated/integration_test'
+ autoload :IntegrationTest, 'action_controller/deprecated/integration_test'
-autoload :HTML, 'action_controller/vendor/html-scanner'
-autoload :AbstractController, 'abstract_controller'
+ autoload :UrlWriter, 'action_controller/url_rewriter'
+
+ autoload_at "action_controller/metal/exceptions" do
+ autoload :ActionControllerError
+ autoload :RenderError
+ autoload :RoutingError
+ autoload :MethodNotAllowed
+ autoload :NotImplemented
+ autoload :UnknownController
+ autoload :MissingFile
+ autoload :RenderError
+ autoload :SessionOverflowError
+ autoload :UnknownHttpMethod
+ end
+end
+# All of these simply register additional autoloads
+require 'abstract_controller'
require 'action_dispatch'
require 'action_view'
+require 'action_controller/vendor/html-scanner'
# Common ActiveSupport usage in ActionController
require "active_support/concern"
diff --git a/actionpack/lib/action_controller/base.rb b/actionpack/lib/action_controller/base.rb
index 4c026fe5f7..48bfbab215 100644
--- a/actionpack/lib/action_controller/base.rb
+++ b/actionpack/lib/action_controller/base.rb
@@ -19,12 +19,11 @@ module ActionController
# Legacy modules
include SessionManagement
- include ActionDispatch::StatusCodes
include ActionController::Caching
include ActionController::MimeResponds
# Rails 2.x compatibility
- include ActionController::Rails2Compatibility
+ include ActionController::Compatibility
include ActionController::Cookies
include ActionController::Session
@@ -91,7 +90,7 @@ module ActionController
end
if options[:status]
- options[:status] = interpret_status(options[:status]).to_i
+ options[:status] = _interpret_status(options[:status])
end
options[:update] = blk if block_given?
@@ -140,9 +139,9 @@ module ActionController
raise ActionControllerError.new("Cannot redirect to nil!") if options.nil?
status = if options.is_a?(Hash) && options.key?(:status)
- interpret_status(options.delete(:status))
+ _interpret_status(options.delete(:status))
elsif response_status.key?(:status)
- interpret_status(response_status[:status])
+ _interpret_status(response_status[:status])
else
302
end
@@ -164,5 +163,14 @@ module ActionController
super(url, status)
end
+
+ private
+ def _interpret_status(status)
+ if status.is_a?(Symbol)
+ (ActionDispatch::StatusCodes::SYMBOL_TO_STATUS_CODE[status] || 500)
+ else
+ status.to_i
+ end
+ end
end
end
diff --git a/actionpack/lib/action_controller/caching.rb b/actionpack/lib/action_controller/caching.rb
index 3caf759032..ad357cceda 100644
--- a/actionpack/lib/action_controller/caching.rb
+++ b/actionpack/lib/action_controller/caching.rb
@@ -30,10 +30,11 @@ module ActionController #:nodoc:
# config.action_controller.cache_store = MyOwnStore.new("parameter")
module Caching
extend ActiveSupport::Concern
+ extend ActiveSupport::Autoload
- autoload :Actions, 'action_controller/caching/actions'
- autoload :Fragments, 'action_controller/caching/fragments'
- autoload :Pages, 'action_controller/caching/pages'
+ autoload :Actions
+ autoload :Fragments
+ autoload :Pages
autoload :Sweeper, 'action_controller/caching/sweeping'
autoload :Sweeping, 'action_controller/caching/sweeping'
diff --git a/actionpack/lib/action_controller/deprecated/integration_test.rb b/actionpack/lib/action_controller/deprecated/integration_test.rb
index 86336b6bc4..05c8c0f156 100644
--- a/actionpack/lib/action_controller/deprecated/integration_test.rb
+++ b/actionpack/lib/action_controller/deprecated/integration_test.rb
@@ -1,2 +1,4 @@
+require "action_dispatch/testing/integration"
+
ActionController::Integration = ActionDispatch::Integration
ActionController::IntegrationTest = ActionDispatch::IntegrationTest
diff --git a/actionpack/lib/action_controller/metal/compatibility.rb b/actionpack/lib/action_controller/metal/compatibility.rb
index 0c264fcd09..a90f798cd5 100644
--- a/actionpack/lib/action_controller/metal/compatibility.rb
+++ b/actionpack/lib/action_controller/metal/compatibility.rb
@@ -1,5 +1,5 @@
module ActionController
- module Rails2Compatibility
+ module Compatibility
extend ActiveSupport::Concern
class ::ActionController::ActionControllerError < StandardError #:nodoc:
diff --git a/actionpack/lib/action_controller/metal/exceptions.rb b/actionpack/lib/action_controller/metal/exceptions.rb
index b9d23da3e0..07024d0a9a 100644
--- a/actionpack/lib/action_controller/metal/exceptions.rb
+++ b/actionpack/lib/action_controller/metal/exceptions.rb
@@ -18,18 +18,9 @@ module ActionController
def initialize(*allowed_methods)
super("Only #{allowed_methods.to_sentence(:locale => :en)} requests are allowed.")
- @allowed_methods = allowed_methods
- end
-
- def allowed_methods_header
- allowed_methods.map { |method_symbol| method_symbol.to_s.upcase } * ', '
- end
-
- def handle_response!(response)
- response.headers['Allow'] ||= allowed_methods_header
end
end
-
+
class NotImplemented < MethodNotAllowed #:nodoc:
end
diff --git a/actionpack/lib/action_controller/metal/flash.rb b/actionpack/lib/action_controller/metal/flash.rb
index f43900faa0..b2d44c6c63 100644
--- a/actionpack/lib/action_controller/metal/flash.rb
+++ b/actionpack/lib/action_controller/metal/flash.rb
@@ -133,8 +133,20 @@ module ActionController #:nodoc:
Array(key || keys).each { |k| used ? @used << k : @used.delete(k) }
return key ? self[key] : self
end
+ end
+
+ # Access the contents of the flash. Use <tt>flash["notice"]</tt> to
+ # read a notice you put there or <tt>flash["notice"] = "hello"</tt>
+ # to put a new one.
+ def flash #:doc:
+ unless @_flash
+ @_flash = session["flash"] || FlashHash.new
+ @_flash.sweep
end
+ @_flash
+ end
+
protected
def process_action(method_name)
super
@@ -146,17 +158,5 @@ module ActionController #:nodoc:
super
@_flash = nil
end
-
- # Access the contents of the flash. Use <tt>flash["notice"]</tt> to
- # read a notice you put there or <tt>flash["notice"] = "hello"</tt>
- # to put a new one.
- def flash #:doc:
- unless @_flash
- @_flash = session["flash"] || FlashHash.new
- @_flash.sweep
- end
-
- @_flash
- end
end
end
diff --git a/actionpack/lib/action_controller/metal/helpers.rb b/actionpack/lib/action_controller/metal/helpers.rb
index b4325e24ad..d0402e5bad 100644
--- a/actionpack/lib/action_controller/metal/helpers.rb
+++ b/actionpack/lib/action_controller/metal/helpers.rb
@@ -52,7 +52,7 @@ module ActionController
included do
# Set the default directory for helpers
extlib_inheritable_accessor(:helpers_dir) do
- defined?(Rails) ? "#{Rails.root}/app/helpers" : "app/helpers"
+ defined?(Rails.root) ? "#{Rails.root}/app/helpers" : "app/helpers"
end
end
diff --git a/actionpack/lib/action_controller/metal/render_options.rb b/actionpack/lib/action_controller/metal/render_options.rb
index 0d69ca10df..b6a7ca0eda 100644
--- a/actionpack/lib/action_controller/metal/render_options.rb
+++ b/actionpack/lib/action_controller/metal/render_options.rb
@@ -1,19 +1,24 @@
module ActionController
+
+ def self.add_renderer(key, &block)
+ RenderOptions.add(key, &block)
+ end
+
module RenderOptions
extend ActiveSupport::Concern
included do
extlib_inheritable_accessor :_renderers
- self._renderers = []
+ self._renderers = {}
end
module ClassMethods
def _write_render_options
- renderers = _renderers.map do |r|
+ renderers = _renderers.map do |name, value|
<<-RUBY_EVAL
- if options.key?(:#{r})
+ if options.key?(:#{name})
_process_options(options)
- return render_#{r}(options[:#{r}], options)
+ return _render_option_#{name}(options[:#{name}], options)
end
RUBY_EVAL
end
@@ -25,79 +30,63 @@ module ActionController
RUBY_EVAL
end
- def _add_render_option(name)
- _renderers << name
+ def use_renderers(*args)
+ args.each do |key|
+ _renderers[key] = RENDERERS[key]
+ end
_write_render_options
end
+ alias use_renderer use_renderers
end
def render_to_body(options)
_handle_render_options(options) || super
end
- end
-
- module RenderOption #:nodoc:
- def self.extended(base)
- base.extend ActiveSupport::Concern
- base.send :include, ::ActionController::RenderOptions
- def base.register_renderer(name)
- included { _add_render_option(name) }
- end
+ RENDERERS = {}
+ def self.add(key, &block)
+ define_method("_render_option_#{key}", &block)
+ RENDERERS[key] = block
+ All._write_render_options
end
- end
- module RenderOptions
- module Json
- extend RenderOption
- register_renderer :json
+ module All
+ extend ActiveSupport::Concern
+ include RenderOptions
- def render_json(json, options)
- json = ActiveSupport::JSON.encode(json) unless json.respond_to?(:to_str)
- json = "#{options[:callback]}(#{json})" unless options[:callback].blank?
- self.content_type ||= Mime::JSON
- self.response_body = json
+ INCLUDED = []
+ included do
+ self._renderers = RENDERERS
+ _write_render_options
+ INCLUDED << self
end
- end
-
- module Js
- extend RenderOption
- register_renderer :js
- def render_js(js, options)
- self.content_type ||= Mime::JS
- self.response_body = js.respond_to?(:to_js) ? js.to_js : js
+ def self._write_render_options
+ INCLUDED.each(&:_write_render_options)
end
end
- module Xml
- extend RenderOption
- register_renderer :xml
-
- def render_xml(xml, options)
- self.content_type ||= Mime::XML
- self.response_body = xml.respond_to?(:to_xml) ? xml.to_xml : xml
- end
+ add :json do |json, options|
+ json = ActiveSupport::JSON.encode(json) unless json.respond_to?(:to_str)
+ json = "#{options[:callback]}(#{json})" unless options[:callback].blank?
+ self.content_type ||= Mime::JSON
+ self.response_body = json
end
- module RJS
- extend RenderOption
- register_renderer :update
-
- def render_update(proc, options)
- generator = ActionView::Helpers::PrototypeHelper::JavaScriptGenerator.new(view_context, &proc)
- self.content_type = Mime::JS
- self.response_body = generator.to_s
- end
+ add :js do |js, options|
+ self.content_type ||= Mime::JS
+ self.response_body = js.respond_to?(:to_js) ? js.to_js : js
end
- module All
- extend ActiveSupport::Concern
+ add :xml do |xml, options|
+ self.content_type ||= Mime::XML
+ self.response_body = xml.respond_to?(:to_xml) ? xml.to_xml : xml
+ end
- include ActionController::RenderOptions::Json
- include ActionController::RenderOptions::Js
- include ActionController::RenderOptions::Xml
- include ActionController::RenderOptions::RJS
+ add :update do |proc, options|
+ generator = ActionView::Helpers::PrototypeHelper::JavaScriptGenerator.new(view_context, &proc)
+ self.content_type = Mime::JS
+ self.response_body = generator.to_s
end
end
end
diff --git a/actionpack/lib/action_controller/metal/rescuable.rb b/actionpack/lib/action_controller/metal/rescue.rb
index bbca1b2179..bbca1b2179 100644
--- a/actionpack/lib/action_controller/metal/rescuable.rb
+++ b/actionpack/lib/action_controller/metal/rescue.rb
diff --git a/actionpack/lib/action_controller/metal/responder.rb b/actionpack/lib/action_controller/metal/responder.rb
index 6c76c57839..cb0e600871 100644
--- a/actionpack/lib/action_controller/metal/responder.rb
+++ b/actionpack/lib/action_controller/metal/responder.rb
@@ -80,6 +80,11 @@ module ActionController #:nodoc:
class Responder
attr_reader :controller, :request, :format, :resource, :resources, :options
+ ACTIONS_FOR_VERBS = {
+ :post => :new,
+ :put => :edit
+ }
+
def initialize(controller, resources, options={})
@controller = controller
@request = controller.request
@@ -138,7 +143,7 @@ module ActionController #:nodoc:
def navigation_behavior(error)
if get?
raise error
- elsif has_errors?
+ elsif has_errors? && default_action
render :action => default_action
else
redirect_to resource_location
@@ -209,7 +214,7 @@ module ActionController #:nodoc:
# the verb is post.
#
def default_action
- @action || (request.post? ? :new : :edit)
+ @action ||= ACTIONS_FOR_VERBS[request.method]
end
end
end
diff --git a/actionpack/lib/action_controller/testing/test_case.rb b/actionpack/lib/action_controller/test_case.rb
index 01a55fe930..7533a22299 100644
--- a/actionpack/lib/action_controller/testing/test_case.rb
+++ b/actionpack/lib/action_controller/test_case.rb
@@ -1,5 +1,8 @@
require 'active_support/test_case'
require 'rack/session/abstract/id'
+require 'action_controller/metal/testing'
+require 'action_controller/testing/process'
+require 'action_dispatch/test_case'
module ActionController
class TestRequest < ActionDispatch::TestRequest #:nodoc:
diff --git a/actionpack/lib/action_controller/vendor/html-scanner.rb b/actionpack/lib/action_controller/vendor/html-scanner.rb
index f622d195ee..2cb20ddd05 100644
--- a/actionpack/lib/action_controller/vendor/html-scanner.rb
+++ b/actionpack/lib/action_controller/vendor/html-scanner.rb
@@ -1,6 +1,8 @@
$LOAD_PATH << "#{File.dirname(__FILE__)}/html-scanner"
module HTML
+ extend ActiveSupport::Autoload
+
autoload :CDATA, 'html/node'
autoload :Document, 'html/document'
autoload :FullSanitizer, 'html/sanitizer'
diff --git a/actionpack/lib/action_dispatch.rb b/actionpack/lib/action_dispatch.rb
index 259814a322..e21dbc59cc 100644
--- a/actionpack/lib/action_dispatch.rb
+++ b/actionpack/lib/action_dispatch.rb
@@ -28,37 +28,38 @@ module Rack
end
module ActionDispatch
- autoload :Request, 'action_dispatch/http/request'
- autoload :Response, 'action_dispatch/http/response'
- autoload :StatusCodes, 'action_dispatch/http/status_codes'
- autoload :Utils, 'action_dispatch/http/utils'
+ extend ActiveSupport::Autoload
- autoload :Callbacks, 'action_dispatch/middleware/callbacks'
- autoload :MiddlewareStack, 'action_dispatch/middleware/stack'
- autoload :ParamsParser, 'action_dispatch/middleware/params_parser'
- autoload :Rescue, 'action_dispatch/middleware/rescue'
- autoload :ShowExceptions, 'action_dispatch/middleware/show_exceptions'
- autoload :Static, 'action_dispatch/middleware/static'
- autoload :StringCoercion, 'action_dispatch/middleware/string_coercion'
+ autoload_under "http" do
+ autoload :Request
+ autoload :Response
+ autoload :StatusCodes
+ autoload :Utils
+ end
- autoload :Routing, 'action_dispatch/routing'
+ autoload_under "middleware" do
+ autoload :Callbacks
+ autoload :ParamsParser
+ autoload :Rescue
+ autoload :ShowExceptions
+ autoload :Static
+ autoload :StringCoercion
+ end
- autoload :Assertions, 'action_dispatch/testing/assertions'
- autoload :Integration, 'action_dispatch/testing/integration'
- autoload :IntegrationTest, 'action_dispatch/testing/integration'
- autoload :PerformanceTest, 'action_dispatch/testing/performance_test'
- autoload :TestRequest, 'action_dispatch/testing/test_request'
- autoload :TestResponse, 'action_dispatch/testing/test_response'
+ autoload :MiddlewareStack, 'action_dispatch/middleware/stack'
+ autoload :Routing
autoload :HTML, 'action_controller/vendor/html-scanner'
module Http
- autoload :Headers, 'action_dispatch/http/headers'
+ extend ActiveSupport::Autoload
+
+ autoload :Headers
end
module Session
autoload :AbstractStore, 'action_dispatch/middleware/session/abstract_store'
- autoload :CookieStore, 'action_dispatch/middleware/session/cookie_store'
+ autoload :CookieStore, 'action_dispatch/middleware/session/cookie_store'
autoload :MemCacheStore, 'action_dispatch/middleware/session/mem_cache_store'
end
end
diff --git a/actionpack/lib/action_dispatch/http/status_codes.rb b/actionpack/lib/action_dispatch/http/status_codes.rb
index 5bac842ec1..ea1475e827 100644
--- a/actionpack/lib/action_dispatch/http/status_codes.rb
+++ b/actionpack/lib/action_dispatch/http/status_codes.rb
@@ -21,22 +21,5 @@ module ActionDispatch
hash[ActiveSupport::Inflector.underscore(message.gsub(/ /, "")).to_sym] = code
hash
}.freeze
-
- private
- # Given a status parameter, determine whether it needs to be converted
- # to a string. If it is a fixnum, use the STATUS_CODES hash to lookup
- # the default message. If it is a symbol, use the SYMBOL_TO_STATUS_CODE
- # hash to convert it.
- def interpret_status(status)
- case status
- when Fixnum then
- "#{status} #{STATUS_CODES[status]}".strip
- when Symbol then
- interpret_status(SYMBOL_TO_STATUS_CODE[status] ||
- "500 Unknown Status #{status.inspect}")
- else
- status.to_s
- end
- end
end
end
diff --git a/actionpack/lib/action_dispatch/middleware/show_exceptions.rb b/actionpack/lib/action_dispatch/middleware/show_exceptions.rb
index 036deec6d2..471d18491c 100644
--- a/actionpack/lib/action_dispatch/middleware/show_exceptions.rb
+++ b/actionpack/lib/action_dispatch/middleware/show_exceptions.rb
@@ -2,8 +2,6 @@ require "active_support/core_ext/exception"
module ActionDispatch
class ShowExceptions
- include StatusCodes
-
LOCALHOST = '127.0.0.1'.freeze
RESCUES_TEMPLATE_PATH = File.join(File.dirname(__FILE__), 'templates')
@@ -29,7 +27,7 @@ module ActionDispatch
'ActionView::MissingTemplate' => 'missing_template',
'ActionController::RoutingError' => 'routing_error',
ActionController::UnknownAction.name => 'unknown_action',
- 'ActionView::TemplateError' => 'template_error'
+ 'ActionView::Template::Error' => 'template_error'
})
FAILSAFE_RESPONSE = [500, {'Content-Type' => 'text/html'},
@@ -104,7 +102,7 @@ module ActionDispatch
end
def status_code(exception)
- interpret_status(@@rescue_responses[exception.class.name]).to_i
+ ActionDispatch::StatusCodes::SYMBOL_TO_STATUS_CODE[@@rescue_responses[exception.class.name]]
end
def render(status, body)
@@ -119,7 +117,7 @@ module ActionDispatch
return unless logger
ActiveSupport::Deprecation.silence do
- if ActionView::TemplateError === exception
+ if ActionView::Template::Error === exception
logger.fatal(exception.to_s)
else
logger.fatal(
diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb
index 400039353c..d480af876d 100644
--- a/actionpack/lib/action_dispatch/routing/mapper.rb
+++ b/actionpack/lib/action_dispatch/routing/mapper.rb
@@ -1,221 +1,193 @@
module ActionDispatch
module Routing
class Mapper
- module Resources
- class Resource #:nodoc:
- attr_reader :plural, :singular
- attr_reader :path_prefix, :name_prefix
-
- def initialize(entities, options = {})
- entities = entities.to_s
-
- @plural = entities.pluralize
- @singular = entities.singularize
-
- @path_prefix = options[:path_prefix]
- @name_prefix = options[:name_prefix]
- end
-
- def name
- plural
- end
-
- def controller
- plural
+ class Constraints
+ def self.new(app, constraints = [])
+ if constraints.any?
+ super(app, constraints)
+ else
+ app
end
+ end
- def member_name
- if name_prefix
- "#{name_prefix}_#{singular}"
- else
- singular
- end
- end
+ def initialize(app, constraints = [])
+ @app, @constraints = app, constraints
+ end
- def collection_name
- if name_prefix
- "#{name_prefix}_#{plural}"
- else
- plural
- end
- end
+ def call(env)
+ req = Rack::Request.new(env)
- def new_name
- if name_prefix
- "new_#{name_prefix}_#{singular}"
- else
- "new_#{singular}"
+ @constraints.each { |constraint|
+ if constraint.respond_to?(:matches?) && !constraint.matches?(req)
+ return [417, {}, []]
+ elsif constraint.respond_to?(:call) && !constraint.call(req)
+ return [417, {}, []]
end
- end
+ }
- def edit_name
- if name_prefix
- "edit_#{name_prefix}_#{singular}"
- else
- "edit_#{singular}"
- end
- end
+ @app.call(env)
end
+ end
- class SingletonResource < Resource #:nodoc:
- def initialize(entity, options = {})
- super(entity)
- end
+ module Base
+ def initialize(set)
+ @set = set
+ end
- def name
- singular
- end
+ def root(options = {})
+ match '/', options.merge(:as => :root)
end
- def resource(*resources, &block)
- options = resources.extract_options!
+ def match(*args)
+ options = args.extract_options!
- if resources.length > 1
- raise ArgumentError if block_given?
- resources.each { |r| resource(r, options) }
- return self
- end
+ path = args.first
- name_prefix = @scope[:options][:name_prefix] if @scope[:options]
- resource = SingletonResource.new(resources.pop, :name_prefix => name_prefix)
+ conditions, defaults = {}, {}
- if @scope[:scope_level] == :resources
- parent_resource = @scope[:scope_level_options][:name]
- parent_named_prefix = @scope[:scope_level_options][:name_prefix]
- with_scope_level(:member) do
- scope(":#{parent_resource}_id", :name_prefix => parent_named_prefix) do
- resource(resource.name, options, &block)
- end
- end
- return self
- end
+ path = nil if path == ""
+ path = "#{@scope[:path]}#{path}" if @scope[:path]
+ path = Rack::Mount::Utils.normalize_path(path) if path
- controller(resource.controller) do
- namespace(resource.name) do
- with_scope_level(:resource, :name => resource.singular, :name_prefix => resource.member_name) do
- yield if block_given?
+ raise ArgumentError, "path is required" unless path
- get "", :to => :show, :as => resource.member_name
- post "", :to => :create
- put "", :to => :update
- delete "", :to => :destroy
- get "new", :to => :new, :as => resource.new_name
- get "edit", :to => :edit, :as => resource.edit_name
- end
- end
+ constraints = options[:constraints] || {}
+ unless constraints.is_a?(Hash)
+ block, constraints = constraints, {}
end
+ blocks = ((@scope[:blocks] || []) + [block]).compact
+ constraints = (@scope[:constraints] || {}).merge(constraints)
+ options.each { |k, v| constraints[k] = v if v.is_a?(Regexp) }
- self
- end
+ conditions[:path_info] = path
+ requirements = constraints.dup
- def resources(*resources, &block)
- options = resources.extract_options!
-
- if resources.length > 1
- raise ArgumentError if block_given?
- resources.each { |r| resources(r, options) }
- return self
- end
+ path_regexp = Rack::Mount::Strexp.compile(path, constraints, SEPARATORS)
+ segment_keys = Rack::Mount::RegexpWithNamedGroups.new(path_regexp).names
+ constraints.reject! { |k, v| segment_keys.include?(k.to_s) }
+ conditions.merge!(constraints)
- name_prefix = @scope[:options][:name_prefix] if @scope[:options]
- resource = Resource.new(resources.pop, :name_prefix => name_prefix)
+ requirements[:controller] ||= @set.controller_constraints
- if @scope[:scope_level] == :resources
- parent_resource = @scope[:scope_level_options][:name]
- parent_named_prefix = @scope[:scope_level_options][:name_prefix]
- with_scope_level(:member) do
- scope(":#{parent_resource}_id", :name_prefix => parent_named_prefix) do
- resources(resource.name, options, &block)
- end
- end
- return self
+ if via = options[:via]
+ via = Array(via).map { |m| m.to_s.upcase }
+ conditions[:request_method] = Regexp.union(*via)
end
- controller(resource.controller) do
- namespace(resource.name) do
- with_scope_level(:resources, :name => resource.singular, :name_prefix => resource.member_name) do
- yield if block_given?
+ defaults[:controller] ||= @scope[:controller].to_s if @scope[:controller]
- collection do
- get "", :to => :index, :as => resource.collection_name
- post "", :to => :create
- get "new", :to => :new, :as => resource.new_name
- end
+ app = initialize_app_endpoint(options, defaults)
+ validate_defaults!(app, defaults, segment_keys)
+ app = Constraints.new(app, blocks)
- member do
- get "", :to => :show, :as => resource.member_name
- put "", :to => :update
- delete "", :to => :destroy
- get "edit", :to => :edit, :as => resource.edit_name
- end
- end
- end
- end
+ @set.add_route(app, conditions, requirements, defaults, options[:as])
self
end
- def collection
- unless @scope[:scope_level] == :resources
- raise ArgumentError, "can't use collection outside resources scope"
- end
+ private
+ def initialize_app_endpoint(options, defaults)
+ app = nil
+
+ if options[:to].respond_to?(:call)
+ app = options[:to]
+ defaults.delete(:controller)
+ defaults.delete(:action)
+ elsif options[:to].is_a?(String)
+ defaults[:controller], defaults[:action] = options[:to].split('#')
+ elsif options[:to].is_a?(Symbol)
+ defaults[:action] = options[:to].to_s
+ end
- with_scope_level(:collection) do
- yield
+ app || Routing::RouteSet::Dispatcher.new(:defaults => defaults)
end
- end
- def member
- unless @scope[:scope_level] == :resources
- raise ArgumentError, "can't use member outside resources scope"
- end
+ def validate_defaults!(app, defaults, segment_keys)
+ return unless app.is_a?(Routing::RouteSet::Dispatcher)
- with_scope_level(:member) do
- scope(":id") do
- yield
+ unless defaults.include?(:controller) || segment_keys.include?("controller")
+ raise ArgumentError, "missing :controller"
+ end
+
+ unless defaults.include?(:action) || segment_keys.include?("action")
+ raise ArgumentError, "missing :action"
end
end
+ end
+
+ module HttpHelpers
+ def get(*args, &block)
+ map_method(:get, *args, &block)
end
- def match(*args)
- options = args.extract_options!
- args.push(options)
+ def post(*args, &block)
+ map_method(:post, *args, &block)
+ end
- case options.delete(:on)
- when :collection
- return collection { match(*args) }
- when :member
- return member { match(*args) }
- end
+ def put(*args, &block)
+ map_method(:put, *args, &block)
+ end
- if @scope[:scope_level] == :resources
- raise ArgumentError, "can't define route directly in resources scope"
- end
+ def delete(*args, &block)
+ map_method(:delete, *args, &block)
+ end
- super
+ def redirect(path, options = {})
+ status = options[:status] || 301
+ lambda { |env|
+ req = Rack::Request.new(env)
+ url = req.scheme + '://' + req.host + path
+ [status, {'Location' => url, 'Content-Type' => 'text/html'}, ['Moved Permanently']]
+ }
end
private
- def with_scope_level(kind, options = {})
- old, @scope[:scope_level] = @scope[:scope_level], kind
- old_options, @scope[:scope_level_options] = @scope[:scope_level_options], options
- yield
- ensure
- @scope[:scope_level] = old
- @scope[:scope_level_options] = old_options
+ def map_method(method, *args, &block)
+ options = args.extract_options!
+ options[:via] = method
+ args.push(options)
+ match(*args, &block)
+ self
end
end
module Scoping
- def self.extended(object)
- object.instance_eval do
- @scope = {}
- end
+ def initialize(*args)
+ @scope = {}
+ super
end
def scope(*args)
options = args.extract_options!
+ case args.first
+ when String
+ options[:path] = args.first
+ when Symbol
+ options[:controller] = args.first
+ end
+
+ if path = options.delete(:path)
+ path_set = true
+ path, @scope[:path] = @scope[:path], Rack::Mount::Utils.normalize_path(@scope[:path].to_s + path.to_s)
+ else
+ path_set = false
+ end
+
+ if name_prefix = options.delete(:name_prefix)
+ name_prefix_set = true
+ name_prefix, @scope[:name_prefix] = @scope[:name_prefix], (@scope[:name_prefix] ? "#{@scope[:name_prefix]}_#{name_prefix}" : name_prefix)
+ else
+ name_prefix_set = false
+ end
+
+ if controller = options.delete(:controller)
+ controller_set = true
+ controller, @scope[:controller] = @scope[:controller], controller
+ else
+ controller_set = false
+ end
+
constraints = options.delete(:constraints) || {}
unless constraints.is_a?(Hash)
block, constraints = constraints, {}
@@ -225,24 +197,12 @@ module ActionDispatch
options, @scope[:options] = @scope[:options], (@scope[:options] || {}).merge(options)
- path_set = controller_set = false
-
- case args.first
- when String
- path_set = true
- path = args.first
- path, @scope[:path] = @scope[:path], "#{@scope[:path]}#{Rack::Mount::Utils.normalize_path(path)}"
- when Symbol
- controller_set = true
- controller = args.first
- controller, @scope[:controller] = @scope[:controller], controller
- end
-
yield
self
ensure
@scope[:path] = path if path_set
+ @scope[:name_prefix] = name_prefix if name_prefix_set
@scope[:controller] = controller if controller_set
@scope[:options] = options
@scope[:blocks] = blocks
@@ -254,7 +214,7 @@ module ActionDispatch
end
def namespace(path)
- scope(path.to_s) { yield }
+ scope("/#{path}") { yield }
end
def constraints(constraints = {})
@@ -263,172 +223,244 @@ module ActionDispatch
def match(*args)
options = args.extract_options!
+
options = (@scope[:options] || {}).merge(options)
+
+ if @scope[:name_prefix] && !options[:as].blank?
+ options[:as] = "#{@scope[:name_prefix]}_#{options[:as]}"
+ elsif @scope[:name_prefix] && options[:as] == ""
+ options[:as] = @scope[:name_prefix].to_s
+ end
+
args.push(options)
super(*args)
end
end
- module HttpHelpers
- def get(*args, &block)
- map_method(:get, *args, &block)
- end
+ module Resources
+ class Resource #:nodoc:
+ attr_reader :plural, :singular
- def post(*args, &block)
- map_method(:post, *args, &block)
- end
+ def initialize(entities, options = {})
+ entities = entities.to_s
- def put(*args, &block)
- map_method(:put, *args, &block)
- end
+ @plural = entities.pluralize
+ @singular = entities.singularize
+ end
- def delete(*args, &block)
- map_method(:delete, *args, &block)
- end
+ def name
+ plural
+ end
- def redirect(path, options = {})
- status = options[:status] || 301
- lambda { |env|
- req = Rack::Request.new(env)
- url = req.scheme + '://' + req.host + path
- [status, {'Location' => url, 'Content-Type' => 'text/html'}, ['Moved Permanently']]
- }
- end
+ def controller
+ plural
+ end
- private
- def map_method(method, *args, &block)
- options = args.extract_options!
- options[:via] = method
- args.push(options)
- match(*args, &block)
- self
+ def member_name
+ singular
end
- end
- class Constraints
- def new(app, constraints = [])
- if constraints.any?
- super(app, constraints)
- else
- app
+ def collection_name
+ plural
+ end
+
+ def id_segment
+ ":#{singular}_id"
end
end
- def initialize(app, constraints = [])
- @app, @constraints = app, constraints
+ class SingletonResource < Resource #:nodoc:
+ def initialize(entity, options = {})
+ super
+ end
+
+ def name
+ singular
+ end
end
- def call(env)
- req = Rack::Request.new(env)
+ def resource(*resources, &block)
+ options = resources.extract_options!
- @constraints.each { |constraint|
- if constraint.respond_to?(:matches?) && !constraint.matches?(req)
- return [417, {}, []]
- elsif constraint.respond_to?(:call) && !constraint.call(req)
- return [417, {}, []]
+ if resources.length > 1
+ raise ArgumentError if block_given?
+ resources.each { |r| resource(r, options) }
+ return self
+ end
+
+ resource = SingletonResource.new(resources.pop)
+
+ if @scope[:scope_level] == :resources
+ nested do
+ resource(resource.name, options, &block)
end
- }
+ return self
+ end
- @app.call(env)
- end
- end
+ scope(:path => "/#{resource.name}", :controller => resource.controller) do
+ with_scope_level(:resource, resource) do
+ yield if block_given?
- def initialize(set)
- @set = set
+ get "(.:format)", :to => :show, :as => resource.member_name
+ post "(.:format)", :to => :create
+ put "(.:format)", :to => :update
+ delete "(.:format)", :to => :destroy
+ get "/new(.:format)", :to => :new, :as => "new_#{resource.singular}"
+ get "/edit(.:format)", :to => :edit, :as => "edit_#{resource.singular}"
+ end
+ end
- extend HttpHelpers
- extend Scoping
- extend Resources
- end
+ self
+ end
- def root(options = {})
- match '/', options.merge(:as => :root)
- end
+ def resources(*resources, &block)
+ options = resources.extract_options!
- def match(*args)
- options = args.extract_options!
+ if resources.length > 1
+ raise ArgumentError if block_given?
+ resources.each { |r| resources(r, options) }
+ return self
+ end
- if args.length > 1
- args.each { |path| match(path, options) }
- return self
- end
+ resource = Resource.new(resources.pop)
- if args.first.is_a?(Symbol)
- return match(args.first.to_s, options.merge(:to => args.first.to_sym))
- end
+ if @scope[:scope_level] == :resources
+ nested do
+ resources(resource.name, options, &block)
+ end
+ return self
+ end
- path = args.first
+ scope(:path => "/#{resource.name}", :controller => resource.controller) do
+ with_scope_level(:resources, resource) do
+ yield if block_given?
- conditions, defaults = {}, {}
+ with_scope_level(:collection) do
+ get "(.:format)", :to => :index, :as => resource.collection_name
+ post "(.:format)", :to => :create
+ with_exclusive_name_prefix :new do
+ get "/new(.:format)", :to => :new, :as => resource.singular
+ end
+ end
+
+ with_scope_level(:member) do
+ scope("/:id") do
+ get "(.:format)", :to => :show, :as => resource.member_name
+ put "(.:format)", :to => :update
+ delete "(.:format)", :to => :destroy
+ with_exclusive_name_prefix :edit do
+ get "/edit(.:format)", :to => :edit, :as => resource.singular
+ end
+ end
+ end
+ end
+ end
- path = nil if path == ""
- path = Rack::Mount::Utils.normalize_path(path) if path
- path = "#{@scope[:path]}#{path}" if @scope[:path]
+ self
+ end
- raise ArgumentError, "path is required" unless path
+ def collection
+ unless @scope[:scope_level] == :resources
+ raise ArgumentError, "can't use collection outside resources scope"
+ end
- constraints = options[:constraints] || {}
- unless constraints.is_a?(Hash)
- block, constraints = constraints, {}
+ with_scope_level(:collection) do
+ scope(:name_prefix => parent_resource.collection_name, :as => "") do
+ yield
+ end
+ end
end
- blocks = ((@scope[:blocks] || []) + [block]).compact
- constraints = (@scope[:constraints] || {}).merge(constraints)
- options.each { |k, v| constraints[k] = v if v.is_a?(Regexp) }
- conditions[:path_info] = path
- requirements = constraints.dup
+ def member
+ unless @scope[:scope_level] == :resources
+ raise ArgumentError, "can't use member outside resources scope"
+ end
- path_regexp = Rack::Mount::Strexp.compile(path, constraints, SEPARATORS)
- segment_keys = Rack::Mount::RegexpWithNamedGroups.new(path_regexp).names
- constraints.reject! { |k, v| segment_keys.include?(k.to_s) }
- conditions.merge!(constraints)
+ with_scope_level(:member) do
+ scope("/:id", :name_prefix => parent_resource.member_name, :as => "") do
+ yield
+ end
+ end
+ end
- requirements[:controller] ||= @set.controller_constraints
+ def nested
+ unless @scope[:scope_level] == :resources
+ raise ArgumentError, "can't use nested outside resources scope"
+ end
- if via = options[:via]
- via = Array(via).map { |m| m.to_s.upcase }
- conditions[:request_method] = Regexp.union(*via)
+ with_scope_level(:nested) do
+ scope("/#{parent_resource.id_segment}", :name_prefix => parent_resource.member_name) do
+ yield
+ end
+ end
end
- defaults[:controller] ||= @scope[:controller].to_s if @scope[:controller]
+ def match(*args)
+ options = args.extract_options!
- app = initialize_app_endpoint(options, defaults)
- validate_defaults!(app, defaults, segment_keys)
- app = Constraints.new(app, blocks)
+ if args.length > 1
+ args.each { |path| match(path, options) }
+ return self
+ end
- @set.add_route(app, conditions, requirements, defaults, options[:as])
+ if args.first.is_a?(Symbol)
+ with_exclusive_name_prefix(args.first) do
+ return match("/#{args.first}(.:format)", options.merge(:to => args.first.to_sym))
+ end
+ end
- self
- end
+ args.push(options)
- private
- def initialize_app_endpoint(options, defaults)
- app = nil
+ case options.delete(:on)
+ when :collection
+ return collection { match(*args) }
+ when :member
+ return member { match(*args) }
+ end
- if options[:to].respond_to?(:call)
- app = options[:to]
- defaults.delete(:controller)
- defaults.delete(:action)
- elsif options[:to].is_a?(String)
- defaults[:controller], defaults[:action] = options[:to].split('#')
- elsif options[:to].is_a?(Symbol)
- defaults[:action] = options[:to].to_s
+ if @scope[:scope_level] == :resources
+ raise ArgumentError, "can't define route directly in resources scope"
end
- app || Routing::RouteSet::Dispatcher.new(:defaults => defaults)
+ super
end
- def validate_defaults!(app, defaults, segment_keys)
- return unless app.is_a?(Routing::RouteSet::Dispatcher)
+ protected
+ def parent_resource
+ @scope[:scope_level_resource]
+ end
- unless defaults.include?(:controller) || segment_keys.include?("controller")
- raise ArgumentError, "missing :controller"
+ private
+ def with_exclusive_name_prefix(prefix)
+ begin
+ old_name_prefix = @scope[:name_prefix]
+
+ if !old_name_prefix.blank?
+ @scope[:name_prefix] = "#{prefix}_#{@scope[:name_prefix]}"
+ else
+ @scope[:name_prefix] = prefix.to_s
+ end
+
+ yield
+ ensure
+ @scope[:name_prefix] = old_name_prefix
+ end
end
- unless defaults.include?(:action) || segment_keys.include?("action")
- raise ArgumentError, "missing :action"
+ def with_scope_level(kind, resource = parent_resource)
+ old, @scope[:scope_level] = @scope[:scope_level], kind
+ old_resource, @scope[:scope_level_resource] = @scope[:scope_level_resource], resource
+ yield
+ ensure
+ @scope[:scope_level] = old
+ @scope[:scope_level_resource] = old_resource
end
- end
+ end
+
+ include Base
+ include HttpHelpers
+ include Scoping
+ include Resources
end
end
end
diff --git a/actionpack/lib/action_dispatch/routing/route_set.rb b/actionpack/lib/action_dispatch/routing/route_set.rb
index a8073c2105..8afd42a293 100644
--- a/actionpack/lib/action_dispatch/routing/route_set.rb
+++ b/actionpack/lib/action_dispatch/routing/route_set.rb
@@ -18,36 +18,37 @@ module ActionDispatch
def call(env)
params = env[PARAMETERS_KEY]
+ prepare_params!(params)
+
+ unless controller = controller(params)
+ return [417, {}, []]
+ end
+
+ controller.action(params[:action]).call(env)
+ end
+
+ def prepare_params!(params)
merge_default_action!(params)
split_glob_param!(params) if @glob_param
+
params.each do |key, value|
if value.is_a?(String)
value = value.dup.force_encoding(Encoding::BINARY) if value.respond_to?(:force_encoding)
params[key] = URI.unescape(value)
end
end
+ end
- unless controller = controller(params)
- return [417, {}, []]
- end
-
- if env['action_controller.recognize']
- [200, {}, params]
- else
- controller.action(params[:action]).call(env)
+ def controller(params)
+ if params && params.has_key?(:controller)
+ controller = "#{params[:controller].camelize}Controller"
+ ActiveSupport::Inflector.constantize(controller)
end
+ rescue NameError
+ nil
end
private
- def controller(params)
- if params && params.has_key?(:controller)
- controller = "#{params[:controller].camelize}Controller"
- ActiveSupport::Inflector.constantize(controller)
- end
- rescue NameError
- nil
- end
-
def merge_default_action!(params)
params[:action] ||= 'index'
end
@@ -216,7 +217,14 @@ module ActionDispatch
def draw(&block)
clear!
- Mapper.new(self).instance_exec(DeprecatedMapper.new(self), &block)
+
+ mapper = Mapper.new(self)
+ if block.arity == 1
+ mapper.instance_exec(DeprecatedMapper.new(self), &block)
+ else
+ mapper.instance_exec(&block)
+ end
+
@set.add_route(NotFound)
install_helpers
@set.freeze
@@ -426,7 +434,7 @@ module ActionDispatch
raise ActionController::RoutingError, "No route matches #{options.inspect}"
end
- uri, params = result
+ path, params = result
params.each do |k, v|
if v
params[k] = v
@@ -435,16 +443,10 @@ module ActionDispatch
end
end
- uri << "?#{params.to_query}" if uri && params.any?
- path = uri
-
if path && method == :generate_extras
- uri = URI(path)
- extras = uri.query ?
- Rack::Utils.parse_nested_query(uri.query).keys.map { |k| k.to_sym } :
- []
- [uri.path, extras]
+ [path, params.keys]
elsif path
+ path << "?#{params.to_query}" if params.any?
path
else
raise ActionController::RoutingError, "No route matches #{options.inspect}"
@@ -455,37 +457,11 @@ module ActionDispatch
def call(env)
@set.call(env)
- rescue ActionController::RoutingError => e
- raise e if env['action_controller.rescue_error'] == false
-
- method, path = env['REQUEST_METHOD'].downcase.to_sym, env['PATH_INFO']
-
- # Route was not recognized. Try to find out why (maybe wrong verb).
- allows = HTTP_METHODS.select { |verb|
- begin
- recognize_path(path, {:method => verb}, false)
- rescue ActionController::RoutingError
- nil
- end
- }
-
- if !HTTP_METHODS.include?(method)
- raise ActionController::NotImplemented.new(*allows)
- elsif !allows.empty?
- raise ActionController::MethodNotAllowed.new(*allows)
- else
- raise e
- end
- end
-
- def recognize(request)
- params = recognize_path(request.path, extract_request_environment(request))
- request.path_parameters = params.with_indifferent_access
- "#{params[:controller].to_s.camelize}Controller".constantize
end
- def recognize_path(path, environment = {}, rescue_error = true)
+ def recognize_path(path, environment = {})
method = (environment[:method] || "GET").to_s.upcase
+ path = Rack::Mount::Utils.normalize_path(path)
begin
env = Rack::MockRequest.env_for(path, {:method => method})
@@ -493,16 +469,16 @@ module ActionDispatch
raise ActionController::RoutingError, e.message
end
- env['action_controller.recognize'] = true
- env['action_controller.rescue_error'] = rescue_error
- status, headers, body = call(env)
- body
- end
+ req = Rack::Request.new(env)
+ @set.recognize(req) do |route, params|
+ dispatcher = route.app
+ if dispatcher.is_a?(Dispatcher) && dispatcher.controller(params)
+ dispatcher.prepare_params!(params)
+ return params
+ end
+ end
- # Subclasses and plugins may override this method to extract further attributes
- # from the request, for use by route conditions and such.
- def extract_request_environment(request)
- { :method => request.method }
+ raise ActionController::RoutingError, "No route matches #{path.inspect} with #{environment.inspect}"
end
end
end
diff --git a/actionpack/lib/action_dispatch/test_case.rb b/actionpack/lib/action_dispatch/test_case.rb
new file mode 100644
index 0000000000..afd708f06f
--- /dev/null
+++ b/actionpack/lib/action_dispatch/test_case.rb
@@ -0,0 +1,6 @@
+require "action_dispatch/testing/assertions"
+require "action_dispatch/testing/integration"
+require "action_dispatch/testing/performance_test"
+require "action_dispatch/testing/test_request"
+require "action_dispatch/testing/test_response"
+require "action_dispatch/testing/integration" \ No newline at end of file
diff --git a/actionpack/lib/action_dispatch/testing/assertions/routing.rb b/actionpack/lib/action_dispatch/testing/assertions/routing.rb
index e6d6b5a3ef..4bc5275e04 100644
--- a/actionpack/lib/action_dispatch/testing/assertions/routing.rb
+++ b/actionpack/lib/action_dispatch/testing/assertions/routing.rb
@@ -134,9 +134,11 @@ module ActionDispatch
# Assume given controller
request = ActionController::TestRequest.new
request.env["REQUEST_METHOD"] = request_method.to_s.upcase if request_method
- request.path = path
+ request.path = path
+
+ params = ActionController::Routing::Routes.recognize_path(path, { :method => request.method })
+ request.path_parameters = params.with_indifferent_access
- ActionController::Routing::Routes.recognize(request)
request
end
end
diff --git a/actionpack/lib/action_dispatch/testing/performance_test.rb b/actionpack/lib/action_dispatch/testing/performance_test.rb
index b1ed9d31f4..1b9a6c18b7 100644
--- a/actionpack/lib/action_dispatch/testing/performance_test.rb
+++ b/actionpack/lib/action_dispatch/testing/performance_test.rb
@@ -1,15 +1,17 @@
require 'active_support/testing/performance'
require 'active_support/testing/default'
-module ActionDispatch
- # An integration test that runs a code profiler on your test methods.
- # Profiling output for combinations of each test method, measurement, and
- # output format are written to your tmp/performance directory.
- #
- # By default, process_time is measured and both flat and graph_html output
- # formats are written, so you'll have two output files per test method.
- class PerformanceTest < ActionDispatch::IntegrationTest
- include ActiveSupport::Testing::Performance
- include ActiveSupport::Testing::Default
+if defined?(ActiveSupport::Testing::Performance)
+ module ActionDispatch
+ # An integration test that runs a code profiler on your test methods.
+ # Profiling output for combinations of each test method, measurement, and
+ # output format are written to your tmp/performance directory.
+ #
+ # By default, process_time is measured and both flat and graph_html output
+ # formats are written, so you'll have two output files per test method.
+ class PerformanceTest < ActionDispatch::IntegrationTest
+ include ActiveSupport::Testing::Performance
+ include ActiveSupport::Testing::Default
+ end
end
-end
+end \ No newline at end of file
diff --git a/actionpack/lib/action_view.rb b/actionpack/lib/action_view.rb
index f6f7ec0c8c..06238ca747 100644
--- a/actionpack/lib/action_view.rb
+++ b/actionpack/lib/action_view.rb
@@ -24,27 +24,29 @@
require File.join(File.dirname(__FILE__), "action_pack")
module ActionView
- def self.load_all!
- [Context, Base, TemplateError]
+ extend ActiveSupport::Autoload
+
+ autoload :Base
+ autoload :Context
+ autoload :Template
+ autoload :Helpers
+ autoload :SafeBuffer
+
+
+ autoload_under "render" do
+ autoload :Partials
+ autoload :Rendering
end
- autoload :Base, 'action_view/base'
- autoload :Context, 'action_view/context'
- autoload :Helpers, 'action_view/helpers'
autoload :MissingTemplate, 'action_view/base'
- autoload :Partials, 'action_view/render/partials'
autoload :Resolver, 'action_view/template/resolver'
autoload :PathResolver, 'action_view/template/resolver'
autoload :PathSet, 'action_view/paths'
- autoload :Rendering, 'action_view/render/rendering'
- autoload :Template, 'action_view/template/template'
- autoload :TemplateError, 'action_view/template/error'
- autoload :TemplateHandler, 'action_view/template/handler'
- autoload :TemplateHandlers, 'action_view/template/handlers'
- autoload :TextTemplate, 'action_view/template/text'
- autoload :Helpers, 'action_view/helpers'
autoload :FileSystemResolverWithFallback, 'action_view/template/resolver'
- autoload :SafeBuffer, 'action_view/safe_buffer'
+
+ autoload :TemplateError, 'action_view/template/error'
+ autoload :TemplateHandler, 'action_view/template'
+ autoload :TemplateHandlers, 'action_view/template'
end
require 'action_view/erb/util'
diff --git a/actionpack/lib/action_view/base.rb b/actionpack/lib/action_view/base.rb
index c33695770f..d69e5109fa 100644
--- a/actionpack/lib/action_view/base.rb
+++ b/actionpack/lib/action_view/base.rb
@@ -196,7 +196,7 @@ module ActionView #:nodoc:
end
class << self
- delegate :erb_trim_mode=, :to => 'ActionView::TemplateHandlers::ERB'
+ delegate :erb_trim_mode=, :to => 'ActionView::Template::Handlers::ERB'
delegate :logger, :to => 'ActionController::Base', :allow_nil => true
end
diff --git a/actionpack/lib/action_view/paths.rb b/actionpack/lib/action_view/paths.rb
index 23bde61f9c..0059b79e5f 100644
--- a/actionpack/lib/action_view/paths.rb
+++ b/actionpack/lib/action_view/paths.rb
@@ -4,7 +4,7 @@ module ActionView #:nodoc:
# TODO: Clean this up
if obj.is_a?(String)
if cache.nil?
- cache = !defined?(Rails) || Rails.application.config.cache_classes
+ cache = !defined?(Rails.application) || Rails.application.config.cache_classes
end
FileSystemResolverWithFallback.new(obj, :cache => cache)
else
diff --git a/actionpack/lib/action_view/template/template.rb b/actionpack/lib/action_view/template.rb
index d1970ca3c7..210ad508f5 100644
--- a/actionpack/lib/action_view/template/template.rb
+++ b/actionpack/lib/action_view/template.rb
@@ -6,7 +6,14 @@ require "action_view/template/resolver"
module ActionView
class Template
- extend TemplateHandlers
+ extend ActiveSupport::Autoload
+
+ autoload :Error
+ autoload :Handler
+ autoload :Handlers
+ autoload :Text
+
+ extend Template::Handlers
attr_reader :source, :identifier, :handler, :mime_type, :formats, :details
def initialize(source, identifier, handler, details)
@@ -32,11 +39,11 @@ module ActionView
view.send(method_name, locals, &block)
end
rescue Exception => e
- if e.is_a?(TemplateError)
+ if e.is_a?(Template::Error)
e.sub_template_of(self)
raise e
else
- raise TemplateError.new(self, view.assigns, e)
+ raise Template::Error.new(self, view.assigns, e)
end
end
@@ -103,7 +110,7 @@ module ActionView
logger.debug "Backtrace: #{e.backtrace.join("\n")}"
end
- raise ActionView::TemplateError.new(self, {}, e)
+ raise ActionView::Template::Error.new(self, {}, e)
end
end
diff --git a/actionpack/lib/action_view/template/error.rb b/actionpack/lib/action_view/template/error.rb
index aa21606f76..648f708d3d 100644
--- a/actionpack/lib/action_view/template/error.rb
+++ b/actionpack/lib/action_view/template/error.rb
@@ -1,101 +1,105 @@
require "active_support/core_ext/enumerable"
module ActionView
- # The TemplateError exception is raised when the compilation of the template fails. This exception then gathers a
- # bunch of intimate details and uses it to report a very precise exception message.
- class TemplateError < ActionViewError #:nodoc:
- SOURCE_CODE_RADIUS = 3
+ class Template
+ # The Template::Error exception is raised when the compilation of the template fails. This exception then gathers a
+ # bunch of intimate details and uses it to report a very precise exception message.
+ class Error < ActionViewError #:nodoc:
+ SOURCE_CODE_RADIUS = 3
- attr_reader :original_exception
+ attr_reader :original_exception
- def initialize(template, assigns, original_exception)
- @template, @assigns, @original_exception = template, assigns.dup, original_exception
- @backtrace = compute_backtrace
- end
+ def initialize(template, assigns, original_exception)
+ @template, @assigns, @original_exception = template, assigns.dup, original_exception
+ @backtrace = compute_backtrace
+ end
- def file_name
- @template.identifier
- end
+ def file_name
+ @template.identifier
+ end
- def message
- ActiveSupport::Deprecation.silence { original_exception.message }
- end
+ def message
+ ActiveSupport::Deprecation.silence { original_exception.message }
+ end
- def clean_backtrace
- if defined?(Rails) && Rails.respond_to?(:backtrace_cleaner)
- Rails.backtrace_cleaner.clean(original_exception.backtrace)
- else
- original_exception.backtrace
+ def clean_backtrace
+ if defined?(Rails) && Rails.respond_to?(:backtrace_cleaner)
+ Rails.backtrace_cleaner.clean(original_exception.backtrace)
+ else
+ original_exception.backtrace
+ end
end
- end
- def sub_template_message
- if @sub_templates
- "Trace of template inclusion: " +
- @sub_templates.collect { |template| template.inspect }.join(", ")
- else
- ""
+ def sub_template_message
+ if @sub_templates
+ "Trace of template inclusion: " +
+ @sub_templates.collect { |template| template.inspect }.join(", ")
+ else
+ ""
+ end
end
- end
- def source_extract(indentation = 0)
- return unless num = line_number
- num = num.to_i
+ def source_extract(indentation = 0)
+ return unless num = line_number
+ num = num.to_i
- source_code = @template.source.split("\n")
+ source_code = @template.source.split("\n")
- start_on_line = [ num - SOURCE_CODE_RADIUS - 1, 0 ].max
- end_on_line = [ num + SOURCE_CODE_RADIUS - 1, source_code.length].min
+ start_on_line = [ num - SOURCE_CODE_RADIUS - 1, 0 ].max
+ end_on_line = [ num + SOURCE_CODE_RADIUS - 1, source_code.length].min
- indent = ' ' * indentation
- line_counter = start_on_line
- return unless source_code = source_code[start_on_line..end_on_line]
+ indent = ' ' * indentation
+ line_counter = start_on_line
+ return unless source_code = source_code[start_on_line..end_on_line]
- source_code.sum do |line|
- line_counter += 1
- "#{indent}#{line_counter}: #{line}\n"
+ source_code.sum do |line|
+ line_counter += 1
+ "#{indent}#{line_counter}: #{line}\n"
+ end
end
- end
-
- def sub_template_of(template_path)
- @sub_templates ||= []
- @sub_templates << template_path
- end
-
- def line_number
- @line_number ||=
- if file_name
- regexp = /#{Regexp.escape File.basename(file_name)}:(\d+)/
- $1 if message =~ regexp or clean_backtrace.find { |line| line =~ regexp }
- end
- end
+ def sub_template_of(template_path)
+ @sub_templates ||= []
+ @sub_templates << template_path
+ end
- def to_s
- "\n#{self.class} (#{message}) #{source_location}:\n" +
- "#{source_extract}\n #{clean_backtrace.join("\n ")}\n\n"
- end
+ def line_number
+ @line_number ||=
+ if file_name
+ regexp = /#{Regexp.escape File.basename(file_name)}:(\d+)/
- # don't do anything nontrivial here. Any raised exception from here becomes fatal
- # (and can't be rescued).
- def backtrace
- @backtrace
- end
+ $1 if message =~ regexp or clean_backtrace.find { |line| line =~ regexp }
+ end
+ end
- private
- def compute_backtrace
- [
- "#{source_location.capitalize}\n\n#{source_extract(4)}\n " +
- clean_backtrace.join("\n ")
- ]
+ def to_s
+ "\n#{self.class} (#{message}) #{source_location}:\n" +
+ "#{source_extract}\n #{clean_backtrace.join("\n ")}\n\n"
end
- def source_location
- if line_number
- "on line ##{line_number} of "
- else
- 'in '
- end + file_name
+ # don't do anything nontrivial here. Any raised exception from here becomes fatal
+ # (and can't be rescued).
+ def backtrace
+ @backtrace
end
+
+ private
+ def compute_backtrace
+ [
+ "#{source_location.capitalize}\n\n#{source_extract(4)}\n " +
+ clean_backtrace.join("\n ")
+ ]
+ end
+
+ def source_location
+ if line_number
+ "on line ##{line_number} of "
+ else
+ 'in '
+ end + file_name
+ end
+ end
end
-end \ No newline at end of file
+
+ TemplateError = Template::Error
+end
diff --git a/actionpack/lib/action_view/template/handler.rb b/actionpack/lib/action_view/template/handler.rb
index 4bf58b9fa8..5a46a27893 100644
--- a/actionpack/lib/action_view/template/handler.rb
+++ b/actionpack/lib/action_view/template/handler.rb
@@ -3,34 +3,39 @@ require "action_dispatch/http/mime_type"
# Legacy TemplateHandler stub
module ActionView
- module TemplateHandlers #:nodoc:
- module Compilable
- def self.included(base)
- base.extend(ClassMethods)
- end
+ class Template
+ module Handlers #:nodoc:
+ module Compilable
+ def self.included(base)
+ base.extend(ClassMethods)
+ end
- module ClassMethods
- def call(template)
- new.compile(template)
+ module ClassMethods
+ def call(template)
+ new.compile(template)
+ end
end
- end
- def compile(template)
- raise "Need to implement #{self.class.name}#compile(template)"
- end
+ def compile(template)
+ raise "Need to implement #{self.class.name}#compile(template)"
+ end
+ end
end
- end
- class TemplateHandler
- extlib_inheritable_accessor :default_format
- self.default_format = Mime::HTML
+ class Template::Handler
+ extlib_inheritable_accessor :default_format
+ self.default_format = Mime::HTML
- def self.call(template)
- raise "Need to implement #{self.class.name}#call(template)"
- end
+ def self.call(template)
+ raise "Need to implement #{self.class.name}#call(template)"
+ end
- def render(template, local_assigns)
- raise "Need to implement #{self.class.name}#render(template, local_assigns)"
+ def render(template, local_assigns)
+ raise "Need to implement #{self.class.name}#render(template, local_assigns)"
+ end
end
end
+
+ TemplateHandlers = Template::Handlers
+ TemplateHandler = Template::Handler
end
diff --git a/actionpack/lib/action_view/template/handlers.rb b/actionpack/lib/action_view/template/handlers.rb
index faf54b9fe5..35488c0391 100644
--- a/actionpack/lib/action_view/template/handlers.rb
+++ b/actionpack/lib/action_view/template/handlers.rb
@@ -1,52 +1,54 @@
module ActionView #:nodoc:
- module TemplateHandlers #:nodoc:
- autoload :ERB, 'action_view/template/handlers/erb'
- autoload :RJS, 'action_view/template/handlers/rjs'
- autoload :Builder, 'action_view/template/handlers/builder'
-
- def self.extended(base)
- base.register_default_template_handler :erb, TemplateHandlers::ERB
- base.register_template_handler :rjs, TemplateHandlers::RJS
- base.register_template_handler :builder, TemplateHandlers::Builder
-
- # TODO: Depreciate old template extensions
- base.register_template_handler :rhtml, TemplateHandlers::ERB
- base.register_template_handler :rxml, TemplateHandlers::Builder
- end
-
- @@template_handlers = {}
- @@default_template_handlers = nil
+ class Template
+ module Handlers #:nodoc:
+ autoload :ERB, 'action_view/template/handlers/erb'
+ autoload :RJS, 'action_view/template/handlers/rjs'
+ autoload :Builder, 'action_view/template/handlers/builder'
+
+ def self.extended(base)
+ base.register_default_template_handler :erb, ERB
+ base.register_template_handler :rjs, RJS
+ base.register_template_handler :builder, Builder
+
+ # TODO: Depreciate old template extensions
+ base.register_template_handler :rhtml, ERB
+ base.register_template_handler :rxml, Builder
+ end
+
+ @@template_handlers = {}
+ @@default_template_handlers = nil
- def self.extensions
- @@template_handlers.keys
- end
-
- # Register a class that knows how to handle template files with the given
- # extension. This can be used to implement new template types.
- # The constructor for the class must take the ActiveView::Base instance
- # as a parameter, and the class must implement a +render+ method that
- # takes the contents of the template to render as well as the Hash of
- # local assigns available to the template. The +render+ method ought to
- # return the rendered template as a string.
- def register_template_handler(extension, klass)
- @@template_handlers[extension.to_sym] = klass
- end
-
- def template_handler_extensions
- @@template_handlers.keys.map {|key| key.to_s }.sort
- end
-
- def registered_template_handler(extension)
- extension && @@template_handlers[extension.to_sym]
- end
-
- def register_default_template_handler(extension, klass)
- register_template_handler(extension, klass)
- @@default_template_handlers = klass
- end
-
- def handler_class_for_extension(extension)
- (extension && registered_template_handler(extension.to_sym)) || @@default_template_handlers
+ def self.extensions
+ @@template_handlers.keys
+ end
+
+ # Register a class that knows how to handle template files with the given
+ # extension. This can be used to implement new template types.
+ # The constructor for the class must take the ActiveView::Base instance
+ # as a parameter, and the class must implement a +render+ method that
+ # takes the contents of the template to render as well as the Hash of
+ # local assigns available to the template. The +render+ method ought to
+ # return the rendered template as a string.
+ def register_template_handler(extension, klass)
+ @@template_handlers[extension.to_sym] = klass
+ end
+
+ def template_handler_extensions
+ @@template_handlers.keys.map {|key| key.to_s }.sort
+ end
+
+ def registered_template_handler(extension)
+ extension && @@template_handlers[extension.to_sym]
+ end
+
+ def register_default_template_handler(extension, klass)
+ register_template_handler(extension, klass)
+ @@default_template_handlers = klass
+ end
+
+ def handler_class_for_extension(extension)
+ (extension && registered_template_handler(extension.to_sym)) || @@default_template_handlers
+ end
end
end
end
diff --git a/actionpack/lib/action_view/template/handlers/builder.rb b/actionpack/lib/action_view/template/handlers/builder.rb
index 5f381f7bf0..a93cfca8aa 100644
--- a/actionpack/lib/action_view/template/handlers/builder.rb
+++ b/actionpack/lib/action_view/template/handlers/builder.rb
@@ -1,6 +1,6 @@
module ActionView
- module TemplateHandlers
- class Builder < TemplateHandler
+ module Template::Handlers
+ class Builder < Template::Handler
include Compilable
self.default_format = Mime::XML
diff --git a/actionpack/lib/action_view/template/handlers/erb.rb b/actionpack/lib/action_view/template/handlers/erb.rb
index 88aeb4b053..f8e6376589 100644
--- a/actionpack/lib/action_view/template/handlers/erb.rb
+++ b/actionpack/lib/action_view/template/handlers/erb.rb
@@ -3,7 +3,7 @@ require 'active_support/core_ext/string/output_safety'
require 'erubis'
module ActionView
- module TemplateHandlers
+ module Template::Handlers
class Erubis < ::Erubis::Eruby
def add_preamble(src)
src << "@output_buffer = ActionView::SafeBuffer.new;"
@@ -26,7 +26,7 @@ module ActionView
end
end
- class ERB < TemplateHandler
+ class ERB < Template::Handler
include Compilable
##
diff --git a/actionpack/lib/action_view/template/handlers/rjs.rb b/actionpack/lib/action_view/template/handlers/rjs.rb
index b1d15dc209..63e7dc0902 100644
--- a/actionpack/lib/action_view/template/handlers/rjs.rb
+++ b/actionpack/lib/action_view/template/handlers/rjs.rb
@@ -1,6 +1,6 @@
module ActionView
- module TemplateHandlers
- class RJS < TemplateHandler
+ module Template::Handlers
+ class RJS < Template::Handler
include Compilable
self.default_format = Mime::JS
diff --git a/actionpack/lib/action_view/template/resolver.rb b/actionpack/lib/action_view/template/resolver.rb
index 7336114e1b..a2f4ab2ef5 100644
--- a/actionpack/lib/action_view/template/resolver.rb
+++ b/actionpack/lib/action_view/template/resolver.rb
@@ -1,6 +1,6 @@
require "pathname"
require "active_support/core_ext/class"
-require "action_view/template/template"
+require "action_view/template"
module ActionView
# Abstract superclass
@@ -20,7 +20,7 @@ module ActionView
register_detail(:locale) { [I18n.locale] }
register_detail(:formats) { Mime::SET.symbols }
register_detail(:handlers, :allow_nil => false) do
- TemplateHandlers.extensions
+ Template::Handlers.extensions
end
def initialize(options = {})
@@ -65,7 +65,7 @@ module ActionView
# as well as incorrectly putting part of the path in the template
# name instead of the prefix.
def normalize_name(name, prefix)
- handlers = TemplateHandlers.extensions.join('|')
+ handlers = Template::Handlers.extensions.join('|')
name = name.to_s.gsub(/\.(?:#{handlers})$/, '')
parts = name.split('/')
diff --git a/actionpack/lib/action_view/template/text.rb b/actionpack/lib/action_view/template/text.rb
index f6e011a5ab..67e086d8bd 100644
--- a/actionpack/lib/action_view/template/text.rb
+++ b/actionpack/lib/action_view/template/text.rb
@@ -1,38 +1,40 @@
module ActionView #:nodoc:
- class TextTemplate < String #:nodoc:
- HTML = Mime[:html]
-
- def initialize(string, content_type = HTML)
- super(string.to_s)
- @content_type = Mime[content_type] || content_type
- end
-
- def details
- {:formats => [@content_type.to_sym]}
- end
-
- def identifier
- self
- end
-
- def inspect
- 'text template'
- end
-
- def render(*args)
- to_s
- end
-
- def mime_type
- @content_type
- end
-
- def formats
- [mime_type]
- end
-
- def partial?
- false
+ class Template
+ class Text < String #:nodoc:
+ HTML = Mime[:html]
+
+ def initialize(string, content_type = HTML)
+ super(string.to_s)
+ @content_type = Mime[content_type] || content_type
+ end
+
+ def details
+ {:formats => [@content_type.to_sym]}
+ end
+
+ def identifier
+ self
+ end
+
+ def inspect
+ 'text template'
+ end
+
+ def render(*args)
+ to_s
+ end
+
+ def mime_type
+ @content_type
+ end
+
+ def formats
+ [mime_type]
+ end
+
+ def partial?
+ false
+ end
end
end
end
diff --git a/actionpack/lib/action_view/test_case.rb b/actionpack/lib/action_view/test_case.rb
index 86bbad822d..ab5bc49cf9 100644
--- a/actionpack/lib/action_view/test_case.rb
+++ b/actionpack/lib/action_view/test_case.rb
@@ -1,5 +1,5 @@
require 'active_support/test_case'
-require 'action_controller/testing/test_case'
+require 'action_controller/test_case'
module ActionView
class Base
diff --git a/actionpack/test/abstract/layouts_test.rb b/actionpack/test/abstract/layouts_test.rb
index ae2f1bf1f2..5028c19b80 100644
--- a/actionpack/test/abstract/layouts_test.rb
+++ b/actionpack/test/abstract/layouts_test.rb
@@ -23,7 +23,7 @@ module AbstractControllerTests
self.view_paths = []
def index
- render :_template => ActionView::TextTemplate.new("Hello blank!")
+ render :_template => ActionView::Template::Text.new("Hello blank!")
end
end
@@ -31,19 +31,19 @@ module AbstractControllerTests
layout "hello"
def index
- render :_template => ActionView::TextTemplate.new("Hello string!")
+ render :_template => ActionView::Template::Text.new("Hello string!")
end
def overwrite_default
- render :_template => ActionView::TextTemplate.new("Hello string!"), :layout => :default
+ render :_template => ActionView::Template::Text.new("Hello string!"), :layout => :default
end
def overwrite_false
- render :_template => ActionView::TextTemplate.new("Hello string!"), :layout => false
+ render :_template => ActionView::Template::Text.new("Hello string!"), :layout => false
end
def overwrite_string
- render :_template => ActionView::TextTemplate.new("Hello string!"), :layout => "omg"
+ render :_template => ActionView::Template::Text.new("Hello string!"), :layout => "omg"
end
def overwrite_skip
@@ -72,7 +72,7 @@ module AbstractControllerTests
layout :hello
def index
- render :_template => ActionView::TextTemplate.new("Hello symbol!")
+ render :_template => ActionView::Template::Text.new("Hello symbol!")
end
private
def hello
@@ -84,7 +84,7 @@ module AbstractControllerTests
layout :no_hello
def index
- render :_template => ActionView::TextTemplate.new("Hello missing symbol!")
+ render :_template => ActionView::Template::Text.new("Hello missing symbol!")
end
private
def no_hello
@@ -96,7 +96,7 @@ module AbstractControllerTests
layout :nilz
def index
- render :_template => ActionView::TextTemplate.new("Hello nilz!")
+ render :_template => ActionView::Template::Text.new("Hello nilz!")
end
def nilz() end
@@ -106,7 +106,7 @@ module AbstractControllerTests
layout :objekt
def index
- render :_template => ActionView::TextTemplate.new("Hello nilz!")
+ render :_template => ActionView::Template::Text.new("Hello nilz!")
end
def objekt
@@ -118,7 +118,7 @@ module AbstractControllerTests
layout :omg_no_method
def index
- render :_template => ActionView::TextTemplate.new("Hello boom!")
+ render :_template => ActionView::Template::Text.new("Hello boom!")
end
end
@@ -126,7 +126,7 @@ module AbstractControllerTests
layout "missing"
def index
- render :_template => ActionView::TextTemplate.new("Hello missing!")
+ render :_template => ActionView::Template::Text.new("Hello missing!")
end
end
@@ -134,7 +134,7 @@ module AbstractControllerTests
layout false
def index
- render :_template => ActionView::TextTemplate.new("Hello false!")
+ render :_template => ActionView::Template::Text.new("Hello false!")
end
end
@@ -142,7 +142,7 @@ module AbstractControllerTests
layout nil
def index
- render :_template => ActionView::TextTemplate.new("Hello nil!")
+ render :_template => ActionView::Template::Text.new("Hello nil!")
end
end
diff --git a/actionpack/test/abstract/render_test.rb b/actionpack/test/abstract/render_test.rb
index 45a4763fe4..331cb6f769 100644
--- a/actionpack/test/abstract/render_test.rb
+++ b/actionpack/test/abstract/render_test.rb
@@ -38,7 +38,7 @@ module AbstractController
end
def object
- render :_template => ActionView::TextTemplate.new("With Object")
+ render :_template => ActionView::Template::Text.new("With Object")
end
end
diff --git a/actionpack/test/abstract_unit.rb b/actionpack/test/abstract_unit.rb
index 9d055da4b9..eab9f8b83d 100644
--- a/actionpack/test/abstract_unit.rb
+++ b/actionpack/test/abstract_unit.rb
@@ -83,7 +83,7 @@ class ActiveSupport::TestCase
# have been loaded.
setup_once do
ActionController::Routing::Routes.draw do |map|
- map.connect ':controller/:action/:id'
+ match ':controller(/:action(/:id))'
end
end
end
diff --git a/actionpack/test/activerecord/active_record_store_test.rb b/actionpack/test/activerecord/active_record_store_test.rb
index c6c079f88c..61bee1b66c 100644
--- a/actionpack/test/activerecord/active_record_store_test.rb
+++ b/actionpack/test/activerecord/active_record_store_test.rb
@@ -155,7 +155,7 @@ class ActiveRecordStoreTest < ActionController::IntegrationTest
def with_test_route_set(options = {})
with_routing do |set|
set.draw do |map|
- map.connect "/:action", :controller => "active_record_store_test/test"
+ match ':action', :to => 'active_record_store_test/test'
end
@app = ActiveRecord::SessionStore.new(set, options.reverse_merge(:key => '_session_id'))
yield
diff --git a/actionpack/test/controller/action_pack_assertions_test.rb b/actionpack/test/controller/action_pack_assertions_test.rb
index 901cb940ea..d54be9bdc0 100644
--- a/actionpack/test/controller/action_pack_assertions_test.rb
+++ b/actionpack/test/controller/action_pack_assertions_test.rb
@@ -221,8 +221,8 @@ class ActionPackAssertionsControllerTest < ActionController::TestCase
def test_assert_redirect_to_named_route
with_routing do |set|
set.draw do |map|
- map.route_one 'route_one', :controller => 'action_pack_assertions', :action => 'nothing'
- map.connect ':controller/:action/:id'
+ match 'route_one', :to => 'action_pack_assertions#nothing', :as => :route_one
+ match ':controller/:action'
end
set.install_helpers
@@ -235,9 +235,9 @@ class ActionPackAssertionsControllerTest < ActionController::TestCase
def test_assert_redirect_to_named_route_failure
with_routing do |set|
set.draw do |map|
- map.route_one 'route_one', :controller => 'action_pack_assertions', :action => 'nothing', :id => 'one'
- map.route_two 'route_two', :controller => 'action_pack_assertions', :action => 'nothing', :id => 'two'
- map.connect ':controller/:action/:id'
+ match 'route_one', :to => 'action_pack_assertions#nothing', :as => :route_one
+ match 'route_two', :to => 'action_pack_assertions#nothing', :id => 'two', :as => :route_two
+ match ':controller/:action'
end
process :redirect_to_named_route
assert_raise(ActiveSupport::TestCase::Assertion) do
@@ -255,8 +255,8 @@ class ActionPackAssertionsControllerTest < ActionController::TestCase
def test_assert_redirect_to_nested_named_route
with_routing do |set|
set.draw do |map|
- map.admin_inner_module 'admin/inner_module', :controller => 'admin/inner_module', :action => 'index'
- map.connect ':controller/:action/:id'
+ match 'admin/inner_module', :to => 'admin/inner_module#index', :as => :admin_inner_module
+ match ':controller/:action'
end
@controller = Admin::InnerModuleController.new
process :redirect_to_index
@@ -268,8 +268,8 @@ class ActionPackAssertionsControllerTest < ActionController::TestCase
def test_assert_redirected_to_top_level_named_route_from_nested_controller
with_routing do |set|
set.draw do |map|
- map.top_level '/action_pack_assertions/:id', :controller => 'action_pack_assertions', :action => 'index'
- map.connect ':controller/:action/:id'
+ match '/action_pack_assertions/:id', :to => 'action_pack_assertions#index', :as => :top_level
+ match ':controller/:action'
end
@controller = Admin::InnerModuleController.new
process :redirect_to_top_level_named_route
@@ -282,8 +282,8 @@ class ActionPackAssertionsControllerTest < ActionController::TestCase
with_routing do |set|
set.draw do |map|
# this controller exists in the admin namespace as well which is the only difference from previous test
- map.top_level '/user/:id', :controller => 'user', :action => 'index'
- map.connect ':controller/:action/:id'
+ match '/user/:id', :to => 'user#index', :as => :top_level
+ match ':controller/:action'
end
@controller = Admin::InnerModuleController.new
process :redirect_to_top_level_named_route
diff --git a/actionpack/test/controller/base_test.rb b/actionpack/test/controller/base_test.rb
index b57550a69a..8f8ada8d8c 100644
--- a/actionpack/test/controller/base_test.rb
+++ b/actionpack/test/controller/base_test.rb
@@ -179,8 +179,8 @@ class DefaultUrlOptionsTest < ActionController::TestCase
def test_default_url_options_are_used_if_set
with_routing do |set|
set.draw do |map|
- map.default_url_options 'default_url_options', :controller => 'default_url_options'
- map.connect ':controller/:action/:id'
+ match 'default_url_options', :to => 'default_url_options#default_url_options_action', :as => :default_url_options
+ match ':controller/:action'
end
get :default_url_options_action # Make a dummy request so that the controller is initialized properly.
@@ -210,7 +210,7 @@ class EnsureNamedRoutesWorksTicket22BugTest < ActionController::TestCase
def test_named_routes_still_work
with_routing do |set|
set.draw do |map|
- map.resources :things
+ resources :things
end
EmptyController.send :include, ActionController::UrlWriter
diff --git a/actionpack/test/controller/caching_test.rb b/actionpack/test/controller/caching_test.rb
index 682a8f3995..4ea2e57741 100644
--- a/actionpack/test/controller/caching_test.rb
+++ b/actionpack/test/controller/caching_test.rb
@@ -70,8 +70,8 @@ class PageCachingTest < ActionController::TestCase
def test_page_caching_resources_saves_to_correct_path_with_extension_even_if_default_route
with_routing do |set|
set.draw do |map|
- map.main '', :controller => 'posts', :format => nil
- map.formatted_posts 'posts.:format', :controller => 'posts'
+ match 'posts.:format', :to => 'posts#index', :as => :formatted_posts
+ match '/', :to => 'posts#index', :as => :main
end
@params[:format] = 'rss'
assert_equal '/posts.rss', @rewriter.rewrite(@params)
@@ -422,8 +422,7 @@ class ActionCacheTest < ActionController::TestCase
def test_xml_version_of_resource_is_treated_as_different_cache
with_routing do |set|
set.draw do |map|
- map.connect ':controller/:action.:format'
- map.connect ':controller/:action'
+ match ':controller(/:action(.:format))'
end
get :index, :format => 'xml'
diff --git a/actionpack/test/controller/helper_test.rb b/actionpack/test/controller/helper_test.rb
index b9be163904..9030e562bb 100644
--- a/actionpack/test/controller/helper_test.rb
+++ b/actionpack/test/controller/helper_test.rb
@@ -191,7 +191,7 @@ class IsolatedHelpersTest < Test::Unit::TestCase
end
def test_helper_in_a
- assert_raise(ActionView::TemplateError) { call_controller(A, "index") }
+ assert_raise(ActionView::Template::Error) { call_controller(A, "index") }
end
def test_helper_in_b
diff --git a/actionpack/test/controller/layout_test.rb b/actionpack/test/controller/layout_test.rb
index feb2f81cc1..f635253156 100644
--- a/actionpack/test/controller/layout_test.rb
+++ b/actionpack/test/controller/layout_test.rb
@@ -115,7 +115,7 @@ class RendersNoLayoutController < LayoutTest
end
class LayoutSetInResponseTest < ActionController::TestCase
- include ActionView::TemplateHandlers
+ include ActionView::Template::Handlers
def test_layout_set_when_using_default_layout
@controller = DefaultLayoutController.new
diff --git a/actionpack/test/controller/mime_responds_test.rb b/actionpack/test/controller/mime_responds_test.rb
index c1fa74b8c8..6b9cace9cd 100644
--- a/actionpack/test/controller/mime_responds_test.rb
+++ b/actionpack/test/controller/mime_responds_test.rb
@@ -599,14 +599,18 @@ class RespondWithControllerTest < ActionController::TestCase
end
end
- def test_using_resource_for_post_with_html
+ def test_using_resource_for_post_with_html_redirects_on_success
with_test_route_set do
post :using_resource
assert_equal "text/html", @response.content_type
assert_equal 302, @response.status
assert_equal "http://www.example.com/customers/13", @response.location
assert @response.redirect?
+ end
+ end
+ def test_using_resource_for_post_with_html_rerender_on_failure
+ with_test_route_set do
errors = { :name => :invalid }
Customer.any_instance.stubs(:errors).returns(errors)
post :using_resource
@@ -617,16 +621,20 @@ class RespondWithControllerTest < ActionController::TestCase
end
end
- def test_using_resource_for_post_with_xml
+ def test_using_resource_for_post_with_xml_yields_created_on_success
with_test_route_set do
@request.accept = "application/xml"
-
post :using_resource
assert_equal "application/xml", @response.content_type
assert_equal 201, @response.status
assert_equal "<name>david</name>", @response.body
assert_equal "http://www.example.com/customers/13", @response.location
+ end
+ end
+ def test_using_resource_for_post_with_xml_yields_unprocessable_entity_on_failure
+ with_test_route_set do
+ @request.accept = "application/xml"
errors = { :name => :invalid }
Customer.any_instance.stubs(:errors).returns(errors)
post :using_resource
@@ -637,14 +645,18 @@ class RespondWithControllerTest < ActionController::TestCase
end
end
- def test_using_resource_for_put_with_html
+ def test_using_resource_for_put_with_html_redirects_on_success
with_test_route_set do
put :using_resource
assert_equal "text/html", @response.content_type
assert_equal 302, @response.status
assert_equal "http://www.example.com/customers/13", @response.location
assert @response.redirect?
+ end
+ end
+ def test_using_resource_for_put_with_html_rerender_on_failure
+ with_test_route_set do
errors = { :name => :invalid }
Customer.any_instance.stubs(:errors).returns(errors)
put :using_resource
@@ -655,14 +667,16 @@ class RespondWithControllerTest < ActionController::TestCase
end
end
- def test_using_resource_for_put_with_xml
+ def test_using_resource_for_put_with_xml_yields_ok_on_success
@request.accept = "application/xml"
-
put :using_resource
assert_equal "application/xml", @response.content_type
assert_equal 200, @response.status
assert_equal " ", @response.body
+ end
+ def test_using_resource_for_put_with_xml_yields_unprocessable_entity_on_failure
+ @request.accept = "application/xml"
errors = { :name => :invalid }
Customer.any_instance.stubs(:errors).returns(errors)
put :using_resource
@@ -672,7 +686,7 @@ class RespondWithControllerTest < ActionController::TestCase
assert_nil @response.location
end
- def test_using_resource_for_delete_with_html
+ def test_using_resource_for_delete_with_html_redirects_on_success
with_test_route_set do
Customer.any_instance.stubs(:destroyed?).returns(true)
delete :using_resource
@@ -682,7 +696,7 @@ class RespondWithControllerTest < ActionController::TestCase
end
end
- def test_using_resource_for_delete_with_xml
+ def test_using_resource_for_delete_with_xml_yields_ok_on_success
Customer.any_instance.stubs(:destroyed?).returns(true)
@request.accept = "application/xml"
delete :using_resource
@@ -691,6 +705,18 @@ class RespondWithControllerTest < ActionController::TestCase
assert_equal " ", @response.body
end
+ def test_using_resource_for_delete_with_html_redirects_on_failure
+ with_test_route_set do
+ errors = { :name => :invalid }
+ Customer.any_instance.stubs(:errors).returns(errors)
+ Customer.any_instance.stubs(:destroyed?).returns(false)
+ delete :using_resource
+ assert_equal "text/html", @response.content_type
+ assert_equal 302, @response.status
+ assert_equal "http://www.example.com/customers/13", @response.location
+ end
+ end
+
def test_using_resource_with_parent_for_get
@request.accept = "application/xml"
get :using_resource_with_parent
@@ -827,9 +853,11 @@ class RespondWithControllerTest < ActionController::TestCase
def with_test_route_set
with_routing do |set|
set.draw do |map|
- map.resources :customers
- map.resources :quiz_stores, :has_many => :customers
- map.connect ":controller/:action/:id"
+ resources :customers
+ resources :quiz_stores do
+ resources :customers
+ end
+ match ":controller/:action"
end
yield
end
diff --git a/actionpack/test/controller/redirect_test.rb b/actionpack/test/controller/redirect_test.rb
index ea278fd8f0..570ff4a41b 100644
--- a/actionpack/test/controller/redirect_test.rb
+++ b/actionpack/test/controller/redirect_test.rb
@@ -233,8 +233,8 @@ class RedirectTest < ActionController::TestCase
def test_redirect_to_record
with_routing do |set|
set.draw do |map|
- map.resources :workshops
- map.connect ':controller/:action/:id'
+ resources :workshops
+ match ':controller/:action'
end
get :redirect_to_existing_record
diff --git a/actionpack/test/controller/render_other_test.rb b/actionpack/test/controller/render_other_test.rb
index 51c3c55545..dfc4f2db8c 100644
--- a/actionpack/test/controller/render_other_test.rb
+++ b/actionpack/test/controller/render_other_test.rb
@@ -2,6 +2,11 @@ require 'abstract_unit'
require 'controller/fake_models'
require 'pathname'
+ActionController.add_renderer :simon do |says, options|
+ self.content_type = Mime::TEXT
+ self.response_body = "Simon says: #{says}"
+end
+
class RenderOtherTest < ActionController::TestCase
class TestController < ActionController::Base
protect_from_forgery
@@ -109,6 +114,10 @@ class RenderOtherTest < ActionController::TestCase
end
end
+ def render_simon_says
+ render :simon => "foo"
+ end
+
private
def default_render
if @alternate_default_render
@@ -240,4 +249,9 @@ class RenderOtherTest < ActionController::TestCase
xhr :get, :render_alternate_default
assert_equal %(Element.replace("foo", "partial html");), @response.body
end
+
+ def test_using_custom_render_option
+ get :render_simon_says
+ assert_equal "Simon says: foo", @response.body
+ end
end
diff --git a/actionpack/test/controller/render_test.rb b/actionpack/test/controller/render_test.rb
index cffa970011..f26b15d2e0 100644
--- a/actionpack/test/controller/render_test.rb
+++ b/actionpack/test/controller/render_test.rb
@@ -39,35 +39,35 @@ class TestController < ActionController::Base
render :action => 'hello_world'
end
end
-
+
def conditional_hello_with_public_header
if stale?(:last_modified => Time.now.utc.beginning_of_day, :etag => [:foo, 123], :public => true)
render :action => 'hello_world'
end
end
-
+
def conditional_hello_with_public_header_and_expires_at
expires_in 1.minute
if stale?(:last_modified => Time.now.utc.beginning_of_day, :etag => [:foo, 123], :public => true)
render :action => 'hello_world'
end
end
-
+
def conditional_hello_with_expires_in
expires_in 60.1.seconds
render :action => 'hello_world'
end
-
+
def conditional_hello_with_expires_in_with_public
expires_in 1.minute, :public => true
render :action => 'hello_world'
end
-
+
def conditional_hello_with_expires_in_with_public_with_more_keys
expires_in 1.minute, :public => true, 'max-stale' => 5.hours
render :action => 'hello_world'
end
-
+
def conditional_hello_with_expires_in_with_public_with_more_keys_old_syntax
expires_in 1.minute, :public => true, :private => nil, 'max-stale' => 5.hours
render :action => 'hello_world'
@@ -272,7 +272,7 @@ class TestController < ActionController::Base
def builder_layout_test
render :action => "hello", :layout => "layouts/builder"
end
-
+
# :move: test this in ActionView
def builder_partial_test
render :action => "hello_world_container"
@@ -1093,8 +1093,8 @@ class RenderTest < ActionController::TestCase
def test_head_with_location_object
with_routing do |set|
set.draw do |map|
- map.resources :customers
- map.connect ':controller/:action/:id'
+ resources :customers
+ match ':controller/:action'
end
get :head_with_location_object
@@ -1306,22 +1306,22 @@ class ExpiresInRenderTest < ActionController::TestCase
def setup
@request.host = "www.nextangle.com"
end
-
+
def test_expires_in_header
get :conditional_hello_with_expires_in
assert_equal "max-age=60, private", @response.headers["Cache-Control"]
end
-
+
def test_expires_in_header_with_public
get :conditional_hello_with_expires_in_with_public
assert_equal "max-age=60, public", @response.headers["Cache-Control"]
end
-
+
def test_expires_in_header_with_additional_headers
get :conditional_hello_with_expires_in_with_public_with_more_keys
assert_equal "max-age=60, public, max-stale=18000", @response.headers["Cache-Control"]
end
-
+
def test_expires_in_old_syntax
get :conditional_hello_with_expires_in_with_public_with_more_keys_old_syntax
assert_equal "max-age=60, public, max-stale=18000", @response.headers["Cache-Control"]
@@ -1425,12 +1425,12 @@ class EtagRenderTest < ActionController::TestCase
get :conditional_hello_with_bangs
assert_response :not_modified
end
-
+
def test_etag_with_public_true_should_set_header
get :conditional_hello_with_public_header
assert_equal "public", @response.headers['Cache-Control']
end
-
+
def test_etag_with_public_true_should_set_header_and_retain_other_headers
get :conditional_hello_with_public_header_and_expires_at
assert_equal "max-age=60, public", @response.headers['Cache-Control']
diff --git a/actionpack/test/controller/render_xml_test.rb b/actionpack/test/controller/render_xml_test.rb
index 68a52c3e8c..b5b0d0b9d5 100644
--- a/actionpack/test/controller/render_xml_test.rb
+++ b/actionpack/test/controller/render_xml_test.rb
@@ -61,8 +61,8 @@ class RenderXmlTest < ActionController::TestCase
def test_rendering_with_object_location_should_set_header_with_url_for
with_routing do |set|
set.draw do |map|
- map.resources :customers
- map.connect ':controller/:action/:id'
+ resources :customers
+ match ':controller/:action'
end
get :render_with_object_location
diff --git a/actionpack/test/controller/resources_test.rb b/actionpack/test/controller/resources_test.rb
index 04e9acf855..1a03396ae9 100644
--- a/actionpack/test/controller/resources_test.rb
+++ b/actionpack/test/controller/resources_test.rb
@@ -403,7 +403,7 @@ class ResourcesTest < ActionController::TestCase
with_restful_routing :messages do
assert_restful_routes_for :messages do |options|
assert_recognizes(options.merge(:action => "new"), :path => "/messages/new", :method => :get)
- assert_raise(ActionController::MethodNotAllowed) do
+ assert_raise(ActionController::RoutingError) do
ActionController::Routing::Routes.recognize_path("/messages/new", :method => :post)
end
end
@@ -689,11 +689,11 @@ class ResourcesTest < ActionController::TestCase
options = { :controller => controller_name.to_s }
collection_path = "/#{controller_name}"
- assert_raise(ActionController::MethodNotAllowed) do
+ assert_raise(ActionController::RoutingError) do
assert_recognizes(options.merge(:action => 'update'), :path => collection_path, :method => :put)
end
- assert_raise(ActionController::MethodNotAllowed) do
+ assert_raise(ActionController::RoutingError) do
assert_recognizes(options.merge(:action => 'destroy'), :path => collection_path, :method => :delete)
end
end
@@ -1378,7 +1378,7 @@ class ResourcesTest < ActionController::TestCase
end
def assert_not_recognizes(expected_options, path)
- assert_raise ActionController::RoutingError, ActionController::MethodNotAllowed, Assertion do
+ assert_raise ActionController::RoutingError, Assertion do
assert_recognizes(expected_options, path)
end
end
diff --git a/actionpack/test/controller/routing_test.rb b/actionpack/test/controller/routing_test.rb
index b83c5792ba..a9a970d67d 100644
--- a/actionpack/test/controller/routing_test.rb
+++ b/actionpack/test/controller/routing_test.rb
@@ -554,10 +554,6 @@ class LegacyRouteSetTests < Test::Unit::TestCase
end
def setup_request_method_routes_for(method)
- @request = ActionController::TestRequest.new
- @request.env["REQUEST_METHOD"] = method
- @request.request_uri = "/match"
-
rs.draw do |r|
r.connect '/match', :controller => 'books', :action => 'get', :conditions => { :method => :get }
r.connect '/match', :controller => 'books', :action => 'post', :conditions => { :method => :post }
@@ -569,8 +565,8 @@ class LegacyRouteSetTests < Test::Unit::TestCase
%w(GET POST PUT DELETE).each do |request_method|
define_method("test_request_method_recognized_with_#{request_method}") do
setup_request_method_routes_for(request_method)
- assert_nothing_raised { rs.recognize(@request) }
- assert_equal request_method.downcase, @request.path_parameters[:action]
+ params = rs.recognize_path("/match", :method => request_method)
+ assert_equal request_method.downcase, params[:action]
end
end
@@ -580,18 +576,11 @@ class LegacyRouteSetTests < Test::Unit::TestCase
r.connect '/match', :controller => 'books', :action => 'not_get_or_post'
end
- @request = ActionController::TestRequest.new
- @request.env["REQUEST_METHOD"] = 'POST'
- @request.request_uri = "/match"
- assert_nothing_raised { rs.recognize(@request) }
- assert_equal 'get_or_post', @request.path_parameters[:action]
+ params = rs.recognize_path("/match", :method => :post)
+ assert_equal 'get_or_post', params[:action]
- # have to recreate or else the RouteSet uses a cached version:
- @request = ActionController::TestRequest.new
- @request.env["REQUEST_METHOD"] = 'PUT'
- @request.request_uri = "/match"
- assert_nothing_raised { rs.recognize(@request) }
- assert_equal 'not_get_or_post', @request.path_parameters[:action]
+ params = rs.recognize_path("/match", :method => :put)
+ assert_equal 'not_get_or_post', params[:action]
end
def test_subpath_recognized
@@ -745,9 +734,7 @@ class RouteSetTest < ActiveSupport::TestCase
set.draw do |map|
map.connect '/users/index', :controller => :users, :action => :index
end
- @request = ActionController::TestRequest.new
- @request.request_uri = '/users/index'
- assert_nothing_raised { set.recognize(@request) }
+ params = set.recognize_path('/users/index', :method => :get)
assert_equal 1, set.routes.size
end
@@ -980,55 +967,34 @@ class RouteSetTest < ActiveSupport::TestCase
end
end
- request.request_uri = "/people"
- request.env["REQUEST_METHOD"] = "GET"
- assert_nothing_raised { set.recognize(request) }
- assert_equal("index", request.path_parameters[:action])
- request.recycle!
+ params = set.recognize_path("/people", :method => :get)
+ assert_equal("index", params[:action])
- request.env["REQUEST_METHOD"] = "POST"
- assert_nothing_raised { set.recognize(request) }
- assert_equal("create", request.path_parameters[:action])
- request.recycle!
+ params = set.recognize_path("/people", :method => :post)
+ assert_equal("create", params[:action])
- request.env["REQUEST_METHOD"] = "PUT"
- assert_nothing_raised { set.recognize(request) }
- assert_equal("update", request.path_parameters[:action])
- request.recycle!
+ params = set.recognize_path("/people", :method => :put)
+ assert_equal("update", params[:action])
- assert_raise(ActionController::UnknownHttpMethod) {
- request.env["REQUEST_METHOD"] = "BACON"
- set.recognize(request)
+ assert_raise(ActionController::RoutingError) {
+ set.recognize_path("/people", :method => :bacon)
}
- request.recycle!
- request.request_uri = "/people/5"
- request.env["REQUEST_METHOD"] = "GET"
- assert_nothing_raised { set.recognize(request) }
- assert_equal("show", request.path_parameters[:action])
- assert_equal("5", request.path_parameters[:id])
- request.recycle!
+ params = set.recognize_path("/people/5", :method => :get)
+ assert_equal("show", params[:action])
+ assert_equal("5", params[:id])
- request.env["REQUEST_METHOD"] = "PUT"
- assert_nothing_raised { set.recognize(request) }
- assert_equal("update", request.path_parameters[:action])
- assert_equal("5", request.path_parameters[:id])
- request.recycle!
+ params = set.recognize_path("/people/5", :method => :put)
+ assert_equal("update", params[:action])
+ assert_equal("5", params[:id])
- request.env["REQUEST_METHOD"] = "DELETE"
- assert_nothing_raised { set.recognize(request) }
- assert_equal("destroy", request.path_parameters[:action])
- assert_equal("5", request.path_parameters[:id])
- request.recycle!
+ params = set.recognize_path("/people/5", :method => :delete)
+ assert_equal("destroy", params[:action])
+ assert_equal("5", params[:id])
- begin
- request.env["REQUEST_METHOD"] = "POST"
- set.recognize(request)
- flunk 'Should have raised MethodNotAllowed'
- rescue ActionController::MethodNotAllowed => e
- assert_equal [:get, :put, :delete], e.allowed_methods
- end
- request.recycle!
+ assert_raise(ActionController::RoutingError) {
+ set.recognize_path("/people/5", :method => :post)
+ }
end
def test_recognize_with_alias_in_conditions
@@ -1038,17 +1004,13 @@ class RouteSetTest < ActiveSupport::TestCase
map.root :people
end
- request.path = "/people"
- request.env["REQUEST_METHOD"] = "GET"
- assert_nothing_raised { set.recognize(request) }
- assert_equal("people", request.path_parameters[:controller])
- assert_equal("index", request.path_parameters[:action])
+ params = set.recognize_path("/people", :method => :get)
+ assert_equal("people", params[:controller])
+ assert_equal("index", params[:action])
- request.path = "/"
- request.env["REQUEST_METHOD"] = "GET"
- assert_nothing_raised { set.recognize(request) }
- assert_equal("people", request.path_parameters[:controller])
- assert_equal("index", request.path_parameters[:action])
+ params = set.recognize_path("/", :method => :get)
+ assert_equal("people", params[:controller])
+ assert_equal("index", params[:action])
end
def test_typo_recognition
@@ -1058,14 +1020,12 @@ class RouteSetTest < ActiveSupport::TestCase
:year => /\d{4}/, :day => /\d{1,2}/, :month => /\d{1,2}/
end
- request.path = "/articles/2005/11/05/a-very-interesting-article"
- request.env["REQUEST_METHOD"] = "GET"
- assert_nothing_raised { set.recognize(request) }
- assert_equal("permalink", request.path_parameters[:action])
- assert_equal("2005", request.path_parameters[:year])
- assert_equal("11", request.path_parameters[:month])
- assert_equal("05", request.path_parameters[:day])
- assert_equal("a-very-interesting-article", request.path_parameters[:title])
+ params = set.recognize_path("/articles/2005/11/05/a-very-interesting-article", :method => :get)
+ assert_equal("permalink", params[:action])
+ assert_equal("2005", params[:year])
+ assert_equal("11", params[:month])
+ assert_equal("05", params[:day])
+ assert_equal("a-very-interesting-article", params[:title])
end
def test_routing_traversal_does_not_load_extra_classes
@@ -1074,9 +1034,7 @@ class RouteSetTest < ActiveSupport::TestCase
map.connect '/profile', :controller => 'profile'
end
- request.path = '/profile'
-
- set.recognize(request) rescue nil
+ params = set.recognize_path("/profile") rescue nil
assert !Object.const_defined?("Profiler__"), "Profiler should not be loaded"
end
@@ -1090,24 +1048,17 @@ class RouteSetTest < ActiveSupport::TestCase
end
end
- request.request_uri = "/people/5"
- request.env["REQUEST_METHOD"] = "GET"
- assert_nothing_raised { set.recognize(request) }
- assert_equal("show", request.path_parameters[:action])
- assert_equal("5", request.path_parameters[:id])
- request.recycle!
+ params = set.recognize_path("/people/5", :method => :get)
+ assert_equal("show", params[:action])
+ assert_equal("5", params[:id])
- request.env["REQUEST_METHOD"] = "PUT"
- assert_nothing_raised { set.recognize(request) }
- assert_equal("update", request.path_parameters[:action])
- request.recycle!
+ params = set.recognize_path("/people/5", :method => :put)
+ assert_equal("update", params[:action])
- request.request_uri = "/people/5.png"
- request.env["REQUEST_METHOD"] = "GET"
- assert_nothing_raised { set.recognize(request) }
- assert_equal("show", request.path_parameters[:action])
- assert_equal("5", request.path_parameters[:id])
- assert_equal("png", request.path_parameters[:_format])
+ params = set.recognize_path("/people/5.png", :method => :get)
+ assert_equal("show", params[:action])
+ assert_equal("5", params[:id])
+ assert_equal("png", params[:_format])
end
def test_generate_with_default_action
@@ -1123,11 +1074,9 @@ class RouteSetTest < ActiveSupport::TestCase
def test_root_map
set.draw { |map| map.root :controller => "people" }
- request.path = ""
- request.env["REQUEST_METHOD"] = "GET"
- assert_nothing_raised { set.recognize(request) }
- assert_equal("people", request.path_parameters[:controller])
- assert_equal("index", request.path_parameters[:action])
+ params = set.recognize_path("", :method => :get)
+ assert_equal("people", params[:controller])
+ assert_equal("index", params[:action])
end
def test_namespace
@@ -1139,11 +1088,9 @@ class RouteSetTest < ActiveSupport::TestCase
end
- request.path = "/api/inventory"
- request.env["REQUEST_METHOD"] = "GET"
- assert_nothing_raised { set.recognize(request) }
- assert_equal("api/products", request.path_parameters[:controller])
- assert_equal("inventory", request.path_parameters[:action])
+ params = set.recognize_path("/api/inventory", :method => :get)
+ assert_equal("api/products", params[:controller])
+ assert_equal("inventory", params[:action])
end
def test_namespaced_root_map
@@ -1155,11 +1102,9 @@ class RouteSetTest < ActiveSupport::TestCase
end
- request.path = "/api"
- request.env["REQUEST_METHOD"] = "GET"
- assert_nothing_raised { set.recognize(request) }
- assert_equal("api/products", request.path_parameters[:controller])
- assert_equal("index", request.path_parameters[:action])
+ params = set.recognize_path("/api", :method => :get)
+ assert_equal("api/products", params[:controller])
+ assert_equal("index", params[:action])
end
def test_namespace_with_path_prefix
@@ -1169,11 +1114,9 @@ class RouteSetTest < ActiveSupport::TestCase
end
end
- request.path = "/prefix/inventory"
- request.env["REQUEST_METHOD"] = "GET"
- assert_nothing_raised { set.recognize(request) }
- assert_equal("api/products", request.path_parameters[:controller])
- assert_equal("inventory", request.path_parameters[:action])
+ params = set.recognize_path("/prefix/inventory", :method => :get)
+ assert_equal("api/products", params[:controller])
+ assert_equal("inventory", params[:action])
end
def test_namespace_with_blank_path_prefix
@@ -1183,11 +1126,9 @@ class RouteSetTest < ActiveSupport::TestCase
end
end
- request.path = "/inventory"
- request.env["REQUEST_METHOD"] = "GET"
- assert_nothing_raised { set.recognize(request) }
- assert_equal("api/products", request.path_parameters[:controller])
- assert_equal("inventory", request.path_parameters[:action])
+ params = set.recognize_path("/inventory", :method => :get)
+ assert_equal("api/products", params[:controller])
+ assert_equal("inventory", params[:action])
end
def test_generate_changes_controller_module
@@ -1316,11 +1257,9 @@ class RouteSetTest < ActiveSupport::TestCase
end
end
- request.path = "/projects/1/milestones"
- request.env["REQUEST_METHOD"] = "GET"
- assert_nothing_raised { set.recognize(request) }
- assert_equal("milestones", request.path_parameters[:controller])
- assert_equal("index", request.path_parameters[:action])
+ params = set.recognize_path("/projects/1/milestones", :method => :get)
+ assert_equal("milestones", params[:controller])
+ assert_equal("index", params[:action])
end
def test_setting_root_in_namespace_using_symbol
@@ -1437,15 +1376,13 @@ class RouteSetTest < ActiveSupport::TestCase
)/x}
end
- pending do
- url = set.generate({:controller => 'pages', :action => 'show', :name => 'david'})
- assert_equal "/page/david", url
- assert_raise ActionController::RoutingError do
- url = set.generate({:controller => 'pages', :action => 'show', :name => 'davidjamis'})
- end
- assert_raise ActionController::RoutingError do
- url = set.generate({:controller => 'pages', :action => 'show', :name => 'JAMIS'})
- end
+ url = set.generate({:controller => 'pages', :action => 'show', :name => 'david'})
+ assert_equal "/page/david", url
+ assert_raise ActionController::RoutingError do
+ url = set.generate({:controller => 'pages', :action => 'show', :name => 'davidjamis'})
+ end
+ assert_raise ActionController::RoutingError do
+ url = set.generate({:controller => 'pages', :action => 'show', :name => 'JAMIS'})
end
end
@@ -1461,10 +1398,8 @@ class RouteSetTest < ActiveSupport::TestCase
)/xi}
end
- pending do
- url = set.generate({:controller => 'pages', :action => 'show', :name => 'JAMIS'})
- assert_equal "/page/JAMIS", url
- end
+ url = set.generate({:controller => 'pages', :action => 'show', :name => 'JAMIS'})
+ assert_equal "/page/JAMIS", url
end
def test_route_requirement_recognize_with_xi_modifiers
@@ -1672,9 +1607,7 @@ class RouteSetTest < ActiveSupport::TestCase
assert_equal("/blog/2006/07/25", set.generate({:day => 25}, last_request))
assert_equal("/blog/2005", set.generate({:year => 2005}, last_request))
assert_equal("/blog/show/123", set.generate({:action => "show" , :id => 123}, last_request))
- pending do
- assert_equal("/blog/2006/07/28", set.generate({:year => 2006}, last_request))
- end
+ assert_equal("/blog/2006", set.generate({:year => 2006}, last_request))
assert_equal("/blog/2006", set.generate({:year => 2006, :month => nil}, last_request))
end
diff --git a/actionpack/test/controller/test_test.rb b/actionpack/test/controller/test_test.rb
index 375878b755..a788b2495e 100644
--- a/actionpack/test/controller/test_test.rb
+++ b/actionpack/test/controller/test_test.rb
@@ -456,8 +456,8 @@ XML
def test_array_path_parameter_handled_properly
with_routing do |set|
set.draw do |map|
- map.connect 'file/*path', :controller => 'test_test/test', :action => 'test_params'
- map.connect ':controller/:action/:id'
+ match 'file/*path', :to => 'test_test/test#test_params'
+ match ':controller/:action'
end
get :test_params, :path => ['hello', 'world']
@@ -628,17 +628,6 @@ XML
assert_nothing_raised(NoMethodError) { @response.binary_content }
end
end
-
- protected
- def with_foo_routing
- with_routing do |set|
- set.draw do |map|
- map.generate_url 'foo', :controller => 'test'
- map.connect ':controller/:action/:id'
- end
- yield set
- end
- end
end
class InferringClassNameTest < ActionController::TestCase
@@ -673,7 +662,7 @@ class NamedRoutesControllerTest < ActionController::TestCase
def test_should_be_able_to_use_named_routes_before_a_request_is_done
with_routing do |set|
- set.draw { |map| map.resources :contents }
+ set.draw { |map| resources :contents }
assert_equal 'http://test.host/contents/new', new_content_url
assert_equal 'http://test.host/contents/1', content_url(:id => 1)
end
diff --git a/actionpack/test/controller/url_rewriter_test.rb b/actionpack/test/controller/url_rewriter_test.rb
index 3b14cbb2d8..428f40b9f8 100644
--- a/actionpack/test/controller/url_rewriter_test.rb
+++ b/actionpack/test/controller/url_rewriter_test.rb
@@ -247,7 +247,7 @@ class UrlWriterTests < ActionController::TestCase
with_routing do |set|
set.draw do |map|
- map.home '/home/sweet/home/:user', :controller => 'home', :action => 'index'
+ match '/home/sweet/home/:user', :to => 'home#index', :as => :home
end
kls = Class.new { include ActionController::UrlWriter }
@@ -264,7 +264,7 @@ class UrlWriterTests < ActionController::TestCase
with_routing do |set|
set.draw do |map|
match 'home/sweet/home/:user', :to => 'home#index', :as => :home
- map.connect ':controller/:action/:id'
+ match ':controller/:action/:id'
end
# We need to create a new class in order to install the new named route.
@@ -331,8 +331,8 @@ class UrlWriterTests < ActionController::TestCase
def test_named_routes_with_nil_keys
with_routing do |set|
set.draw do |map|
- map.main '', :controller => 'posts', :format => nil
- map.resources :posts
+ match 'posts.:format', :to => 'posts#index', :as => :posts
+ match '/', :to => 'posts#index', :as => :main
end
# We need to create a new class in order to install the new named route.
@@ -350,7 +350,7 @@ class UrlWriterTests < ActionController::TestCase
def test_formatted_url_methods_are_deprecated
with_routing do |set|
set.draw do |map|
- map.resources :posts
+ resources :posts
end
# We need to create a new class in order to install the new named route.
kls = Class.new { include ActionController::UrlWriter }
diff --git a/actionpack/test/controller/webservice_test.rb b/actionpack/test/controller/webservice_test.rb
index 0514c098bf..5882a8cfa3 100644
--- a/actionpack/test/controller/webservice_test.rb
+++ b/actionpack/test/controller/webservice_test.rb
@@ -255,9 +255,7 @@ class WebServiceTest < ActionController::IntegrationTest
def with_test_route_set
with_routing do |set|
set.draw do |map|
- map.with_options :controller => "web_service_test/test" do |c|
- c.connect "/", :action => "assign_parameters"
- end
+ match '/', :to => 'web_service_test/test#assign_parameters'
end
yield
end
diff --git a/actionpack/test/dispatch/request/multipart_params_parsing_test.rb b/actionpack/test/dispatch/request/multipart_params_parsing_test.rb
index 301080842e..40c5ac2d09 100644
--- a/actionpack/test/dispatch/request/multipart_params_parsing_test.rb
+++ b/actionpack/test/dispatch/request/multipart_params_parsing_test.rb
@@ -151,7 +151,7 @@ class MultipartParamsParsingTest < ActionController::IntegrationTest
def with_test_routing
with_routing do |set|
set.draw do |map|
- map.connect ':action', :controller => "multipart_params_parsing_test/test"
+ match ':action', :to => 'multipart_params_parsing_test/test'
end
yield
end
diff --git a/actionpack/test/dispatch/routing_test.rb b/actionpack/test/dispatch/routing_test.rb
index b8bcdc2808..425796b460 100644
--- a/actionpack/test/dispatch/routing_test.rb
+++ b/actionpack/test/dispatch/routing_test.rb
@@ -14,7 +14,7 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest
stub_controllers do |routes|
Routes = routes
- Routes.draw do |map|
+ Routes.draw do
controller :sessions do
get 'login', :to => :new, :as => :login
post 'login', :to => :create
@@ -58,8 +58,10 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest
end
resources :people do
- namespace ":access_token" do
- resource :avatar
+ nested do
+ namespace ":access_token" do
+ resource :avatar
+ end
end
member do
@@ -93,9 +95,9 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest
end
controller :articles do
- scope 'articles' do
- scope ':title', :title => /[a-z]+/, :as => :with_title do
- match ':id', :to => :with_id
+ scope '/articles', :name_prefix => 'article' do
+ scope :path => '/:title', :title => /[a-z]+/, :as => :with_title do
+ match '/:id', :to => :with_id
end
end
end
@@ -194,14 +196,26 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest
assert_equal 'projects#index', @response.body
assert_equal '/projects', projects_path
+ get '/projects.xml'
+ assert_equal 'projects#index', @response.body
+ assert_equal '/projects.xml', projects_path(:format => 'xml')
+
get '/projects/new'
assert_equal 'projects#new', @response.body
assert_equal '/projects/new', new_project_path
+ get '/projects/new.xml'
+ assert_equal 'projects#new', @response.body
+ assert_equal '/projects/new.xml', new_project_path(:format => 'xml')
+
get '/projects/1'
assert_equal 'projects#show', @response.body
assert_equal '/projects/1', project_path(:id => '1')
+ get '/projects/1.xml'
+ assert_equal 'projects#show', @response.body
+ assert_equal '/projects/1.xml', project_path(:id => '1', :format => 'xml')
+
get '/projects/1/edit'
assert_equal 'projects#edit', @response.body
assert_equal '/projects/1/edit', edit_project_path(:id => '1')
@@ -214,9 +228,23 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest
assert_equal 'involvements#index', @response.body
assert_equal '/projects/1/involvements', project_involvements_path(:project_id => '1')
+ get '/projects/1/involvements/new'
+ assert_equal 'involvements#new', @response.body
+ assert_equal '/projects/1/involvements/new', new_project_involvement_path(:project_id => '1')
+
get '/projects/1/involvements/1'
assert_equal 'involvements#show', @response.body
assert_equal '/projects/1/involvements/1', project_involvement_path(:project_id => '1', :id => '1')
+
+ put '/projects/1/involvements/1'
+ assert_equal 'involvements#update', @response.body
+
+ delete '/projects/1/involvements/1'
+ assert_equal 'involvements#destroy', @response.body
+
+ get '/projects/1/involvements/1/edit'
+ assert_equal 'involvements#edit', @response.body
+ assert_equal '/projects/1/involvements/1/edit', edit_project_involvement_path(:project_id => '1', :id => '1')
end
end
@@ -236,10 +264,7 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest
put '/projects/1/participants/update_all'
assert_equal 'participants#update_all', @response.body
-
- pending do
- assert_equal '/projects/1/participants/update_all', update_all_project_participants_path(:project_id => '1')
- end
+ assert_equal '/projects/1/participants/update_all', update_all_project_participants_path(:project_id => '1')
end
end
@@ -255,9 +280,7 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest
get '/projects/1/companies/1/avatar'
assert_equal 'avatars#show', @response.body
- pending do
- assert_equal '/projects/1/companies/1/avatar', project_company_avatar_path(:project_id => '1', :company_id => '1')
- end
+ assert_equal '/projects/1/companies/1/avatar', project_company_avatar_path(:project_id => '1', :company_id => '1')
end
end
@@ -269,9 +292,7 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest
post '/projects/1/images/1/revise'
assert_equal 'images#revise', @response.body
- pending do
- assert_equal '/projects/1/images/1/revise', revise_project_image_path(:project_id => '1', :id => '1')
- end
+ assert_equal '/projects/1/images/1/revise', revise_project_image_path(:project_id => '1', :id => '1')
end
end
@@ -287,27 +308,19 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest
get '/projects/1/people/1/7a2dec8/avatar'
assert_equal 'avatars#show', @response.body
- pending do
- assert_equal '/projects/1/people/1/7a2dec8/avatar', project_person_avatar_path(:project_id => '1', :person_id => '1', :access_token => '7a2dec8')
- end
+ assert_equal '/projects/1/people/1/7a2dec8/avatar', project_person_avatar_path(:project_id => '1', :person_id => '1', :access_token => '7a2dec8')
put '/projects/1/people/1/accessible_projects'
assert_equal 'people#accessible_projects', @response.body
- pending do
- assert_equal '/projects/1/people/1/accessible_projects', accessible_projects_project_person_path(:project_id => '1', :id => '1')
- end
+ assert_equal '/projects/1/people/1/accessible_projects', accessible_projects_project_person_path(:project_id => '1', :id => '1')
post '/projects/1/people/1/resend'
assert_equal 'people#resend', @response.body
- pending do
- assert_equal '/projects/1/people/1/resend', resend_project_person_path(:project_id => '1', :id => '1')
- end
+ assert_equal '/projects/1/people/1/resend', resend_project_person_path(:project_id => '1', :id => '1')
post '/projects/1/people/1/generate_new_password'
assert_equal 'people#generate_new_password', @response.body
- pending do
- assert_equal '/projects/1/people/1/generate_new_password', generate_new_password_project_person_path(:project_id => '1', :id => '1')
- end
+ assert_equal '/projects/1/people/1/generate_new_password', generate_new_password_project_person_path(:project_id => '1', :id => '1')
end
end
@@ -319,27 +332,19 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest
get '/projects/1/posts/archive'
assert_equal 'posts#archive', @response.body
- pending do
- assert_equal '/projects/1/posts/archive', archive_project_posts_path(:project_id => '1')
- end
+ assert_equal '/projects/1/posts/archive', archive_project_posts_path(:project_id => '1')
get '/projects/1/posts/toggle_view'
assert_equal 'posts#toggle_view', @response.body
- pending do
- assert_equal '/projects/1/posts/toggle_view', toggle_view_project_posts_path(:project_id => '1')
- end
+ assert_equal '/projects/1/posts/toggle_view', toggle_view_project_posts_path(:project_id => '1')
post '/projects/1/posts/1/preview'
assert_equal 'posts#preview', @response.body
- pending do
- assert_equal '/projects/1/posts/1/preview', preview_project_post_path(:project_id => '1', :id => '1')
- end
+ assert_equal '/projects/1/posts/1/preview', preview_project_post_path(:project_id => '1', :id => '1')
get '/projects/1/posts/1/subscription'
assert_equal 'subscriptions#show', @response.body
- pending do
- assert_equal '/projects/1/posts/1/subscription', project_post_subscription_path(:project_id => '1', :post_id => '1')
- end
+ assert_equal '/projects/1/posts/1/subscription', project_post_subscription_path(:project_id => '1', :post_id => '1')
get '/projects/1/posts/1/comments'
assert_equal 'comments#index', @response.body
@@ -347,9 +352,7 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest
post '/projects/1/posts/1/comments/preview'
assert_equal 'comments#preview', @response.body
- pending do
- assert_equal '/projects/1/posts/1/comments/preview', preview_project_post_comments_path(:project_id => '1', :post_id => '1')
- end
+ assert_equal '/projects/1/posts/1/comments/preview', preview_project_post_comments_path(:project_id => '1', :post_id => '1')
end
end
@@ -407,7 +410,7 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest
assert_raise(ActionController::RoutingError) { get '/articles/123/1' }
- assert_equal '/articles/rails/1', with_title_path(:title => 'rails', :id => 1)
+ assert_equal '/articles/rails/1', article_with_title_path(:title => 'rails', :id => 1)
end
end
diff --git a/actionpack/test/template/atom_feed_helper_test.rb b/actionpack/test/template/atom_feed_helper_test.rb
index 6a5fb0acff..347cb98303 100644
--- a/actionpack/test/template/atom_feed_helper_test.rb
+++ b/actionpack/test/template/atom_feed_helper_test.rb
@@ -187,10 +187,9 @@ class ScrollsController < ActionController::Base
end
protected
-
- def rescue_action(e)
- raise(e)
- end
+ def rescue_action(e)
+ raise(e)
+ end
end
class AtomFeedTest < ActionController::TestCase
@@ -311,11 +310,12 @@ class AtomFeedTest < ActionController::TestCase
assert_select "summary div p", :text => "after 2"
end
end
-private
+
+ private
def with_restful_routing(resources)
with_routing do |set|
set.draw do |map|
- map.resources(resources)
+ resources(resources)
end
yield
end
diff --git a/actionpack/test/template/render_test.rb b/actionpack/test/template/render_test.rb
index 35c51ca7ea..fdf3db1cdb 100644
--- a/actionpack/test/template/render_test.rb
+++ b/actionpack/test/template/render_test.rb
@@ -106,8 +106,8 @@ module RenderTestCases
def test_render_partial_with_errors
@view.render(:partial => "test/raise")
- flunk "Render did not raise TemplateError"
- rescue ActionView::TemplateError => e
+ flunk "Render did not raise Template::Error"
+ rescue ActionView::Template::Error => e
assert_match "undefined local variable or method `doesnt_exist'", e.message
assert_equal "", e.sub_template_message
assert_equal "1", e.line_number
@@ -116,8 +116,8 @@ module RenderTestCases
def test_render_sub_template_with_errors
@view.render(:file => "test/sub_template_raise")
- flunk "Render did not raise TemplateError"
- rescue ActionView::TemplateError => e
+ flunk "Render did not raise Template::Error"
+ rescue ActionView::Template::Error => e
assert_match "undefined local variable or method `doesnt_exist'", e.message
assert_equal "Trace of template inclusion: #{File.expand_path("#{FIXTURE_LOAD_PATH}/test/sub_template_raise.html.erb")}", e.sub_template_message
assert_equal "1", e.line_number
diff --git a/actionpack/test/template/test_case_test.rb b/actionpack/test/template/test_case_test.rb
index 05a409d05a..9a448ce328 100644
--- a/actionpack/test/template/test_case_test.rb
+++ b/actionpack/test/template/test_case_test.rb
@@ -114,7 +114,7 @@ module ActionView
test "is able to use named routes" do
with_routing do |set|
- set.draw { |map| map.resources :contents }
+ set.draw { |map| resources :contents }
assert_equal 'http://test.host/contents/new', new_content_url
assert_equal 'http://test.host/contents/1', content_url(:id => 1)
end
@@ -122,7 +122,7 @@ module ActionView
test "named routes can be used from helper included in view" do
with_routing do |set|
- set.draw { |map| map.resources :contents }
+ set.draw { |map| resources :contents }
_helpers.module_eval do
def render_from_helper
new_content_url
diff --git a/actionpack/test/template/url_helper_test.rb b/actionpack/test/template/url_helper_test.rb
index 5c463a4f60..d4b58efe1e 100644
--- a/actionpack/test/template/url_helper_test.rb
+++ b/actionpack/test/template/url_helper_test.rb
@@ -451,7 +451,7 @@ class UrlHelperControllerTest < ActionController::TestCase
def with_url_helper_routing
with_routing do |set|
set.draw do |map|
- map.show_named_route 'url_helper_controller_test/url_helper/show_named_route', :controller => 'url_helper_controller_test/url_helper', :action => 'show_named_route'
+ match 'url_helper_controller_test/url_helper/show_named_route', :to => 'url_helper_controller_test/url_helper#show_named_route', :as => :show_named_route
end
yield
end
@@ -505,7 +505,7 @@ class LinkToUnlessCurrentWithControllerTest < ActionController::TestCase
def with_restful_routing
with_routing do |set|
set.draw do |map|
- map.resources :tasks
+ resources :tasks
end
yield
end
@@ -625,8 +625,8 @@ class PolymorphicControllerTest < ActionController::TestCase
def with_restful_routing
with_routing do |set|
set.draw do |map|
- map.resources :workshops do |w|
- w.resources :sessions
+ resources :workshops do
+ resources :sessions
end
end
yield