Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMayra Cabrera <mcabrera@gitlab.com>2018-04-05 20:22:34 +0300
committerMayra Cabrera <mcabrera@gitlab.com>2018-04-07 05:20:16 +0300
commit8315861c9a50675b4f4f4ca536f0da90f27994f3 (patch)
treeb5f25e5dbd74621ef77d480ba69f4f21d5c00d7d /spec/models/deploy_token_spec.rb
parent72220a99d1cdbcf8a914f9e765c43e63eaee2548 (diff)
Include ProjectDeployTokens
Also: - Changes scopes from serializer to use boolean columns - Fixes broken specs
Diffstat (limited to 'spec/models/deploy_token_spec.rb')
-rw-r--r--spec/models/deploy_token_spec.rb50
1 files changed, 35 insertions, 15 deletions
diff --git a/spec/models/deploy_token_spec.rb b/spec/models/deploy_token_spec.rb
index 50f6f441a58..395c97f13a5 100644
--- a/spec/models/deploy_token_spec.rb
+++ b/spec/models/deploy_token_spec.rb
@@ -1,28 +1,49 @@
require 'spec_helper'
describe DeployToken do
- let(:deploy_token) { create(:deploy_token) }
+ subject(:deploy_token) { create(:deploy_token) }
- it { is_expected.to belong_to :project }
- it { is_expected.to validate_presence_of :project }
+ it { is_expected.to have_many :project_deploy_tokens }
+ it { is_expected.to have_many(:projects).through(:project_deploy_tokens) }
- describe 'validations' do
- context 'with no scopes defined' do
- it 'should not be valid' do
- deploy_token.scopes = []
+ describe '#ensure_token' do
+ it 'should ensure a token' do
+ deploy_token.token = nil
+ deploy_token.save
+
+ expect(deploy_token.token).not_to be_empty
+ end
+ end
+
+ describe '#ensure_at_least_one_scope' do
+ context 'with at least one scope' do
+ it 'should be valid' do
+ is_expected.to be_valid
+ end
+ end
+
+ context 'with no scopes' do
+ it 'should be invalid' do
+ deploy_token = build(:deploy_token, read_repository: false, read_registry: false)
expect(deploy_token).not_to be_valid
- expect(deploy_token.errors[:scopes].first).to eq("can't be blank")
+ expect(deploy_token.errors[:base].first).to eq("Scopes can't be blank")
end
end
end
- describe '#ensure_token' do
- it 'should ensure a token' do
- deploy_token.token = nil
- deploy_token.save
+ describe '#scopes' do
+ context 'with all the scopes' do
+ it 'should return scopes assigned to DeployToken' do
+ expect(deploy_token.scopes).to eq([:read_repository, :read_registry])
+ end
+ end
- expect(deploy_token.token).not_to be_empty
+ context 'with only one scope' do
+ it 'should return scopes assigned to DeployToken' do
+ deploy_token = create(:deploy_token, read_registry: false)
+ expect(deploy_token.scopes).to eq([:read_repository])
+ end
end
end
@@ -50,8 +71,7 @@ describe DeployToken do
describe '#username' do
it 'returns Ghost username' do
- ghost = User.ghost
- expect(deploy_token.username).to eq(ghost.username)
+ expect(deploy_token.username).to eq("gitlab+deploy-token-#{deploy_token.id}")
end
end
end