diff options
author | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2015-08-11 11:28:42 +0300 |
---|---|---|
committer | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2015-08-11 11:28:42 +0300 |
commit | 9f10943c1a76576ac40d96189a28a4d6123a75d8 (patch) | |
tree | 88955d92ebc98a4165d66a36cb8a2cf92709981a /spec | |
parent | 84727fba96c6794874e1f94d581408b70e1842a7 (diff) |
Revert "Merge branch 'drop-satellites'"
This reverts commit 957e849f41d96fa9778fcdd06792d2f0274b29ab, reversing
changes made to 6b9dbe9f5a175a8162abf296367f561bab3eea1a.
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
Diffstat (limited to 'spec')
-rw-r--r-- | spec/lib/gitlab/reference_extractor_spec.rb | 8 | ||||
-rw-r--r-- | spec/lib/gitlab/satellite/action_spec.rb | 116 | ||||
-rw-r--r-- | spec/lib/gitlab/satellite/merge_action_spec.rb | 104 | ||||
-rw-r--r-- | spec/models/merge_request_spec.rb | 2 | ||||
-rw-r--r-- | spec/models/project_services/slack_service_spec.rb | 2 | ||||
-rw-r--r-- | spec/models/project_spec.rb | 1 | ||||
-rw-r--r-- | spec/models/repository_spec.rb | 4 | ||||
-rw-r--r-- | spec/requests/api/files_spec.rb | 2 | ||||
-rw-r--r-- | spec/requests/api/merge_requests_spec.rb | 26 | ||||
-rw-r--r-- | spec/routing/project_routing_spec.rb | 14 | ||||
-rw-r--r-- | spec/services/merge_requests/create_service_spec.rb | 2 | ||||
-rw-r--r-- | spec/services/merge_requests/merge_service_spec.rb | 5 | ||||
-rw-r--r-- | spec/support/mentionable_shared_examples.rb | 2 |
13 files changed, 258 insertions, 30 deletions
diff --git a/spec/lib/gitlab/reference_extractor_spec.rb b/spec/lib/gitlab/reference_extractor_spec.rb index 088e34f050c..f921dd9cc09 100644 --- a/spec/lib/gitlab/reference_extractor_spec.rb +++ b/spec/lib/gitlab/reference_extractor_spec.rb @@ -25,7 +25,7 @@ describe Gitlab::ReferenceExtractor do project.team << [@u_bar, :guest] subject.analyze(%Q{ - Inline code: `@foo` + Inline code: `@foo` Code block: @@ -33,7 +33,7 @@ describe Gitlab::ReferenceExtractor do @bar ``` - Quote: + Quote: > @offteam }) @@ -49,8 +49,8 @@ describe Gitlab::ReferenceExtractor do end it 'accesses valid merge requests' do - @m0 = create(:merge_request, source_project: project, target_project: project, source_branch: 'markdown') - @m1 = create(:merge_request, source_project: project, target_project: project, source_branch: 'feature_conflict') + @m0 = create(:merge_request, source_project: project, target_project: project, source_branch: 'aaa') + @m1 = create(:merge_request, source_project: project, target_project: project, source_branch: 'bbb') subject.analyze("!999, !#{@m1.iid}, and !#{@m0.iid}.") expect(subject.merge_requests).to eq([@m1, @m0]) diff --git a/spec/lib/gitlab/satellite/action_spec.rb b/spec/lib/gitlab/satellite/action_spec.rb new file mode 100644 index 00000000000..0a93676edc3 --- /dev/null +++ b/spec/lib/gitlab/satellite/action_spec.rb @@ -0,0 +1,116 @@ +require 'spec_helper' + +describe 'Gitlab::Satellite::Action' do + let(:project) { create(:project) } + let(:user) { create(:user) } + + describe '#prepare_satellite!' do + it 'should be able to fetch timeout from conf' do + expect(Gitlab::Satellite::Action::DEFAULT_OPTIONS[:git_timeout]).to eq(30.seconds) + end + + it 'create a repository with a parking branch and one remote: origin' do + repo = project.satellite.repo + + #now lets dirty it up + + starting_remote_count = repo.git.list_remotes.size + expect(starting_remote_count).to be >= 1 + #kind of hookey way to add a second remote + origin_uri = repo.git.remote({ v: true }).split(" ")[1] + + repo.git.remote({ raise: true }, 'add', 'another-remote', origin_uri) + repo.git.branch({ raise: true }, 'a-new-branch') + + expect(repo.heads.size).to be > (starting_remote_count) + expect(repo.git.remote().split(" ").size).to be > (starting_remote_count) + + repo.git.config({}, "user.name", "#{user.name} -- foo") + repo.git.config({}, "user.email", "#{user.email} -- foo") + expect(repo.config['user.name']).to eq("#{user.name} -- foo") + expect(repo.config['user.email']).to eq("#{user.email} -- foo") + + + #These must happen in the context of the satellite directory... + satellite_action = Gitlab::Satellite::Action.new(user, project) + project.satellite.lock do + #Now clean it up, use send to get around prepare_satellite! being protected + satellite_action.send(:prepare_satellite!, repo) + end + + #verify it's clean + heads = repo.heads.map(&:name) + expect(heads.size).to eq(1) + expect(heads.include?(Gitlab::Satellite::Satellite::PARKING_BRANCH)).to eq(true) + remotes = repo.git.remote().split(' ') + expect(remotes.size).to eq(1) + expect(remotes.include?('origin')).to eq(true) + expect(repo.config['user.name']).to eq(user.name) + expect(repo.config['user.email']).to eq(user.email) + end + end + + describe '#in_locked_and_timed_satellite' do + + it 'should make use of a lockfile' do + repo = project.satellite.repo + called = false + + #set assumptions + FileUtils.rm_f(project.satellite.lock_file) + + expect(File.exists?(project.satellite.lock_file)).to be_falsey + + satellite_action = Gitlab::Satellite::Action.new(user, project) + satellite_action.send(:in_locked_and_timed_satellite) do |sat_repo| + expect(repo).to eq(sat_repo) + expect(File.exists? project.satellite.lock_file).to be_truthy + called = true + end + + expect(called).to be_truthy + + end + + it 'should be able to use the satellite after locking' do + repo = project.satellite.repo + called = false + + # Set base assumptions + if File.exists? project.satellite.lock_file + expect(FileLockStatusChecker.new(project.satellite.lock_file).flocked?).to be_falsey + end + + satellite_action = Gitlab::Satellite::Action.new(user, project) + satellite_action.send(:in_locked_and_timed_satellite) do |sat_repo| + called = true + expect(repo).to eq(sat_repo) + expect(File.exists? project.satellite.lock_file).to be_truthy + expect(FileLockStatusChecker.new(project.satellite.lock_file).flocked?).to be_truthy + end + + expect(called).to be_truthy + expect(FileLockStatusChecker.new(project.satellite.lock_file).flocked?).to be_falsey + + end + + class FileLockStatusChecker < File + def flocked?(&block) + status = flock LOCK_EX|LOCK_NB + case status + when false + return true + when 0 + begin + block ? block.call : false + ensure + flock LOCK_UN + end + else + raise SystemCallError, status + end + end + end + + end +end diff --git a/spec/lib/gitlab/satellite/merge_action_spec.rb b/spec/lib/gitlab/satellite/merge_action_spec.rb new file mode 100644 index 00000000000..9b1c9a34e29 --- /dev/null +++ b/spec/lib/gitlab/satellite/merge_action_spec.rb @@ -0,0 +1,104 @@ +require 'spec_helper' + +describe 'Gitlab::Satellite::MergeAction' do + include RepoHelpers + + let(:project) { create(:project, namespace: create(:group)) } + let(:fork_project) { create(:project, namespace: create(:group), forked_from_project: project) } + let(:merge_request) { create(:merge_request, source_project: project, target_project: project) } + let(:merge_request_fork) { create(:merge_request, source_project: fork_project, target_project: project) } + + let(:merge_request_with_conflict) { create(:merge_request, :conflict, source_project: project, target_project: project) } + let(:merge_request_fork_with_conflict) { create(:merge_request, :conflict, source_project: project, target_project: project) } + + describe '#commits_between' do + def verify_commits(commits, first_commit_sha, last_commit_sha) + commits.each { |commit| expect(commit.class).to eq(Gitlab::Git::Commit) } + expect(commits.first.id).to eq(first_commit_sha) + expect(commits.last.id).to eq(last_commit_sha) + end + + context 'on fork' do + it 'should get proper commits between' do + commits = Gitlab::Satellite::MergeAction.new(merge_request_fork.author, merge_request_fork).commits_between + verify_commits(commits, sample_compare.commits.first, sample_compare.commits.last) + end + end + + context 'between branches' do + it 'should raise exception -- not expected to be used by non forks' do + expect { Gitlab::Satellite::MergeAction.new(merge_request.author, merge_request).commits_between }.to raise_error(RuntimeError) + end + end + end + + describe '#format_patch' do + def verify_content(patch) + sample_compare.commits.each do |commit| + expect(patch.include?(commit)).to be_truthy + end + end + + context 'on fork' do + it 'should build a format patch' do + patch = Gitlab::Satellite::MergeAction.new(merge_request_fork.author, merge_request_fork).format_patch + verify_content(patch) + end + end + + context 'between branches' do + it 'should build a format patch' do + patch = Gitlab::Satellite::MergeAction.new(merge_request_fork.author, merge_request).format_patch + verify_content(patch) + end + end + end + + describe '#diffs_between_satellite tested against diff_in_satellite' do + def is_a_matching_diff(diff, diffs) + diff_count = diff.scan('diff --git').size + expect(diff_count).to be >= 1 + expect(diffs.size).to eq(diff_count) + diffs.each do |a_diff| + expect(a_diff.class).to eq(Gitlab::Git::Diff) + expect(diff.include? a_diff.diff).to be_truthy + end + end + + context 'on fork' do + it 'should get proper diffs' do + diffs = Gitlab::Satellite::MergeAction.new(merge_request_fork.author, merge_request_fork).diffs_between_satellite + diff = Gitlab::Satellite::MergeAction.new(merge_request.author, merge_request_fork).diff_in_satellite + is_a_matching_diff(diff, diffs) + end + end + + context 'between branches' do + it 'should get proper diffs' do + expect{ Gitlab::Satellite::MergeAction.new(merge_request.author, merge_request).diffs_between_satellite }.to raise_error(RuntimeError) + end + end + end + + describe '#can_be_merged?' do + context 'on fork' do + it do + expect(Gitlab::Satellite::MergeAction.new(merge_request_fork.author, merge_request_fork).can_be_merged?).to be_truthy + end + + it do + expect(Gitlab::Satellite::MergeAction.new(merge_request_fork_with_conflict.author, merge_request_fork_with_conflict).can_be_merged?).to be_falsey + end + end + + context 'between branches' do + it do + expect(Gitlab::Satellite::MergeAction.new(merge_request.author, merge_request).can_be_merged?).to be_truthy + end + + it do + expect(Gitlab::Satellite::MergeAction.new(merge_request_with_conflict.author, merge_request_with_conflict).can_be_merged?).to be_falsey + end + end + end +end diff --git a/spec/models/merge_request_spec.rb b/spec/models/merge_request_spec.rb index b91687bc09f..76f6d8c54c4 100644 --- a/spec/models/merge_request_spec.rb +++ b/spec/models/merge_request_spec.rb @@ -165,7 +165,7 @@ describe MergeRequest do end it_behaves_like 'an editable mentionable' do - subject { create(:merge_request) } + subject { create(:merge_request, source_project: project) } let(:backref_text) { "merge request #{subject.to_reference}" } let(:set_mentionable_text) { ->(txt){ subject.description = txt } } diff --git a/spec/models/project_services/slack_service_spec.rb b/spec/models/project_services/slack_service_spec.rb index 97b60e19e40..69466b11f09 100644 --- a/spec/models/project_services/slack_service_spec.rb +++ b/spec/models/project_services/slack_service_spec.rb @@ -67,7 +67,7 @@ describe SlackService do opts = { title: 'Awesome merge_request', description: 'please fix', - source_branch: 'feature', + source_branch: 'stable', target_branch: 'master' } merge_service = MergeRequests::CreateService.new(project, diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb index 2fcbd5ae108..5d40754d59d 100644 --- a/spec/models/project_spec.rb +++ b/spec/models/project_spec.rb @@ -91,6 +91,7 @@ describe Project do describe 'Respond to' do it { is_expected.to respond_to(:url_to_repo) } it { is_expected.to respond_to(:repo_exists?) } + it { is_expected.to respond_to(:satellite) } it { is_expected.to respond_to(:update_merge_requests) } it { is_expected.to respond_to(:execute_hooks) } it { is_expected.to respond_to(:name_with_namespace) } diff --git a/spec/models/repository_spec.rb b/spec/models/repository_spec.rb index d96244f23e0..d25351b0f0e 100644 --- a/spec/models/repository_spec.rb +++ b/spec/models/repository_spec.rb @@ -36,13 +36,13 @@ describe Repository do describe :can_be_merged? do context 'mergeable branches' do - subject { repository.can_be_merged?('0b4bc9a49b562e85de7cc9e834518ea6828729b9', 'master') } + subject { repository.can_be_merged?('feature', 'master') } it { is_expected.to be_truthy } end context 'non-mergeable branches' do - subject { repository.can_be_merged?('bb5206fee213d983da88c47f9cf4cc6caf9c66dc', 'feature') } + subject { repository.can_be_merged?('feature_conflict', 'feature') } it { is_expected.to be_falsey } end diff --git a/spec/requests/api/files_spec.rb b/spec/requests/api/files_spec.rb index 8cb8790c339..6c7860511e8 100644 --- a/spec/requests/api/files_spec.rb +++ b/spec/requests/api/files_spec.rb @@ -110,7 +110,7 @@ describe API::API, api: true do expect(response.status).to eq(400) end - it "should return a 400 if fails to create file" do + it "should return a 400 if satellite fails to create file" do allow_any_instance_of(Repository).to receive(:remove_file).and_return(false) delete api("/projects/#{project.id}/repository/files", user), valid_params diff --git a/spec/requests/api/merge_requests_spec.rb b/spec/requests/api/merge_requests_spec.rb index 942768fa254..29db035b2de 100644 --- a/spec/requests/api/merge_requests_spec.rb +++ b/spec/requests/api/merge_requests_spec.rb @@ -148,7 +148,7 @@ describe API::API, api: true do it "should return merge_request" do post api("/projects/#{project.id}/merge_requests", user), title: 'Test merge_request', - source_branch: 'feature_conflict', + source_branch: 'stable', target_branch: 'master', author: user, labels: 'label, label2' @@ -171,20 +171,20 @@ describe API::API, api: true do it "should return 400 when target_branch is missing" do post api("/projects/#{project.id}/merge_requests", user), - title: "Test merge_request", source_branch: "markdown", author: user + title: "Test merge_request", source_branch: "stable", author: user expect(response.status).to eq(400) end it "should return 400 when title is missing" do post api("/projects/#{project.id}/merge_requests", user), - target_branch: 'master', source_branch: 'markdown' + target_branch: 'master', source_branch: 'stable' expect(response.status).to eq(400) end it 'should return 400 on invalid label names' do post api("/projects/#{project.id}/merge_requests", user), title: 'Test merge_request', - source_branch: 'markdown', + source_branch: 'stable', target_branch: 'master', author: user, labels: 'label, ?' @@ -198,7 +198,7 @@ describe API::API, api: true do before do post api("/projects/#{project.id}/merge_requests", user), title: 'Test merge_request', - source_branch: 'feature_conflict', + source_branch: 'stable', target_branch: 'master', author: user @mr = MergeRequest.all.last @@ -208,7 +208,7 @@ describe API::API, api: true do expect do post api("/projects/#{project.id}/merge_requests", user), title: 'New test merge_request', - source_branch: 'feature_conflict', + source_branch: 'stable', target_branch: 'master', author: user end.to change { MergeRequest.count }.by(0) @@ -228,8 +228,7 @@ describe API::API, api: true do it "should return merge_request" do post api("/projects/#{fork_project.id}/merge_requests", user2), - title: 'Test merge_request', source_branch: "feature_conflict", target_branch: "master", - author: user2, target_project_id: project.id, description: 'Test description for Test merge_request' + title: 'Test merge_request', source_branch: "stable", target_branch: "master", author: user2, target_project_id: project.id, description: 'Test description for Test merge_request' expect(response.status).to eq(201) expect(json_response['title']).to eq('Test merge_request') expect(json_response['description']).to eq('Test description for Test merge_request') @@ -259,7 +258,7 @@ describe API::API, api: true do it "should return 400 when title is missing" do post api("/projects/#{fork_project.id}/merge_requests", user2), - target_branch: 'master', source_branch: 'markdown', author: user2, target_project_id: project.id + target_branch: 'master', source_branch: 'stable', author: user2, target_project_id: project.id expect(response.status).to eq(400) end @@ -268,7 +267,7 @@ describe API::API, api: true do post api("/projects/#{project.id}/merge_requests", user), title: 'Test merge_request', target_branch: 'master', - source_branch: 'markdown', + source_branch: 'stable', author: user, target_project_id: fork_project.id expect(response.status).to eq(422) @@ -278,7 +277,7 @@ describe API::API, api: true do post api("/projects/#{fork_project.id}/merge_requests", user2), title: 'Test merge_request', target_branch: 'master', - source_branch: 'markdown', + source_branch: 'stable', author: user2, target_project_id: unrelated_project.id expect(response.status).to eq(422) @@ -287,7 +286,7 @@ describe API::API, api: true do it "should return 201 when target_branch is specified and for the same project" do post api("/projects/#{fork_project.id}/merge_requests", user2), - title: 'Test merge_request', target_branch: 'master', source_branch: 'markdown', author: user2, target_project_id: fork_project.id + title: 'Test merge_request', target_branch: 'master', source_branch: 'stable', author: user2, target_project_id: fork_project.id expect(response.status).to eq(201) end end @@ -303,6 +302,9 @@ describe API::API, api: true do describe "PUT /projects/:id/merge_request/:merge_request_id/merge" do it "should return merge_request in case of success" do + allow_any_instance_of(MergeRequest). + to receive_messages(can_be_merged?: true, automerge!: true) + put api("/projects/#{project.id}/merge_request/#{merge_request.id}/merge", user) expect(response.status).to eq(200) diff --git a/spec/routing/project_routing_spec.rb b/spec/routing/project_routing_spec.rb index 82f62a8709c..0040718d9be 100644 --- a/spec/routing/project_routing_spec.rb +++ b/spec/routing/project_routing_spec.rb @@ -210,8 +210,8 @@ end # diffs_namespace_project_merge_request GET /:namespace_id/:project_id/merge_requests/:id/diffs(.:format) projects/merge_requests#diffs # commits_namespace_project_merge_request GET /:namespace_id/:project_id/merge_requests/:id/commits(.:format) projects/merge_requests#commits -# merge_namespace_project_merge_request POST /:namespace_id/:project_id/merge_requests/:id/merge(.:format) projects/merge_requests#merge -# merge_check_namespace_project_merge_request GET /:namespace_id/:project_id/merge_requests/:id/merge_check(.:format) projects/merge_requests#merge_check +# automerge_namespace_project_merge_request POST /:namespace_id/:project_id/merge_requests/:id/automerge(.:format) projects/merge_requests#automerge +# automerge_check_namespace_project_merge_request GET /:namespace_id/:project_id/merge_requests/:id/automerge_check(.:format) projects/merge_requests#automerge_check # ci_status_namespace_project_merge_request GET /:namespace_id/:project_id/merge_requests/:id/ci_status(.:format) projects/merge_requests#ci_status # toggle_subscription_namespace_project_merge_request POST /:namespace_id/:project_id/merge_requests/:id/toggle_subscription(.:format) projects/merge_requests#toggle_subscription # branch_from_namespace_project_merge_requests GET /:namespace_id/:project_id/merge_requests/branch_from(.:format) projects/merge_requests#branch_from @@ -233,15 +233,15 @@ describe Projects::MergeRequestsController, 'routing' do expect(get('/gitlab/gitlabhq/merge_requests/1/commits')).to route_to('projects/merge_requests#commits', namespace_id: 'gitlab', project_id: 'gitlabhq', id: '1') end - it 'to #merge' do - expect(post('/gitlab/gitlabhq/merge_requests/1/merge')).to route_to( - 'projects/merge_requests#merge', + it 'to #automerge' do + expect(post('/gitlab/gitlabhq/merge_requests/1/automerge')).to route_to( + 'projects/merge_requests#automerge', namespace_id: 'gitlab', project_id: 'gitlabhq', id: '1' ) end - it 'to #merge_check' do - expect(get('/gitlab/gitlabhq/merge_requests/1/merge_check')).to route_to('projects/merge_requests#merge_check', namespace_id: 'gitlab', project_id: 'gitlabhq', id: '1') + it 'to #automerge_check' do + expect(get('/gitlab/gitlabhq/merge_requests/1/automerge_check')).to route_to('projects/merge_requests#automerge_check', namespace_id: 'gitlab', project_id: 'gitlabhq', id: '1') end it 'to #branch_from' do diff --git a/spec/services/merge_requests/create_service_spec.rb b/spec/services/merge_requests/create_service_spec.rb index cc64d69361e..d9bfdf64308 100644 --- a/spec/services/merge_requests/create_service_spec.rb +++ b/spec/services/merge_requests/create_service_spec.rb @@ -10,7 +10,7 @@ describe MergeRequests::CreateService do { title: 'Awesome merge_request', description: 'please fix', - source_branch: 'feature', + source_branch: 'stable', target_branch: 'master' } end diff --git a/spec/services/merge_requests/merge_service_spec.rb b/spec/services/merge_requests/merge_service_spec.rb index 7b564d34d7b..0a25fb12f4e 100644 --- a/spec/services/merge_requests/merge_service_spec.rb +++ b/spec/services/merge_requests/merge_service_spec.rb @@ -24,6 +24,11 @@ describe MergeRequests::MergeService do it { expect(merge_request).to be_valid } it { expect(merge_request).to be_merged } + it 'should execute hooks with merge action' do + expect(service).to have_received(:execute_hooks). + with(merge_request, 'merge') + end + it 'should send email to user2 about merge of new merge_request' do email = ActionMailer::Base.deliveries.last expect(email.to.first).to eq(user2.email) diff --git a/spec/support/mentionable_shared_examples.rb b/spec/support/mentionable_shared_examples.rb index e3de0afb448..f0717e61781 100644 --- a/spec/support/mentionable_shared_examples.rb +++ b/spec/support/mentionable_shared_examples.rb @@ -9,7 +9,7 @@ def common_mentionable_setup let(:author) { subject.author } let(:mentioned_issue) { create(:issue, project: project) } - let!(:mentioned_mr) { create(:merge_request, :simple, source_project: project) } + let(:mentioned_mr) { create(:merge_request, :simple, source_project: project) } let(:mentioned_commit) { project.commit } let(:ext_proj) { create(:project, :public) } |