From 7a113edeb28a1d3deb9697f885989c4314df6f21 Mon Sep 17 00:00:00 2001 From: mio Date: Tue, 13 Dec 2011 13:51:23 +0100 Subject: [PATCH] added :dependent => :destroy to is_impressionable --- app/models/impressionist/impressionable.rb | 2 +- test_app/Gemfile.lock | 9 ++------- test_app/spec/models/model_spec.rb | 10 +++++++++- 3 files changed, 12 insertions(+), 9 deletions(-) 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