pg_rails 7.0.8.pre.alpha.50 → 7.0.8.pre.alpha.51
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/pg_engine/app/admin/mensaje_contactos.rb +28 -0
- data/pg_engine/app/controllers/concerns/pg_engine/resource.rb +1 -1
- data/pg_engine/app/controllers/public/mensaje_contactos_controller.rb +29 -0
- data/pg_engine/app/decorators/mensaje_contacto_decorator.rb +16 -0
- data/pg_engine/app/models/mensaje_contacto.rb +21 -0
- data/pg_engine/app/policies/mensaje_contacto_policy.rb +31 -0
- data/pg_engine/app/views/public/mensaje_contactos/_form.html.slim +14 -0
- data/pg_engine/app/views/public/mensaje_contactos/_gracias.html.slim +8 -0
- data/pg_engine/config/routes.rb +3 -0
- data/pg_engine/db/migrate/20240428152916_create_mensaje_contactos.rb +15 -0
- data/pg_engine/spec/controllers/public/mensaje_contactos_controller_spec.rb +91 -0
- data/pg_engine/spec/factories/mensaje_contactos.rb +12 -0
- data/pg_engine/spec/models/mensaje_contacto_spec.rb +13 -0
- data/pg_rails/lib/version.rb +1 -1
- metadata +12 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 12e2f8570100688111978d151d42a814178f2382d18b373455535f7b5d625216
|
4
|
+
data.tar.gz: e867b8911a1a67781515d30efbf3facf6ad31cb27c296444327016c3ad2fdbca
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e7bc0a0f4e182d2f0fc451278e779acb22c31de3e7939de6d9feeb5047590b972586a70c8f03823b648c1e298bfa9ca7cc9609748175f8de941bc03658e42476
|
7
|
+
data.tar.gz: e5b2f79ca65227fdf85761af0a96629405c0904c6f0027b3f16e001648470c375920c8b5eb2d550ae0b697e4784b95f791ec4d073d4d22ebb37f6d8ea73e9dd9
|
@@ -0,0 +1,28 @@
|
|
1
|
+
ActiveAdmin.register MensajeContacto do
|
2
|
+
permit_params :nombre, :email, :telefono, :mensaje
|
3
|
+
|
4
|
+
index do
|
5
|
+
selectable_column
|
6
|
+
id_column
|
7
|
+
column :nombre
|
8
|
+
column :email
|
9
|
+
column :telefono
|
10
|
+
column :mensaje
|
11
|
+
actions
|
12
|
+
end
|
13
|
+
|
14
|
+
filter :nombre
|
15
|
+
filter :email
|
16
|
+
filter :telefono
|
17
|
+
filter :mensaje
|
18
|
+
|
19
|
+
form do |f|
|
20
|
+
f.inputs do
|
21
|
+
f.input :nombre
|
22
|
+
f.input :email
|
23
|
+
f.input :telefono
|
24
|
+
f.input :mensaje
|
25
|
+
end
|
26
|
+
f.actions
|
27
|
+
end
|
28
|
+
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module PgEngine
|
2
2
|
module Resource
|
3
3
|
def self.included(clazz)
|
4
|
-
clazz.before_action :authenticate_user!
|
4
|
+
# clazz.before_action :authenticate_user!
|
5
5
|
clazz.helper_method :atributos_para_listar
|
6
6
|
clazz.helper_method :atributos_para_mostrar
|
7
7
|
clazz.helper_method :current_page_size
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# generado con pg_rails
|
4
|
+
|
5
|
+
module Public
|
6
|
+
class MensajeContactosController < PublicController
|
7
|
+
include PgEngine::Resource
|
8
|
+
|
9
|
+
before_action { @clase_modelo = MensajeContacto }
|
10
|
+
|
11
|
+
before_action(only: :index) { authorize MensajeContacto }
|
12
|
+
|
13
|
+
before_action :set_instancia_modelo, only: %i[new create]
|
14
|
+
|
15
|
+
def create
|
16
|
+
if @mensaje_contacto.save
|
17
|
+
render turbo_stream: turbo_stream.update('mensaje_contacto', partial: 'gracias')
|
18
|
+
else
|
19
|
+
render :new, status: :unprocessable_entity
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def atributos_permitidos
|
26
|
+
%i[nombre email telefono mensaje]
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# generado con pg_rails
|
4
|
+
|
5
|
+
class MensajeContactoDecorator < PgEngine::BaseDecorator
|
6
|
+
delegate_all
|
7
|
+
|
8
|
+
# Define presentation-specific methods here. Helpers are accessed through
|
9
|
+
# `helpers` (aka `h`). You can override attributes, for example:
|
10
|
+
#
|
11
|
+
# def created_at
|
12
|
+
# helpers.content_tag :span, class: 'time' do
|
13
|
+
# object.created_at.strftime("%a %m/%d/%y")
|
14
|
+
# end
|
15
|
+
# end
|
16
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# == Schema Information
|
4
|
+
#
|
5
|
+
# Table name: mensaje_contactos
|
6
|
+
#
|
7
|
+
# id :bigint not null, primary key
|
8
|
+
# email :string
|
9
|
+
# mensaje :string
|
10
|
+
# nombre :string
|
11
|
+
# telefono :string
|
12
|
+
# created_at :datetime not null
|
13
|
+
# updated_at :datetime not null
|
14
|
+
#
|
15
|
+
|
16
|
+
class MensajeContacto < ApplicationRecord
|
17
|
+
audited
|
18
|
+
|
19
|
+
validates :nombre, :email, :mensaje, presence: true
|
20
|
+
validates_format_of :email, with: /\A[^@\s]+@[^@\s]+\z/
|
21
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# generado con pg_rails
|
4
|
+
|
5
|
+
class MensajeContactoPolicy < ApplicationPolicy
|
6
|
+
class Scope < ApplicationPolicy::Scope
|
7
|
+
# def resolve
|
8
|
+
# if policy.acceso_total?
|
9
|
+
# scope.all
|
10
|
+
# else
|
11
|
+
# scope.none
|
12
|
+
# end
|
13
|
+
# end
|
14
|
+
end
|
15
|
+
|
16
|
+
# def puede_editar?
|
17
|
+
# acceso_total? && !record.readonly?
|
18
|
+
# end
|
19
|
+
|
20
|
+
# def puede_crear?
|
21
|
+
# acceso_total? || user.asesor?
|
22
|
+
# end
|
23
|
+
|
24
|
+
# def puede_borrar?
|
25
|
+
# acceso_total? && !record.readonly?
|
26
|
+
# end
|
27
|
+
|
28
|
+
def acceso_total?
|
29
|
+
true
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
/ # locals: (object: nil, asociable: false)
|
2
|
+
#mensaje_contacto.text-center
|
3
|
+
.d-inline-block style="width: 22em; max-width: 100%"
|
4
|
+
div data-controller="pg_form"
|
5
|
+
= pg_form_for(@mensaje_contacto || object, asociable:) do |f|
|
6
|
+
= f.mensajes_de_error
|
7
|
+
|
8
|
+
= hidden_field_tag :asociable, true if asociable
|
9
|
+
= f.input :nombre
|
10
|
+
= f.input :email
|
11
|
+
= f.input :telefono, hint: '(Opcional)'
|
12
|
+
= f.input :mensaje, as: :text
|
13
|
+
.mt-2
|
14
|
+
= f.button :submit, value: 'Enviar'
|
data/pg_engine/config/routes.rb
CHANGED
@@ -1,6 +1,9 @@
|
|
1
1
|
include PgEngine::RouteHelpers
|
2
2
|
|
3
3
|
Rails.application.routes.draw do
|
4
|
+
namespace :public, path: '' do
|
5
|
+
pg_resource(:mensaje_contactos, only: [:new, :create], path: 'contacto')
|
6
|
+
end
|
4
7
|
devise_for :users, controllers: {
|
5
8
|
confirmations: 'users/confirmations',
|
6
9
|
registrations: 'users/registrations'
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# generado con pg_rails
|
2
|
+
|
3
|
+
class CreateMensajeContactos < ActiveRecord::Migration[7.1]
|
4
|
+
def change
|
5
|
+
create_table :mensaje_contactos do |t|
|
6
|
+
t.string :nombre
|
7
|
+
t.string :email
|
8
|
+
t.string :telefono
|
9
|
+
t.string :mensaje
|
10
|
+
|
11
|
+
t.timestamps
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,91 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# generado con pg_rails
|
4
|
+
|
5
|
+
require 'rails_helper'
|
6
|
+
|
7
|
+
# This spec was generated by rspec-rails when you ran the scaffold generator.
|
8
|
+
# It demonstrates how one might use RSpec to specify the controller code that
|
9
|
+
# was generated by Rails when you ran the scaffold generator.
|
10
|
+
#
|
11
|
+
# It assumes that the implementation code is generated by the rails scaffold
|
12
|
+
# generator. If you are using any extension libraries to generate different
|
13
|
+
# controller code, this generated spec may or may not pass.
|
14
|
+
#
|
15
|
+
# It only uses APIs available in rails and/or rspec-rails. There are a number
|
16
|
+
# of tools you can use to make these specs even more expressive, but we're
|
17
|
+
# sticking to rails and rspec-rails APIs to keep things simple and stable.
|
18
|
+
#
|
19
|
+
# Compared to earlier versions of this generator, there is very limited use of
|
20
|
+
# stubs and message expectations in this spec. Stubs are only used when there
|
21
|
+
# is no simpler way to get a handle on the object needed for the example.
|
22
|
+
# Message expectations are only used when there is no simpler way to specify
|
23
|
+
# that an instance is receiving a specific message.
|
24
|
+
#
|
25
|
+
# Also compared to earlier versions of this generator, there are no longer any
|
26
|
+
# expectations of assigns and templates rendered. These features have been
|
27
|
+
# removed from Rails core in Rails 5, but can be added back in via the
|
28
|
+
# `rails-controller-testing` gem.
|
29
|
+
|
30
|
+
RSpec.describe Public::MensajeContactosController do
|
31
|
+
render_views
|
32
|
+
# This should return the minimal set of attributes required to create a valid
|
33
|
+
# MensajeContacto. As you add validations to MensajeContacto, be sure to
|
34
|
+
# adjust the attributes here as well.
|
35
|
+
let(:valid_attributes) do
|
36
|
+
attributes_for(:mensaje_contacto)
|
37
|
+
end
|
38
|
+
|
39
|
+
let(:invalid_attributes) do
|
40
|
+
{
|
41
|
+
nombre: nil
|
42
|
+
}
|
43
|
+
end
|
44
|
+
|
45
|
+
let(:logged_user) { create :user, :developer }
|
46
|
+
|
47
|
+
before do
|
48
|
+
sign_in logged_user if logged_user.present?
|
49
|
+
end
|
50
|
+
|
51
|
+
describe 'routing' do
|
52
|
+
it 'routes GET index correctly' do
|
53
|
+
route = { get: '/contacto/new' }
|
54
|
+
expect(route).to route_to(controller: 'public/mensaje_contactos', action: 'new')
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
describe 'GET #new' do
|
59
|
+
it 'returns a success response' do
|
60
|
+
get :new, params: {}
|
61
|
+
expect(response).to be_successful
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
describe 'POST #create' do
|
66
|
+
context 'with valid params' do
|
67
|
+
it 'creates a new MensajeContacto' do
|
68
|
+
expect do
|
69
|
+
post :create, params: { mensaje_contacto: valid_attributes }
|
70
|
+
end.to change(MensajeContacto, :count).by(1)
|
71
|
+
end
|
72
|
+
|
73
|
+
it 'redirects to the created mensaje_contacto' do
|
74
|
+
post :create, params: { mensaje_contacto: valid_attributes }
|
75
|
+
expect(response).to have_http_status(:ok)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
context 'with invalid params' do
|
80
|
+
it 'returns a unprocessable_entity response' do
|
81
|
+
post :create, params: { mensaje_contacto: invalid_attributes }
|
82
|
+
expect(response).to have_http_status(:unprocessable_entity)
|
83
|
+
end
|
84
|
+
|
85
|
+
it 'renders the new template' do
|
86
|
+
post :create, params: { mensaje_contacto: invalid_attributes }
|
87
|
+
expect(response).to render_template(:new)
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# generado con pg_rails
|
4
|
+
|
5
|
+
FactoryBot.define do
|
6
|
+
factory :mensaje_contacto do
|
7
|
+
nombre { Faker::Lorem.sentence }
|
8
|
+
email { Faker::Internet.email }
|
9
|
+
telefono { Faker::Lorem.sentence }
|
10
|
+
mensaje { Faker::Lorem.sentence }
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# generado con pg_rails
|
4
|
+
|
5
|
+
require 'rails_helper'
|
6
|
+
|
7
|
+
RSpec.describe MensajeContacto do
|
8
|
+
let(:mensaje_contacto) { create(:mensaje_contacto) }
|
9
|
+
|
10
|
+
it 'se persiste' do
|
11
|
+
expect(mensaje_contacto).to be_persisted
|
12
|
+
end
|
13
|
+
end
|
data/pg_rails/lib/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pg_rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 7.0.8.pre.alpha.
|
4
|
+
version: 7.0.8.pre.alpha.51
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Martín Rosso
|
@@ -846,6 +846,7 @@ files:
|
|
846
846
|
- pg_engine/app/admin/accounts.rb
|
847
847
|
- pg_engine/app/admin/audits.rb
|
848
848
|
- pg_engine/app/admin/dashboard.rb
|
849
|
+
- pg_engine/app/admin/mensaje_contactos.rb
|
849
850
|
- pg_engine/app/admin/user_accounts.rb
|
850
851
|
- pg_engine/app/admin/users.rb
|
851
852
|
- pg_engine/app/assets/javascripts/active_admin.js
|
@@ -858,9 +859,11 @@ files:
|
|
858
859
|
- pg_engine/app/controllers/pg_engine/base_controller.rb
|
859
860
|
- pg_engine/app/controllers/pg_engine/devise_controller.rb
|
860
861
|
- pg_engine/app/controllers/pg_engine/require_sign_in.rb
|
862
|
+
- pg_engine/app/controllers/public/mensaje_contactos_controller.rb
|
861
863
|
- pg_engine/app/controllers/users/confirmations_controller.rb
|
862
864
|
- pg_engine/app/controllers/users/registrations_controller.rb
|
863
865
|
- pg_engine/app/decorators/account_decorator.rb
|
866
|
+
- pg_engine/app/decorators/mensaje_contacto_decorator.rb
|
864
867
|
- pg_engine/app/decorators/pg_engine/base_decorator.rb
|
865
868
|
- pg_engine/app/decorators/user_account_decorator.rb
|
866
869
|
- pg_engine/app/decorators/user_decorator.rb
|
@@ -878,10 +881,12 @@ files:
|
|
878
881
|
- pg_engine/app/lib/pg_form_builder.rb
|
879
882
|
- pg_engine/app/models/account.rb
|
880
883
|
- pg_engine/app/models/current.rb
|
884
|
+
- pg_engine/app/models/mensaje_contacto.rb
|
881
885
|
- pg_engine/app/models/pg_engine/base_record.rb
|
882
886
|
- pg_engine/app/models/user.rb
|
883
887
|
- pg_engine/app/models/user_account.rb
|
884
888
|
- pg_engine/app/policies/account_policy.rb
|
889
|
+
- pg_engine/app/policies/mensaje_contacto_policy.rb
|
885
890
|
- pg_engine/app/policies/pg_engine/application_policy.rb
|
886
891
|
- pg_engine/app/policies/user_account_policy.rb
|
887
892
|
- pg_engine/app/policies/user_policy.rb
|
@@ -904,6 +909,8 @@ files:
|
|
904
909
|
- pg_engine/app/views/pg_engine/base/edit.html.slim
|
905
910
|
- pg_engine/app/views/pg_engine/base/index.html.slim
|
906
911
|
- pg_engine/app/views/pg_engine/base/new.html.slim
|
912
|
+
- pg_engine/app/views/public/mensaje_contactos/_form.html.slim
|
913
|
+
- pg_engine/app/views/public/mensaje_contactos/_gracias.html.slim
|
907
914
|
- pg_engine/config/initializers/action_mailer.rb
|
908
915
|
- pg_engine/config/initializers/active_admin.rb
|
909
916
|
- pg_engine/config/initializers/anycable.rb
|
@@ -925,6 +932,7 @@ files:
|
|
925
932
|
- pg_engine/db/migrate/20240222115722_create_active_storage_tables.active_storage.rb
|
926
933
|
- pg_engine/db/migrate/20240305200900_nombre_user.rb
|
927
934
|
- pg_engine/db/migrate/20240314114503_remove_hash_ids.rb
|
935
|
+
- pg_engine/db/migrate/20240428152916_create_mensaje_contactos.rb
|
928
936
|
- pg_engine/db/seeds.rb
|
929
937
|
- pg_engine/lib/pg_engine.rb
|
930
938
|
- pg_engine/lib/pg_engine/configuracion.rb
|
@@ -941,9 +949,11 @@ files:
|
|
941
949
|
- pg_engine/spec/controllers/concerns/pg_engine/resource_helper_spec.rb
|
942
950
|
- pg_engine/spec/controllers/devise/sessions_controller_spec.rb
|
943
951
|
- pg_engine/spec/controllers/pg_engine/base_controller_spec.rb
|
952
|
+
- pg_engine/spec/controllers/public/mensaje_contactos_controller_spec.rb
|
944
953
|
- pg_engine/spec/controllers/users/confirmations_controller_spec.rb
|
945
954
|
- pg_engine/spec/controllers/users/registrations_controller_spec.rb
|
946
955
|
- pg_engine/spec/factories/accounts.rb
|
956
|
+
- pg_engine/spec/factories/mensaje_contactos.rb
|
947
957
|
- pg_engine/spec/factories/user_accounts.rb
|
948
958
|
- pg_engine/spec/factories/users.rb
|
949
959
|
- pg_engine/spec/fixtures/test.pdf
|
@@ -952,6 +962,7 @@ files:
|
|
952
962
|
- pg_engine/spec/lib/pg_engine/utils/pg_engine/pg_logger_spec.rb
|
953
963
|
- pg_engine/spec/lib/pg_form_builder_spec.rb
|
954
964
|
- pg_engine/spec/models/account_spec.rb
|
965
|
+
- pg_engine/spec/models/mensaje_contacto_spec.rb
|
955
966
|
- pg_engine/spec/models/pg_engine/base_record_spec.rb
|
956
967
|
- pg_engine/spec/models/user_account_spec.rb
|
957
968
|
- pg_engine/spec/models/user_spec.rb
|