Commit a1a4d7be authored by Stan Hu's avatar Stan Hu

Merge branch '330300-ajk-model-specs-26' into 'master'

Remove references to service in spec/models/integrations/base_chat_notification_spec.rb

See merge request gitlab-org/gitlab!65038
parents 541ba913 8c21f24d
...@@ -34,7 +34,7 @@ RSpec.describe Integrations::BaseChatNotification do ...@@ -34,7 +34,7 @@ RSpec.describe Integrations::BaseChatNotification do
end end
describe '#execute' do describe '#execute' do
subject(:chat_service) { described_class.new } subject(:chat_integration) { described_class.new }
let_it_be(:project) { create(:project, :repository) } let_it_be(:project) { create(:project, :repository) }
...@@ -43,7 +43,7 @@ RSpec.describe Integrations::BaseChatNotification do ...@@ -43,7 +43,7 @@ RSpec.describe Integrations::BaseChatNotification do
let(:data) { Gitlab::DataBuilder::Push.build_sample(subject.project, user) } let(:data) { Gitlab::DataBuilder::Push.build_sample(subject.project, user) }
before do before do
allow(chat_service).to receive_messages( allow(chat_integration).to receive_messages(
project: project, project: project,
project_id: project.id, project_id: project.id,
service_hook: true, service_hook: true,
...@@ -57,8 +57,8 @@ RSpec.describe Integrations::BaseChatNotification do ...@@ -57,8 +57,8 @@ RSpec.describe Integrations::BaseChatNotification do
context 'with a repository' do context 'with a repository' do
it 'returns true' do it 'returns true' do
expect(chat_service).to receive(:notify).and_return(true) expect(chat_integration).to receive(:notify).and_return(true)
expect(chat_service.execute(data)).to be true expect(chat_integration.execute(data)).to be true
end end
end end
...@@ -66,8 +66,8 @@ RSpec.describe Integrations::BaseChatNotification do ...@@ -66,8 +66,8 @@ RSpec.describe Integrations::BaseChatNotification do
it 'returns true' do it 'returns true' do
subject.project = create(:project, :empty_repo) subject.project = create(:project, :empty_repo)
expect(chat_service).to receive(:notify).and_return(true) expect(chat_integration).to receive(:notify).and_return(true)
expect(chat_service.execute(data)).to be true expect(chat_integration.execute(data)).to be true
end end
end end
...@@ -75,8 +75,8 @@ RSpec.describe Integrations::BaseChatNotification do ...@@ -75,8 +75,8 @@ RSpec.describe Integrations::BaseChatNotification do
it 'does not remove spaces' do it 'does not remove spaces' do
allow(project).to receive(:full_name).and_return('Project Name') allow(project).to receive(:full_name).and_return('Project Name')
expect(chat_service).to receive(:get_message).with(any_args, hash_including(project_name: 'Project Name')) expect(chat_integration).to receive(:get_message).with(any_args, hash_including(project_name: 'Project Name'))
chat_service.execute(data) chat_integration.execute(data)
end end
end end
...@@ -89,76 +89,76 @@ RSpec.describe Integrations::BaseChatNotification do ...@@ -89,76 +89,76 @@ RSpec.describe Integrations::BaseChatNotification do
let(:data) { Gitlab::DataBuilder::Note.build(note, user) } let(:data) { Gitlab::DataBuilder::Note.build(note, user) }
shared_examples 'notifies the chat service' do shared_examples 'notifies the chat integration' do
specify do specify do
expect(chat_service).to receive(:notify).with(any_args) expect(chat_integration).to receive(:notify).with(any_args)
chat_service.execute(data) chat_integration.execute(data)
end end
end end
shared_examples 'does not notify the chat service' do shared_examples 'does not notify the chat integration' do
specify do specify do
expect(chat_service).not_to receive(:notify).with(any_args) expect(chat_integration).not_to receive(:notify).with(any_args)
chat_service.execute(data) chat_integration.execute(data)
end end
end end
it_behaves_like 'notifies the chat service' it_behaves_like 'notifies the chat integration'
context 'with label filter' do context 'with label filter' do
subject(:chat_service) { described_class.new(labels_to_be_notified: '~Bug') } subject(:chat_integration) { described_class.new(labels_to_be_notified: '~Bug') }
it_behaves_like 'notifies the chat service' it_behaves_like 'notifies the chat integration'
context 'MergeRequest events' do context 'MergeRequest events' do
let(:data) { create(:merge_request, labels: [label]).to_hook_data(user) } let(:data) { create(:merge_request, labels: [label]).to_hook_data(user) }
it_behaves_like 'notifies the chat service' it_behaves_like 'notifies the chat integration'
end end
context 'Issue events' do context 'Issue events' do
let(:data) { issue.to_hook_data(user) } let(:data) { issue.to_hook_data(user) }
it_behaves_like 'notifies the chat service' it_behaves_like 'notifies the chat integration'
end end
end end
context 'when labels_to_be_notified_behavior is not defined' do context 'when labels_to_be_notified_behavior is not defined' do
subject(:chat_service) { described_class.new(labels_to_be_notified: label_filter) } subject(:chat_integration) { described_class.new(labels_to_be_notified: label_filter) }
context 'no matching labels' do context 'no matching labels' do
let(:label_filter) { '~some random label' } let(:label_filter) { '~some random label' }
it_behaves_like 'does not notify the chat service' it_behaves_like 'does not notify the chat integration'
end end
context 'only one label matches' do context 'only one label matches' do
let(:label_filter) { '~some random label, ~Bug' } let(:label_filter) { '~some random label, ~Bug' }
it_behaves_like 'notifies the chat service' it_behaves_like 'notifies the chat integration'
end end
end end
context 'when labels_to_be_notified_behavior is blank' do context 'when labels_to_be_notified_behavior is blank' do
subject(:chat_service) { described_class.new(labels_to_be_notified: label_filter, labels_to_be_notified_behavior: '') } subject(:chat_integration) { described_class.new(labels_to_be_notified: label_filter, labels_to_be_notified_behavior: '') }
context 'no matching labels' do context 'no matching labels' do
let(:label_filter) { '~some random label' } let(:label_filter) { '~some random label' }
it_behaves_like 'does not notify the chat service' it_behaves_like 'does not notify the chat integration'
end end
context 'only one label matches' do context 'only one label matches' do
let(:label_filter) { '~some random label, ~Bug' } let(:label_filter) { '~some random label, ~Bug' }
it_behaves_like 'notifies the chat service' it_behaves_like 'notifies the chat integration'
end end
end end
context 'when labels_to_be_notified_behavior is match_any' do context 'when labels_to_be_notified_behavior is match_any' do
subject(:chat_service) do subject(:chat_integration) do
described_class.new( described_class.new(
labels_to_be_notified: label_filter, labels_to_be_notified: label_filter,
labels_to_be_notified_behavior: 'match_any' labels_to_be_notified_behavior: 'match_any'
...@@ -168,24 +168,24 @@ RSpec.describe Integrations::BaseChatNotification do ...@@ -168,24 +168,24 @@ RSpec.describe Integrations::BaseChatNotification do
context 'no label filter' do context 'no label filter' do
let(:label_filter) { nil } let(:label_filter) { nil }
it_behaves_like 'notifies the chat service' it_behaves_like 'notifies the chat integration'
end end
context 'no matching labels' do context 'no matching labels' do
let(:label_filter) { '~some random label' } let(:label_filter) { '~some random label' }
it_behaves_like 'does not notify the chat service' it_behaves_like 'does not notify the chat integration'
end end
context 'only one label matches' do context 'only one label matches' do
let(:label_filter) { '~some random label, ~Bug' } let(:label_filter) { '~some random label, ~Bug' }
it_behaves_like 'notifies the chat service' it_behaves_like 'notifies the chat integration'
end end
end end
context 'when labels_to_be_notified_behavior is match_all' do context 'when labels_to_be_notified_behavior is match_all' do
subject(:chat_service) do subject(:chat_integration) do
described_class.new( described_class.new(
labels_to_be_notified: label_filter, labels_to_be_notified: label_filter,
labels_to_be_notified_behavior: 'match_all' labels_to_be_notified_behavior: 'match_all'
...@@ -195,31 +195,31 @@ RSpec.describe Integrations::BaseChatNotification do ...@@ -195,31 +195,31 @@ RSpec.describe Integrations::BaseChatNotification do
context 'no label filter' do context 'no label filter' do
let(:label_filter) { nil } let(:label_filter) { nil }
it_behaves_like 'notifies the chat service' it_behaves_like 'notifies the chat integration'
end end
context 'no matching labels' do context 'no matching labels' do
let(:label_filter) { '~some random label' } let(:label_filter) { '~some random label' }
it_behaves_like 'does not notify the chat service' it_behaves_like 'does not notify the chat integration'
end end
context 'only one label matches' do context 'only one label matches' do
let(:label_filter) { '~some random label, ~Bug' } let(:label_filter) { '~some random label, ~Bug' }
it_behaves_like 'does not notify the chat service' it_behaves_like 'does not notify the chat integration'
end end
context 'labels matches exactly' do context 'labels matches exactly' do
let(:label_filter) { '~Bug, ~Backend, ~Community contribution' } let(:label_filter) { '~Bug, ~Backend, ~Community contribution' }
it_behaves_like 'notifies the chat service' it_behaves_like 'notifies the chat integration'
end end
context 'labels matches but object has more' do context 'labels matches but object has more' do
let(:label_filter) { '~Bug, ~Backend' } let(:label_filter) { '~Bug, ~Backend' }
it_behaves_like 'notifies the chat service' it_behaves_like 'notifies the chat integration'
end end
context 'labels are distributed on multiple objects' do context 'labels are distributed on multiple objects' do
...@@ -241,22 +241,22 @@ RSpec.describe Integrations::BaseChatNotification do ...@@ -241,22 +241,22 @@ RSpec.describe Integrations::BaseChatNotification do
}) })
end end
it_behaves_like 'does not notify the chat service' it_behaves_like 'does not notify the chat integration'
end end
end end
end end
context 'with "channel" property' do context 'with "channel" property' do
before do before do
allow(chat_service).to receive(:channel).and_return(channel) allow(chat_integration).to receive(:channel).and_return(channel)
end end
context 'empty string' do context 'empty string' do
let(:channel) { '' } let(:channel) { '' }
it 'does not include the channel' do it 'does not include the channel' do
expect(chat_service).to receive(:notify).with(any_args, hash_excluding(:channel)).and_return(true) expect(chat_integration).to receive(:notify).with(any_args, hash_excluding(:channel)).and_return(true)
expect(chat_service.execute(data)).to be(true) expect(chat_integration.execute(data)).to be(true)
end end
end end
...@@ -264,20 +264,20 @@ RSpec.describe Integrations::BaseChatNotification do ...@@ -264,20 +264,20 @@ RSpec.describe Integrations::BaseChatNotification do
let(:channel) { ' ' } let(:channel) { ' ' }
it 'does not include the channel' do it 'does not include the channel' do
expect(chat_service).to receive(:notify).with(any_args, hash_excluding(:channel)).and_return(true) expect(chat_integration).to receive(:notify).with(any_args, hash_excluding(:channel)).and_return(true)
expect(chat_service.execute(data)).to be(true) expect(chat_integration.execute(data)).to be(true)
end end
end end
end end
shared_examples 'with channel specified' do |channel, expected_channels| shared_examples 'with channel specified' do |channel, expected_channels|
before do before do
allow(chat_service).to receive(:push_channel).and_return(channel) allow(chat_integration).to receive(:push_channel).and_return(channel)
end end
it 'notifies all channels' do it 'notifies all channels' do
expect(chat_service).to receive(:notify).with(any_args, hash_including(channel: expected_channels)).and_return(true) expect(chat_integration).to receive(:notify).with(any_args, hash_including(channel: expected_channels)).and_return(true)
expect(chat_service.execute(data)).to be(true) expect(chat_integration.execute(data)).to be(true)
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