Skip to content

Commit 4772e71

Browse files
committed
[#73750] Additional contract and resource specs
1 parent e20a425 commit 4772e71

3 files changed

Lines changed: 59 additions & 0 deletions

File tree

modules/backlogs/spec/contracts/work_packages/shared_contract_examples.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,21 @@
125125
it_behaves_like "contract is invalid", sprint: :not_shared_with_project
126126
end
127127

128+
context "when sprint is completed (shared with project but not assignable)" do
129+
let(:completed_sprint) { build_stubbed(:agile_sprint, status: :completed) }
130+
let(:work_package_sprint) { completed_sprint }
131+
132+
before do
133+
# The sprint is still shared with the project (the outer before mock makes
134+
# `Agile::Sprint.for_project.exists?` return true), so `sprint_shared_with_project`
135+
# passes. We stub assignable_sprints to exclude it, simulating the `.not_completed`
136+
# scope, so only `validate_sprint_is_assignable` fires.
137+
allow(work_package_project).to receive(:assignable_sprints).and_return([])
138+
end
139+
140+
it_behaves_like "contract is invalid", sprint_id: :inclusion
141+
end
142+
128143
context "when sprint is set while the user lacks the :manage_sprint_items permission" do
129144
let(:effective_permissions) { permissions - [:manage_sprint_items] }
130145

modules/backlogs/spec/requests/api/v3/work_packages/create_resource_spec.rb

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
shared_let(:status) { create(:status, is_default: true) }
4141
shared_let(:priority) { create(:priority, is_default: true) }
4242
shared_let(:sprint) { create(:agile_sprint, project:) }
43+
shared_let(:completed_sprint) { create(:agile_sprint, project:, status: :completed) }
4344
shared_let(:outside_sprint) { create(:agile_sprint, project: create(:project)) }
4445

4546
let(:role) { create(:project_role, permissions:) }
@@ -104,6 +105,30 @@
104105
end
105106
end
106107

108+
context "when attempting to create the work package on a completed sprint" do
109+
let(:parameters) do
110+
{
111+
subject: "new work packages",
112+
storyPoints: 5,
113+
_links: {
114+
type: {
115+
href: api_v3_paths.type(type.id)
116+
},
117+
project: {
118+
href: api_v3_paths.project(project.id)
119+
},
120+
sprint: {
121+
href: api_v3_paths.sprint(completed_sprint.id)
122+
}
123+
}
124+
}
125+
end
126+
127+
it_behaves_like "constraint violation" do
128+
let(:message) { "Sprint is not set to one of the allowed values." }
129+
end
130+
end
131+
107132
context "when attempting to create the work package on a non valid sprint" do
108133
let(:parameters) do
109134
{

modules/backlogs/spec/requests/api/v3/work_packages/update_resource_spec.rb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
shared_let(:status) { create(:status, is_default: true) }
4242
shared_let(:priority) { create(:priority, is_default: true) }
4343
shared_let(:sprint) { create(:agile_sprint, project:) }
44+
shared_let(:completed_sprint) { create(:agile_sprint, project:, status: :completed) }
4445
shared_let(:outside_sprint) { create(:agile_sprint, project: other_project) }
4546
shared_let(:work_package) { create(:work_package, project:, type:, status:, priority:) }
4647

@@ -138,6 +139,24 @@
138139
it_behaves_like "read-only violation", "subject", WorkPackage
139140
end
140141

142+
context "when attempting to assign the work package to a completed sprint" do
143+
let(:parameters) do
144+
{
145+
storyPoints: 5,
146+
lockVersion: work_package.lock_version,
147+
_links: {
148+
sprint: {
149+
href: api_v3_paths.sprint(completed_sprint.id)
150+
}
151+
}
152+
}
153+
end
154+
155+
it_behaves_like "constraint violation" do
156+
let(:message) { "Sprint is not set to one of the allowed values." }
157+
end
158+
end
159+
141160
context "when attempting to assign the work package to a non valid sprint" do
142161
let(:other_permissions) { [] }
143162
let(:parameters) do

0 commit comments

Comments
 (0)