2019-03-30 07:23:56 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2013-11-21 12:18:02 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 18:09:03 +00:00
|
|
|
RSpec.describe AssemblaService do
|
2019-04-21 10:03:26 +00:00
|
|
|
include StubRequests
|
|
|
|
|
2013-11-21 12:18:02 +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-11-21 12:18:02 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
describe "Execute" do
|
|
|
|
let(:user) { create(:user) }
|
2017-01-26 22:44:58 +00:00
|
|
|
let(:project) { create(:project, :repository) }
|
2013-11-21 12:18:02 +00:00
|
|
|
|
|
|
|
before do
|
2017-07-25 17:09:00 +00:00
|
|
|
@assembla_service = described_class.new
|
2015-05-21 21:49:06 +00:00
|
|
|
allow(@assembla_service).to receive_messages(
|
2013-11-21 12:18:02 +00:00
|
|
|
project_id: project.id,
|
|
|
|
project: project,
|
|
|
|
service_hook: true,
|
2014-01-24 07:42:24 +00:00
|
|
|
token: 'verySecret',
|
|
|
|
subdomain: 'project_name'
|
2013-11-21 12:18:02 +00:00
|
|
|
)
|
2016-08-12 08:09:29 +00:00
|
|
|
@sample_data = Gitlab::DataBuilder::Push.build_sample(project, user)
|
2014-01-24 07:42:24 +00:00
|
|
|
@api_url = 'https://atlas.assembla.com/spaces/project_name/github_tool?secret_key=verySecret'
|
2019-04-21 10:03:26 +00:00
|
|
|
stub_full_request(@api_url, method: :post)
|
2013-11-21 12:18:02 +00:00
|
|
|
end
|
|
|
|
|
2016-08-01 15:00:44 +00:00
|
|
|
it "calls Assembla API" do
|
2013-11-21 12:18:02 +00:00
|
|
|
@assembla_service.execute(@sample_data)
|
2019-04-21 10:03:26 +00:00
|
|
|
expect(WebMock).to have_requested(:post, stubbed_hostname(@api_url)).with(
|
2013-11-21 12:18:02 +00:00
|
|
|
body: /#{@sample_data[:before]}.*#{@sample_data[:after]}.*#{project.path}/
|
|
|
|
).once
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|