|
38 | 38 |
|
39 | 39 | before { allow(mail_double).to receive(:deliver_later) } |
40 | 40 |
|
41 | | - describe "copy project succeeds with errors" do |
42 | | - let(:source_project) { create(:project, types: [type]) } |
43 | | - |
44 | | - let!(:work_package) { create(:work_package, :skip_validations, done_ratio: 101, project: source_project, type:) } |
| 41 | + describe "with a source project having invalid work packages" do |
| 42 | + shared_let(:type) { create(:type_bug) } |
| 43 | + shared_let(:source_project) { create(:project, types: [type]) } |
| 44 | + |
| 45 | + shared_let(:work_package_with_model_errors) do |
| 46 | + # done ratio must be between 0 and 100, this is a model validation |
| 47 | + create(:work_package, :skip_validations, |
| 48 | + project: source_project, type:, |
| 49 | + subject: "wp with invalid done_ratio", |
| 50 | + done_ratio: 101) |
| 51 | + end |
| 52 | + shared_let(:work_package_with_contract_errors) do |
| 53 | + # remaining work must be less than or equal to work, this is a WorkPackages::BaseContract validation |
| 54 | + create(:work_package, :skip_validations, |
| 55 | + project: source_project, type:, |
| 56 | + subject: "wp with invalid work and remaining work", |
| 57 | + remaining_hours: 10, estimated_hours: 2) |
| 58 | + end |
45 | 59 |
|
46 | | - let(:type) { create(:type_bug) } |
47 | 60 | let(:job_args) do |
48 | 61 | { |
49 | 62 | target_project_params: params, |
|
52 | 65 | end |
53 | 66 |
|
54 | 67 | let(:params) { { name: "Copy", identifier: "copy", type_ids: [type.id] } } |
55 | | - let(:expected_error_message) do |
56 | | - "#{WorkPackage.model_name.human} '#{work_package.type.name} ##{work_package.id}: " \ |
57 | | - "#{work_package.subject}': % Complete " \ |
58 | | - "#{I18n.t('activerecord.errors.models.work_package.attributes.done_ratio.inclusion')}" |
59 | | - end |
60 | 68 |
|
61 | | - it "copies the project", :aggregate_failures do |
| 69 | + it "copies the project and invalid work packages without reporting any errors", :aggregate_failures do |
62 | 70 | copy_job = nil |
63 | 71 | batch = GoodJob::Batch.enqueue(user: admin, source_project:) do |
64 | 72 | copy_job = described_class.perform_later(**job_args) |
|
67 | 75 | batch.reload |
68 | 76 |
|
69 | 77 | copied_project = Project.find_by(identifier: params[:identifier]) |
70 | | - |
71 | 78 | expect(copied_project).to eq(batch.properties[:target_project]) |
72 | | - expect(batch.properties[:errors].first).to eq(expected_error_message) |
| 79 | + |
| 80 | + # all work packages were copied, even if they are invalid |
| 81 | + expect(copied_project.work_packages.count).to eq(source_project.work_packages.count) |
| 82 | + # no errors reported |
| 83 | + expect(batch.properties[:errors]).to be_empty |
73 | 84 |
|
74 | 85 | # expect to create a status |
75 | 86 | expect(copy_job.job_status).to be_present |
|
80 | 91 | expect(copy_job.job_status[:payload]["_links"]["project"]).to eq(expected_link) |
81 | 92 | end |
82 | 93 |
|
83 | | - it "ensures that error messages are correctly localized" do |
84 | | - batch = GoodJob::Batch.enqueue(user: user_de, source_project:) do |
85 | | - described_class.perform_later(**job_args) |
| 94 | + context "when the source project has automatically generated subjects" do |
| 95 | + before do |
| 96 | + type.update(patterns: { subject: { blueprint: "wp {{id}} in project {{project_id}}", enabled: true } }) |
86 | 97 | end |
87 | | - GoodJob.perform_inline |
88 | | - batch.reload |
89 | 98 |
|
90 | | - msg = /Arbeitspaket 'Bug #\d+: WorkPackage No. \d+': % abgeschlossen muss zwischen 0 und 100 liegen\./ |
91 | | - expect(batch.properties[:errors].first).to match(msg) |
| 99 | + it "copies the project without reporting any errors and generates subjects different from source project" do |
| 100 | + batch = GoodJob::Batch.enqueue(user: admin, source_project:) do |
| 101 | + described_class.perform_later(**job_args) |
| 102 | + end |
| 103 | + GoodJob.perform_inline |
| 104 | + batch.reload |
| 105 | + |
| 106 | + copied_project = Project.find_by(identifier: params[:identifier]) |
| 107 | + |
| 108 | + # all work packages were copied, even if they are invalid |
| 109 | + expect(copied_project.work_packages.count).to eq(source_project.work_packages.count) |
| 110 | + # no errors reported |
| 111 | + expect(batch.properties[:errors]).to be_empty |
| 112 | + |
| 113 | + # generated subjects are different from source project |
| 114 | + copied_project.work_packages.each do |work_package| |
| 115 | + expect(work_package.subject).to eq("wp #{work_package.id} in project #{copied_project.id}") |
| 116 | + end |
| 117 | + end |
92 | 118 | end |
93 | 119 | end |
94 | 120 |
|
|
0 commit comments