mirror of
https://github.com/redmine/redmine.git
synced 2026-05-07 00:16:24 +02:00
Adds support for custom date format when importing a CSV file (#950).
git-svn-id: http://svn.redmine.org/redmine/trunk@14495 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
4
test/fixtures/files/import_dates.csv
vendored
Normal file
4
test/fixtures/files/import_dates.csv
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
subject;start;due;custom
|
||||
Valid dates;10/07/2015;12/08/2015;14/07/2015
|
||||
Invalid start date;04/15/2015;;
|
||||
Invalid custom date;;;04/15/2015
|
||||
|
@@ -69,13 +69,14 @@ class ImportsControllerTest < ActionController::TestCase
|
||||
import = generate_import
|
||||
|
||||
post :settings, :id => import.to_param,
|
||||
:import_settings => {:separator => ":", :wrapper => "|", :encoding => "UTF-8"}
|
||||
:import_settings => {:separator => ":", :wrapper => "|", :encoding => "UTF-8", :date_format => '%m/%d/%Y'}
|
||||
assert_redirected_to "/imports/#{import.to_param}/mapping"
|
||||
|
||||
import.reload
|
||||
assert_equal ":", import.settings['separator']
|
||||
assert_equal "|", import.settings['wrapper']
|
||||
assert_equal "UTF-8", import.settings['encoding']
|
||||
assert_equal '%m/%d/%Y', import.settings['date_format']
|
||||
end
|
||||
|
||||
def test_post_settings_should_update_total_items_count
|
||||
|
||||
@@ -78,6 +78,20 @@ class IssueImportTest < ActiveSupport::TestCase
|
||||
assert_equal [false, true, false], issues.map(&:is_private)
|
||||
end
|
||||
|
||||
def test_dates_should_be_parsed_using_date_format_setting
|
||||
field = IssueCustomField.generate!(:field_format => 'date', :is_for_all => true, :trackers => Tracker.all)
|
||||
import = generate_import_with_mapping('import_dates.csv')
|
||||
import.settings.merge!('date_format' => Import::DATE_FORMATS[1])
|
||||
import.mapping.merge!('subject' => '0', 'start_date' => '1', 'due_date' => '2', "cf_#{field.id}" => '3')
|
||||
import.save!
|
||||
|
||||
issue = new_record(Issue) { import.run } # only 1 valid issue
|
||||
assert_equal "Valid dates", issue.subject
|
||||
assert_equal Date.parse('2015-07-10'), issue.start_date
|
||||
assert_equal Date.parse('2015-08-12'), issue.due_date
|
||||
assert_equal '2015-07-14', issue.custom_field_value(field)
|
||||
end
|
||||
|
||||
def test_run_should_remove_the_file
|
||||
import = generate_import_with_mapping
|
||||
file_path = import.filepath
|
||||
|
||||
Reference in New Issue
Block a user