Defect #38254 » 0001-fix-import-of-user-references-in-time-entry-custom-f.patch
| app/models/time_entry_import.rb | ||
|---|---|---|
| 116 | 116 | |
| 117 | 117 |
if issue_id = row_value(row, 'issue_id').presence |
| 118 | 118 |
attributes[:issue_id] = issue_id |
| 119 |
object.project = issue_project(issue_id) |
|
| 119 | 120 |
else |
| 120 | 121 |
attributes[:project_id] = project.id |
| 122 |
object.project = project |
|
| 121 | 123 |
end |
| 122 | 124 | |
| 123 | 125 |
attributes['custom_field_values'] = object.custom_field_values.inject({}) do |h, v|
|
| ... | ... | |
| 137 | 139 |
object.send(:safe_attributes=, attributes, user) |
| 138 | 140 |
object |
| 139 | 141 |
end |
| 142 | ||
| 143 |
def issue_project(issue_id) |
|
| 144 |
if issue_project_id = Issue.where(id: issue_id).limit(1).pluck(:project_id).first |
|
| 145 |
(@projects_cache ||= {})[issue_project_id] ||= allowed_target_projects.find_by_id(issue_project_id)
|
|
| 146 |
end |
|
| 147 |
end |
|
| 140 | 148 |
end |
| test/unit/time_entry_import_test.rb | ||
|---|---|---|
| 187 | 187 |
assert_equal 1, fourth.project_id |
| 188 | 188 |
end |
| 189 | 189 | |
| 190 |
def test_imports_custom_field_with_user_format |
|
| 191 |
cf = TimeEntryCustomField.create! name: 'User Field', field_format: 'user' |
|
| 192 |
import = generate_import |
|
| 193 |
import.settings = {
|
|
| 194 |
'separator' => ';', 'wrapper' => '"', 'encoding' => 'UTF-8', |
|
| 195 |
'mapping' => {
|
|
| 196 |
'project_id' => '1', |
|
| 197 |
'activity' => 'value:10', |
|
| 198 |
'issue_id' => '1', |
|
| 199 |
'spent_on' => '2', |
|
| 200 |
'hours' => '3', |
|
| 201 |
'comments' => '4', |
|
| 202 |
'user' => '7', |
|
| 203 |
"cf_#{cf.id}" => '7'
|
|
| 204 |
} |
|
| 205 |
} |
|
| 206 |
import.save! |
|
| 207 |
first, second, third, fourth = new_records(TimeEntry, 4) {import.run}
|
|
| 208 |
jsmith = User.find_by_login 'jsmith' |
|
| 209 |
dlopper = User.find_by_login 'dlopper' |
|
| 210 | ||
| 211 |
assert_equal dlopper.id, third.custom_values.where(custom_field: cf.id).first.value.to_i |
|
| 212 |
assert_equal jsmith.id, fourth.custom_values.where(custom_field: cf.id).first.value.to_i |
|
| 213 |
assert_equal jsmith.id, first.custom_values.where(custom_field: cf.id).first.value.to_i |
|
| 214 |
assert_equal jsmith.id, second.custom_values.where(custom_field: cf.id).first.value.to_i |
|
| 215 |
end |
|
| 216 | ||
| 190 | 217 |
protected |
| 191 | 218 | |
| 192 | 219 |
def generate_import(fixture_name='import_time_entries.csv') |