2019-04-11 08:17:24 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-07-28 13:28:56 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2017-07-10 10:24:02 -04:00
|
|
|
describe Members::RequestAccessService do
|
2016-07-28 13:28:56 -04:00
|
|
|
let(:user) { create(:user) }
|
|
|
|
|
|
|
|
shared_examples 'a service raising Gitlab::Access::AccessDeniedError' do
|
|
|
|
it 'raises Gitlab::Access::AccessDeniedError' do
|
2018-02-16 09:10:22 -05:00
|
|
|
expect { described_class.new(user).execute(source) }.to raise_error(Gitlab::Access::AccessDeniedError)
|
2016-07-28 13:28:56 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
shared_examples 'a service creating a access request' do
|
|
|
|
it 'succeeds' do
|
2018-02-16 09:10:22 -05:00
|
|
|
expect { described_class.new(user).execute(source) }.to change { source.requesters.count }.by(1)
|
2016-07-28 13:28:56 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns a <Source>Member' do
|
2018-02-16 09:10:22 -05:00
|
|
|
member = described_class.new(user).execute(source)
|
2016-07-28 13:28:56 -04:00
|
|
|
|
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-08-02 15:55:11 -04:00
|
|
|
%i[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-08-02 15:55:11 -04:00
|
|
|
%i[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-08-02 15:55:11 -04:00
|
|
|
%i[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
|