Skip to content

Commit

Permalink
1320: add example tests for file overwriting
Browse files Browse the repository at this point in the history
  • Loading branch information
kkoehn committed Oct 2, 2024
1 parent 972ee15 commit d27e358
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def execute
private

def import_task
upsert_files @proforma_task, @task
@task.assign_attributes(
user:,
title: @proforma_task.title,
Expand All @@ -37,7 +38,6 @@ def import_task
tests:,
model_solutions:
)
upsert_files @proforma_task, @task
delete_removed_files
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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') }
Expand All @@ -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
Expand Down Expand Up @@ -654,45 +654,45 @@
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

it 'imports everything correctly' do

Check failure on line 683 in spec/services/proforma_service/convert_proforma_task_to_task_spec.rb

View workflow job for this annotation

GitHub Actions / test

ProformaService::ConvertProformaTaskToTask#execute when proforma_task has been exported from task when files have been move around imports everything correctly Failure/Error: expect(convert_to_task_service).to have_attributes( id: task.id, files: have(1).item.and(include(have_attributes( id: test_files.first.id ))), model_solutions: have(1).item.and(include(have_attributes( id: model_solutions.first.id, files: have(1).item.and(include(have_attributes(id: task_files.first.id))) ))), tests: have(1).item.and(include(have_attributes( expected #<Task id: 485, title: "title", description: "description", internal_description: nil, uuid: "236e243...rivate", submission_restrictions: nil, external_resources: nil, grading_hints: nil, state_list: nil> to have attributes {:files => (have 1 item and include (have attributes {:id => 216})), :id => 485, :model_solutions => (have ...attributes {:files => (have 1 item and include (have attributes {:id => 215})), :id => 987654325}))} but had attributes {:files => [#<TaskFile id: 216, content: "content", path: "", name: "name", internal_description: "orig...nil, task_id: 485, meta_data: nil, testing_framework_id: nil, configuration: nil, parent_id: nil>]>} Diff: @@ -1,5 +1,5 @@ -:files => (have 1 item and include (have attributes {:id => 216})), +:files => [#<TaskFile id: 216, content: "content", path: "", name: "name", internal_description: "original test file", mime_type: nil, used_by_grader: true, visible: "yes", usage_by_lms: "display", fileable_type: "Task", fileable_id: 485, created_at: "2024-10-02 22:07:04.185524000 +0000", updated_at: "2024-10-02 22:07:04.185524000 +0000", xml_id: "229", parent_id: nil>], :id => 485, -:model_solutions => (have 1 item and include (have attributes {:files => (have 1 item and include (have attributes {:id => 217})), :id => 63})), -:tests => (have 1 item and include (have attributes {:files => (have 1 item and include (have attributes {:id => 215})), :id => 987654325})), +:model_solutions => #<ActiveRecord::Associations::CollectionProxy [#<ModelSolution id: 63, description: nil, internal_description: nil, xml_id: "ms_55", task_id: 485, created_at: "2024-10-02 22:07:04.173958000 +0000", updated_at: "2024-10-02 22:07:04.173958000 +0000", parent_id: nil>]>, +:tests => #<ActiveRecord::Associations::CollectionProxy [#<Test id: 70, created_at: "2024-10-02 22:07:04.246159000 +0000", updated_at: "2024-10-02 22:07:04.246159000 +0000", title: "replacement Test", description: nil, internal_description: nil, test_type: nil, xml_id: "987654325", validity: nil, timeout: nil, task_id: 485, meta_data: nil, testing_framework_id: nil, configuration: nil, parent_id: nil>]>,

Check failure on line 683 in spec/services/proforma_service/convert_proforma_task_to_task_spec.rb

View workflow job for this annotation

GitHub Actions / test

