diff options
author | Robert Speicher <robert@gitlab.com> | 2016-10-02 14:33:06 +0300 |
---|---|---|
committer | Robert Speicher <robert@gitlab.com> | 2016-10-02 14:33:06 +0300 |
commit | 076e0406390cb03ade887723bceb3a6bb9613986 (patch) | |
tree | ba47bc00ee3a1de6b76a80527c7dc306684e10d2 /spec/services/members | |
parent | c9352aa6e388293784f50ecd26892f1780522256 (diff) | |
parent | 76232d541baebb25ca3536364e27b379e5356460 (diff) |
Merge branch 'rc-new-members-request-access-service' into 'master'
New `Members::RequestAccessService`
Part of #21979.
See merge request !6265
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 |