diff options
-rw-r--r-- | app/helpers/deploy_tokens_helper.rb | 4 | ||||
-rw-r--r-- | app/models/deploy_token.rb | 4 | ||||
-rw-r--r-- | app/services/deploy_tokens/create_service.rb | 2 | ||||
-rw-r--r-- | db/migrate/20180319190020_create_deploy_tokens.rb | 2 | ||||
-rw-r--r-- | db/schema.rb | 2 | ||||
-rw-r--r-- | spec/services/deploy_tokens/create_service_spec.rb | 10 |
6 files changed, 17 insertions, 7 deletions
diff --git a/app/helpers/deploy_tokens_helper.rb b/app/helpers/deploy_tokens_helper.rb index 8496cc2e4b2..31aa041b00a 100644 --- a/app/helpers/deploy_tokens_helper.rb +++ b/app/helpers/deploy_tokens_helper.rb @@ -11,10 +11,10 @@ module DeployTokensHelper end def expires_at_value(expires_at) - expires_at unless expires_at >= DeployToken::FUTURE_DATE + expires_at unless expires_at >= DeployToken::FOREVER end def show_expire_at?(token) - token.expires? && token.expires_at != DeployToken::FUTURE_DATE + token.expires? && token.expires_at != DeployToken::FOREVER end end diff --git a/app/models/deploy_token.rb b/app/models/deploy_token.rb index 688540dd67f..bfdc5457157 100644 --- a/app/models/deploy_token.rb +++ b/app/models/deploy_token.rb @@ -4,7 +4,9 @@ class DeployToken < ActiveRecord::Base add_authentication_token_field :token AVAILABLE_SCOPES = %i(read_repository read_registry).freeze - FUTURE_DATE = Date.new(3000 - 01 - 01) + FOREVER = DateTime.new(3000, 1, 1) + + default_value_for :expires_at, FOREVER has_many :project_deploy_tokens, inverse_of: :deploy_token has_many :projects, through: :project_deploy_tokens diff --git a/app/services/deploy_tokens/create_service.rb b/app/services/deploy_tokens/create_service.rb index b5989e0bbf1..04977ca4c18 100644 --- a/app/services/deploy_tokens/create_service.rb +++ b/app/services/deploy_tokens/create_service.rb @@ -16,7 +16,7 @@ module DeployTokens end def default_expires_at - DeployToken::FUTURE_DATE + DeployToken::FOREVER end end end diff --git a/db/migrate/20180319190020_create_deploy_tokens.rb b/db/migrate/20180319190020_create_deploy_tokens.rb index b8f77f5ae17..318ad3f0610 100644 --- a/db/migrate/20180319190020_create_deploy_tokens.rb +++ b/db/migrate/20180319190020_create_deploy_tokens.rb @@ -7,7 +7,7 @@ class CreateDeployTokens < ActiveRecord::Migration t.boolean :read_repository, null: false, default: false t.boolean :read_registry, null: false, default: false - t.datetime_with_timezone :expires_at, null: false, default: '3000-01-01' + t.datetime_with_timezone :expires_at, null: false t.datetime_with_timezone :created_at, null: false t.string :name, null: false diff --git a/db/schema.rb b/db/schema.rb index b0174a4ed46..a50c5fba969 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -687,7 +687,7 @@ ActiveRecord::Schema.define(version: 20180405142733) do t.boolean "revoked", default: false t.boolean "read_repository", default: false, null: false t.boolean "read_registry", default: false, null: false - t.datetime_with_timezone "expires_at", default: '3000-01-01 00:00:00', null: false + t.datetime_with_timezone "expires_at", null: false t.datetime_with_timezone "created_at", null: false t.string "name", null: false t.string "token", null: false diff --git a/spec/services/deploy_tokens/create_service_spec.rb b/spec/services/deploy_tokens/create_service_spec.rb index 2a308a9bf8c..2e02b7a28b5 100644 --- a/spec/services/deploy_tokens/create_service_spec.rb +++ b/spec/services/deploy_tokens/create_service_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe DeployTokens::CreateService, :clean_gitlab_redis_shared_state do +describe DeployTokens::CreateService do let(:project) { create(:project) } let(:user) { create(:user) } let(:deploy_token_params) { attributes_for(:deploy_token) } @@ -22,6 +22,14 @@ describe DeployTokens::CreateService, :clean_gitlab_redis_shared_state do end end + context 'when expires at date is not passed' do + let(:deploy_token_params) { attributes_for(:deploy_token, expires_at: '') } + + it 'should set FOREVER date' do + expect(subject.expires_at).to eq(DeployToken::FOREVER) + end + end + context 'when the deploy token is invalid' do let(:deploy_token_params) { attributes_for(:deploy_token, read_repository: false, read_registry: false) } |