mirror of
https://0xacab.org/sutty/sutty
synced 2024-11-25 00:46:22 +00:00
132 lines
3.2 KiB
Ruby
132 lines
3.2 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
require 'test_helper'
|
|
|
|
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
|
|
design = create :design
|
|
|
|
post sites_url, headers: @authorization, params: {
|
|
site: {
|
|
name: name,
|
|
title: name,
|
|
description: name * 2,
|
|
design_id: design.id,
|
|
licencia_id: create(:licencia).id,
|
|
deploys_attributes: {
|
|
'0' => {
|
|
type: 'DeployLocal'
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
site = Site.find_by_name(name)
|
|
|
|
assert site
|
|
assert_equal @usuarie.email, site.roles.first.usuarie.email
|
|
assert_equal 'usuarie', site.roles.first.rol
|
|
|
|
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.create', name: name),
|
|
site.repository.rugged.head.target.message
|
|
|
|
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'
|
|
}
|
|
}
|
|
}
|
|
}
|
|
end
|
|
end
|
|
|
|
test 'se pueden encolar' do
|
|
Sidekiq::Testing.fake!
|
|
|
|
post site_enqueue_url(@site), headers: @authorization
|
|
|
|
assert DeployWorker.jobs.count.positive?
|
|
assert @site.reload.enqueued?
|
|
|
|
Sidekiq::Testing.inline!
|
|
end
|
|
|
|
test 'se pueden actualizar' do
|
|
name = SecureRandom.hex
|
|
design = create :design
|
|
|
|
put site_url(@site), headers: @authorization, params: {
|
|
site: {
|
|
name: name,
|
|
title: name,
|
|
description: name * 2,
|
|
design_id: design.id,
|
|
licencia_id: create(:licencia).id,
|
|
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
|
|
end
|
|
end
|