2020-06-16 22:20:22 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'test_helper'
|
|
|
|
|
|
|
|
class MetadataBooleanTest < ActiveSupport::TestCase
|
2023-10-06 14:14:24 +00:00
|
|
|
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
|
|
|
|
|
2023-10-06 14:18:38 +00:00
|
|
|
def random_value
|
|
|
|
[true, false].sample
|
|
|
|
end
|
|
|
|
|
|
|
|
test 'se guarda en el encabezado' do
|
|
|
|
assert @metadata.front_matter?
|
|
|
|
end
|
|
|
|
|
|
|
|
test 'no se puede indexar' do
|
|
|
|
assert_not @metadata.indexable?
|
|
|
|
end
|
|
|
|
|
|
|
|
test 'nunca es privado' do
|
|
|
|
assert_not @metadata.private?
|
|
|
|
end
|
|
|
|
|
2020-06-16 22:20:22 +00:00
|
|
|
test 'son false por defecto' do
|
2023-10-06 14:14:24 +00:00
|
|
|
assert_equal false, @metadata.default_value
|
|
|
|
end
|
2020-06-16 22:20:22 +00:00
|
|
|
|
2023-10-06 14:18:38 +00:00
|
|
|
test 'aunque sean false nunca son considerados vacíos' do
|
|
|
|
assert_not @metadata.empty?
|
|
|
|
end
|
|
|
|
|
2023-10-06 14:14:24 +00:00
|
|
|
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)
|
2020-06-16 22:20:22 +00:00
|
|
|
|
2023-10-06 14:14:24 +00:00
|
|
|
assert_equal default, @metadata.default_value
|
|
|
|
end
|
2020-06-16 22:20:22 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
test 'pueden ser 0' do
|
2023-10-06 14:14:24 +00:00
|
|
|
@metadata.value = '0'
|
2020-06-16 22:20:22 +00:00
|
|
|
|
2023-10-06 14:14:24 +00:00
|
|
|
assert_equal false, @metadata.value
|
2020-06-16 22:20:22 +00:00
|
|
|
|
2023-10-06 14:14:24 +00:00
|
|
|
@metadata.save
|
2020-06-16 22:20:22 +00:00
|
|
|
|
2023-10-06 14:14:24 +00:00
|
|
|
assert_equal false, @metadata.value
|
2020-06-16 22:20:22 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
test 'pueden ser 1' do
|
2023-10-06 14:14:24 +00:00
|
|
|
@metadata.value = '1'
|
2020-06-16 22:20:22 +00:00
|
|
|
|
2023-10-06 14:14:24 +00:00
|
|
|
assert_equal true, @metadata.value
|
2020-06-16 22:20:22 +00:00
|
|
|
|
2023-10-06 14:14:24 +00:00
|
|
|
@metadata.save
|
2020-06-16 22:20:22 +00:00
|
|
|
|
2023-10-06 14:14:24 +00:00
|
|
|
assert_equal true, @metadata.value
|
2020-06-16 22:20:22 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
test 'pueden ser false' do
|
2023-10-06 14:14:24 +00:00
|
|
|
@metadata.value = false
|
2020-06-16 22:20:22 +00:00
|
|
|
|
2023-10-06 14:14:24 +00:00
|
|
|
assert_equal false, @metadata.value
|
2020-06-16 22:20:22 +00:00
|
|
|
|
2023-10-06 14:14:24 +00:00
|
|
|
@metadata.save
|
2020-06-16 22:20:22 +00:00
|
|
|
|
2023-10-06 14:14:24 +00:00
|
|
|
assert_equal false, @metadata.value
|
2020-06-16 22:20:22 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
test 'pueden ser true' do
|
2023-10-06 14:14:24 +00:00
|
|
|
@metadata.value = true
|
2020-06-16 22:20:22 +00:00
|
|
|
|
2023-10-06 14:14:24 +00:00
|
|
|
assert_equal true, @metadata.value
|
2020-06-16 22:20:22 +00:00
|
|
|
|
2023-10-06 14:14:24 +00:00
|
|
|
@metadata.save
|
2020-06-16 22:20:22 +00:00
|
|
|
|
2023-10-06 14:14:24 +00:00
|
|
|
assert_equal true, @metadata.value
|
2020-06-16 22:20:22 +00:00
|
|
|
end
|
|
|
|
end
|