pg_rails 7.6.17 → 7.6.19

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. checksums.yaml +4 -4
  2. data/pg_associable/app/javascript/modal_controller.js +17 -1
  3. data/pg_engine/app/assets/stylesheets/pg_rails_b5.scss +8 -1
  4. data/pg_engine/app/components/inline_edit/inline_show_component.html.slim +2 -1
  5. data/pg_engine/app/components/search_bar_toggler_component.html.slim +5 -3
  6. data/pg_engine/app/controllers/admin/accounts_controller.rb +0 -4
  7. data/pg_engine/app/controllers/admin/email_logs_controller.rb +0 -4
  8. data/pg_engine/app/controllers/admin/emails_controller.rb +0 -4
  9. data/pg_engine/app/controllers/admin/simple_user_notifiers_controller.rb +0 -2
  10. data/pg_engine/app/controllers/admin/user_accounts_controller.rb +0 -4
  11. data/pg_engine/app/controllers/admin/users_controller.rb +0 -4
  12. data/pg_engine/app/controllers/concerns/pg_engine/resource.rb +121 -41
  13. data/pg_engine/app/controllers/public/mensaje_contactos_controller.rb +0 -4
  14. data/pg_engine/app/controllers/users/accounts_controller.rb +0 -4
  15. data/pg_engine/app/decorators/pg_engine/base_record_decorator.rb +39 -13
  16. data/pg_engine/app/helpers/pg_engine/index_helper.rb +17 -3
  17. data/pg_engine/app/helpers/pg_engine/route_helper.rb +4 -0
  18. data/pg_engine/app/lib/pg_engine/filtros_builder.rb +7 -9
  19. data/pg_engine/app/models/account.rb +2 -0
  20. data/pg_engine/app/models/concerns/pg_engine/naming.rb +5 -0
  21. data/pg_engine/app/models/pg_engine/base_record.rb +1 -4
  22. data/pg_engine/app/models/user.rb +1 -1
  23. data/pg_engine/app/policies/account_policy.rb +9 -9
  24. data/pg_engine/app/policies/pg_engine/base_policy.rb +15 -3
  25. data/pg_engine/app/views/admin/accounts/show.html.slim +0 -7
  26. data/pg_engine/app/views/admin/email_logs/show.html.slim +0 -7
  27. data/pg_engine/app/views/admin/emails/show.html.slim +0 -7
  28. data/pg_engine/app/views/admin/simple_user_notifiers/show.html.slim +0 -5
  29. data/pg_engine/app/views/admin/user_accounts/show.html.slim +0 -7
  30. data/pg_engine/app/views/admin/users/show.html.slim +1 -5
  31. data/pg_engine/app/views/pg_engine/base/index.html.slim +40 -15
  32. data/pg_engine/config/locales/es.rb +42 -0
  33. data/pg_engine/config/locales/es.yml +1 -6
  34. data/pg_engine/lib/pg_engine/route_helpers.rb +5 -0
  35. data/pg_engine/spec/controllers/admin/accounts_controller_spec.rb +4 -9
  36. data/pg_engine/spec/controllers/admin/email_logs_controller_spec.rb +4 -4
  37. data/pg_engine/spec/controllers/admin/emails_controller_spec.rb +4 -4
  38. data/pg_engine/spec/controllers/admin/user_accounts_controller_spec.rb +4 -4
  39. data/pg_engine/spec/controllers/admin/users_controller_spec.rb +4 -9
  40. data/pg_engine/spec/requests/resource_spec.rb +84 -0
  41. data/pg_engine/spec/requests/users/switcher_spec.rb +2 -2
  42. data/pg_engine/spec/system/breadcrumbs_spec.rb +9 -21
  43. data/pg_engine/spec/system/destroy_spec.rb +3 -3
  44. data/pg_engine/spec/system/login_spec.rb +1 -1
  45. data/pg_engine/spec/system/modal_windows_spec.rb +5 -5
  46. data/pg_engine/spec/system/tenants_spec.rb +2 -2
  47. data/pg_layout/app/javascript/application.js +4 -2
  48. data/pg_layout/app/javascript/controllers/embedded_frame_controller.js +4 -0
  49. data/pg_layout/app/views/layouts/pg_layout/base.html.slim +3 -1
  50. data/pg_layout/app/views/layouts/pg_layout/show.html.slim +10 -0
  51. data/pg_rails/lib/version.rb +1 -1
  52. data/pg_scaffold/lib/generators/pg_rspec/scaffold/templates/controller_spec.rb +4 -11
  53. data/pg_scaffold/lib/generators/pg_scaffold/templates/controller.rb +1 -5
  54. data/pg_scaffold/lib/generators/pg_slim/templates/show.html.slim +0 -7
  55. metadata +5 -3
  56. data/pg_engine/app/components/actions_component.rb +0 -14
