diff --git a/app/services/proforma_service/convert_proforma_task_to_task.rb b/app/services/proforma_service/convert_proforma_task_to_task.rb index 5e7a22426..42b7a2ba9 100644 --- a/app/services/proforma_service/convert_proforma_task_to_task.rb +++ b/app/services/proforma_service/convert_proforma_task_to_task.rb @@ -19,6 +19,7 @@ def execute private def import_task + upsert_files @proforma_task, @task @task.assign_attributes( user:, title: @proforma_task.title, @@ -37,7 +38,6 @@ def import_task tests:, model_solutions: ) - upsert_files @proforma_task, @task delete_removed_files end diff --git a/spec/services/proforma_service/convert_proforma_task_to_task_spec.rb b/spec/services/proforma_service/convert_proforma_task_to_task_spec.rb index 3ce29715c..7e9b88907 100644 --- a/spec/services/proforma_service/convert_proforma_task_to_task_spec.rb +++ b/spec/services/proforma_service/convert_proforma_task_to_task_spec.rb @@ -579,7 +579,7 @@ context 'when proforma_task has been exported from task' do let(:proforma_task) { ProformaService::ConvertTaskToProformaTask.call(task:) } - let(:task) { create(:task, files: task_files, tests:, model_solutions:, title: 'title') } + let!(:task) { create(:task, files: task_files, tests:, model_solutions:, title: 'title') } let(:task_files) { build_list(:task_file, 1, :exportable, internal_description: 'original task file') } let(:tests) { build_list(:test, 1, files: test_files) } let(:test_files) { build_list(:task_file, 1, :exportable, internal_description: 'original test file') } @@ -596,11 +596,11 @@ ))), model_solutions: have(1).item.and(include(have_attributes( id: model_solutions.first.id, - files: include(have_attributes(id: model_solutions.first.files.first.id)) + files: have(1).item.and(include(have_attributes(id: model_solutions.first.files.first.id))) ))), tests: have(1).item.and(include(have_attributes( id: tests.first.id, - files: include(have_attributes(id: tests.first.files.first.id)) + files: have(1).item.and(include(have_attributes(id: tests.first.files.first.id))) ))) ) end @@ -654,29 +654,29 @@ task_file = proforma_task.files.first test_file = proforma_task.tests.first.files.first model_solution_file = proforma_task.model_solutions.first.files.first - proforma_task.files = [model_solution_file] - proforma_task.tests.first.files = [task_file] - proforma_task.model_solutions.first.files = [test_file] + proforma_task.files = [test_file] + proforma_task.tests = [ProformaXML::Test.new(title: 'replacement Test', id: 987_654_325, files: [model_solution_file])] + proforma_task.model_solutions.first.files = [task_file] end it 'imports taskfiles correctly' do expect(convert_to_task_service.files.first).to have_attributes( - id: model_solution_files.first.id, - internal_description: model_solution_files.first.internal_description + id: test_files.first.id, + internal_description: test_files.first.internal_description ) end it 'imports testfiles correctly' do expect(convert_to_task_service.tests.first.files.first).to have_attributes( - id: task_files.first.id, - internal_description: task_files.first.internal_description + id: model_solution_files.first.id, + internal_description: model_solution_files.first.internal_description ) end it 'imports msfiles correctly' do expect(convert_to_task_service.model_solutions.first.files.first).to have_attributes( - id: test_files.first.id, - internal_description: test_files.first.internal_description + id: task_files.first.id, + internal_description: task_files.first.internal_description ) end @@ -684,15 +684,15 @@ expect(convert_to_task_service).to have_attributes( id: task.id, files: have(1).item.and(include(have_attributes( - id: model_solution_files.first.id - ))), + id: test_files.first.id + ))), model_solutions: have(1).item.and(include(have_attributes( id: model_solutions.first.id, - files: include(have_attributes(id: test_files.first.id)) + files: have(1).item.and(include(have_attributes(id: task_files.first.id))) ))), tests: have(1).item.and(include(have_attributes( - id: tests.first.id, - files: include(have_attributes(id: task_files.first.id)) + id: 987_654_325, + files: have(1).item.and(include(have_attributes(id: model_solution_files.first.id))) ))) ) end @@ -705,22 +705,22 @@ it 'imports taskfiles correctly' do expect(task.files.first).to have_attributes( - id: model_solution_files.first.id, - internal_description: model_solution_files.first.internal_description + id: test_files.first.id, + internal_description: test_files.first.internal_description ) end it 'imports testfiles correctly' do expect(task.tests.first.files.first).to have_attributes( - id: task_files.first.id, - internal_description: task_files.first.internal_description + id: model_solution_files.first.id, + internal_description: model_solution_files.first.internal_description ) end it 'imports msfiles correctly' do expect(task.model_solutions.first.files.first).to have_attributes( - id: test_files.first.id, - internal_description: test_files.first.internal_description + id: task_files.first.id, + internal_description: task_files.first.internal_description ) end @@ -728,15 +728,15 @@ expect(task).to have_attributes( id: task.id, files: have(1).item.and(include(have_attributes( - id: model_solution_files.first.id - ))), + id: test_files.first.id + ))), model_solutions: have(1).item.and(include(have_attributes( id: model_solutions.first.id, - files: include(have_attributes(id: test_files.first.id)) + files: have(1).item.and(include(have_attributes(id: task_files.first.id))) ))), tests: have(1).item.and(include(have_attributes( - id: tests.first.id, - files: include(have_attributes(id: task_files.first.id)) + id: 987_654_325, + files: have(1).item.and(include(have_attributes(id: model_solution_files.first.id))) ))) ) end