debian-mirror-gitlab/spec/services/protected_branches/create_service_spec.rb

40 lines
1.3 KiB
Ruby
Raw Normal View History

2016-09-29 09:46:39 +05:30
require 'spec_helper'
2017-09-10 17:25:29 +05:30
describe ProtectedBranches::CreateService do
let(:project) { create(:project) }
2016-09-29 09:46:39 +05:30
let(:user) { project.owner }
let(:params) do
{
name: 'master',
2017-08-17 22:00:37 +05:30
merge_access_levels_attributes: [{ access_level: Gitlab::Access::MASTER }],
push_access_levels_attributes: [{ access_level: Gitlab::Access::MASTER }]
2016-09-29 09:46:39 +05:30
}
end
describe '#execute' do
subject(:service) { described_class.new(project, user, params) }
it 'creates a new protected branch' do
expect { service.execute }.to change(ProtectedBranch, :count).by(1)
expect(project.protected_branches.last.push_access_levels.map(&:access_level)).to eq([Gitlab::Access::MASTER])
expect(project.protected_branches.last.merge_access_levels.map(&:access_level)).to eq([Gitlab::Access::MASTER])
end
2018-03-17 18:26:18 +05:30
context 'when user does not have permission' do
let(:user) { create(:user) }
before do
project.add_developer(user)
end
it 'creates a new protected branch if we skip authorization step' do
expect { service.execute(skip_authorization: true) }.to change(ProtectedBranch, :count).by(1)
end
it 'raises Gitlab::Access:AccessDeniedError' do
expect { service.execute }.to raise_error(Gitlab::Access::AccessDeniedError)
end
end
2016-09-29 09:46:39 +05:30
end
end