Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. # Redmine - project management software
  2. # Copyright (C) 2006-2015 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 IssueImportTest < ActiveSupport::TestCase
  19. fixtures :projects, :enabled_modules,
  20. :users, :email_addresses,
  21. :roles, :members, :member_roles,
  22. :issues, :issue_statuses,
  23. :trackers, :projects_trackers,
  24. :versions,
  25. :issue_categories,
  26. :enumerations,
  27. :workflows,
  28. :custom_fields,
  29. :custom_values,
  30. :custom_fields_projects,
  31. :custom_fields_trackers
  32. def test_create_versions_should_create_missing_versions
  33. import = generate_import_with_mapping
  34. import.mapping.merge!('fixed_version' => '9', 'create_versions' => '1')
  35. import.save!
  36. version = new_record(Version) do
  37. assert_difference 'Issue.count', 3 do
  38. import.run
  39. end
  40. end
  41. assert_equal '2.1', version.name
  42. end
  43. def test_create_categories_should_create_missing_categories
  44. import = generate_import_with_mapping
  45. import.mapping.merge!('category' => '10', 'create_categories' => '1')
  46. import.save!
  47. category = new_record(IssueCategory) do
  48. assert_difference 'Issue.count', 3 do
  49. import.run
  50. end
  51. end
  52. assert_equal 'New category', category.name
  53. end
  54. def test_parent_should_be_set
  55. import = generate_import_with_mapping
  56. import.mapping.merge!('parent_issue_id' => '5')
  57. import.save!
  58. issues = new_records(Issue, 3) { import.run }
  59. assert_nil issues[0].parent
  60. assert_equal issues[0].id, issues[1].parent_id
  61. assert_equal 2, issues[2].parent_id
  62. end
  63. def test_assignee_should_be_set
  64. import = generate_import_with_mapping
  65. import.mapping.merge!('assigned_to' => '11')
  66. import.save!
  67. issues = new_records(Issue, 3) { import.run }
  68. assert_equal [User.find(3), nil, nil], issues.map(&:assigned_to)
  69. end
  70. def test_user_custom_field_should_be_set
  71. field = IssueCustomField.generate!(:field_format => 'user', :is_for_all => true, :trackers => Tracker.all)
  72. import = generate_import_with_mapping
  73. import.mapping.merge!("cf_#{field.id}" => '11')
  74. import.save!
  75. issues = new_records(Issue, 3) { import.run }
  76. assert_equal '3', issues.first.custom_field_value(field)
  77. end
  78. def test_is_private_should_be_set_based_on_user_locale
  79. import = generate_import_with_mapping
  80. import.mapping.merge!('is_private' => '6')
  81. import.save!
  82. issues = new_records(Issue, 3) { import.run }
  83. assert_equal [false, true, false], issues.map(&:is_private)
  84. end
  85. def test_dates_should_be_parsed_using_date_format_setting
  86. field = IssueCustomField.generate!(:field_format => 'date', :is_for_all => true, :trackers => Tracker.all)
  87. import = generate_import_with_mapping('import_dates.csv')
  88. import.settings.merge!('date_format' => Import::DATE_FORMATS[1])
  89. import.mapping.merge!('subject' => '0', 'start_date' => '1', 'due_date' => '2', "cf_#{field.id}" => '3')
  90. import.save!
  91. issue = new_record(Issue) { import.run } # only 1 valid issue
  92. assert_equal "Valid dates", issue.subject
  93. assert_equal Date.parse('2015-07-10'), issue.start_date
  94. assert_equal Date.parse('2015-08-12'), issue.due_date
  95. assert_equal '2015-07-14', issue.custom_field_value(field)
  96. end
  97. def test_date_format_should_default_to_user_language
  98. user = User.generate!(:language => 'fr')
  99. import = Import.new
  100. import.user = user
  101. assert_nil import.settings['date_format']
  102. import.set_default_settings
  103. assert_equal '%d/%m/%Y', import.settings['date_format']
  104. end
  105. def test_run_should_remove_the_file
  106. import = generate_import_with_mapping
  107. file_path = import.filepath
  108. assert File.exists?(file_path)
  109. import.run
  110. assert !File.exists?(file_path)
  111. end
  112. end