diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-07-20 15:26:25 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-07-20 15:26:25 +0300 |
commit | a09983ae35713f5a2bbb100981116d31ce99826e (patch) | |
tree | 2ee2af7bd104d57086db360a7e6d8c9d5d43667a /spec/serializers/deploy_key_entity_spec.rb | |
parent | 18c5ab32b738c0b6ecb4d0df3994000482f34bd8 (diff) |
Add latest changes from gitlab-org/gitlab@13-2-stable-ee
Diffstat (limited to 'spec/serializers/deploy_key_entity_spec.rb')
-rw-r--r-- | spec/serializers/deploy_key_entity_spec.rb | 43 |
1 files changed, 41 insertions, 2 deletions
diff --git a/spec/serializers/deploy_key_entity_spec.rb b/spec/serializers/deploy_key_entity_spec.rb index 0dbbf0de59b..3404d27a23c 100644 --- a/spec/serializers/deploy_key_entity_spec.rb +++ b/spec/serializers/deploy_key_entity_spec.rb @@ -2,15 +2,16 @@ require 'spec_helper' -describe DeployKeyEntity do +RSpec.describe DeployKeyEntity do include RequestAwareEntity let(:user) { create(:user) } let(:project) { create(:project, :internal)} let(:project_private) { create(:project, :private)} let(:deploy_key) { create(:deploy_key) } + let(:options) { { user: user } } - let(:entity) { described_class.new(deploy_key, user: user) } + let(:entity) { described_class.new(deploy_key, options) } before do project.deploy_keys << deploy_key @@ -74,4 +75,42 @@ describe DeployKeyEntity do it { expect(entity_public.as_json).to include(can_edit: true) } end end + + describe 'with_owner option' do + it 'does not return an owner payload when it is set to false' do + options[:with_owner] = false + + payload = entity.as_json + + expect(payload[:owner]).not_to be_present + end + + describe 'when with_owner is set to true' do + before do + options[:with_owner] = true + end + + it 'returns an owner payload' do + payload = entity.as_json + + expect(payload[:owner]).to be_present + expect(payload[:owner].keys).to include(:id, :name, :username, :avatar_url) + end + + it 'does not return an owner if current_user cannot read the owner' do + allow(Ability).to receive(:allowed?).and_call_original + allow(Ability).to receive(:allowed?).with(options[:user], :read_user, deploy_key.user).and_return(false) + + payload = entity.as_json + + expect(payload[:owner]).to be_nil + end + end + end + + it 'does not return an owner payload with_owner option not passed in' do + payload = entity.as_json + + expect(payload[:owner]).not_to be_present + end end |