Commit e5ffe7f3f7d21e836ed5de4fb7357aa946c71f82

Authored by Victor Costa
1 parent 724a52cb

Added more tests to comment group plugin

plugins/comment_group/lib/comment_group_plugin/macros/allow_comment.rb
... ... @@ -11,7 +11,6 @@ class CommentGroupPlugin::AllowComment < Noosfero::Plugin::Macro
11 11 :css_files => 'comment_group.css' }
12 12 end
13 13  
14   - #FIXME Make this test
15 14 def parse(params, inner_html, source)
16 15 group_id = params[:group_id].to_i
17 16 article = source
... ...
plugins/comment_group/lib/ext/article.rb
... ... @@ -2,13 +2,10 @@ require_dependency 'article'
2 2  
3 3 class Article
4 4  
5   - #FIXME make this test
6 5 has_many :group_comments, :class_name => 'Comment', :foreign_key => 'source_id', :dependent => :destroy, :order => 'created_at asc', :conditions => [ 'group_id IS NOT NULL']
7 6  
8   - #FIXME make this test
9 7 validate :not_empty_group_comments_removed
10 8  
11   - #FIXME make this test
12 9 def not_empty_group_comments_removed
13 10 if body
14 11 groups_with_comments = group_comments.collect {|comment| comment.group_id}.uniq
... ...
plugins/comment_group/test/functional/comment_group_plugin_profile_controller_test.rb
1   -require File.dirname(__FILE__) + '/../../../../test/test_helper'
  1 +require File.dirname(__FILE__) + '/../test_helper'
2 2 require File.dirname(__FILE__) + '/../../controllers/profile/comment_group_plugin_profile_controller'
3 3  
4 4 # Re-raise errors caught by the controller.
... ...
plugins/comment_group/test/functional/comment_group_plugin_public_controller_test.rb
1   -require File.dirname(__FILE__) + '/../../../../test/test_helper'
  1 +require File.dirname(__FILE__) + '/../test_helper'
2 2 require File.dirname(__FILE__) + '/../../controllers/public/comment_group_plugin_public_controller'
3 3  
4 4 # Re-raise errors caught by the controller.
... ...
plugins/comment_group/test/functional/content_viewer_controller_test.rb 0 → 100644
... ... @@ -0,0 +1,28 @@
  1 +require File.dirname(__FILE__) + '/../test_helper'
  2 +
  3 +class ContentViewerController
  4 + append_view_path File.join(File.dirname(__FILE__) + '/../../views')
  5 + def rescue_action(e)
  6 + raise e
  7 + end
  8 +end
  9 +
  10 +class ContentViewerControllerTest < ActionController::TestCase
  11 +
  12 + def setup
  13 + @profile = fast_create(Community)
  14 + @page = fast_create(Article, :profile_id => @profile.id, :body => "<div class=\"macro\" data-macro-group_id=\"1\" data-macro='comment_group_plugin/allow_comment' ></div>")
  15 + @environment = Environment.default
  16 + @environment.enable_plugin(CommentGroupPlugin)
  17 + end
  18 +
  19 + attr_reader :page
  20 +
  21 + should 'parse article body and render comment group view' do
  22 + comment1 = fast_create(Comment, :group_id => 1, :source_id => page.id)
  23 + get :view_page, @page.url
  24 + assert_tag 'div', :attributes => {:class => 'comment_group_1'}
  25 + assert_tag 'div', :attributes => {:id => 'comments_group_count_1'}
  26 + end
  27 +
  28 +end
... ...
plugins/comment_group/test/test_helper.rb 0 → 100644
... ... @@ -0,0 +1 @@
  1 +require File.dirname(__FILE__) + '/../../../test/test_helper'
... ...
plugins/comment_group/test/unit/allow_comment_test.rb 0 → 100644
... ... @@ -0,0 +1,26 @@
  1 +require File.dirname(__FILE__) + '/../test_helper'
  2 +
  3 +class AllowCommentTest < ActiveSupport::TestCase
  4 +
  5 + def setup
  6 + @macro = CommentGroupPlugin::AllowComment.new
  7 + end
  8 +
  9 + attr_reader :macro
  10 +
  11 + should 'have a configuration' do
  12 + assert CommentGroupPlugin::AllowComment.configuration
  13 + end
  14 +
  15 + should 'parse contents to include comment group view' do
  16 + profile = fast_create(Community)
  17 + article = fast_create(Article, :profile_id => profile.id)
  18 + comment = fast_create(Comment, :group_id => 1, :source_id => article.id)
  19 + inner_html = 'inner'
  20 + content = macro.parse({:group_id => comment.group_id}, inner_html, article)
  21 +
  22 + expects(:render).with({:partial => 'plugins/comment_group/views/comment_group.rhtml', :locals => {:group_id => comment.group_id, :article_id => article.id, :inner_html => inner_html, :count => 1, :profile_identifier => profile.identifier} })
  23 + instance_eval(&content)
  24 + end
  25 +
  26 +end