@@ -34,6 +34,8 @@ class Account < ApplicationRecord
34
34
 
35
35
  validates :plan, :nombre, presence: true
36
36
 
37
+ has_many :audits, dependent: :nullify, class_name: 'Audited::Audit'
38
+
37
39
  ransacker :search do |parent|
38
40
  parent.table[:nombre]
39
41
  end
@@ -1,5 +1,6 @@
1
1
  module PgEngine
2
2
  module Naming
3
+ deprecate :gender, deprecator: PgEngine.deprecator
3
4
  def gender
4
5
  self.class.model_name.human.downcase.ends_with?('a') ? 'f' : 'm'
5
6
  end
@@ -13,6 +14,10 @@ module PgEngine
13
14
  # BUT **the values are independent between all of them**
14
15
  attr_accessor :default_modal, :inline_editable_fields
15
16
 
17
+ def gender
18
+ model_name.human.downcase.ends_with?('a') ? 'f' : 'm'
19
+ end
20
+
16
21
  def inline_editable?(attribute)
17
22
  inline_editable_fields.present? && inline_editable_fields.include?(attribute.to_sym)
18
23
  end
@@ -14,14 +14,11 @@ module PgEngine
14
14
  before_create :setear_creado_y_actualizado_por
15
15
  before_update :setear_actualizado_por
16
16
 
17
+ scope :unkept, -> { discarded }
17
18
  # ransacker :search do |parent|
18
19
  # parent.table[:nombre]
19
20
  # end
20
21
 
21
- def actions_component
22
- ActionsComponent.new(self)
23
- end
24
-
25
22
  # Para el dom_id (index.html)
26
23
  def to_key
27
24
  if respond_to? :hashid
@@ -36,7 +36,7 @@ class User < ApplicationRecord
36
36
  audited
37
37
  include Discard::Model
38
38
 
39
- has_many :user_accounts
39
+ has_many :user_accounts, dependent: :destroy
40
40
 
41
41
  # Hace falta?
42
42
  has_many :accounts, through: :user_accounts
@@ -13,17 +13,17 @@ class AccountPolicy < ApplicationPolicy
13
13
  # end
14
14
  end
15
15
 
16
- # def puede_editar?
17
- # acceso_total? && !record.readonly?
18
- # end
16
+ def puede_editar?
17
+ user.developer?
18
+ end
19
19
 
20
- # def puede_crear?
21
- # acceso_total? || user.asesor?
22
- # end
20
+ def puede_crear?
21
+ user.developer?
22
+ end
23
23
 
24
- # def puede_borrar?
25
- # acceso_total? && !record.readonly?
26
- # end
24
+ def puede_borrar?
25
+ user.developer?
26
+ end
27
27
 
28
28
  # def acceso_total?
29
29
  # user.developer?
@@ -13,6 +13,10 @@ module PgEngine
13
13
  base_access_to_collection?
14
14
  end
15
15
 
16
+ def archived?
17
+ base_access_to_collection?
18
+ end
19
+
16
20
  def show?
17
21
  base_access_to_record?
18
22
  end
@@ -30,7 +34,7 @@ module PgEngine
30
34
  end
31
35
 
32
36
  def update?
33
- puede_editar? && !objeto_borrado?
37
+ puede_editar? && !record_discarded?
34
38
  end
35
39
 
36
40
  def edit?
@@ -38,7 +42,15 @@ module PgEngine
38
42
  end
39
43
 
40
44
  def destroy?
41
- puede_borrar? && !objeto_borrado?
45
+ puede_borrar?
46
+ end
47
+
48
+ def archive?
49
+ puede_borrar? && !record_discarded?
50
+ end
51
+
52
+ def restore?
53
+ puede_borrar? && record.respond_to?(:discarded?) && record.discarded?
42
54
  end
43
55
 
44
56
  def scope
@@ -92,7 +104,7 @@ module PgEngine
92
104
  user&.developer?
93
105
  end
94
106
 
95
- def objeto_borrado?
107
+ def record_discarded?
96
108
  if record.respond_to?(:kept?)
97
109
  !record.kept?
98
110
  else
@@ -1,10 +1,3 @@
1
- - content_for :title do
2
- = @account.to_s
3
- - content_for :actions do
4
- = @account.destroy_link_redirect
5
- .ms-1
6
- = @account.edit_link
7
-
8
1
  table.table.table-borderless.table-sm.w-auto.mb-0.m-3
9
2
  - atributos_para_mostrar.each do |att|
10
3
  tr
@@ -1,10 +1,3 @@
1
- - content_for :title do
2
- = @email_log.to_s
3
- - content_for :actions do
4
- = @email_log.destroy_link_redirect
5
- .ms-1
6
- = @email_log.edit_link
7
-
8
1
  table.table.table-borderless.table-sm.w-auto.mb-0.m-3
9
2
  - atributos_para_mostrar.each do |att|
10
3
  tr
@@ -1,10 +1,3 @@
1
- - content_for :title do
2
- = @email.to_s
3
- - content_for :actions do
4
- = @email.destroy_link_redirect
5
- .ms-1
6
- = @email.edit_link
7
-
8
1
  table.table.table-borderless.table-sm.w-auto.mb-0
9
2
  - atributos_para_mostrar.each do |att|
10
3
  tr
@@ -1,8 +1,3 @@
1
- - content_for :actions do
2
- = @simple_user_notifier.destroy_link_redirect
3
- .ms-1
4
- = @simple_user_notifier.edit_link
5
-
6
1
  table.table.table-borderless.table-sm.w-auto.mb-0.m-3
7
2
  - atributos_para_mostrar.each do |att|
8
3
  tr
@@ -1,10 +1,3 @@
1
- - content_for :title do
2
- = @user_account.to_s
3
- - content_for :actions do
4
- = @user_account.destroy_link_redirect
5
- .ms-1
6
- = @user_account.edit_link
7
-
8
1
  table.table.table-borderless.table-sm.w-auto.mb-0.m-3
9
2
  - atributos_para_mostrar.each do |att|
10
3
  tr
@@ -1,10 +1,6 @@
1
1
  - content_for :title do
2
2
  = @user.to_s
3
- - content_for :actions do
4
- = @user.destroy_link_redirect
5
- .ms-1
6
- = @user.edit_link
7
- .ms-1
3
+ - content_for :extra_actions do
8
4
  = link_to login_as_path(id: @user.id), class: 'btn btn-light btn-sm' do
9
5
  span.bi.bi-arrow-right
10
6
  | Login as
@@ -6,10 +6,31 @@
6
6
  data: { controller: :tooltip, 'bs-title': 'Actualizar' } do
7
7
  i.bi.bi-arrow-clockwise
8
8
  .ms-1
9
- - if @filtros.present?
10
- = render SearchBarTogglerComponent.new
9
+ - if action_name == 'index' && (nested_record.blank? || nested_record.kept?)
10
+ = @clase_modelo.new.decorate.new_link
11
11
  .ms-1
12
- = @clase_modelo.new.decorate.new_link
12
+ .dropdown data-controller="tooltip" data-bs-title="Más opciones"
13
+ button.btn.btn-outline-secondary.btn-sm.xdropdown-toggle[
14
+ type="button" data-bs-toggle="dropdown" aria-expanded="false"]
15
+ i.bi.bi-list
16
+ ul.dropdown-menu
17
+ - unless action_name == 'archived'
18
+ li = link_to [:archived, pg_namespace, nested_record, @clase_modelo].compact,
19
+ class: 'icon-link dropdown-item' do
20
+ i.bi.bi-archive-fill.lh-1
21
+ = t('pg_engine.base.index.see_archived', model: clase_modelo)
22
+ - if @filtros.present?
23
+ li = render SearchBarTogglerComponent.new
24
+ - unless @export_link == false
25
+ li = @clase_modelo.new.decorate.export_link(request.url, text: 'Exportar en excel')
26
+
27
+ - if action_name == 'archived'
28
+ .text-center.p-3.text-warning-emphasis.border-bottom
29
+ div
30
+ i.bi.bi-archive-fill
31
+ div
32
+ => t('pg_engine.base.index.youre_in_archived_index', model: clase_modelo)
33
+ = link_to t('.back_to_index'), @index_url
13
34
 
14
35
  - if @filtros.present?
15
36
  = render SearchBarComponent.new(@q, @filtros)
