Actualizar el hostname si cambia el name
This commit is contained in:
parent
b9d7a27105
commit
c08cfb1637
3 changed files with 13 additions and 6 deletions
|
@ -3,7 +3,7 @@
|
|||
# Alojamiento local, genera el sitio como si corriéramos `jekyll build`.
|
||||
class DeployLocal < Deploy
|
||||
# Asegurarse que el hostname es el permitido.
|
||||
before_save :default_hostname!
|
||||
before_save :reset_hostname!, :default_hostname!
|
||||
|
||||
# Realizamos la construcción del sitio usando Jekyll y un entorno
|
||||
# limpio para no pasarle secretos
|
||||
|
@ -46,6 +46,10 @@ class DeployLocal < Deploy
|
|||
|
||||
private
|
||||
|
||||
def reset_hostname!
|
||||
self.hostname = nil
|
||||
end
|
||||
|
||||
# Crea el directorio destino si no existe.
|
||||
def mkdir
|
||||
FileUtils.mkdir_p destination
|
||||
|
|
|
@ -58,7 +58,7 @@ class Site < ApplicationRecord
|
|||
after_initialize :load_jekyll
|
||||
after_create :load_jekyll, :static_file_migration!
|
||||
# Cambiar el nombre del directorio
|
||||
before_update :update_name!
|
||||
before_update :update_name!, :update_deploy_local_hostname!, if: :name_changed?
|
||||
before_save :add_private_key_if_missing!
|
||||
# Guardar la configuración si hubo cambios
|
||||
after_save :sync_attributes_with_config!
|
||||
|
@ -450,8 +450,6 @@ class Site < ApplicationRecord
|
|||
end
|
||||
|
||||
def update_name!
|
||||
return unless name_changed?
|
||||
|
||||
FileUtils.mv path_was, path
|
||||
reload_jekyll!
|
||||
end
|
||||
|
@ -469,6 +467,11 @@ class Site < ApplicationRecord
|
|||
config.hostname = hostname
|
||||
end
|
||||
|
||||
# Si cambia el nombre queremos actualizarlo en el DeployLocal
|
||||
def update_deploy_local_hostname!
|
||||
deploy_local&.update hostname: name
|
||||
end
|
||||
|
||||
# Migra los archivos a Sutty
|
||||
def static_file_migration!
|
||||
Site::StaticFileMigration.new(site: self).migrate!
|
||||
|
|
|
@ -93,9 +93,9 @@ class SiteTest < ActiveSupport::TestCase
|
|||
test 'tienen un hostname que puede cambiar' do
|
||||
assert_equal "#{site.name}.#{Site.domain}", site.hostname
|
||||
|
||||
site.name = name = SecureRandom.hex
|
||||
site.update(name: (new_name = SecureRandom.hex))
|
||||
|
||||
assert_equal "#{name}.#{Site.domain}", site.hostname
|
||||
assert_equal "#{new_name}.#{Site.domain}", site.hostname
|
||||
end
|
||||
|
||||
test 'se pueden traer los datos de una plantilla' do
|
||||
|
|
Loading…
Reference in a new issue