From d32f8c9feb0780ed3efc7fa1c082c9c83abc5956 Mon Sep 17 00:00:00 2001 From: Victor Costa Date: Mon, 24 Feb 2014 18:55:03 -0300 Subject: [PATCH] rails3: fix comment_group plugin --- plugins/comment_group/lib/comment_group_plugin.rb | 2 +- plugins/comment_group/lib/comment_group_plugin/macros/allow_comment.rb | 2 +- plugins/comment_group/lib/ext/article.rb | 2 +- plugins/comment_group/lib/ext/comment.rb | 4 ++-- plugins/comment_group/test/functional/comment_group_plugin_profile_controller_test.rb | 4 ++-- plugins/comment_group/test/unit/allow_comment_test.rb | 2 +- plugins/comment_group/test/unit/article_test.rb | 2 +- plugins/comment_group/views/_comment_group.rhtml | 32 -------------------------------- plugins/comment_group/views/comment_group_plugin_profile/_comment_group.html.erb | 32 ++++++++++++++++++++++++++++++++ plugins/comment_group/views/comment_group_plugin_profile/view_comments.rjs | 4 ++-- 10 files changed, 43 insertions(+), 43 deletions(-) delete mode 100644 plugins/comment_group/views/_comment_group.rhtml create mode 100644 plugins/comment_group/views/comment_group_plugin_profile/_comment_group.html.erb diff --git a/plugins/comment_group/lib/comment_group_plugin.rb b/plugins/comment_group/lib/comment_group_plugin.rb index 6cd23d2..51f453e 100644 --- a/plugins/comment_group/lib/comment_group_plugin.rb +++ b/plugins/comment_group/lib/comment_group_plugin.rb @@ -15,7 +15,7 @@ class CommentGroupPlugin < Noosfero::Plugin def comment_form_extra_contents(args) comment = args[:comment] group_id = comment.group_id || args[:group_id] - lambda { + proc { hidden_field_tag('comment[group_id]', group_id) if group_id } end 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 f71556b..0afd736 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 @@ -16,6 +16,6 @@ class CommentGroupPlugin::AllowComment < Noosfero::Plugin::Macro article = source count = article.group_comments.without_spam.in_group(group_id).count - 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 }} + 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 }} end end diff --git a/plugins/comment_group/lib/ext/article.rb b/plugins/comment_group/lib/ext/article.rb index 3e073c0..1cde990 100644 --- a/plugins/comment_group/lib/ext/article.rb +++ b/plugins/comment_group/lib/ext/article.rb @@ -10,7 +10,7 @@ class Article if body && body_changed? groups_with_comments = Comment.find(:all, :select => 'distinct group_id', :conditions => {:source_id => self.id}).map(&:group_id).compact groups = Hpricot(body.to_s).search('.macro').collect{|element| element['data-macro-group_id'].to_i} - errors.add_to_base(N_('Not empty group comment cannot be removed')) unless (groups_with_comments-groups).empty? + errors[:base] << (N_('Not empty group comment cannot be removed')) unless (groups_with_comments-groups).empty? end end diff --git a/plugins/comment_group/lib/ext/comment.rb b/plugins/comment_group/lib/ext/comment.rb index 89bce1c..3298b85 100644 --- a/plugins/comment_group/lib/ext/comment.rb +++ b/plugins/comment_group/lib/ext/comment.rb @@ -2,9 +2,9 @@ require_dependency 'comment' class Comment - named_scope :without_group, :conditions => {:group_id => nil } + scope :without_group, :conditions => {:group_id => nil } - named_scope :in_group, lambda { |group_id| { + scope :in_group, proc { |group_id| { :conditions => ['group_id = ?', group_id] } } 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 de95915..ecdcfd4 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 @@ -21,7 +21,7 @@ class CommentGroupPluginProfileControllerTest < ActionController::TestCase should 'be able to show group comments' do comment = fast_create(Comment, :source_id => article, :author_id => profile, :title => 'a comment', :body => 'lalala', :group_id => 0) xhr :get, :view_comments, :profile => @profile.identifier, :article_id => article.id, :group_id => 0 - assert_template 'comment_group_plugin_profile/view_comments.rjs' + assert_template 'comment_group_plugin_profile/view_comments' assert_match /comments_list_group_0/, @response.body assert_match /\"comment-count-0\", \"1\"/, @response.body end @@ -30,7 +30,7 @@ class CommentGroupPluginProfileControllerTest < ActionController::TestCase fast_create(Comment, :source_id => article, :author_id => profile, :title => 'global comment', :body => 'global', :group_id => nil) fast_create(Comment, :source_id => article, :author_id => profile, :title => 'a comment', :body => 'lalala', :group_id => 0) xhr :get, :view_comments, :profile => @profile.identifier, :article_id => article.id, :group_id => 0 - assert_template 'comment_group_plugin_profile/view_comments.rjs' + assert_template 'comment_group_plugin_profile/view_comments' assert_match /comments_list_group_0/, @response.body assert_match /\"comment-count-0\", \"1\"/, @response.body end diff --git a/plugins/comment_group/test/unit/allow_comment_test.rb b/plugins/comment_group/test/unit/allow_comment_test.rb index 4b8148c..4616f15 100644 --- a/plugins/comment_group/test/unit/allow_comment_test.rb +++ b/plugins/comment_group/test/unit/allow_comment_test.rb @@ -19,7 +19,7 @@ class AllowCommentTest < ActiveSupport::TestCase 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} }) + 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} }) instance_eval(&content) end diff --git a/plugins/comment_group/test/unit/article_test.rb b/plugins/comment_group/test/unit/article_test.rb index 4448760..e9d5f04 100644 --- a/plugins/comment_group/test/unit/article_test.rb +++ b/plugins/comment_group/test/unit/article_test.rb @@ -20,7 +20,7 @@ class ArticleTest < ActiveSupport::TestCase article.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] + 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 diff --git a/plugins/comment_group/views/_comment_group.rhtml b/plugins/comment_group/views/_comment_group.rhtml deleted file mode 100644 index c7c7644..0000000 --- a/plugins/comment_group/views/_comment_group.rhtml +++ /dev/null @@ -1,32 +0,0 @@ -
-
-
- <%= link_to_remote(image_tag("/plugins/comment_group/images/comments.gif"), - :url => { :profile => profile_identifier, :controller => 'comment_group_plugin_profile', :action => 'view_comments', :group_id => group_id, :article_id => article_id}, - :loaded => visual_effect(:highlight, "comments_list_group_#{group_id}"), - :method => :post, - :condition => "!toggleGroup(#{group_id})", - :complete => "loadCompleted(#{group_id})")%> -
- -
<%= count %>
- -
- -
- <%= inner_html %> -
- -
- - -
diff --git a/plugins/comment_group/views/comment_group_plugin_profile/_comment_group.html.erb b/plugins/comment_group/views/comment_group_plugin_profile/_comment_group.html.erb new file mode 100644 index 0000000..c7c7644 --- /dev/null +++ b/plugins/comment_group/views/comment_group_plugin_profile/_comment_group.html.erb @@ -0,0 +1,32 @@ +
+
+
+ <%= link_to_remote(image_tag("/plugins/comment_group/images/comments.gif"), + :url => { :profile => profile_identifier, :controller => 'comment_group_plugin_profile', :action => 'view_comments', :group_id => group_id, :article_id => article_id}, + :loaded => visual_effect(:highlight, "comments_list_group_#{group_id}"), + :method => :post, + :condition => "!toggleGroup(#{group_id})", + :complete => "loadCompleted(#{group_id})")%> +
+ +
<%= count %>
+ +
+ +
+ <%= inner_html %> +
+ +
+ + +
diff --git a/plugins/comment_group/views/comment_group_plugin_profile/view_comments.rjs b/plugins/comment_group/views/comment_group_plugin_profile/view_comments.rjs index 90640ec..76e5263 100644 --- a/plugins/comment_group/views/comment_group_plugin_profile/view_comments.rjs +++ b/plugins/comment_group/views/comment_group_plugin_profile/view_comments.rjs @@ -1,7 +1,7 @@ if @group_comment_page == 1 - page.replace_html "comments_list_group_#{@group_id}", :partial => 'comment/comment.rhtml', :collection => @comments + page.replace_html "comments_list_group_#{@group_id}", :partial => 'comment/comment.html.erb', :collection => @comments else - page.insert_html :bottom, "comments_list_group_#{@group_id}", :partial => 'comment/comment.rhtml', :collection => @comments + page.insert_html :bottom, "comments_list_group_#{@group_id}", :partial => 'comment/comment.html.erb', :collection => @comments end page.replace_html "comment-count-#{@group_id}", @comments_count -- libgit2 0.21.2