... ...
plugins/comment_group/test/unit/article_test.rb 0 → 100644
... ... @@ -0,0 +1,31 @@
  1 +require File.dirname(__FILE__) + '/../test_helper'
  2 +
  3 +class ArticleTest < ActiveSupport::TestCase
  4 +
  5 + def setup
  6 + profile = fast_create(Community)
  7 + @article = fast_create(Article, :profile_id => profile.id)
  8 + end
  9 +
  10 + attr_reader :article
  11 +
  12 + should 'return group comments from article' do
  13 + comment1 = fast_create(Comment, :group_id => 1, :source_id => article.id)
  14 + comment2 = fast_create(Comment, :group_id => nil, :source_id => article.id)
  15 + assert_equal [comment1], article.group_comments
  16 + end
  17 +
  18 + should 'do not allow a exclusion of a group comment macro if this group has comments' do
  19 + article.update_attribute(:body, "<div class=\"macro\" data-macro-group_id=2></div>")
  20 + comment1 = fast_create(Comment, :group_id => 1, :source_id => article.id)
  21 + assert !article.save
  22 + assert_equal 'Not empty group comment cannot be removed', article.errors[:base]
  23 + end
  24 +
  25 + should 'allow save if comment group macro is not removed for group with comments' do
  26 + article.update_attribute(:body, "<div class=\"macro\" data-macro-group_id=1></div>")
  27 + comment1 = fast_create(Comment, :group_id => 1, :source_id => article.id)
  28 + assert article.save
  29 + end
  30 +
  31 +end
... ...
plugins/comment_group/test/unit/comment_group_plugin_test.rb
1   -require File.dirname(__FILE__) + '/../../../../test/test_helper'
  1 +require File.dirname(__FILE__) + '/../test_helper'
2 2  
3 3 class CommentGroupPluginTest < ActiveSupport::TestCase
4 4  
5   - include Noosfero::Plugin::HotSpot
6   -
7 5 def setup
8 6 @environment = Environment.default
  7 + @plugin = CommentGroupPlugin.new
  8 + end
  9 +
  10 + attr_reader :environment, :plugin
  11 +
  12 + should 'have a name' do
  13 + assert_not_equal Noosfero::Plugin.plugin_name, CommentGroupPlugin::plugin_name
  14 + end
  15 +
  16 + should 'describe yourself' do
  17 + assert_not_equal Noosfero::Plugin.plugin_description, CommentGroupPlugin::plugin_description
  18 + end
  19 +
  20 + should 'have a js file' do
  21 + assert !plugin.js_files.blank?
9 22 end
10 23  
11   - attr_reader :environment
  24 + should 'have stylesheet' do
  25 + assert plugin.stylesheet?
  26 + end
  27 +
  28 + should 'have extra contents for comment form' do
  29 + comment = fast_create(Comment, :group_id => 1)
  30 + content = plugin.comment_form_extra_contents({:comment => comment})
  31 + expects(:hidden_field_tag).with('comment[group_id]', comment.group_id).once
  32 + instance_eval(&content)
  33 + end
  34 +
  35 + should 'do not have extra contents for comments without group' do
  36 + comment = fast_create(Comment, :group_id => nil)
  37 + content = plugin.comment_form_extra_contents({:comment => comment})
  38 + assert_equal nil, instance_eval(&content)
  39 + end
  40 +
  41 + should 'call without_group for scope passed as parameter to unavailable_comments' do
  42 + article = fast_create(Article)
  43 + article.expects(:without_group).once
  44 + plugin.unavailable_comments(article)
  45 + end
12 46  
13 47 #FIXME Obsolete test
14 48 #
... ...
plugins/comment_group/test/unit/comment_test.rb 0 → 100644
... ... @@ -0,0 +1,26 @@
  1 +require File.dirname(__FILE__) + '/../test_helper'
  2 +
  3 +class CommentTest < ActiveSupport::TestCase
  4 +
  5 + def setup
  6 + profile = fast_create(Community)
  7 + @article = fast_create(Article, :profile_id => profile.id)
  8 + end
  9 +
  10 + attr_reader :article
  11 +
  12 + should 'return comments that belongs to a specified group' do
  13 + comment1 = fast_create(Comment, :group_id => 1, :source_id => article.id)
  14 + comment2 = fast_create(Comment, :group_id => nil, :source_id => article.id)
  15 + comment3 = fast_create(Comment, :group_id => 2, :source_id => article.id)
  16 + assert_equal [comment1], article.comments.in_group(1)
  17 + end
  18 +
  19 + should 'return comments that do not belongs to any group' do
  20 + comment1 = fast_create(Comment, :group_id => 1, :source_id => article.id)
  21 + comment2 = fast_create(Comment, :group_id => nil, :source_id => article.id)
  22 + comment3 = fast_create(Comment, :group_id => 2, :source_id => article.id)
  23 + assert_equal [comment2], article.comments.without_group
  24 + end
  25 +
  26 +end
... ...