Commit 362d23e0a51611ad95c926c483bbcd2e9db54e01

Authored by Victor Costa
1 parent d2dc1474

Move to vote plugin all modifications on core related to vote_fu

(ActionItem2786)
app/models/article.rb
@@ -76,8 +76,6 @@ class Article < ActiveRecord::Base @@ -76,8 +76,6 @@ class Article < ActiveRecord::Base
76 belongs_to :translation_of, :class_name => 'Article', :foreign_key => :translation_of_id 76 belongs_to :translation_of, :class_name => 'Article', :foreign_key => :translation_of_id
77 before_destroy :rotate_translations 77 before_destroy :rotate_translations
78 78
79 - acts_as_voteable  
80 -  
81 before_create do |article| 79 before_create do |article|
82 article.published_at ||= Time.now 80 article.published_at ||= Time.now
83 if article.reference_article && !article.parent 81 if article.reference_article && !article.parent
app/models/comment.rb
@@ -35,8 +35,6 @@ class Comment < ActiveRecord::Base @@ -35,8 +35,6 @@ class Comment < ActiveRecord::Base
35 35
36 xss_terminate :only => [ :body, :title, :name ], :on => 'validation' 36 xss_terminate :only => [ :body, :title, :name ], :on => 'validation'
37 37
38 - acts_as_voteable  
39 -  
40 def comment_root 38 def comment_root
41 (reply_of && reply_of.comment_root) || self 39 (reply_of && reply_of.comment_root) || self
42 end 40 end
app/models/person.rb
@@ -81,8 +81,6 @@ class Person < Profile @@ -81,8 +81,6 @@ class Person < Profile
81 81
82 belongs_to :user, :dependent => :delete 82 belongs_to :user, :dependent => :delete
83 83
84 - acts_as_voter  
85 -  
86 def can_control_scrap?(scrap) 84 def can_control_scrap?(scrap)
87 begin 85 begin
88 !self.scraps(scrap).nil? 86 !self.scraps(scrap).nil?
plugins/vote/lib/ext/article.rb 0 → 100644
@@ -0,0 +1,7 @@ @@ -0,0 +1,7 @@
  1 +require_dependency 'article'
  2 +
  3 +class Article
  4 +
  5 + acts_as_voteable
  6 +
  7 +end
plugins/vote/lib/ext/comment.rb 0 → 100644
@@ -0,0 +1,7 @@ @@ -0,0 +1,7 @@
  1 +require_dependency 'comment'
  2 +
  3 +class Comment
  4 +
  5 + acts_as_voteable
  6 +
  7 +end
plugins/vote/lib/ext/person.rb 0 → 100644
@@ -0,0 +1,7 @@ @@ -0,0 +1,7 @@
  1 +require_dependency 'person'
  2 +
  3 +class Person
  4 +
  5 + acts_as_voter
  6 +
  7 +end
plugins/vote/test/unit/article_test.rb 0 → 100644
@@ -0,0 +1,24 @@ @@ -0,0 +1,24 @@
  1 +require 'test_helper'
  2 +
  3 +class ArticleTest < ActiveSupport::TestCase
  4 +
  5 + def setup
  6 + @profile = create_user('testing').person
  7 + end
  8 +
  9 + attr_reader :profile
  10 +
  11 + should 'vote in a article' do
  12 + article = Article.create!(:name => 'Test', :profile => profile, :last_changed_by => nil)
  13 + profile.vote(article, 5)
  14 + assert_equal 1, article.voters_who_voted.length
  15 + assert_equal 5, article.votes_total
  16 + end
  17 +
  18 + should 'be able to remove a voted article' do
  19 + article = Article.create!(:name => 'Test', :profile => profile, :last_changed_by => nil)
  20 + profile.vote(article, 5)
  21 + article.destroy
  22 + end
  23 +
  24 +end
