diff --git a/plugins/vote/lib/ext/vote.rb b/plugins/vote/lib/ext/vote.rb index 12f78f6..be349ca 100644 --- a/plugins/vote/lib/ext/vote.rb +++ b/plugins/vote/lib/ext/vote.rb @@ -2,6 +2,10 @@ require_dependency 'models/vote' class Vote - validates_uniqueness_of :voteable_id, :scope => [:voteable_type, :voter_type, :voter_id] + validates_uniqueness_of :voteable_id, :scope => [:voteable_type, :voter_type, :voter_id], :if => :allow_duplicated_vote? + + def allow_duplicated_vote? + voter.present? + end end diff --git a/plugins/vote/test/unit/article_test.rb b/plugins/vote/test/unit/article_test.rb index 8962ac2..d24ae45 100644 --- a/plugins/vote/test/unit/article_test.rb +++ b/plugins/vote/test/unit/article_test.rb @@ -21,4 +21,12 @@ class ArticleTest < ActiveSupport::TestCase article.destroy end + should 'be able to vote in an article without a user' do + article = create(Article, :name => 'Test', :profile => profile, :last_changed_by => nil) + assert_difference 'article.votes_for', 2 do + Vote.create!(:voteable => article, :vote => 1) + Vote.create!(:voteable => article, :vote => 1) + end + end + end -- libgit2 0.21.2