Commit 500cef40 authored by Felipe Artur's avatar Felipe Artur

Fix error when archiving requirements

Make sure to call proper services when syncing work items
with requirements.
Prevents an error when archiving requirements.

Changelog: fixed
EE: true
parent 584868af
...@@ -38,6 +38,9 @@ module RequirementsManagement ...@@ -38,6 +38,9 @@ module RequirementsManagement
def perform_sync(requirement, attributes) def perform_sync(requirement, attributes)
requirement_issue = requirement.requirement_issue requirement_issue = requirement.requirement_issue
state_change = attributes.delete(:state)
update_requirement_issue_state(requirement_issue, state_change)
::Issues::UpdateService.new(project: project, current_user: current_user, params: attributes) ::Issues::UpdateService.new(project: project, current_user: current_user, params: attributes)
.execute(requirement_issue) .execute(requirement_issue)
end end
......
...@@ -117,23 +117,32 @@ RSpec.describe RequirementsManagement::UpdateRequirementService do ...@@ -117,23 +117,32 @@ RSpec.describe RequirementsManagement::UpdateRequirementService do
context 'when updating state' do context 'when updating state' do
context 'to archived' do context 'to archived' do
let(:params) do let(:params) { { state: 'archived' } }
{ state: 'archived' }
it 'closes issue' do
expect_next_instance_of(::Issues::CloseService) do |service|
expect(service).to receive(:execute).with(requirement_issue, any_args).and_call_original
end end
it_behaves_like 'keeps requirement and its requirement_issue in sync' expect { subject }.to change { requirement.requirement_issue.reload.state }.from('opened').to('closed')
end
end end
context 'to opened' do context 'to opened' do
let(:params) do let(:params) { { state: 'opened' } }
{ state: 'opened' }
end
before do before do
requirement_issue.close
requirement.update!(state: 'archived') requirement.update!(state: 'archived')
end end
it_behaves_like 'keeps requirement and its requirement_issue in sync' it 'reopens issue' do
expect_next_instance_of(::Issues::ReopenService) do |service|
expect(service).to receive(:execute).with(requirement_issue, any_args).and_call_original
end
expect { subject }.to change { requirement.requirement_issue.reload.state }.from('closed').to('opened')
end
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment