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.
- checksums.yaml +4 -4
- data/pg_associable/app/javascript/modal_controller.js +17 -1
- data/pg_engine/app/assets/stylesheets/pg_rails_b5.scss +8 -1
- data/pg_engine/app/components/inline_edit/inline_show_component.html.slim +2 -1
- data/pg_engine/app/components/search_bar_toggler_component.html.slim +5 -3
- data/pg_engine/app/controllers/admin/accounts_controller.rb +0 -4
- data/pg_engine/app/controllers/admin/email_logs_controller.rb +0 -4
- data/pg_engine/app/controllers/admin/emails_controller.rb +0 -4
- data/pg_engine/app/controllers/admin/simple_user_notifiers_controller.rb +0 -2
- data/pg_engine/app/controllers/admin/user_accounts_controller.rb +0 -4
- data/pg_engine/app/controllers/admin/users_controller.rb +0 -4
- data/pg_engine/app/controllers/concerns/pg_engine/resource.rb +121 -41
- data/pg_engine/app/controllers/public/mensaje_contactos_controller.rb +0 -4
- data/pg_engine/app/controllers/users/accounts_controller.rb +0 -4
- data/pg_engine/app/decorators/pg_engine/base_record_decorator.rb +39 -13
- data/pg_engine/app/helpers/pg_engine/index_helper.rb +17 -3
- data/pg_engine/app/helpers/pg_engine/route_helper.rb +4 -0
- data/pg_engine/app/lib/pg_engine/filtros_builder.rb +7 -9
- data/pg_engine/app/models/account.rb +2 -0
- data/pg_engine/app/models/concerns/pg_engine/naming.rb +5 -0
- data/pg_engine/app/models/pg_engine/base_record.rb +1 -4
- data/pg_engine/app/models/user.rb +1 -1
- data/pg_engine/app/policies/account_policy.rb +9 -9
- data/pg_engine/app/policies/pg_engine/base_policy.rb +15 -3
- data/pg_engine/app/views/admin/accounts/show.html.slim +0 -7
- data/pg_engine/app/views/admin/email_logs/show.html.slim +0 -7
- data/pg_engine/app/views/admin/emails/show.html.slim +0 -7
- data/pg_engine/app/views/admin/simple_user_notifiers/show.html.slim +0 -5
- data/pg_engine/app/views/admin/user_accounts/show.html.slim +0 -7
- data/pg_engine/app/views/admin/users/show.html.slim +1 -5
- data/pg_engine/app/views/pg_engine/base/index.html.slim +40 -15
- data/pg_engine/config/locales/es.rb +42 -0
- data/pg_engine/config/locales/es.yml +1 -6
- data/pg_engine/lib/pg_engine/route_helpers.rb +5 -0
- data/pg_engine/spec/controllers/admin/accounts_controller_spec.rb +4 -9
- data/pg_engine/spec/controllers/admin/email_logs_controller_spec.rb +4 -4
- data/pg_engine/spec/controllers/admin/emails_controller_spec.rb +4 -4
- data/pg_engine/spec/controllers/admin/user_accounts_controller_spec.rb +4 -4
- data/pg_engine/spec/controllers/admin/users_controller_spec.rb +4 -9
- data/pg_engine/spec/requests/resource_spec.rb +84 -0
- data/pg_engine/spec/requests/users/switcher_spec.rb +2 -2
- data/pg_engine/spec/system/breadcrumbs_spec.rb +9 -21
- data/pg_engine/spec/system/destroy_spec.rb +3 -3
- data/pg_engine/spec/system/login_spec.rb +1 -1
- data/pg_engine/spec/system/modal_windows_spec.rb +5 -5
- data/pg_engine/spec/system/tenants_spec.rb +2 -2
- data/pg_layout/app/javascript/application.js +4 -2
- data/pg_layout/app/javascript/controllers/embedded_frame_controller.js +4 -0
- data/pg_layout/app/views/layouts/pg_layout/base.html.slim +3 -1
- data/pg_layout/app/views/layouts/pg_layout/show.html.slim +10 -0
- data/pg_rails/lib/version.rb +1 -1
- data/pg_scaffold/lib/generators/pg_rspec/scaffold/templates/controller_spec.rb +4 -11
- data/pg_scaffold/lib/generators/pg_scaffold/templates/controller.rb +1 -5
- data/pg_scaffold/lib/generators/pg_slim/templates/show.html.slim +0 -7
- metadata +5 -3
- data/pg_engine/app/components/actions_component.rb +0 -14
@@ -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
|
@@ -13,17 +13,17 @@ class AccountPolicy < ApplicationPolicy
|
|
13
13
|
# end
|
14
14
|
end
|
15
15
|
|
16
|
-
|
17
|
-
|
18
|
-
|
16
|
+
def puede_editar?
|
17
|
+
user.developer?
|
18
|
+
end
|
19
19
|
|
20
|
-
|
21
|
-
|
22
|
-
|
20
|
+
def puede_crear?
|
21
|
+
user.developer?
|
22
|
+
end
|
23
23
|
|
24
|
-
|
25
|
-
|
26
|
-
|
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? && !
|
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?
|
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
|
107
|
+
def record_discarded?
|
96
108
|
if record.respond_to?(:kept?)
|
97
109
|
!record.kept?
|
98
110
|
else
|
@@ -1,10 +1,6 @@
|
|
1
1
|
- content_for :title do
|
2
2
|
= @user.to_s
|
3
|
-
- content_for :
|
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
|
10
|
-
=
|
9
|
+
- if action_name == 'index' && (nested_record.blank? || nested_record.kept?)
|
10
|
+
= @clase_modelo.new.decorate.new_link
|
11
11
|
.ms-1
|
12
|
-
=
|
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
|
-
|
27
|
-
-
|
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
|
-
-
|
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.
|
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: :
|
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: :
|
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
|
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
|
@@ -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,
|
188
|
+
delete :destroy, params: { id: account.to_param, land_on: }
|
189
189
|
end
|
190
190
|
|
191
191
|
let!(:account) { create :account }
|
192
|
-
let(:
|
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
|
209
|
-
let(:
|
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,
|
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(:
|
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
|
173
|
-
let(:
|
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,
|
146
|
+
delete :destroy, params: { id: email.to_param, land_on: }
|
147
147
|
end
|
148
148
|
|
149
149
|
let!(:email) { create :email }
|
150
|
-
let(:
|
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
|
162
|
-
let(:
|
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,
|
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(:
|
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
|
193
|
-
let(:
|
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,
|
172
|
+
delete :destroy, params: { id: user.to_param, land_on: }
|
173
173
|
end
|
174
174
|
|
175
175
|
let!(:user) { create :user }
|
176
|
-
let(:
|
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
|
193
|
-
let(:
|
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
|
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
|
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
|