summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorblackst0ne <blackst0ne.ru@gmail.com>2018-11-06 22:07:07 +1100
committerblackst0ne <blackst0ne.ru@gmail.com>2018-11-06 22:07:07 +1100
commit762959465c36d6ff119676353ba21bb56fd1609c (patch)
tree8966dbde5805b518797e20b0d749d5d238f18ac1
parenta7439b4a90bf0401b60436991bbc9127ea5a6ae7 (diff)
downloadgitlab-ce-762959465c36d6ff119676353ba21bb56fd1609c.tar.gz
DRY specs, fix typos in docs
-rw-r--r--app/models/project_services/discord_service.rb2
-rw-r--r--doc/user/project/integrations/discord_notifications.md2
-rw-r--r--spec/models/project_services/discord_service_spec.rb32
-rw-r--r--spec/models/project_services/hangouts_chat_service_spec.rb35
-rw-r--r--spec/support/shared_examples/models/project_services_spec.rb9
5 files changed, 35 insertions, 45 deletions
diff --git a/app/models/project_services/discord_service.rb b/app/models/project_services/discord_service.rb
index 3718af3a6e6..ee7d737a68b 100644
--- a/app/models/project_services/discord_service.rb
+++ b/app/models/project_services/discord_service.rb
@@ -16,7 +16,7 @@ class DiscordService < ChatNotificationService
end
def help
- "This service sends notifications about projects events to Discord channels.<br />
+ "This service sends notifications about project events to Discord channels.<br />
To set up this service:
<ol>
<li><a href='https://support.discordapp.com/hc/en-us/articles/228383668-Intro-to-Webhooks'>Setup a custom Incoming Webhook</a>.</li>
diff --git a/doc/user/project/integrations/discord_notifications.md b/doc/user/project/integrations/discord_notifications.md
index b65b897c442..e157f5cc106 100644
--- a/doc/user/project/integrations/discord_notifications.md
+++ b/doc/user/project/integrations/discord_notifications.md
@@ -4,7 +4,7 @@
The Discord Notifications service sends event notifications from GitLab to the channel for which the webhook was created.
-To send GitLab event notifications to a Discord channel, create a webhook in Discourse and configure it in GitLab.
+To send GitLab event notifications to a Discord channel, create a webhook in Discord and configure it in GitLab.
## Create webhook
diff --git a/spec/models/project_services/discord_service_spec.rb b/spec/models/project_services/discord_service_spec.rb
index 695fa96d9c1..99c2ada7ad8 100644
--- a/spec/models/project_services/discord_service_spec.rb
+++ b/spec/models/project_services/discord_service_spec.rb
@@ -43,20 +43,12 @@ describe DiscordService do
WebMock.stub_request(:post, webhook_url)
end
- shared_examples "Discord service" do
- it "calls Discord Webhooks API" do
- subject.execute(sample_data)
-
- expect(WebMock).to have_requested(:post, webhook_url).with { |req| req.body =~ /\A{"content":.+}\Z/ }.once
- end
- end
-
context "with push events" do
let(:sample_data) do
Gitlab::DataBuilder::Push.build_sample(project, user)
end
- it_behaves_like "Discord service"
+ it_behaves_like "Interacts with external service", "Discord", content_key: :content
it "specifies the webhook when it is configured" do
expect(Discordrb::Webhooks::Client).to receive(:new).with(url: webhook_url).and_return(double(:discord_service).as_null_object)
@@ -86,7 +78,7 @@ describe DiscordService do
subject.notify_only_default_branch = false
end
- it_behaves_like "Discord service"
+ it_behaves_like "Interacts with external service", "Discord", content_key: :content
end
end
end
@@ -99,7 +91,7 @@ describe DiscordService do
service.hook_data(issue, "open")
end
- it_behaves_like "Discord service"
+ it_behaves_like "Interacts with external service", "Discord", content_key: :content
end
context "with merge events" do
@@ -122,7 +114,7 @@ describe DiscordService do
project.add_developer(user)
end
- it_behaves_like "Discord service"
+ it_behaves_like "Interacts with external service", "Discord", content_key: :content
end
context "with wiki page events" do
@@ -137,7 +129,7 @@ describe DiscordService do
let(:wiki_page) { create(:wiki_page, wiki: project.wiki, attrs: opts) }
let(:sample_data) { Gitlab::DataBuilder::WikiPage.build(wiki_page, user, "create") }
- it_behaves_like "Discord service"
+ it_behaves_like "Interacts with external service", "Discord", content_key: :content
end
context "with note events" do
@@ -152,7 +144,7 @@ describe DiscordService do
note: "a comment on a commit")
end
- it_behaves_like "Discord service"
+ it_behaves_like "Interacts with external service", "Discord", content_key: :content
end
context "with merge request comment" do
@@ -160,7 +152,7 @@ describe DiscordService do
create(:note_on_merge_request, project: project, note: "merge request note")
end
- it_behaves_like "Discord service"
+ it_behaves_like "Interacts with external service", "Discord", content_key: :content
end
context "with issue comment" do
@@ -168,7 +160,7 @@ describe DiscordService do
create(:note_on_issue, project: project, note: "issue note")
end
- it_behaves_like "Discord service"
+ it_behaves_like "Interacts with external service", "Discord", content_key: :content
end
context "with snippet comment" do
@@ -176,7 +168,7 @@ describe DiscordService do
create(:note_on_project_snippet, project: project, note: "snippet note")
end
- it_behaves_like "Discord service"
+ it_behaves_like "Interacts with external service", "Discord", content_key: :content
end
end
@@ -191,7 +183,7 @@ describe DiscordService do
context "with failed pipeline" do
let(:status) { "failed" }
- it_behaves_like "Discord service"
+ it_behaves_like "Interacts with external service", "Discord", content_key: :content
end
context "with succeeded pipeline" do
@@ -210,7 +202,7 @@ describe DiscordService do
subject.notify_only_broken_pipelines = false
end
- it_behaves_like "Discord service"
+ it_behaves_like "Interacts with external service", "Discord", content_key: :content
end
end
@@ -236,7 +228,7 @@ describe DiscordService do
subject.notify_only_default_branch = false
end
- it_behaves_like "Discord service"
+ it_behaves_like "Interacts with external service", "Discord", content_key: :content
end
end
end
diff --git a/spec/models/project_services/hangouts_chat_service_spec.rb b/spec/models/project_services/hangouts_chat_service_spec.rb
index cfa55188a64..3557f62fde2 100644
--- a/spec/models/project_services/hangouts_chat_service_spec.rb
+++ b/spec/models/project_services/hangouts_chat_service_spec.rb
@@ -41,23 +41,12 @@ describe HangoutsChatService do
WebMock.stub_request(:post, webhook_url)
end
- shared_examples 'Hangouts Chat service' do
- it 'calls Hangouts Chat API' do
- subject.execute(sample_data)
-
- expect(WebMock)
- .to have_requested(:post, webhook_url)
- .with { |req| req.body =~ /\A{"text":.+}\Z/ }
- .once
- end
- end
-
context 'with push events' do
let(:sample_data) do
Gitlab::DataBuilder::Push.build_sample(project, user)
end
- it_behaves_like 'Hangouts Chat service'
+ it_behaves_like "Interacts with external service", "Hangouts Chat", content_key: :text
it 'specifies the webhook when it is configured' do
expect(HangoutsChat::Sender).to receive(:new).with(webhook_url).and_return(double(:hangouts_chat_service).as_null_object)
@@ -87,7 +76,7 @@ describe HangoutsChatService do
subject.notify_only_default_branch = false
end
- it_behaves_like 'Hangouts Chat service'
+ it_behaves_like "Interacts with external service", "Hangouts Chat", content_key: :text
end
end
end
@@ -100,7 +89,7 @@ describe HangoutsChatService do
service.hook_data(issue, 'open')
end
- it_behaves_like 'Hangouts Chat service'
+ it_behaves_like "Interacts with external service", "Hangouts Chat", content_key: :text
end
context 'with merge events' do
@@ -123,7 +112,7 @@ describe HangoutsChatService do
project.add_developer(user)
end
- it_behaves_like 'Hangouts Chat service'
+ it_behaves_like "Interacts with external service", "Hangouts Chat", content_key: :text
end
context 'with wiki page events' do
@@ -138,7 +127,7 @@ describe HangoutsChatService do
let(:wiki_page) { create(:wiki_page, wiki: project.wiki, attrs: opts) }
let(:sample_data) { Gitlab::DataBuilder::WikiPage.build(wiki_page, user, 'create') }
- it_behaves_like 'Hangouts Chat service'
+ it_behaves_like "Interacts with external service", "Hangouts Chat", content_key: :text
end
context 'with note events' do
@@ -152,7 +141,7 @@ describe HangoutsChatService do
note: 'a comment on a commit')
end
- it_behaves_like 'Hangouts Chat service'
+ it_behaves_like "Interacts with external service", "Hangouts Chat", content_key: :text
end
context 'with merge request comment' do
@@ -161,7 +150,7 @@ describe HangoutsChatService do
note: 'merge request note')
end
- it_behaves_like 'Hangouts Chat service'
+ it_behaves_like "Interacts with external service", "Hangouts Chat", content_key: :text
end
context 'with issue comment' do
@@ -169,7 +158,7 @@ describe HangoutsChatService do
create(:note_on_issue, project: project, note: 'issue note')
end
- it_behaves_like 'Hangouts Chat service'
+ it_behaves_like "Interacts with external service", "Hangouts Chat", content_key: :text
end
context 'with snippet comment' do
@@ -178,7 +167,7 @@ describe HangoutsChatService do
note: 'snippet note')
end
- it_behaves_like 'Hangouts Chat service'
+ it_behaves_like "Interacts with external service", "Hangouts Chat", content_key: :text
end
end
@@ -193,7 +182,7 @@ describe HangoutsChatService do
context 'with failed pipeline' do
let(:status) { 'failed' }
- it_behaves_like 'Hangouts Chat service'
+ it_behaves_like "Interacts with external service", "Hangouts Chat", content_key: :text
end
context 'with succeeded pipeline' do
@@ -212,7 +201,7 @@ describe HangoutsChatService do
subject.notify_only_broken_pipelines = false
end
- it_behaves_like 'Hangouts Chat service'
+ it_behaves_like "Interacts with external service", "Hangouts Chat", content_key: :text
end
end
@@ -238,7 +227,7 @@ describe HangoutsChatService do
subject.notify_only_default_branch = false
end
- it_behaves_like 'Hangouts Chat service'
+ it_behaves_like "Interacts with external service", "Hangouts Chat", content_key: :text
end
end
end
diff --git a/spec/support/shared_examples/models/project_services_spec.rb b/spec/support/shared_examples/models/project_services_spec.rb
new file mode 100644
index 00000000000..4eec52a2d52
--- /dev/null
+++ b/spec/support/shared_examples/models/project_services_spec.rb
@@ -0,0 +1,9 @@
+require "spec_helper"
+
+shared_examples_for "Interacts with external service" do |service_name, content_key:|
+ it "calls #{service_name} Webhooks API" do
+ subject.execute(sample_data)
+
+ expect(WebMock).to have_requested(:post, webhook_url).with { |req| req.body =~ /\A{"#{content_key}":.+}\Z/ }.once
+ end
+end