debian-mirror-gitlab/spec/services/resource_events/change_state_service_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

108 lines
3.2 KiB
Ruby
Raw Permalink Normal View History

2020-06-23 00:09:42 +05:30
# frozen_string_literal: true
require 'spec_helper'
2023-05-27 22:25:52 +05:30
RSpec.describe ResourceEvents::ChangeStateService, feature_category: :team_planning do
2020-06-23 00:09:42 +05:30
let_it_be(:project) { create(:project) }
let_it_be(:user) { create(:user) }
let(:issue) { create(:issue, project: project) }
let(:merge_request) { create(:merge_request, source_project: project) }
2020-07-28 23:09:34 +05:30
let(:source_commit) { create(:commit, project: project) }
let(:source_merge_request) { create(:merge_request, source_project: project, target_project: project, target_branch: 'foo') }
2020-06-23 00:09:42 +05:30
2020-07-28 23:09:34 +05:30
shared_examples 'a state event' do
%w[opened reopened closed locked].each do |state|
it "creates the expected event if resource has #{state} state" do
described_class.new(user: user, resource: resource).execute(status: state, mentionable_source: source)
event = resource.resource_state_events.last
2020-06-23 00:09:42 +05:30
2023-01-13 00:05:48 +05:30
case resource
when Issue
2020-07-28 23:09:34 +05:30
expect(event.issue).to eq(resource)
2020-06-23 00:09:42 +05:30
expect(event.merge_request).to be_nil
2023-01-13 00:05:48 +05:30
when MergeRequest
2020-07-28 23:09:34 +05:30
expect(event.issue).to be_nil
expect(event.merge_request).to eq(resource)
2020-06-23 00:09:42 +05:30
end
2020-07-28 23:09:34 +05:30
expect(event.state).to eq(state)
expect_event_source(event, source)
2020-06-23 00:09:42 +05:30
end
2021-03-08 18:12:59 +05:30
it "sets the created_at timestamp from the system_note_timestamp" do
resource.system_note_timestamp = Time.at(43).utc
described_class.new(user: user, resource: resource).execute(status: state, mentionable_source: source)
event = resource.resource_state_events.last
expect(event.created_at).to eq(Time.at(43).utc)
end
2020-06-23 00:09:42 +05:30
end
2020-07-28 23:09:34 +05:30
end
2020-06-23 00:09:42 +05:30
2020-07-28 23:09:34 +05:30
describe '#execute' do
context 'when resource is an Issue' do
context 'when no source is given' do
it_behaves_like 'a state event' do
let(:resource) { issue }
let(:source) { nil }
end
end
2020-06-23 00:09:42 +05:30
2020-07-28 23:09:34 +05:30
context 'when source commit is given' do
it_behaves_like 'a state event' do
let(:resource) { issue }
let(:source) { source_commit }
end
end
context 'when source merge request is given' do
it_behaves_like 'a state event' do
let(:resource) { issue }
let(:source) { source_merge_request }
2020-06-23 00:09:42 +05:30
end
end
end
2020-07-28 23:09:34 +05:30
context 'when resource is a MergeRequest' do
context 'when no source is given' do
it_behaves_like 'a state event' do
let(:resource) { merge_request }
let(:source) { nil }
end
end
context 'when source commit is given' do
it_behaves_like 'a state event' do
let(:resource) { merge_request }
let(:source) { source_commit }
end
end
context 'when source merge request is given' do
it_behaves_like 'a state event' do
let(:resource) { merge_request }
let(:source) { source_merge_request }
end
end
end
end
def expect_event_source(event, source)
2023-01-13 00:05:48 +05:30
case source
when MergeRequest
2020-07-28 23:09:34 +05:30
expect(event.source_commit).to be_nil
expect(event.source_merge_request).to eq(source)
2023-01-13 00:05:48 +05:30
when Commit
2020-07-28 23:09:34 +05:30
expect(event.source_commit).to eq(source.id)
expect(event.source_merge_request).to be_nil
else
expect(event.source_merge_request).to be_nil
expect(event.source_commit).to be_nil
end
2020-06-23 00:09:42 +05:30
end
end