Permalink
Browse files

Ensure Action is logged in Rails 2.3.x, fix from @yar

Closes issue #11
  • Loading branch information...
1 parent 4158d71 commit d5e3b9e02c7557c6cf66e317962d18832ae1dc63 @noahd1 committed Jul 8, 2011
Showing with 18 additions and 4 deletions.
  1. +12 −3 lib/oink/middleware.rb
  2. +6 −1 spec/oink/middleware_spec.rb
@@ -28,9 +28,10 @@ def log_completed
end
def log_routing(env)
- if env.has_key?('action_dispatch.request.parameters')
- controller = env['action_dispatch.request.parameters']['controller']
- action = env['action_dispatch.request.parameters']['action']
+ routing_info = rails3_routing_info(env) || rails2_routing_info(env)
+ if routing_info
+ controller = routing_info['controller']
+ action = routing_info['action']
@logger.info("Oink Action: #{controller}##{action}")
end
end
@@ -53,6 +54,14 @@ def log_activerecord
private
+ def rails3_routing_info(env)
+ env['action_dispatch.request.parameters']
+ end
+
+ def rails2_routing_info(env)
+ env['action_controller.request.path_parameters']
+ end
+
def reset_objects_instantiated
ActiveRecord::Base.reset_instance_type_count
end
@@ -42,11 +42,16 @@ def call(env)
log_output.string.should include("Oink Log Entry Complete")
end
- it "logs the action and controller" do
+ it "logs the action and controller in rails 3.x" do
get "/no_pigs", {}, {'action_dispatch.request.parameters' => {'controller' => 'oinkoink', 'action' => 'piggie'}}
log_output.string.should include("Oink Action: oinkoink#piggie")
end
+ it "logs the action and controller in rails 2.3.x" do
+ get "/no_pigs", {}, {'action_controller.request.path_parameters' => {'controller' => 'oinkoink', 'action' => 'piggie'}}
+ log_output.string.should include("Oink Action: oinkoink#piggie")
+ end
+
it "logs the action and controller within a module" do
get "/no_pigs", {}, {'action_dispatch.request.parameters' => {'controller' => 'oinkoink/admin', 'action' => 'piggie'}}
log_output.string.should include("Oink Action: oinkoink/admin#piggie")

0 comments on commit d5e3b9e

Please sign in to comment.