5
0
Fork 0
mirror of https://0xacab.org/sutty/sutty synced 2024-11-25 19:26:22 +00:00
panel/test/controllers/sites_controller_test.rb

185 lines
4.7 KiB
Ruby
Raw Permalink Normal View History

2019-07-12 23:40:44 +00:00
# frozen_string_literal: true
2019-08-09 19:49:25 +00:00
require 'test_helper'
2019-07-12 23:40:44 +00:00
class SitesControllerTest < ActionDispatch::IntegrationTest
setup do
@rol = create :rol
@site = @rol.site
@usuarie = @rol.usuarie
@authorization = {
Authorization: ActionController::HttpAuthentication::Basic
.encode_credentials(@usuarie.email, @usuarie.password)
}
end
teardown do
@site.destroy
end
test 'se pueden ver' do
get sites_url, headers: @authorization
assert_match @site.name, response.body
end
test 'se puede ver el formulario de creación' do
get new_site_url, headers: @authorization
assert_match(/<form.*id="new_site"/, response.body)
end
test 'se pueden crear' do
name = SecureRandom.hex
2020-10-05 18:23:11 +00:00
design = Design.all.where.not(gem: Design::NO_THEMES).sample
2019-07-12 23:40:44 +00:00
post sites_url, headers: @authorization, params: {
site: {
2019-07-17 22:18:48 +00:00
name: name,
2019-07-31 20:55:34 +00:00
title: name,
description: name * 2,
2019-08-09 19:49:25 +00:00
design_id: design.id,
licencia_id: Licencia.first.id,
deploys_attributes: {
'0' => {
type: 'DeployLocal'
}
}
2019-07-12 23:40:44 +00:00
}
}
site = Site.find_by_name(name)
assert site
assert_equal @usuarie.email, site.roles.first.usuarie.email
assert_equal 'usuarie', site.roles.first.rol
2019-08-09 19:49:25 +00:00
assert_equal name, site.name
assert_equal name, site.title
assert_equal name * 2, site.description
assert_equal design, site.design
assert_equal design.gem, site.config.theme
assert_equal name, site.config.title
assert_equal name * 2, site.config.description
# TODO: Esto requiere que podamos buscar hacia atrás en la historia
# del repositorio
# assert_equal I18n.t('site_service.create', name: name),
# site.repository.rugged.head.target.message
I18n.available_locales.each do |locale|
assert_equal 3, site.posts(lang: locale).size
end
2019-08-09 19:49:25 +00:00
site.destroy
end
test 'no se pueden crear con cualquier deploy' do
name = SecureRandom.hex
assert_raise ActiveRecord::SubclassNotFound do
post sites_url, headers: @authorization, params: {
site: {
name: name,
design_id: create(:design).id,
licencia_id: create(:licencia).id,
deploys_attributes: {
'0' => {
type: 'DeployNoExiste'
}
}
}
}
2019-07-12 23:40:44 +00:00
end
end
2019-07-26 01:11:01 +00:00
test 'se pueden encolar' do
post site_enqueue_url(@site), headers: @authorization
2019-09-16 16:44:29 +00:00
assert File.directory?(@site.deploys.first.destination)
assert File.exist?(File.join(@site.deploys.first.destination,
'index.html'))
2019-07-26 01:11:01 +00:00
end
2019-08-09 19:49:25 +00:00
test 'no se pueden encolar varias veces seguidas' do
assert_enqueued_jobs 2 do
post site_enqueue_url(@site), headers: @authorization
post site_enqueue_url(@site), headers: @authorization
end
end
2019-08-09 19:49:25 +00:00
test 'se pueden actualizar' do
name = SecureRandom.hex
2020-09-29 21:22:28 +00:00
design = Design.all.where.not(id: @site.design_id).sample
2019-08-09 19:49:25 +00:00
put site_url(@site), headers: @authorization, params: {
site: {
name: name,
title: name,
description: name * 2,
design_id: design.id,
licencia_id: Licencia.all.second.id,
2019-08-09 19:49:25 +00:00
deploys_attributes: {
'0' => {
type: 'DeployLocal'
}
}
}
}
@site = Site.find(@site.id)
assert_equal name, @site.name
assert_equal name, @site.title
assert_equal name * 2, @site.description
assert_equal design, @site.design
assert_equal design.gem, @site.config.theme
assert_equal name, @site.config.title
assert_equal name * 2, @site.config.description
# assert_equal I18n.t('site_service.update', name: name),
# @site.repository.rugged.head.target.message
I18n.available_locales.each do |locale|
Mobility.with_locale(locale) do
assert @site.posts(lang: locale).find_by(title: @site.licencia.name)
end
end
end
test 'se pueden cambiar las licencias' do
name = SecureRandom.hex
post sites_url, headers: @authorization, params: {
site: {
name: name,
title: name,
description: name * 2,
design_id: create(:design).id,
licencia_id: Licencia.first.id,
deploys_attributes: {
'0' => {
type: 'DeployLocal'
}
}
}
}
site = Site.find_by_name(name)
put site_url(site), headers: @authorization, params: {
site: { licencia_id: Licencia.all.second.id }
}
site.reload
I18n.available_locales.each do |locale|
Mobility.with_locale(locale) do
assert site.posts(lang: locale).find_by(title: site.licencia.name)
end
end
site.destroy
2019-08-09 19:49:25 +00:00
end
2019-07-12 23:40:44 +00:00
end