From 5a53facaa75dede801c5dfa299b3492b660aca55 Mon Sep 17 00:00:00 2001 From: f Date: Sat, 14 Aug 2021 20:27:08 -0300 Subject: [PATCH] Al cambiar el nombre actualizamos el www --- app/models/deploy_local.rb | 9 +++++++++ test/models/site/deployment_test.rb | 12 ++++++++++++ 2 files changed, 21 insertions(+) diff --git a/app/models/deploy_local.rb b/app/models/deploy_local.rb index 655e11e9..5a6a87cd 100644 --- a/app/models/deploy_local.rb +++ b/app/models/deploy_local.rb @@ -4,6 +4,8 @@ class DeployLocal < Deploy # Asegurarse que el hostname es el permitido. before_validation :reset_hostname!, :default_hostname! + # Actualiza el hostname con www si cambiamos el hostname + before_update :update_deploy_www!, if: :hostname_changed? # Realizamos la construcción del sitio usando Jekyll y un entorno # limpio para no pasarle secretos @@ -43,6 +45,13 @@ class DeployLocal < Deploy self.hostname = nil end + # XXX: En realidad el DeployWww debería regenerar su propio hostname. + def update_deploy_www! + site.deploys.where(type: 'DeployWww').map do |www| + www.update hostname: www.default_hostname + end + end + # Crea el directorio destino si no existe. def mkdir FileUtils.mkdir_p destination diff --git a/test/models/site/deployment_test.rb b/test/models/site/deployment_test.rb index f2e73c6d..799a33e7 100644 --- a/test/models/site/deployment_test.rb +++ b/test/models/site/deployment_test.rb @@ -54,6 +54,18 @@ class Site::DeploymentTest < ActiveSupport::TestCase assert File.exist?(site.deploy_local.destination) end + test 'al cambiar el nombre se actualiza el www' do + site_name = site.name + new_name = "test-#{SecureRandom.hex}" + + assert (deploy_www = site.deploys.create(type: 'DeployWww')) + assert site.deploy_local.deploy + assert_not site.deploy_local.destination_changed? + assert site.update(name: new_name) + assert deploy_www.reload.hostname.include?(new_name) + assert_equal 4, site.deploys.count + end + test 'al cambiar el nombre varias veces se crean varios links' do assert site.deploy_local.deploy