From d2757acbbb8e94667c9ff941a8718d9e6a090e78 Mon Sep 17 00:00:00 2001 From: Lidia Mokevnina Date: Mon, 10 Apr 2023 17:56:40 +0200 Subject: [PATCH] [402] removed validation on create_source inclusion --- core/app/lib/uffizzi_core/concerns/models/deployment.rb | 4 ---- core/app/models/uffizzi_core/deployment.rb | 3 +++ core/app/services/uffizzi_core/deployment_service.rb | 2 +- .../cli/v1/projects/deployments_controller/create_test.rb | 8 ++++---- core/test/factories/deployment.rb | 6 +----- 5 files changed, 9 insertions(+), 14 deletions(-) diff --git a/core/app/lib/uffizzi_core/concerns/models/deployment.rb b/core/app/lib/uffizzi_core/concerns/models/deployment.rb index 2758755b..ae1c0138 100644 --- a/core/app/lib/uffizzi_core/concerns/models/deployment.rb +++ b/core/app/lib/uffizzi_core/concerns/models/deployment.rb @@ -24,12 +24,8 @@ module UffizziCore::Concerns::Models::Deployment has_many :activity_items, dependent: :destroy has_one :ingress_container, -> { where(receive_incoming_requests: true) }, class_name: UffizziCore::Container.name - validates :kind, presence: true - enumerize :creation_source, in: [:manual, :demo, :continuous_preview, :compose_file_manual, :compose_file_continuous_preview], - predicates: true, scope: true, default: :manual - accepts_nested_attributes_for :containers, allow_destroy: true after_destroy_commit :clean diff --git a/core/app/models/uffizzi_core/deployment.rb b/core/app/models/uffizzi_core/deployment.rb index 3708ad7f..76b48643 100644 --- a/core/app/models/uffizzi_core/deployment.rb +++ b/core/app/models/uffizzi_core/deployment.rb @@ -21,4 +21,7 @@ class UffizziCore::Deployment < UffizziCore::ApplicationRecord include UffizziCore::Concerns::Models::Deployment + + const_set(:COMPOSE_FILE_MANUAL, :compose_file_manual) + validates :creation_source, presence: true end diff --git a/core/app/services/uffizzi_core/deployment_service.rb b/core/app/services/uffizzi_core/deployment_service.rb index a7a6173a..16db7b94 100644 --- a/core/app/services/uffizzi_core/deployment_service.rb +++ b/core/app/services/uffizzi_core/deployment_service.rb @@ -19,7 +19,7 @@ def create_from_compose(compose_file, project, user, params) deployment_form = UffizziCore::Api::Cli::V1::Deployment::CreateForm.new(deployment_attributes) deployment_form.assign_dependences!(project, user) deployment_form.compose_file = compose_file - deployment_form.creation_source = params[:creation_source] || UffizziCore::Deployment.creation_source.compose_file_manual + deployment_form.creation_source = params[:creation_source] || UffizziCore::Deployment::COMPOSE_FILE_MANUAL deployment_form.metadata = params[:metadata] || {} run_deployment_creation_tasks(deployment_form) if deployment_form.save diff --git a/core/test/controllers/uffizzi_core/api/cli/v1/projects/deployments_controller/create_test.rb b/core/test/controllers/uffizzi_core/api/cli/v1/projects/deployments_controller/create_test.rb index 61b9e2b5..e5a1f3d1 100644 --- a/core/test/controllers/uffizzi_core/api/cli/v1/projects/deployments_controller/create_test.rb +++ b/core/test/controllers/uffizzi_core/api/cli/v1/projects/deployments_controller/create_test.rb @@ -142,13 +142,13 @@ class UffizziCore::Api::Cli::V1::Projects::DeploymentsControllerTest < ActionCon deployment = compose_file.deployments.first assert_equal(@metadata, deployment.metadata) assert_equal(deployment.subdomain.downcase, deployment.subdomain) - assert_equal(deployment.creation_source, UffizziCore::Deployment.creation_source.compose_file_manual) + assert_equal(deployment.creation_source, UffizziCore::Deployment::COMPOSE_FILE_MANUAL.to_s) Sidekiq::Worker.clear_all Sidekiq::Testing.inline! end - test '#create - from the existing compose file with creation_source' do + test '#create - from the existing compose file with custom creation source' do Sidekiq::Worker.clear_all Sidekiq::Testing.fake! @@ -177,7 +177,7 @@ class UffizziCore::Api::Cli::V1::Projects::DeploymentsControllerTest < ActionCon } create(:template, :compose_file_source, compose_file: compose_file, project: @project, added_by: @admin, payload: template_payload) stub_dockerhub_repository('library', 'redis') - creation_source = UffizziCore::Deployment.creation_source.manual + creation_source = 'custom_source' params = { project_slug: @project.slug, compose_file: {}, dependencies: [], creation_source: creation_source } @@ -186,7 +186,7 @@ class UffizziCore::Api::Cli::V1::Projects::DeploymentsControllerTest < ActionCon assert_response :success deployment = compose_file.deployments.first - assert_equal(deployment.creation_source, creation_source) + assert_equal(creation_source, deployment.creation_source) Sidekiq::Worker.clear_all Sidekiq::Testing.inline! diff --git a/core/test/factories/deployment.rb b/core/test/factories/deployment.rb index 37d12539..971a749a 100644 --- a/core/test/factories/deployment.rb +++ b/core/test/factories/deployment.rb @@ -7,7 +7,7 @@ created_at { DateTime.current } memory_limit { 1 } continuous_preview_payload { nil } - creation_source { nil } + creation_source { UffizziCore::Deployment::COMPOSE_FILE_MANUAL } metadata { {} } trait :active do @@ -17,9 +17,5 @@ trait :disabled do state { :disabled } end - - trait :compose_file_source do - creation_source { UffizziCore::Deployment.creation_source.compose_file_manual } - end end end