pg_rails 7.2.3 → 7.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (85) hide show
  1. checksums.yaml +4 -4
  2. data/pg_associable/app/helpers/pg_associable/form_builder_methods.rb +9 -2
  3. data/pg_associable/app/helpers/pg_associable/helpers.rb +4 -5
  4. data/pg_associable/app/javascript/modal_controller.js +80 -6
  5. data/pg_associable/spec/system/associable_spec.rb +30 -7
  6. data/pg_engine/app/assets/stylesheets/pg_rails_b5.scss +5 -0
  7. data/pg_engine/app/components/actions_component.rb +14 -0
  8. data/pg_engine/app/components/asociable_modal_component.html.slim +6 -0
  9. data/pg_engine/app/components/asociable_modal_component.rb +7 -0
  10. data/pg_engine/app/components/date_selector_component.rb +2 -2
  11. data/pg_engine/app/components/modal_component.html.slim +5 -0
  12. data/pg_engine/app/components/modal_component.rb +11 -0
  13. data/pg_engine/app/components/modal_content_component.rb +29 -0
  14. data/pg_engine/app/components/search_bar_component.html.slim +1 -1
  15. data/pg_engine/app/controllers/admin/accounts_controller.rb +1 -1
  16. data/pg_engine/app/controllers/admin/email_logs_controller.rb +1 -1
  17. data/pg_engine/app/controllers/admin/emails_controller.rb +4 -21
  18. data/pg_engine/app/controllers/admin/user_accounts_controller.rb +1 -1
  19. data/pg_engine/app/controllers/admin/users_controller.rb +1 -1
  20. data/pg_engine/app/controllers/concerns/pg_engine/resource.rb +288 -133
  21. data/pg_engine/app/controllers/pg_engine/base_controller.rb +5 -0
  22. data/pg_engine/app/controllers/public/mensaje_contactos_controller.rb +1 -1
  23. data/pg_engine/app/decorators/pg_engine/base_record_decorator.rb +36 -10
  24. data/pg_engine/app/helpers/pg_engine/flash_helper.rb +6 -2
  25. data/pg_engine/app/helpers/pg_engine/form_helper.rb +15 -2
  26. data/pg_engine/app/helpers/pg_engine/frame_helper.rb +52 -0
  27. data/pg_engine/app/lib/pg_engine/bootstrap5_breadcrumbs_builder.rb +22 -0
  28. data/pg_engine/app/lib/pg_engine/filtros_builder.rb +3 -2
  29. data/pg_engine/app/models/current.rb +1 -1
  30. data/pg_engine/app/models/email.rb +2 -0
  31. data/pg_engine/app/models/pg_engine/base_record.rb +13 -0
  32. data/pg_engine/app/views/admin/accounts/_form.html.slim +1 -4
  33. data/pg_engine/app/views/admin/email_logs/_form.html.slim +2 -5
  34. data/pg_engine/app/views/admin/emails/_form.html.slim +13 -13
  35. data/pg_engine/app/views/admin/emails/_send.html.slim +0 -1
  36. data/pg_engine/app/views/admin/emails/show.html.slim +19 -20
  37. data/pg_engine/app/views/admin/eventos/new.html.slim +0 -2
  38. data/pg_engine/app/views/admin/user_accounts/_form.html.slim +1 -4
  39. data/pg_engine/app/views/admin/users/_form.html.slim +1 -4
  40. data/pg_engine/app/views/pg_engine/base/edit.html.slim +1 -2
  41. data/pg_engine/app/views/pg_engine/base/index.html.slim +6 -3
  42. data/pg_engine/app/views/pg_engine/base/new.html.slim +1 -2
  43. data/pg_engine/app/views/public/mensaje_contactos/new.html.slim +2 -5
  44. data/pg_engine/config/initializers/kaminari.rb +3 -0
  45. data/pg_engine/config/initializers/ransack_memory.rb +13 -2
  46. data/pg_engine/config/locales/es.yml +1 -1
  47. data/pg_engine/lib/pg_engine/utils/pg_logger.rb +10 -10
  48. data/pg_engine/spec/controllers/admin/accounts_controller_spec.rb +2 -2
  49. data/pg_engine/spec/controllers/admin/email_logs_controller_spec.rb +2 -2
  50. data/pg_engine/spec/controllers/admin/emails_controller_spec.rb +2 -2
  51. data/pg_engine/spec/controllers/admin/user_accounts_controller_spec.rb +2 -2
  52. data/pg_engine/spec/controllers/admin/users_controller_spec.rb +2 -2
  53. data/pg_engine/spec/controllers/concerns/pg_engine/resource_helper_spec.rb +0 -2
  54. data/pg_engine/spec/lib/pg_engine/form_helper_spec.rb +51 -0
  55. data/pg_engine/spec/system/breadcrumbs_spec.rb +61 -0
  56. data/pg_engine/spec/system/destroy_spec.rb +1 -1
  57. data/pg_engine/spec/system/login_spec.rb +1 -1
  58. data/pg_engine/spec/system/modal_windows_spec.rb +89 -0
  59. data/pg_engine/spec/system/send_mail_spec.rb +1 -1
  60. data/pg_layout/app/javascript/application.js +38 -0
  61. data/pg_layout/app/javascript/config/turbo_rails/index.js +4 -1
  62. data/pg_layout/app/javascript/controllers/embedded_frame_controller.js +10 -0
  63. data/pg_layout/app/javascript/controllers/index.js +2 -0
  64. data/pg_layout/app/javascript/controllers/popover_toggler_controller.js +3 -2
  65. data/pg_layout/app/javascript/controllers/tooltip_controller.js +8 -0
  66. data/pg_layout/app/javascript/elements/index.js +1 -0
  67. data/pg_layout/app/javascript/elements/pg_event.js +13 -0
  68. data/pg_layout/app/views/devise/confirmations/new.html.erb +0 -1
  69. data/pg_layout/app/views/devise/passwords/edit.html.erb +0 -2
  70. data/pg_layout/app/views/devise/passwords/new.html.erb +0 -2
  71. data/pg_layout/app/views/devise/registrations/edit.html.erb +0 -2
  72. data/pg_layout/app/views/devise/registrations/new.html.erb +0 -2
  73. data/pg_layout/app/views/devise/unlocks/new.html.erb +0 -1
  74. data/pg_layout/app/views/layouts/pg_layout/base.html.slim +45 -17
  75. data/pg_layout/app/views/layouts/pg_layout/containerized.html.slim +1 -1
  76. data/pg_rails/lib/version.rb +1 -1
  77. data/pg_rails/scss/bootstrap_overrides.scss +2 -1
  78. data/pg_rails/scss/pg_rails.scss +8 -1
  79. data/pg_scaffold/lib/generators/pg_rspec/scaffold/templates/controller_spec.rb +2 -2
  80. data/pg_scaffold/lib/generators/pg_scaffold/templates/controller.rb +2 -4
  81. data/pg_scaffold/lib/generators/pg_slim/templates/_form.html.slim +2 -5
  82. data/pg_scaffold/lib/generators/pg_slim/templates/show.html.slim +1 -1
  83. metadata +17 -4
  84. data/pg_associable/app/views/pg_engine/base/_pg_associable_modal.html.slim +0 -14
  85. data/pg_layout/app/views/pg_layout/_modal_show.html.slim +0 -14
