From b19b4d74e08858d62baeb959ace422002dc66aaf Mon Sep 17 00:00:00 2001 From: tatsus Date: Sun, 27 Oct 2013 19:13:26 +0900 Subject: [PATCH 1/2] Fix a bug which cannot be imported correctly when using underscore and number for user.login --- app/controllers/importer_controller.rb | 8 +++----- test/samples/AllStandardBlankFields.csv | 3 +++ test/samples/NumberAsStringFields.csv | 2 ++ 3 files changed, 8 insertions(+), 5 deletions(-) create mode 100644 test/samples/AllStandardBlankFields.csv create mode 100644 test/samples/NumberAsStringFields.csv diff --git a/app/controllers/importer_controller.rb b/app/controllers/importer_controller.rb index 87982e9..ca3d668 100644 --- a/app/controllers/importer_controller.rb +++ b/app/controllers/importer_controller.rb @@ -49,7 +49,6 @@ def match @samples = [] CSV.new(iip.csv_data, {:headers=>true, - :converters => :all, :encoding=>iip.encoding, :quote_char=>iip.quote_char, :col_sep=>iip.col_sep}).each do |row| @@ -226,7 +225,6 @@ def result end CSV.new(iip.csv_data, {:headers=>true, - :converters => :all, :encoding=>iip.encoding, :quote_char=>iip.quote_char, :col_sep=>iip.col_sep}).each do |row| @@ -255,7 +253,7 @@ def result category.save end assigned_to = row[attrs_map["assigned_to"]] != nil ? user_for_login!(row[attrs_map["assigned_to"]]) : nil - fixed_version_name = row[attrs_map["fixed_version"]] + fixed_version_name = row[attrs_map["fixed_version"]].blank? ? nil : row[attrs_map["fixed_version"]] fixed_version_id = fixed_version_name ? version_id_for_name!(project,fixed_version_name,add_versions) : nil watchers = row[attrs_map["watchers"]] # new issue or find exists one @@ -343,8 +341,8 @@ def result # optional attributes issue.description = row[attrs_map["description"]] || issue.description issue.category_id = category != nil ? category.id : issue.category_id - issue.start_date = row[attrs_map["start_date"]] || issue.start_date - issue.due_date = row[attrs_map["due_date"]] || issue.due_date + issue.start_date = row[attrs_map["start_date"]].blank? ? nil : Date.parse(row[attrs_map["start_date"]]) + issue.due_date = row[attrs_map["due_date"]].blank? ? nil : Date.parse(row[attrs_map["due_date"]]) issue.assigned_to_id = assigned_to != nil ? assigned_to.id : issue.assigned_to_id issue.fixed_version_id = fixed_version_id != nil ? fixed_version_id : issue.fixed_version_id issue.done_ratio = row[attrs_map["done_ratio"]] || issue.done_ratio diff --git a/test/samples/AllStandardBlankFields.csv b/test/samples/AllStandardBlankFields.csv new file mode 100644 index 0000000..e6dcf75 --- /dev/null +++ b/test/samples/AllStandardBlankFields.csv @@ -0,0 +1,3 @@ +"Subject","Description","Assigned To","Fixed version","Author","Category","Priority","Tracker","Status","Start date","Due date","Done Ratio","Estimated hours","Watchers" +"A blank task","","","","","","","","",,,,,"" +"A blank task",,,,"",,,,,,,,, diff --git a/test/samples/NumberAsStringFields.csv b/test/samples/NumberAsStringFields.csv new file mode 100644 index 0000000..93e9914 --- /dev/null +++ b/test/samples/NumberAsStringFields.csv @@ -0,0 +1,2 @@ +"Subject","Description","Assigned To","Fixed version","Author","Category","Priority","Tracker","Status","Start date","Due date","Done Ratio","Estimated hours","Watchers" +"A number task","","100_001","9.99","100_001","","","","",,,,,"" From 30a7041a151306eaa634853b06857faa628ff67e Mon Sep 17 00:00:00 2001 From: tatsus Date: Sun, 27 Oct 2013 19:19:44 +0900 Subject: [PATCH 2/2] Fix error message --- app/controllers/importer_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/importer_controller.rb b/app/controllers/importer_controller.rb index ca3d668..ef50561 100644 --- a/app/controllers/importer_controller.rb +++ b/app/controllers/importer_controller.rb @@ -426,7 +426,7 @@ def result @failed_issues[@failed_count] = row flash_message(:warning, "The following data-validation errors occurred on issue #{@failed_count} in the list below") issue.errors.each do |attr, error_message| - flash_message(:warning, "  "+error_message) + flash_message(:warning, "  #{error_message}") end else if unique_field