Commit 3a110cbaaa7b0a6f43b760ea11962e266693186f

Authored by Daniela Feitosa
2 parents e9867fe1 ad72412b

Merge commit 'refs/merge-requests/414' of git://gitorious.org/noosfero/noosfero …

…into merge-requests/414
app/helpers/application_helper.rb
... ... @@ -1425,7 +1425,7 @@ module ApplicationHelper
1425 1425  
1426 1426 def filter_html(html, source)
1427 1427 if @plugins && source.has_macro?
1428   - html = convert_macro(html, source)
  1428 + html = convert_macro(html, source) unless @plugins.enabled_macros.blank?
1429 1429 #TODO This parse should be done through the macro infra, but since there
1430 1430 # are old things that do not support it we are keeping this hot spot.
1431 1431 html = @plugins.pipeline(:parse_content, html, source).first
... ...
plugins/comment_group/controllers/profile/comment_group_plugin_profile_controller.rb
1 1 class CommentGroupPluginProfileController < ProfileController
2   - append_view_path File.join(File.dirname(__FILE__) + '/../views')
  2 + append_view_path File.join(File.dirname(__FILE__) + '/../../views')
3 3  
4 4 def view_comments
5   - article_id = params[:article_id]
6   - group_id = params[:group_id]
  5 + @article_id = params[:article_id]
  6 + @group_id = params[:group_id]
7 7  
8   - article = profile.articles.find(article_id)
9   - comments = article.group_comments.without_spam.in_group(group_id)
10   - render :update do |page|
11   - page.replace_html "comments_list_group_#{group_id}", :partial => 'comment/comment.rhtml', :collection => comments
12   - page.replace_html "comment-count-#{group_id}", comments.count
13   - end
  8 + article = profile.articles.find(@article_id)
  9 + @group_comment_page = (params[:group_comment_page] || 1).to_i
  10 +
  11 + @comments = article.comments.without_spam.in_group(@group_id)
  12 + @comments_count = @comments.count
  13 + @comments = @comments.without_reply.paginate(:per_page => per_page, :page => @group_comment_page )
  14 +
  15 + @no_more_pages = @comments_count <= @group_comment_page * per_page
  16 + end
  17 +
  18 + def per_page
  19 + 3
14 20 end
15 21  
16 22 end
... ...
plugins/comment_group/lib/comment_group_plugin.rb
... ... @@ -24,6 +24,11 @@ class CommentGroupPlugin &lt; Noosfero::Plugin
24 24 'comment_group_macro.js'
25 25 end
26 26  
  27 + def stylesheet?
  28 + true
  29 + end
  30 +
  31 +
27 32 end
28 33  
29 34 require_dependency 'comment_group_plugin/macros/allow_comment'
... ...
plugins/comment_group/lib/comment_group_plugin/macros/allow_comment.rb
... ... @@ -11,7 +11,6 @@ class CommentGroupPlugin::AllowComment &lt; 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 &#39;article&#39;
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/public/style.css 0 → 100644
... ... @@ -0,0 +1,7 @@
  1 +div.article-comments-list-more{
  2 + width: 100%;
  3 + height: 30px;
  4 + text-align: center;
  5 + font-size: 20px;
  6 + margin-bottom: 5px;
  7 +}
... ...
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.
... ... @@ -21,18 +21,52 @@ class CommentGroupPluginProfileControllerTest &lt; ActionController::TestCase
21 21 should 'be able to show group comments' do
22 22 comment = fast_create(Comment, :source_id => article, :author_id => profile, :title => 'a comment', :body => 'lalala', :group_id => 0)
23 23 xhr :get, :view_comments, :profile => @profile.identifier, :article_id => article.id, :group_id => 0
24   - assert_template 'comment/_comment.rhtml'
  24 + assert_template 'comment_group_plugin_profile/view_comments.rjs'
25 25 assert_match /comments_list_group_0/, @response.body
26 26 assert_match /\"comment-count-0\", \"1\"/, @response.body
27 27 end
28 28  
29 29 should 'do not show global comments' do
30   - comment = fast_create(Comment, :source_id => article, :author_id => profile, :title => 'global comment', :body => 'global', :group_id => nil)
31   - comment = fast_create(Comment, :source_id => article, :author_id => profile, :title => 'a comment', :body => 'lalala', :group_id => 0)
  30 + fast_create(Comment, :source_id => article, :author_id => profile, :title => 'global comment', :body => 'global', :group_id => nil)
  31 + fast_create(Comment, :source_id => article, :author_id => profile, :title => 'a comment', :body => 'lalala', :group_id => 0)
32 32 xhr :get, :view_comments, :profile => @profile.identifier, :article_id => article.id, :group_id => 0
33   - assert_template 'comment/_comment.rhtml'
  33 + assert_template 'comment_group_plugin_profile/view_comments.rjs'
