summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorSebastian Klier <sebastian@sebastianklier.com>2016-02-28 15:26:52 +0800
committerSebastian Klier <sebastian@sebastianklier.com>2016-04-20 08:25:40 +0800
commit54661d3d44a7d98ed52680b074b2caed7aa33676 (patch)
treeb55ca87853bebdd44e8039b04f959a6d07f5213d /spec
parent9617c274ab301e4d2401b2d9a179f40649259d3c (diff)
downloadgitlab-ce-54661d3d44a7d98ed52680b074b2caed7aa33676.tar.gz
add slack notifications for wiki pages
update changelog
Diffstat (limited to 'spec')
-rw-r--r--spec/models/project_services/slack_service/wiki_page_message_spec.rb56
-rw-r--r--spec/models/project_services/slack_service_spec.rb17
2 files changed, 73 insertions, 0 deletions
diff --git a/spec/models/project_services/slack_service/wiki_page_message_spec.rb b/spec/models/project_services/slack_service/wiki_page_message_spec.rb
new file mode 100644
index 00000000000..c272e0e0aac
--- /dev/null
+++ b/spec/models/project_services/slack_service/wiki_page_message_spec.rb
@@ -0,0 +1,56 @@
+require 'spec_helper'
+
+describe SlackService::WikiPageMessage, models: true do
+ subject { SlackService::WikiPageMessage.new(args) }
+
+ let(:args) do
+ {
+ user: {
+ name: 'Test User',
+ username: 'Test User'
+ },
+ project_name: 'project_name',
+ project_url: 'somewhere.com',
+
+ object_attributes: {
+ title: 'Wiki page title',
+ url: 'url',
+ action: 'create',
+ content: 'Wiki page description'
+ }
+ }
+ end
+
+ let(:color) { '#345' }
+
+ context 'create' do
+ it 'returns a message regarding creation of pages' do
+ expect(subject.pretext).to eq(
+ 'Test User created <url|wiki page> in <somewhere.com|project_name>: '\
+ '*Wiki page title*')
+ expect(subject.attachments).to eq([
+ {
+ text: "Wiki page description",
+ color: color,
+ }
+ ])
+ end
+ end
+
+ context 'update' do
+ before do
+ args[:object_attributes][:action] = 'update'
+ end
+ it 'returns a message regarding updating of pages' do
+ expect(subject.pretext). to eq(
+ 'Test User edited <url|wiki page> in <somewhere.com|project_name>: '\
+ '*Wiki page title*')
+ expect(subject.attachments).to eq([
+ {
+ text: "Wiki page description",
+ color: color,
+ }
+ ])
+ end
+ end
+end
diff --git a/spec/models/project_services/slack_service_spec.rb b/spec/models/project_services/slack_service_spec.rb
index a9e0afad90f..478d59be08b 100644
--- a/spec/models/project_services/slack_service_spec.rb
+++ b/spec/models/project_services/slack_service_spec.rb
@@ -75,6 +75,17 @@ describe SlackService, models: true do
@merge_request = merge_service.execute
@merge_sample_data = merge_service.hook_data(@merge_request,
'open')
+
+ opts = {
+ title: "Awesome wiki_page",
+ content: "Some text describing some thing or another",
+ format: "md",
+ message: "user created page: Awesome wiki_page"
+ }
+
+ wiki_page_service = WikiPages::CreateService.new(project, user, opts)
+ @wiki_page = wiki_page_service.execute
+ @wiki_page_sample_data = wiki_page_service.hook_data(@wiki_page, 'create')
end
it "should call Slack API for push events" do
@@ -95,6 +106,12 @@ describe SlackService, models: true do
expect(WebMock).to have_requested(:post, webhook_url).once
end
+ it "should call Slack API for wiki page events" do
+ slack.execute(@wiki_page_sample_data)
+
+ expect(WebMock).to have_requested(:post, webhook_url).once
+ end
+
it 'should use the username as an option for slack when configured' do
allow(slack).to receive(:username).and_return(username)
expect(Slack::Notifier).to receive(:new).