Commit fdb09d35e2389249959d754ffa348922ad7c5ad0
Committed by
Rodrigo Souto
1 parent
a9b65794
Exists in
master
and in
12 other branches
Fix logic readability for duplicated votes
Signed-off-by: Victor Costa <vfcosta@gmail.com>
Showing
2 changed files
with
11 additions
and
3 deletions
Show diff stats
lib/noosfero/vote_ext.rb
@@ -2,10 +2,10 @@ require_dependency 'models/vote' | @@ -2,10 +2,10 @@ require_dependency 'models/vote' | ||
2 | 2 | ||
3 | class Vote | 3 | class Vote |
4 | 4 | ||
5 | - validates_uniqueness_of :voteable_id, :scope => [:voteable_type, :voter_type, :voter_id], :if => :allow_duplicated_vote? | 5 | + validates_uniqueness_of :voteable_id, :scope => [:voteable_type, :voter_type, :voter_id], :unless => :allow_duplicate? |
6 | 6 | ||
7 | - def allow_duplicated_vote? | ||
8 | - voter.present? | 7 | + def allow_duplicate? |
8 | + voter.blank? | ||
9 | end | 9 | end |
10 | 10 | ||
11 | end | 11 | end |
test/unit/article_test.rb
@@ -2190,6 +2190,14 @@ class ArticleTest < ActiveSupport::TestCase | @@ -2190,6 +2190,14 @@ class ArticleTest < ActiveSupport::TestCase | ||
2190 | article.destroy | 2190 | article.destroy |
2191 | end | 2191 | end |
2192 | 2192 | ||
2193 | + should 'be able to vote in an article without a user' do | ||
2194 | + article = create(Article, :name => 'Test', :profile => profile, :last_changed_by => nil) | ||
2195 | + assert_difference 'article.votes_for', 2 do | ||
2196 | + Vote.create!(:voteable => article, :vote => 1) | ||
2197 | + Vote.create!(:voteable => article, :vote => 1) | ||
2198 | + end | ||
2199 | + end | ||
2200 | + | ||
2193 | should 'have can_display_media_panel with default false' do | 2201 | should 'have can_display_media_panel with default false' do |
2194 | a = Article.new | 2202 | a = Article.new |
2195 | assert !a.can_display_media_panel? | 2203 | assert !a.can_display_media_panel? |