@@ -1,7 +1,11 @@
1
1
  module PgEngine
2
2
  module FlashHelper
3
- def render_turbo_stream_flash_messages
4
- turbo_stream.prepend 'flash', partial: 'pg_layout/flash'
3
+ def render_turbo_stream_flash_messages(to: nil)
4
+ if to.present?
5
+ turbo_stream.prepend_all to, partial: 'pg_layout/flash'
6
+ else
7
+ turbo_stream.prepend 'flash', partial: 'pg_layout/flash'
8
+ end
5
9
  end
6
10
 
7
11
  def render_turbo_stream_title
@@ -2,7 +2,8 @@
2
2
 
3
3
  module PgEngine
4
4
  module FormHelper
5
- def pg_form_for(object, *args, &)
5
+ # rubocop:disable Metrics/CyclomaticComplexity
6
+ def pg_form_for(object, *args, &block_passed)
6
7
  resource = object
7
8
  if object.is_a? PgEngine::BaseRecordDecorator
8
9
  object = object.target_object
@@ -27,8 +28,20 @@ module PgEngine
27
28
  options[:html][:data][:errors] = resource.errors.details.to_json
28
29
  end
29
30
 
30
- simple_form_for(object, *(args << options), &)
31
+ if options[:render_errors].nil?
32
+ options[:render_errors] = true
33
+ end
34
+
35
+ block_with_additives = lambda do |f|
36
+ ret = ''.html_safe
37
+ ret += f.mensajes_de_error if options[:render_errors]
38
+ ret += capture(f, &block_passed)
39
+ ret
40
+ end
41
+
42
+ simple_form_for(object, *(args << options), &block_with_additives)
31
43
  end
