2013-08-19 09:11:36 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2017-07-10 14:24:02 +00:00
|
|
|
describe FlowdockService do
|
2013-08-19 09:11:36 +00:00
|
|
|
describe "Associations" do
|
2015-02-12 18:17:35 +00:00
|
|
|
it { is_expected.to belong_to :project }
|
|
|
|
it { is_expected.to have_one :service_hook }
|
2013-08-19 09:11:36 +00:00
|
|
|
end
|
|
|
|
|
2016-04-21 15:13:14 +00:00
|
|
|
describe 'Validations' do
|
|
|
|
context 'when service is active' do
|
2017-06-14 18:18:56 +00:00
|
|
|
before do
|
|
|
|
subject.active = true
|
|
|
|
end
|
2016-04-21 15:13:14 +00:00
|
|
|
|
|
|
|
it { is_expected.to validate_presence_of(:token) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when service is inactive' do
|
2017-06-14 18:18:56 +00:00
|
|
|
before do
|
|
|
|
subject.active = false
|
|
|
|
end
|
2016-04-21 15:13:14 +00:00
|
|
|
|
|
|
|
it { is_expected.not_to validate_presence_of(:token) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-08-19 09:11:36 +00:00
|
|
|
describe "Execute" do
|
|
|
|
let(:user) { create(:user) }
|
2017-01-26 22:44:58 +00:00
|
|
|
let(:project) { create(:project, :repository) }
|
2013-08-19 09:11:36 +00:00
|
|
|
|
|
|
|
before do
|
2017-07-25 17:09:00 +00:00
|
|
|
@flowdock_service = described_class.new
|
2015-05-21 21:49:06 +00:00
|
|
|
allow(@flowdock_service).to receive_messages(
|
2013-08-19 09:11:36 +00:00
|
|
|
project_id: project.id,
|
|
|
|
project: project,
|
|
|
|
service_hook: true,
|
|
|
|
token: 'verySecret'
|
|
|
|
)
|
2016-08-12 08:09:29 +00:00
|
|
|
@sample_data = Gitlab::DataBuilder::Push.build_sample(project, user)
|
2015-08-14 13:31:11 +00:00
|
|
|
@api_url = 'https://api.flowdock.com/v1/messages'
|
2013-08-19 09:11:36 +00:00
|
|
|
WebMock.stub_request(:post, @api_url)
|
|
|
|
end
|
|
|
|
|
2016-08-01 15:00:44 +00:00
|
|
|
it "calls FlowDock API" do
|
2013-08-19 09:11:36 +00:00
|
|
|
@flowdock_service.execute(@sample_data)
|
2015-08-14 13:31:11 +00:00
|
|
|
@sample_data[:commits].each do |commit|
|
|
|
|
# One request to Flowdock per new commit
|
|
|
|
next if commit[:id] == @sample_data[:before]
|
|
|
|
expect(WebMock).to have_requested(:post, @api_url).with(
|
|
|
|
body: /#{commit[:id]}.*#{project.path}/
|
|
|
|
).once
|
|
|
|
end
|
2013-08-19 09:11:36 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|