debian-mirror-gitlab/spec/services/members/request_access_service_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

57 lines
1.7 KiB
Ruby
Raw Permalink Normal View History

2019-07-31 22:56:46 +05:30
# frozen_string_literal: true
2016-11-03 12:29:30 +05:30
require 'spec_helper'
2023-05-27 22:25:52 +05:30
RSpec.describe Members::RequestAccessService, feature_category: :subgroups do
2016-11-03 12:29:30 +05:30
let(:user) { create(:user) }
shared_examples 'a service raising Gitlab::Access::AccessDeniedError' do
it 'raises Gitlab::Access::AccessDeniedError' do
2018-03-27 19:54:05 +05:30
expect { described_class.new(user).execute(source) }.to raise_error(Gitlab::Access::AccessDeniedError)
2016-11-03 12:29:30 +05:30
end
end
shared_examples 'a service creating a access request' do
it 'succeeds' do
2018-03-27 19:54:05 +05:30
expect { described_class.new(user).execute(source) }.to change { source.requesters.count }.by(1)
2016-11-03 12:29:30 +05:30
end
it 'returns a <Source>Member' do
2018-03-27 19:54:05 +05:30
member = described_class.new(user).execute(source)
2016-11-03 12:29:30 +05:30
expect(member).to be_a "#{source.class}Member".constantize
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-09-10 17:25:29 +05:30
%i[project group].each do |source_type|
2017-08-17 22:00:37 +05:30
it_behaves_like 'a service raising Gitlab::Access::AccessDeniedError' do
let(:source) { create(source_type, :private) }
end
2016-11-03 12:29:30 +05:30
end
2017-08-17 22:00:37 +05:30
end
2016-11-03 12:29:30 +05:30
2017-08-17 22:00:37 +05:30
context 'when access requests are disabled' do
2017-09-10 17:25:29 +05:30
%i[project group].each do |source_type|
2017-08-17 22:00:37 +05:30
it_behaves_like 'a service raising Gitlab::Access::AccessDeniedError' do
2019-12-21 20:55:43 +05:30
let(:source) { create(source_type, :public, :request_access_disabled) }
2017-08-17 22:00:37 +05:30
end
2016-11-03 12:29:30 +05:30
end
end
context 'when current user can request access to the project' do
2017-09-10 17:25:29 +05:30
%i[project group].each do |source_type|
2017-08-17 22:00:37 +05:30
it_behaves_like 'a service creating a access request' do
2019-12-21 20:55:43 +05:30
let(:source) { create(source_type, :public) }
2017-08-17 22:00:37 +05:30
end
2016-11-03 12:29:30 +05:30
end
end
end