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
|
2020-03-24 17:06:33 +00:00
|
|
|
def site
|
|
|
|
@site ||= create :site
|
|
|
|
end
|
|
|
|
|
2019-07-12 19:11:07 +00:00
|
|
|
# Asegurarse que el sitio se destruye al terminar de usarlo
|
|
|
|
teardown do
|
2020-03-24 17:06:33 +00:00
|
|
|
site&.destroy
|
2019-07-12 19:11:07 +00:00
|
|
|
end
|
|
|
|
|
2019-07-12 18:22:37 +00:00
|
|
|
test 'se puede crear un sitio' do
|
|
|
|
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
|
2020-03-24 17:06:33 +00:00
|
|
|
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
|
2020-03-24 17:06:33 +00:00
|
|
|
@site = build :site, name: 'hola.chau'
|
2019-07-17 22:18:48 +00:00
|
|
|
site.validate
|
2019-07-12 19:11:07 +00:00
|
|
|
|
2019-07-17 22:18:48 +00:00
|
|
|
assert_not site.errors.messages[:name].present?
|
2019-07-12 19:11:07 +00:00
|
|
|
end
|
|
|
|
|
2019-11-18 17:08:30 +00:00
|
|
|
test 'el nombre del sitio puede terminar con punto' do
|
2020-03-24 17:06:33 +00:00
|
|
|
@site = build :site, name: 'hola.chau.'
|
2019-07-17 22:18:48 +00:00
|
|
|
site.validate
|
2019-07-12 19:11:07 +00:00
|
|
|
|
2019-11-18 17:08:30 +00:00
|
|
|
assert_not site.errors.messages[:name].present?
|
2019-07-12 19:11:07 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
test 'el nombre del sitio no puede contener wildcard' do
|
2020-03-24 17:06:33 +00:00
|
|
|
@site = build :site, name: '*.chau'
|
2019-07-17 22:18:48 +00:00
|
|
|
site.validate
|
2019-07-12 19:11:07 +00:00
|
|
|
|
2019-07-17 22:18:48 +00:00
|
|
|
assert site.errors.messages[:name].present?
|
2019-07-12 19:11:07 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
test 'el nombre del sitio solo tiene letras, numeros y guiones' do
|
2020-03-24 17:06:33 +00:00
|
|
|
@site = build :site, name: 'A_Z!'
|
2019-07-17 22:18:48 +00:00
|
|
|
site.validate
|
2019-07-12 19:11:07 +00:00
|
|
|
|
2019-07-17 22:18:48 +00:00
|
|
|
assert site.errors.messages[:name].present?
|
2019-07-12 19:11:07 +00:00
|
|
|
end
|
|
|
|
|
2019-07-12 18:34:16 +00:00
|
|
|
test 'al destruir un sitio se eliminan los archivos' do
|
2020-03-24 17:06:33 +00:00
|
|
|
@site = create :site
|
2019-07-12 18:34:16 +00:00
|
|
|
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
|
|
|
|
assert site.valid?
|
|
|
|
assert !site.posts.empty?
|
2018-05-11 16:24:30 +00:00
|
|
|
end
|
2019-07-13 00:20:36 +00:00
|
|
|
|
|
|
|
test 'se pueden renombrar' do
|
2020-03-24 17:06:33 +00:00
|
|
|
path = site.path
|
2019-07-13 00:20:36 +00:00
|
|
|
|
2020-03-24 17:06:33 +00:00
|
|
|
site.update_attribute :name, SecureRandom.hex
|
2019-07-13 00:20:36 +00:00
|
|
|
|
2020-03-24 17:06:33 +00:00
|
|
|
assert_not_equal path, site.path
|
|
|
|
assert File.directory?(site.path)
|
2019-07-13 00:20:36 +00:00
|
|
|
assert_not File.directory?(path)
|
|
|
|
end
|
2019-08-01 23:13:38 +00:00
|
|
|
|
|
|
|
test 'no se puede guardar html en title y description' do
|
2020-03-24 17:06:33 +00:00
|
|
|
_site = build :site
|
|
|
|
_site.description = "<a href='hola'>hola</a><script>alert('pwned')</script>"
|
|
|
|
_site.title = "<a href='hola'>hola</a><script>alert('pwned')</script>"
|
2019-08-01 23:13:38 +00:00
|
|
|
|
2020-03-24 17:06:33 +00:00
|
|
|
assert_equal 'hola', _site.description
|
|
|
|
assert_equal 'hola', _site.title
|
2019-08-01 23:13:38 +00:00
|
|
|
end
|
2019-08-06 23:17:29 +00:00
|
|
|
|
|
|
|
test 'el sitio tiene artículos en distintos idiomas' do
|
|
|
|
I18n.available_locales.each do |locale|
|
2020-03-24 17:06:33 +00:00
|
|
|
assert site.posts(lang: locale).size.positive?
|
2019-08-06 23:17:29 +00:00
|
|
|
end
|
|
|
|
end
|
2020-03-24 17:06:33 +00:00
|
|
|
|
|
|
|
test 'tienen un hostname que puede cambiar' do
|
|
|
|
assert_equal "#{site.name}.#{Site.domain}", site.hostname
|
|
|
|
|
|
|
|
site.name = name = SecureRandom.hex
|
|
|
|
|
|
|
|
assert_equal "#{name}.#{Site.domain}", site.hostname
|
|
|
|
end
|
|
|
|
|
|
|
|
test 'se pueden traer los datos de una plantilla' do
|
|
|
|
@site = create :site, design: Design.find_by(gem: 'editorial-autogestiva-jekyll-theme')
|
|
|
|
|
|
|
|
assert_equal %i[post], site.layouts.to_h.keys
|
|
|
|
|
|
|
|
site.config.write
|
|
|
|
site.reload
|
|
|
|
|
2021-04-16 13:37:53 +00:00
|
|
|
assert_equal %w[book cart confirmation editorial menu payment post shipment], site.data['layouts'].keys
|
|
|
|
assert_equal %i[book cart confirmation editorial menu payment post shipment], site.layouts.to_h.keys
|
2020-03-24 17:06:33 +00:00
|
|
|
end
|
2021-04-16 14:06:24 +00:00
|
|
|
|
|
|
|
test 'se pueden encolar una sola vez' do
|
|
|
|
assert site.enqueue!
|
|
|
|
assert site.enqueued?
|
|
|
|
assert_not site.enqueue!
|
2020-03-24 17:06:33 +00:00
|
|
|
end
|
2018-04-27 18:48:26 +00:00
|
|
|
end
|