5
0
Fork 0
mirror of https://0xacab.org/sutty/sutty synced 2024-11-24 04:26:23 +00:00

test: testear validaciones
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful

This commit is contained in:
f 2023-10-09 14:19:47 -03:00
parent 036f64f958
commit 3649dc6e4e
No known key found for this signature in database

View file

@ -11,6 +11,10 @@ class MetadataFileTest < ActiveSupport::TestCase
@metadata = MetadataFile.new(site: @site, document: @document, name: @name, type: 'file', layout: @layout)
end
teardown do
@site&.destroy
end
def random_value
{
'path' => "public/#{SecureRandom.base36(28)}/#{SecureRandom.hex}.pdf",
@ -103,8 +107,6 @@ class MetadataFileTest < ActiveSupport::TestCase
assert_instance_of String, @metadata.value['path']
assert_instance_of ActiveStorage::Attachment, @metadata.static_file
assert_not @metadata.empty?
ensure
@site.destroy
end
test 'se puede volver a encontrar un archivo subido' do
@ -124,8 +126,6 @@ class MetadataFileTest < ActiveSupport::TestCase
assert_instance_of String, @metadata.value['path']
assert_instance_of ActiveStorage::Attachment, @metadata.static_file
assert_not @metadata.empty?
ensure
@site.destroy
end
test 'si el archivo esta en el repositorio lo podemos asociar al sitio' do
@ -144,7 +144,24 @@ class MetadataFileTest < ActiveSupport::TestCase
@metadata.save
assert_instance_of ActiveStorage::Attachment, @metadata.static_file
ensure
@site.destroy
end
test 'no se pueden subir archivos si el sitio no existe' do
assert_not @metadata.valid?
assert @metadata.errors.include?(I18n.t('metadata.file.site_invalid'))
end
test 'si es obligatorio hay que asignarle un archivo' do
@site.design.save
@site.design_id = @site.design.id
@site.save
@metadata.required = true
@metadata.value = random_value
@metadata.value.delete 'path'
assert @metadata.empty?
assert_not @metadata.valid?
assert @metadata.errors.include?(I18n.t('metadata.file.path_required'))
end
end