44
+ # rubocop:enable Metrics/CyclomaticComplexity
32
45
 
33
46
  def url_change_format(url, formato)
34
47
  uri = URI.parse(url)
@@ -0,0 +1,52 @@
1
+ module PgEngine
2
+ module FrameHelper
3
+ # Will the current view rendered in a modal?
4
+ def using_modal?
5
+ controller.instance_variable_get(:@using_modal) ||
6
+ modal_targeted?
7
+ end
8
+
9
+ def using_modal2?
10
+ @using_modal || modal_targeted?
11
+ end
12
+
13
+ def in_modal?
14
+ request.headers['Modal-Opened'] == 'true'
15
+ end
16
+
17
+ def current_turbo_frame
18
+ request.headers['Turbo-Frame']
19
+ end
20
+
21
+ def turbo_frame?
22
+ current_turbo_frame.present?
23
+ end
24
+
25
+ def modal_targeted?
26
+ current_turbo_frame == 'modal_content'
27
+ end
28
+
29
+ def frame_embedded?
30
+ turbo_frame? && current_turbo_frame.include?('embedded')
31
+ end
32
+
33
+ def embed_index(object, key)
34
+ content_tag(:div, 'data-controller': 'embedded-frame') do
35
+ turbo_frame_tag "embedded--#{key}",
36
+ refresh: :morph, src: url_for([pg_namespace, object, key]) do
37
+ content_tag(:p, class: 'p text-body-secondary text-center') { 'Cargando...' }
38
+ end
39
+ end
40
+ end
41
+
42
+ def nav_bg
43
+ if frame_embedded?
44
+ 'bg-warning bg-opacity-25'
45
+ elsif using_modal?
46
+ 'bg-warning bg-opacity-50'
47
+ else
48
+ 'bg-primary-subtle'
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,22 @@
1
+ module PgEngine
2
+ class Bootstrap5BreadcrumbsBuilder < BreadcrumbsOnRails::Breadcrumbs::Builder
3
+ def render
4
+ @elements.collect do |element|
5
+ render_element(element)
6
+ end.join(@options[:separator] || '')
7
+ end
8
+
9
+ def render_element(element)
10
+ content = if element.path.nil?
11
+ compute_name(element)
12
+ else
13
+ # TODO: add aria-current="page"
14
+ @context.link_to_unless_current(
15
+ compute_name(element), compute_path(element), element.options
16
+ )
17
+ end
18
+
19
+ @context.content_tag('li', content, class: 'breadcrumb-item')
20
+ end
21
+ end
22
+ end
@@ -64,11 +64,12 @@ module PgEngine
64
64
  @filtros[campo][:scope_asociacion] = block
65
65
  end
66
66
 
67
+ # FIXME: deprecar
67
68
  def filtrar(query, parametros = nil)
68
- parametros = parametros_controller if parametros.nil?
69
+ parametros_controller if parametros.nil?
69
70
 
70
71
  # Filtro soft deleted
71
- query = query.kept if query.respond_to?(:kept) && parametros[:archived] != 'true'
72
+ query = query.kept if query.respond_to?(:kept)
72
73
 
73
74
  query
74
75
  end
@@ -1,5 +1,5 @@
1
1
  class Current < ActiveSupport::CurrentAttributes
2
- attribute :account, :user, :namespace
2
+ attribute :account, :user, :namespace, :controller
3
3
  # attribute :request_id, :user_agent, :ip_address
4
4
 
5
5
  # resets { Time.zone = nil }
@@ -36,6 +36,8 @@ class Email < ApplicationRecord
36
36
  include Hashid::Rails
37
37
  audited
38
38
 
39
+ self.default_modal = true
40
+
39
41
  after_commit do
40
42
  associated.email_updated(self) if associated.respond_to? :email_updated
41
43
  end
@@ -13,6 +13,12 @@ module PgEngine
13
13
  before_create :setear_creado_y_actualizado_por
