Merge pull request #16 from georgmittendorfer/feature-dependent-destroy

Added dependent destroy to is_impressionable (fixes issue #9)
This commit is contained in:
John McAliley 2011-12-14 18:30:53 -08:00
commit 359b912f2b
4 changed files with 13 additions and 10 deletions

View File

@ -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? 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 # only record impression if the request has a unique combination of type, id, and session
impressionist :unique => [:impressionable_type, :impressionable_id, :session_hash] impressionist :unique => [:impressionable_type, :impressionable_id, :session_hash]

View File

@ -11,7 +11,7 @@ module Impressionist
@cache_options = nil @cache_options = nil
def is_impressionable(options={}) def is_impressionable(options={})
has_many :impressions, :as=>:impressionable has_many :impressions, :as => :impressionable, :dependent => :destroy
@cache_options = options[:counter_cache] @cache_options = options[:counter_cache]
end end

View File

@ -1,12 +1,11 @@
PATH PATH
remote: /Users/coryschires/Desktop/work/applications/impressionist remote: /home/mio/prog/projects/impressionist
specs: specs:
impressionist (0.4.0) impressionist (1.0.1)
GEM GEM
remote: http://rubygems.org/ remote: http://rubygems.org/
specs: specs:
ZenTest (4.6.2)
actionmailer (3.1.0) actionmailer (3.1.0)
actionpack (= 3.1.0) actionpack (= 3.1.0)
mail (~> 2.3.0) mail (~> 2.3.0)
@ -38,8 +37,6 @@ GEM
multi_json (~> 1.0) multi_json (~> 1.0)
addressable (2.2.6) addressable (2.2.6)
arel (2.2.1) arel (2.2.1)
autotest (4.4.6)
ZenTest (>= 4.4.1)
autotest-notification (2.3.3) autotest-notification (2.3.3)
autotest-standalone (~> 4.5) autotest-standalone (~> 4.5)
autotest-standalone (4.5.8) autotest-standalone (4.5.8)
@ -158,8 +155,6 @@ PLATFORMS
ruby ruby
DEPENDENCIES DEPENDENCIES
ZenTest
autotest
autotest-notification autotest-notification
capybara capybara
cucumber cucumber

View File

@ -49,7 +49,15 @@ describe Impression do
@article.impressionist_count(:filter=>:session_hash).should eq 7 @article.impressionist_count(:filter=>:session_hash).should eq 7
end 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 #OLD COUNT METHODS. DEPRECATE SOON
it "should return the impression count with no date range specified" do it "should return the impression count with no date range specified" do