From faec2b20044feac9913eac5d965b6ce26768fb39 Mon Sep 17 00:00:00 2001 From: f Date: Fri, 6 Oct 2023 11:14:24 -0300 Subject: [PATCH] fix: arreglar tests ahora no es necesario generar todo un sitio para testear atributos --- test/models/metadata_boolean_test.rb | 72 +++++++++++++--------------- 1 file changed, 32 insertions(+), 40 deletions(-) diff --git a/test/models/metadata_boolean_test.rb b/test/models/metadata_boolean_test.rb index 05a4dd50..9f97d757 100644 --- a/test/models/metadata_boolean_test.rb +++ b/test/models/metadata_boolean_test.rb @@ -3,72 +3,64 @@ require 'test_helper' class MetadataBooleanTest < ActiveSupport::TestCase + setup do + @site = build(:site) + @document = build(:document, site: @site.jekyll) + @name = SecureRandom.hex + @layout = build(:layout, site: @site) + @metadata = MetadataBoolean.new(site: @site, document: @document, name: @name, type: 'boolean', layout: @layout) + end + test 'son false por defecto' do - site = create :site - post = site.posts.build + assert_equal false, @metadata.default_value + end - assert_equal false, post.draft.value + test 'pueden tener un valor por defecto desde el layout' do + [true, false].each do |default| + @layout = build(:layout, site: @site, metadata: { @name => { 'default' => { I18n.locale.to_s => default } } }) + @metadata = MetadataBoolean.new(site: @site, document: @document, name: @name, type: 'boolean', layout: @layout) - site.destroy + assert_equal default, @metadata.default_value + end end test 'pueden ser 0' do - site = create :site - post = site.posts.build + @metadata.value = '0' - post.draft.value = '0' + assert_equal false, @metadata.value - assert_equal false, post.draft.value + @metadata.save - post.save - - assert_equal false, post.draft.value - - site.destroy + assert_equal false, @metadata.value end test 'pueden ser 1' do - site = create :site - post = site.posts.build + @metadata.value = '1' - post.draft.value = '1' + assert_equal true, @metadata.value - assert_equal true, post.draft.value + @metadata.save - post.save - - assert_equal true, post.draft.value - - site.destroy + assert_equal true, @metadata.value end test 'pueden ser false' do - site = create :site - post = site.posts.build + @metadata.value = false - post.draft.value = false + assert_equal false, @metadata.value - assert_equal false, post.draft.value + @metadata.save - post.save - - assert_equal false, post.draft.value - - site.destroy + assert_equal false, @metadata.value end test 'pueden ser true' do - site = create :site - post = site.posts.build + @metadata.value = true - post.draft.value = true + assert_equal true, @metadata.value - assert_equal true, post.draft.value + @metadata.save - post.save - - assert_equal true, post.draft.value - - site.destroy + assert_equal true, @metadata.value end end