Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #70 from tyrauber/non-restful-controller-support

Non-restful controller support
  • Loading branch information...
commit d3a52b18cf64d94dbbfa001ce6a07ddb247464a7 2 parents 27c9352 + 495e0a4
@johnmcaliley johnmcaliley authored
View
11 lib/impressionist/models/active_record/impression.rb
@@ -10,11 +10,12 @@ class Impression < ActiveRecord::Base
private
def update_impressions_counter_cache
- impressionable_class = self.impressionable_type.constantize
-
- if impressionable_class.impressionist_counter_cache_options
- resouce = impressionable_class.find(self.impressionable_id)
- resouce.try(:update_impressionist_counter_cache)
+ if self.impressionable_type && self.impressionable_id
+ impressionable_class = self.impressionable_type.constantize
+ if impressionable_class.impressionist_counter_cache_options
+ resouce = impressionable_class.find(self.impressionable_id)
+ resouce.try(:update_impressionist_counter_cache)
+ end
end
end
end
View
2  test_app/app/controllers/dummy_controller.rb
@@ -3,4 +3,6 @@ class DummyController < ActionController::Base
impressionist
+ def index
+ end
end
View
0  test_app/app/views/dummy/index.html.erb
No changes.
View
2  test_app/config/routes.rb
@@ -1,3 +1,3 @@
TestApp::Application.routes.draw do
- resources :articles, :posts, :widgets
+ resources :articles, :posts, :widgets, :dummy
end
View
9 test_app/spec/controllers/controller_spec.rb
@@ -123,3 +123,12 @@
end
end
+describe DummyController do
+ fixtures :impressions
+ render_views
+
+ it "should log impression at the per action level on non-restful controller" do
+ get "index"
+ Impression.all.size.should eq 12
+ end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.