Commit e4eebdf7020c495bb4cc12f30c174ce48a5e305b
1 parent
815ff510
Exists in
staging
and in
3 other branches
comment_paragraph: force quotes when exporting comments
Showing
4 changed files
with
17 additions
and
16 deletions
Show diff stats
plugins/comment_paragraph/controllers/profile/comment_paragraph_plugin_profile_controller.rb
plugins/comment_paragraph/lib/comment_paragraph_plugin/comments_report.rb
1 | +require 'csv' | |
2 | + | |
1 | 3 | module CommentParagraphPlugin::CommentsReport |
2 | 4 | |
3 | 5 | #FIXME make this test |
... | ... | @@ -15,7 +17,7 @@ module CommentParagraphPlugin::CommentsReport |
15 | 17 | @export << create_comment_element(comment, paragraph, paragraph_id) |
16 | 18 | end |
17 | 19 | else # There are no comments for this paragraph |
18 | - @export << { paragraph_id: paragraph_id, paragraph_text: paragraph } | |
20 | + @export << create_comment_element(nil, paragraph, paragraph_id) | |
19 | 21 | end |
20 | 22 | paragraph_id += 1 |
21 | 23 | end |
... | ... | @@ -27,7 +29,7 @@ module CommentParagraphPlugin::CommentsReport |
27 | 29 | return _("No comments for article[%{id}]: %{path}\n\n") % {:id => article.id, :path => article.path} if @export.empty? |
28 | 30 | |
29 | 31 | column_names = @export.first.keys |
30 | - CSV.generate do |csv| | |
32 | + CSV.generate(force_quotes: true) do |csv| | |
31 | 33 | csv << column_names |
32 | 34 | @export.each { |x| csv << x.values } |
33 | 35 | end |
... | ... | @@ -38,13 +40,13 @@ module CommentParagraphPlugin::CommentsReport |
38 | 40 | def create_comment_element(comment, paragraph, paragraph_id) |
39 | 41 | { |
40 | 42 | paragraph_id: paragraph_id, |
41 | - paragraph_text: paragraph.present? ? paragraph.text : nil, | |
42 | - comment_id: comment.id, | |
43 | - comment_reply_to: comment.reply_of_id, | |
44 | - comment_title: comment.title, | |
45 | - comment_content: comment.body, | |
46 | - comment_author_name: comment.author_name, | |
47 | - comment_author_email: comment.author_email | |
43 | + paragraph_text: paragraph.present? ? paragraph.text.strip : nil, | |
44 | + comment_id: comment.present? ? comment.id : '-', | |
45 | + comment_reply_to: comment.present? ? comment.reply_of_id : '-', | |
46 | + comment_title: comment.present? ? comment.title : '-', | |
47 | + comment_content: comment.present? ? comment.body : '-', | |
48 | + comment_author_name: comment.present? ? comment.author_name : '-', | |
49 | + comment_author_email: comment.present? ? comment.author_email : '-' | |
48 | 50 | } |
49 | 51 | end |
50 | 52 | ... | ... |
plugins/comment_paragraph/test/functional/comment_paragraph_plugin_profile_controller_test.rb
... | ... | @@ -56,8 +56,8 @@ class CommentParagraphPluginProfileControllerTest < ActionController::TestCase |
56 | 56 | xhr :get, :export_comments, :profile => @profile.identifier, :id => article.id |
57 | 57 | assert_equal 'text/csv; charset=UTF-8; header=present', @response.content_type |
58 | 58 | lines = @response.body.split("\n") |
59 | - assert_equal "paragraph_text,comment_id,comment_title,comment_content,comment_author_name,comment_author_email", lines.first | |
60 | - assert_equal ",#{comment2.id},b comment,b comment,#{comment2.author_name},#{comment2.author_email}", lines.second | |
59 | + assert_equal '"paragraph_id","paragraph_text","comment_id","comment_reply_to","comment_title","comment_content","comment_author_name","comment_author_email"', lines.first | |
60 | + assert_equal "\"\",\"\",\"#{comment2.id}\",\"\",\"b comment\",\"b comment\",\"#{comment2.author_name}\",\"#{comment2.author_email}\"", lines.second | |
61 | 61 | end |
62 | 62 | |
63 | 63 | should 'not export any comments as CSV' do | ... | ... |
plugins/comment_paragraph/test/unit/comment_paragraph_plugin_test.rb
... | ... | @@ -69,7 +69,7 @@ class CommentParagraphPluginTest < ActiveSupport::TestCase |
69 | 69 | article = fast_create(Article, :profile_id => profile.id) |
70 | 70 | article.expects(:comment_paragraph_plugin_enabled?).returns(true) |
71 | 71 | article.expects(:allow_edit?).with(user).returns(true) |
72 | - article.expects(:comment_paragraph_plugin_activated?).returns(false) | |
72 | + article.expects(:comment_paragraph_plugin_activated?).at_least_once.returns(false) | |
73 | 73 | |
74 | 74 | assert_equal 'Activate Comments', plugin.article_extra_toolbar_buttons(article).first[:title] |
75 | 75 | end |
... | ... | @@ -79,7 +79,7 @@ class CommentParagraphPluginTest < ActiveSupport::TestCase |
79 | 79 | article = fast_create(Article, :profile_id => profile.id) |
80 | 80 | article.expects(:comment_paragraph_plugin_enabled?).returns(true) |
81 | 81 | article.expects(:allow_edit?).with(user).returns(true) |
82 | - article.expects(:comment_paragraph_plugin_activated?).returns(true) | |
82 | + article.expects(:comment_paragraph_plugin_activated?).at_least_once.returns(true) | |
83 | 83 | |
84 | 84 | assert_equal 'Deactivate Comments', plugin.article_extra_toolbar_buttons(article).first[:title] |
85 | 85 | end |
... | ... | @@ -89,9 +89,9 @@ class CommentParagraphPluginTest < ActiveSupport::TestCase |
89 | 89 | article = fast_create(Article, :profile_id => profile.id) |
90 | 90 | article.expects(:comment_paragraph_plugin_enabled?).returns(true) |
91 | 91 | article.expects(:allow_edit?).with(user).returns(true) |
92 | - article.expects(:comment_paragraph_plugin_activated?).returns(false) | |
92 | + article.expects(:comment_paragraph_plugin_activated?).at_least_once.returns(true) | |
93 | 93 | |
94 | - assert_equal 'Export Comments', plugin.article_extra_toolbar_buttons(article).last[:title] | |
94 | + assert_includes plugin.article_extra_toolbar_buttons(article).map {|b| b[:title]}, 'Export Comments' | |
95 | 95 | end |
96 | 96 | |
97 | 97 | end | ... | ... |