pg_rails 7.0.1 → 7.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (162) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +6 -4
  3. data/pg_associable/app/assets/css/pg_associable.scss +99 -0
  4. data/pg_associable/app/assets/js/asociable_controller.js +59 -0
  5. data/pg_associable/app/assets/js/asociable_inline_controller.js +141 -0
  6. data/pg_associable/app/assets/js/modal_controller.js +130 -0
  7. data/pg_associable/app/helpers/pg_associable/form_builder_methods.rb +31 -0
  8. data/pg_associable/app/helpers/pg_associable/helpers.rb +19 -0
  9. data/pg_associable/app/inputs/pg_associable/pg_associable_inline_input.rb +39 -0
  10. data/pg_associable/app/inputs/pg_associable/pg_associable_input.rb +41 -0
  11. data/pg_associable/app/views/pg_associable/_resultados.html.slim +9 -0
  12. data/pg_associable/app/views/pg_associable/_resultados_inline.html.slim +12 -0
  13. data/pg_associable/app/views/pg_engine/base/_pg_associable_modal.html.slim +39 -0
  14. data/pg_associable/index.js +7 -0
  15. data/pg_associable/lib/pg_associable/engine.rb +12 -0
  16. data/pg_associable/lib/pg_associable/simple_form_initializer.rb +34 -0
  17. data/pg_associable/lib/pg_associable.rb +5 -0
  18. data/{lib/tasks/pg_rails_tasks.rake → pg_associable/lib/tasks/pg_associable_tasks.rake} +1 -2
  19. data/pg_engine/app/assets/stylesheets/pg_rails_b5.scss +74 -0
  20. data/pg_engine/app/controllers/pg_engine/base_controller.rb +365 -0
  21. data/pg_engine/app/controllers/pg_engine/devise_controller.rb +9 -0
  22. data/pg_engine/app/controllers/pg_engine/signed_in_controller.rb +7 -0
  23. data/{app/decorators/pg_rails → pg_engine/app/decorators/pg_engine}/base_decorator.rb +21 -23
  24. data/pg_engine/app/helpers/pg_engine/flash_helper.rb +26 -0
  25. data/pg_engine/app/helpers/pg_engine/form_helper.rb +33 -0
  26. data/pg_engine/app/helpers/pg_engine/index_helper.rb +42 -0
  27. data/{app/helpers/pg_rails → pg_engine/app/helpers/pg_engine}/postgres_helper.rb +1 -1
  28. data/{app/helpers/pg_rails → pg_engine/app/helpers/pg_engine}/print_helper.rb +15 -31
  29. data/pg_engine/app/helpers/pg_engine/route_helper.rb +41 -0
  30. data/pg_engine/app/inputs/pg_engine/fecha_input.rb +20 -0
  31. data/{app/lib/pg_rails → pg_engine/app/lib/pg_engine}/filtros_builder.rb +16 -17
  32. data/pg_engine/app/lib/pg_form_builder.rb +22 -0
  33. data/pg_engine/app/models/pg_engine/base_record.rb +63 -0
  34. data/{app/policies/pg_rails → pg_engine/app/policies/pg_engine}/application_policy.rb +2 -2
  35. data/pg_engine/app/views/pg_engine/base/download.xlsx.axlsx +14 -0
  36. data/pg_engine/app/views/pg_engine/base/index.html.slim +51 -0
  37. data/pg_engine/config/locales/es.yml +48 -0
  38. data/pg_engine/config/simple_form/simple_form.rb +178 -0
  39. data/pg_engine/config/simple_form/simple_form_bootstrap.rb +371 -0
  40. data/{lib/pg_rails → pg_engine/lib/pg_engine}/configuracion.rb +3 -1
  41. data/pg_engine/lib/pg_engine/engine.rb +53 -0
  42. data/{lib/pg_rails → pg_engine/lib/pg_engine}/utils/logueador.rb +8 -1
  43. data/pg_engine/lib/pg_engine.rb +35 -0
  44. data/{lib → pg_engine/lib}/tasks/auto_anotar_modelos.rake +1 -1
  45. data/pg_engine/lib/templates/activeadmin/audits.rb +53 -0
  46. data/pg_engine/lib/templates/activeadmin/users.rb +54 -0
  47. data/pg_layout/app/assets/stylesheets/sidebar.scss +106 -0
  48. data/pg_layout/app/javascript/cookies.js +23 -0
  49. data/pg_layout/app/javascript/navbar_controller.js +10 -0
  50. data/pg_layout/app/lib/navbar.rb +61 -0
  51. data/pg_layout/app/views/devise/confirmations/new.html.erb +20 -0
  52. data/pg_layout/app/views/devise/mailer/confirmation_instructions.html.erb +5 -0
  53. data/pg_layout/app/views/devise/mailer/email_changed.html.erb +7 -0
  54. data/pg_layout/app/views/devise/mailer/password_change.html.erb +3 -0
  55. data/pg_layout/app/views/devise/mailer/reset_password_instructions.html.erb +8 -0
  56. data/pg_layout/app/views/devise/mailer/unlock_instructions.html.erb +7 -0
  57. data/pg_layout/app/views/devise/passwords/edit.html.erb +27 -0
  58. data/pg_layout/app/views/devise/passwords/new.html.erb +18 -0
  59. data/pg_layout/app/views/devise/registrations/edit.html.erb +35 -0
  60. data/pg_layout/app/views/devise/registrations/new.html.erb +25 -0
  61. data/pg_layout/app/views/devise/sessions/new.html.erb +20 -0
  62. data/pg_layout/app/views/devise/shared/_error_messages.html.erb +15 -0
  63. data/pg_layout/app/views/devise/shared/_links.html.erb +25 -0
  64. data/pg_layout/app/views/devise/unlocks/new.html.erb +19 -0
  65. data/pg_layout/app/views/kaminari/_first_page.html.slim +3 -0
  66. data/pg_layout/app/views/kaminari/_gap.html.slim +2 -0
  67. data/pg_layout/app/views/kaminari/_last_page.html.slim +3 -0
  68. data/pg_layout/app/views/kaminari/_next_page.html.slim +3 -0
  69. data/pg_layout/app/views/kaminari/_page.html.slim +6 -0
  70. data/pg_layout/app/views/kaminari/_paginator.html.slim +12 -0
  71. data/pg_layout/app/views/kaminari/_prev_page.html.slim +3 -0
  72. data/pg_layout/app/views/layouts/pg_layout/devise.html.slim +24 -0
  73. data/pg_layout/app/views/layouts/pg_layout/layout.html.slim +30 -0
  74. data/pg_layout/app/views/pg_layout/_flash.html.slim +10 -0
  75. data/pg_layout/app/views/pg_layout/_navbar.html.erb +43 -0
  76. data/pg_layout/app/views/pg_layout/_sidebar.html.erb +42 -0
  77. data/pg_layout/index.js +35 -0
  78. data/pg_layout/lib/pg_layout/engine.rb +7 -0
  79. data/pg_layout/lib/pg_layout.rb +9 -0
  80. data/pg_rails/js/index.js +2 -0
  81. data/pg_rails/lib/pg_rails.rb +7 -0
  82. data/{lib/pg_rails → pg_rails/lib}/version.rb +1 -1
  83. data/pg_rails/scss/pg_rails.scss +3 -0
  84. data/pg_scaffold/lib/generators/pg_active_record/model/model_generator.rb +34 -0
  85. data/pg_scaffold/lib/generators/pg_active_record/model/templates/admin.rb +19 -0
  86. data/pg_scaffold/lib/generators/pg_active_record/model/templates/create_table_migration.rb.tt +46 -0
  87. data/pg_scaffold/lib/generators/pg_active_record/model/templates/migration.rb.tt +48 -0
  88. data/pg_scaffold/lib/generators/pg_active_record/model/templates/model.rb +47 -0
  89. data/pg_scaffold/lib/generators/pg_active_record/model/templates/module.rb +9 -0
  90. data/pg_scaffold/lib/generators/pg_decorator/USAGE +8 -0
  91. data/pg_scaffold/lib/generators/pg_decorator/pg_decorator_generator.rb +31 -0
  92. data/pg_scaffold/lib/generators/pg_decorator/templates/decorator.rb +22 -0
  93. data/pg_scaffold/lib/generators/pg_factory_bot/model/model_generator.rb +95 -0
  94. data/pg_scaffold/lib/generators/pg_factory_bot/model/templates/factories.erb +14 -0
  95. data/pg_scaffold/lib/generators/pg_pundit/USAGE +8 -0
  96. data/pg_scaffold/lib/generators/pg_pundit/pg_pundit_generator.rb +21 -0
  97. data/pg_scaffold/lib/generators/pg_pundit/templates/policy.rb +37 -0
  98. data/pg_scaffold/lib/generators/pg_rails/instalar/USAGE +8 -0
  99. data/pg_scaffold/lib/generators/pg_rails/instalar/instalar_generator.rb +17 -0
  100. data/pg_scaffold/lib/generators/pg_rails/instalar/templates/pg_rails.rb +10 -0
  101. data/pg_scaffold/lib/generators/pg_resource_route/pg_resource_route_generator.rb +27 -0
  102. data/pg_scaffold/lib/generators/pg_rspec/model/model_generator.rb +30 -0
  103. data/pg_scaffold/lib/generators/pg_rspec/model/templates/model_spec.rb +15 -0
  104. data/pg_scaffold/lib/generators/pg_rspec/scaffold/scaffold_generator.rb +43 -0
  105. data/pg_scaffold/lib/generators/pg_rspec/scaffold/templates/api_controller_spec.rb +167 -0
  106. data/pg_scaffold/lib/generators/pg_rspec/scaffold/templates/controller_spec.rb +269 -0
  107. data/pg_scaffold/lib/generators/pg_rspec/scaffold/templates/edit_spec.rb +34 -0
  108. data/pg_scaffold/lib/generators/pg_rspec/scaffold/templates/index_spec.rb +28 -0
  109. data/pg_scaffold/lib/generators/pg_rspec/scaffold/templates/new_spec.rb +34 -0
  110. data/pg_scaffold/lib/generators/pg_rspec/scaffold/templates/routing_spec.rb +50 -0
  111. data/pg_scaffold/lib/generators/pg_rspec/scaffold/templates/show_spec.rb +26 -0
  112. data/pg_scaffold/lib/generators/pg_scaffold/USAGE +8 -0
  113. data/pg_scaffold/lib/generators/pg_scaffold/pg_scaffold_generator.rb +87 -0
  114. data/pg_scaffold/lib/generators/pg_scaffold/templates/controller.rb +37 -0
  115. data/pg_scaffold/lib/generators/pg_slim/USAGE +8 -0
  116. data/pg_scaffold/lib/generators/pg_slim/pg_slim_generator.rb +31 -0
  117. data/pg_scaffold/lib/generators/pg_slim/templates/_form.html.slim +12 -0
  118. data/pg_scaffold/lib/generators/pg_slim/templates/download.xlsx.axlsx +14 -0
  119. data/pg_scaffold/lib/generators/pg_slim/templates/edit.html.slim +5 -0
  120. data/pg_scaffold/lib/generators/pg_slim/templates/index.html.slim +51 -0
  121. data/pg_scaffold/lib/generators/pg_slim/templates/new.html.slim +5 -0
  122. data/pg_scaffold/lib/generators/pg_slim/templates/partial.html.slim +1 -0
  123. data/pg_scaffold/lib/generators/pg_slim/templates/show.html.slim +38 -0
  124. data/pg_scaffold/lib/pg_scaffold/monkey_patches/mejoras_a_named_base.rb +37 -0
  125. data/pg_scaffold/lib/pg_scaffold/monkey_patches/mejoras_de_atributos.rb +116 -0
  126. data/pg_scaffold/lib/pg_scaffold/railtie.rb +16 -0
  127. data/pg_scaffold/lib/pg_scaffold.rb +4 -0
  128. metadata +134 -48
  129. data/Rakefile +0 -36
  130. data/app/assets/javascripts/pg_rails/asociacion_creable.js +0 -85
  131. data/app/assets/javascripts/pg_rails/best_in_place_datepicker.js +0 -58
  132. data/app/assets/javascripts/pg_rails/librerias.js +0 -13
  133. data/app/assets/javascripts/pg_rails/librerias_b3.js +0 -14
  134. data/app/assets/javascripts/pg_rails/validaciones.js +0 -44
  135. data/app/assets/javascripts/pg_rails.js +0 -318
  136. data/app/assets/stylesheets/pg_rails/librerias.scss +0 -5
  137. data/app/assets/stylesheets/pg_rails/pg_chosen.scss +0 -29
  138. data/app/assets/stylesheets/pg_rails/pg_rails.scss +0 -199
  139. data/app/assets/stylesheets/pg_rails_b3.scss +0 -10
  140. data/app/assets/stylesheets/pg_rails_b4.scss +0 -12
  141. data/app/assets/stylesheets/pg_rails_b5.scss +0 -1
  142. data/app/controllers/pg_rails/application_controller.rb +0 -316
  143. data/app/controllers/pg_rails/editar_en_lugar_controller.rb +0 -24
  144. data/app/helpers/pg_rails/editar_en_lugar_helper.rb +0 -106
  145. data/app/helpers/pg_rails/form_helper.rb +0 -25
  146. data/app/inputs/pg_rails/asociacion_creable_input.rb +0 -72
  147. data/app/inputs/pg_rails/fecha_input.rb +0 -20
  148. data/app/inputs/pg_rails/selects_dependientes_input.rb +0 -9
  149. data/app/lib/pg_form_builder.rb +0 -31
  150. data/app/models/pg_rails/application_record.rb +0 -51
  151. data/app/views/application/_abrir_modal.js.erb +0 -14
  152. data/app/views/application/_actualizar_smart_listing.html.slim +0 -3
  153. data/app/views/application/_cerrar_modal.js.erb +0 -8
  154. data/app/views/application/_modal_ajax_form.js.erb +0 -7
  155. data/config/brakeman.ignore +0 -42
  156. data/config/locales/es.yml +0 -17
  157. data/config/routes.rb +0 -3
  158. data/config/spring.rb +0 -1
  159. data/lib/pg_rails/engine.rb +0 -42
  160. data/lib/pg_rails/simple_form/initializer.rb +0 -583
  161. data/lib/pg_rails.rb +0 -23
  162. /data/{lib/pg_rails → pg_engine/lib/pg_engine}/core_ext.rb +0 -0
@@ -0,0 +1,10 @@
1
+ <%= clase_aplicacion %>.configure do
2
+ config.generators do |g|
3
+ g.fixture_replacement :pg_factory_bot, dir: 'spec/factories'
4
+ g.test_framework :pg_rspec
5
+ g.orm :pg_active_record
6
+
7
+ g.fallbacks[:pg_rspec] = :rspec
8
+ g.fallbacks[:pg_active_record] = :active_record
9
+ end
10
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ # require 'generators/rails/resource_route/resource_route_generator'
4
+
5
+ class PgResourceRouteGenerator < Rails::Generators::NamedBase
6
+ source_root File.expand_path('templates', __dir__)
7
+
8
+ # Properly nests namespaces passed into a generator
9
+ #
10
+ # $ bin/rails generate resource admin/users/products
11
+ #
12
+ # should give you
13
+ #
14
+ # namespace :admin do
15
+ # namespace :users do
16
+ # resources :products
17
+ # end
18
+ # end
19
+ def add_resource_route
20
+ return if options[:actions].present?
21
+
22
+ route_s = <<~RUBY
23
+ PgEngine.resource_route(self, :#{file_name.pluralize})
24
+ RUBY
25
+ route route_s, namespace: regular_class_path
26
+ end
27
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'generators/rspec/model/model_generator'
4
+
5
+ module PgRspec
6
+ module Generators
7
+ class ModelGenerator < Rspec::Generators::ModelGenerator
8
+ # agrego la carpeta para que busque templates
9
+ # manteniendo la source_root de Rspec::Generators::ScaffoldGenerator
10
+ # para poder copiar sólo los que quiero cambiar
11
+ source_paths << File.expand_path('templates', __dir__)
12
+
13
+ remove_hook_for :fixture_replacement
14
+
15
+ invoke 'pg_factory_bot:model'
16
+
17
+ # Esto quizas no es necesario
18
+ def namespace
19
+ nil
20
+ end
21
+
22
+ # :doc:
23
+ def class_path
24
+ []
25
+ end
26
+
27
+ def create_module_file; end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ # generado con pg_rails
4
+
5
+ require 'rails_helper'
6
+
7
+ <% module_namespacing do -%>
8
+ RSpec.describe <%= class_name %> do
9
+ let(:<%= singular_name %>) { create(:<%= singular_table_name %>) }
10
+
11
+ it 'se persiste' do
12
+ expect(<%= singular_name %>).to be_persisted
13
+ end
14
+ end
15
+ <% end -%>
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'generators/rspec/scaffold/scaffold_generator'
4
+
5
+ module PgRspec
6
+ module Generators
7
+ class ScaffoldGenerator < Rspec::Generators::ScaffoldGenerator
8
+ # agrego la carpeta para que busque templates
9
+ # manteniendo la source_root de Rspec::Generators::ScaffoldGenerator
10
+ # para poder copiar sólo los que quiero cambiar
11
+ source_paths << File.expand_path('templates', __dir__)
12
+
13
+ class_option :paranoia, type: :boolean, default: false, desc: 'Paranoid y deleted_at.'
14
+ class_option :discard, type: :boolean, default: false, desc: 'Discard y discarded_at.'
15
+ class_option :trackeo_de_usuarios, type: :boolean, default: true,
16
+ desc: 'Genera campos creado_por y actualizado_por.'
17
+
18
+ class_option :controller_specs, type: :boolean, default: true
19
+ class_option :request_specs, type: :boolean, default: false
20
+ class_option :view_specs, type: :boolean, default: false
21
+
22
+ # remove_hook_for :integration_tool, as: :integration
23
+ # remove_hook_for :fixture_replacement
24
+
25
+ def generate_routing_spec
26
+ # piso el método para que no genere nada
27
+ end
28
+
29
+ protected
30
+
31
+ def referencias_requeridas
32
+ attributes.select { |at| at.reference? && at.required? }
33
+ end
34
+
35
+ def merge_referencias
36
+ return if referencias_requeridas.blank?
37
+
38
+ asd = referencias_requeridas.map { |r| "#{r.name}_id: #{r.name}.id" }
39
+ ".merge(#{asd.join(', ')})"
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,167 @@
1
+ # generado con pg_rails
2
+
3
+ require 'rails_helper'
4
+
5
+ # This spec was generated by rspec-rails when you ran the scaffold generator.
6
+ # It demonstrates how one might use RSpec to specify the controller code that
7
+ # was generated by Rails when you ran the scaffold generator.
8
+ #
9
+ # It assumes that the implementation code is generated by the rails scaffold
10
+ # generator. If you are using any extension libraries to generate different
11
+ # controller code, this generated spec may or may not pass.
12
+ #
13
+ # It only uses APIs available in rails and/or rspec-rails. There are a number
14
+ # of tools you can use to make these specs even more expressive, but we're
15
+ # sticking to rails and rspec-rails APIs to keep things simple and stable.
16
+ #
17
+ # Compared to earlier versions of this generator, there is very limited use of
18
+ # stubs and message expectations in this spec. Stubs are only used when there
19
+ # is no simpler way to get a handle on the object needed for the example.
20
+ # Message expectations are only used when there is no simpler way to specify
21
+ # that an instance is receiving a specific message.
22
+ #
23
+ # Also compared to earlier versions of this generator, there are no longer any
24
+ # expectations of assigns and templates rendered. These features have been
25
+ # removed from Rails core in Rails 5, but can be added back in via the
26
+ # `rails-controller-testing` gem.
27
+
28
+ <% module_namespacing do -%>
29
+ RSpec.describe <%= controller_class_name %>Controller, <%= type_metatag(:controller) %> do
30
+
31
+ # This should return the minimal set of attributes required to create a valid
32
+ # <%= class_name %>. As you add validations to <%= class_name %>, be sure to
33
+ # adjust the attributes here as well.
34
+ let(:valid_attributes) {
35
+ skip("Add a hash of attributes valid for your model")
36
+ }
37
+
38
+ let(:invalid_attributes) {
39
+ skip("Add a hash of attributes invalid for your model")
40
+ }
41
+
42
+ # This should return the minimal set of values that should be in the session
43
+ # in order to pass any filters (e.g. authentication) defined in
44
+ # <%= controller_class_name %>Controller. Be sure to keep this updated too.
45
+ let(:valid_session) { {} }
46
+
47
+ <% unless options[:singleton] -%>
48
+ describe "GET #index" do
49
+ it "returns a success response" do
50
+ <%= file_name %> = <%= class_name %>.create! valid_attributes
51
+ <% if RUBY_VERSION < '1.9.3' -%>
52
+ get :index, {}, valid_session
53
+ <% else -%>
54
+ get :index, params: {}, session: valid_session
55
+ <% end -%>
56
+ expect(response).to be_successful
57
+ end
58
+ end
59
+
60
+ <% end -%>
61
+ describe "GET #show" do
62
+ it "returns a success response" do
63
+ <%= file_name %> = <%= class_name %>.create! valid_attributes
64
+ <% if RUBY_VERSION < '1.9.3' -%>
65
+ get :show, {:id => <%= file_name %>.to_param}, valid_session
66
+ <% else -%>
67
+ get :show, params: {id: <%= file_name %>.to_param}, session: valid_session
68
+ <% end -%>
69
+ expect(response).to be_successful
70
+ end
71
+ end
72
+
73
+ describe "POST #create" do
74
+ context "with valid params" do
75
+ it "creates a new <%= class_name %>" do
76
+ expect {
77
+ <% if RUBY_VERSION < '1.9.3' -%>
78
+ post :create, {:<%= ns_file_name %> => valid_attributes}, valid_session
79
+ <% else -%>
80
+ post :create, params: {<%= ns_file_name %>: valid_attributes}, session: valid_session
81
+ <% end -%>
82
+ }.to change(<%= class_name %>, :count).by(1)
83
+ end
84
+
85
+ it "renders a JSON response with the new <%= ns_file_name %>" do
86
+ <% if RUBY_VERSION < '1.9.3' -%>
87
+ post :create, {:<%= ns_file_name %> => valid_attributes}, valid_session
88
+ <% else %>
89
+ post :create, params: {<%= ns_file_name %>: valid_attributes}, session: valid_session
90
+ <% end -%>
91
+ expect(response).to have_http_status(:created)
92
+ expect(response.content_type).to eq('application/json')
93
+ expect(response.location).to eq(<%= ns_file_name %>_url(<%= class_name %>.last))
94
+ end
95
+ end
96
+
97
+ context "with invalid params" do
98
+ it "renders a JSON response with errors for the new <%= ns_file_name %>" do
99
+ <% if RUBY_VERSION < '1.9.3' -%>
100
+ post :create, {:<%= ns_file_name %> => invalid_attributes}, valid_session
101
+ <% else %>
102
+ post :create, params: {<%= ns_file_name %>: invalid_attributes}, session: valid_session
103
+ <% end -%>
104
+ expect(response).to have_http_status(:unprocessable_entity)
105
+ expect(response.content_type).to eq('application/json')
106
+ end
107
+ end
108
+ end
109
+
110
+ describe "PUT #update" do
111
+ context "with valid params" do
112
+ let(:new_attributes) {
113
+ skip("Add a hash of attributes valid for your model")
114
+ }
115
+
116
+ it "updates the requested <%= ns_file_name %>" do
117
+ <%= file_name %> = <%= class_name %>.create! valid_attributes
118
+ <% if RUBY_VERSION < '1.9.3' -%>
119
+ put :update, {:id => <%= file_name %>.to_param, :<%= ns_file_name %> => new_attributes}, valid_session
120
+ <% else -%>
121
+ put :update, params: {id: <%= file_name %>.to_param, <%= ns_file_name %>: new_attributes}, session: valid_session
122
+ <% end -%>
123
+ <%= file_name %>.reload
124
+ skip("Add assertions for updated state")
125
+ end
126
+
127
+ it "renders a JSON response with the <%= ns_file_name %>" do
128
+ <%= file_name %> = <%= class_name %>.create! valid_attributes
129
+ <% if RUBY_VERSION < '1.9.3' -%>
130
+ put :update, {:id => <%= file_name %>.to_param, :<%= ns_file_name %> => valid_attributes}, valid_session
131
+ <% else %>
132
+ put :update, params: {id: <%= file_name %>.to_param, <%= ns_file_name %>: valid_attributes}, session: valid_session
133
+ <% end -%>
134
+ expect(response).to have_http_status(:ok)
135
+ expect(response.content_type).to eq('application/json')
136
+ end
137
+ end
138
+
139
+ context "with invalid params" do
140
+ it "renders a JSON response with errors for the <%= ns_file_name %>" do
141
+ <%= file_name %> = <%= class_name %>.create! valid_attributes
142
+ <% if RUBY_VERSION < '1.9.3' -%>
143
+ put :update, {:id => <%= file_name %>.to_param, :<%= ns_file_name %> => invalid_attributes}, valid_session
144
+ <% else %>
145
+ put :update, params: {id: <%= file_name %>.to_param, <%= ns_file_name %>: invalid_attributes}, session: valid_session
146
+ <% end -%>
147
+ expect(response).to have_http_status(:unprocessable_entity)
148
+ expect(response.content_type).to eq('application/json')
149
+ end
150
+ end
151
+ end
152
+
153
+ describe "DELETE #destroy" do
154
+ it "destroys the requested <%= ns_file_name %>" do
155
+ <%= file_name %> = <%= class_name %>.create! valid_attributes
156
+ expect {
157
+ <% if RUBY_VERSION < '1.9.3' -%>
158
+ delete :destroy, {:id => <%= file_name %>.to_param}, valid_session
159
+ <% else -%>
160
+ delete :destroy, params: {id: <%= file_name %>.to_param}, session: valid_session
161
+ <% end -%>
162
+ }.to change(<%= class_name %>, :count).by(-1)
163
+ end
164
+ end
165
+
166
+ end
167
+ <% end -%>
@@ -0,0 +1,269 @@
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
+ <% module_namespacing do -%>
31
+ RSpec.describe <%= controller_class_name %>Controller do
32
+ render_views
33
+ <% if mountable_engine? -%>
34
+ routes { <%= mountable_engine? %>::Engine.routes }
35
+
36
+ <% end -%>
37
+ <% referencias_requeridas.each do |atributo| -%>
38
+ let(:<%= atributo.name %>) { create :<%= atributo.name %> }
39
+
40
+ <% end -%>
41
+ # This should return the minimal set of attributes required to create a valid
42
+ # <%= class_name %>. As you add validations to <%= class_name %>, be sure to
43
+ # adjust the attributes here as well.
44
+ let(:valid_attributes) do
45
+ attributes_for(:<%= nombre_tabla_completo_singular %>)<%= merge_referencias %>
46
+ end
47
+ <% if attributes.any? { |at| at.required? } -%>
48
+ <% required_att = attributes.select { |at| at.required? }.first -%>
49
+
50
+ let(:invalid_attributes) do
51
+ {
52
+ <%= "#{required_att.name}: nil" %>
53
+ }
54
+ end
55
+ <% end -%>
56
+
57
+ let(:user) { create :user, :admin }
58
+
59
+ before do
60
+ sign_in user if user.present?
61
+ end
62
+
63
+ <% unless options[:singleton] -%>
64
+ describe 'GET #index' do
65
+ subject do
66
+ <% if Rails::VERSION::STRING < '5.0' -%>
67
+ get :index, {}
68
+ <% else -%>
69
+ get :index, params: {}
70
+ <% end -%>
71
+ end
72
+
73
+ let!(:<%= nombre_tabla_completo_singular %>) { create :<%= nombre_tabla_completo_singular %> }
74
+
75
+ it 'returns a success response' do
76
+ subject
77
+ expect(response).to be_successful
78
+ end
79
+
80
+ context 'when user is not logged in' do
81
+ let(:user) { nil }
82
+
83
+ it 'redirects to login path' do
84
+ subject
85
+ expect(response).to redirect_to(new_user_session_path)
86
+ end
87
+ end
88
+ <% if options[:discard] -%>
89
+
90
+ context 'when está descartado' do
91
+ before { <%= nombre_tabla_completo_singular %>.discard! }
92
+
93
+ it do
94
+ subject
95
+ expect(assigns(:collection)).to be_empty
96
+ end
97
+ end
98
+ <% end -%>
99
+
100
+ context 'when se pide el excel' do
101
+ subject do
102
+ get :index, params: {}, format: 'xlsx'
103
+ end
104
+
105
+ it 'returns a success response' do
106
+ subject
107
+ expect(response).to be_successful
108
+ end
109
+ end
110
+ end
111
+
112
+ <% end -%>
113
+ describe 'GET #show' do
114
+ it 'returns a success response' do
115
+ <%= file_name %> = create(:<%= nombre_tabla_completo_singular %>)
116
+ <% if Rails::VERSION::STRING < '5.0' -%>
117
+ get :show, { id: <%= file_name %>.to_param }
118
+ <% else -%>
119
+ get :show, params: { id: <%= file_name %>.to_param }
120
+ <% end -%>
121
+ expect(response).to be_successful
122
+ end
123
+ end
124
+
125
+ describe 'GET #new' do
126
+ it 'returns a success response' do
127
+ <% if Rails::VERSION::STRING < '5.0' -%>
128
+ get :new, {}
129
+ <% else -%>
130
+ get :new, params: {}
131
+ <% end -%>
132
+ expect(response).to be_successful
133
+ end
134
+ end
135
+
136
+ describe 'GET #edit' do
137
+ it 'returns a success response' do
138
+ <%= file_name %> = create(:<%= nombre_tabla_completo_singular %>)
139
+ <% if Rails::VERSION::STRING < '5.0' -%>
140
+ get :edit, { id: <%= file_name %>.to_param }
141
+ <% else -%>
142
+ get :edit, params: { id: <%= file_name %>.to_param }
143
+ <% end -%>
144
+ expect(response).to be_successful
145
+ end
146
+ end
147
+
148
+ describe 'POST #create' do
149
+ context 'with valid params' do
150
+ it 'creates a new <%= class_name %>' do
151
+ expect do
152
+ <% if Rails::VERSION::STRING < '5.0' -%>
153
+ post :create, { <%= nombre_tabla_completo_singular %>: valid_attributes }
154
+ <% else -%>
155
+ post :create, params: { <%= nombre_tabla_completo_singular %>: valid_attributes }
156
+ <% end -%>
157
+ end.to change(<%= class_name %>, :count).by(1)
158
+ end
159
+
160
+ it 'redirects to the created <%= nombre_tabla_completo_singular %>' do
161
+ <% if Rails::VERSION::STRING < '5.0' -%>
162
+ post :create, { <%= nombre_tabla_completo_singular %>: valid_attributes }
163
+ <% else -%>
164
+ post :create, params: { <%= nombre_tabla_completo_singular %>: valid_attributes }
165
+ <% end -%>
166
+ expect(response).to redirect_to(<%= class_name %>.last.decorate.target_object)
167
+ end
168
+ end
169
+ <% if attributes.any? { |at| at.required? } -%>
170
+
171
+ context 'with invalid params' do
172
+ it 'returns a unprocessable_entity response' do
173
+ post :create, params: { <%= nombre_tabla_completo_singular %>: invalid_attributes }
174
+ expect(response).to have_http_status(:unprocessable_entity)
175
+ end
176
+
177
+ it 'renders the new template' do
178
+ post :create, params: { <%= nombre_tabla_completo_singular %>: invalid_attributes }
179
+ expect(response).to render_template(:new)
180
+ end
181
+ end
182
+ <% end -%>
183
+ end
184
+
185
+ describe 'PUT #update' do
186
+ context 'with valid params' do
187
+ let(:new_attributes) do
188
+ attributes_for(:<%= nombre_tabla_completo_singular %>)
189
+ end
190
+
191
+ it 'updates the requested <%= nombre_tabla_completo_singular %>' do
192
+ <%= file_name %> = create(:<%= nombre_tabla_completo_singular %>)
193
+ <% if Rails::VERSION::STRING < '5.0' -%>
194
+ put :update, { id: <%= file_name %>.to_param, <%= nombre_tabla_completo_singular %>: new_attributes }
195
+ <% else -%>
196
+ put :update, params: { id: <%= file_name %>.to_param, <%= nombre_tabla_completo_singular %>: new_attributes }
197
+ <% end -%>
198
+ <%= file_name %>.reload
199
+ <% atributo = attributes.find { |at| !at.reference? && at.required? } -%>
200
+ <% if atributo.present? -%>
201
+ expect(<%= file_name%>.<%= atributo.name %>).to eq new_attributes[:<%= atributo.name %>]
202
+ <% else -%>
203
+ skip('Add assertions for updated state')
204
+ <% end -%>
205
+ end
206
+
207
+ it 'redirects to the <%= nombre_tabla_completo_singular %>' do
208
+ <%= file_name %> = create(:<%= nombre_tabla_completo_singular %>)
209
+ <% if Rails::VERSION::STRING < '5.0' -%>
210
+ put :update, { id: <%= file_name %>.to_param, <%= nombre_tabla_completo_singular %>: valid_attributes }
211
+ <% else -%>
212
+ put :update, params: { id: <%= file_name %>.to_param, <%= nombre_tabla_completo_singular %>: valid_attributes }
213
+ <% end -%>
214
+ expect(response).to redirect_to(<%= file_name %>.decorate.target_object)
215
+ end
216
+ end
217
+ <% if attributes.any? { |at| at.required? } -%>
218
+
219
+ context 'with invalid params' do
220
+ it 'returns a unprocessable_entity response' do
221
+ <%= file_name %> = create(:<%= nombre_tabla_completo_singular %>)
222
+ put :update, params: { id: <%= file_name %>.to_param, <%= nombre_tabla_completo_singular %>: invalid_attributes }
223
+ expect(response).to have_http_status(:unprocessable_entity)
224
+ end
225
+
226
+ it 'renders the edit template' do
227
+ <%= nombre_tabla_completo_singular %> = create(:<%= nombre_tabla_completo_singular %>)
228
+ put :update, params: { id: <%= nombre_tabla_completo_singular %>.to_param, <%= nombre_tabla_completo_singular %>: invalid_attributes }
229
+ expect(response).to render_template(:edit)
230
+ end
231
+ end
232
+ <% end -%>
233
+ end
234
+
235
+ describe 'DELETE #destroy' do
236
+ subject do
237
+ <% if Rails::VERSION::STRING < '5.0' -%>
238
+ delete :destroy, { id: <%= file_name %>.to_param }
239
+ <% else -%>
240
+ delete :destroy, params: { id: <%= file_name %>.to_param }
241
+ <% end -%>
242
+ end
243
+
244
+ let!(:<%= nombre_tabla_completo_singular %>) { create :<%= nombre_tabla_completo_singular %> }
245
+
246
+ it 'destroys the requested <%= nombre_tabla_completo_singular %>' do
247
+ <% if options[:discard] -%>
248
+ expect { subject }.to change(<%= class_name %>.kept, :count).by(-1)
249
+ <% elsif options[:paranoia] -%>
250
+ expect { subject }.to change(<%= class_name %>.without_deleted, :count).by(-1)
251
+ <% else -%>
252
+ expect { subject }.to change(<%= class_name %>, :count).by(-1)
253
+ <% end -%>
254
+ end
255
+
256
+ <% if options[:discard] -%>
257
+ it 'setea el discarded_at' do
258
+ subject
259
+ expect(<%= nombre_tabla_completo_singular %>.reload.discarded_at).to be_present
260
+ end
261
+
262
+ <% end -%>
263
+ it 'redirects to the <%= table_name %> list' do
264
+ subject
265
+ expect(response).to redirect_to(<%= index_helper %>_url)
266
+ end
267
+ end
268
+ end
269
+ <% end -%>
@@ -0,0 +1,34 @@
1
+ # generado con pg_rails
2
+
3
+ require 'rails_helper'
4
+
5
+ <% output_attributes = attributes.reject{|attribute| [:datetime, :timestamp, :time, :date].index(attribute.type) } -%>
6
+ RSpec.describe "<%= ruta_vistas %>/edit", <%= type_metatag(:view) %> do
7
+ PgRails::ConfiguradorRSpec.helpers(self)
8
+ <% if mountable_engine? -%>
9
+ helper <%= mountable_engine? %>::Engine.routes.url_helpers
10
+ <% end -%>
11
+
12
+ let(:user) { create(:user, :admin) }
13
+
14
+ before(:each) do
15
+ sign_in user
16
+ @<%= singular_name %> = assign(:<%= singular_name %>, create(:<%= nombre_tabla_completo_singular %>).decorate)
17
+ @clase_modelo = assign(:clase_modelo, <%= nombre_clase_completo %>)
18
+ end
19
+
20
+ it "renders the edit <%= singular_name %> form" do
21
+ render
22
+
23
+ assert_select "form[action=?][method=?]", <%= ns_file_name %>_path(@<%= singular_name %>), "post" do
24
+ <% for attribute in output_attributes -%>
25
+ <%- name = attribute.respond_to?(:column_name) ? attribute.column_name : attribute.name %>
26
+ <% if Rails.version.to_f >= 5.1 -%>
27
+ assert_select "<%= attribute.input_type -%>[name=?]", "<%= ns_file_name %>[<%= name %>]"
28
+ <% else -%>
29
+ assert_select "<%= attribute.input_type -%>#<%= ns_file_name %>_<%= name %>[name=?]", "<%= ns_file_name %>[<%= name %>]"
30
+ <% end -%>
31
+ <% end -%>
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,28 @@
1
+ # generado con pg_rails
2
+
3
+ require 'rails_helper'
4
+
5
+ <% output_attributes = attributes.reject{|attribute| [:datetime, :timestamp, :time, :date].index(attribute.type) } -%>
6
+ RSpec.describe "<%= ruta_vistas %>/index", <%= type_metatag(:view) %> do
7
+ PgRails::ConfiguradorRSpec.helpers(self)
8
+ <% if mountable_engine? -%>
9
+ helper <%= mountable_engine? %>::Engine.routes.url_helpers
10
+ <% end -%>
11
+
12
+ let(:user) { create(:user, :admin) }
13
+ let!(:<%= plural_name %>) { create_list(:<%= nombre_tabla_completo_singular %>, rand(10..20))}
14
+
15
+ before(:each) do
16
+ sign_in user
17
+ @clase_modelo = assign(:clase_modelo, <%= nombre_clase_completo %>)
18
+ smart_listing_create :<%= plural_name %>, <%= nombre_clase_completo %>.all, partial: '<%= ruta_vistas %>/listing'
19
+
20
+ assign(:filtros, PgEngine::FiltrosBuilder.new(
21
+ self, <%= nombre_clase_completo %>, []))
22
+ end
23
+
24
+ it "renders a list of <%= ns_table_name %>" do
25
+ render
26
+ assert_select "table", 1
27
+ end
28
+ end
@@ -0,0 +1,34 @@
1
+ # generado con pg_rails
2
+
3
+ require 'rails_helper'
4
+
5
+ <% output_attributes = attributes.reject{|attribute| [:datetime, :timestamp, :time, :date].index(attribute.type) } -%>
6
+ RSpec.describe "<%= ruta_vistas %>/new", <%= type_metatag(:view) %> do
7
+ PgEngine::ConfiguradorRSpec.helpers(self)
8
+ <% if mountable_engine? -%>
9
+ helper <%= mountable_engine? %>::Engine.routes.url_helpers
10
+ <% end -%>
11
+
12
+ let(:user) { create(:user, :admin) }
13
+
14
+ before(:each) do
15
+ sign_in user
16
+ @<%= singular_name %> = assign(:<%= singular_name %>, build(:<%= nombre_tabla_completo_singular %>).decorate)
17
+ @clase_modelo = assign(:clase_modelo, <%= nombre_clase_completo %>)
18
+ end
19
+
20
+ it "renders new <%= ns_file_name %> form" do
21
+ render
22
+
23
+ assert_select "form[action=?][method=?]", <%= index_helper %>_path, "post" do
24
+ <% for attribute in output_attributes -%>
25
+ <%- name = attribute.respond_to?(:column_name) ? attribute.column_name : attribute.name %>
26
+ <% if Rails.version.to_f >= 5.1 -%>
27
+ assert_select "<%= attribute.input_type -%>[name=?]", "<%= ns_file_name %>[<%= name %>]"
28
+ <% else -%>
29
+ assert_select "<%= attribute.input_type -%>#<%= ns_file_name %>_<%= name %>[name=?]", "<%= ns_file_name %>[<%= name %>]"
30
+ <% end -%>
31
+ <% end -%>
32
+ end
33
+ end
34
+ end