@@ -21,24 +42,27 @@
21
42
  caption.ps-3 = page_entries_info @collection
22
43
  thead.table-light
23
44
  tr
45
+ th
24
46
  - atributos_para_listar.each do |att|
25
47
  th.text-nowrap style="font-size: 0.8em" = encabezado att, ordenable: true
26
- th.text-end
27
- - unless @export_link == false
28
- .actions-wrapper
29
- = @clase_modelo.new.decorate.export_link(request.url)
48
+ - if action_name == 'archived'
49
+ th.text-nowrap style="font-size: 0.8em" = encabezado :discarded_at, ordenable: true
30
50
  tbody
31
51
  - @collection.each do |object|
32
52
  - object = object.decorate
33
53
  tr id="#{dom_id(object)}"
34
- - atributos_para_listar.each do |att, _sort_field|
35
- = column_for object, att
36
- td.text-nowrap.text-end.ps-5
54
+ td.text-nowrap.xtext-end.xps-5
37
55
  .actions-wrapper
38
- = object.extra_actions(size: :sm) if object.respond_to? :extra_actions
39
- = object.show_link
56
+ = object.show_link(text: '')
40
57
  = object.edit_link(text: '', klass: 'btn-light')
58
+ = object.archive_link
59
+ = object.restore_link
41
60
  = object.destroy_link
61
+ = object.extra_actions(size: :sm) if object.respond_to? :extra_actions
62
+ - atributos_para_listar.each do |att, _sort_field|
63
+ = column_for object, att
64
+ - if action_name == 'archived'
65
+ = column_for object, :discarded_at
42
66
 
43
67
  .d-flex.justify-content-center
44
68
  = paginate(@collection)
@@ -50,12 +74,13 @@
50
74
  url_for(page_size:),
51
75
  class: "list-group-item py-0 px-1 #{'active' if current_page_size == page_size}"
52
76
  - elsif @records_filtered
53
- - i18n_key = "#{controller_key}.#{action_name}.index.empty_but_filtered"
77
+ / - i18n_key = "#{controller_key}.#{action_name}.index.empty_but_filtered"
78
+ - i18n_key = :".#{action_name}.empty_but_filtered"
54
79
  p.m-3
55
- = t(i18n_key, default: :'.empty_but_filtered', model: @clase_modelo.nombre_plural.downcase)
80
+ = t(i18n_key, default: :".#{action_name}.empty_but_filtered", model: @clase_modelo)
56
81
  | :
57
82
  span.ms-2
58
83
  = link_to 'Limpiar búsqueda', url_for + '?cancel_filter=true'
59
84
  - else
60
85
  - i18n_key = "#{controller_key}.#{action_name}.index.empty"
61
- p.m-3 = t(i18n_key, default: :'.empty', model: @clase_modelo.nombre_plural.downcase)
86
+ p.m-3 = t(i18n_key, default: :".#{action_name}.empty", model: @clase_modelo)
@@ -0,0 +1,42 @@
1
+ module PgEngine
2
+ module I18nRules
3
+ def self.rule(text)
4
+ lambda do |key, options|
5
+ male = options[:model].gender == 'm'
6
+ model_plural = options[:model].nombre_plural
7
+ model_singular = options[:model].nombre_singular
8
+ text.gsub(/^%{plural_model}/, model_plural)
9
+ .gsub(/^%{singular_model}/, model_singular)
10
+ .gsub('%{plural_model}', model_plural.downcase)
11
+ .gsub('%{singular_model}', model_singular.downcase)
12
+ .gsub(/%{genderize\((?<female>(?:(?!%{).)+),(?<male>(?:(?!%{).)+)\)}/, male ? '\k<male>' : '\k<female>' )
13
+ end
14
+ end
15
+ end
16
+ end
17
+
18
+ {
19
+ :es => {
20
+ pg_engine: {
21
+ resource_destroyed: PgEngine::I18nRules.rule("Se eliminó %{genderize(la,el)} %{singular_model}"),
22
+ resource_not_destroyed: PgEngine::I18nRules.rule("Hubo un error al intentar eliminar %{genderize(la,el)} %{singular_model}"),
23
+ resource_not_updated: PgEngine::I18nRules.rule("Hubo un error al intentar actualizar %{genderize(la,el)} %{singular_model}"),
24
+ resource_not_destroyed_because_associated: PgEngine::I18nRules.rule("No se pudo eliminar %{genderize(la,el)} %{singular_model} porque está asociado a otros elementos"),
25
+ base: {
26
+ index: {
27
+ archived: {
28
+ empty_but_filtered: PgEngine::I18nRules.rule("No hay %{genderize(ninguna,ningún)} %{singular_model} %{genderize(archivada,archivado)} para los filtros aplicados"),
29
+ empty: PgEngine::I18nRules.rule("No hay %{genderize(ninguna,ningún)} %{singular_model} %{genderize(archivada,archivado)}"),
30
+ },
31
+ index: {
32
+ empty_but_filtered: PgEngine::I18nRules.rule("No hay %{genderize(ninguna,ningún)} %{singular_model} para los filtros aplicados"),
33
+ empty: PgEngine::I18nRules.rule("No hay %{genderize(ninguna,ningún)} %{singular_model} que mostrar"),
34
+ },
35
+ youre_in_archived_index: PgEngine::I18nRules.rule("Estás viendo el listado de %{plural_model} %{genderize(archivadas,archivados)}"),
36
+ see_archived: PgEngine::I18nRules.rule("%{plural_model} %{genderize(archivadas,archivados)}"),
37
+ back_to_index: 'Volver al listado principal'
38
+ }
39
+ }
40
+ }
41
+ }
42
+ }
@@ -11,11 +11,6 @@ es:
11
11
  gt: 'desde'
12
12
  lteq: 'hasta'
13
13
  gteq: 'desde'
14
- pg_engine:
15
- base:
16
- index:
17
- empty: 'No hay %{model} que mostrar'
18
- empty_but_filtered: 'No hay %{model} para los filtros aplicados'
19
14
  gender:
20
15
  reset_password_token: m
21
16
  confirmation_token: m
@@ -27,7 +22,7 @@ es:
27
22
  external_id: ID externo
28
23
  created_at: Fecha de creación
29
24
  updated_at: Fecha de actualización
30
- discarded_at: Fecha de borrado
25
+ discarded_at: Fecha de archivado
31
26
  confirmed_at: Fecha de confirmación
32
27
  actualizado_por: Actualizado por
33
28
  creado_por: Creado por
@@ -2,7 +2,12 @@ module PgEngine
2
2
  module RouteHelpers
3
3
  def pg_resource(key, options = {})
4
4
  resources(key, options) do
5
+ member do
6
+ post :archive
7
+ post :restore
8
+ end
5
9
  collection do
10
+ get :archived
6
11
  get :abrir_modal
7
12
  post :buscar
8
13
  end
@@ -185,28 +185,23 @@ RSpec.describe Admin::AccountsController do
185
185
  describe 'DELETE #destroy' do
186
186
  subject do
187
187
  request.headers['Accept'] = 'text/vnd.turbo-stream.html,text/html'
188
- delete :destroy, params: { id: account.to_param, redirect_to: redirect_url }
188
+ delete :destroy, params: { id: account.to_param, land_on: }
189
189
  end
190
190
 
191
191
  let!(:account) { create :account }
192
- let(:redirect_url) { nil }
192
+ let(:land_on) { nil }
193
193
 
194
194
  it 'destroys the requested account' do
195
195
  expect { subject }.to change(Account.kept, :count).by(-1)
196
196
  end
197
197
 
198
- it 'setea el discarded_at' do
199
- subject
200
- expect(account.reload.discarded_at).to be_present
201
- end
202
-
203
198
  it 'envía el pg-event' do
204
199
  subject
205
200
  expect(response.body).to include('<pg-event data-event-name="pg:record-destroyed"')
206
201
  end
207
202
 
208
- context 'si hay redirect_to' do
209
- let(:redirect_url) { admin_accounts_url }
203
+ context 'si hay land_on' do
204
+ let(:land_on) { :index }
210
205
 
211
206
  it 'redirects to the accounts list' do
212
207
  subject
@@ -154,11 +154,11 @@ RSpec.describe Admin::EmailLogsController do
154
154
  describe 'DELETE #destroy' do
155
155
  subject do
156
156
  request.headers['Accept'] = 'text/vnd.turbo-stream.html,text/html'
157
- delete :destroy, params: { id: email_log.to_param, redirect_to: redirect_url }
157
+ delete :destroy, params: { id: email_log.to_param, land_on: }
158
158
  end
159
159
 
160
160
  let!(:email_log) { create :email_log }
161
- let(:redirect_url) { nil }
161
+ let(:land_on) { nil }
162
162
 
163
163
  it 'destroys the requested email_log' do
164
164
  expect { subject }.to change(EmailLog, :count).by(-1)
@@ -169,8 +169,8 @@ RSpec.describe Admin::EmailLogsController do
169
169
  expect(response.body).to include('<pg-event data-event-name="pg:record-destroyed"')
170
170
  end
171
171
 
172
- context 'si hay redirect_to' do
173
- let(:redirect_url) { admin_email_logs_url }
172
+ context 'si hay land_on' do
173
+ let(:land_on) { :index }
174
174
 
175
175
  it 'redirects to the email_logs list' do
176
176
  subject
@@ -143,11 +143,11 @@ RSpec.describe Admin::EmailsController do
143
143
  describe 'DELETE #destroy' do
144
144
  subject do
145
145
  request.headers['Accept'] = 'text/vnd.turbo-stream.html,text/html'
146
- delete :destroy, params: { id: email.to_param, redirect_to: redirect_url }
146
+ delete :destroy, params: { id: email.to_param, land_on: }
147
147
  end
148
148
 
149
149
  let!(:email) { create :email }
150
- let(:redirect_url) { nil }
150
+ let(:land_on) { nil }
151
151
 
152
152
  it 'destroys the requested email' do
153
153
  expect { subject }.to change(Email, :count).by(-1)
@@ -158,8 +158,8 @@ RSpec.describe Admin::EmailsController do
158
158
  expect(response.body).to include('<pg-event data-event-name="pg:record-destroyed"')
159
159
  end
160
160
 
161
- context 'si hay redirect_to' do
162
- let(:redirect_url) { admin_emails_url }
161
+ context 'si hay land_on' do
162
+ let(:land_on) { :index }
163
163
 
164
164
  it 'redirects to the emails list' do
165
165
  subject
@@ -174,11 +174,11 @@ RSpec.describe Admin::UserAccountsController do
174
174
  describe 'DELETE #destroy' do
175
175
  subject do
176
176
  request.headers['Accept'] = 'text/vnd.turbo-stream.html,text/html'
177
- delete :destroy, params: { id: user_account.to_param, redirect_to: redirect_url }
177
+ delete :destroy, params: { id: user_account.to_param, land_on: }
178
178
  end
179
179
 
180
180
  let!(:user_account) { create :user_account }
181
- let(:redirect_url) { nil }
181
+ let(:land_on) { nil }
182
182
 
183
183
  it 'destroys the requested user_account' do
184
184
  expect { subject }.to change(UserAccount, :count).by(-1)
@@ -189,8 +189,8 @@ RSpec.describe Admin::UserAccountsController do
189
189
  expect(response.body).to include('<pg-event data-event-name="pg:record-destroyed"')
190
190
  end
191
191
 
192
- context 'si hay redirect_to' do
193
- let(:redirect_url) { admin_user_accounts_url }
192
+ context 'si hay land_on' do
193
+ let(:land_on) { :index }
194
194
 
195
195
  it 'redirects to the user_accounts list' do
196
196
  subject
@@ -169,28 +169,23 @@ RSpec.describe Admin::UsersController do
169
169
  describe 'DELETE #destroy' do
170
170
  subject do
171
171
  request.headers['Accept'] = 'text/vnd.turbo-stream.html,text/html'
172
- delete :destroy, params: { id: user.to_param, redirect_to: redirect_url }
172
+ delete :destroy, params: { id: user.to_param, land_on: }
173
173
  end
174
174
 
175
175
  let!(:user) { create :user }
176
- let(:redirect_url) { nil }
176
+ let(:land_on) { nil }
177
177
 
178
178
  it 'destroys the requested user' do
179
179
  expect { subject }.to change(User.kept, :count).by(-1)
180
180
  end
181
181
 
182
- it 'setea el discarded_at' do
183
- subject
184
- expect(user.reload.discarded_at).to be_present
185
- end
186
-
187
182
  it 'envía el pg-event' do
188
183
  subject
189
184
  expect(response.body).to include('<pg-event data-event-name="pg:record-destroyed"')
190
185
  end
191
186
 
192
- context 'si hay redirect_to' do
193
- let(:redirect_url) { admin_users_url }
187
+ context 'si hay land_on' do
188
+ let(:land_on) { :index }
194
189
 
195
190
  it 'redirects to the users list' do
196
191
  subject
@@ -0,0 +1,84 @@
1
+ require 'rails_helper'
2
+
3
+ describe 'Resources' do
4
+ let(:user) { create :user }
5
+ let(:cosa) { create :cosa }
6
+
7
+ before do
8
+ sign_in user
9
+ end
10
+
11
+ describe 'action links' do
12
+ it 'shows the archive link' do
13
+ get '/u/cosas/' + cosa.to_param
14
+ expect(response).to have_http_status(:ok)
15
+ regex = %r{<a data-turbo-method="post" .* href="/u/cosas/[\d]+/archive">}
16
+ expect(response.body).to match regex
17
+ end
18
+
19
+ it 'shows the unarchive link' do
20
+ cosa.update(discarded_at: Time.current)
21
+ get '/u/cosas/' + cosa.to_param
22
+ expect(response.body).to have_link(href: %r{/u/cosas/[\d]+/restore})
23
+ end
24
+ end
25
+
26
+ describe 'set breadcrumbs for all actions' do
27
+ it 'when flat archived index' do
28
+ get '/u/cosas/archived'
29
+ expect(response.body).to have_css('.breadcrumb a[href="/u/cosas"]')
30
+ end
31
+
32
+ it 'when nested archived index' do
33
+ get "/u/categoria_de_cosas/#{cosa.categoria_de_cosa.to_param}/cosas/archived"
34
+ expect(response.body).to \
35
+ have_css ".breadcrumb a[href=\"/u/categoria_de_cosas/#{cosa.categoria_de_cosa.to_param}/cosas\"]"
36
+ end
37
+ end
38
+
39
+ describe '#archive' do
40
+ let(:url) { "/u/cosas/#{cosa.to_param}/archive" }
41
+
42
+ it 'when accepts turbo stream' do
43
+ headers = { 'ACCEPT' => 'text/vnd.turbo-stream.html' }
44
+ expect { post url, headers: }.to change { cosa.reload.discarded_at }.to(be_present)
45
+ expect(response.body).to have_css('turbo-stream')
46
+ end
47
+
48
+ it 'when accepts only html' do
49
+ expect { post url }.to change { cosa.reload.discarded_at }.to(be_present)
50
+ expect(response).to redirect_to([:users, cosa])
51
+ end
52
+
53
+ context 'when fails' do
54
+ before do
55
+ allow_any_instance_of(Cosa).to receive(:discard).and_return(false)
56
+ end
57
+
58
+ it 'when accepts turbo stream' do
59
+ post url, headers: { 'ACCEPT' => 'text/vnd.turbo-stream.html' }
60
+ expect(response.body).to have_css('turbo-stream')
61
+ expect(response.body).to include('Hubo un error al intentar actualizar el coso')
62
+ expect(response).to have_http_status(:unprocessable_entity)
63
+ end
64
+
65
+ it 'when accepts only html' do
66
+ post url
67
+ expect(response).to redirect_to([:users, cosa])
68
+ expect(flash[:alert]).to eq 'Hubo un error al intentar actualizar el coso'
69
+ end
70
+ end
71
+ end
72
+
73
+ describe '#restore' do
74
+ subject do
75
+ post "/u/cosas/#{cosa.to_param}/restore"
76
+ end
77
+
78
+ let(:cosa) { create :cosa, discarded_at: Time.zone.now }
79
+
80
+ it do
81
+ expect { subject }.to change { cosa.reload.discarded_at }.to(be_nil)
82
+ end
83
+ end
84
+ end
@@ -29,7 +29,7 @@ describe 'redirection' do
29
29
  context 'when account is discarded' do
30
30
  it do
31
31
  get '/u/cosas'
32
- expect(response.body).to include 'No hay cosos que mostrar'
32
+ expect(response.body).to include 'No hay ningún coso que mostrar'
33
33
  logged_user.user_accounts.first.account.discard!
34
34
  get '/u/cosas'
35
35
  expect(response).to redirect_to users_account_switcher_path
@@ -62,7 +62,7 @@ describe 'redirection' do
62
62
  get '/u/cosas'
63
63
  expect(response).to have_http_status(:ok)
64
64
  expect(response.body).to include other_account.to_s
65
- expect(response.body).to include 'No hay cosos que mostrar'
65
+ expect(response.body).to include 'No hay ningún coso que mostrar'
66
66
  other_user_account.destroy!
67
67
  get '/u/cosas'
68
68
  expect(response).to redirect_to users_account_switcher_path