14
14
  before_update :setear_actualizado_por
15
15
 
16
+ class << self
17
+ # This is a per class variable, all subclasses of BaseRecord inherit it
18
+ # BUT **the values are independent between all of them**
19
+ attr_accessor :default_modal
20
+ end
21
+
16
22
  scope :query, ->(param) { param.present? ? where(id: param) : all }
17
23
 
18
24
  def self.ransackable_associations(_auth_object = nil)
@@ -47,6 +53,10 @@ module PgEngine
47
53
  end
48
54
  end
49
55
 
56
+ def actions_component
57
+ ActionsComponent.new(self)
58
+ end
59
+
50
60
  # Para el dom_id (index.html)
51
61
  def to_key
52
62
  if respond_to? :hashid
@@ -58,6 +68,9 @@ module PgEngine
58
68
 
59
69
  def to_s
60
70
  %i[nombre name].each do |campo|
71
+ # Using `_in_database` for consistent breadcrumbs when editing the name
72
+ campo = :"#{campo}_in_database"
73
+
61
74
  return "#{send(campo)} ##{to_param}" if try(campo).present?
62
75
  end
63
76
  if to_param.present?
@@ -1,10 +1,7 @@
1
- / # locals: (object: nil, asociable: false)
1
+ / # locals: (object: nil)
2
2
 
3
3
  div style="max-width: 22em"
4
4
  = pg_form_for(@account || object) do |f|
5
- = f.mensajes_de_error
6
-
7
- = hidden_field_tag :asociable, true if asociable
8
5
  = f.input :plan
9
6
  = f.input :nombre
10
7
  .mt-2
@@ -1,10 +1,7 @@
1
- / # locals: (object: nil, asociable: false)
1
+ / # locals: (object: nil)
2
2
 
3
3
  div style="max-width: 22em" data-controller="pg_form"
4
- = pg_form_for(@email_log || object, asociable:) do |f|
5
- = f.mensajes_de_error
6
-
7
- = hidden_field_tag :asociable, true if asociable
4
+ = pg_form_for(@email_log || object) do |f|
8
5
  = f.pg_associable :email
9
6
  = f.input :log_id
10
7
  = f.input :event
@@ -1,17 +1,17 @@
1
- / # locals: (object: nil, asociable: false)
1
+ / # locals: (object: nil)
2
2
 
3
- div style="max-width: 22em" data-controller="pg_form"
4
- = pg_form_for(@email || object, asociable:) do |f|
5
- = f.mensajes_de_error
6
-
7
- / = hidden_field_tag :asociable, true if asociable
8
- / = f.input :from_address
9
- / = f.input :from_name
10
- / = f.input :reply_to
11
- / = f.input :to
12
- / = f.input :subject
13
- / = f.input :body_input, as: :text
14
- = f.input :status
3
+ - object ||= @email
4
+ div style="max-width: 52em" data-controller="pg_form"
5
+ = pg_form_for(object) do |f|
6
+ - if object.persisted?
7
+ = f.input :status
8
+ - else
9
+ = f.input :from_name
10
+ = f.input :from_address
11
+ = f.input :to
12
+ = f.input :subject
13
+ = f.input :reply_to
14
+ = f.input :body_input, as: :text, input_html: { rows: 5 }
15
15
 
16
16
  .mt-2
17
17
  = f.button :submit
@@ -1,7 +1,6 @@
1
1
  / # locals: (email:)
2
2
 
3
3
  = pg_form_for email do |f|
4
- = f.mensajes_de_error
5
4
  = f.input :from_name
6
5
  = f.input :from_address
7
6
  = f.input :to
@@ -5,7 +5,7 @@
5
5
  .ms-1
6
6
  = @email.edit_link
7
7
 
8
- table.table.table-borderless.table-sm.w-auto.mb-0.m-3
8
+ table.table.table-borderless.table-sm.w-auto.mb-0
9
9
  - atributos_para_mostrar.each do |att|
10
10
  tr
11
11
  th = @clase_modelo.human_attribute_name(att)
@@ -23,23 +23,22 @@ table.table.table-borderless.table-sm.w-auto.mb-0.m-3
23
23
  th = t('attributes.updated_at')
24
24
  td = @email.updated_at
25
25
 
