mirror of
https://0xacab.org/sutty/sutty
synced 2025-03-19 05:58:19 +00:00
wip: pruebas de #1142
This commit is contained in:
parent
f733716ff9
commit
92cd59b781
4 changed files with 76 additions and 48 deletions
|
@ -23,7 +23,11 @@ class Post
|
||||||
# TODO: Reemplazar cuando leamos el contenido del Document
|
# TODO: Reemplazar cuando leamos el contenido del Document
|
||||||
# a demanda?
|
# a demanda?
|
||||||
def find_layout(path)
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -106,7 +110,7 @@ class Post
|
||||||
|
|
||||||
# Devuelve una llave para poder guardar el post en una cache
|
# Devuelve una llave para poder guardar el post en una cache
|
||||||
def cache_key
|
def cache_key
|
||||||
'posts/' + uuid.value
|
"posts/#{uuid.value}"
|
||||||
end
|
end
|
||||||
|
|
||||||
def cache_version
|
def cache_version
|
||||||
|
@ -116,7 +120,7 @@ class Post
|
||||||
# Agregar el timestamp para saber si cambió, siguiendo el módulo
|
# Agregar el timestamp para saber si cambió, siguiendo el módulo
|
||||||
# ActiveRecord::Integration
|
# ActiveRecord::Integration
|
||||||
def cache_key_with_version
|
def cache_key_with_version
|
||||||
cache_key + '-' + cache_version
|
"#{cache_key}-#{cache_version}"
|
||||||
end
|
end
|
||||||
|
|
||||||
# TODO: Convertir a UUID?
|
# TODO: Convertir a UUID?
|
||||||
|
|
|
@ -83,46 +83,53 @@
|
||||||
|
|
||||||
TODO: Verificar qué pasa cuando se gestiona el sitio en
|
TODO: Verificar qué pasa cuando se gestiona el sitio en
|
||||||
distintos idiomas a la vez
|
distintos idiomas a la vez
|
||||||
- cache_if @usuarie, post do
|
- begin
|
||||||
- checkbox_id = "checkbox-#{post.uuid.value}"
|
- cache_if @usuarie, post do
|
||||||
%tr{ id: post.uuid.value, data: { target: 'reorder.row' } }
|
- checkbox_id = "checkbox-#{post.uuid.value}"
|
||||||
%td
|
%tr{ id: post.uuid.value, data: { target: 'reorder.row' } }
|
||||||
.custom-control.custom-checkbox
|
%td
|
||||||
%input.custom-control-input{ id: checkbox_id, type: 'checkbox', autocomplete: 'off', data: { action: 'reorder#select' } }
|
.custom-control.custom-checkbox
|
||||||
%label.custom-control-label{ for: checkbox_id }
|
%input.custom-control-input{ id: checkbox_id, type: 'checkbox', autocomplete: 'off', data: { action: 'reorder#select' } }
|
||||||
%span.sr-only= t('posts.reorder.select')
|
%label.custom-control-label{ for: checkbox_id }
|
||||||
-# Orden más alto es mayor prioridad
|
%span.sr-only= t('posts.reorder.select')
|
||||||
= hidden_field 'post[reorder]', post.uuid.value,
|
-# Orden más alto es mayor prioridad
|
||||||
value: @posts.length - i,
|
= hidden_field 'post[reorder]', post.uuid.value,
|
||||||
data: { reorder: true }
|
value: @posts.length - i,
|
||||||
%td.w-100{ class: dir }
|
data: { reorder: true }
|
||||||
= link_to site_post_path(@site, post.id) do
|
%td.w-100{ class: dir }
|
||||||
%span{ lang: post.lang.value, dir: dir }= post.title.value
|
= link_to site_post_path(@site, post.id) do
|
||||||
- if post.attributes.include? :draft
|
%span{ lang: post.lang.value, dir: dir }= post.title.value
|
||||||
- if post.draft.value
|
- if post.attributes.include? :draft
|
||||||
%span.badge.badge-primary
|
- if post.draft.value
|
||||||
= post_label_t(:draft, post: post)
|
%span.badge.badge-primary
|
||||||
- if post.attributes.include? :categories
|
= post_label_t(:draft, post: post)
|
||||||
- unless post.categories.value.empty?
|
- if post.attributes.include? :categories
|
||||||
%br
|
- unless post.categories.value.empty?
|
||||||
%small
|
%br
|
||||||
- (post.categories.respond_to?(:belongs_to) ? post.categories.belongs_to : post.categories.value).each do |c|
|
%small
|
||||||
= link_to site_posts_path(@site, category: (c.respond_to?(:uuid) ? c.uuid.value : c)) do
|
- (post.categories.respond_to?(:belongs_to) ? post.categories.belongs_to : post.categories.value).each do |c|
|
||||||
%span{ lang: post.lang.value, dir: dir }= (c.respond_to?(:title) ? c.title.value : c)
|
= link_to site_posts_path(@site, category: (c.respond_to?(:uuid) ? c.uuid.value : c)) do
|
||||||
|
%span{ lang: post.lang.value, dir: dir }= (c.respond_to?(:title) ? c.title.value : c)
|
||||||
|
|
||||||
%td
|
%td
|
||||||
= post.date.value.strftime('%F')
|
= post.date.value.strftime('%F')
|
||||||
%br/
|
%br/
|
||||||
- if post.attribute? :order
|
- if post.attribute? :order
|
||||||
= post.order.value
|
= post.order.value
|
||||||
%td
|
%td
|
||||||
- if @usuarie || policy(post).edit?
|
- if @usuarie || policy(post).edit?
|
||||||
= link_to t('posts.edit'),
|
= link_to t('posts.edit'),
|
||||||
edit_site_post_path(@site, post.id),
|
edit_site_post_path(@site, post.id),
|
||||||
class: 'btn btn-block'
|
class: 'btn btn-block'
|
||||||
- if @usuarie || policy(post).destroy?
|
- if @usuarie || policy(post).destroy?
|
||||||
= link_to t('posts.destroy'),
|
= link_to t('posts.destroy'),
|
||||||
site_post_path(@site, post.id),
|
site_post_path(@site, post.id),
|
||||||
class: 'btn btn-block',
|
class: 'btn btn-block',
|
||||||
method: :delete,
|
method: :delete,
|
||||||
data: { confirm: t('posts.confirm_destroy') }
|
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 })
|
||||||
|
|
|
@ -50,6 +50,15 @@ Rails.application.configure do
|
||||||
config.action_mailer.default_url_options = { host: 'localhost',
|
config.action_mailer.default_url_options = { host: 'localhost',
|
||||||
port: 3000 }
|
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.
|
# Print deprecation notices to the stderr.
|
||||||
config.active_support.deprecation = :stderr
|
config.active_support.deprecation = :stderr
|
||||||
|
|
||||||
|
|
|
@ -150,7 +150,7 @@ class PostsControllerTest < ActionDispatch::IntegrationTest
|
||||||
end
|
end
|
||||||
|
|
||||||
posts = @site.posts(**lang)
|
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),
|
post site_posts_reorder_url(@site),
|
||||||
headers: @authorization,
|
headers: @authorization,
|
||||||
|
@ -159,10 +159,18 @@ class PostsControllerTest < ActionDispatch::IntegrationTest
|
||||||
@site = Site.find @site.id
|
@site = Site.find @site.id
|
||||||
|
|
||||||
assert_equal reorder,
|
assert_equal reorder,
|
||||||
Hash[@site.posts(**lang).map do |p|
|
@site.posts(**lang).map do |p|
|
||||||
[p.uuid.value, p.order.value]
|
[p.uuid.value, p.order.value]
|
||||||
end]
|
end.to_h
|
||||||
assert_equal I18n.t('post_service.reorder'),
|
assert_equal I18n.t('post_service.reorder'),
|
||||||
@site.repository.rugged.head.target.message
|
@site.repository.rugged.head.target.message
|
||||||
end
|
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
|
end
|
||||||
|
|
Loading…
Reference in a new issue