ProformaService::ConvertProformaTaskToTask#execute when proforma_task has been exported from task when files have been move around imports everything correctly Failure/Error: expect(convert_to_task_service).to have_attributes( id: task.id, files: have(1).item.and(include(have_attributes( id: test_files.first.id ))), model_solutions: have(1).item.and(include(have_attributes( id: model_solutions.first.id, files: have(1).item.and(include(have_attributes(id: task_files.first.id))) ))), tests: have(1).item.and(include(have_attributes( expected #<Task id: 17, title: "title", description: "description", internal_description: nil, uuid: "57c43f94...rivate", submission_restrictions: nil, external_resources: nil, grading_hints: nil, state_list: nil> to have attributes {:files => (have 1 item and include (have attributes {:id => 26})), :id => 17, :model_solutions => (have 1 ... attributes {:files => (have 1 item and include (have attributes {:id => 25})), :id => 987654325}))} but had attributes {:files => [#<TaskFile id: 26, content: "content", path: "", name: "name", internal_description: "origi... nil, task_id: 17, meta_data: nil, testing_framework_id: nil, configuration: nil, parent_id: nil>]>} Diff: @@ -1,5 +1,5 @@ -:files => (have 1 item and include (have attributes {:id => 26})), +:files => [#<TaskFile id: 26, content: "content", path: "", name: "name", internal_description: "original test file", mime_type: nil, used_by_grader: true, visible: "yes", usage_by_lms: "display", fileable_type: "Task", fileable_id: 17, created_at: "2024-10-02 22:09:17.324401000 +0000", updated_at: "2024-10-02 22:09:17.324401000 +0000", xml_id: "269", parent_id: nil>], :id => 17, -:model_solutions => (have 1 item and include (have attributes {:files => (have 1 item and include (have attributes {:id => 27})), :id => 9})), -:tests => (have 1 item and include (have attributes {:files => (have 1 item and include (have attributes {:id => 25})), :id => 987654325})), +:model_solutions => #<ActiveRecord::Associations::CollectionProxy [#<ModelSolution id: 9, description: nil, internal_description: nil, xml_id: "ms_86", task_id: 17, created_at: "2024-10-02 22:09:17.313059000 +0000", updated_at: "2024-10-02 22:09:17.313059000 +0000", parent_id: nil>]>, +:tests => #<ActiveRecord::Associations::CollectionProxy [#<Test id: 10, created_at: "2024-10-02 22:09:17.385328000 +0000", updated_at: "2024-10-02 22:09:17.385328000 +0000", title: "replacement Test", description: nil, internal_description: nil, test_type: nil, xml_id: "987654325", validity: nil, timeout: nil, task_id: 17, meta_data: nil, testing_framework_id: nil, configuration: nil, parent_id: nil>]>,
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
Expand All @@ -705,38 +705,38 @@

it 'imports taskfiles correctly' do

Check failure on line 706 in spec/services/proforma_service/convert_proforma_task_to_task_spec.rb

View workflow job for this annotation

GitHub Actions / test

ProformaService::ConvertProformaTaskToTask#execute when proforma_task has been exported from task when files have been move around when imported task is persisted imports taskfiles correctly Failure/Error: expect(task.files.first).to have_attributes( id: test_files.first.id, internal_description: test_files.first.internal_description ) expected nil to respond to :id, :internal_description with 0 arguments

Check failure on line 706 in spec/services/proforma_service/convert_proforma_task_to_task_spec.rb

View workflow job for this annotation

GitHub Actions / test

ProformaService::ConvertProformaTaskToTask#execute when proforma_task has been exported from task when files have been move around when imported task is persisted imports taskfiles correctly Failure/Error: expect(task.files.first).to have_attributes( id: test_files.first.id, internal_description: test_files.first.internal_description ) expected nil to respond to :id, :internal_description with 0 arguments
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

it 'imports everything correctly' do

Check failure on line 727 in spec/services/proforma_service/convert_proforma_task_to_task_spec.rb

View workflow job for this annotation

GitHub Actions / test