plugins/vote/test/unit/comment_test.rb 0 → 100644
@@ -0,0 +1,59 @@ @@ -0,0 +1,59 @@
  1 +require 'test_helper'
  2 +
  3 +class CommentTest < ActiveSupport::TestCase
  4 +
  5 + should 'vote in a comment' do
  6 + comment = create_comment
  7 + person = create_user('voter').person
  8 + person.vote(comment, 5)
  9 + assert_equal 1, comment.voters_who_voted.length
  10 + assert_equal 5, comment.votes_total
  11 + end
  12 +
  13 + should 'like a comment' do
  14 + comment = create_comment
  15 + person = create_user('voter').person
  16 + assert !comment.voted_by?(person, true)
  17 + person.vote_for(comment)
  18 + assert comment.voted_by?(person, true)
  19 + assert !comment.voted_by?(person, false)
  20 + end
  21 +
  22 + should 'count voters for' do
  23 + comment = create_comment
  24 + person = create_user('voter').person
  25 + person2 = create_user('voter2').person
  26 + person3 = create_user('voter3').person
  27 + person.vote_for(comment)
  28 + person2.vote_for(comment)
  29 + person3.vote_against(comment)
  30 + assert_equal 2, comment.votes_for
  31 + end
  32 +
  33 + should 'count votes againts' do
  34 + comment = create_comment
  35 + person = create_user('voter').person
  36 + person2 = create_user('voter2').person
  37 + person3 = create_user('voter3').person
  38 + person.vote_against(comment)
  39 + person2.vote_against(comment)
  40 + person3.vote_for(comment)
  41 + assert_equal 2, comment.votes_against
  42 + end
  43 +
  44 + should 'be able to remove a voted comment' do
  45 + comment = create_comment
  46 + person = create_user('voter').person
  47 + person.vote(comment, 5)
  48 + comment.destroy
  49 + end
  50 +
  51 + private
  52 +
  53 + def create_comment(args = {})
  54 + owner = create_user('testuser').person
  55 + article = create(TextileArticle, :profile_id => owner.id)
  56 + create(Comment, { :name => 'foo', :email => 'foo@example.com', :source => article }.merge(args))
  57 + end
  58 +
  59 +end
plugins/vote/test/unit/person_test.rb 0 → 100644
@@ -0,0 +1,134 @@ @@ -0,0 +1,134 @@
  1 +require 'test_helper'
  2 +
  3 +class PersonTest < ActiveSupport::TestCase
  4 +
  5 + should 'vote in a comment with value greater than 1' do
  6 + comment = fast_create(Comment)
  7 + person = fast_create(Person)
  8 +
  9 + person.vote(comment, 5)
  10 + assert_equal 1, person.vote_count
  11 + assert_equal 5, person.votes.first.vote
  12 + assert person.voted_on?(comment)
  13 + end
  14 +
  15 + should 'vote in a comment with value lesser than -1' do
  16 + comment = fast_create(Comment)
  17 + person = fast_create(Person)
  18 +
  19 + person.vote(comment, -5)
  20 + assert_equal 1, person.vote_count
  21 + assert_equal -5, person.votes.first.vote
  22 + end
  23 +
  24 + should 'vote for a comment' do
  25 + comment = fast_create(Comment)
  26 + person = fast_create(Person)
  27 +
  28 + assert !person.voted_for?(comment)
  29 + person.vote_for(comment)
  30 + assert person.voted_for?(comment)
  31 + assert !person.voted_against?(comment)
  32 + end
  33 +
  34 + should 'vote against a comment' do
  35 + comment = fast_create(Comment)
  36 + person = fast_create(Person)
  37 +
  38 + assert !person.voted_against?(comment)
  39 + person.vote_against(comment)
  40 + assert !person.voted_for?(comment)
  41 + assert person.voted_against?(comment)
  42 + end
  43 +
  44 + should 'do not vote against a comment twice' do
  45 + comment = fast_create(Comment)
  46 + person = fast_create(Person)
  47 +
  48 + assert person.vote_against(comment)
  49 + assert !person.vote_against(comment)
  50 + end
  51 +
  52 + should 'do not vote for a comment twice' do
  53 + comment = fast_create(Comment)
  54 + person = fast_create(Person)
  55 +
  56 + assert person.vote_for(comment)
  57 + assert !person.vote_for(comment)
  58 + end
  59 +
  60 + should 'not vote against a voted for comment' do
  61 + comment = fast_create(Comment)
  62 + person = fast_create(Person)
  63 +
  64 + person.vote_for(comment)
  65 + person.vote_against(comment)
  66 + assert person.voted_for?(comment)
  67 + assert !person.voted_against?(comment)
  68 + end
  69 +
  70 + should 'not vote for a voted against comment' do
  71 + comment = fast_create(Comment)
  72 + person = fast_create(Person)
  73 +
  74 + person.vote_against(comment)
  75 + person.vote_for(comment)
  76 + assert !person.voted_for?(comment)
  77 + assert person.voted_against?(comment)
  78 + end
  79 +
  80 + should 'undo a vote for a comment' do
  81 + comment = fast_create(Comment)
  82 + person = fast_create(Person)
  83 +
  84 + person.vote_for(comment)
  85 + assert person.voted_for?(comment)
  86 + person.votes.for_voteable(comment).destroy_all
  87 + assert !person.voted_for?(comment)
  88 + end
  89 +
  90 + should 'count comments voted' do
  91 + comment = fast_create(Comment)
  92 + person = fast_create(Person)
  93 +
  94 + comment2 = fast_create(Comment)
  95 + comment3 = fast_create(Comment)
  96 + person.vote_for(comment)
  97 + person.vote_for(comment2)
  98 + person.vote_against(comment3)
  99 + assert_equal 3, person.vote_count
  100 + assert_equal 2, person.vote_count(true)
  101 + assert_equal 1, person.vote_count(false)
  102 + end
  103 +
  104 + should 'vote in a article with value greater than 1' do
  105 + article = fast_create(Article)
  106 + person = fast_create(Person)
  107 +
  108 + person.vote(article, 5)
  109 + assert_equal 1, person.vote_count
  110 + assert_equal 5, person.votes.first.vote
  111 + assert person.voted_on?(article)
  112 + end
  113 +
  114 + should 'vote for a article' do
  115 + article = fast_create(Article)
  116 + person = fast_create(Person)
  117 +
  118 + assert !person.voted_for?(article)
  119 + person.vote_for(article)
  120 + assert person.voted_for?(article)
  121 + assert !person.voted_against?(article)
  122 + end
  123 +
  124 + should 'vote against a article' do
  125 + article = fast_create(Article)
  126 + person = fast_create(Person)
  127 +
  128 + assert !person.voted_against?(article)
  129 + person.vote_against(article)
  130 + assert !person.voted_for?(article)
  131 + assert person.voted_against?(article)
  132 + end
  133 +
  134 +end
test/unit/article_test.rb
@@ -1744,17 +1744,4 @@ class ArticleTest &lt; ActiveSupport::TestCase @@ -1744,17 +1744,4 @@ class ArticleTest &lt; ActiveSupport::TestCase
1744 assert_nil article.author_id 1744 assert_nil article.author_id
1745 end 1745 end
1746 1746
1747 - should 'vote in a article' do  
1748 - article = Article.create!(:name => 'Test', :profile => profile, :last_changed_by => nil)  
1749 - profile.vote(article, 5)  
1750 - assert_equal 1, article.voters_who_voted.length  
1751 - assert_equal 5, article.votes_total  
1752 - end  
1753 -  
1754 - should 'be able to remove a voted article' do  
1755 - article = Article.create!(:name => 'Test', :profile => profile, :last_changed_by => nil)  
1756 - profile.vote(article, 5)  
1757 - article.destroy  
1758 - end  
1759 -  
1760 end 1747 end
test/unit/comment_test.rb
@@ -685,52 +685,6 @@ class CommentTest &lt; ActiveSupport::TestCase @@ -685,52 +685,6 @@ class CommentTest &lt; ActiveSupport::TestCase
685 assert_equivalent [c1,c4], Comment.without_reply 685 assert_equivalent [c1,c4], Comment.without_reply
686 end 686 end
687 687
688 - should 'vote in a comment' do  
689 - comment = create_comment  
690 - person = create_user('voter').person  
691 - person.vote(comment, 5)  
692 - assert_equal 1, comment.voters_who_voted.length  
693 - assert_equal 5, comment.votes_total  
694 - end  
695 -  
696 - should 'like a comment' do  
697 - comment = create_comment  
698 - person = create_user('voter').person  
699 - assert !comment.voted_by?(person, true)  
700 - person.vote_for(comment)  
701 - assert comment.voted_by?(person, true)  
702 - assert !comment.voted_by?(person, false)  
703 - end  
704 -  
705 - should 'count voters for' do  
706 - comment = create_comment  
707 - person = create_user('voter').person  
708 - person2 = create_user('voter2').person  
709 - person3 = create_user('voter3').person  
710 - person.vote_for(comment)  
711 - person2.vote_for(comment)  
712 - person3.vote_against(comment)  
713 - assert_equal 2, comment.votes_for  
714 - end  
715 -  
716 - should 'count votes againts' do  
717 - comment = create_comment  
718 - person = create_user('voter').person  
719 - person2 = create_user('voter2').person  
720 - person3 = create_user('voter3').person  
721 - person.vote_against(comment)  
722 - person2.vote_against(comment)  
723 - person3.vote_for(comment)  
724 - assert_equal 2, comment.votes_against  
725 - end  
726 -  
727 - should 'be able to remove a voted comment' do  
728 - comment = create_comment  
729 - person = create_user('voter').person  
730 - person.vote(comment, 5)  
731 - comment.destroy  
732 - end  
733 -  
734 private 688 private
735 689
736 def create_comment(args = {}) 690 def create_comment(args = {})
test/unit/person_test.rb
@@ -1335,133 +1335,4 @@ class PersonTest &lt; ActiveSupport::TestCase @@ -1335,133 +1335,4 @@ class PersonTest &lt; ActiveSupport::TestCase
1335 assert_includes non_abusers, not_abuser 1335 assert_includes non_abusers, not_abuser
1336 end 1336 end
1337 1337
1338 - should 'vote in a comment with value greater than 1' do  
1339 - comment = fast_create(Comment)  
1340 - person = fast_create(Person)  
1341 -  
1342 - person.vote(comment, 5)  
1343 - assert_equal 1, person.vote_count  
1344 - assert_equal 5, person.votes.first.vote  
1345 - assert person.voted_on?(comment)  
1346 - end  
1347 -  
1348 - should 'vote in a comment with value lesser than -1' do  
1349 - comment = fast_create(Comment)  
1350 - person = fast_create(Person)  
1351 -  
1352 - person.vote(comment, -5)  
1353 - assert_equal 1, person.vote_count  
1354 - assert_equal -5, person.votes.first.vote  
1355 - end  
1356 -  
1357 - should 'vote for a comment' do  
1358 - comment = fast_create(Comment)  
1359 - person = fast_create(Person)  
1360 -  
1361 - assert !person.voted_for?(comment)  
1362 - person.vote_for(comment)  
1363 - assert person.voted_for?(comment)  
1364 - assert !person.voted_against?(comment)  
1365 - end  
1366 -  
1367 - should 'vote against a comment' do  
1368 - comment = fast_create(Comment)  
1369 - person = fast_create(Person)  
1370 -  
1371 - assert !person.voted_against?(comment)  
1372 - person.vote_against(comment)  
1373 - assert !person.voted_for?(comment)  
1374 - assert person.voted_against?(comment)  
1375 - end  
1376 -  
1377 - should 'do not vote against a comment twice' do  
1378 - comment = fast_create(Comment)  
1379 - person = fast_create(Person)  
1380 -  
1381 - assert person.vote_against(comment)  
1382 - assert !person.vote_against(comment)  
1383 - end  
1384 -  
1385 - should 'do not vote for a comment twice' do  
1386 - comment = fast_create(Comment)  
1387 - person = fast_create(Person)  
1388 -  
1389 - assert person.vote_for(comment)  
1390 - assert !person.vote_for(comment)  
1391 - end  
1392 -  
1393 - should 'not vote against a voted for comment' do  
1394 - comment = fast_create(Comment)  
1395 - person = fast_create(Person)  
1396 -  
1397 - person.vote_for(comment)  
1398 - person.vote_against(comment)  
1399 - assert person.voted_for?(comment)  
1400 - assert !person.voted_against?(comment)  
1401 - end  
1402 -  
1403 - should 'not vote for a voted against comment' do  
1404 - comment = fast_create(Comment)  
1405 - person = fast_create(Person)  
1406 -  
1407 - person.vote_against(comment)  
1408 - person.vote_for(comment)  
1409 - assert !person.voted_for?(comment)  
1410 - assert person.voted_against?(comment)  
1411 - end  
1412 -  
1413 - should 'undo a vote for a comment' do  
1414 - comment = fast_create(Comment)  
1415 - person = fast_create(Person)  
1416 -  
1417 - person.vote_for(comment)  
1418 - assert person.voted_for?(comment)  
1419 - person.votes.for_voteable(comment).destroy_all  
1420 - assert !person.voted_for?(comment)  
1421 - end  
1422 -  
1423 - should 'count comments voted' do  
1424 - comment = fast_create(Comment)  
1425 - person = fast_create(Person)  
1426 -  
1427 - comment2 = fast_create(Comment)  
1428 - comment3 = fast_create(Comment)  
1429 - person.vote_for(comment)  
1430 - person.vote_for(comment2)  
1431 - person.vote_against(comment3)  
1432 - assert_equal 3, person.vote_count  
1433 - assert_equal 2, person.vote_count(true)  
1434 - assert_equal 1, person.vote_count(false)  
1435 - end  
1436 -  
1437 - should 'vote in a article with value greater than 1' do  
1438 - article = fast_create(Article)  
1439 - person = fast_create(Person)  
1440 -  
1441 - person.vote(article, 5)  
1442 - assert_equal 1, person.vote_count  
1443 - assert_equal 5, person.votes.first.vote  
1444 - assert person.voted_on?(article)  
1445 - end  
1446 -  
1447 - should 'vote for a article' do  
1448 - article = fast_create(Article)  
1449 - person = fast_create(Person)  
1450 -  
1451 - assert !person.voted_for?(article)  
1452 - person.vote_for(article)  
1453 - assert person.voted_for?(article)  
1454 - assert !person.voted_against?(article)  
1455 - end  
1456 -  
1457 - should 'vote against a article' do  
1458 - article = fast_create(Article)  
1459 - person = fast_create(Person)  
1460 -  
1461 - assert !person.voted_against?(article)  
1462 - person.vote_against(article)  
1463 - assert !person.voted_for?(article)  
1464 - assert person.voted_against?(article)  
1465 - end  
1466 -  
1467 end 1338 end