Commit d32f8c9feb0780ed3efc7fa1c082c9c83abc5956

Authored by Victor Costa
1 parent a3bd503a

rails3: fix comment_group plugin

plugins/comment_group/lib/comment_group_plugin.rb
... ... @@ -15,7 +15,7 @@ class CommentGroupPlugin < Noosfero::Plugin
15 15 def comment_form_extra_contents(args)
16 16 comment = args[:comment]
17 17 group_id = comment.group_id || args[:group_id]
18   - lambda {
  18 + proc {
19 19 hidden_field_tag('comment[group_id]', group_id) if group_id
20 20 }
21 21 end
... ...
plugins/comment_group/lib/comment_group_plugin/macros/allow_comment.rb
... ... @@ -16,6 +16,6 @@ class CommentGroupPlugin::AllowComment < Noosfero::Plugin::Macro
16 16 article = source
17 17 count = article.group_comments.without_spam.in_group(group_id).count
18 18  
19   - lambda {render :partial => 'plugins/comment_group/views/comment_group.rhtml', :locals => {:group_id => group_id, :article_id => article.id, :inner_html => inner_html, :count => count, :profile_identifier => article.profile.identifier }}
  19 + proc {render :partial => 'comment_group_plugin_profile/comment_group', :locals => {:group_id => group_id, :article_id => article.id, :inner_html => inner_html, :count => count, :profile_identifier => article.profile.identifier }}
20 20 end
21 21 end
... ...
plugins/comment_group/lib/ext/article.rb
... ... @@ -10,7 +10,7 @@ class Article
10 10 if body && body_changed?
11 11 groups_with_comments = Comment.find(:all, :select => 'distinct group_id', :conditions => {:source_id => self.id}).map(&:group_id).compact
12 12 groups = Hpricot(body.to_s).search('.macro').collect{|element| element['data-macro-group_id'].to_i}
13   - errors.add_to_base(N_('Not empty group comment cannot be removed')) unless (groups_with_comments-groups).empty?
  13 + errors[:base] << (N_('Not empty group comment cannot be removed')) unless (groups_with_comments-groups).empty?
14 14 end
15 15 end
16 16  
... ...
plugins/comment_group/lib/ext/comment.rb
... ... @@ -2,9 +2,9 @@ require_dependency &#39;comment&#39;
2 2  
3 3 class Comment
4 4  
5   - named_scope :without_group, :conditions => {:group_id => nil }
  5 + scope :without_group, :conditions => {:group_id => nil }
6 6  
7   - named_scope :in_group, lambda { |group_id| {
  7 + scope :in_group, proc { |group_id| {
8 8 :conditions => ['group_id = ?', group_id]
9 9 }
10 10 }
... ...
plugins/comment_group/test/functional/comment_group_plugin_profile_controller_test.rb
... ... @@ -21,7 +21,7 @@ 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_group_plugin_profile/view_comments.rjs'
  24 + assert_template 'comment_group_plugin_profile/view_comments'
25 25 assert_match /comments_list_group_0/, @response.body
26 26 assert_match /\"comment-count-0\", \"1\"/, @response.body
27 27 end
... ... @@ -30,7 +30,7 @@ class CommentGroupPluginProfileControllerTest &lt; ActionController::TestCase
30 30 fast_create(Comment, :source_id => article, :author_id => profile, :title => 'global comment', :body => 'global', :group_id => nil)
31 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_group_plugin_profile/view_comments.rjs'
  33 + assert_template 'comment_group_plugin_profile/view_comments'
34 34 assert_match /comments_list_group_0/, @response.body
35 35 assert_match /\"comment-count-0\", \"1\"/, @response.body
36 36 end
... ...
plugins/comment_group/test/unit/allow_comment_test.rb
... ... @@ -19,7 +19,7 @@ class AllowCommentTest &lt; ActiveSupport::TestCase
19 19 inner_html = 'inner'
20 20 content = macro.parse({:group_id => comment.group_id}, inner_html, article)
21 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} })
  22 + expects(:render).with({:partial => 'comment_group_plugin_profile/comment_group', :locals => {:group_id => comment.group_id, :article_id => article.id, :inner_html => inner_html, :count => 1, :profile_identifier => profile.identifier} })
