diff options
author | Toshi MARUYAMA <marutosijp2@yahoo.co.jp> | 2011-11-24 09:43:01 +0000 |
---|---|---|
committer | Toshi MARUYAMA <marutosijp2@yahoo.co.jp> | 2011-11-24 09:43:01 +0000 |
commit | f936b7b5a4ecd335f0464adb07d629d7c4f6b081 (patch) | |
tree | 70837876ecff9a57b291caec9a3c74fdb15f4e6c /test/unit/lib | |
parent | be29227c12da043996cf05a489fa6b7ef26bea81 (diff) | |
download | redmine-f936b7b5a4ecd335f0464adb07d629d7c4f6b081.tar.gz redmine-f936b7b5a4ecd335f0464adb07d629d7c4f6b081.zip |
pdf: lib: add the method to return attachment from filename and encoding (#3261)
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@7912 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'test/unit/lib')
-rw-r--r-- | test/unit/lib/redmine/export/pdf_test.rb | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/test/unit/lib/redmine/export/pdf_test.rb b/test/unit/lib/redmine/export/pdf_test.rb index d80741cdd..9b89958b8 100644 --- a/test/unit/lib/redmine/export/pdf_test.rb +++ b/test/unit/lib/redmine/export/pdf_test.rb @@ -19,6 +19,8 @@ require File.expand_path('../../../../../test_helper', __FILE__) require 'iconv' class PdfTest < ActiveSupport::TestCase + fixtures :users, :projects, :roles, :members, :member_roles, + :enabled_modules, :issues, :trackers, :attachments def test_fix_text_encoding_nil assert_equal '', Redmine::Export::PDF::RDMPdfEncoding::rdm_from_utf8(nil, "UTF-8") @@ -87,4 +89,39 @@ class PdfTest < ActiveSupport::TestCase assert_equal "Texte encod? en ISO-8859-1", txt_1 assert_equal "?a?b?c?d?e test", txt_2 end + + def test_attach + Attachment.storage_path = "#{Rails.root}/test/fixtures/files" + + str2 = "\x83e\x83X\x83g" + str2.force_encoding("ASCII-8BIT") if str2.respond_to?(:force_encoding) + encoding = ( RUBY_PLATFORM == 'java' ? "SJIS" : "CP932" ) + + a1 = Attachment.find(17) + a2 = Attachment.find(19) + + User.current = User.find(1) + assert a1.readable? + assert a1.visible? + assert a2.readable? + assert a2.visible? + + aa1 = Redmine::Export::PDF::RDMPdfEncoding::attach(Attachment.all, "Testfile.PNG", "UTF-8") + assert_equal 17, aa1.id + aa2 = Redmine::Export::PDF::RDMPdfEncoding::attach(Attachment.all, "test#{str2}.png", encoding) + assert_equal 19, aa2.id + + User.current = nil + assert a1.readable? + assert (! a1.visible?) + assert a2.readable? + assert (! a2.visible?) + + aa1 = Redmine::Export::PDF::RDMPdfEncoding::attach(Attachment.all, "Testfile.PNG", "UTF-8") + assert_equal nil, aa1 + aa2 = Redmine::Export::PDF::RDMPdfEncoding::attach(Attachment.all, "test#{str2}.png", encoding) + assert_equal nil, aa2 + + set_tmp_attachments_directory + end end |