mirror of
https://0xacab.org/sutty/sutty
synced 2024-11-16 17:46:21 +00:00
Al cambiar el nombre del sitio no puede haber un dominio alternativo igual
This commit is contained in:
parent
a1fde94378
commit
df29c4ca95
4 changed files with 41 additions and 0 deletions
|
@ -17,6 +17,7 @@ class Site
|
|||
validates :name, hostname: true
|
||||
validates_presence_of :canonical_deploy
|
||||
validate :deploy_local_presence
|
||||
validate :name_changed_is_unique_hostname, if: :name_changed?
|
||||
|
||||
has_one :canonical_deploy, class_name: 'Deploy'
|
||||
has_many :deploys, dependent: :destroy
|
||||
|
@ -68,6 +69,19 @@ class Site
|
|||
|
||||
private
|
||||
|
||||
# Validar que al cambiar el nombre no estemos utilizando un
|
||||
# hostname reservado por otro sitio.
|
||||
#
|
||||
# Al cambiar el nombre del DeployLocal se va a validar que el
|
||||
# hostname nuevo sea único.
|
||||
def name_changed_is_unique_hostname
|
||||
deploy_local.hostname = nil
|
||||
|
||||
return if deploy_local.valid?
|
||||
|
||||
errors.add :name, I18n.t('activerecord.errors.models.site.attributes.name.duplicated_hostname')
|
||||
end
|
||||
|
||||
# Si cambia el nombre queremos actualizarlo en el DeployLocal y
|
||||
# recargar el deploy canónico para tomar el nombre que
|
||||
# corresponda.
|
||||
|
|
|
@ -147,6 +147,7 @@ en:
|
|||
attributes:
|
||||
name:
|
||||
no_subdomains: 'Name cannot contain dots'
|
||||
duplicated_hostname: 'There already is a site with this address'
|
||||
deploys:
|
||||
deploy_local_presence: 'We need to be build the site!'
|
||||
design_id:
|
||||
|
|
|
@ -147,6 +147,7 @@ es:
|
|||
attributes:
|
||||
name:
|
||||
no_subdomains: 'El nombre no puede contener puntos'
|
||||
duplicated_hostname: 'Ya existe un sitio con ese nombre'
|
||||
deploys:
|
||||
deploy_local_presence: '¡Necesitamos poder generar el sitio!'
|
||||
design_id:
|
||||
|
|
25
test/models/site/deployment_test.rb
Normal file
25
test/models/site/deployment_test.rb
Normal file
|
@ -0,0 +1,25 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'test_helper'
|
||||
|
||||
class Site::DeploymentTest < ActiveSupport::TestCase
|
||||
def site
|
||||
@site ||= create :site
|
||||
end
|
||||
|
||||
teardown do
|
||||
@site&.destroy
|
||||
end
|
||||
|
||||
test 'al publicar el sitio se crea el directorio' do
|
||||
assert site.deploy_local.deploy
|
||||
assert site.deploy_local.exist?
|
||||
end
|
||||
|
||||
test 'al cambiar el nombre no puede pisar un dominio que ya existe' do
|
||||
site_pre = create :site
|
||||
dup_name = "test-#{SecureRandom.hex}"
|
||||
assert site_pre.deploys.create(type: 'DeployAlternativeDomain', hostname: "#{dup_name}.#{Site.domain}")
|
||||
assert_not site.update(name: dup_name)
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue