Commit ad08087b authored by Justin Ho's avatar Justin Ho

Change back to args syntax for Slack Notifier

- Update specs to use helper
- Fix specs to accept array instead of string
parent 4e495da7
...@@ -36,10 +36,7 @@ class SlackService < ChatNotificationService ...@@ -36,10 +36,7 @@ class SlackService < ChatNotificationService
def notify(message, opts) def notify(message, opts)
# See https://github.com/stevenosloan/slack-notifier#custom-http-client # See https://github.com/stevenosloan/slack-notifier#custom-http-client
notifier = Slack::Notifier.new(webhook) do notifier = Slack::Notifier.new(webhook, opts.merge(http_client: HTTPClient))
http_client HTTPClient
defaults opts
end
notifier.ping( notifier.ping(
message.pretext, message.pretext,
......
...@@ -151,22 +151,14 @@ RSpec.shared_examples 'slack or mattermost notifications' do |service_name| ...@@ -151,22 +151,14 @@ RSpec.shared_examples 'slack or mattermost notifications' do |service_name|
it 'uses the username as an option for slack when configured' do it 'uses the username as an option for slack when configured' do
allow(chat_service).to receive(:username).and_return(username) allow(chat_service).to receive(:username).and_return(username)
expect(Slack::Notifier).to receive(:new) expect(Slack::Notifier).to execute_with_options(username: username)
.with(webhook_url, username: username, http_client: SlackService::Notifier::HTTPClient)
.and_return(
double(:slack_service).as_null_object
)
chat_service.execute(data) chat_service.execute(data)
end end
it 'uses the channel as an option when it is configured' do it 'uses the channel as an option when it is configured' do
allow(chat_service).to receive(:channel).and_return(channel) allow(chat_service).to receive(:channel).and_return(channel)
expect(Slack::Notifier).to receive(:new) expect(Slack::Notifier).to execute_with_options(channel: [channel])
.with(webhook_url, channel: channel, http_client: SlackService::Notifier::HTTPClient)
.and_return(
double(:slack_service).as_null_object
)
chat_service.execute(data) chat_service.execute(data)
end end
...@@ -174,11 +166,7 @@ RSpec.shared_examples 'slack or mattermost notifications' do |service_name| ...@@ -174,11 +166,7 @@ RSpec.shared_examples 'slack or mattermost notifications' do |service_name|
it "uses the right channel for push event" do it "uses the right channel for push event" do
chat_service.update(push_channel: "random") chat_service.update(push_channel: "random")
expect(Slack::Notifier).to receive(:new) expect(Slack::Notifier).to execute_with_options(channel: ['random'])
.with(webhook_url, channel: "random", http_client: SlackService::Notifier::HTTPClient)
.and_return(
double(:slack_service).as_null_object
)
chat_service.execute(data) chat_service.execute(data)
end end
...@@ -186,11 +174,7 @@ RSpec.shared_examples 'slack or mattermost notifications' do |service_name| ...@@ -186,11 +174,7 @@ RSpec.shared_examples 'slack or mattermost notifications' do |service_name|
it "uses the right channel for merge request event" do it "uses the right channel for merge request event" do
chat_service.update(merge_request_channel: "random") chat_service.update(merge_request_channel: "random")
expect(Slack::Notifier).to receive(:new) expect(Slack::Notifier).to execute_with_options(channel: ['random'])
.with(webhook_url, channel: "random", http_client: SlackService::Notifier::HTTPClient)
.and_return(
double(:slack_service).as_null_object
)
chat_service.execute(@merge_sample_data) chat_service.execute(@merge_sample_data)
end end
...@@ -198,11 +182,7 @@ RSpec.shared_examples 'slack or mattermost notifications' do |service_name| ...@@ -198,11 +182,7 @@ RSpec.shared_examples 'slack or mattermost notifications' do |service_name|
it "uses the right channel for issue event" do it "uses the right channel for issue event" do
chat_service.update(issue_channel: "random") chat_service.update(issue_channel: "random")
expect(Slack::Notifier).to receive(:new) expect(Slack::Notifier).to execute_with_options(channel: ['random'])
.with(webhook_url, channel: "random", http_client: SlackService::Notifier::HTTPClient)
.and_return(
double(:slack_service).as_null_object
)
chat_service.execute(@issues_sample_data) chat_service.execute(@issues_sample_data)
end end
...@@ -213,7 +193,7 @@ RSpec.shared_examples 'slack or mattermost notifications' do |service_name| ...@@ -213,7 +193,7 @@ RSpec.shared_examples 'slack or mattermost notifications' do |service_name|
it "uses confidential issue channel" do it "uses confidential issue channel" do
chat_service.update(confidential_issue_channel: 'confidential') chat_service.update(confidential_issue_channel: 'confidential')
expect(Slack::Notifier).to execute_with_options(channel: 'confidential') expect(Slack::Notifier).to execute_with_options(channel: ['confidential'])
chat_service.execute(@issues_sample_data) chat_service.execute(@issues_sample_data)
end end
...@@ -221,7 +201,7 @@ RSpec.shared_examples 'slack or mattermost notifications' do |service_name| ...@@ -221,7 +201,7 @@ RSpec.shared_examples 'slack or mattermost notifications' do |service_name|
it 'falls back to issue channel' do it 'falls back to issue channel' do
chat_service.update(issue_channel: 'fallback_channel') chat_service.update(issue_channel: 'fallback_channel')
expect(Slack::Notifier).to execute_with_options(channel: 'fallback_channel') expect(Slack::Notifier).to execute_with_options(channel: ['fallback_channel'])
chat_service.execute(@issues_sample_data) chat_service.execute(@issues_sample_data)
end end
...@@ -230,11 +210,7 @@ RSpec.shared_examples 'slack or mattermost notifications' do |service_name| ...@@ -230,11 +210,7 @@ RSpec.shared_examples 'slack or mattermost notifications' do |service_name|
it "uses the right channel for wiki event" do it "uses the right channel for wiki event" do
chat_service.update(wiki_page_channel: "random") chat_service.update(wiki_page_channel: "random")
expect(Slack::Notifier).to receive(:new) expect(Slack::Notifier).to execute_with_options(channel: ['random'])
.with(webhook_url, channel: "random", http_client: SlackService::Notifier::HTTPClient)
.and_return(
double(:slack_service).as_null_object
)
chat_service.execute(@wiki_page_sample_data) chat_service.execute(@wiki_page_sample_data)
end end
...@@ -249,11 +225,7 @@ RSpec.shared_examples 'slack or mattermost notifications' do |service_name| ...@@ -249,11 +225,7 @@ RSpec.shared_examples 'slack or mattermost notifications' do |service_name|
note_data = Gitlab::DataBuilder::Note.build(issue_note, user) note_data = Gitlab::DataBuilder::Note.build(issue_note, user)
expect(Slack::Notifier).to receive(:new) expect(Slack::Notifier).to execute_with_options(channel: ['random'])
.with(webhook_url, channel: "random", http_client: SlackService::Notifier::HTTPClient)
.and_return(
double(:slack_service).as_null_object
)
chat_service.execute(note_data) chat_service.execute(note_data)
end end
...@@ -268,7 +240,7 @@ RSpec.shared_examples 'slack or mattermost notifications' do |service_name| ...@@ -268,7 +240,7 @@ RSpec.shared_examples 'slack or mattermost notifications' do |service_name|
note_data = Gitlab::DataBuilder::Note.build(issue_note, user) note_data = Gitlab::DataBuilder::Note.build(issue_note, user)
expect(Slack::Notifier).to execute_with_options(channel: 'confidential') expect(Slack::Notifier).to execute_with_options(channel: ['confidential'])
chat_service.execute(note_data) chat_service.execute(note_data)
end end
...@@ -278,7 +250,7 @@ RSpec.shared_examples 'slack or mattermost notifications' do |service_name| ...@@ -278,7 +250,7 @@ RSpec.shared_examples 'slack or mattermost notifications' do |service_name|
note_data = Gitlab::DataBuilder::Note.build(issue_note, user) note_data = Gitlab::DataBuilder::Note.build(issue_note, user)
expect(Slack::Notifier).to execute_with_options(channel: 'fallback_channel') expect(Slack::Notifier).to execute_with_options(channel: ['fallback_channel'])
chat_service.execute(note_data) chat_service.execute(note_data)
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