diff --git a/plugins/comment_paragraph/controllers/profile/comment_paragraph_plugin_profile_controller.rb b/plugins/comment_paragraph/controllers/profile/comment_paragraph_plugin_profile_controller.rb index 72201ee..98791be 100644 --- a/plugins/comment_paragraph/controllers/profile/comment_paragraph_plugin_profile_controller.rb +++ b/plugins/comment_paragraph/controllers/profile/comment_paragraph_plugin_profile_controller.rb @@ -1,4 +1,3 @@ -require 'csv' class CommentParagraphPluginProfileController < CommentController append_view_path File.join(File.dirname(__FILE__) + '/../../views') diff --git a/plugins/comment_paragraph/lib/comment_paragraph_plugin/comments_report.rb b/plugins/comment_paragraph/lib/comment_paragraph_plugin/comments_report.rb index c73afb1..3c7b884 100644 --- a/plugins/comment_paragraph/lib/comment_paragraph_plugin/comments_report.rb +++ b/plugins/comment_paragraph/lib/comment_paragraph_plugin/comments_report.rb @@ -1,3 +1,5 @@ +require 'csv' + module CommentParagraphPlugin::CommentsReport #FIXME make this test @@ -15,7 +17,7 @@ module CommentParagraphPlugin::CommentsReport @export << create_comment_element(comment, paragraph, paragraph_id) end else # There are no comments for this paragraph - @export << { paragraph_id: paragraph_id, paragraph_text: paragraph } + @export << create_comment_element(nil, paragraph, paragraph_id) end paragraph_id += 1 end @@ -27,7 +29,7 @@ module CommentParagraphPlugin::CommentsReport return _("No comments for article[%{id}]: %{path}\n\n") % {:id => article.id, :path => article.path} if @export.empty? column_names = @export.first.keys - CSV.generate do |csv| + CSV.generate(force_quotes: true) do |csv| csv << column_names @export.each { |x| csv << x.values } end @@ -38,13 +40,13 @@ module CommentParagraphPlugin::CommentsReport def create_comment_element(comment, paragraph, paragraph_id) { paragraph_id: paragraph_id, - paragraph_text: paragraph.present? ? paragraph.text : nil, - comment_id: comment.id, - comment_reply_to: comment.reply_of_id, - comment_title: comment.title, - comment_content: comment.body, - comment_author_name: comment.author_name, - comment_author_email: comment.author_email + paragraph_text: paragraph.present? ? paragraph.text.strip : nil, + comment_id: comment.present? ? comment.id : '-', + comment_reply_to: comment.present? ? comment.reply_of_id : '-', + comment_title: comment.present? ? comment.title : '-', + comment_content: comment.present? ? comment.body : '-', + comment_author_name: comment.present? ? comment.author_name : '-', + comment_author_email: comment.present? ? comment.author_email : '-' } end diff --git a/plugins/comment_paragraph/test/functional/comment_paragraph_plugin_profile_controller_test.rb b/plugins/comment_paragraph/test/functional/comment_paragraph_plugin_profile_controller_test.rb index 0403a66..ca9d057 100644 --- a/plugins/comment_paragraph/test/functional/comment_paragraph_plugin_profile_controller_test.rb +++ b/plugins/comment_paragraph/test/functional/comment_paragraph_plugin_profile_controller_test.rb @@ -56,8 +56,8 @@ class CommentParagraphPluginProfileControllerTest < ActionController::TestCase xhr :get, :export_comments, :profile => @profile.identifier, :id => article.id assert_equal 'text/csv; charset=UTF-8; header=present', @response.content_type lines = @response.body.split("\n") - assert_equal "paragraph_text,comment_id,comment_title,comment_content,comment_author_name,comment_author_email", lines.first - assert_equal ",#{comment2.id},b comment,b comment,#{comment2.author_name},#{comment2.author_email}", lines.second + assert_equal '"paragraph_id","paragraph_text","comment_id","comment_reply_to","comment_title","comment_content","comment_author_name","comment_author_email"', lines.first + assert_equal "\"\",\"\",\"#{comment2.id}\",\"\",\"b comment\",\"b comment\",\"#{comment2.author_name}\",\"#{comment2.author_email}\"", lines.second end should 'not export any comments as CSV' do diff --git a/plugins/comment_paragraph/test/unit/comment_paragraph_plugin_test.rb b/plugins/comment_paragraph/test/unit/comment_paragraph_plugin_test.rb index 2fbaf42..f75e233 100644 --- a/plugins/comment_paragraph/test/unit/comment_paragraph_plugin_test.rb +++ b/plugins/comment_paragraph/test/unit/comment_paragraph_plugin_test.rb @@ -69,7 +69,7 @@ class CommentParagraphPluginTest < ActiveSupport::TestCase article = fast_create(Article, :profile_id => profile.id) article.expects(:comment_paragraph_plugin_enabled?).returns(true) article.expects(:allow_edit?).with(user).returns(true) - article.expects(:comment_paragraph_plugin_activated?).returns(false) + article.expects(:comment_paragraph_plugin_activated?).at_least_once.returns(false) assert_equal 'Activate Comments', plugin.article_extra_toolbar_buttons(article).first[:title] end @@ -79,7 +79,7 @@ class CommentParagraphPluginTest < ActiveSupport::TestCase article = fast_create(Article, :profile_id => profile.id) article.expects(:comment_paragraph_plugin_enabled?).returns(true) article.expects(:allow_edit?).with(user).returns(true) - article.expects(:comment_paragraph_plugin_activated?).returns(true) + article.expects(:comment_paragraph_plugin_activated?).at_least_once.returns(true) assert_equal 'Deactivate Comments', plugin.article_extra_toolbar_buttons(article).first[:title] end @@ -89,9 +89,9 @@ class CommentParagraphPluginTest < ActiveSupport::TestCase article = fast_create(Article, :profile_id => profile.id) article.expects(:comment_paragraph_plugin_enabled?).returns(true) article.expects(:allow_edit?).with(user).returns(true) - article.expects(:comment_paragraph_plugin_activated?).returns(false) + article.expects(:comment_paragraph_plugin_activated?).at_least_once.returns(true) - assert_equal 'Export Comments', plugin.article_extra_toolbar_buttons(article).last[:title] + assert_includes plugin.article_extra_toolbar_buttons(article).map {|b| b[:title]}, 'Export Comments' end end -- libgit2 0.21.2