diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-09-13 18:12:03 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-09-13 18:12:03 +0300 |
commit | 82b9539d93d7fd3d9d7ebccf4d4472d451e888da (patch) | |
tree | 318118d7375b1c509e0f3878eeef51543e4363e8 /spec/presenters | |
parent | 3c293d24c3408d204be7d84d6319b373c83ff6ae (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/presenters')
-rw-r--r-- | spec/presenters/event_presenter_spec.rb | 100 |
1 files changed, 100 insertions, 0 deletions
diff --git a/spec/presenters/event_presenter_spec.rb b/spec/presenters/event_presenter_spec.rb index 9093791421d..3f34c96ad8e 100644 --- a/spec/presenters/event_presenter_spec.rb +++ b/spec/presenters/event_presenter_spec.rb @@ -76,4 +76,104 @@ RSpec.describe EventPresenter do .to have_attributes(note_target_type_name: 'issue') end end + + describe '#push_activity_description' do + subject { event.present.push_activity_description } + + context 'when event is a regular event' do + let(:event) { build(:event, project: project) } + + it { is_expected.to be_nil } + end + + context 'when event is a push event' do + let!(:push_event_payload) { build(:push_event_payload, event: event, ref_count: ref_count) } + let(:event) { build(:push_event, project: project) } + + context 'when it is an individual event' do + let(:ref_count) { nil } + + it { is_expected.to eq 'pushed to branch' } + end + + context 'when it is a batch event' do + let(:ref_count) { 1 } + + it { is_expected.to eq 'pushed to 1 branch' } + end + end + end + + describe '#batch_push?' do + subject { event.present.batch_push? } + + context 'when event is a regular event' do + let(:event) { build(:event, project: project) } + + it { is_expected.to be_falsey } + end + + context 'when event is a push event' do + let!(:push_event_payload) { build(:push_event_payload, event: event, ref_count: ref_count) } + let(:event) { build(:push_event, project: project) } + + context 'when it is an individual event' do + let(:ref_count) { nil } + + it { is_expected.to be_falsey } + end + + context 'when it is a batch event' do + let(:ref_count) { 1 } + + it { is_expected.to be_truthy } + end + end + end + + describe '#linked_to_reference?' do + subject { event.present.linked_to_reference? } + + context 'when event is a regular event' do + let(:event) { build(:event, project: project) } + + it { is_expected.to be_falsey } + end + + context 'when event is a push event' do + let!(:push_event_payload) { build(:push_event_payload, event: event, ref: ref, ref_type: ref_type) } + let(:ref) { 'master' } + let(:ref_type) { :branch } + + context 'when event belongs to group' do + let(:event) { build(:push_event, group: group) } + + it { is_expected.to be_falsey } + end + + context 'when event belongs to project' do + let(:event) { build(:push_event, project: project) } + + it { is_expected.to be_falsey } + + context 'when matching tag exists' do + let(:ref_type) { :tag } + + before do + allow(project.repository).to receive(:tag_exists?).with(ref).and_return(true) + end + + it { is_expected.to be_truthy } + end + + context 'when matching branch exists' do + before do + allow(project.repository).to receive(:branch_exists?).with(ref).and_return(true) + end + + it { is_expected.to be_truthy } + end + end + end + end end |