34 34 assert_match /comments_list_group_0/, @response.body
35 35 assert_match /\"comment-count-0\", \"1\"/, @response.body
36 36 end
37 37  
  38 + should 'show first page comments only' do
  39 + comment1 = fast_create(Comment, :source_id => article, :author_id => profile, :title => 'a comment', :body => 'secondpage', :group_id => 0)
  40 + comment2 = fast_create(Comment, :source_id => article, :author_id => profile, :title => 'a comment', :body => 'firstpage 1', :group_id => 0)
  41 + comment3 = fast_create(Comment, :source_id => article, :author_id => profile, :title => 'a comment', :body => 'firstpage 2', :group_id => 0)
  42 + comment4 = fast_create(Comment, :source_id => article, :author_id => profile, :title => 'a comment', :body => 'firstpage 3', :group_id => 0)
  43 + xhr :get, :view_comments, :profile => @profile.identifier, :article_id => article.id, :group_id => 0
  44 + assert_match /firstpage 1/, @response.body
  45 + assert_match /firstpage 2/, @response.body
  46 + assert_match /firstpage 3/, @response.body
  47 + assert_no_match /secondpage/, @response.body
  48 + end
  49 +
  50 + should 'show link to display more comments' do
  51 + comment = fast_create(Comment, :source_id => article, :author_id => profile, :title => 'a comment', :body => 'lalala', :group_id => 0)
  52 + comment = fast_create(Comment, :source_id => article, :author_id => profile, :title => 'a comment', :body => 'lalala', :group_id => 0)
  53 + comment = fast_create(Comment, :source_id => article, :author_id => profile, :title => 'a comment', :body => 'lalala', :group_id => 0)
  54 + comment = fast_create(Comment, :source_id => article, :author_id => profile, :title => 'secondpage', :body => 'secondpage', :group_id => 0)
  55 + xhr :get, :view_comments, :profile => @profile.identifier, :article_id => article.id, :group_id => 0
  56 + assert_match /group_comment_page=2/, @response.body
  57 + end
  58 +
  59 + should 'do not show link to display more comments if do not have more pages' do
  60 + comment = fast_create(Comment, :source_id => article, :author_id => profile, :title => 'a comment', :body => 'lalala', :group_id => 0)
  61 + comment = fast_create(Comment, :source_id => article, :author_id => profile, :title => 'a comment', :body => 'lalala', :group_id => 0)
  62 + comment = fast_create(Comment, :source_id => article, :author_id => profile, :title => 'a comment', :body => 'lalala', :group_id => 0)
  63 + xhr :get, :view_comments, :profile => @profile.identifier, :article_id => article.id, :group_id => 0
  64 + assert_no_match /group_comment_page/, @response.body
  65 + end
  66 +
  67 + should 'do not show link to display more comments if do not have any comments' do
  68 + xhr :get, :view_comments, :profile => @profile.identifier, :article_id => article.id, :group_id => 0
  69 + assert_no_match /group_comment_page/, @response.body
  70 + end
  71 +
38 72 end
... ...
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
... ...
plugins/comment_group/views/_comment_group.rhtml
... ... @@ -20,7 +20,13 @@
20 20 <div class="comment-group-loading-<%= group_id %>"/>
21 21  
22 22 <div class="comments_list_toggle_group_<%= group_id %>" style="display:none">
23   - <div class="article-comments-list" id="comments_list_group_<%= group_id %>"></div>
24   - <div id="page-comment-form-<%= group_id %>" class='post_comment_box closed'><%= render :partial => 'comment/comment_form', :locals => {:comment => Comment.new, :display_link => true, :cancel_triggers_hide => true, :group_id => group_id}%></div>
  23 + <div class="article-comments-list" id="comments_list_group_<%= group_id %>">
  24 + </div>
  25 + <div class ="article-comments-list-more" id="comments_list_group_<%= group_id %>_more">
  26 + </div>
  27 + <div id="page-comment-form-<%= group_id %>" class='post_comment_box closed'>
  28 + <%= render :partial => 'comment/comment_form', :locals => {:comment => Comment.new, :display_link => true, :cancel_triggers_hide => true, :group_id => group_id}%>
  29 + </div>
  30 +
25 31 </div>
26 32 </div>
... ...
plugins/comment_group/views/comment_group_plugin_profile/view_comments.rjs 0 → 100644
... ... @@ -0,0 +1,12 @@
  1 +if @group_comment_page == 1
  2 + page.replace_html "comments_list_group_#{@group_id}", :partial => 'comment/comment.rhtml', :collection => @comments
  3 +else
  4 + page.insert_html :bottom, "comments_list_group_#{@group_id}", :partial => 'comment/comment.rhtml', :collection => @comments
  5 +end
  6 +page.replace_html "comment-count-#{@group_id}", @comments_count
  7 +
  8 +if @no_more_pages
  9 + page.replace_html "comments_list_group_#{@group_id}_more", ""
  10 +else
  11 + page.replace_html "comments_list_group_#{@group_id}_more", link_to_remote(_('More'), :url => { :profile => profile.identifier, :controller => 'comment_group_plugin_profile', :action => 'view_comments', :group_id => @group_id, :article_id => @article_id, :group_comment_page => @group_comment_page + 1}, :loaded => visual_effect(:highlight, "comments_list_group_#{@group_id}"), :method => :post, :complete => "loadCompleted(#{@group_id})")
  12 +end
... ...
test/unit/application_helper_test.rb
... ... @@ -814,6 +814,19 @@ class ApplicationHelperTest &lt; ActiveSupport::TestCase
814 814 assert_no_match /Test1/, parsed_html
815 815 end
816 816  
  817 + should 'not convert macro if there is no macro plugin active' do
  818 + profile = create_user('testuser').person
  819 + article = fast_create(Article, :profile_id => profile.id)
  820 + class Plugin1 < Noosfero::Plugin; end
  821 +
  822 + environment = Environment.default
  823 + environment.enable_plugin(Plugin1)
  824 + @plugins = Noosfero::Plugin::Manager.new(environment, self)
  825 +
  826 + expects(:convert_macro).never
  827 + filter_html(article.body, nil)
  828 + end
  829 +
817 830 protected
818 831 include NoosferoTestHelper
819 832  
... ...