Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'spec/models/project_services')
-rw-r--r--spec/models/project_services/asana_service_spec.rb65
-rw-r--r--spec/models/project_services/assembla_service_spec.rb53
-rw-r--r--spec/models/project_services/buildkite_service_spec.rb82
-rw-r--r--spec/models/project_services/flowdock_service_spec.rb52
-rw-r--r--spec/models/project_services/gemnasium_service_spec.rb48
-rw-r--r--spec/models/project_services/gitlab_ci_service_spec.rb70
-rw-r--r--spec/models/project_services/gitlab_issue_tracker_service_spec.rb66
-rw-r--r--spec/models/project_services/hipchat_service_spec.rb217
-rw-r--r--spec/models/project_services/irker_service_spec.rb108
-rw-r--r--spec/models/project_services/jira_service_spec.rb102
-rw-r--r--spec/models/project_services/pushover_service_spec.rb74
-rw-r--r--spec/models/project_services/slack_service/issue_message_spec.rb56
-rw-r--r--spec/models/project_services/slack_service/merge_message_spec.rb51
-rw-r--r--spec/models/project_services/slack_service/note_message_spec.rb129
-rw-r--r--spec/models/project_services/slack_service/push_message_spec.rb88
-rw-r--r--spec/models/project_services/slack_service_spec.rb170
16 files changed, 0 insertions, 1431 deletions
diff --git a/spec/models/project_services/asana_service_spec.rb b/spec/models/project_services/asana_service_spec.rb
deleted file mode 100644
index 13c8d54a2af..00000000000
--- a/spec/models/project_services/asana_service_spec.rb
+++ /dev/null
@@ -1,65 +0,0 @@
-# == Schema Information
-#
-# Table name: services
-#
-# id :integer not null, primary key
-# type :string(255)
-# title :string(255)
-# project_id :integer
-# created_at :datetime
-# updated_at :datetime
-# active :boolean default(FALSE), not null
-# properties :text
-# template :boolean default(FALSE)
-# push_events :boolean default(TRUE)
-# issues_events :boolean default(TRUE)
-# merge_requests_events :boolean default(TRUE)
-# tag_push_events :boolean default(TRUE)
-#
-
-require 'spec_helper'
-
-describe AsanaService, models: true do
- describe 'Associations' do
- it { is_expected.to belong_to :project }
- it { is_expected.to have_one :service_hook }
- end
-
- describe 'Validations' do
- context 'active' do
- before do
- subject.active = true
- end
-
- it { is_expected.to validate_presence_of :api_key }
- end
- end
-
- describe 'Execute' do
- let(:user) { create(:user) }
- let(:project) { create(:project) }
-
- before do
- @asana = AsanaService.new
- @asana.stub(
- project: project,
- project_id: project.id,
- service_hook: true,
- api_key: 'verySecret',
- restrict_to_branch: 'master'
- )
- end
-
- it 'should call Asana service to created a story' do
- expect(Asana::Task).to receive(:find).with('123456').once
-
- @asana.check_commit('related to #123456', 'pushed')
- end
-
- it 'should call Asana service to created a story and close a task' do
- expect(Asana::Task).to receive(:find).with('456789').twice
-
- @asana.check_commit('fix #456789', 'pushed')
- end
- end
-end
diff --git a/spec/models/project_services/assembla_service_spec.rb b/spec/models/project_services/assembla_service_spec.rb
deleted file mode 100644
index 91730da1eec..00000000000
--- a/spec/models/project_services/assembla_service_spec.rb
+++ /dev/null
@@ -1,53 +0,0 @@
-# == Schema Information
-#
-# Table name: services
-#
-# id :integer not null, primary key
-# type :string(255)
-# title :string(255)
-# project_id :integer
-# created_at :datetime
-# updated_at :datetime
-# active :boolean default(FALSE), not null
-# properties :text
-# template :boolean default(FALSE)
-# push_events :boolean default(TRUE)
-# issues_events :boolean default(TRUE)
-# merge_requests_events :boolean default(TRUE)
-# tag_push_events :boolean default(TRUE)
-#
-
-require 'spec_helper'
-
-describe AssemblaService, models: true do
- describe "Associations" do
- it { is_expected.to belong_to :project }
- it { is_expected.to have_one :service_hook }
- end
-
- describe "Execute" do
- let(:user) { create(:user) }
- let(:project) { create(:project) }
-
- before do
- @assembla_service = AssemblaService.new
- @assembla_service.stub(
- project_id: project.id,
- project: project,
- service_hook: true,
- token: 'verySecret',
- subdomain: 'project_name'
- )
- @sample_data = Gitlab::PushDataBuilder.build_sample(project, user)
- @api_url = 'https://atlas.assembla.com/spaces/project_name/github_tool?secret_key=verySecret'
- WebMock.stub_request(:post, @api_url)
- end
-
- it "should call Assembla API" do
- @assembla_service.execute(@sample_data)
- expect(WebMock).to have_requested(:post, @api_url).with(
- body: /#{@sample_data[:before]}.*#{@sample_data[:after]}.*#{project.path}/
- ).once
- end
- end
-end
diff --git a/spec/models/project_services/buildkite_service_spec.rb b/spec/models/project_services/buildkite_service_spec.rb
deleted file mode 100644
index e987241f3ca..00000000000
--- a/spec/models/project_services/buildkite_service_spec.rb
+++ /dev/null
@@ -1,82 +0,0 @@
-# == Schema Information
-#
-# Table name: services
-#
-# id :integer not null, primary key
-# type :string(255)
-# title :string(255)
-# project_id :integer
-# created_at :datetime
-# updated_at :datetime
-# active :boolean default(FALSE), not null
-# properties :text
-# template :boolean default(FALSE)
-# push_events :boolean default(TRUE)
-# issues_events :boolean default(TRUE)
-# merge_requests_events :boolean default(TRUE)
-# tag_push_events :boolean default(TRUE)
-#
-
-require 'spec_helper'
-
-describe BuildkiteService do
- describe 'Associations' do
- it { is_expected.to belong_to :project }
- it { is_expected.to have_one :service_hook }
- end
-
- describe 'commits methods' do
- before do
- @project = Project.new
- @project.stub(
- default_branch: 'default-brancho'
- )
-
- @service = BuildkiteService.new
- @service.stub(
- project: @project,
- service_hook: true,
- project_url: 'https://buildkite.com/account-name/example-project',
- token: 'secret-sauce-webhook-token:secret-sauce-status-token'
- )
- end
-
- describe :webhook_url do
- it 'returns the webhook url' do
- expect(@service.webhook_url).to eq(
- 'https://webhook.buildkite.com/deliver/secret-sauce-webhook-token'
- )
- end
- end
-
- describe :commit_status_path do
- it 'returns the correct status page' do
- expect(@service.commit_status_path('2ab7834c')).to eq(
- 'https://gitlab.buildkite.com/status/secret-sauce-status-token.json?commit=2ab7834c'
- )
- end
- end
-
- describe :build_page do
- it 'returns the correct build page' do
- expect(@service.build_page('2ab7834c', nil)).to eq(
- 'https://buildkite.com/account-name/example-project/builds?commit=2ab7834c'
- )
- end
- end
-
- describe :builds_page do
- it 'returns the correct path to the builds page' do
- expect(@service.builds_path).to eq(
- 'https://buildkite.com/account-name/example-project/builds?branch=default-brancho'
- )
- end
- end
-
- describe :status_img_path do
- it 'returns the correct path to the status image' do
- expect(@service.status_img_path).to eq('https://badge.buildkite.com/secret-sauce-status-token.svg')
- end
- end
- end
-end
diff --git a/spec/models/project_services/flowdock_service_spec.rb b/spec/models/project_services/flowdock_service_spec.rb
deleted file mode 100644
index 73f68301a34..00000000000
--- a/spec/models/project_services/flowdock_service_spec.rb
+++ /dev/null
@@ -1,52 +0,0 @@
-# == Schema Information
-#
-# Table name: services
-#
-# id :integer not null, primary key
-# type :string(255)
-# title :string(255)
-# project_id :integer
-# created_at :datetime
-# updated_at :datetime
-# active :boolean default(FALSE), not null
-# properties :text
-# template :boolean default(FALSE)
-# push_events :boolean default(TRUE)
-# issues_events :boolean default(TRUE)
-# merge_requests_events :boolean default(TRUE)
-# tag_push_events :boolean default(TRUE)
-#
-
-require 'spec_helper'
-
-describe FlowdockService do
- describe "Associations" do
- it { is_expected.to belong_to :project }
- it { is_expected.to have_one :service_hook }
- end
-
- describe "Execute" do
- let(:user) { create(:user) }
- let(:project) { create(:project) }
-
- before do
- @flowdock_service = FlowdockService.new
- @flowdock_service.stub(
- project_id: project.id,
- project: project,
- service_hook: true,
- token: 'verySecret'
- )
- @sample_data = Gitlab::PushDataBuilder.build_sample(project, user)
- @api_url = 'https://api.flowdock.com/v1/git/verySecret'
- WebMock.stub_request(:post, @api_url)
- end
-
- it "should call FlowDock API" do
- @flowdock_service.execute(@sample_data)
- expect(WebMock).to have_requested(:post, @api_url).with(
- body: /#{@sample_data[:before]}.*#{@sample_data[:after]}.*#{project.path}/
- ).once
- end
- end
-end
diff --git a/spec/models/project_services/gemnasium_service_spec.rb b/spec/models/project_services/gemnasium_service_spec.rb
deleted file mode 100644
index d44064bbe6a..00000000000
--- a/spec/models/project_services/gemnasium_service_spec.rb
+++ /dev/null
@@ -1,48 +0,0 @@
-# == Schema Information
-#
-# Table name: services
-#
-# id :integer not null, primary key
-# type :string(255)
-# title :string(255)
-# project_id :integer
-# created_at :datetime
-# updated_at :datetime
-# active :boolean default(FALSE), not null
-# properties :text
-# template :boolean default(FALSE)
-# push_events :boolean default(TRUE)
-# issues_events :boolean default(TRUE)
-# merge_requests_events :boolean default(TRUE)
-# tag_push_events :boolean default(TRUE)
-#
-
-require 'spec_helper'
-
-describe GemnasiumService do
- describe "Associations" do
- it { is_expected.to belong_to :project }
- it { is_expected.to have_one :service_hook }
- end
-
- describe "Execute" do
- let(:user) { create(:user) }
- let(:project) { create(:project) }
-
- before do
- @gemnasium_service = GemnasiumService.new
- @gemnasium_service.stub(
- project_id: project.id,
- project: project,
- service_hook: true,
- token: 'verySecret',
- api_key: 'GemnasiumUserApiKey'
- )
- @sample_data = Gitlab::PushDataBuilder.build_sample(project, user)
- end
- it "should call Gemnasium service" do
- expect(Gemnasium::GitlabService).to receive(:execute).with(an_instance_of(Hash)).once
- @gemnasium_service.execute(@sample_data)
- end
- end
-end
diff --git a/spec/models/project_services/gitlab_ci_service_spec.rb b/spec/models/project_services/gitlab_ci_service_spec.rb
deleted file mode 100644
index 6a557d839ca..00000000000
--- a/spec/models/project_services/gitlab_ci_service_spec.rb
+++ /dev/null
@@ -1,70 +0,0 @@
-# == Schema Information
-#
-# Table name: services
-#
-# id :integer not null, primary key
-# type :string(255)
-# title :string(255)
-# project_id :integer
-# created_at :datetime
-# updated_at :datetime
-# active :boolean default(FALSE), not null
-# properties :text
-# template :boolean default(FALSE)
-# push_events :boolean default(TRUE)
-# issues_events :boolean default(TRUE)
-# merge_requests_events :boolean default(TRUE)
-# tag_push_events :boolean default(TRUE)
-#
-
-require 'spec_helper'
-
-describe GitlabCiService do
- describe "Associations" do
- it { is_expected.to belong_to :project }
- it { is_expected.to have_one :service_hook }
- end
-
- describe "Mass assignment" do
- end
-
- describe 'commits methods' do
- before do
- @service = GitlabCiService.new
- @service.stub(
- service_hook: true,
- project_url: 'http://ci.gitlab.org/projects/2',
- token: 'verySecret'
- )
- end
-
- describe :commit_status_path do
- it { expect(@service.commit_status_path("2ab7834c", 'master')).to eq("http://ci.gitlab.org/projects/2/refs/master/commits/2ab7834c/status.json?token=verySecret")}
- end
-
- describe :build_page do
- it { expect(@service.build_page("2ab7834c", 'master')).to eq("http://ci.gitlab.org/projects/2/refs/master/commits/2ab7834c")}
- end
- end
-
- describe "Fork registration" do
- before do
- @old_project = create(:empty_project)
- @project = create(:empty_project)
- @user = create(:user)
-
- @service = GitlabCiService.new
- @service.stub(
- service_hook: true,
- project_url: 'http://ci.gitlab.org/projects/2',
- token: 'verySecret',
- project: @old_project
- )
- end
-
- it "performs http reuquest to ci" do
- stub_request(:post, "http://ci.gitlab.org/api/v1/forks")
- @service.fork_registration(@project, @user.private_token)
- end
- end
-end
diff --git a/spec/models/project_services/gitlab_issue_tracker_service_spec.rb b/spec/models/project_services/gitlab_issue_tracker_service_spec.rb
deleted file mode 100644
index f94bef5c365..00000000000
--- a/spec/models/project_services/gitlab_issue_tracker_service_spec.rb
+++ /dev/null
@@ -1,66 +0,0 @@
-# == Schema Information
-#
-# Table name: services
-#
-# id :integer not null, primary key
-# type :string(255)
-# title :string(255)
-# project_id :integer
-# created_at :datetime
-# updated_at :datetime
-# active :boolean default(FALSE), not null
-# properties :text
-# template :boolean default(FALSE)
-# push_events :boolean default(TRUE)
-# issues_events :boolean default(TRUE)
-# merge_requests_events :boolean default(TRUE)
-# tag_push_events :boolean default(TRUE)
-#
-
-require 'spec_helper'
-
-describe GitlabIssueTrackerService do
- describe "Associations" do
- it { is_expected.to belong_to :project }
- it { is_expected.to have_one :service_hook }
- end
-
-
- describe 'project and issue urls' do
- let(:project) { create(:project) }
-
- context 'with absolute urls' do
- before do
- GitlabIssueTrackerService.default_url_options[:script_name] = "/gitlab/root"
- @service = project.create_gitlab_issue_tracker_service(active: true)
- end
-
- after do
- @service.destroy!
- end
-
- it 'should give the correct path' do
- expect(@service.project_url).to eq("http://localhost/gitlab/root/#{project.path_with_namespace}/issues")
- expect(@service.new_issue_url).to eq("http://localhost/gitlab/root/#{project.path_with_namespace}/issues/new")
- expect(@service.issue_url(432)).to eq("http://localhost/gitlab/root/#{project.path_with_namespace}/issues/432")
- end
- end
-
- context 'with relative urls' do
- before do
- GitlabIssueTrackerService.default_url_options[:script_name] = "/gitlab/root"
- @service = project.create_gitlab_issue_tracker_service(active: true)
- end
-
- after do
- @service.destroy!
- end
-
- it 'should give the correct path' do
- expect(@service.project_path).to eq("/gitlab/root/#{project.path_with_namespace}/issues")
- expect(@service.new_issue_path).to eq("/gitlab/root/#{project.path_with_namespace}/issues/new")
- expect(@service.issue_path(432)).to eq("/gitlab/root/#{project.path_with_namespace}/issues/432")
- end
- end
- end
-end
diff --git a/spec/models/project_services/hipchat_service_spec.rb b/spec/models/project_services/hipchat_service_spec.rb
deleted file mode 100644
index 8ab847e6432..00000000000
--- a/spec/models/project_services/hipchat_service_spec.rb
+++ /dev/null
@@ -1,217 +0,0 @@
-# == Schema Information
-#
-# Table name: services
-#
-# id :integer not null, primary key
-# type :string(255)
-# title :string(255)
-# project_id :integer not null
-# created_at :datetime
-# updated_at :datetime
-# active :boolean default(FALSE), not null
-# properties :text
-# push_events :boolean default(TRUE)
-# issues_events :boolean default(TRUE)
-# merge_requests_events :boolean default(TRUE)
-# tag_push_events :boolean default(TRUE)
-#
-
-require 'spec_helper'
-
-describe HipchatService do
- describe "Associations" do
- it { is_expected.to belong_to :project }
- it { is_expected.to have_one :service_hook }
- end
-
- describe "Execute" do
- let(:hipchat) { HipchatService.new }
- let(:user) { create(:user, username: 'username') }
- let(:project) { create(:project, name: 'project') }
- let(:api_url) { 'https://hipchat.example.com/v2/room/123456/notification?auth_token=verySecret' }
- let(:project_name) { project.name_with_namespace.gsub(/\s/, '') }
-
- before(:each) do
- hipchat.stub(
- project_id: project.id,
- project: project,
- room: 123456,
- server: 'https://hipchat.example.com',
- token: 'verySecret'
- )
- WebMock.stub_request(:post, api_url)
- end
-
- context 'push events' do
- let(:push_sample_data) { Gitlab::PushDataBuilder.build_sample(project, user) }
-
- it "should call Hipchat API for push events" do
- hipchat.execute(push_sample_data)
-
- expect(WebMock).to have_requested(:post, api_url).once
- end
-
- it "should create a push message" do
- message = hipchat.send(:create_push_message, push_sample_data)
-
- obj_attr = push_sample_data[:object_attributes]
- branch = push_sample_data[:ref].gsub('refs/heads/', '')
- expect(message).to include("#{user.name} pushed to branch " \
- "<a href=\"#{project.web_url}/commits/#{branch}\">#{branch}</a> of " \
- "<a href=\"#{project.web_url}\">#{project_name}</a>")
- end
- end
-
- context 'tag_push events' do
- let(:push_sample_data) { Gitlab::PushDataBuilder.build(project, user, Gitlab::Git::BLANK_SHA, '1' * 40, 'refs/tags/test', []) }
-
- it "should call Hipchat API for tag push events" do
- hipchat.execute(push_sample_data)
-
- expect(WebMock).to have_requested(:post, api_url).once
- end
-
- it "should create a tag push message" do
- message = hipchat.send(:create_push_message, push_sample_data)
-
- obj_attr = push_sample_data[:object_attributes]
- expect(message).to eq("#{user.name} pushed new tag " \
- "<a href=\"#{project.web_url}/commits/test\">test</a> to " \
- "<a href=\"#{project.web_url}\">#{project_name}</a>\n")
- end
- end
-
- context 'issue events' do
- let(:issue) { create(:issue, title: 'Awesome issue', description: 'please fix') }
- let(:issue_service) { Issues::CreateService.new(project, user) }
- let(:issues_sample_data) { issue_service.hook_data(issue, 'open') }
-
- it "should call Hipchat API for issue events" do
- hipchat.execute(issues_sample_data)
-
- expect(WebMock).to have_requested(:post, api_url).once
- end
-
- it "should create an issue message" do
- message = hipchat.send(:create_issue_message, issues_sample_data)
-
- obj_attr = issues_sample_data[:object_attributes]
- expect(message).to eq("#{user.name} opened " \
- "<a href=\"#{obj_attr[:url]}\">issue ##{obj_attr["iid"]}</a> in " \
- "<a href=\"#{project.web_url}\">#{project_name}</a>: " \
- "<b>Awesome issue</b>" \
- "<pre>please fix</pre>")
- end
- end
-
- context 'merge request events' do
- let(:merge_request) { create(:merge_request, description: 'please fix', title: 'Awesome merge request', target_project: project, source_project: project) }
- let(:merge_service) { MergeRequests::CreateService.new(project, user) }
- let(:merge_sample_data) { merge_service.hook_data(merge_request, 'open') }
-
- it "should call Hipchat API for merge requests events" do
- hipchat.execute(merge_sample_data)
-
- expect(WebMock).to have_requested(:post, api_url).once
- end
-
- it "should create a merge request message" do
- message = hipchat.send(:create_merge_request_message,
- merge_sample_data)
-
- obj_attr = merge_sample_data[:object_attributes]
- expect(message).to eq("#{user.name} opened " \
- "<a href=\"#{obj_attr[:url]}\">merge request ##{obj_attr["iid"]}</a> in " \
- "<a href=\"#{project.web_url}\">#{project_name}</a>: " \
- "<b>Awesome merge request</b>" \
- "<pre>please fix</pre>")
- end
- end
-
- context "Note events" do
- let(:user) { create(:user) }
- let(:project) { create(:project, creator_id: user.id) }
- let(:issue) { create(:issue, project: project) }
- let(:merge_request) { create(:merge_request, source_project: project, target_project: project) }
- let(:snippet) { create(:project_snippet, project: project) }
- let(:commit_note) { create(:note_on_commit, author: user, project: project, commit_id: project.repository.commit.id, note: 'a comment on a commit') }
- let(:merge_request_note) { create(:note_on_merge_request, noteable_id: merge_request.id, note: "merge request note") }
- let(:issue_note) { create(:note_on_issue, noteable_id: issue.id, note: "issue note")}
- let(:snippet_note) { create(:note_on_project_snippet, noteable_id: snippet.id, note: "snippet note") }
-
- it "should call Hipchat API for commit comment events" do
- data = Gitlab::NoteDataBuilder.build(commit_note, user)
- hipchat.execute(data)
-
- expect(WebMock).to have_requested(:post, api_url).once
-
- message = hipchat.send(:create_message, data)
-
- obj_attr = data[:object_attributes]
- commit_id = Commit.truncate_sha(data[:commit][:id])
- title = hipchat.send(:format_title, data[:commit][:message])
-
- expect(message).to eq("#{user.name} commented on " \
- "<a href=\"#{obj_attr[:url]}\">commit #{commit_id}</a> in " \
- "<a href=\"#{project.web_url}\">#{project_name}</a>: " \
- "#{title}" \
- "<pre>a comment on a commit</pre>")
- end
-
- it "should call Hipchat API for merge request comment events" do
- data = Gitlab::NoteDataBuilder.build(merge_request_note, user)
- hipchat.execute(data)
-
- expect(WebMock).to have_requested(:post, api_url).once
-
- message = hipchat.send(:create_message, data)
-
- obj_attr = data[:object_attributes]
- merge_id = data[:merge_request]['iid']
- title = data[:merge_request]['title']
-
- expect(message).to eq("#{user.name} commented on " \
- "<a href=\"#{obj_attr[:url]}\">merge request ##{merge_id}</a> in " \
- "<a href=\"#{project.web_url}\">#{project_name}</a>: " \
- "<b>#{title}</b>" \
- "<pre>merge request note</pre>")
- end
-
- it "should call Hipchat API for issue comment events" do
- data = Gitlab::NoteDataBuilder.build(issue_note, user)
- hipchat.execute(data)
-
- message = hipchat.send(:create_message, data)
-
- obj_attr = data[:object_attributes]
- issue_id = data[:issue]['iid']
- title = data[:issue]['title']
-
- expect(message).to eq("#{user.name} commented on " \
- "<a href=\"#{obj_attr[:url]}\">issue ##{issue_id}</a> in " \
- "<a href=\"#{project.web_url}\">#{project_name}</a>: " \
- "<b>#{title}</b>" \
- "<pre>issue note</pre>")
- end
-
- it "should call Hipchat API for snippet comment events" do
- data = Gitlab::NoteDataBuilder.build(snippet_note, user)
- hipchat.execute(data)
-
- expect(WebMock).to have_requested(:post, api_url).once
-
- message = hipchat.send(:create_message, data)
-
- obj_attr = data[:object_attributes]
- snippet_id = data[:snippet]['id']
- title = data[:snippet]['title']
-
- expect(message).to eq("#{user.name} commented on " \
- "<a href=\"#{obj_attr[:url]}\">snippet ##{snippet_id}</a> in " \
- "<a href=\"#{project.web_url}\">#{project_name}</a>: " \
- "<b>#{title}</b>" \
- "<pre>snippet note</pre>")
- end
- end
- end
-end
diff --git a/spec/models/project_services/irker_service_spec.rb b/spec/models/project_services/irker_service_spec.rb
deleted file mode 100644
index d55399bc360..00000000000
--- a/spec/models/project_services/irker_service_spec.rb
+++ /dev/null
@@ -1,108 +0,0 @@
-# == Schema Information
-#
-# Table name: services
-#
-# id :integer not null, primary key
-# type :string(255)
-# title :string(255)
-# project_id :integer
-# created_at :datetime
-# updated_at :datetime
-# active :boolean default(FALSE), not null
-# properties :text
-# template :boolean default(FALSE)
-# push_events :boolean default(TRUE)
-# issues_events :boolean default(TRUE)
-# merge_requests_events :boolean default(TRUE)
-# tag_push_events :boolean default(TRUE)
-#
-
-require 'spec_helper'
-require 'socket'
-require 'json'
-
-describe IrkerService do
- describe 'Associations' do
- it { should belong_to :project }
- it { should have_one :service_hook }
- end
-
- describe 'Validations' do
- before do
- subject.active = true
- subject.properties['recipients'] = _recipients
- end
-
- context 'active' do
- let(:_recipients) { nil }
- it { should validate_presence_of :recipients }
- end
-
- context 'too many recipients' do
- let(:_recipients) { 'a b c d' }
- it 'should add an error if there is too many recipients' do
- subject.send :check_recipients_count
- subject.errors.should_not be_blank
- end
- end
-
- context '3 recipients' do
- let(:_recipients) { 'a b c' }
- it 'should not add an error if there is 3 recipients' do
- subject.send :check_recipients_count
- subject.errors.should be_blank
- end
- end
- end
-
- describe 'Execute' do
- let(:irker) { IrkerService.new }
- let(:user) { create(:user) }
- let(:project) { create(:project) }
- let(:sample_data) { Gitlab::PushDataBuilder.build_sample(project, user) }
-
- let(:recipients) { '#commits' }
- let(:colorize_messages) { '1' }
-
- before do
- irker.stub(
- active: true,
- project: project,
- project_id: project.id,
- service_hook: true,
- properties: {
- 'recipients' => recipients,
- 'colorize_messages' => colorize_messages
- }
- )
- irker.settings = {
- server_ip: 'localhost',
- server_port: 6659,
- max_channels: 3,
- default_irc_uri: 'irc://chat.freenode.net/'
- }
- irker.valid?
- @irker_server = TCPServer.new 'localhost', 6659
- end
-
- after do
- @irker_server.close
- end
-
- it 'should send valid JSON messages to an Irker listener' do
- irker.execute(sample_data)
-
- conn = @irker_server.accept
- conn.readlines.each do |line|
- msg = JSON.load(line.chomp("\n"))
- msg.keys.should match_array(['to', 'privmsg'])
- if msg['to'].is_a?(String)
- msg['to'].should == 'irc://chat.freenode.net/#commits'
- else
- msg['to'].should match_array(['irc://chat.freenode.net/#commits'])
- end
- end
- conn.close
- end
- end
-end
diff --git a/spec/models/project_services/jira_service_spec.rb b/spec/models/project_services/jira_service_spec.rb
deleted file mode 100644
index 355911e6377..00000000000
--- a/spec/models/project_services/jira_service_spec.rb
+++ /dev/null
@@ -1,102 +0,0 @@
-# == Schema Information
-#
-# Table name: services
-#
-# id :integer not null, primary key
-# type :string(255)
-# title :string(255)
-# project_id :integer
-# created_at :datetime
-# updated_at :datetime
-# active :boolean default(FALSE), not null
-# properties :text
-# template :boolean default(FALSE)
-# push_events :boolean default(TRUE)
-# issues_events :boolean default(TRUE)
-# merge_requests_events :boolean default(TRUE)
-# tag_push_events :boolean default(TRUE)
-#
-
-require 'spec_helper'
-
-describe JiraService do
- describe "Associations" do
- it { is_expected.to belong_to :project }
- it { is_expected.to have_one :service_hook }
- end
-
- describe "Validations" do
- context "active" do
- before do
- subject.active = true
- end
-
- it { is_expected.to validate_presence_of :project_url }
- it { is_expected.to validate_presence_of :issues_url }
- it { is_expected.to validate_presence_of :new_issue_url }
- end
- end
-
- describe 'description and title' do
- let(:project) { create(:project) }
-
- context 'when it is not set' do
- before do
- @service = project.create_jira_service(active: true)
- end
-
- after do
- @service.destroy!
- end
-
- it 'should be initialized' do
- expect(@service.title).to eq('JIRA')
- expect(@service.description).to eq("Jira issue tracker")
- end
- end
-
- context 'when it is set' do
- before do
- properties = { 'title' => 'Jira One', 'description' => 'Jira One issue tracker' }
- @service = project.create_jira_service(active: true, properties: properties)
- end
-
- after do
- @service.destroy!
- end
-
- it "should be correct" do
- expect(@service.title).to eq('Jira One')
- expect(@service.description).to eq('Jira One issue tracker')
- end
- end
- end
-
- describe 'project and issue urls' do
- let(:project) { create(:project) }
-
- context 'when gitlab.yml was initialized' do
- before do
- settings = { "jira" => {
- "title" => "Jira",
- "project_url" => "http://jira.sample/projects/project_a",
- "issues_url" => "http://jira.sample/issues/:id",
- "new_issue_url" => "http://jira.sample/projects/project_a/issues/new"
- }
- }
- allow(Gitlab.config).to receive(:issues_tracker).and_return(settings)
- @service = project.create_jira_service(active: true)
- end
-
- after do
- @service.destroy!
- end
-
- it 'should be prepopulated with the settings' do
- expect(@service.properties[:project_url]).to eq('http://jira.sample/projects/project_a')
- expect(@service.properties[:issues_url]).to eq("http://jira.sample/issues/:id")
- expect(@service.properties[:new_issue_url]).to eq("http://jira.sample/projects/project_a/issues/new")
- end
- end
- end
-end
diff --git a/spec/models/project_services/pushover_service_spec.rb b/spec/models/project_services/pushover_service_spec.rb
deleted file mode 100644
index 5a18fd09bfc..00000000000
--- a/spec/models/project_services/pushover_service_spec.rb
+++ /dev/null
@@ -1,74 +0,0 @@
-# == Schema Information
-#
-# Table name: services
-#
-# id :integer not null, primary key
-# type :string(255)
-# title :string(255)
-# project_id :integer
-# created_at :datetime
-# updated_at :datetime
-# active :boolean default(FALSE), not null
-# properties :text
-# template :boolean default(FALSE)
-# push_events :boolean default(TRUE)
-# issues_events :boolean default(TRUE)
-# merge_requests_events :boolean default(TRUE)
-# tag_push_events :boolean default(TRUE)
-#
-
-require 'spec_helper'
-
-describe PushoverService do
- describe 'Associations' do
- it { is_expected.to belong_to :project }
- it { is_expected.to have_one :service_hook }
- end
-
- describe 'Validations' do
- context 'active' do
- before do
- subject.active = true
- end
-
- it { is_expected.to validate_presence_of :api_key }
- it { is_expected.to validate_presence_of :user_key }
- it { is_expected.to validate_presence_of :priority }
- end
- end
-
- describe 'Execute' do
- let(:pushover) { PushoverService.new }
- let(:user) { create(:user) }
- let(:project) { create(:project) }
- let(:sample_data) { Gitlab::PushDataBuilder.build_sample(project, user) }
-
- let(:api_key) { 'verySecret' }
- let(:user_key) { 'verySecret' }
- let(:device) { 'myDevice' }
- let(:priority) { 0 }
- let(:sound) { 'bike' }
- let(:api_url) { 'https://api.pushover.net/1/messages.json' }
-
- before do
- pushover.stub(
- project: project,
- project_id: project.id,
- service_hook: true,
- api_key: api_key,
- user_key: user_key,
- device: device,
- priority: priority,
- sound: sound
- )
-
- WebMock.stub_request(:post, api_url)
- end
-
- it 'should call Pushover API' do
- pushover.execute(sample_data)
-
- expect(WebMock).to have_requested(:post, api_url).once
- end
- end
-end
diff --git a/spec/models/project_services/slack_service/issue_message_spec.rb b/spec/models/project_services/slack_service/issue_message_spec.rb
deleted file mode 100644
index 8bca1fef44c..00000000000
--- a/spec/models/project_services/slack_service/issue_message_spec.rb
+++ /dev/null
@@ -1,56 +0,0 @@
-require 'spec_helper'
-
-describe SlackService::IssueMessage do
- subject { SlackService::IssueMessage.new(args) }
-
- let(:args) {
- {
- user: {
- name: 'Test User',
- username: 'Test User'
- },
- project_name: 'project_name',
- project_url: 'somewhere.com',
-
- object_attributes: {
- title: 'Issue title',
- id: 10,
- iid: 100,
- assignee_id: 1,
- url: 'url',
- action: 'open',
- state: 'opened',
- description: 'issue description'
- }
- }
- }
-
- let(:color) { '#345' }
-
- context 'open' do
- it 'returns a message regarding opening of issues' do
- expect(subject.pretext).to eq(
- 'Test User opened <url|issue #100> in <somewhere.com|project_name>: '\
- '*Issue title*')
- expect(subject.attachments).to eq([
- {
- text: "issue description",
- color: color,
- }
- ])
- end
- end
-
- context 'close' do
- before do
- args[:object_attributes][:action] = 'close'
- args[:object_attributes][:state] = 'closed'
- end
- it 'returns a message regarding closing of issues' do
- expect(subject.pretext). to eq(
- 'Test User closed <url|issue #100> in <somewhere.com|project_name>: '\
- '*Issue title*')
- expect(subject.attachments).to be_empty
- end
- end
-end
diff --git a/spec/models/project_services/slack_service/merge_message_spec.rb b/spec/models/project_services/slack_service/merge_message_spec.rb
deleted file mode 100644
index aeb408aa766..00000000000
--- a/spec/models/project_services/slack_service/merge_message_spec.rb
+++ /dev/null
@@ -1,51 +0,0 @@
-require 'spec_helper'
-
-describe SlackService::MergeMessage do
- subject { SlackService::MergeMessage.new(args) }
-
- let(:args) {
- {
- user: {
- name: 'Test User',
- username: 'Test User'
- },
- project_name: 'project_name',
- project_url: 'somewhere.com',
-
- object_attributes: {
- title: "Issue title\nSecond line",
- id: 10,
- iid: 100,
- assignee_id: 1,
- url: 'url',
- state: 'opened',
- description: 'issue description',
- source_branch: 'source_branch',
- target_branch: 'target_branch',
- }
- }
- }
-
- let(:color) { '#345' }
-
- context 'open' do
- it 'returns a message regarding opening of merge requests' do
- expect(subject.pretext).to eq(
- 'Test User opened <somewhere.com/merge_requests/100|merge request #100> '\
- 'in <somewhere.com|project_name>: *Issue title*')
- expect(subject.attachments).to be_empty
- end
- end
-
- context 'close' do
- before do
- args[:object_attributes][:state] = 'closed'
- end
- it 'returns a message regarding closing of merge requests' do
- expect(subject.pretext).to eq(
- 'Test User closed <somewhere.com/merge_requests/100|merge request #100> '\
- 'in <somewhere.com|project_name>: *Issue title*')
- expect(subject.attachments).to be_empty
- end
- end
-end
diff --git a/spec/models/project_services/slack_service/note_message_spec.rb b/spec/models/project_services/slack_service/note_message_spec.rb
deleted file mode 100644
index 21fb575480b..00000000000
--- a/spec/models/project_services/slack_service/note_message_spec.rb
+++ /dev/null
@@ -1,129 +0,0 @@
-require 'spec_helper'
-
-describe SlackService::NoteMessage do
- let(:color) { '#345' }
-
- before do
- @args = {
- user: {
- name: 'Test User',
- username: 'username',
- avatar_url: 'http://fakeavatar'
- },
- project_name: 'project_name',
- project_url: 'somewhere.com',
- repository: {
- name: 'project_name',
- url: 'somewhere.com',
- },
- object_attributes: {
- id: 10,
- note: 'comment on a commit',
- url: 'url',
- noteable_type: 'Commit'
- }
- }
- end
-
- context 'commit notes' do
- before do
- @args[:object_attributes][:note] = 'comment on a commit'
- @args[:object_attributes][:noteable_type] = 'Commit'
- @args[:commit] = {
- id: '5f163b2b95e6f53cbd428f5f0b103702a52b9a23',
- message: "Added a commit message\ndetails\n123\n"
- }
- end
-
- it 'returns a message regarding notes on commits' do
- message = SlackService::NoteMessage.new(@args)
- expect(message.pretext).to eq("Test User commented on " \
- "<url|commit 5f163b2b> in <somewhere.com|project_name>: " \
- "*Added a commit message*")
- expected_attachments = [
- {
- text: "comment on a commit",
- color: color,
- }
- ]
- expect(message.attachments).to eq(expected_attachments)
- end
- end
-
- context 'merge request notes' do
- before do
- @args[:object_attributes][:note] = 'comment on a merge request'
- @args[:object_attributes][:noteable_type] = 'MergeRequest'
- @args[:merge_request] = {
- id: 1,
- iid: 30,
- title: "merge request title\ndetails\n"
- }
- end
- it 'returns a message regarding notes on a merge request' do
- message = SlackService::NoteMessage.new(@args)
- expect(message.pretext).to eq("Test User commented on " \
- "<url|merge request #30> in <somewhere.com|project_name>: " \
- "*merge request title*")
- expected_attachments = [
- {
- text: "comment on a merge request",
- color: color,
- }
- ]
- expect(message.attachments).to eq(expected_attachments)
- end
- end
-
- context 'issue notes' do
- before do
- @args[:object_attributes][:note] = 'comment on an issue'
- @args[:object_attributes][:noteable_type] = 'Issue'
- @args[:issue] = {
- id: 1,
- iid: 20,
- title: "issue title\ndetails\n"
- }
- end
-
- it 'returns a message regarding notes on an issue' do
- message = SlackService::NoteMessage.new(@args)
- expect(message.pretext).to eq(
- "Test User commented on " \
- "<url|issue #20> in <somewhere.com|project_name>: " \
- "*issue title*")
- expected_attachments = [
- {
- text: "comment on an issue",
- color: color,
- }
- ]
- expect(message.attachments).to eq(expected_attachments)
- end
- end
-
- context 'project snippet notes' do
- before do
- @args[:object_attributes][:note] = 'comment on a snippet'
- @args[:object_attributes][:noteable_type] = 'Snippet'
- @args[:snippet] = {
- id: 5,
- title: "snippet title\ndetails\n"
- }
- end
-
- it 'returns a message regarding notes on a project snippet' do
- message = SlackService::NoteMessage.new(@args)
- expect(message.pretext).to eq("Test User commented on " \
- "<url|snippet #5> in <somewhere.com|project_name>: " \
- "*snippet title*")
- expected_attachments = [
- {
- text: "comment on a snippet",
- color: color,
- }
- ]
- expect(message.attachments).to eq(expected_attachments)
- end
- end
-end
diff --git a/spec/models/project_services/slack_service/push_message_spec.rb b/spec/models/project_services/slack_service/push_message_spec.rb
deleted file mode 100644
index 10963481a12..00000000000
--- a/spec/models/project_services/slack_service/push_message_spec.rb
+++ /dev/null
@@ -1,88 +0,0 @@
-require 'spec_helper'
-
-describe SlackService::PushMessage do
- subject { SlackService::PushMessage.new(args) }
-
- let(:args) {
- {
- after: 'after',
- before: 'before',
- project_name: 'project_name',
- ref: 'refs/heads/master',
- user_name: 'user_name',
- project_url: 'url'
- }
- }
-
- let(:color) { '#345' }
-
- context 'push' do
- before do
- args[:commits] = [
- { message: 'message1', url: 'url1', id: 'abcdefghijkl', author: { name: 'author1' } },
- { message: 'message2', url: 'url2', id: '123456789012', author: { name: 'author2' } },
- ]
- end
-
- it 'returns a message regarding pushes' do
- expect(subject.pretext).to eq(
- 'user_name pushed to branch <url/commits/master|master> of '\
- '<url|project_name> (<url/compare/before...after|Compare changes>)'
- )
- expect(subject.attachments).to eq([
- {
- text: "<url1|abcdefgh>: message1 - author1\n"\
- "<url2|12345678>: message2 - author2",
- color: color,
- }
- ])
- end
- end
-
- context 'tag push' do
- let(:args) {
- {
- after: 'after',
- before: Gitlab::Git::BLANK_SHA,
- project_name: 'project_name',
- ref: 'refs/tags/new_tag',
- user_name: 'user_name',
- project_url: 'url'
- }
- }
-
- it 'returns a message regarding pushes' do
- expect(subject.pretext).to eq('user_name pushed new tag ' \
- '<url/commits/new_tag|new_tag> to ' \
- '<url|project_name>')
- expect(subject.attachments).to be_empty
- end
- end
-
- context 'new branch' do
- before do
- args[:before] = Gitlab::Git::BLANK_SHA
- end
-
- it 'returns a message regarding a new branch' do
- expect(subject.pretext).to eq(
- 'user_name pushed new branch <url/commits/master|master> to '\
- '<url|project_name>'
- )
- expect(subject.attachments).to be_empty
- end
- end
-
- context 'removed branch' do
- before do
- args[:after] = Gitlab::Git::BLANK_SHA
- end
-
- it 'returns a message regarding a removed branch' do
- expect(subject.pretext).to eq(
- 'user_name removed branch master from <url|project_name>'
- )
- expect(subject.attachments).to be_empty
- end
- end
-end
diff --git a/spec/models/project_services/slack_service_spec.rb b/spec/models/project_services/slack_service_spec.rb
deleted file mode 100644
index c36506644b3..00000000000
--- a/spec/models/project_services/slack_service_spec.rb
+++ /dev/null
@@ -1,170 +0,0 @@
-# == Schema Information
-#
-# Table name: services
-#
-# id :integer not null, primary key
-# type :string(255)
-# title :string(255)
-# project_id :integer
-# created_at :datetime
-# updated_at :datetime
-# active :boolean default(FALSE), not null
-# properties :text
-# template :boolean default(FALSE)
-# push_events :boolean default(TRUE)
-# issues_events :boolean default(TRUE)
-# merge_requests_events :boolean default(TRUE)
-# tag_push_events :boolean default(TRUE)
-#
-
-require 'spec_helper'
-
-describe SlackService do
- describe "Associations" do
- it { is_expected.to belong_to :project }
- it { is_expected.to have_one :service_hook }
- end
-
- describe "Validations" do
- context "active" do
- before do
- subject.active = true
- end
-
- it { is_expected.to validate_presence_of :webhook }
- end
- end
-
- describe "Execute" do
- let(:slack) { SlackService.new }
- let(:user) { create(:user) }
- let(:project) { create(:project) }
- let(:push_sample_data) { Gitlab::PushDataBuilder.build_sample(project, user) }
- let(:webhook_url) { 'https://hooks.slack.com/services/SVRWFV0VVAR97N/B02R25XN3/ZBqu7xMupaEEICInN685' }
- let(:username) { 'slack_username' }
- let(:channel) { 'slack_channel' }
-
- before do
- slack.stub(
- project: project,
- project_id: project.id,
- service_hook: true,
- webhook: webhook_url
- )
-
- WebMock.stub_request(:post, webhook_url)
-
- opts = {
- title: 'Awesome issue',
- description: 'please fix'
- }
-
- issue_service = Issues::CreateService.new(project, user, opts)
- @issue = issue_service.execute
- @issues_sample_data = issue_service.hook_data(@issue, 'open')
-
- opts = {
- title: 'Awesome merge_request',
- description: 'please fix',
- source_branch: 'stable',
- target_branch: 'master'
- }
- merge_service = MergeRequests::CreateService.new(project,
- user, opts)
- @merge_request = merge_service.execute
- @merge_sample_data = merge_service.hook_data(@merge_request,
- 'open')
- end
-
- it "should call Slack API for push events" do
- slack.execute(push_sample_data)
-
- expect(WebMock).to have_requested(:post, webhook_url).once
- end
-
- it "should call Slack API for issue events" do
- slack.execute(@issues_sample_data)
-
- expect(WebMock).to have_requested(:post, webhook_url).once
- end
-
- it "should call Slack API for merge requests events" do
- slack.execute(@merge_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
- slack.stub(username: username)
- expect(Slack::Notifier).to receive(:new).
- with(webhook_url, username: username).
- and_return(
- double(:slack_service).as_null_object
- )
- slack.execute(push_sample_data)
- end
-
- it 'should use the channel as an option when it is configured' do
- slack.stub(channel: channel)
- expect(Slack::Notifier).to receive(:new).
- with(webhook_url, channel: channel).
- and_return(
- double(:slack_service).as_null_object
- )
- slack.execute(push_sample_data)
- end
- end
-
- describe "Note events" do
- let(:slack) { SlackService.new }
- let(:user) { create(:user) }
- let(:project) { create(:project, creator_id: user.id) }
- let(:issue) { create(:issue, project: project) }
- let(:merge_request) { create(:merge_request, source_project: project, target_project: project) }
- let(:snippet) { create(:project_snippet, project: project) }
- let(:commit_note) { create(:note_on_commit, author: user, project: project, commit_id: project.repository.commit.id, note: 'a comment on a commit') }
- let(:merge_request_note) { create(:note_on_merge_request, noteable_id: merge_request.id, note: "merge request note") }
- let(:issue_note) { create(:note_on_issue, noteable_id: issue.id, note: "issue note")}
- let(:snippet_note) { create(:note_on_project_snippet, noteable_id: snippet.id, note: "snippet note") }
- let(:webhook_url) { 'https://hooks.slack.com/services/SVRWFV0VVAR97N/B02R25XN3/ZBqu7xMupaEEICInN685' }
-
- before do
- slack.stub(
- project: project,
- project_id: project.id,
- service_hook: true,
- webhook: webhook_url
- )
-
- WebMock.stub_request(:post, webhook_url)
- end
-
- it "should call Slack API for commit comment events" do
- data = Gitlab::NoteDataBuilder.build(commit_note, user)
- slack.execute(data)
-
- expect(WebMock).to have_requested(:post, webhook_url).once
- end
-
- it "should call Slack API for merge request comment events" do
- data = Gitlab::NoteDataBuilder.build(merge_request_note, user)
- slack.execute(data)
-
- expect(WebMock).to have_requested(:post, webhook_url).once
- end
-
- it "should call Slack API for issue comment events" do
- data = Gitlab::NoteDataBuilder.build(issue_note, user)
- slack.execute(data)
-
- expect(WebMock).to have_requested(:post, webhook_url).once
- end
-
- it "should call Slack API for snippet comment events" do
- data = Gitlab::NoteDataBuilder.build(snippet_note, user)
- slack.execute(data)
-
- expect(WebMock).to have_requested(:post, webhook_url).once
- end
- end
-end