Commit 56cc28dc8b10f3ec9912b0a761060cc9e82cd667

Authored by Leandro Santos
2 parents bde4a4f8 51dcaa95

Merge branch 'filename-comment-paragraph' into 'master'

comment_paragraph: change filename of exported comments



See merge request !966
plugins/comment_paragraph/lib/comment_paragraph_plugin/api.rb
@@ -40,7 +40,7 @@ class CommentParagraphPlugin::API < Grape::API @@ -40,7 +40,7 @@ class CommentParagraphPlugin::API < Grape::API
40 get ":id/comment_paragraph_plugin/export" do 40 get ":id/comment_paragraph_plugin/export" do
41 article = find_article(environment.articles, params[:id]) 41 article = find_article(environment.articles, params[:id])
42 result = export_comments_csv(article) 42 result = export_comments_csv(article)
43 - filename = "comments_for_article#{article.id}_#{DateTime.now.to_i}.csv" 43 + filename = "#{article.slug}_#{DateTime.now.strftime("%Y%m%d%H%M")}.csv"
44 content_type 'text/csv; charset=UTF-8; header=present' 44 content_type 'text/csv; charset=UTF-8; header=present'
45 env['api.format'] = :binary # there's no formatter for :binary, data will be returned "as is" 45 env['api.format'] = :binary # there's no formatter for :binary, data will be returned "as is"
46 header 'Content-Disposition', "attachment; filename*=UTF-8''#{CGI.escape(filename)}" 46 header 'Content-Disposition', "attachment; filename*=UTF-8''#{CGI.escape(filename)}"
plugins/comment_paragraph/test/unit/api_test.rb
@@ -102,6 +102,7 @@ class APITest < ActiveSupport::TestCase @@ -102,6 +102,7 @@ class APITest < ActiveSupport::TestCase
102 lines = last_response.body.split("\n") 102 lines = last_response.body.split("\n")
103 assert_equal '"paragraph_id","paragraph_text","comment_id","comment_reply_to","comment_title","comment_content","comment_author_name","comment_author_email"', lines.first 103 assert_equal '"paragraph_id","paragraph_text","comment_id","comment_reply_to","comment_title","comment_content","comment_author_name","comment_author_email"', lines.first
104 assert_equal "\"\",\"\",\"#{comment2.id}\",\"\",\"b comment\",\"b comment\",\"#{comment2.author_name}\",\"#{comment2.author_email}\"", lines.second 104 assert_equal "\"\",\"\",\"#{comment2.id}\",\"\",\"b comment\",\"b comment\",\"#{comment2.author_name}\",\"#{comment2.author_email}\"", lines.second
  105 + assert_match /#{article.slug}/, last_response.original_headers["Content-Disposition"]
105 end 106 end
106 107
107 end 108 end