Skip to content

Commit 9c9206d

Browse files
committed
1320: add example tests for file overwriting
1 parent 86c4ee9 commit 9c9206d

File tree

2 files changed

+29
-29
lines changed

2 files changed

+29
-29
lines changed

app/services/proforma_service/convert_proforma_task_to_task.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ def execute
1919
private
2020

2121
def import_task
22+
upsert_files @proforma_task, @task
2223
@task.assign_attributes(
2324
user:,
2425
title: @proforma_task.title,
@@ -37,7 +38,6 @@ def import_task
3738
tests:,
3839
model_solutions:
3940
)
40-
upsert_files @proforma_task, @task
4141
delete_removed_files
4242
end
4343

spec/services/proforma_service/convert_proforma_task_to_task_spec.rb

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -579,7 +579,7 @@
579579

580580
context 'when proforma_task has been exported from task' do
581581
let(:proforma_task) { ProformaService::ConvertTaskToProformaTask.call(task:) }
582-
let(:task) { create(:task, files: task_files, tests:, model_solutions:, title: 'title') }
582+
let!(:task) { create(:task, files: task_files, tests:, model_solutions:, title: 'title') }
583583
let(:task_files) { build_list(:task_file, 1, :exportable, internal_description: 'original task file') }
584584
let(:tests) { build_list(:test, 1, files: test_files) }
585585
let(:test_files) { build_list(:task_file, 1, :exportable, internal_description: 'original test file') }
@@ -596,11 +596,11 @@
596596
))),
597597
model_solutions: have(1).item.and(include(have_attributes(
598598
id: model_solutions.first.id,
599-
files: include(have_attributes(id: model_solutions.first.files.first.id))
599+
files: have(1).item.and(include(have_attributes(id: model_solutions.first.files.first.id)))
600600
))),
601601
tests: have(1).item.and(include(have_attributes(
602602
id: tests.first.id,
603-
files: include(have_attributes(id: tests.first.files.first.id))
603+
files: have(1).item.and(include(have_attributes(id: tests.first.files.first.id)))
604604
)))
605605
)
606606
end
@@ -654,45 +654,45 @@
654654
task_file = proforma_task.files.first
655655
test_file = proforma_task.tests.first.files.first
656656
model_solution_file = proforma_task.model_solutions.first.files.first
657-
proforma_task.files = [model_solution_file]
658-
proforma_task.tests.first.files = [task_file]
659-
proforma_task.model_solutions.first.files = [test_file]
657+
proforma_task.files = [test_file]
658+
proforma_task.tests = [ProformaXML::Test.new(title: 'replacement Test', id: 987_654_325, files: [model_solution_file])]
659+
proforma_task.model_solutions.first.files = [task_file]
660660
end
661661

662662
it 'imports taskfiles correctly' do
663663
expect(convert_to_task_service.files.first).to have_attributes(
664-
id: model_solution_files.first.id,
665-
internal_description: model_solution_files.first.internal_description
664+
id: test_files.first.id,
665+
internal_description: test_files.first.internal_description
666666
)
667667
end
668668

669669
it 'imports testfiles correctly' do
670670
expect(convert_to_task_service.tests.first.files.first).to have_attributes(
671-
id: task_files.first.id,
672-
internal_description: task_files.first.internal_description
671+
id: model_solution_files.first.id,
672+
internal_description: model_solution_files.first.internal_description
673673
)
674674
end
675675

676676
it 'imports msfiles correctly' do
677677
expect(convert_to_task_service.model_solutions.first.files.first).to have_attributes(
678-
id: test_files.first.id,
679-
internal_description: test_files.first.internal_description
678+
id: task_files.first.id,
679+
internal_description: task_files.first.internal_description
680680
)
681681
end
682682

683683
it 'imports everything correctly' do
684684
expect(convert_to_task_service).to have_attributes(
685685
id: task.id,
686686
files: have(1).item.and(include(have_attributes(
687-
id: model_solution_files.first.id
688-
))),
687+
id: test_files.first.id
688+
))),
689689
model_solutions: have(1).item.and(include(have_attributes(
690690
id: model_solutions.first.id,
691-
files: include(have_attributes(id: test_files.first.id))
691+
files: have(1).item.and(include(have_attributes(id: task_files.first.id)))
692692
))),
693693
tests: have(1).item.and(include(have_attributes(
694-
id: tests.first.id,
695-
files: include(have_attributes(id: task_files.first.id))
694+
id: 987_654_325,
695+
files: have(1).item.and(include(have_attributes(id: model_solution_files.first.id)))
696696
)))
697697
)
698698
end
@@ -705,38 +705,38 @@
705705

706706
it 'imports taskfiles correctly' do
707707
expect(task.files.first).to have_attributes(
708-
id: model_solution_files.first.id,
709-
internal_description: model_solution_files.first.internal_description
708+
id: test_files.first.id,
709+
internal_description: test_files.first.internal_description
710710
)
711711
end
712712

713713
it 'imports testfiles correctly' do
714714
expect(task.tests.first.files.first).to have_attributes(
715-
id: task_files.first.id,
716-
internal_description: task_files.first.internal_description
715+
id: model_solution_files.first.id,
716+
internal_description: model_solution_files.first.internal_description
717717
)
718718
end
719719

720720
it 'imports msfiles correctly' do
721721
expect(task.model_solutions.first.files.first).to have_attributes(
722-
id: test_files.first.id,
723-
internal_description: test_files.first.internal_description
722+
id: task_files.first.id,
723+
internal_description: task_files.first.internal_description
724724
)
725725
end
726726

727727
it 'imports everything correctly' do
728728
expect(task).to have_attributes(
729729
id: task.id,
730730
files: have(1).item.and(include(have_attributes(
731-
id: model_solution_files.first.id
732-
))),
731+
id: test_files.first.id
732+
))),
733733
model_solutions: have(1).item.and(include(have_attributes(
734734
id: model_solutions.first.id,
735-
files: include(have_attributes(id: test_files.first.id))
735+
files: have(1).item.and(include(have_attributes(id: task_files.first.id)))
736736
))),
737737
tests: have(1).item.and(include(have_attributes(
738-
id: tests.first.id,
739-
files: include(have_attributes(id: task_files.first.id))
738+
id: 987_654_325,
739+
files: have(1).item.and(include(have_attributes(id: model_solution_files.first.id)))
740740
)))
741741
)
742742
end

0 commit comments

Comments
 (0)