mirror of
https://0xacab.org/sutty/sutty
synced 2024-11-22 12:46:22 +00:00
implementar Post.destroy
This commit is contained in:
parent
322df19d41
commit
e9a7625010
3 changed files with 28 additions and 1 deletions
|
@ -68,6 +68,8 @@ Metrics/BlockLength:
|
|||
# Configuration parameters: CountComments.
|
||||
Metrics/ClassLength:
|
||||
Max: 379
|
||||
Exclude:
|
||||
- 'app/models/post.rb'
|
||||
|
||||
# Offense count: 6
|
||||
Metrics/CyclomaticComplexity:
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue