diff --git a/app/models/article.rb b/app/models/article.rb index 470959f..4f564d8 100644 --- a/app/models/article.rb +++ b/app/models/article.rb @@ -76,8 +76,6 @@ class Article < ActiveRecord::Base belongs_to :translation_of, :class_name => 'Article', :foreign_key => :translation_of_id before_destroy :rotate_translations - acts_as_voteable - before_create do |article| article.published_at ||= Time.now if article.reference_article && !article.parent diff --git a/app/models/comment.rb b/app/models/comment.rb index efe03a3..f5dd826 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -35,8 +35,6 @@ class Comment < ActiveRecord::Base xss_terminate :only => [ :body, :title, :name ], :on => 'validation' - acts_as_voteable - def comment_root (reply_of && reply_of.comment_root) || self end diff --git a/app/models/person.rb b/app/models/person.rb index ca22982..8729394 100644 --- a/app/models/person.rb +++ b/app/models/person.rb @@ -81,8 +81,6 @@ class Person < Profile belongs_to :user, :dependent => :delete - acts_as_voter - def can_control_scrap?(scrap) begin !self.scraps(scrap).nil? diff --git a/plugins/vote/lib/ext/article.rb b/plugins/vote/lib/ext/article.rb new file mode 100644 index 0000000..dab91a0 --- /dev/null +++ b/plugins/vote/lib/ext/article.rb @@ -0,0 +1,7 @@ +require_dependency 'article' + +class Article + + acts_as_voteable + +end diff --git a/plugins/vote/lib/ext/comment.rb b/plugins/vote/lib/ext/comment.rb new file mode 100644 index 0000000..2cb6be6 --- /dev/null +++ b/plugins/vote/lib/ext/comment.rb @@ -0,0 +1,7 @@ +require_dependency 'comment' + +class Comment + + acts_as_voteable + +end diff --git a/plugins/vote/lib/ext/person.rb b/plugins/vote/lib/ext/person.rb new file mode 100644 index 0000000..0b3f6a9 --- /dev/null +++ b/plugins/vote/lib/ext/person.rb @@ -0,0 +1,7 @@ +require_dependency 'person' + +class Person + + acts_as_voter + +end diff --git a/plugins/vote/test/unit/article_test.rb b/plugins/vote/test/unit/article_test.rb new file mode 100644 index 0000000..7a4a0c6 --- /dev/null +++ b/plugins/vote/test/unit/article_test.rb @@ -0,0 +1,24 @@ +require 'test_helper' + +class ArticleTest < ActiveSupport::TestCase + + def setup + @profile = create_user('testing').person + end + + attr_reader :profile + + should 'vote in a article' do + article = Article.create!(:name => 'Test', :profile => profile, :last_changed_by => nil) + profile.vote(article, 5) + assert_equal 1, article.voters_who_voted.length + assert_equal 5, article.votes_total + end + + should 'be able to remove a voted article' do + article = Article.create!(:name => 'Test', :profile => profile, :last_changed_by => nil) + profile.vote(article, 5) + article.destroy + end + +end diff --git a/plugins/vote/test/unit/comment_test.rb b/plugins/vote/test/unit/comment_test.rb new file mode 100644 index 0000000..355ee64 --- /dev/null +++ b/plugins/vote/test/unit/comment_test.rb @@ -0,0 +1,59 @@ +require 'test_helper' + +class CommentTest < ActiveSupport::TestCase + + should 'vote in a comment' do + comment = create_comment + person = create_user('voter').person + person.vote(comment, 5) + assert_equal 1, comment.voters_who_voted.length + assert_equal 5, comment.votes_total + end + + should 'like a comment' do + comment = create_comment + person = create_user('voter').person + assert !comment.voted_by?(person, true) + person.vote_for(comment) + assert comment.voted_by?(person, true) + assert !comment.voted_by?(person, false) + end + + should 'count voters for' do + comment = create_comment + person = create_user('voter').person + person2 = create_user('voter2').person + person3 = create_user('voter3').person + person.vote_for(comment) + person2.vote_for(comment) + person3.vote_against(comment) + assert_equal 2, comment.votes_for + end + + should 'count votes againts' do + comment = create_comment + person = create_user('voter').person + person2 = create_user('voter2').person + person3 = create_user('voter3').person + person.vote_against(comment) + person2.vote_against(comment) + person3.vote_for(comment) + assert_equal 2, comment.votes_against + end + + should 'be able to remove a voted comment' do + comment = create_comment + person = create_user('voter').person + person.vote(comment, 5) + comment.destroy + end + + private + + def create_comment(args = {}) + owner = create_user('testuser').person + article = create(TextileArticle, :profile_id => owner.id) + create(Comment, { :name => 'foo', :email => 'foo@example.com', :source => article }.merge(args)) + end + +end diff --git a/plugins/vote/test/unit/person_test.rb b/plugins/vote/test/unit/person_test.rb new file mode 100644 index 0000000..99bb4e2 --- /dev/null +++ b/plugins/vote/test/unit/person_test.rb @@ -0,0 +1,134 @@ +require 'test_helper' + +class PersonTest < ActiveSupport::TestCase + + should 'vote in a comment with value greater than 1' do + comment = fast_create(Comment) + person = fast_create(Person) + + person.vote(comment, 5) + assert_equal 1, person.vote_count + assert_equal 5, person.votes.first.vote + assert person.voted_on?(comment) + end + + should 'vote in a comment with value lesser than -1' do + comment = fast_create(Comment) + person = fast_create(Person) + + person.vote(comment, -5) + assert_equal 1, person.vote_count + assert_equal -5, person.votes.first.vote + end + + should 'vote for a comment' do + comment = fast_create(Comment) + person = fast_create(Person) + + assert !person.voted_for?(comment) + person.vote_for(comment) + assert person.voted_for?(comment) + assert !person.voted_against?(comment) + end + + should 'vote against a comment' do + comment = fast_create(Comment) + person = fast_create(Person) + + assert !person.voted_against?(comment) + person.vote_against(comment) + assert !person.voted_for?(comment) + assert person.voted_against?(comment) + end + + should 'do not vote against a comment twice' do + comment = fast_create(Comment) + person = fast_create(Person) + + assert person.vote_against(comment) + assert !person.vote_against(comment) + end + + should 'do not vote for a comment twice' do + comment = fast_create(Comment) + person = fast_create(Person) + + assert person.vote_for(comment) + assert !person.vote_for(comment) + end + + should 'not vote against a voted for comment' do + comment = fast_create(Comment) + person = fast_create(Person) + + person.vote_for(comment) + person.vote_against(comment) + assert person.voted_for?(comment) + assert !person.voted_against?(comment) + end + + should 'not vote for a voted against comment' do + comment = fast_create(Comment) + person = fast_create(Person) + + person.vote_against(comment) + person.vote_for(comment) + assert !person.voted_for?(comment) + assert person.voted_against?(comment) + end + + should 'undo a vote for a comment' do + comment = fast_create(Comment) + person = fast_create(Person) + + person.vote_for(comment) + assert person.voted_for?(comment) + person.votes.for_voteable(comment).destroy_all + assert !person.voted_for?(comment) + end + + should 'count comments voted' do + comment = fast_create(Comment) + person = fast_create(Person) + + comment2 = fast_create(Comment) + comment3 = fast_create(Comment) + person.vote_for(comment) + person.vote_for(comment2) + person.vote_against(comment3) + assert_equal 3, person.vote_count + assert_equal 2, person.vote_count(true) + assert_equal 1, person.vote_count(false) + end + + should 'vote in a article with value greater than 1' do + article = fast_create(Article) + person = fast_create(Person) + + person.vote(article, 5) + assert_equal 1, person.vote_count + assert_equal 5, person.votes.first.vote + assert person.voted_on?(article) + end + + should 'vote for a article' do + article = fast_create(Article) + person = fast_create(Person) + + assert !person.voted_for?(article) + person.vote_for(article) + assert person.voted_for?(article) + assert !person.voted_against?(article) + end + + should 'vote against a article' do + article = fast_create(Article) + person = fast_create(Person) + + assert !person.voted_against?(article) + person.vote_against(article) + assert !person.voted_for?(article) + assert person.voted_against?(article) + end + +end diff --git a/test/unit/article_test.rb b/test/unit/article_test.rb index be5a549..6838b6c 100644 --- a/test/unit/article_test.rb +++ b/test/unit/article_test.rb @@ -1744,17 +1744,4 @@ class ArticleTest < ActiveSupport::TestCase assert_nil article.author_id end - should 'vote in a article' do - article = Article.create!(:name => 'Test', :profile => profile, :last_changed_by => nil) - profile.vote(article, 5) - assert_equal 1, article.voters_who_voted.length - assert_equal 5, article.votes_total - end - - should 'be able to remove a voted article' do - article = Article.create!(:name => 'Test', :profile => profile, :last_changed_by => nil) - profile.vote(article, 5) - article.destroy - end - end diff --git a/test/unit/comment_test.rb b/test/unit/comment_test.rb index 080da07..fdd48f0 100644 --- a/test/unit/comment_test.rb +++ b/test/unit/comment_test.rb @@ -685,52 +685,6 @@ class CommentTest < ActiveSupport::TestCase assert_equivalent [c1,c4], Comment.without_reply end - should 'vote in a comment' do - comment = create_comment - person = create_user('voter').person - person.vote(comment, 5) - assert_equal 1, comment.voters_who_voted.length - assert_equal 5, comment.votes_total - end - - should 'like a comment' do - comment = create_comment - person = create_user('voter').person - assert !comment.voted_by?(person, true) - person.vote_for(comment) - assert comment.voted_by?(person, true) - assert !comment.voted_by?(person, false) - end - - should 'count voters for' do - comment = create_comment - person = create_user('voter').person - person2 = create_user('voter2').person - person3 = create_user('voter3').person - person.vote_for(comment) - person2.vote_for(comment) - person3.vote_against(comment) - assert_equal 2, comment.votes_for - end - - should 'count votes againts' do - comment = create_comment - person = create_user('voter').person - person2 = create_user('voter2').person - person3 = create_user('voter3').person - person.vote_against(comment) - person2.vote_against(comment) - person3.vote_for(comment) - assert_equal 2, comment.votes_against - end - - should 'be able to remove a voted comment' do - comment = create_comment - person = create_user('voter').person - person.vote(comment, 5) - comment.destroy - end - private def create_comment(args = {}) diff --git a/test/unit/person_test.rb b/test/unit/person_test.rb index 6e6df78..610a81f 100644 --- a/test/unit/person_test.rb +++ b/test/unit/person_test.rb @@ -1335,133 +1335,4 @@ class PersonTest < ActiveSupport::TestCase assert_includes non_abusers, not_abuser end - should 'vote in a comment with value greater than 1' do - comment = fast_create(Comment) - person = fast_create(Person) - - person.vote(comment, 5) - assert_equal 1, person.vote_count - assert_equal 5, person.votes.first.vote - assert person.voted_on?(comment) - end - - should 'vote in a comment with value lesser than -1' do - comment = fast_create(Comment) - person = fast_create(Person) - - person.vote(comment, -5) - assert_equal 1, person.vote_count - assert_equal -5, person.votes.first.vote - end - - should 'vote for a comment' do - comment = fast_create(Comment) - person = fast_create(Person) - - assert !person.voted_for?(comment) - person.vote_for(comment) - assert person.voted_for?(comment) - assert !person.voted_against?(comment) - end - - should 'vote against a comment' do - comment = fast_create(Comment) - person = fast_create(Person) - - assert !person.voted_against?(comment) - person.vote_against(comment) - assert !person.voted_for?(comment) - assert person.voted_against?(comment) - end - - should 'do not vote against a comment twice' do - comment = fast_create(Comment) - person = fast_create(Person) - - assert person.vote_against(comment) - assert !person.vote_against(comment) - end - - should 'do not vote for a comment twice' do - comment = fast_create(Comment) - person = fast_create(Person) - - assert person.vote_for(comment) - assert !person.vote_for(comment) - end - - should 'not vote against a voted for comment' do - comment = fast_create(Comment) - person = fast_create(Person) - - person.vote_for(comment) - person.vote_against(comment) - assert person.voted_for?(comment) - assert !person.voted_against?(comment) - end - - should 'not vote for a voted against comment' do - comment = fast_create(Comment) - person = fast_create(Person) - - person.vote_against(comment) - person.vote_for(comment) - assert !person.voted_for?(comment) - assert person.voted_against?(comment) - end - - should 'undo a vote for a comment' do - comment = fast_create(Comment) - person = fast_create(Person) - - person.vote_for(comment) - assert person.voted_for?(comment) - person.votes.for_voteable(comment).destroy_all - assert !person.voted_for?(comment) - end - - should 'count comments voted' do - comment = fast_create(Comment) - person = fast_create(Person) - - comment2 = fast_create(Comment) - comment3 = fast_create(Comment) - person.vote_for(comment) - person.vote_for(comment2) - person.vote_against(comment3) - assert_equal 3, person.vote_count - assert_equal 2, person.vote_count(true) - assert_equal 1, person.vote_count(false) - end - - should 'vote in a article with value greater than 1' do - article = fast_create(Article) - person = fast_create(Person) - - person.vote(article, 5) - assert_equal 1, person.vote_count - assert_equal 5, person.votes.first.vote - assert person.voted_on?(article) - end - - should 'vote for a article' do - article = fast_create(Article) - person = fast_create(Person) - - assert !person.voted_for?(article) - person.vote_for(article) - assert person.voted_for?(article) - assert !person.voted_against?(article) - end - - should 'vote against a article' do - article = fast_create(Article) - person = fast_create(Person) - - assert !person.voted_against?(article) - person.vote_against(article) - assert !person.voted_for?(article) - assert person.voted_against?(article) - end - end -- libgit2 0.21.2