diff --git a/plugins/comment_group/lib/comment_group_plugin/macros/allow_comment.rb b/plugins/comment_group/lib/comment_group_plugin/macros/allow_comment.rb index 97c65c3..f71556b 100644 --- a/plugins/comment_group/lib/comment_group_plugin/macros/allow_comment.rb +++ b/plugins/comment_group/lib/comment_group_plugin/macros/allow_comment.rb @@ -11,7 +11,6 @@ class CommentGroupPlugin::AllowComment < Noosfero::Plugin::Macro :css_files => 'comment_group.css' } end - #FIXME Make this test def parse(params, inner_html, source) group_id = params[:group_id].to_i article = source diff --git a/plugins/comment_group/lib/ext/article.rb b/plugins/comment_group/lib/ext/article.rb index fb7e156..042e260 100644 --- a/plugins/comment_group/lib/ext/article.rb +++ b/plugins/comment_group/lib/ext/article.rb @@ -2,13 +2,10 @@ require_dependency 'article' class Article - #FIXME make this test has_many :group_comments, :class_name => 'Comment', :foreign_key => 'source_id', :dependent => :destroy, :order => 'created_at asc', :conditions => [ 'group_id IS NOT NULL'] - #FIXME make this test validate :not_empty_group_comments_removed - #FIXME make this test def not_empty_group_comments_removed if body groups_with_comments = group_comments.collect {|comment| comment.group_id}.uniq diff --git a/plugins/comment_group/test/functional/comment_group_plugin_profile_controller_test.rb b/plugins/comment_group/test/functional/comment_group_plugin_profile_controller_test.rb index e119a77..de95915 100644 --- a/plugins/comment_group/test/functional/comment_group_plugin_profile_controller_test.rb +++ b/plugins/comment_group/test/functional/comment_group_plugin_profile_controller_test.rb @@ -1,4 +1,4 @@ -require File.dirname(__FILE__) + '/../../../../test/test_helper' +require File.dirname(__FILE__) + '/../test_helper' require File.dirname(__FILE__) + '/../../controllers/profile/comment_group_plugin_profile_controller' # Re-raise errors caught by the controller. diff --git a/plugins/comment_group/test/functional/comment_group_plugin_public_controller_test.rb b/plugins/comment_group/test/functional/comment_group_plugin_public_controller_test.rb index fe330f3..f6b26c1 100644 --- a/plugins/comment_group/test/functional/comment_group_plugin_public_controller_test.rb +++ b/plugins/comment_group/test/functional/comment_group_plugin_public_controller_test.rb @@ -1,4 +1,4 @@ -require File.dirname(__FILE__) + '/../../../../test/test_helper' +require File.dirname(__FILE__) + '/../test_helper' require File.dirname(__FILE__) + '/../../controllers/public/comment_group_plugin_public_controller' # Re-raise errors caught by the controller. diff --git a/plugins/comment_group/test/functional/content_viewer_controller_test.rb b/plugins/comment_group/test/functional/content_viewer_controller_test.rb new file mode 100644 index 0000000..1a47b4b --- /dev/null +++ b/plugins/comment_group/test/functional/content_viewer_controller_test.rb @@ -0,0 +1,28 @@ +require File.dirname(__FILE__) + '/../test_helper' + +class ContentViewerController + append_view_path File.join(File.dirname(__FILE__) + '/../../views') + def rescue_action(e) + raise e + end +end + +class ContentViewerControllerTest < ActionController::TestCase + + def setup + @profile = fast_create(Community) + @page = fast_create(Article, :profile_id => @profile.id, :body => "
") + @environment = Environment.default + @environment.enable_plugin(CommentGroupPlugin) + end + + attr_reader :page + + should 'parse article body and render comment group view' do + comment1 = fast_create(Comment, :group_id => 1, :source_id => page.id) + get :view_page, @page.url + assert_tag 'div', :attributes => {:class => 'comment_group_1'} + assert_tag 'div', :attributes => {:id => 'comments_group_count_1'} + end + +end diff --git a/plugins/comment_group/test/test_helper.rb b/plugins/comment_group/test/test_helper.rb new file mode 100644 index 0000000..cca1fd3 --- /dev/null +++ b/plugins/comment_group/test/test_helper.rb @@ -0,0 +1 @@ +require File.dirname(__FILE__) + '/../../../test/test_helper' diff --git a/plugins/comment_group/test/unit/allow_comment_test.rb b/plugins/comment_group/test/unit/allow_comment_test.rb new file mode 100644 index 0000000..4b8148c --- /dev/null +++ b/plugins/comment_group/test/unit/allow_comment_test.rb @@ -0,0 +1,26 @@ +require File.dirname(__FILE__) + '/../test_helper' + +class AllowCommentTest < ActiveSupport::TestCase + + def setup + @macro = CommentGroupPlugin::AllowComment.new + end + + attr_reader :macro + + should 'have a configuration' do + assert CommentGroupPlugin::AllowComment.configuration + end + + should 'parse contents to include comment group view' do + profile = fast_create(Community) + article = fast_create(Article, :profile_id => profile.id) + comment = fast_create(Comment, :group_id => 1, :source_id => article.id) + inner_html = 'inner' + content = macro.parse({:group_id => comment.group_id}, inner_html, article) + + 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} }) + instance_eval(&content) + end + +end diff --git a/plugins/comment_group/test/unit/article_test.rb b/plugins/comment_group/test/unit/article_test.rb new file mode 100644 index 0000000..12f9b3a --- /dev/null +++ b/plugins/comment_group/test/unit/article_test.rb @@ -0,0 +1,31 @@ +require File.dirname(__FILE__) + '/../test_helper' + +class ArticleTest < ActiveSupport::TestCase + + def setup + profile = fast_create(Community) + @article = fast_create(Article, :profile_id => profile.id) + end + + attr_reader :article + + should 'return group comments from article' do + comment1 = fast_create(Comment, :group_id => 1, :source_id => article.id) + comment2 = fast_create(Comment, :group_id => nil, :source_id => article.id) + assert_equal [comment1], article.group_comments + end + + should 'do not allow a exclusion of a group comment macro if this group has comments' do + article.update_attribute(:body, "
") + comment1 = fast_create(Comment, :group_id => 1, :source_id => article.id) + assert !article.save + assert_equal 'Not empty group comment cannot be removed', article.errors[:base] + end + + should 'allow save if comment group macro is not removed for group with comments' do + article.update_attribute(:body, "
") + comment1 = fast_create(Comment, :group_id => 1, :source_id => article.id) + assert article.save + end + +end diff --git a/plugins/comment_group/test/unit/comment_group_plugin_test.rb b/plugins/comment_group/test/unit/comment_group_plugin_test.rb index 94e473e..304922b 100644 --- a/plugins/comment_group/test/unit/comment_group_plugin_test.rb +++ b/plugins/comment_group/test/unit/comment_group_plugin_test.rb @@ -1,14 +1,48 @@ -require File.dirname(__FILE__) + '/../../../../test/test_helper' +require File.dirname(__FILE__) + '/../test_helper' class CommentGroupPluginTest < ActiveSupport::TestCase - include Noosfero::Plugin::HotSpot - def setup @environment = Environment.default + @plugin = CommentGroupPlugin.new + end + + attr_reader :environment, :plugin + + should 'have a name' do + assert_not_equal Noosfero::Plugin.plugin_name, CommentGroupPlugin::plugin_name + end + + should 'describe yourself' do + assert_not_equal Noosfero::Plugin.plugin_description, CommentGroupPlugin::plugin_description + end + + should 'have a js file' do + assert !plugin.js_files.blank? end - attr_reader :environment + should 'have stylesheet' do + assert plugin.stylesheet? + end + + should 'have extra contents for comment form' do + comment = fast_create(Comment, :group_id => 1) + content = plugin.comment_form_extra_contents({:comment => comment}) + expects(:hidden_field_tag).with('comment[group_id]', comment.group_id).once + instance_eval(&content) + end + + should 'do not have extra contents for comments without group' do + comment = fast_create(Comment, :group_id => nil) + content = plugin.comment_form_extra_contents({:comment => comment}) + assert_equal nil, instance_eval(&content) + end + + should 'call without_group for scope passed as parameter to unavailable_comments' do + article = fast_create(Article) + article.expects(:without_group).once + plugin.unavailable_comments(article) + end #FIXME Obsolete test # diff --git a/plugins/comment_group/test/unit/comment_test.rb b/plugins/comment_group/test/unit/comment_test.rb new file mode 100644 index 0000000..09c4bf4 --- /dev/null +++ b/plugins/comment_group/test/unit/comment_test.rb @@ -0,0 +1,26 @@ +require File.dirname(__FILE__) + '/../test_helper' + +class CommentTest < ActiveSupport::TestCase + + def setup + profile = fast_create(Community) + @article = fast_create(Article, :profile_id => profile.id) + end + + attr_reader :article + + should 'return comments that belongs to a specified group' do + comment1 = fast_create(Comment, :group_id => 1, :source_id => article.id) + comment2 = fast_create(Comment, :group_id => nil, :source_id => article.id) + comment3 = fast_create(Comment, :group_id => 2, :source_id => article.id) + assert_equal [comment1], article.comments.in_group(1) + end + + should 'return comments that do not belongs to any group' do + comment1 = fast_create(Comment, :group_id => 1, :source_id => article.id) + comment2 = fast_create(Comment, :group_id => nil, :source_id => article.id) + comment3 = fast_create(Comment, :group_id => 2, :source_id => article.id) + assert_equal [comment2], article.comments.without_group + end + +end -- libgit2 0.21.2