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

Non-restful controller support
This commit is contained in:
John McAliley 2013-04-01 12:56:14 -07:00
commit d3a52b18cf
5 changed files with 18 additions and 6 deletions

View File

@ -10,11 +10,12 @@ class Impression < ActiveRecord::Base
private private
def update_impressions_counter_cache def update_impressions_counter_cache
impressionable_class = self.impressionable_type.constantize if self.impressionable_type && self.impressionable_id
impressionable_class = self.impressionable_type.constantize
if impressionable_class.impressionist_counter_cache_options if impressionable_class.impressionist_counter_cache_options
resouce = impressionable_class.find(self.impressionable_id) resouce = impressionable_class.find(self.impressionable_id)
resouce.try(:update_impressionist_counter_cache) resouce.try(:update_impressionist_counter_cache)
end
end end
end end
end end

View File

@ -3,4 +3,6 @@ class DummyController < ActionController::Base
impressionist impressionist
def index
end
end end

View File

View File

@ -1,3 +1,3 @@
TestApp::Application.routes.draw do TestApp::Application.routes.draw do
resources :articles, :posts, :widgets resources :articles, :posts, :widgets, :dummy
end end

View File

@ -123,3 +123,12 @@ describe WidgetsController do
end end
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