Commit 8516e3ab authored by Micaël Bergeron's avatar Micaël Bergeron

add spec for forked project

parent 4714cb58
require 'spec_helper' require 'spec_helper'
describe Projects::MergeRequestsController do shared_examples 'approvals' do
let(:project) { create(:project, :repository) } def json_response
let(:merge_request) { create(:merge_request_with_diffs, target_project: project, source_project: project) } JSON.parse(response.body)
let(:user) { project.owner } end
let(:viewer) { user }
let(:approver) { create(:user) }
before do before do
sign_in(viewer) merge_request.update_attribute :approvals_before_merge, 2
project.team << [approver, :developer]
project.approver_ids = [user, approver].map(&:id).join(',')
end end
context 'approvals' do describe 'approve' do
def json_response before do
JSON.parse(response.body) post :approve,
namespace_id: project.namespace.to_param,
project_id: project.to_param,
id: merge_request.iid,
format: :json
end end
let(:approver) { create(:user) } it 'approves the merge request' do
expect(response).to be_success
before do expect(json_response['approvals_left']).to eq 1
merge_request.update_attribute :approvals_before_merge, 2 expect(json_response['approved_by'].size).to eq 1
project.team << [approver, :developer] expect(json_response['approved_by'][0]['user']['username']).to eq user.username
project.approver_ids = [user, approver].map(&:id).join(',') expect(json_response['user_has_approved']).to be true
expect(json_response['user_can_approve']).to be false
expect(json_response['suggested_approvers'].size).to eq 1
expect(json_response['suggested_approvers'][0]['username']).to eq approver.username
end end
end
describe 'approve' do describe 'approvals' do
before do before do
post :approve, merge_request.approvals.create(user: approver)
get :approvals,
namespace_id: project.namespace.to_param, namespace_id: project.namespace.to_param,
project_id: project.to_param, project_id: project.to_param,
id: merge_request.iid, id: merge_request.iid,
format: :json format: :json
end end
it 'approves the merge request' do it 'shows approval information' do
expect(response).to be_success expect(response).to be_success
expect(json_response['approvals_left']).to eq 1 expect(json_response['approvals_left']).to eq 1
expect(json_response['approved_by'].size).to eq 1 expect(json_response['approved_by'].size).to eq 1
expect(json_response['approved_by'][0]['user']['username']).to eq user.username expect(json_response['approved_by'][0]['user']['username']).to eq approver.username
expect(json_response['user_has_approved']).to be true expect(json_response['user_has_approved']).to be false
expect(json_response['user_can_approve']).to be false expect(json_response['user_can_approve']).to be true
expect(json_response['suggested_approvers'].size).to eq 1 expect(json_response['suggested_approvers'].size).to eq 1
expect(json_response['suggested_approvers'][0]['username']).to eq approver.username expect(json_response['suggested_approvers'][0]['username']).to eq user.username
end
end end
end
describe 'approvals' do describe 'unapprove' do
before do before do
merge_request.approvals.create(user: approver) merge_request.approvals.create(user: user)
get :approvals, delete :unapprove,
namespace_id: project.namespace.to_param, namespace_id: project.namespace.to_param,
project_id: project.to_param, project_id: project.to_param,
id: merge_request.iid, id: merge_request.iid,
format: :json format: :json
end end
it 'shows approval information' do it 'unapproves the merge request' do
expect(response).to be_success expect(response).to be_success
expect(json_response['approvals_left']).to eq 1 expect(json_response['approvals_left']).to eq 2
expect(json_response['approved_by'].size).to eq 1 expect(json_response['approved_by']).to be_empty
expect(json_response['approved_by'][0]['user']['username']).to eq approver.username expect(json_response['user_has_approved']).to be false
expect(json_response['user_has_approved']).to be false expect(json_response['user_can_approve']).to be true
expect(json_response['user_can_approve']).to be true expect(json_response['suggested_approvers'].size).to eq 2
expect(json_response['suggested_approvers'].size).to eq 1
expect(json_response['suggested_approvers'][0]['username']).to eq user.username
end
end end
end
end
describe 'unapprove' do describe Projects::MergeRequestsController do
before do let(:project) { create(:project, :repository) }
merge_request.approvals.create(user: user) let(:merge_request) { create(:merge_request_with_diffs, target_project: project, source_project: project) }
delete :unapprove, let(:user) { project.owner }
namespace_id: project.namespace.to_param, let(:viewer) { user }
project_id: project.to_param,
id: merge_request.iid,
format: :json
end
it 'unapproves the merge request' do before do
expect(response).to be_success sign_in(viewer)
expect(json_response['approvals_left']).to eq 2
expect(json_response['approved_by']).to be_empty
expect(json_response['user_has_approved']).to be false
expect(json_response['user_can_approve']).to be true
expect(json_response['suggested_approvers'].size).to eq 2
end
end
end end
it_behaves_like 'approvals'
describe 'PUT update' do describe 'PUT update' do
def update_merge_request(params = {}) def update_merge_request(params = {})
post :update, post :update,
...@@ -353,6 +355,8 @@ describe Projects::MergeRequestsController do ...@@ -353,6 +355,8 @@ describe Projects::MergeRequestsController do
fork_project.add_reporter(user) fork_project.add_reporter(user)
end end
it_behaves_like 'approvals'
context 'user cannot push to source branch' do context 'user cannot push to source branch' do
it 'returns 404' do it 'returns 404' do
expect_rebase_worker_for(viewer).never expect_rebase_worker_for(viewer).never
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment