Commit 2982832237ed39a5c48b3fb6f3fe24cc61bbb26a

Authored by Victor Costa
2 parents e56b19a7 b80d0b1a

Merge branch 'vote_not_logged_in' into stable

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
... ...