Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

csv_test.rb 1.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. # Redmine - project management software
  2. # Copyright (C) 2006-2017 Jean-Philippe Lang
  3. #
  4. # This program is free software; you can redistribute it and/or
  5. # modify it under the terms of the GNU General Public License
  6. # as published by the Free Software Foundation; either version 2
  7. # of the License, or (at your option) any later version.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU General Public License
  15. # along with this program; if not, write to the Free Software
  16. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  17. require File.expand_path('../../../../../test_helper', __FILE__)
  18. class CsvTest < ActiveSupport::TestCase
  19. include Redmine::I18n
  20. BOM = "\xEF\xBB\xBF".force_encoding('UTF-8')
  21. def test_should_include_bom_when_utf8_encoded
  22. with_locale 'sk' do
  23. string = Redmine::Export::CSV.generate {|csv| csv << %w(Foo Bar)}
  24. assert_equal 'UTF-8', string.encoding.name
  25. assert string.starts_with?(BOM)
  26. end
  27. end
  28. def test_generate_should_return_strings_with_given_encoding
  29. with_locale 'en' do
  30. string = Redmine::Export::CSV.generate({encoding: 'ISO-8859-3'}) {|csv| csv << %w(Foo Bar)}
  31. assert_equal 'ISO-8859-3', string.encoding.name
  32. assert_not_equal l(:general_csv_encoding), string.encoding.name
  33. end
  34. end
  35. def test_generate_should_return_strings_with_general_csv_encoding_if_invalid_encoding_is_given
  36. with_locale 'en' do
  37. string = Redmine::Export::CSV.generate({encoding: 'invalid-encoding-name'}) {|csv| csv << %w(Foo Bar)}
  38. assert_equal l(:general_csv_encoding), string.encoding.name
  39. end
  40. end
  41. end