Commit 3203baf3 authored by Mayra Cabrera's avatar Mayra Cabrera
Browse files

Include ProjectDeployTokens

Also:
- Changes scopes from serializer to use boolean columns
- Fixes broken specs
parent 3316b8eff61b
require 'rails_helper'
RSpec.describe ProjectDeployToken, type: :model do
let(:project) { create(:project) }
let(:deploy_token) { create(:deploy_token) }
subject(:project_deploy_token) { create(:project_deploy_token, project: project, deploy_token: deploy_token) }
it { is_expected.to belong_to :project }
it { is_expected.to belong_to :deploy_token }
it { is_expected.to accept_nested_attributes_for :deploy_token }
it { is_expected.to validate_presence_of :deploy_token }
it { is_expected.to validate_presence_of :project }
it { is_expected.to validate_uniqueness_of(:deploy_token_id).scoped_to(:project_id) }
end
......@@ -84,6 +84,8 @@
it { is_expected.to have_many(:custom_attributes).class_name('ProjectCustomAttribute') }
it { is_expected.to have_many(:project_badges).class_name('ProjectBadge') }
it { is_expected.to have_many(:lfs_file_locks) }
it { is_expected.to have_many(:project_deploy_tokens) }
it { is_expected.to have_many(:deploy_tokens).through(:project_deploy_tokens) }
context 'after initialized' do
it "has a project_feature" do
......
......@@ -15,7 +15,7 @@
it { is_expected.to be_allowed(:create_deploy_token) }
end
context 'when user is not master' do
before do
project.add_developer(current_user)
......
......@@ -3,25 +3,11 @@
describe Projects::Settings::DeployTokensPresenter do
let(:user) { create(:user) }
let(:project) { create(:project) }
let(:deploy_tokens) { create_list(:deploy_token, 3, project: project) }
let!(:project_deploy_tokens) { create_list(:project_deploy_token, 3, project: project) }
let(:deploy_tokens) { project.deploy_tokens }
subject(:presenter) { described_class.new(deploy_tokens, current_user: user, project: project) }
describe '#available_scopes' do
it 'returns the all the deploy token scopes' do
expect(presenter.available_scopes).to match_array(%w(read_repository read_registry))
end
end
describe '#scope_description' do
let(:deploy_token) { create(:deploy_token, project: project, scopes: [:read_registry]) }
it 'returns the description for a given scope' do
description = 'Allows read-only access to the registry images'
expect(presenter.scope_description('read_registry')).to eq(description)
end
end
describe '#length' do
it 'returns the size of deploy tokens presented' do
expect(presenter.length).to eq(3)
......
......@@ -558,6 +558,7 @@
let(:project) { create(:project, :public) }
context 'when pulling and pushing' do
let(:current_user) { create(:deploy_token, projects: [project]) }
let(:current_params) do
{ scope: "repository:#{project.full_path}:pull,push" }
end
......
......@@ -13,42 +13,50 @@
expect { subject }.to change { DeployToken.count }.by(1)
end
it 'returns a DeployToken' do
expect(subject).to be_an_instance_of DeployToken
it 'should create a new ProjectDeployToken' do
expect { subject }.to change { ProjectDeployToken.count }.by(1)
end
it 'should assign the DeployToken to the project' do
expect(subject.project).to eq(project)
it 'returns a DeployToken' do
expect(subject).to be_an_instance_of DeployToken
end
it 'should store the token on redis' do
redis_key = subject.redis_shared_state_key(user.id)
redis_key = DeployToken.redis_shared_state_key(user.id)
subject
expect(Gitlab::Redis::SharedState.with { |redis| redis.get(redis_key) }).not_to be_nil
end
it 'should not store deploy token attributes on redis' do
redis_key = subject.redis_shared_state_key(user.id) + ":attributes"
it 'should not store deploy token attributes on redis' do
redis_key = DeployToken.redis_shared_state_key(user.id) + ":attributes"
subject
expect(Gitlab::Redis::SharedState.with { |redis| redis.get(redis_key) }).to be_nil
end
end
context 'when the deploy token is invalid' do
let(:deploy_token_params) { attributes_for(:deploy_token, scopes: []) }
let(:deploy_token_params) { attributes_for(:deploy_token, read_repository: false, read_registry: false) }
it 'it should not create a new DeployToken' do
it 'should not create a new DeployToken' do
expect { subject }.not_to change { DeployToken.count }
end
it 'should not create a new ProjectDeployToken' do
expect { subject }.not_to change { ProjectDeployToken.count }
end
it 'should not store the token on redis' do
redis_key = subject.redis_shared_state_key(user.id)
redis_key = DeployToken.redis_shared_state_key(user.id)
subject
expect(Gitlab::Redis::SharedState.with { |redis| redis.get(redis_key) }).to be_nil
end
it 'should store deploy token attributes on redis' do
redis_key = subject.redis_shared_state_key(user.id) + ":attributes"
redis_key = DeployToken.redis_shared_state_key(user.id) + ":attributes"
subject
expect(Gitlab::Redis::SharedState.with { |redis| redis.get(redis_key) }).not_to be_nil
end
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment