aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_dispatch
diff options
context:
space:
mode:
Diffstat (limited to 'actionpack/lib/action_dispatch')
-rw-r--r--actionpack/lib/action_dispatch/http/mime_type.rb26
-rw-r--r--actionpack/lib/action_dispatch/routing/mapper.rb17
-rw-r--r--actionpack/lib/action_dispatch/testing/assertions/response.rb15
3 files changed, 33 insertions, 25 deletions
diff --git a/actionpack/lib/action_dispatch/http/mime_type.rb b/actionpack/lib/action_dispatch/http/mime_type.rb
index b64f660ec5..b8d395854c 100644
--- a/actionpack/lib/action_dispatch/http/mime_type.rb
+++ b/actionpack/lib/action_dispatch/http/mime_type.rb
@@ -47,15 +47,10 @@ module Mime
def const_missing(sym)
ext = sym.downcase
if Mime[ext]
- ActiveSupport::Deprecation.warn <<-eow
-Accessing mime types via constants is deprecated. Please change:
-
- `Mime::#{sym}`
-
-to:
-
- `Mime[:#{ext}]`
- eow
+ ActiveSupport::Deprecation.warn(<<-MSG.squish)
+ Accessing mime types via constants is deprecated.
+ Please change `Mime::#{sym}` to `Mime[:#{ext}]`.
+ MSG
Mime[ext]
else
super
@@ -65,15 +60,10 @@ to:
def const_defined?(sym, inherit = true)
ext = sym.downcase
if Mime[ext]
- ActiveSupport::Deprecation.warn <<-eow
-Accessing mime types via constants is deprecated. Please change:
-
- `Mime.const_defined?(#{sym})`
-
-to:
-
- `Mime[:#{ext}]`
- eow
+ ActiveSupport::Deprecation.warn(<<-MSG.squish)
+ Accessing mime types via constants is deprecated.
+ Please change `Mime.const_defined?(#{sym})` to `Mime[:#{ext}]`.
+ MSG
true
else
super
diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb
index 7c0404ca62..18cd205bad 100644
--- a/actionpack/lib/action_dispatch/routing/mapper.rb
+++ b/actionpack/lib/action_dispatch/routing/mapper.rb
@@ -11,7 +11,7 @@ module ActionDispatch
class Mapper
URL_OPTIONS = [:protocol, :subdomain, :domain, :host, :port]
- class Constraints < Endpoint #:nodoc:
+ class Constraints < Routing::Endpoint #:nodoc:
attr_reader :app, :constraints
SERVE = ->(app, req) { app.serve req }
@@ -600,17 +600,20 @@ module ActionDispatch
def mount(app, options = nil)
if options
path = options.delete(:at)
- else
- unless Hash === app
- raise ArgumentError, "must be called with mount point"
- end
-
+ elsif Hash === app
options = app
app, path = options.find { |k, _| k.respond_to?(:call) }
options.delete(app) if app
end
- raise "A rack application must be specified" unless path
+ raise ArgumentError, "A rack application must be specified" unless app.respond_to?(:call)
+ raise ArgumentError, <<-MSG.strip_heredoc unless path
+ Must be called with mount point
+
+ mount SomeRackApp, at: "some_route"
+ or
+ mount(SomeRackApp => "some_route")
+ MSG
rails_app = rails_app? app
options[:as] ||= app_name(app, rails_app)
diff --git a/actionpack/lib/action_dispatch/testing/assertions/response.rb b/actionpack/lib/action_dispatch/testing/assertions/response.rb
index eab20b075d..5af052afb4 100644
--- a/actionpack/lib/action_dispatch/testing/assertions/response.rb
+++ b/actionpack/lib/action_dispatch/testing/assertions/response.rb
@@ -27,6 +27,8 @@ module ActionDispatch
# # Asserts that the response code was status code 401 (unauthorized)
# assert_response 401
def assert_response(type, message = nil)
+ message ||= generate_response_message(type)
+
if Symbol === type
if [:success, :missing, :redirect, :error].include?(type)
assert_predicate @response, RESPONSE_PREDICATES[type], message
@@ -82,6 +84,19 @@ module ActionDispatch
handle._compute_redirect_to_location(@request, fragment)
end
end
+
+ def generate_response_message(type)
+ message = "Expected response to be a <#{type}>, but was"
+
+ if @response.redirection?
+ redirect_is = normalize_argument_to_redirection(@response.location)
+ message << " a redirect to <#{redirect_is}>"
+ else
+ message << " <#{@response.response_code}>"
+ end
+
+ message
+ end
end
end
end