diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-07-15 15:09:26 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-07-15 15:09:26 +0300 |
commit | 9215d9f7619929f9da16744fa37636635b66949b (patch) | |
tree | 754fa5c3a99700176b117d96b30268cbd3c07581 /spec/serializers/deploy_key_entity_spec.rb | |
parent | a898b6057ecf9ab635c45217568d44eab5c32ec0 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/serializers/deploy_key_entity_spec.rb')
-rw-r--r-- | spec/serializers/deploy_key_entity_spec.rb | 41 |
1 files changed, 40 insertions, 1 deletions
diff --git a/spec/serializers/deploy_key_entity_spec.rb b/spec/serializers/deploy_key_entity_spec.rb index 3354db5cf8d..3404d27a23c 100644 --- a/spec/serializers/deploy_key_entity_spec.rb +++ b/spec/serializers/deploy_key_entity_spec.rb @@ -9,8 +9,9 @@ RSpec.describe DeployKeyEntity do 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 @@ RSpec.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 |