From fdb09d35e2389249959d754ffa348922ad7c5ad0 Mon Sep 17 00:00:00 2001 From: Marcos Ronaldo Date: Wed, 20 Jan 2016 16:00:29 -0200 Subject: [PATCH] Fix logic readability for duplicated votes --- lib/noosfero/vote_ext.rb | 6 +++--- test/unit/article_test.rb | 8 ++++++++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/noosfero/vote_ext.rb b/lib/noosfero/vote_ext.rb index be349ca..4d1e601 100644 --- a/lib/noosfero/vote_ext.rb +++ b/lib/noosfero/vote_ext.rb @@ -2,10 +2,10 @@ require_dependency 'models/vote' class Vote - validates_uniqueness_of :voteable_id, :scope => [:voteable_type, :voter_type, :voter_id], :if => :allow_duplicated_vote? + validates_uniqueness_of :voteable_id, :scope => [:voteable_type, :voter_type, :voter_id], :unless => :allow_duplicate? - def allow_duplicated_vote? - voter.present? + def allow_duplicate? + voter.blank? end end diff --git a/test/unit/article_test.rb b/test/unit/article_test.rb index 633ca6b..13aa81b 100644 --- a/test/unit/article_test.rb +++ b/test/unit/article_test.rb @@ -2190,6 +2190,14 @@ 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 + should 'have can_display_media_panel with default false' do a = Article.new assert !a.can_display_media_panel? -- libgit2 0.21.2