diff --git a/README.md b/README.md index 5853b4d..03f6701 100644 --- a/README.md +++ b/README.md @@ -118,7 +118,7 @@ If you'd like to include only unique impressions in your count: What if I only want to record unique impressions? ------------------------------------------------- -Maybe you only care about unique impressions and would like to eliminate unnecessary database calls. You can specify conditions for recording impressions in your controller: +Maybe you only care about unique impressions and would like to avoid unnecessary database records. You can specify conditions for recording impressions in your controller: # only record impression if the request has a unique combination of type, id, and session impressionist :unique => [:impressionable_type, :impressionable_id, :session_hash] diff --git a/app/models/impressionist/impressionable.rb b/app/models/impressionist/impressionable.rb index 9b5d650..a6284f6 100644 --- a/app/models/impressionist/impressionable.rb +++ b/app/models/impressionist/impressionable.rb @@ -11,7 +11,7 @@ module Impressionist @cache_options = nil def is_impressionable(options={}) - has_many :impressions, :as=>:impressionable + has_many :impressions, :as => :impressionable, :dependent => :destroy @cache_options = options[:counter_cache] end diff --git a/test_app/Gemfile.lock b/test_app/Gemfile.lock index 130489c..d03c6a3 100644 --- a/test_app/Gemfile.lock +++ b/test_app/Gemfile.lock @@ -1,12 +1,11 @@ PATH - remote: /Users/coryschires/Desktop/work/applications/impressionist + remote: /home/mio/prog/projects/impressionist specs: - impressionist (0.4.0) + impressionist (1.0.1) GEM remote: http://rubygems.org/ specs: - ZenTest (4.6.2) actionmailer (3.1.0) actionpack (= 3.1.0) mail (~> 2.3.0) @@ -38,8 +37,6 @@ GEM multi_json (~> 1.0) addressable (2.2.6) arel (2.2.1) - autotest (4.4.6) - ZenTest (>= 4.4.1) autotest-notification (2.3.3) autotest-standalone (~> 4.5) autotest-standalone (4.5.8) @@ -158,8 +155,6 @@ PLATFORMS ruby DEPENDENCIES - ZenTest - autotest autotest-notification capybara cucumber diff --git a/test_app/spec/models/model_spec.rb b/test_app/spec/models/model_spec.rb index bd9f558..1fdb9c2 100644 --- a/test_app/spec/models/model_spec.rb +++ b/test_app/spec/models/model_spec.rb @@ -49,7 +49,15 @@ describe Impression do @article.impressionist_count(:filter=>:session_hash).should eq 7 end - + # tests :dependent => :destroy + it "should delete impressions on deletion of impressionable" do + impressions_count = Impression.all.size + a = Article.create + i = a.impressions.create + a.destroy + a.destroyed?.should be_true + i.destroyed?.should be_true + end #OLD COUNT METHODS. DEPRECATE SOON it "should return the impression count with no date range specified" do