26
- .m-4
27
- h4 Logs
28
- table.table
26
+ h4 Logs
27
+ table.table
28
+ tr
29
+ th log_id
30
+ th event
31
+ th log_level
32
+ th severity
33
+ th timestamp
34
+ th created_at
35
+ th updated_at
36
+ - @email.email_logs.order(timestamp: :desc).each do |log|
29
37
  tr
30
- th log_id
31
- th event
32
- th log_level
33
- th severity
34
- th timestamp
35
- th created_at
36
- th updated_at
37
- - @email.email_logs.order(timestamp: :desc).each do |log|
38
- tr
39
- td = log.log_id
40
- td = log.event
41
- td = log.log_level
42
- td = log.severity
43
- td = log.timestamp
44
- td = log.created_at
45
- td = log.updated_at
38
+ td = log.log_id
39
+ td = log.event
40
+ td = log.log_level
41
+ td = log.severity
42
+ td = log.timestamp
43
+ td = log.created_at
44
+ td = log.updated_at
@@ -1,6 +1,4 @@
1
1
  = pg_form_for @event, url: admin_eventos_path do |f|
2
- = f.mensajes_de_error
3
-
4
2
  = f.input :type, as: :select, collection: @notifier_types
5
3
  - if params[:plain_text]
6
4
  = link_to 'Change to rich text', url_for
@@ -1,10 +1,7 @@
1
- / # locals: (object: nil, asociable: false)
1
+ / # locals: (object: nil)
2
2
 
3
3
  div style="max-width: 22em"
4
4
  = pg_form_for(@user_account || object) do |f|
5
- = f.mensajes_de_error
6
-
7
- = hidden_field_tag :asociable, true if asociable
8
5
  = f.pg_associable :user
9
6
  = f.pg_associable :account
10
7
  = f.input :profiles
@@ -1,10 +1,7 @@
1
- / # locals: (object: nil, asociable: false)
1
+ / # locals: (object: nil)
2
2
 
3
3
  div style="max-width: 22em"
4
4
  = pg_form_for(@user || object) do |f|
5
- = f.mensajes_de_error
6
-
7
- = hidden_field_tag :asociable, true if asociable
8
5
  = f.input :nombre
9
6
  = f.input :apellido
10
7
  = f.input :email
@@ -1,5 +1,4 @@
1
1
  - content_for :title do
2
2
  | Modificar #{@clase_modelo.nombre_singular.downcase}
3
3
 
4
- .p-3
5
- = render 'form'
4
+ = render 'form'
@@ -2,6 +2,10 @@
2
2
  - content_for :actions do
3
3
  - @actions&.each do |link_args|
4
4
  = link_to(*link_args)
5
+ = link_to request.url, class: 'btn btn-sm btn-outline-primary',
6
+ data: { controller: :tooltip, 'bs-title': 'Actualizar' } do
7
+ i.bi.bi-arrow-clockwise
8
+ .ms-1
5
9
  - if @filtros.present?
6
10
  = render SearchBarTogglerComponent.new
7
11
  .ms-1
@@ -42,7 +46,7 @@ div
42
46
  ul.list-group.list-group-horizontal
43
47
  - available_page_sizes.each do |page_size|
44
48
  = link_to page_size,
45
- namespaced_path(@clase_modelo, page_size:),
49
+ url_for(page_size:),
46
50
  class: "list-group-item py-0 px-1 #{'active' if current_page_size == page_size}"
47
51
  - elsif @records_filtered
48
52
  - i18n_key = "#{controller_key}.#{action_name}.index.empty_but_filtered"
@@ -50,8 +54,7 @@ div
50
54
  = t(i18n_key, default: :'.empty_but_filtered', model: @clase_modelo.nombre_plural.downcase)
51
55
  | :
52
56
  span.ms-2
53
- = link_to namespaced_path(@clase_modelo, mostrar_filtros: 1) do
54
- | Limpiar búsqueda
57
+ = link_to 'Limpiar búsqueda', url_for + '?cancel_filter=true'
55
58
  - else
56
59
  - i18n_key = "#{controller_key}.#{action_name}.index.empty"
57
60
  p.m-3 = t(i18n_key, default: :'.empty', model: @clase_modelo.nombre_plural.downcase)
@@ -1,5 +1,4 @@
1
1
  - content_for :title do
