Commit 2982832237ed39a5c48b3fb6f3fe24cc61bbb26a
Exists in
theme-brasil-digital-from-staging
and in
9 other branches
Merge branch 'vote_not_logged_in' into stable
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 | ... | ... |