5
0
Fork 0
mirror of https://0xacab.org/sutty/sutty synced 2024-06-27 02:26:09 +00:00

wip: pruebas de #1142

This commit is contained in:
f 2021-04-21 14:11:11 -03:00
parent f733716ff9
commit 92cd59b781
4 changed files with 76 additions and 48 deletions

View file

@ -23,7 +23,11 @@ class Post
# TODO: Reemplazar cuando leamos el contenido del Document
# a demanda?
def find_layout(path)
IO.foreach(path).lazy.grep(/^layout: /).take(1).first&.split(' ')&.last&.tr('\'', '')&.tr('"', '')&.to_sym
IO.foreach(path).lazy.grep(/^layout: /).take(1).first&.split(' ')&.last&.tr('\'', '')&.tr('"', '')&.to_sym || :post
rescue Errno::ENOENT => e
ExceptionNotifier.notify(e)
:post
end
end
@ -106,7 +110,7 @@ class Post
# Devuelve una llave para poder guardar el post en una cache
def cache_key
'posts/' + uuid.value
"posts/#{uuid.value}"
end
def cache_version
@ -116,7 +120,7 @@ class Post
# Agregar el timestamp para saber si cambió, siguiendo el módulo
# ActiveRecord::Integration
def cache_key_with_version
cache_key + '-' + cache_version
"#{cache_key}-#{cache_version}"
end
# TODO: Convertir a UUID?

View file

@ -83,6 +83,7 @@
TODO: Verificar qué pasa cuando se gestiona el sitio en
distintos idiomas a la vez
- begin
- cache_if @usuarie, post do
- checkbox_id = "checkbox-#{post.uuid.value}"
%tr{ id: post.uuid.value, data: { target: 'reorder.row' } }
@ -126,3 +127,9 @@
class: 'btn btn-block',
method: :delete,
data: { confirm: t('posts.confirm_destroy') }
-#
Rescatar cualquier error en un post, notificarlo e
ignorar su renderización.
- rescue ActionView::Template::Error => e
- binding.pry
- ExceptionNotifier.notify_exception(e.cause, data: { site: @site.name, post: @post.path.absolute, usuarie: current_usuarie.id })

View file

@ -50,6 +50,15 @@ Rails.application.configure do
config.action_mailer.default_url_options = { host: 'localhost',
port: 3000 }
config.middleware.use ExceptionNotification::Rack,
error_grouping: true,
email: {
email_prefix: '',
sender_address: ENV['DEFAULT_FROM'],
exception_recipients: ENV['EXCEPTION_TO'],
normalize_subject: true
}
# Print deprecation notices to the stderr.
config.active_support.deprecation = :stderr

View file

@ -150,7 +150,7 @@ class PostsControllerTest < ActionDispatch::IntegrationTest
end
posts = @site.posts(**lang)
reorder = Hash[posts.map { |p| p.uuid.value }.shuffle.each_with_index.to_a]
reorder = posts.map { |p| p.uuid.value }.shuffle.each_with_index.to_a.to_h
post site_posts_reorder_url(@site),
headers: @authorization,
@ -159,10 +159,18 @@ class PostsControllerTest < ActionDispatch::IntegrationTest
@site = Site.find @site.id
assert_equal reorder,
Hash[@site.posts(**lang).map do |p|
@site.posts(**lang).map do |p|
[p.uuid.value, p.order.value]
end]
end.to_h
assert_equal I18n.t('post_service.reorder'),
@site.repository.rugged.head.target.message
end
test 'si hay algún error se recupera' do
File.open(File.join(@site.path, '_es', "#{Date.today}-#{SecureRandom.hex}.markdown"), 'w') do |f|
f.write ''
end
get site_posts_url(@site), headers: @authorization
end
end