From 58a6f1aa9c2f2d01ffca3aa2abe6b676963a2766 Mon Sep 17 00:00:00 2001 From: f Date: Tue, 16 Jun 2020 19:20:22 -0300 Subject: [PATCH] por fin arreglar los metadatos booleanos! --- app/models/metadata_template.rb | 2 +- test/models/metadata_boolean_test.rb | 74 ++++++++++++++++++++++++++++ 2 files changed, 75 insertions(+), 1 deletion(-) create mode 100644 test/models/metadata_boolean_test.rb diff --git a/app/models/metadata_template.rb b/app/models/metadata_template.rb index d53a0459..e6c0763a 100644 --- a/app/models/metadata_template.rb +++ b/app/models/metadata_template.rb @@ -82,7 +82,7 @@ MetadataTemplate = Struct.new(:site, :document, :name, :label, :type, # # Ver ActionText::ContentHelper#sanitize_action_text_content def sanitize(string) - return unless string + return if string.nil? return string unless string.is_a? String sanitizer.sanitize(string, diff --git a/test/models/metadata_boolean_test.rb b/test/models/metadata_boolean_test.rb new file mode 100644 index 00000000..05a4dd50 --- /dev/null +++ b/test/models/metadata_boolean_test.rb @@ -0,0 +1,74 @@ +# frozen_string_literal: true + +require 'test_helper' + +class MetadataBooleanTest < ActiveSupport::TestCase + test 'son false por defecto' do + site = create :site + post = site.posts.build + + assert_equal false, post.draft.value + + site.destroy + end + + test 'pueden ser 0' do + site = create :site + post = site.posts.build + + post.draft.value = '0' + + assert_equal false, post.draft.value + + post.save + + assert_equal false, post.draft.value + + site.destroy + end + + test 'pueden ser 1' do + site = create :site + post = site.posts.build + + post.draft.value = '1' + + assert_equal true, post.draft.value + + post.save + + assert_equal true, post.draft.value + + site.destroy + end + + test 'pueden ser false' do + site = create :site + post = site.posts.build + + post.draft.value = false + + assert_equal false, post.draft.value + + post.save + + assert_equal false, post.draft.value + + site.destroy + end + + test 'pueden ser true' do + site = create :site + post = site.posts.build + + post.draft.value = true + + assert_equal true, post.draft.value + + post.save + + assert_equal true, post.draft.value + + site.destroy + end +end