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/integrations/drone_ci_spec.rb')
-rw-r--r--spec/models/integrations/drone_ci_spec.rb58
1 files changed, 36 insertions, 22 deletions
diff --git a/spec/models/integrations/drone_ci_spec.rb b/spec/models/integrations/drone_ci_spec.rb
index 137f078edca..062e23d628e 100644
--- a/spec/models/integrations/drone_ci_spec.rb
+++ b/spec/models/integrations/drone_ci_spec.rb
@@ -5,11 +5,6 @@ require 'spec_helper'
RSpec.describe Integrations::DroneCi, :use_clean_rails_memory_store_caching do
include ReactiveCachingHelpers
- 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
@@ -18,7 +13,7 @@ RSpec.describe Integrations::DroneCi, :use_clean_rails_memory_store_caching do
it { is_expected.to validate_presence_of(:token) }
it { is_expected.to validate_presence_of(:drone_url) }
- it_behaves_like 'issue tracker service URL attribute', :drone_url
+ it_behaves_like 'issue tracker integration URL attribute', :drone_url
end
context 'inactive' do
@@ -32,7 +27,15 @@ RSpec.describe Integrations::DroneCi, :use_clean_rails_memory_store_caching do
end
shared_context :drone_ci_integration do
- let(:drone) { described_class.new }
+ subject(:drone) do
+ described_class.new(
+ project: project,
+ active: true,
+ drone_url: drone_url,
+ token: token
+ )
+ end
+
let(:project) { create(:project, :repository, name: 'project') }
let(:path) { project.full_path }
let(:drone_url) { 'http://drone.example.com' }
@@ -45,16 +48,6 @@ RSpec.describe Integrations::DroneCi, :use_clean_rails_memory_store_caching do
let(:build_page) { "#{drone_url}/gitlab/#{path}/redirect/commits/#{sha}?branch=#{branch}" }
let(:commit_status_path) { "#{drone_url}/gitlab/#{path}/commits/#{sha}?branch=#{branch}&access_token=#{token}" }
- before do
- allow(drone).to receive_messages(
- project_id: project.id,
- project: project,
- active: true,
- drone_url: drone_url,
- token: token
- )
- end
-
def stub_request(status: 200, body: nil)
body ||= %q({"status":"success"})
@@ -66,7 +59,21 @@ RSpec.describe Integrations::DroneCi, :use_clean_rails_memory_store_caching do
end
end
- describe "service page/path methods" do
+ it_behaves_like Integrations::HasWebHook do
+ include_context :drone_ci_integration
+
+ let(:integration) { drone }
+ let(:hook_url) { "#{drone_url}/hook?owner=#{project.namespace.full_path}&name=#{project.path}&access_token=#{token}" }
+
+ it 'does not create a hook if project is not present' do
+ integration.project = nil
+ integration.instance = true
+
+ expect { integration.save! }.not_to change(ServiceHook, :count)
+ end
+ end
+
+ describe "integration page/path methods" do
include_context :drone_ci_integration
it { expect(drone.build_page(sha, branch)).to eq(build_page) }
@@ -137,10 +144,17 @@ RSpec.describe Integrations::DroneCi, :use_clean_rails_memory_store_caching do
Gitlab::DataBuilder::Push.build_sample(project, user)
end
- it do
- service_hook = double
- expect(service_hook).to receive(:execute)
- expect(drone).to receive(:service_hook).and_return(service_hook)
+ it 'executes the webhook' do
+ expect(drone).to receive(:execute_web_hook!).with(push_sample_data)
+
+ drone.execute(push_sample_data)
+ end
+
+ it 'does not try to execute the webhook if the integration is not in a project' do
+ drone.project = nil
+ drone.instance = true
+
+ expect(drone).not_to receive(:execute_web_hook!)
drone.execute(push_sample_data)
end