2
2
  | Crear #{@clase_modelo.nombre_singular.downcase}
3
3
 
4
- .p-3
5
- = render 'form'
4
+ = render 'form'
@@ -1,4 +1,4 @@
1
- / # locals: (object: nil, asociable: false)
1
+ / # locals: (object: nil)
2
2
 
3
3
  .d-none
4
4
  / Preload
@@ -8,10 +8,7 @@
8
8
  h2 Ponete en contacto
9
9
  .d-inline-block style="width: 30em; max-width: 100%"
10
10
  div data-controller="pg_form"
11
- = pg_form_for(@mensaje_contacto || object, asociable:) do |f|
12
- = f.mensajes_de_error
13
-
14
- = hidden_field_tag :asociable, true if asociable
11
+ = pg_form_for(@mensaje_contacto || object) do |f|
15
12
  - unless user_signed_in?
16
13
  = f.input :nombre, input_html: { style: 'max-width: 22em' }
17
14
  = f.input :email, input_html: { style: 'max-width: 23em' }
@@ -0,0 +1,3 @@
1
+ Kaminari.configure do |config|
2
+ config.params_on_first_page = true
3
+ end
@@ -1,4 +1,15 @@
1
1
  RansackMemory::Core.config = {
2
- param: :q, # this means the default Ransack param name for searching. You can change it
3
- session_key_format: '%controller_name%_%action_name%_%request_format%' # this means how the key used to store the information to the session will be stored. Currently it interpolates request parameters. You can customize it and use these vars to build a key that fits your needs
2
+ # This means the default Ransack param name for searching. You can change it
3
+ param: :q,
4
+
5
+ # This means how the key used to store the information to the session
6
+ # will be stored. Currently it interpolates request parameters.
7
+ # You can customize it and use these vars to build a key that fits your needs
8
+ #
9
+ # Available variables are:
10
+ # controller_name
11
+ # action_name
12
+ # request_format
13
+ # turbo_frame
14
+ session_key_format: '%controller_name%_%action_name%_%request_format%_%turbo_frame%'
4
15
  }
@@ -14,7 +14,7 @@ es:
14
14
  pg_engine:
15
15
  base:
16
16
  index:
17
- empty: 'No hay %{model} aún'
17
+ empty: 'No hay %{model} que mostrar'
18
18
  empty_but_filtered: 'No hay %{model} para los filtros aplicados'
19
19
  attributes:
20
20
  external_labels: Etiquetas externas
@@ -19,20 +19,20 @@ def pg_err(*args)
19
19
  pg_log(:error, *args)
20
20
  end
21
21
 
22
- def pg_warn(*args)
23
- pg_log(:warn, *args)
22
+ def pg_warn(*)
23
+ pg_log(:warn, *)
24
24
  end
25
25
 
26
- def pg_info(*args)
27
- pg_log(:info, *args)
26
+ def pg_info(*)
27
+ pg_log(:info, *)
28
28
  end
29
29
 
30
- def pg_debug(*args)
31
- pg_log(:debug, *args)
30
+ def pg_debug(*)
31
+ pg_log(:debug, *)
32
32
  end
33
33
 
34
- def pg_log(*args)
35
- PgEngine::PgLogger.log(*args)
34
+ def pg_log(*)
35
+ PgEngine::PgLogger.log(*)
36
36
  end
37
37
 
38
38
  module PgEngine
@@ -42,8 +42,8 @@ module PgEngine
42
42
  end
43
43
 
44
44
  class << self
45
- def log(type, *args)
46
- notify_all(build_msg(*args), type)
45
+ def log(type, *)
46
+ notify_all(build_msg(*), type)
47
47
  end
48
48
 
49
49
  private
@@ -200,9 +200,9 @@ RSpec.describe Admin::AccountsController do
200
200
  expect(account.reload.discarded_at).to be_present
201
201
  end
202
202
 
203
- it 'quita el elemento de la lista' do
203
+ it 'envía el pg-event' do
204
204
  subject
205
- expect(response.body).to include('turbo-stream action="remove"')
205
+ expect(response.body).to include('<pg-event data-event-name="pg:record-destroyed"')
206
206
  end
207
207
 
208
208
  context 'si hay redirect_to' do
@@ -162,9 +162,9 @@ RSpec.describe Admin::EmailLogsController do
162
162
  expect { subject }.to change(EmailLog, :count).by(-1)
