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

add spec for forked project

parent 4714cb58
require 'spec_helper'
describe Projects::MergeRequestsController do
let(:project) { create(:project, :repository) }
let(:merge_request) { create(:merge_request_with_diffs, target_project: project, source_project: project) }
let(:user) { project.owner }
let(:viewer) { user }
shared_examples 'approvals' do
def json_response
JSON.parse(response.body)
end
let(:approver) { create(:user) }
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
context 'approvals' do
def json_response
JSON.parse(response.body)
describe 'approve' do
before do
post :approve,
namespace_id: project.namespace.to_param,
project_id: project.to_param,
id: merge_request.iid,
format: :json
end
let(:approver) { create(:user) }
before do
merge_request.update_attribute :approvals_before_merge, 2
project.team << [approver, :developer]
project.approver_ids = [user, approver].map(&:id).join(',')
it 'approves the merge request' do
expect(response).to be_success
expect(json_response['approvals_left']).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['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
describe 'approve' do
before do
post :approve,
describe 'approvals' do
before do
merge_request.approvals.create(user: approver)
get :approvals,
namespace_id: project.namespace.to_param,
project_id: project.to_param,
id: merge_request.iid,
format: :json
end
end
it 'approves the merge request' do
expect(response).to be_success
expect(json_response['approvals_left']).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['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
it 'shows approval information' do
expect(response).to be_success
expect(json_response['approvals_left']).to eq 1
expect(json_response['approved_by'].size).to eq 1
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_can_approve']).to be true
expect(json_response['suggested_approvers'].size).to eq 1
expect(json_response['suggested_approvers'][0]['username']).to eq user.username
end
end
describe 'approvals' do
before do
merge_request.approvals.create(user: approver)
get :approvals,
namespace_id: project.namespace.to_param,
project_id: project.to_param,
id: merge_request.iid,
format: :json
end
describe 'unapprove' do
before do
merge_request.approvals.create(user: user)
delete :unapprove,
namespace_id: project.namespace.to_param,
project_id: project.to_param,
id: merge_request.iid,
format: :json
end
it 'shows approval information' do
expect(response).to be_success
expect(json_response['approvals_left']).to eq 1
expect(json_response['approved_by'].size).to eq 1
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_can_approve']).to be true
expect(json_response['suggested_approvers'].size).to eq 1
expect(json_response['suggested_approvers'][0]['username']).to eq user.username
end
it 'unapproves the merge request' do
expect(response).to be_success
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
describe 'unapprove' do
before do
merge_request.approvals.create(user: user)
delete :unapprove,
namespace_id: project.namespace.to_param,
project_id: project.to_param,
id: merge_request.iid,
format: :json
end
describe Projects::MergeRequestsController do
let(:project) { create(:project, :repository) }
let(:merge_request) { create(:merge_request_with_diffs, target_project: project, source_project: project) }
let(:user) { project.owner }
let(:viewer) { user }
it 'unapproves the merge request' do
expect(response).to be_success
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
before do
sign_in(viewer)
end
it_behaves_like 'approvals'
describe 'PUT update' do
def update_merge_request(params = {})
post :update,
......@@ -353,6 +355,8 @@ describe Projects::MergeRequestsController do
fork_project.add_reporter(user)
end
it_behaves_like 'approvals'
context 'user cannot push to source branch' do
it 'returns 404' do
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