From 3649dc6e4ee84536d209779af1bdf3fb1ca2232f Mon Sep 17 00:00:00 2001 From: f Date: Mon, 9 Oct 2023 14:19:47 -0300 Subject: [PATCH] test: testear validaciones --- test/models/metadata_file_test.rb | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/test/models/metadata_file_test.rb b/test/models/metadata_file_test.rb index 8d8b6806..09c2e74c 100644 --- a/test/models/metadata_file_test.rb +++ b/test/models/metadata_file_test.rb @@ -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