23 23 instance_eval(&content)
24 24 end
25 25  
... ...
plugins/comment_group/test/unit/article_test.rb
... ... @@ -20,7 +20,7 @@ class ArticleTest &lt; ActiveSupport::TestCase
20 20 article.body = "<div class=\"macro\" data-macro-group_id=2></div>"
21 21 comment1 = fast_create(Comment, :group_id => 1, :source_id => article.id)
22 22 assert !article.save
23   - assert_equal 'Not empty group comment cannot be removed', article.errors[:base]
  23 + assert_equal ['Not empty group comment cannot be removed'], article.errors[:base]
24 24 end
25 25  
26 26 should 'allow save if comment group macro is not removed for group with comments' do
... ...
plugins/comment_group/views/_comment_group.rhtml
... ... @@ -1,32 +0,0 @@
1   -<div class="comments">
2   - <div class="comment_group_<%= group_id %>" style="float: left">
3   - <div style="float: left">
4   - <%= link_to_remote(image_tag("/plugins/comment_group/images/comments.gif"),
5   - :url => { :profile => profile_identifier, :controller => 'comment_group_plugin_profile', :action => 'view_comments', :group_id => group_id, :article_id => article_id},
6   - :loaded => visual_effect(:highlight, "comments_list_group_#{group_id}"),
7   - :method => :post,
8   - :condition => "!toggleGroup(#{group_id})",
9   - :complete => "loadCompleted(#{group_id})")%>
10   - </div>
11   - <!-- FIXME: css file -->
12   - <div id="comments_group_count_<%= group_id %>" style="float: right; vertical-align: middle; padding-left: 3px; padding-right: 5px; color: #5AC1FC"><span id="comment-count-<%= group_id %>" class='comment-count'><%= count %></span></div>
13   -
14   - </div>
15   -
16   - <div>
17   - <%= inner_html %>
18   - </div>
19   -
20   - <div class="comment-group-loading-<%= group_id %>"/>
21   -
22   - <div class="comments_list_toggle_group_<%= group_id %>" style="display:none">
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   -
31   - </div>
32   -</div>
plugins/comment_group/views/comment_group_plugin_profile/_comment_group.html.erb 0 → 100644
... ... @@ -0,0 +1,32 @@
  1 +<div class="comments">
  2 + <div class="comment_group_<%= group_id %>" style="float: left">
  3 + <div style="float: left">
  4 + <%= link_to_remote(image_tag("/plugins/comment_group/images/comments.gif"),
  5 + :url => { :profile => profile_identifier, :controller => 'comment_group_plugin_profile', :action => 'view_comments', :group_id => group_id, :article_id => article_id},
  6 + :loaded => visual_effect(:highlight, "comments_list_group_#{group_id}"),
  7 + :method => :post,
  8 + :condition => "!toggleGroup(#{group_id})",
  9 + :complete => "loadCompleted(#{group_id})")%>
  10 + </div>
  11 + <!-- FIXME: css file -->
  12 + <div id="comments_group_count_<%= group_id %>" style="float: right; vertical-align: middle; padding-left: 3px; padding-right: 5px; color: #5AC1FC"><span id="comment-count-<%= group_id %>" class='comment-count'><%= count %></span></div>
  13 +
  14 + </div>
  15 +
  16 + <div>
  17 + <%= inner_html %>
  18 + </div>
  19 +
  20 + <div class="comment-group-loading-<%= group_id %>"/>
  21 +
  22 + <div class="comments_list_toggle_group_<%= group_id %>" style="display:none">
  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 +
  31 + </div>
  32 +</div>
... ...
plugins/comment_group/views/comment_group_plugin_profile/view_comments.rjs
1 1 if @group_comment_page == 1
2   - page.replace_html "comments_list_group_#{@group_id}", :partial => 'comment/comment.rhtml', :collection => @comments
  2 + page.replace_html "comments_list_group_#{@group_id}", :partial => 'comment/comment.html.erb', :collection => @comments
3 3 else
4   - page.insert_html :bottom, "comments_list_group_#{@group_id}", :partial => 'comment/comment.rhtml', :collection => @comments
  4 + page.insert_html :bottom, "comments_list_group_#{@group_id}", :partial => 'comment/comment.html.erb', :collection => @comments
5 5 end
6 6 page.replace_html "comment-count-#{@group_id}", @comments_count
7 7  
... ...