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/middleware/notifications.rb19
-rw-r--r--actionpack/lib/action_dispatch/middleware/params_parser.rb6
-rw-r--r--actionpack/lib/action_dispatch/middleware/stack.rb4
-rw-r--r--actionpack/lib/action_dispatch/railties/subscriber.rb4
-rw-r--r--actionpack/lib/action_dispatch/routing/mapper.rb36
-rw-r--r--actionpack/lib/action_dispatch/testing/integration.rb4
6 files changed, 54 insertions, 19 deletions
diff --git a/actionpack/lib/action_dispatch/middleware/notifications.rb b/actionpack/lib/action_dispatch/middleware/notifications.rb
index 01d2cbb435..c3776d53a8 100644
--- a/actionpack/lib/action_dispatch/middleware/notifications.rb
+++ b/actionpack/lib/action_dispatch/middleware/notifications.rb
@@ -8,17 +8,24 @@ module ActionDispatch
@app = app
end
- def call(stack_env)
- env = stack_env.dup
- ActiveSupport::Notifications.instrument("action_dispatch.before_dispatch", :env => env)
+ def call(env)
+ payload = retrieve_payload_from_env(env)
+ ActiveSupport::Notifications.instrument("action_dispatch.before_dispatch", payload)
- ActiveSupport::Notifications.instrument!("action_dispatch.after_dispatch", :env => env) do
- @app.call(stack_env)
+ ActiveSupport::Notifications.instrument!("action_dispatch.after_dispatch", payload) do
+ @app.call(env)
end
rescue Exception => exception
ActiveSupport::Notifications.instrument('action_dispatch.exception',
- :env => stack_env, :exception => exception)
+ :env => env, :exception => exception)
raise exception
end
+
+ protected
+
+ # Remove any rack related constants from the env, like rack.input.
+ def retrieve_payload_from_env(env)
+ Hash[:env => env.except(*env.keys.select { |k| k.to_s.index("rack.") == 0 })]
+ end
end
end \ No newline at end of file
diff --git a/actionpack/lib/action_dispatch/middleware/params_parser.rb b/actionpack/lib/action_dispatch/middleware/params_parser.rb
index 534390d4aa..522982e202 100644
--- a/actionpack/lib/action_dispatch/middleware/params_parser.rb
+++ b/actionpack/lib/action_dispatch/middleware/params_parser.rb
@@ -35,14 +35,14 @@ module ActionDispatch
when Proc
strategy.call(request.raw_post)
when :xml_simple, :xml_node
- request.body.size == 0 ? {} : Hash.from_xml(request.body).with_indifferent_access
+ request.body.size == 0 ? {} : Hash.from_xml(request.raw_post).with_indifferent_access
when :yaml
- YAML.load(request.body)
+ YAML.load(request.raw_post)
when :json
if request.body.size == 0
{}
else
- data = ActiveSupport::JSON.decode(request.body)
+ data = ActiveSupport::JSON.decode(request.raw_post)
data = {:_json => data} unless data.is_a?(Hash)
data.with_indifferent_access
end
diff --git a/actionpack/lib/action_dispatch/middleware/stack.rb b/actionpack/lib/action_dispatch/middleware/stack.rb
index 24be4fee55..0dc1d70e37 100644
--- a/actionpack/lib/action_dispatch/middleware/stack.rb
+++ b/actionpack/lib/action_dispatch/middleware/stack.rb
@@ -60,9 +60,7 @@ module ActionDispatch
end
def inspect
- str = klass.to_s
- args.each { |arg| str += ", #{build_args.inspect}" }
- str
+ klass.to_s
end
def build(app)
diff --git a/actionpack/lib/action_dispatch/railties/subscriber.rb b/actionpack/lib/action_dispatch/railties/subscriber.rb
index c08a844c6a..cdb1162eac 100644
--- a/actionpack/lib/action_dispatch/railties/subscriber.rb
+++ b/actionpack/lib/action_dispatch/railties/subscriber.rb
@@ -5,8 +5,8 @@ module ActionDispatch
request = Request.new(event.payload[:env])
path = request.request_uri.inspect rescue "unknown"
- info "\n\nProcessing #{path} to #{request.formats.join(', ')} " <<
- "(for #{request.remote_ip} at #{event.time.to_s(:db)}) [#{request.method.to_s.upcase}]"
+ info "\n\nStarted #{request.method.to_s.upcase} #{path} " <<
+ "for #{request.remote_ip} at #{event.time.to_s(:db)}"
end
def logger
diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb
index 811c287355..fcbb70749f 100644
--- a/actionpack/lib/action_dispatch/routing/mapper.rb
+++ b/actionpack/lib/action_dispatch/routing/mapper.rb
@@ -375,6 +375,15 @@ module ActionDispatch
end
end
+ def action_type(action)
+ case action
+ when :index, :create
+ :collection
+ when :show, :update, :destroy
+ :member
+ end
+ end
+
def name
options[:as] || plural
end
@@ -391,6 +400,15 @@ module ActionDispatch
plural
end
+ def name_for_action(action)
+ case action_type(action)
+ when :collection
+ collection_name
+ when :member
+ member_name
+ end
+ end
+
def id_segment
":#{singular}_id"
end
@@ -405,6 +423,13 @@ module ActionDispatch
super
end
+ def action_type(action)
+ case action
+ when :show, :create, :update, :destroy
+ :member
+ end
+ end
+
def name
options[:as] || singular
end
@@ -428,7 +453,7 @@ module ActionDispatch
with_scope_level(:resource, resource) do
yield if block_given?
- get :show, :as => resource.member_name if resource.actions.include?(:show)
+ get :show if resource.actions.include?(:show)
post :create if resource.actions.include?(:create)
put :update if resource.actions.include?(:update)
delete :destroy if resource.actions.include?(:destroy)
@@ -454,14 +479,14 @@ module ActionDispatch
yield if block_given?
with_scope_level(:collection) do
- get :index, :as => resource.collection_name if resource.actions.include?(:index)
+ get :index if resource.actions.include?(:index)
post :create if resource.actions.include?(:create)
get :new, :as => resource.singular if resource.actions.include?(:new)
end
with_scope_level(:member) do
scope(':id') do
- get :show, :as => resource.member_name if resource.actions.include?(:show)
+ get :show if resource.actions.include?(:show)
put :update if resource.actions.include?(:update)
delete :destroy if resource.actions.include?(:destroy)
get :edit, :as => resource.singular if resource.actions.include?(:edit)
@@ -525,7 +550,10 @@ module ActionDispatch
begin
old_path = @scope[:path]
@scope[:path] = "#{@scope[:path]}(.:format)"
- return match(options.reverse_merge(:to => action))
+ return match(options.reverse_merge(
+ :to => action,
+ :as => parent_resource.name_for_action(action)
+ ))
ensure
@scope[:path] = old_path
end
diff --git a/actionpack/lib/action_dispatch/testing/integration.rb b/actionpack/lib/action_dispatch/testing/integration.rb
index 4ec47d146c..d4c9df7ebd 100644
--- a/actionpack/lib/action_dispatch/testing/integration.rb
+++ b/actionpack/lib/action_dispatch/testing/integration.rb
@@ -259,7 +259,9 @@ module ActionDispatch
"HTTP_HOST" => host,
"REMOTE_ADDR" => remote_addr,
"CONTENT_TYPE" => "application/x-www-form-urlencoded",
- "HTTP_ACCEPT" => accept
+ "HTTP_ACCEPT" => accept,
+
+ "action_dispatch.show_exceptions" => false
}
(rack_environment || {}).each do |key, value|