From 7c1ac8ccdc2fe7541b455bdd984feb16b0c0fef9 Mon Sep 17 00:00:00 2001 From: cowboycoded Date: Thu, 17 Feb 2011 08:11:06 -0500 Subject: [PATCH] log the controller_name and action_name when impressionist is called manually inside a controller action --- app/controllers/impressionist_controller.rb | 6 ++++-- test_app/Gemfile.lock | 2 +- test_app/spec/controllers/controller_spec.rb | 5 +++++ 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/app/controllers/impressionist_controller.rb b/app/controllers/impressionist_controller.rb index 20cd935..cf0b64e 100644 --- a/app/controllers/impressionist_controller.rb +++ b/app/controllers/impressionist_controller.rb @@ -18,7 +18,9 @@ module ImpressionistController obj.impressions.create(:message=> message, :request_hash=> @impressionist_hash, :ip_address=> request.remote_ip, - :user_id=> user_id) + :user_id=> user_id, + :controller_name=>controller_name, + :action_name=> action_name) else raise "#{obj.class.to_s} is not impressionable!" end @@ -47,7 +49,7 @@ module ImpressionistController private def bypass Impressionist::Bots::WILD_CARDS.each do |wild_card| - return true if request.user_agent.downcase.include? wild_card + return true if request.user_agent and request.user_agent.downcase.include? wild_card end Impressionist::Bots::LIST.include? request.user_agent end diff --git a/test_app/Gemfile.lock b/test_app/Gemfile.lock index 224f02a..31b0da6 100644 --- a/test_app/Gemfile.lock +++ b/test_app/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: /rails_plugins/mine/impressionist specs: - impressionist (0.2.2) + impressionist (0.2.3) GEM remote: http://rubygems.org/ diff --git a/test_app/spec/controllers/controller_spec.rb b/test_app/spec/controllers/controller_spec.rb index 7af42b9..b315b0a 100644 --- a/test_app/spec/controllers/controller_spec.rb +++ b/test_app/spec/controllers/controller_spec.rb @@ -13,12 +13,16 @@ describe ArticlesController do get "index" Impression.all.size.should eq 11 Article.first.impressions.last.message.should eq "this is a test article impression" + Article.first.impressions.last.controller_name.should eq "articles" + Article.first.impressions.last.action_name.should eq "index" end it "should log an impression without a message" do get "show", :id=> 1 Impression.all.size.should eq 11 Article.first.impressions.last.message.should eq nil + Article.first.impressions.last.controller_name.should eq "articles" + Article.first.impressions.last.action_name.should eq "show" end it "should log the user_id if user is authenticated (@current_user before_filter method)" do @@ -38,6 +42,7 @@ describe PostsController do get "show", :id=> 1 Impression.all.size.should eq 11 Impression.last.controller_name.should eq "posts" + Impression.last.action_name.should eq "show" Impression.last.impressionable_type.should eq "Post" Impression.last.impressionable_id.should eq 1 end