]> source.dussan.org Git - redmine.git/commitdiff
Merged r22112 from trunk to 5.0-stable (#38254).
authorGo MAEDA <maeda@farend.jp>
Fri, 24 Feb 2023 04:44:36 +0000 (04:44 +0000)
committerGo MAEDA <maeda@farend.jp>
Fri, 24 Feb 2023 04:44:36 +0000 (04:44 +0000)
git-svn-id: https://svn.redmine.org/redmine/branches/5.0-stable@22114 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/models/time_entry_import.rb
test/unit/time_entry_import_test.rb

index f00b24f613a9966eb89ee2cea3b19cfed016396e..8e336083a69f754a01752c8bcd01de148cc8ee62 100644 (file)
@@ -85,6 +85,7 @@ class TimeEntryImport < Import
   def build_object(row, item)
     object = TimeEntry.new
     object.author = user
+    object.project = project
 
     activity_id = nil
     if activity
index 9f2cb6cc2a1e5b2282ac9977410ae2727bf97336..5ab0c096f020aa6f51d05264b55e6b4f6d927017 100644 (file)
@@ -165,6 +165,33 @@ class TimeEntryImportTest < ActiveSupport::TestCase
     assert_equal 2, fourth.user_id
   end
 
+  def test_imports_custom_field_with_user_format
+    cf = TimeEntryCustomField.create! name: 'User Field', field_format: 'user'
+    import = generate_import
+    import.settings = {
+      'separator' => ';', 'wrapper' => '"', 'encoding' => 'UTF-8',
+      'mapping' => {
+        'project_id' => '1',
+        'activity'   => 'value:10',
+        'issue_id'   => '1',
+        'spent_on'   => '2',
+        'hours'      => '3',
+        'comments'   => '4',
+        'user'       => '7',
+        "cf_#{cf.id}" => '7'
+      }
+    }
+    import.save!
+    first, second, third, fourth = new_records(TimeEntry, 4) {import.run}
+    jsmith = User.find_by_login 'jsmith'
+    dlopper = User.find_by_login 'dlopper'
+
+    assert_equal dlopper.id, third.custom_values.where(custom_field: cf.id).first.value.to_i
+    assert_equal jsmith.id, fourth.custom_values.where(custom_field: cf.id).first.value.to_i
+    assert_equal jsmith.id, first.custom_values.where(custom_field: cf.id).first.value.to_i
+    assert_equal jsmith.id, second.custom_values.where(custom_field: cf.id).first.value.to_i
+  end
+
   protected
 
   def generate_import(fixture_name='import_time_entries.csv')