|
24 | 24 | end |
25 | 25 |
|
26 | 26 | describe '#execute' do |
27 | | - subject(:convert_to_task_service) { described_class.call(proforma_task:, user:, task:) } |
| 27 | + subject(:convert_to_task_service) { described_class.call(proforma_task:, user:, task:).reload } |
28 | 28 |
|
29 | 29 | let(:proforma_task) do |
30 | 30 | ProformaXML::Task.new( |
|
237 | 237 | end |
238 | 238 |
|
239 | 239 | it 'creates files with correct attributes' do |
240 | | - expect(convert_to_task_service.tests[1].files[0]).to have_attributes(convert_to_task_service.tests[0].files[0].attributes.merge('xml_id' => 'id-2')) |
241 | | - expect(convert_to_task_service.tests[2].files[0]).to have_attributes(convert_to_task_service.tests[0].files[0].attributes.merge('xml_id' => 'id-3')) |
| 240 | + attribute_exceptions = %w[id created_at fileable_id updated_at] |
| 241 | + expect(convert_to_task_service.tests[1].files[0]).to have_attributes(convert_to_task_service.tests[0].files[0].attributes.except(*attribute_exceptions).merge('xml_id' => 'id-2')) |
| 242 | + expect(convert_to_task_service.tests[2].files[0]).to have_attributes(convert_to_task_service.tests[0].files[0].attributes.except(*attribute_exceptions).merge('xml_id' => 'id-3')) |
242 | 243 | end |
243 | 244 |
|
244 | 245 | it 'creates separate copies of referenced file' do |
|
321 | 322 | internal_description: 'internal_description', |
322 | 323 | test_type: 'test_type', |
323 | 324 | files: test_files, |
324 | | - meta_data: test_meta_data |
| 325 | + meta_data: test_meta_data, |
| 326 | + configuration: |
325 | 327 | ) |
326 | 328 | end |
327 | 329 |
|
| 330 | + let(:configuration) {} |
328 | 331 | let(:test_meta_data) {} |
329 | 332 | let(:test_files) { [test_file] } |
330 | 333 | let(:test_file) do |
|
402 | 405 | end |
403 | 406 |
|
404 | 407 | context 'when test has custom configuration' do |
405 | | - let(:test) { build(:test, :with_unittest) } |
| 408 | + let(:configuration) { attributes_for(:test, :with_unittest)[:configuration] } |
406 | 409 |
|
407 | 410 | it 'creates a test with the supplied test configuration' do |
408 | 411 | expect(convert_to_task_service.tests.first).to have_attributes(configuration: test.configuration) |
409 | 412 | end |
410 | 413 | end |
411 | 414 |
|
412 | 415 | context 'when test has multiple custom configuration' do |
413 | | - let(:test) { build(:test, :with_multiple_custom_configurations) } |
| 416 | + let(:configuration) { attributes_for(:test, :with_multiple_custom_configurations)[:configuration] } |
414 | 417 |
|
415 | 418 | it 'creates a test with the supplied test configurations' do |
416 | 419 | expect(convert_to_task_service.tests.first).to have_attributes(configuration: test.configuration) |
|
420 | 423 | context 'when proforma_task has multiple tests' do |
421 | 424 | let(:tests) { [test, test2] } |
422 | 425 | let(:test2) do |
423 | | - ProformaXML::Test.new(files: test_files2) |
| 426 | + ProformaXML::Test.new( |
| 427 | + id: 'test_file_id', |
| 428 | + title: 'wild-title', |
| 429 | + files: test_files2 |
| 430 | + ) |
424 | 431 | end |
425 | 432 | let(:test_files2) { [test_file2] } |
426 | 433 | let(:test_file2) do |
|
473 | 480 | let(:task) do |
474 | 481 | create( |
475 | 482 | :task, |
| 483 | + user:, |
476 | 484 | title: 'task-title', |
477 | 485 | description: 'task-description', |
478 | 486 | internal_description: 'task-internal_description' |
|
579 | 587 |
|
580 | 588 | context 'when proforma_task has been exported from task' do |
581 | 589 | let(:proforma_task) { ProformaService::ConvertTaskToProformaTask.call(task:) } |
582 | | - let!(:task) { create(:task, files: task_files, tests:, model_solutions:, title: 'title') } |
| 590 | + let!(:task) { create(:task, user:, files: task_files, tests:, model_solutions:, title: 'title') } |
583 | 591 | let(:task_files) { build_list(:task_file, 1, :exportable, internal_description: 'original task file') } |
584 | 592 | let(:tests) { build_list(:test, 1, files: test_files) } |
585 | 593 | let(:test_files) { build_list(:task_file, 1, :exportable, internal_description: 'original test file') } |
|
605 | 613 | ) |
606 | 614 | end |
607 | 615 |
|
| 616 | + it 'does not update updated_at of unchanged files' do |
| 617 | + task_file_updated_at = task_files.first.updated_at |
| 618 | + test_file_updated_at = test_files.first.updated_at |
| 619 | + ms_file_update_at = model_solution_files.first.updated_at |
| 620 | + |
| 621 | + expect(convert_to_task_service).to have_attributes( |
| 622 | + files: have(1).item.and(include(have_attributes( |
| 623 | + updated_at: task_file_updated_at |
| 624 | + ))), |
| 625 | + model_solutions: have(1).item.and(include(have_attributes( |
| 626 | + files: have(1).item.and(include(have_attributes(updated_at: ms_file_update_at))) |
| 627 | + ))), |
| 628 | + tests: have(1).item.and(include(have_attributes( |
| 629 | + id: tests.first.id, |
| 630 | + files: have(1).item.and(include(have_attributes(updated_at: test_file_updated_at))) |
| 631 | + ))) |
| 632 | + ) |
| 633 | + end |
| 634 | + |
608 | 635 | context 'when files have been deleted' do |
609 | 636 | context 'when task files have been deleted' do |
610 | | - before { task.files = [] } |
| 637 | + before { proforma_task.files = [] } |
611 | 638 |
|
612 | 639 | it 'imports task files correctly' do |
613 | 640 | expect(convert_to_task_service.files).to be_empty |
614 | 641 | end |
615 | 642 |
|
616 | 643 | it 'saves the task correctly' do |
617 | | - convert_to_task_service.save |
618 | | - task.reload |
619 | | - expect(task.files).to be_empty |
| 644 | + convert_to_task_service |
| 645 | + expect(task.reload.files).to be_empty |
620 | 646 | end |
621 | 647 | end |
622 | 648 |
|
623 | 649 | context 'when test files have been deleted' do |
624 | | - before { task.tests.first.files = [] } |
| 650 | + before { proforma_task.tests.first.files = [] } |
625 | 651 |
|
626 | 652 | it 'imports test files correctly' do |
627 | 653 | expect(convert_to_task_service.tests.first.files).to be_empty |
628 | 654 | end |
629 | 655 |
|
630 | 656 | it 'saves the task correctly' do |
631 | | - convert_to_task_service.save |
632 | | - task.reload |
| 657 | + convert_to_task_service |
633 | 658 | expect(task.tests.first.files).to be_empty |
634 | 659 | end |
635 | 660 | end |
636 | 661 |
|
637 | 662 | context 'when model solution files have been deleted' do |
638 | | - before { task.model_solutions.first.files = [] } |
| 663 | + before { proforma_task.model_solutions.first.files = [] } |
639 | 664 |
|
640 | 665 | it 'imports model solution files correctly' do |
641 | 666 | expect(convert_to_task_service.model_solutions.first.files).to be_empty |
642 | 667 | end |
643 | 668 |
|
644 | 669 | it 'saves the task correctly' do |
645 | | - convert_to_task_service.save |
646 | | - task.reload |
| 670 | + convert_to_task_service |
647 | 671 | expect(task.model_solutions.first.files).to be_empty |
648 | 672 | end |
649 | 673 | end |
650 | 674 | end |
651 | 675 |
|
652 | | - context 'when files have been move around' do |
| 676 | + context 'when files have been moved around' do |
653 | 677 | before do |
654 | 678 | task_file = proforma_task.files.first |
655 | 679 | test_file = proforma_task.tests.first.files.first |
|
691 | 715 | files: have(1).item.and(include(have_attributes(id: task_files.first.id))) |
692 | 716 | ))), |
693 | 717 | tests: have(1).item.and(include(have_attributes( |
694 | | - id: 987_654_325, |
| 718 | + xml_id: '987654325', |
695 | 719 | files: have(1).item.and(include(have_attributes(id: model_solution_files.first.id))) |
696 | 720 | ))) |
697 | 721 | ) |
698 | 722 | end |
699 | 723 |
|
700 | 724 | context 'when imported task is persisted' do |
701 | 725 | before do |
702 | | - convert_to_task_service.save |
| 726 | + convert_to_task_service.save! |
703 | 727 | task.reload |
704 | 728 | end |
705 | 729 |
|
|
735 | 759 | files: have(1).item.and(include(have_attributes(id: task_files.first.id))) |
736 | 760 | ))), |
737 | 761 | tests: have(1).item.and(include(have_attributes( |
738 | | - id: 987_654_325, |
| 762 | + xml_id: '987654325', |
739 | 763 | files: have(1).item.and(include(have_attributes(id: model_solution_files.first.id))) |
740 | 764 | ))) |
741 | 765 | ) |
|
0 commit comments