Commit b80d0b1a460c1718ea5ff438d878121219da29ef
1 parent
6edafc75
Exists in
theme-brasil-digital-from-staging
and in
9 other branches
vote_plugin: allow anonymous votes
Showing
2 changed files
with
13 additions
and
1 deletions
Show diff stats
plugins/vote/lib/ext/vote.rb
| ... | ... | @@ -2,6 +2,10 @@ require_dependency 'models/vote' |
| 2 | 2 | |
| 3 | 3 | class Vote |
| 4 | 4 | |
| 5 | - validates_uniqueness_of :voteable_id, :scope => [:voteable_type, :voter_type, :voter_id] | |
| 5 | + validates_uniqueness_of :voteable_id, :scope => [:voteable_type, :voter_type, :voter_id], :if => :allow_duplicated_vote? | |
| 6 | + | |
| 7 | + def allow_duplicated_vote? | |
| 8 | + voter.present? | |
| 9 | + end | |
| 6 | 10 | |
| 7 | 11 | end | ... | ... |
plugins/vote/test/unit/article_test.rb
| ... | ... | @@ -21,4 +21,12 @@ class ArticleTest < ActiveSupport::TestCase |
| 21 | 21 | article.destroy |
| 22 | 22 | end |
| 23 | 23 | |
| 24 | + should 'be able to vote in an article without a user' do | |
| 25 | + article = create(Article, :name => 'Test', :profile => profile, :last_changed_by => nil) | |
| 26 | + assert_difference 'article.votes_for', 2 do | |
| 27 | + Vote.create!(:voteable => article, :vote => 1) | |
| 28 | + Vote.create!(:voteable => article, :vote => 1) | |
| 29 | + end | |
| 30 | + end | |
| 31 | + | |
| 24 | 32 | end | ... | ... |