5
0
Fork 0
mirror of https://0xacab.org/sutty/sutty synced 2024-11-14 07:11:41 +00:00

implementar Post.destroy

This commit is contained in:
f 2019-05-30 12:52:12 -03:00
parent 322df19d41
commit e9a7625010
No known key found for this signature in database
GPG key ID: 2AE5A13E321F953D
3 changed files with 28 additions and 1 deletions

View file

@ -68,6 +68,8 @@ Metrics/BlockLength:
# Configuration parameters: CountComments.
Metrics/ClassLength:
Max: 379
Exclude:
- 'app/models/post.rb'
# Offense count: 6
Metrics/CyclomaticComplexity:

View file

@ -17,7 +17,7 @@ require 'jekyll/utils'
class Post
attr_accessor :content, :front_matter
attr_reader :post, :site, :errors, :old_post, :lang, :template,
:template_fields
:template_fields, :collection
REJECT_FROM_DATA = %w[excerpt].freeze
# datos que no tienen que terminar en el front matter
@ -369,6 +369,18 @@ class Post
@template ||= template_from_layout
end
# Eliminar el artículo del repositorio y de la lista de artículos del
# sitio
def destroy
FileUtils.rm_f path
site.posts_for(collection).delete_if do |post|
post.path == path
end
true
end
private
# Completa el front_matter a partir de las variables de otro post que

View file

@ -28,4 +28,17 @@ class PostTest < ActiveSupport::TestCase
test 'Es obvio que un post recién cargado es válido' do
assert @post.valid?
end
test 'El post se puede borrar' do
path = @post.path
assert @post.destroy
assert_not File.exist?(path)
post = @site.posts_for(@post.collection).find do |p|
p.path == @post.path
end
assert_not post
end
end