diff options
| author | Douwe Maan <douwe@gitlab.com> | 2016-08-11 18:23:29 +0000 |
|---|---|---|
| committer | Douwe Maan <douwe@gitlab.com> | 2016-08-11 18:23:29 +0000 |
| commit | a40268352c811762d9e70e869d5157c01107c1a5 (patch) | |
| tree | c9016c4fc6c26a748799f3fe05faedc44e7bfdd7 /spec | |
| parent | 1e3d15a71ed49a932c6539d1e783b5948f31192e (diff) | |
| parent | 9ba4a0aa4fc104189873134644a2d5da28f5b4b7 (diff) | |
| download | gitlab-shell-a40268352c811762d9e70e869d5157c01107c1a5.tar.gz | |
Merge branch 'feature/new-merge-request-url' into 'master'
Show Merge request link after pushing if new brach
This is part of implementation for issue https://gitlab.com/gitlab-org/gitlab-ce/issues/18266
See merge request !77
Diffstat (limited to 'spec')
| -rw-r--r-- | spec/gitlab_post_receive_spec.rb | 124 |
1 files changed, 102 insertions, 22 deletions
diff --git a/spec/gitlab_post_receive_spec.rb b/spec/gitlab_post_receive_spec.rb index 6762d49..db1e776 100644 --- a/spec/gitlab_post_receive_spec.rb +++ b/spec/gitlab_post_receive_spec.rb @@ -17,12 +17,12 @@ describe GitlabPostReceive do before do GitlabConfig.any_instance.stub(repos_path: repository_path) - GitlabNet.any_instance.stub(broadcast_message: { "message" => message }) + GitlabNet.any_instance.stub(broadcast_message: { }) + GitlabNet.any_instance.stub(:merge_request_urls).with(repo_name, wrongly_encoded_changes) { [] } expect(Time).to receive(:now).and_return(enqueued_at) end describe "#exec" do - before do allow_any_instance_of(GitlabNet).to receive(:redis_client).and_return(redis_client) allow_any_instance_of(GitlabReferenceCounter).to receive(:redis_client).and_return(redis_client) @@ -32,27 +32,107 @@ describe GitlabPostReceive do allow(redis_client).to receive(:rpush).and_return(true) end - it "prints the broadcast message" do - expect(redis_client).to receive(:rpush) - expect(gitlab_post_receive).to receive(:puts).ordered - expect(gitlab_post_receive).to receive(:puts).with( - "========================================================================" - ).ordered - expect(gitlab_post_receive).to receive(:puts).ordered - - expect(gitlab_post_receive).to receive(:puts).with( - " test test test test test test test test test test message message" - ).ordered - expect(gitlab_post_receive).to receive(:puts).with( - " message message message message message message message message" - ).ordered - - expect(gitlab_post_receive).to receive(:puts).ordered - expect(gitlab_post_receive).to receive(:puts).with( - "========================================================================" - ).ordered + context 'Without broad cast message' do + context 'pushing new branch' do + before do + GitlabNet.any_instance.stub(:merge_request_urls).with(repo_name, wrongly_encoded_changes) do + [{ + "branch_name" => "new_branch", + "url" => "http://localhost/dzaporozhets/gitlab-ci/merge_requests/new?merge_request%5Bsource_branch%5D=new_branch", + "new_merge_request" => true + }] + end + end - gitlab_post_receive.exec + it "prints the new merge request url" do + expect(redis_client).to receive(:rpush) + + expect(gitlab_post_receive).to receive(:puts).ordered + expect(gitlab_post_receive).to receive(:puts).with( + "Create merge request for new_branch:" + ).ordered + expect(gitlab_post_receive).to receive(:puts).with( + " http://localhost/dzaporozhets/gitlab-ci/merge_requests/new?merge_request%5Bsource_branch%5D=new_branch" + ).ordered + expect(gitlab_post_receive).to receive(:puts).ordered + + gitlab_post_receive.exec + end + end + + context 'pushing existing branch with merge request created' do + before do + GitlabNet.any_instance.stub(:merge_request_urls).with(repo_name, wrongly_encoded_changes) do + [{ + "branch_name" => "feature_branch", + "url" => "http://localhost/dzaporozhets/gitlab-ci/merge_requests/1", + "new_merge_request" => false + }] + end + end + + it "prints the view merge request url" do + expect(redis_client).to receive(:rpush) + + expect(gitlab_post_receive).to receive(:puts).ordered + expect(gitlab_post_receive).to receive(:puts).with( + "View merge request for feature_branch:" + ).ordered + expect(gitlab_post_receive).to receive(:puts).with( + " http://localhost/dzaporozhets/gitlab-ci/merge_requests/1" + ).ordered + expect(gitlab_post_receive).to receive(:puts).ordered + + gitlab_post_receive.exec + end + end + end + + context 'show broadcast message and merge request link' do + before do + GitlabNet.any_instance.stub(:merge_request_urls).with(repo_name, wrongly_encoded_changes) do + [{ + "branch_name" => "new_branch", + "url" => "http://localhost/dzaporozhets/gitlab-ci/merge_requests/new?merge_request%5Bsource_branch%5D=new_branch", + "new_merge_request" => true + }] + end + GitlabNet.any_instance.stub(broadcast_message: { "message" => message }) + end + + it 'prints the broadcast message and create new merge request link' do + expect(redis_client).to receive(:rpush) + + expect(gitlab_post_receive).to receive(:puts).ordered + expect(gitlab_post_receive).to receive(:puts).with( + "========================================================================" + ).ordered + expect(gitlab_post_receive).to receive(:puts).ordered + + expect(gitlab_post_receive).to receive(:puts).with( + " test test test test test test test test test test message message" + ).ordered + expect(gitlab_post_receive).to receive(:puts).with( + " message message message message message message message message" + ).ordered + + expect(gitlab_post_receive).to receive(:puts).ordered + expect(gitlab_post_receive).to receive(:puts).with( + "========================================================================" + ).ordered + + expect(gitlab_post_receive).to receive(:puts).ordered + expect(gitlab_post_receive).to receive(:puts).with( + "Create merge request for new_branch:" + ).ordered + expect(gitlab_post_receive).to receive(:puts).with( + " http://localhost/dzaporozhets/gitlab-ci/merge_requests/new?merge_request%5Bsource_branch%5D=new_branch" + ).ordered + expect(gitlab_post_receive).to receive(:puts).ordered + + + gitlab_post_receive.exec + end end it "pushes a Sidekiq job onto the queue" do |