163
163
  end
164
164
 
165
- it 'quita el elemento de la lista' do
165
+ it 'envía el pg-event' do
166
166
  subject
167
- expect(response.body).to include('turbo-stream action="remove"')
167
+ expect(response.body).to include('<pg-event data-event-name="pg:record-destroyed"')
168
168
  end
169
169
 
170
170
  context 'si hay redirect_to' do
@@ -153,9 +153,9 @@ RSpec.describe Admin::EmailsController do
153
153
  expect { subject }.to change(Email, :count).by(-1)
154
154
  end
155
155
 
156
- it 'quita el elemento de la lista' do
156
+ it 'envía el pg-event' do
157
157
  subject
158
- expect(response.body).to include('turbo-stream action="remove"')
158
+ expect(response.body).to include('<pg-event data-event-name="pg:record-destroyed"')
159
159
  end
160
160
 
161
161
  context 'si hay redirect_to' do
@@ -183,9 +183,9 @@ RSpec.describe Admin::UserAccountsController do
183
183
  expect { subject }.to change(UserAccount, :count).by(-1)
184
184
  end
185
185
 
186
- it 'quita el elemento de la lista' do
186
+ it 'envía el pg-event' do
187
187
  subject
188
- expect(response.body).to include('turbo-stream action="remove"')
188
+ expect(response.body).to include('<pg-event data-event-name="pg:record-destroyed"')
189
189
  end
190
190
 
191
191
  context 'si hay redirect_to' do
@@ -174,9 +174,9 @@ RSpec.describe Admin::UsersController do
174
174
  expect(user.reload.discarded_at).to be_present
175
175
  end
176
176
 
177
- it 'quita el elemento de la lista' do
177
+ it 'envía el pg-event' do
178
178
  subject
179
- expect(response.body).to include('turbo-stream action="remove"')
179
+ expect(response.body).to include('<pg-event data-event-name="pg:record-destroyed"')
180
180
  end
181
181
 
182
182
  context 'si hay redirect_to' do
@@ -14,7 +14,6 @@ describe PgEngine::Resource do
14
14
  allow(request).to receive_messages(filtered_parameters: { id: 321 },
15
15
  parameters: { id: 321 })
16
16
  allow(instancia).to receive(:request).and_return(request)
17
- instancia.set_clase_modelo
18
17
  end
19
18
 
20
19
  it do
@@ -34,7 +33,6 @@ describe PgEngine::Resource do
34
33
  allow(request).to receive_messages(filtered_parameters: { id: categoria_de_cosa.to_param },
35
34
  parameters: { id: categoria_de_cosa.to_param })
36
35
  allow(instancia).to receive(:request).and_return(request)
37
- instancia.set_clase_modelo
38
36
  end
39
37
 
40
38
  it do
@@ -0,0 +1,51 @@
1
+ require 'rails_helper'
2
+
3
+ describe PgEngine::FormHelper do
4
+ subject do
5
+ view_context.pg_form_for(cosa, **options) do |f|
6
+ f.submit 'ACEPTAR'
7
+ end
8
+ end
9
+
10
+ let(:options) do
11
+ {}
12
+ end
13
+
14
+ let(:view_context) do
15
+ cont = Admin::CosasController.new
16
+ cont.request = ActionDispatch::TestRequest.create
17
+ cont.view_context
18
+ end
19
+ let(:cosa) { Cosa.new }
20
+
21
+ before do
22
+ Current.namespace = :admin
23
+ end
24
+
25
+ it 'renders the form and the button' do
26
+ expect(subject).to include 'ACEPTAR'
27
+ expect(subject).to include '<form'
28
+ end
29
+
30
+ context 'when there are errors' do
31
+ let(:cosa) do
32
+ ret = Cosa.new(nombre: nil)
33
+ ret.validate
34
+ ret
35
+ end
36
+
37
+ it 'renders the errors' do
38
+ expect(subject).to include 'Por favor, revisá los campos obligatorios'
39
+ end
40
+
41
+ context 'and its requested not to render errors' do
42
+ let(:options) do
43
+ { render_errors: false }
44
+ end
45
+
46
+ it 'renders the errors' do
47
+ expect(subject).not_to include 'Por favor, revisá los campos obligatorios'
48
+ end
49
+ end
50
+ end
51
+ end