diff options
author | Douwe Maan <douwe@gitlab.com> | 2015-10-07 15:15:35 +0200 |
---|---|---|
committer | Douwe Maan <douwe@gitlab.com> | 2015-10-07 15:15:35 +0200 |
commit | 4f629dab2a14c190b641bd709c28ebdad5b7a062 (patch) | |
tree | 00035d114b896a38b4a2a6ac835411ba36d3e1e5 /spec/models/project_services/drone_ci_service_spec.rb | |
parent | 48837850838c8acb0c02ae60b29e18d287865878 (diff) | |
parent | 0611a18964a998b6edc81ef9b469f9f70430e542 (diff) | |
download | gitlab-ce-4f629dab2a14c190b641bd709c28ebdad5b7a062.tar.gz |
Merge branch 'master' into rs-redactor-filter
Diffstat (limited to 'spec/models/project_services/drone_ci_service_spec.rb')
-rw-r--r-- | spec/models/project_services/drone_ci_service_spec.rb | 104 |
1 files changed, 104 insertions, 0 deletions
diff --git a/spec/models/project_services/drone_ci_service_spec.rb b/spec/models/project_services/drone_ci_service_spec.rb new file mode 100644 index 00000000000..e9967f5fe0b --- /dev/null +++ b/spec/models/project_services/drone_ci_service_spec.rb @@ -0,0 +1,104 @@ +# == 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) +# note_events :boolean default(TRUE), not null +# + +require 'spec_helper' + +describe DroneCiService 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 { allow(subject).to receive(:activated?).and_return(true) } + + it { is_expected.to validate_presence_of(:token) } + it { is_expected.to validate_presence_of(:drone_url) } + it { is_expected.to allow_value('ewf9843kdnfdfs89234n').for(:token) } + it { is_expected.to allow_value('http://ci.example.com').for(:drone_url) } + it { is_expected.not_to allow_value('this is not url').for(:drone_url) } + it { is_expected.not_to allow_value('http//noturl').for(:drone_url) } + it { is_expected.not_to allow_value('ftp://ci.example.com').for(:drone_url) } + end + + context 'inactive' do + before { allow(subject).to receive(:activated?).and_return(false) } + + it { is_expected.not_to validate_presence_of(:token) } + it { is_expected.not_to validate_presence_of(:drone_url) } + it { is_expected.to allow_value('ewf9843kdnfdfs89234n').for(:token) } + it { is_expected.to allow_value('http://drone.example.com').for(:drone_url) } + it { is_expected.to allow_value('ftp://drone.example.com').for(:drone_url) } + end + end + + shared_context :drone_ci_service do + let(:drone) { DroneCiService.new } + let(:project) { create(:project, name: 'project') } + let(:path) { "#{project.namespace.path}/#{project.path}" } + let(:drone_url) { 'http://drone.example.com' } + let(:sha) { '2ab7834c' } + let(:branch) { 'dev' } + let(:token) { 'secret' } + let(:iid) { rand(1..9999) } + + before(:each) do + allow(drone).to receive_messages( + project_id: project.id, + project: project, + active: true, + drone_url: drone_url, + token: token + ) + end + end + + describe "service page/path methods" do + include_context :drone_ci_service + + # URL's + let(:commit_page) { "#{drone_url}/gitlab/#{path}/redirect/commits/#{sha}?branch=#{branch}" } + let(:merge_request_page) { "#{drone_url}/gitlab/#{path}/redirect/pulls/#{iid}" } + let(:commit_status_path) { "#{drone_url}/gitlab/#{path}/commits/#{sha}?branch=#{branch}&access_token=#{token}" } + let(:merge_request_status_path) { "#{drone_url}/gitlab/#{path}/pulls/#{iid}?access_token=#{token}" } + + it { expect(drone.build_page(sha, branch)).to eq(commit_page) } + it { expect(drone.commit_page(sha, branch)).to eq(commit_page) } + it { expect(drone.merge_request_page(iid, sha, branch)).to eq(merge_request_page) } + it { expect(drone.commit_status_path(sha, branch)).to eq(commit_status_path) } + it { expect(drone.merge_request_status_path(iid, sha, branch)).to eq(merge_request_status_path) } + end + + describe "execute" do + include_context :drone_ci_service + + let(:user) { create(:user, username: 'username') } + let(:push_sample_data) { Gitlab::PushDataBuilder.build_sample(project, user) } + + it do + service_hook = double + expect(service_hook).to receive(:execute) + expect(drone).to receive(:service_hook).and_return(service_hook) + + drone.execute(push_sample_data) + end + end +end |