Commit 51dcaa95e04f45694c444669a4f6bb65ddaf94e2

Authored by Victor Costa
1 parent 9db0c7d6

comment_paragraph: change filename of exported comments

plugins/comment_paragraph/lib/comment_paragraph_plugin/api.rb
... ... @@ -40,7 +40,7 @@ class CommentParagraphPlugin::API < Grape::API
40 40 get ":id/comment_paragraph_plugin/export" do
41 41 article = find_article(environment.articles, params[:id])
42 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 44 content_type 'text/csv; charset=UTF-8; header=present'
45 45 env['api.format'] = :binary # there's no formatter for :binary, data will be returned "as is"
46 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 102 lines = last_response.body.split("\n")
103 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 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 106 end
106 107  
107 108 end
... ...