Commit d2dc1474dcbb2c18a2456c35cd0912c7f67eabf9
1 parent
772c27b5
Exists in
master
and in
29 other branches
Change vote plugin to remove votes when a voteable is removed
Showing
3 changed files
with
14 additions
and
1 deletions
Show diff stats
test/unit/article_test.rb
| @@ -1751,4 +1751,10 @@ class ArticleTest < ActiveSupport::TestCase | @@ -1751,4 +1751,10 @@ class ArticleTest < ActiveSupport::TestCase | ||
| 1751 | assert_equal 5, article.votes_total | 1751 | assert_equal 5, article.votes_total |
| 1752 | end | 1752 | end |
| 1753 | 1753 | ||
| 1754 | + should 'be able to remove a voted article' do | ||
| 1755 | + article = Article.create!(:name => 'Test', :profile => profile, :last_changed_by => nil) | ||
| 1756 | + profile.vote(article, 5) | ||
| 1757 | + article.destroy | ||
| 1758 | + end | ||
| 1759 | + | ||
| 1754 | end | 1760 | end |
test/unit/comment_test.rb
| @@ -724,6 +724,13 @@ class CommentTest < ActiveSupport::TestCase | @@ -724,6 +724,13 @@ class CommentTest < ActiveSupport::TestCase | ||
| 724 | assert_equal 2, comment.votes_against | 724 | assert_equal 2, comment.votes_against |
| 725 | end | 725 | end |
| 726 | 726 | ||
| 727 | + should 'be able to remove a voted comment' do | ||
| 728 | + comment = create_comment | ||
| 729 | + person = create_user('voter').person | ||
| 730 | + person.vote(comment, 5) | ||
| 731 | + comment.destroy | ||
| 732 | + end | ||
| 733 | + | ||
| 727 | private | 734 | private |
| 728 | 735 | ||
| 729 | def create_comment(args = {}) | 736 | def create_comment(args = {}) |
vendor/plugins/vote_fu/lib/acts_as_voteable.rb
| @@ -16,7 +16,7 @@ module Juixe | @@ -16,7 +16,7 @@ module Juixe | ||
| 16 | # Note: Specifying a counter will add it to that model‘s list of readonly attributes using attr_readonly. | 16 | # Note: Specifying a counter will add it to that model‘s list of readonly attributes using attr_readonly. |
| 17 | # | 17 | # |
| 18 | def acts_as_voteable options={} | 18 | def acts_as_voteable options={} |
| 19 | - has_many :votes, :as => :voteable, :dependent => :nullify | 19 | + has_many :votes, :as => :voteable, :dependent => :destroy |
| 20 | include Juixe::Acts::Voteable::InstanceMethods | 20 | include Juixe::Acts::Voteable::InstanceMethods |
| 21 | extend Juixe::Acts::Voteable::SingletonMethods | 21 | extend Juixe::Acts::Voteable::SingletonMethods |
| 22 | if (options[:vote_counter]) | 22 | if (options[:vote_counter]) |