ProformaService::ConvertProformaTaskToTask#execute when proforma_task has been exported from task when files have been move around when imported task is persisted imports everything correctly Failure/Error: expect(task).to have_attributes( id: task.id, files: have(1).item.and(include(have_attributes( id: test_files.first.id ))), model_solutions: have(1).item.and(include(have_attributes( id: model_solutions.first.id, files: have(1).item.and(include(have_attributes(id: task_files.first.id))) ))), tests: have(1).item.and(include(have_attributes( expected #<Task id: 489, title: "title", description: "description", internal_description: nil, uuid: "379ef41...rivate", submission_restrictions: nil, external_resources: nil, grading_hints: nil, state_list: nil> to have attributes {:files => (have 1 item and include (have attributes {:id => 228})), :id => 489, :model_solutions => (have ...attributes {:files => (have 1 item and include (have attributes {:id => 227})), :id => 987654325}))} but had attributes {:files => #<ActiveRecord::Associations::CollectionProxy []>, :id => 489, :model_solutions => #<ActiveRecor...nil, task_id: 489, meta_data: nil, testing_framework_id: nil, configuration: nil, parent_id: nil>]>} Diff: @@ -1,5 +1,5 @@ -:files => (have 1 item and include (have attributes {:id => 228})), +:files => #<ActiveRecord::Associations::CollectionProxy []>, :id => 489, -:model_solutions => (have 1 item and include (have attributes {:files => (have 1 item and include (have attributes {:id => 229})), :id => 67})), -:tests => (have 1 item and include (have attributes {:files => (have 1 item and include (have attributes {:id => 227})), :id => 987654325})), +:model_solutions => #<ActiveRecord::Associations::CollectionProxy [#<ModelSolution id: 67, description: nil, internal_description: nil, xml_id: "ms_59", task_id: 489, created_at: "2024-10-02 22:07:05.735514000 +0000", updated_at: "2024-10-02 22:07:05.735514000 +0000", parent_id: nil>]>, +:tests => #<ActiveRecord::Associations::CollectionProxy [#<Test id: 78, created_at: "2024-10-02 22:07:05.807409000 +0000", updated_at: "2024-10-02 22:07:05.807409000 +0000", title: "replacement Test", description: nil, internal_description: nil, test_type: nil, xml_id: "987654325", validity: nil, timeout: nil, task_id: 489, meta_data: nil, testing_framework_id: nil, configuration: nil, parent_id: nil>]>,

Check failure on line 727 in spec/services/proforma_service/convert_proforma_task_to_task_spec.rb

View workflow job for this annotation

GitHub Actions / test

ProformaService::ConvertProformaTaskToTask#execute when proforma_task has been exported from task when files have been move around when imported task is persisted imports everything correctly Failure/Error: expect(task).to have_attributes( id: task.id, files: have(1).item.and(include(have_attributes( id: test_files.first.id ))), model_solutions: have(1).item.and(include(have_attributes( id: model_solutions.first.id, files: have(1).item.and(include(have_attributes(id: task_files.first.id))) ))), tests: have(1).item.and(include(have_attributes( expected #<Task id: 22, title: "title", description: "description", internal_description: nil, uuid: "ff79fdc1...rivate", submission_restrictions: nil, external_resources: nil, grading_hints: nil, state_list: nil> to have attributes {:files => (have 1 item and include (have attributes {:id => 41})), :id => 22, :model_solutions => (have 1 ... attributes {:files => (have 1 item and include (have attributes {:id => 40})), :id => 987654325}))} but had attributes {:files => #<ActiveRecord::Associations::CollectionProxy []>, :id => 22, :model_solutions => #<ActiveRecord... nil, task_id: 22, meta_data: nil, testing_framework_id: nil, configuration: nil, parent_id: nil>]>} Diff: @@ -1,5 +1,5 @@ -:files => (have 1 item and include (have attributes {:id => 41})), +:files => #<ActiveRecord::Associations::CollectionProxy []>, :id => 22, -:model_solutions => (have 1 item and include (have attributes {:files => (have 1 item and include (have attributes {:id => 42})), :id => 14})), -:tests => (have 1 item and include (have attributes {:files => (have 1 item and include (have attributes {:id => 40})), :id => 987654325})), +:model_solutions => #<ActiveRecord::Associations::CollectionProxy [#<ModelSolution id: 14, description: nil, internal_description: nil, xml_id: "ms_91", task_id: 22, created_at: "2024-10-02 22:09:18.891741000 +0000", updated_at: "2024-10-02 22:09:18.891741000 +0000", parent_id: nil>]>, +:tests => #<ActiveRecord::Associations::CollectionProxy [#<Test id: 20, created_at: "2024-10-02 22:09:18.961962000 +0000", updated_at: "2024-10-02 22:09:18.961962000 +0000", title: "replacement Test", description: nil, internal_description: nil, test_type: nil, xml_id: "987654325", validity: nil, timeout: nil, task_id: 22, meta_data: nil, testing_framework_id: nil, configuration: nil, parent_id: nil>]>,
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
Expand Down

0 comments on commit d27e358

Please sign in to comment.