From d2dc1474dcbb2c18a2456c35cd0912c7f67eabf9 Mon Sep 17 00:00:00 2001 From: Victor Costa Date: Wed, 15 Jan 2014 12:55:46 -0300 Subject: [PATCH] Change vote plugin to remove votes when a voteable is removed --- test/unit/article_test.rb | 6 ++++++ test/unit/comment_test.rb | 7 +++++++ vendor/plugins/vote_fu/lib/acts_as_voteable.rb | 2 +- 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/test/unit/article_test.rb b/test/unit/article_test.rb index ff23e04..be5a549 100644 --- a/test/unit/article_test.rb +++ b/test/unit/article_test.rb @@ -1751,4 +1751,10 @@ class ArticleTest < ActiveSupport::TestCase assert_equal 5, article.votes_total end + should 'be able to remove a voted article' do + article = Article.create!(:name => 'Test', :profile => profile, :last_changed_by => nil) + profile.vote(article, 5) + article.destroy + end + end diff --git a/test/unit/comment_test.rb b/test/unit/comment_test.rb index cf3c18c..080da07 100644 --- a/test/unit/comment_test.rb +++ b/test/unit/comment_test.rb @@ -724,6 +724,13 @@ class CommentTest < ActiveSupport::TestCase assert_equal 2, comment.votes_against end + should 'be able to remove a voted comment' do + comment = create_comment + person = create_user('voter').person + person.vote(comment, 5) + comment.destroy + end + private def create_comment(args = {}) diff --git a/vendor/plugins/vote_fu/lib/acts_as_voteable.rb b/vendor/plugins/vote_fu/lib/acts_as_voteable.rb index 7962260..30415ea 100644 --- a/vendor/plugins/vote_fu/lib/acts_as_voteable.rb +++ b/vendor/plugins/vote_fu/lib/acts_as_voteable.rb @@ -16,7 +16,7 @@ module Juixe # Note: Specifying a counter will add it to that model‘s list of readonly attributes using attr_readonly. # def acts_as_voteable options={} - has_many :votes, :as => :voteable, :dependent => :nullify + has_many :votes, :as => :voteable, :dependent => :destroy include Juixe::Acts::Voteable::InstanceMethods extend Juixe::Acts::Voteable::SingletonMethods if (options[:vote_counter]) -- libgit2 0.21.2