diff options
author | Rémy Coutable <remy@rymai.me> | 2016-07-28 19:28:56 +0200 |
---|---|---|
committer | Rémy Coutable <remy@rymai.me> | 2016-09-22 11:12:17 +0200 |
commit | 6b02127f03b1f8e1dbbecccfc2ba16e62aadcbed (patch) | |
tree | 203e8df9de809ffcc5a8d31c76885ecd0d088ab2 /spec/services/members | |
parent | 98b3d6ce695a9751f72adc35bc09f82eb2f624a4 (diff) | |
download | gitlab-ce-6b02127f03b1f8e1dbbecccfc2ba16e62aadcbed.tar.gz |
New Members::RequestAccessService
Signed-off-by: Rémy Coutable <remy@rymai.me>
Diffstat (limited to 'spec/services/members')
-rw-r--r-- | spec/services/members/request_access_service_spec.rb | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/spec/services/members/request_access_service_spec.rb b/spec/services/members/request_access_service_spec.rb new file mode 100644 index 00000000000..dff5b4917ae --- /dev/null +++ b/spec/services/members/request_access_service_spec.rb @@ -0,0 +1,57 @@ +require 'spec_helper' + +describe Members::RequestAccessService, services: true do + let(:user) { create(:user) } + let(:project) { create(:project, :private) } + let(:group) { create(:group, :private) } + + 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 + + expect(member).to be_a "#{source.class.to_s}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 + it_behaves_like 'a service raising Gitlab::Access::AccessDeniedError' do + let(:source) { project } + end + + it_behaves_like 'a service raising Gitlab::Access::AccessDeniedError' do + let(:source) { group } + end + end + + context 'when current user can request access to the project' do + before do + project.update(visibility_level: Gitlab::VisibilityLevel::PUBLIC) + group.update(visibility_level: Gitlab::VisibilityLevel::PUBLIC) + end + + it_behaves_like 'a service creating a access request' do + let(:source) { project } + end + + it_behaves_like 'a service creating a access request' do + let(:source) { group } + end + end +end |