2016-07-28 13:28:56 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Members::RequestAccessService, services: true do
|
|
|
|
let(:user) { create(:user) }
|
|
|
|
|
|
|
|
shared_examples 'a service raising Gitlab::Access::AccessDeniedError' do
|
|
|
|
it 'raises Gitlab::Access::AccessDeniedError' do
|
|
|
|
expect { described_class.new(source, user).execute }.to raise_error(Gitlab::Access::AccessDeniedError)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
shared_examples 'a service creating a access request' do
|
|
|
|
it 'succeeds' do
|
|
|
|
expect { described_class.new(source, user).execute }.to change { source.requesters.count }.by(1)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns a <Source>Member' do
|
|
|
|
member = described_class.new(source, user).execute
|
|
|
|
|
2016-10-03 10:09:57 -04:00
|
|
|
expect(member).to be_a "#{source.class}Member".constantize
|
2016-07-28 13:28:56 -04:00
|
|
|
expect(member.requested_at).to be_present
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when source is nil' do
|
|
|
|
it_behaves_like 'a service raising Gitlab::Access::AccessDeniedError' do
|
|
|
|
let(:source) { nil }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when current user cannot request access to the project' do
|
2017-03-27 17:14:01 -04:00
|
|
|
%i[empty_project group].each do |source_type|
|
2016-11-11 07:51:50 -05:00
|
|
|
it_behaves_like 'a service raising Gitlab::Access::AccessDeniedError' do
|
|
|
|
let(:source) { create(source_type, :private) }
|
|
|
|
end
|
2016-07-28 13:28:56 -04:00
|
|
|
end
|
2016-11-11 07:51:50 -05:00
|
|
|
end
|
2016-07-28 13:28:56 -04:00
|
|
|
|
2016-11-11 07:51:50 -05:00
|
|
|
context 'when access requests are disabled' do
|
2017-03-27 17:14:01 -04:00
|
|
|
%i[empty_project group].each do |source_type|
|
2016-11-11 07:51:50 -05:00
|
|
|
it_behaves_like 'a service raising Gitlab::Access::AccessDeniedError' do
|
|
|
|
let(:source) { create(source_type, :public) }
|
|
|
|
end
|
2016-07-28 13:28:56 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when current user can request access to the project' do
|
2017-03-27 17:14:01 -04:00
|
|
|
%i[empty_project group].each do |source_type|
|
2016-11-11 07:51:50 -05:00
|
|
|
it_behaves_like 'a service creating a access request' do
|
|
|
|
let(:source) { create(source_type, :public, :access_requestable) }
|
|
|
|
end
|
2016-07-28 13:28:56 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|