mirror of
https://0xacab.org/sutty/sutty
synced 2024-11-24 08:36:21 +00:00
test: testear validaciones
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
This commit is contained in:
parent
036f64f958
commit
3649dc6e4e
1 changed files with 23 additions and 6 deletions
|
@ -11,6 +11,10 @@ class MetadataFileTest < ActiveSupport::TestCase
|
||||||
@metadata = MetadataFile.new(site: @site, document: @document, name: @name, type: 'file', layout: @layout)
|
@metadata = MetadataFile.new(site: @site, document: @document, name: @name, type: 'file', layout: @layout)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
teardown do
|
||||||
|
@site&.destroy
|
||||||
|
end
|
||||||
|
|
||||||
def random_value
|
def random_value
|
||||||
{
|
{
|
||||||
'path' => "public/#{SecureRandom.base36(28)}/#{SecureRandom.hex}.pdf",
|
'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 String, @metadata.value['path']
|
||||||
assert_instance_of ActiveStorage::Attachment, @metadata.static_file
|
assert_instance_of ActiveStorage::Attachment, @metadata.static_file
|
||||||
assert_not @metadata.empty?
|
assert_not @metadata.empty?
|
||||||
ensure
|
|
||||||
@site.destroy
|
|
||||||
end
|
end
|
||||||
|
|
||||||
test 'se puede volver a encontrar un archivo subido' do
|
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 String, @metadata.value['path']
|
||||||
assert_instance_of ActiveStorage::Attachment, @metadata.static_file
|
assert_instance_of ActiveStorage::Attachment, @metadata.static_file
|
||||||
assert_not @metadata.empty?
|
assert_not @metadata.empty?
|
||||||
ensure
|
|
||||||
@site.destroy
|
|
||||||
end
|
end
|
||||||
|
|
||||||
test 'si el archivo esta en el repositorio lo podemos asociar al sitio' do
|
test 'si el archivo esta en el repositorio lo podemos asociar al sitio' do
|
||||||
|
@ -144,7 +144,24 @@ class MetadataFileTest < ActiveSupport::TestCase
|
||||||
@metadata.save
|
@metadata.save
|
||||||
|
|
||||||
assert_instance_of ActiveStorage::Attachment, @metadata.static_file
|
assert_instance_of ActiveStorage::Attachment, @metadata.static_file
|
||||||
ensure
|
end
|
||||||
@site.destroy
|
|
||||||
|
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
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue