5
0
Fork 0
mirror of https://0xacab.org/sutty/sutty synced 2024-11-26 08:06:23 +00:00

testear que lo que diga sutty termine en jekyll

agregué el método `Jekyll::Document#reset` para que no queden datos de
la versión anterior, porque jekyll mergea la información.

además, para evitar bugs en las plantillas, se mantienen los arrays
vacíos en el front matter para que se puedan seguir usando métodos de
arrays, como each y sort.
This commit is contained in:
f 2021-05-14 11:15:32 -03:00
parent fc6e7da5d6
commit 3dacdf82bf
5 changed files with 72 additions and 8 deletions

View file

@ -230,12 +230,14 @@ class Post
template = public_send attr template = public_send attr
unless template.front_matter? unless template.front_matter?
body += "\n\n" body += "\n\n" if body.present?
body += template.value body += template.value
next next
end end
next if template.empty? # Queremos mantener los Array en el resultado final para que
# siempre respondan a {% for %} en Liquid.
next if template.empty? && !template.value.is_a?(Array)
[attr.to_s, template.value] [attr.to_s, template.value]
end.compact.to_h end.compact.to_h
@ -285,6 +287,7 @@ class Post
return false unless write return false unless write
# Vuelve a leer el post para tomar los cambios # Vuelve a leer el post para tomar los cambios
document.reset
read read
written? written?

View file

@ -52,7 +52,7 @@ module Jekyll
# Solo lee los datos # Solo lee los datos
def read_data def read_data
@site.data = DataReader.new(site).read(site.config["data_dir"]) @site.data = DataReader.new(site).read(site.config['data_dir'])
end end
# Lee todos los artículos del sitio # Lee todos los artículos del sitio
@ -73,6 +73,15 @@ module Jekyll
Document.class_eval do Document.class_eval do
alias_method :read!, :read alias_method :read!, :read
def read; end def read; end
# Permitir restablecer el documento sin crear uno nuevo
def reset
@path = @extname = @has_yaml_header = @relative_path = nil
@basename_without_ext = @data = @basename = nil
@renderer = @url_placeholders = @url = nil
@to_liquid = @write_p = @excerpt_separator = @id = nil
@related_posts = @cleaned_relative_path = self.content = nil
end
end end
# Prevenir la instanciación de Time # Prevenir la instanciación de Time

View file

@ -12,6 +12,11 @@ class MetadataBelongsToTest < ActiveSupport::TestCase
assert_equal post, reply.in_reply_to.belongs_to assert_equal post, reply.in_reply_to.belongs_to
assert_includes post.posts.has_many, reply assert_includes post.posts.has_many, reply
assert post.save
assert_equal reply.document.data['in_reply_to'], post.document.data['uuid']
assert_includes post.document.data['posts'], reply.document.data['uuid']
end end
test 'se puede eliminar la relación' do test 'se puede eliminar la relación' do
@ -19,12 +24,17 @@ class MetadataBelongsToTest < ActiveSupport::TestCase
reply = @site.posts.create(layout: :post, title: SecureRandom.hex, in_reply_to: post.uuid.value) reply = @site.posts.create(layout: :post, title: SecureRandom.hex, in_reply_to: post.uuid.value)
reply.in_reply_to.value = '' reply.in_reply_to.value = ''
reply.save assert reply.save
assert_not_equal post, reply.in_reply_to.belongs_to assert_not_equal post, reply.in_reply_to.belongs_to
assert_equal post, reply.in_reply_to.belonged_to assert_equal post, reply.in_reply_to.belonged_to
assert_nil reply.in_reply_to.belongs_to assert_nil reply.in_reply_to.belongs_to
assert_not_includes post.posts.has_many, reply assert_not_includes post.posts.has_many, reply
assert post.save
assert_nil reply.document.data['in_reply_to']
assert_not_includes post.document.data['posts'], reply.document.data['uuid']
end end
test 'se puede cambiar la relación' do test 'se puede cambiar la relación' do
@ -33,7 +43,7 @@ class MetadataBelongsToTest < ActiveSupport::TestCase
reply = @site.posts.create(layout: :post, title: SecureRandom.hex, in_reply_to: post1.uuid.value) reply = @site.posts.create(layout: :post, title: SecureRandom.hex, in_reply_to: post1.uuid.value)
reply.in_reply_to.value = post2.uuid.value reply.in_reply_to.value = post2.uuid.value
reply.save assert reply.save
assert_not_equal post1, reply.in_reply_to.belongs_to assert_not_equal post1, reply.in_reply_to.belongs_to
assert_equal post1, reply.in_reply_to.belonged_to assert_equal post1, reply.in_reply_to.belonged_to
@ -41,5 +51,12 @@ class MetadataBelongsToTest < ActiveSupport::TestCase
assert_equal post2, reply.in_reply_to.belongs_to assert_equal post2, reply.in_reply_to.belongs_to
assert_includes post2.posts.has_many, reply assert_includes post2.posts.has_many, reply
assert post1.save
assert post2.save
assert_equal post2.document.data['uuid'], reply.document.data['in_reply_to']
assert_includes post2.document.data['posts'], reply.document.data['uuid']
assert_not_includes post1.document.data['posts'], reply.document.data['uuid']
end end
end end

View file

@ -15,6 +15,11 @@ class MetadataHasAndBelongsManyTest < ActiveSupport::TestCase
assert_includes author.posts.has_many, post assert_includes author.posts.has_many, post
assert_includes post.authors.has_many, author assert_includes post.authors.has_many, author
assert author.save
assert_includes author.document.data['posts'], post.document.data['uuid']
assert_includes post.document.data['authors'], author.document.data['uuid']
end end
test 'se puede eliminar la relación' do test 'se puede eliminar la relación' do
@ -25,7 +30,6 @@ class MetadataHasAndBelongsManyTest < ActiveSupport::TestCase
assert_includes author.posts.value, post.uuid.value assert_includes author.posts.value, post.uuid.value
post.authors.value = [] post.authors.value = []
ENV['HOLA'] = 'hola'
assert post.save assert post.save
assert_not_includes author.posts.has_many, post assert_not_includes author.posts.has_many, post
@ -33,6 +37,11 @@ class MetadataHasAndBelongsManyTest < ActiveSupport::TestCase
assert_includes author.posts.had_many, post assert_includes author.posts.had_many, post
assert_includes post.authors.had_many, author assert_includes post.authors.had_many, author
assert author.save
assert_not_includes author.document.data['posts'], post.document.data['uuid']
assert_not_includes post.document.data['authors'], author.document.data['uuid']
end end
test 'se puede cambiar la relación' do test 'se puede cambiar la relación' do
@ -54,5 +63,14 @@ class MetadataHasAndBelongsManyTest < ActiveSupport::TestCase
assert_includes author.posts.has_many, post2 assert_includes author.posts.has_many, post2
assert_includes post2.authors.has_many, author assert_includes post2.authors.has_many, author
assert post1.save
assert post2.save
assert_not_includes author.document.data['posts'], post1.document.data['uuid']
assert_not_includes post1.document.data['authors'], author.document.data['uuid']
assert_includes author.document.data['posts'], post2.document.data['uuid']
assert_includes post2.document.data['authors'], author.document.data['uuid']
end end
end end

View file

@ -12,6 +12,11 @@ class MetadataHasManyTest < ActiveSupport::TestCase
assert_equal post, reply.in_reply_to.belongs_to assert_equal post, reply.in_reply_to.belongs_to
assert_includes post.posts.has_many, reply assert_includes post.posts.has_many, reply
assert reply.save
assert_equal reply.document.data['in_reply_to'], post.document.data['uuid']
assert_includes post.document.data['posts'], reply.document.data['uuid']
end end
test 'se puede eliminar la relación' do test 'se puede eliminar la relación' do
@ -19,12 +24,17 @@ class MetadataHasManyTest < ActiveSupport::TestCase
post = @site.posts.create(layout: :post, title: SecureRandom.hex, posts: [reply.uuid.value]) post = @site.posts.create(layout: :post, title: SecureRandom.hex, posts: [reply.uuid.value])
post.posts.value = [] post.posts.value = []
post.save assert post.save
assert_not_equal post, reply.in_reply_to.belongs_to assert_not_equal post, reply.in_reply_to.belongs_to
assert_equal post, reply.in_reply_to.belonged_to assert_equal post, reply.in_reply_to.belonged_to
assert_nil reply.in_reply_to.belongs_to assert_nil reply.in_reply_to.belongs_to
assert_not_includes post.posts.has_many, reply assert_not_includes post.posts.has_many, reply
assert reply.save
assert_nil reply.document.data['in_reply_to']
assert_not_includes post.document.data['posts'], reply.document.data['uuid']
end end
test 'se puede cambiar la relación' do test 'se puede cambiar la relación' do
@ -33,7 +43,7 @@ class MetadataHasManyTest < ActiveSupport::TestCase
post2 = @site.posts.create(layout: :post, title: SecureRandom.hex) post2 = @site.posts.create(layout: :post, title: SecureRandom.hex)
reply.in_reply_to.value = post2.uuid.value reply.in_reply_to.value = post2.uuid.value
reply.save assert reply.save
assert_not_equal post1, reply.in_reply_to.belongs_to assert_not_equal post1, reply.in_reply_to.belongs_to
assert_equal post1, reply.in_reply_to.belonged_to assert_equal post1, reply.in_reply_to.belonged_to
@ -41,5 +51,12 @@ class MetadataHasManyTest < ActiveSupport::TestCase
assert_equal post2, reply.in_reply_to.belongs_to assert_equal post2, reply.in_reply_to.belongs_to
assert_includes post2.posts.has_many, reply assert_includes post2.posts.has_many, reply
assert post1.save
assert post2.save
assert_equal post2.document.data['uuid'], reply.document.data['in_reply_to']
assert_includes post2.document.data['posts'], reply.document.data['uuid']
assert_not_includes post1.document.data['posts'], reply.document.data['uuid']
end end
end end