[noosfero/noosfero][master] 2 commits: Move vote infra from plugin to core

Leandro Nunes gitlab at gitlab.com
Tue Jun 2 13:56:38 BRT 2015


Leandro Nunes pushed to branch master at Noosfero / noosfero


Commits:
f6c9fd61 by Victor Costa at 2015-06-02T09:43:54Z
Move vote infra from plugin to core

- - - - -
509ae63b by Leandro Nunes at 2015-06-02T16:56:28Z
Merge branch 'vote_infra' into 'master'

Move vote infra from plugin to core

Move vote infra from plugin to core to avoid dependencies between plugins and allow features that uses the vote_fu plugin to be added in noosfero core.

See merge request !589

- - - - -


12 changed files:

- app/models/article.rb
- app/models/comment.rb
- app/models/person.rb
- − plugins/vote/lib/ext/article.rb
- − plugins/vote/lib/ext/comment.rb
- − plugins/vote/lib/ext/person.rb
- − plugins/vote/test/unit/article_test.rb
- − plugins/vote/test/unit/comment_test.rb
- − plugins/vote/test/unit/person_test.rb
- test/unit/article_test.rb
- test/unit/comment_test.rb
- test/unit/person_test.rb


Changes:

=====================================
app/models/article.rb
=====================================
--- a/app/models/article.rb
+++ b/app/models/article.rb
@@ -96,6 +96,8 @@ 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


=====================================
app/models/comment.rb
=====================================
--- a/app/models/comment.rb
+++ b/app/models/comment.rb
@@ -37,6 +37,8 @@ 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


=====================================
app/models/person.rb
=====================================
--- a/app/models/person.rb
+++ b/app/models/person.rb
@@ -103,6 +103,8 @@ roles] }
 
   belongs_to :user, :dependent => :delete
 
+  acts_as_voter
+
   def can_change_homepage?
     !environment.enabled?('cant_change_homepage') || is_admin?
   end


=====================================
plugins/vote/lib/ext/article.rb deleted
=====================================
--- a/plugins/vote/lib/ext/article.rb
+++ /dev/null
@@ -1,7 +0,0 @@
-require_dependency 'article'
-
-class Article
-
-  acts_as_voteable
-
-end


=====================================
plugins/vote/lib/ext/comment.rb deleted
=====================================
--- a/plugins/vote/lib/ext/comment.rb
+++ /dev/null
@@ -1,7 +0,0 @@
-require_dependency 'comment'
-
-class Comment
-
-  acts_as_voteable
-
-end


=====================================
plugins/vote/lib/ext/person.rb deleted
=====================================
--- a/plugins/vote/lib/ext/person.rb
+++ /dev/null
@@ -1,7 +0,0 @@
-require_dependency 'person'
-
-class Person
-
-  acts_as_voter
-
-end


=====================================
plugins/vote/test/unit/article_test.rb deleted
=====================================
--- a/plugins/vote/test/unit/article_test.rb
+++ /dev/null
@@ -1,24 +0,0 @@
-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 = create(Article, :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 = create(Article, :name => 'Test', :profile => profile, :last_changed_by => nil)
-    profile.vote(article, 5)
-    article.destroy
-  end
-
-end


=====================================
plugins/vote/test/unit/comment_test.rb deleted
=====================================
--- a/plugins/vote/test/unit/comment_test.rb
+++ /dev/null
@@ -1,59 +0,0 @@
-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 at example.com', :source => article }.merge(args))
-  end
-
-end


=====================================
plugins/vote/test/unit/person_test.rb deleted
=====================================
--- a/plugins/vote/test/unit/person_test.rb
+++ /dev/null
@@ -1,134 +0,0 @@
-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


=====================================
test/unit/article_test.rb
=====================================
--- a/test/unit/article_test.rb
+++ b/test/unit/article_test.rb
@@ -2154,4 +2154,17 @@ class ArticleTest < ActiveSupport::TestCase
     assert_equivalent [a1,a2], Article.display_filter(nil, user)
   end
 
+  should 'vote in a article' do
+    article = create(Article, :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 = create(Article, :name => 'Test', :profile => profile, :last_changed_by => nil)
+    profile.vote(article, 5)
+    article.destroy
+  end
+
 end


=====================================
test/unit/comment_test.rb
=====================================
--- a/test/unit/comment_test.rb
+++ b/test/unit/comment_test.rb
@@ -703,6 +703,52 @@ 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 = {})


=====================================
test/unit/person_test.rb
=====================================
--- a/test/unit/person_test.rb
+++ b/test/unit/person_test.rb
@@ -1638,4 +1638,133 @@ class PersonTest < ActiveSupport::TestCase
     assert_equal false, person.follows?(nil)
   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



View it on GitLab: https://gitlab.com/noosfero/noosfero/compare/f9f5164a20a2ebca419d30af1331af89db2a79fe...509ae63b798bb59ad87c90f778b182e900b047dc
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listas.softwarelivre.org/pipermail/noosfero-dev/attachments/20150602/db1087f9/attachment-0001.html>


More information about the Noosfero-dev mailing list