summaryrefslogtreecommitdiff
path: root/spec/services/git
diff options
context:
space:
mode:
Diffstat (limited to 'spec/services/git')
-rw-r--r--spec/services/git/branch_hooks_service_spec.rb28
-rw-r--r--spec/services/git/branch_push_service_spec.rb28
-rw-r--r--spec/services/git/process_ref_changes_service_spec.rb6
3 files changed, 44 insertions, 18 deletions
diff --git a/spec/services/git/branch_hooks_service_spec.rb b/spec/services/git/branch_hooks_service_spec.rb
index 19694a0a354..a93f594b360 100644
--- a/spec/services/git/branch_hooks_service_spec.rb
+++ b/spec/services/git/branch_hooks_service_spec.rb
@@ -92,7 +92,7 @@ RSpec.describe Git::BranchHooksService, :clean_gitlab_redis_shared_state do
end
describe 'Push Event' do
- let(:event) { Event.pushed_action.first }
+ let(:event) { Event.pushed_action.take }
subject(:execute_service) { service.execute }
@@ -134,7 +134,7 @@ RSpec.describe Git::BranchHooksService, :clean_gitlab_redis_shared_state do
context 'when usage ping is disabled' do
before do
- stub_application_setting(usage_ping_enabled: false)
+ allow(::ServicePing::ServicePingSettings).to receive(:enabled?).and_return(false)
end
it 'does not track the event' do
@@ -171,7 +171,7 @@ RSpec.describe Git::BranchHooksService, :clean_gitlab_redis_shared_state do
end
end
- context "with a new branch" do
+ context "with a new default branch" do
let(:oldrev) { Gitlab::Git::BLANK_SHA }
it 'generates a push event with more than one commit' do
@@ -183,12 +183,32 @@ RSpec.describe Git::BranchHooksService, :clean_gitlab_redis_shared_state do
expect(event.push_event_payload).to be_an_instance_of(PushEventPayload)
expect(event.push_event_payload.commit_from).to be_nil
expect(event.push_event_payload.commit_to).to eq(newrev)
- expect(event.push_event_payload.commit_title).to eq('Initial commit')
+ expect(event.push_event_payload.commit_title).to eq('Change some files')
expect(event.push_event_payload.ref).to eq('master')
expect(event.push_event_payload.commit_count).to be > 1
end
end
+ context "with a new non-default branch" do
+ let(:oldrev) { Gitlab::Git::BLANK_SHA }
+ let(:branch) { 'fix' }
+ let(:commit_id) { project.commit(branch).id }
+
+ it 'generates a push event with more than one commit' do
+ execute_service
+
+ expect(event).to be_an_instance_of(PushEvent)
+ expect(event.project).to eq(project)
+ expect(event).to be_pushed_action
+ expect(event.push_event_payload).to be_an_instance_of(PushEventPayload)
+ expect(event.push_event_payload.commit_from).to be_nil
+ expect(event.push_event_payload.commit_to).to eq(newrev)
+ expect(event.push_event_payload.commit_title).to eq('Test file for directories with a leading dot')
+ expect(event.push_event_payload.ref).to eq('fix')
+ expect(event.push_event_payload.commit_count).to be > 1
+ end
+ end
+
context 'removing a branch' do
let(:newrev) { Gitlab::Git::BLANK_SHA }
diff --git a/spec/services/git/branch_push_service_spec.rb b/spec/services/git/branch_push_service_spec.rb
index fc629fe583d..d70e458ba5e 100644
--- a/spec/services/git/branch_push_service_spec.rb
+++ b/spec/services/git/branch_push_service_spec.rb
@@ -151,9 +151,9 @@ RSpec.describe Git::BranchPushService, services: true do
it "when pushing a new branch for the first time" do
expect(UpdateMergeRequestsWorker)
.to receive(:perform_async)
- .with(project.id, user.id, blankrev, 'newrev', ref)
+ .with(project.id, user.id, blankrev, newrev, ref)
- execute_service(project, user, oldrev: blankrev, newrev: 'newrev', ref: ref)
+ execute_service(project, user, oldrev: blankrev, newrev: newrev, ref: ref)
end
end
@@ -162,13 +162,13 @@ RSpec.describe Git::BranchPushService, services: true do
it "calls the copy attributes method for the first push to the default branch" do
expect(project.repository).to receive(:copy_gitattributes).with('master')
- execute_service(project, user, oldrev: blankrev, newrev: 'newrev', ref: ref)
+ execute_service(project, user, oldrev: blankrev, newrev: newrev, ref: ref)
end
it "calls the copy attributes method for changes to the default branch" do
expect(project.repository).to receive(:copy_gitattributes).with(ref)
- execute_service(project, user, oldrev: 'oldrev', newrev: 'newrev', ref: ref)
+ execute_service(project, user, oldrev: oldrev, newrev: newrev, ref: ref)
end
end
@@ -195,7 +195,7 @@ RSpec.describe Git::BranchPushService, services: true do
it "when pushing a branch for the first time" do
expect(project).to receive(:execute_hooks)
expect(project.default_branch).to eq("master")
- execute_service(project, user, oldrev: blankrev, newrev: 'newrev', ref: ref)
+ execute_service(project, user, oldrev: blankrev, newrev: newrev, ref: ref)
expect(project.protected_branches).not_to be_empty
expect(project.protected_branches.first.push_access_levels.map(&:access_level)).to eq([Gitlab::Access::MAINTAINER])
expect(project.protected_branches.first.merge_access_levels.map(&:access_level)).to eq([Gitlab::Access::MAINTAINER])
@@ -206,7 +206,7 @@ RSpec.describe Git::BranchPushService, services: true do
expect(project).to receive(:execute_hooks)
expect(project.default_branch).to eq("master")
- execute_service(project, user, oldrev: blankrev, newrev: 'newrev', ref: ref)
+ execute_service(project, user, oldrev: blankrev, newrev: newrev, ref: ref)
expect(project.protected_branches).to be_empty
end
@@ -216,7 +216,7 @@ RSpec.describe Git::BranchPushService, services: true do
expect(project).to receive(:execute_hooks)
expect(project.default_branch).to eq("master")
- execute_service(project, user, oldrev: blankrev, newrev: 'newrev', ref: ref)
+ execute_service(project, user, oldrev: blankrev, newrev: newrev, ref: ref)
expect(project.protected_branches).not_to be_empty
expect(project.protected_branches.last.push_access_levels.map(&:access_level)).to eq([Gitlab::Access::DEVELOPER])
@@ -231,7 +231,7 @@ RSpec.describe Git::BranchPushService, services: true do
expect(project.default_branch).to eq("master")
expect(ProtectedBranches::CreateService).not_to receive(:new)
- execute_service(project, user, oldrev: blankrev, newrev: 'newrev', ref: ref)
+ execute_service(project, user, oldrev: blankrev, newrev: newrev, ref: ref)
expect(project.protected_branches).not_to be_empty
expect(project.protected_branches.last.push_access_levels.map(&:access_level)).to eq([Gitlab::Access::NO_ACCESS])
@@ -243,7 +243,7 @@ RSpec.describe Git::BranchPushService, services: true do
expect(project).to receive(:execute_hooks)
expect(project.default_branch).to eq("master")
- execute_service(project, user, oldrev: blankrev, newrev: 'newrev', ref: ref)
+ execute_service(project, user, oldrev: blankrev, newrev: newrev, ref: ref)
expect(project.protected_branches).not_to be_empty
expect(project.protected_branches.first.push_access_levels.map(&:access_level)).to eq([Gitlab::Access::MAINTAINER])
expect(project.protected_branches.first.merge_access_levels.map(&:access_level)).to eq([Gitlab::Access::DEVELOPER])
@@ -251,7 +251,7 @@ RSpec.describe Git::BranchPushService, services: true do
it "when pushing new commits to existing branch" do
expect(project).to receive(:execute_hooks)
- execute_service(project, user, oldrev: 'oldrev', newrev: 'newrev', ref: ref)
+ execute_service(project, user, oldrev: oldrev, newrev: newrev, ref: ref)
end
end
end
@@ -597,7 +597,7 @@ RSpec.describe Git::BranchPushService, services: true do
let(:oldrev) { blankrev }
it 'does nothing' do
- expect(::Ci::StopEnvironmentsService).not_to receive(:new)
+ expect(::Environments::StopService).not_to receive(:new)
execute_service(project, user, oldrev: oldrev, newrev: newrev, ref: ref)
end
@@ -605,7 +605,7 @@ RSpec.describe Git::BranchPushService, services: true do
context 'update branch' do
it 'does nothing' do
- expect(::Ci::StopEnvironmentsService).not_to receive(:new)
+ expect(::Environments::StopService).not_to receive(:new)
execute_service(project, user, oldrev: oldrev, newrev: newrev, ref: ref)
end
@@ -615,10 +615,10 @@ RSpec.describe Git::BranchPushService, services: true do
let(:newrev) { blankrev }
it 'stops environments' do
- expect_next_instance_of(::Ci::StopEnvironmentsService) do |stop_service|
+ expect_next_instance_of(::Environments::StopService) do |stop_service|
expect(stop_service.project).to eq(project)
expect(stop_service.current_user).to eq(user)
- expect(stop_service).to receive(:execute).with(branch)
+ expect(stop_service).to receive(:execute_for_branch).with(branch)
end
execute_service(project, user, oldrev: oldrev, newrev: newrev, ref: ref)
diff --git a/spec/services/git/process_ref_changes_service_spec.rb b/spec/services/git/process_ref_changes_service_spec.rb
index ac9bac4e6ad..2a223091d0c 100644
--- a/spec/services/git/process_ref_changes_service_spec.rb
+++ b/spec/services/git/process_ref_changes_service_spec.rb
@@ -116,6 +116,8 @@ RSpec.describe Git::ProcessRefChangesService do
if changes_method == :tag_changes
allow_any_instance_of(Repository).to receive(:tag_exists?) { true }
end
+
+ allow(Gitlab::Git::Commit).to receive(:between) { [] }
end
context 'when git_push_create_all_pipelines is disabled' do
@@ -150,6 +152,8 @@ RSpec.describe Git::ProcessRefChangesService do
context 'with invalid .gitlab-ci.yml' do
before do
stub_ci_pipeline_yaml_file(nil)
+
+ allow(Gitlab::Git::Commit).to receive(:between) { [] }
end
it 'does not create a pipeline' do
@@ -190,6 +194,8 @@ RSpec.describe Git::ProcessRefChangesService do
allow(MergeRequests::PushedBranchesService).to receive(:new).and_return(
double(execute: %w(create1 create2)), double(execute: %w(changed1)), double(execute: %w(removed2))
)
+
+ allow(Gitlab::Git::Commit).to receive(:between).and_return([])
end
it 'schedules job for existing merge requests' do