From afb68bfcbd9bdb7042172ccb00c1928a1cc9093c Mon Sep 17 00:00:00 2001 From: f Date: Fri, 12 Jul 2019 15:34:16 -0300 Subject: [PATCH] se pueden eliminar sitios --- app/models/site.rb | 6 ++++++ test/factories/site.rb | 2 +- test/models/site_test.rb | 7 +++++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/app/models/site.rb b/app/models/site.rb index 71cb7bc..d2e7d0b 100644 --- a/app/models/site.rb +++ b/app/models/site.rb @@ -17,6 +17,8 @@ class Site < ApplicationRecord # Clonar el directorio de esqueleto antes de crear el sitio before_create :clone_skel! + # Elimina el directorio al destruir un sitio + before_destroy :remove_directories! # Carga el sitio Jekyll una vez que se inicializa el modelo o despuĆ©s # de crearlo after_initialize :load_jekyll! @@ -363,4 +365,8 @@ class Site < ApplicationRecord @jekyll ||= Site.load_jekyll(Dir.pwd) end end + + def remove_directories! + FileUtils.rm_rf path + end end diff --git a/test/factories/site.rb b/test/factories/site.rb index 7947e8a..9d80180 100644 --- a/test/factories/site.rb +++ b/test/factories/site.rb @@ -2,6 +2,6 @@ FactoryBot.define do factory :site do - name { SecureRandom.hex } + name { "test-#{SecureRandom.hex}" } end end diff --git a/test/models/site_test.rb b/test/models/site_test.rb index 98e9940..66ad25b 100644 --- a/test/models/site_test.rb +++ b/test/models/site_test.rb @@ -10,6 +10,13 @@ class SiteTest < ActiveSupport::TestCase # TODO: Mover a la validaciĆ³n del sitio o hacer algo similar assert File.directory?(site.path) assert File.directory?(File.join(site.path, '.git')) + assert site.destroy + end + + test 'al destruir un sitio se eliminan los archivos' do + site = create :site + assert site.destroy + assert !File.directory?(site.path) end test 'se puede leer un sitio' do