2019-03-26 15:32:20 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-04-27 18:48:26 +00:00
|
|
|
require 'test_helper'
|
|
|
|
|
|
|
|
class SiteTest < ActiveSupport::TestCase
|
2019-07-12 19:11:07 +00:00
|
|
|
# Asegurarse que el sitio se destruye al terminar de usarlo
|
|
|
|
teardown do
|
|
|
|
@site&.destroy
|
|
|
|
end
|
|
|
|
|
2019-07-12 18:22:37 +00:00
|
|
|
test 'se puede crear un sitio' do
|
|
|
|
site = create :site
|
2018-05-02 17:23:45 +00:00
|
|
|
|
2019-07-12 18:22:37 +00:00
|
|
|
assert site.valid?
|
|
|
|
# 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'))
|
2019-07-12 18:34:16 +00:00
|
|
|
assert site.destroy
|
|
|
|
end
|
|
|
|
|
2019-07-12 18:37:11 +00:00
|
|
|
test 'el nombre tiene que ser único' do
|
2019-07-12 19:11:07 +00:00
|
|
|
@site = create :site
|
|
|
|
site2 = build :site, name: @site.name
|
2019-07-12 18:37:11 +00:00
|
|
|
|
|
|
|
assert_not site2.valid?
|
|
|
|
end
|
|
|
|
|
2019-07-12 19:11:07 +00:00
|
|
|
test 'el nombre del sitio puede contener subdominios' do
|
|
|
|
site = build :site, name: 'hola.chau'
|
|
|
|
|
|
|
|
assert site.valid?
|
|
|
|
end
|
|
|
|
|
|
|
|
test 'el nombre del sitio no puede terminar con punto' do
|
|
|
|
site = build :site, name: 'hola.chau.'
|
|
|
|
|
|
|
|
assert_not site.valid?
|
|
|
|
end
|
|
|
|
|
|
|
|
test 'el nombre del sitio no puede contener wildcard' do
|
|
|
|
site = build :site, name: '*.chau'
|
|
|
|
|
|
|
|
assert_not site.valid?
|
|
|
|
end
|
|
|
|
|
|
|
|
test 'el nombre del sitio solo tiene letras, numeros y guiones' do
|
|
|
|
site = build :site, name: 'A_Z!'
|
|
|
|
|
|
|
|
assert_not site.valid?
|
|
|
|
end
|
|
|
|
|
2019-07-12 18:34:16 +00:00
|
|
|
test 'al destruir un sitio se eliminan los archivos' do
|
|
|
|
site = create :site
|
|
|
|
assert site.destroy
|
|
|
|
assert !File.directory?(site.path)
|
2018-04-30 18:51:39 +00:00
|
|
|
end
|
2018-05-11 16:24:30 +00:00
|
|
|
|
2019-07-12 18:22:37 +00:00
|
|
|
test 'se puede leer un sitio' do
|
|
|
|
site = create :site, name: 'sutty.nl'
|
2018-05-11 16:24:30 +00:00
|
|
|
|
2019-07-12 18:22:37 +00:00
|
|
|
assert site.valid?
|
|
|
|
assert !site.posts.empty?
|
2018-05-11 16:24:30 +00:00
|
|
|
end
|
2018-04-27 18:48:26 +00:00
|
|
|
end
|