|
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 |
|
605 | 612 | ) |
606 | 613 | end |
607 | 614 |
|
| 615 | + it 'does not update updated_at of unchanged files' do |
| 616 | + task_file_updated_at = task_files.first.updated_at |
| 617 | + test_file_updated_at = test_files.first.updated_at |
| 618 | + ms_file_update_at = model_solution_files.first.updated_at |
| 619 | + |
| 620 | + expect(convert_to_task_service).to have_attributes( |
| 621 | + files: have(1).item.and(include(have_attributes( |
| 622 | + updated_at: task_file_updated_at |
| 623 | + ))), |
| 624 | + model_solutions: have(1).item.and(include(have_attributes( |
| 625 | + files: have(1).item.and(include(have_attributes(updated_at: ms_file_update_at))) |
| 626 | + ))), |
| 627 | + tests: have(1).item.and(include(have_attributes( |
| 628 | + id: tests.first.id, |
| 629 | + files: have(1).item.and(include(have_attributes(updated_at: test_file_updated_at))) |
| 630 | + ))) |
| 631 | + ) |
| 632 | + end |
| 633 | + |
608 | 634 | context 'when files have been deleted' do |
609 | 635 | context 'when task files have been deleted' do |
610 | | - before { task.files = [] } |
| 636 | + before { proforma_task.files = [] } |
611 | 637 |
|
612 | 638 | it 'imports task files correctly' do |
613 | 639 | expect(convert_to_task_service.files).to be_empty |
614 | 640 | end |
615 | 641 |
|
616 | 642 | it 'saves the task correctly' do |
617 | | - convert_to_task_service.save |
618 | | - task.reload |
619 | | - expect(task.files).to be_empty |
| 643 | + convert_to_task_service |
| 644 | + expect(task.reload.files).to be_empty |
620 | 645 | end |
621 | 646 | end |
622 | 647 |
|
623 | 648 | context 'when test files have been deleted' do |
624 | | - before { task.tests.first.files = [] } |
| 649 | + before { proforma_task.tests.first.files = [] } |
625 | 650 |
|
626 | 651 | it 'imports test files correctly' do |
627 | 652 | expect(convert_to_task_service.tests.first.files).to be_empty |
628 | 653 | end |
629 | 654 |
|
630 | 655 | it 'saves the task correctly' do |
631 | | - convert_to_task_service.save |
632 | | - task.reload |
| 656 | + convert_to_task_service |
633 | 657 | expect(task.tests.first.files).to be_empty |
634 | 658 | end |
635 | 659 | end |
636 | 660 |
|
637 | 661 | context 'when model solution files have been deleted' do |
638 | | - before { task.model_solutions.first.files = [] } |
| 662 | + before { proforma_task.model_solutions.first.files = [] } |
639 | 663 |
|
640 | 664 | it 'imports model solution files correctly' do |
641 | 665 | expect(convert_to_task_service.model_solutions.first.files).to be_empty |
642 | 666 | end |
643 | 667 |
|
644 | 668 | it 'saves the task correctly' do |
645 | | - convert_to_task_service.save |
646 | | - task.reload |
| 669 | + convert_to_task_service |
647 | 670 | expect(task.model_solutions.first.files).to be_empty |
648 | 671 | end |
649 | 672 | end |
650 | 673 | end |
651 | 674 |
|
652 | | - context 'when files have been move around' do |
| 675 | + context 'when files have been moved around' do |
653 | 676 | before do |
654 | 677 | task_file = proforma_task.files.first |
655 | 678 | test_file = proforma_task.tests.first.files.first |
|
691 | 714 | files: have(1).item.and(include(have_attributes(id: task_files.first.id))) |
692 | 715 | ))), |
693 | 716 | tests: have(1).item.and(include(have_attributes( |
694 | | - id: 987_654_325, |
| 717 | + xml_id: '987654325', |
695 | 718 | files: have(1).item.and(include(have_attributes(id: model_solution_files.first.id))) |
696 | 719 | ))) |
697 | 720 | ) |
698 | 721 | end |
699 | 722 |
|
700 | 723 | context 'when imported task is persisted' do |
701 | 724 | before do |
702 | | - convert_to_task_service.save |
| 725 | + convert_to_task_service.save! |
703 | 726 | task.reload |
704 | 727 | end |
705 | 728 |
|
|
735 | 758 | files: have(1).item.and(include(have_attributes(id: task_files.first.id))) |
736 | 759 | ))), |
737 | 760 | tests: have(1).item.and(include(have_attributes( |
738 | | - id: 987_654_325, |
| 761 | + xml_id: '987654325', |
739 | 762 | files: have(1).item.and(include(have_attributes(id: model_solution_files.first.id))) |
740 | 763 | ))) |
741 | 764 | ) |
|
0 commit comments