2014-08-18 06:54:51 -04:00
|
|
|
# == Schema Information
|
|
|
|
#
|
|
|
|
# Table name: services
|
|
|
|
#
|
2015-02-19 00:02:57 -05:00
|
|
|
# id :integer not null, primary key
|
|
|
|
# type :string(255)
|
|
|
|
# title :string(255)
|
2015-03-04 17:14:00 -05:00
|
|
|
# project_id :integer
|
2015-02-19 00:02:57 -05:00
|
|
|
# created_at :datetime
|
|
|
|
# updated_at :datetime
|
|
|
|
# active :boolean default(FALSE), not null
|
|
|
|
# properties :text
|
2015-03-04 17:14:00 -05:00
|
|
|
# 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)
|
2015-05-03 12:05:38 -04:00
|
|
|
# note_events :boolean default(TRUE), not null
|
2014-08-18 06:54:51 -04:00
|
|
|
#
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
2015-12-09 04:50:51 -05:00
|
|
|
describe BuildkiteService, models: true do
|
2014-08-18 06:54:51 -04:00
|
|
|
describe 'Associations' do
|
2015-02-12 13:17:35 -05:00
|
|
|
it { is_expected.to belong_to :project }
|
|
|
|
it { is_expected.to have_one :service_hook }
|
2014-08-18 06:54:51 -04:00
|
|
|
end
|
|
|
|
|
2016-04-21 11:13:14 -04:00
|
|
|
describe 'Validations' do
|
|
|
|
context 'when service is active' do
|
|
|
|
before { subject.active = true }
|
|
|
|
|
|
|
|
it { is_expected.to validate_presence_of(:project_url) }
|
|
|
|
it { is_expected.to validate_presence_of(:token) }
|
|
|
|
it_behaves_like 'issue tracker service URL attribute', :project_url
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when service is inactive' do
|
|
|
|
before { subject.active = false }
|
|
|
|
|
|
|
|
it { is_expected.not_to validate_presence_of(:project_url) }
|
|
|
|
it { is_expected.not_to validate_presence_of(:token) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-08-18 06:54:51 -04:00
|
|
|
describe 'commits methods' do
|
|
|
|
before do
|
|
|
|
@project = Project.new
|
2015-05-21 17:49:06 -04:00
|
|
|
allow(@project).to receive(:default_branch).and_return('default-brancho')
|
2014-08-18 06:54:51 -04:00
|
|
|
|
2015-04-11 14:02:13 -04:00
|
|
|
@service = BuildkiteService.new
|
2015-05-21 17:49:06 -04:00
|
|
|
allow(@service).to receive_messages(
|
2014-08-18 06:54:51 -04:00
|
|
|
project: @project,
|
|
|
|
service_hook: true,
|
2015-03-26 07:40:43 -04:00
|
|
|
project_url: 'https://buildkite.com/account-name/example-project',
|
2014-08-18 06:54:51 -04:00
|
|
|
token: 'secret-sauce-webhook-token:secret-sauce-status-token'
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
2016-07-11 18:12:31 -04:00
|
|
|
describe '#webhook_url' do
|
2014-08-18 06:54:51 -04:00
|
|
|
it 'returns the webhook url' do
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(@service.webhook_url).to eq(
|
2015-03-26 07:40:43 -04:00
|
|
|
'https://webhook.buildkite.com/deliver/secret-sauce-webhook-token'
|
2015-02-12 13:17:35 -05:00
|
|
|
)
|
2014-08-18 06:54:51 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-07-11 18:12:31 -04:00
|
|
|
describe '#commit_status_path' do
|
2014-08-18 06:54:51 -04:00
|
|
|
it 'returns the correct status page' do
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(@service.commit_status_path('2ab7834c')).to eq(
|
2015-03-26 07:40:43 -04:00
|
|
|
'https://gitlab.buildkite.com/status/secret-sauce-status-token.json?commit=2ab7834c'
|
2015-02-12 13:17:35 -05:00
|
|
|
)
|
2014-08-18 06:54:51 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-07-11 18:12:31 -04:00
|
|
|
describe '#build_page' do
|
2014-08-18 06:54:51 -04:00
|
|
|
it 'returns the correct build page' do
|
2015-03-05 09:58:04 -05:00
|
|
|
expect(@service.build_page('2ab7834c', nil)).to eq(
|
2015-03-26 07:40:43 -04:00
|
|
|
'https://buildkite.com/account-name/example-project/builds?commit=2ab7834c'
|
2015-02-12 13:17:35 -05:00
|
|
|
)
|
2014-08-18 06:54:51 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|