pg_rails 7.0.1 → 7.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (166) 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_associable/spec/pg_associable/helpers_spec.rb +24 -0
  20. data/pg_engine/app/assets/stylesheets/pg_rails_b5.scss +74 -0
  21. data/pg_engine/app/controllers/pg_engine/base_controller.rb +82 -0
  22. data/pg_engine/app/controllers/pg_engine/devise_controller.rb +9 -0
  23. data/pg_engine/app/controllers/pg_engine/require_sign_in.rb +9 -0
  24. data/pg_engine/app/controllers/pg_engine/resource_helper.rb +289 -0
  25. data/{app/decorators/pg_rails → pg_engine/app/decorators/pg_engine}/base_decorator.rb +21 -23
  26. data/pg_engine/app/helpers/pg_engine/flash_helper.rb +28 -0
  27. data/pg_engine/app/helpers/pg_engine/form_helper.rb +33 -0
  28. data/pg_engine/app/helpers/pg_engine/index_helper.rb +42 -0
  29. data/{app/helpers/pg_rails → pg_engine/app/helpers/pg_engine}/postgres_helper.rb +1 -1
  30. data/{app/helpers/pg_rails → pg_engine/app/helpers/pg_engine}/print_helper.rb +15 -31
  31. data/pg_engine/app/helpers/pg_engine/route_helper.rb +43 -0
  32. data/pg_engine/app/inputs/pg_engine/fecha_input.rb +20 -0
  33. data/{app/lib/pg_rails → pg_engine/app/lib/pg_engine}/filtros_builder.rb +16 -17
  34. data/pg_engine/app/lib/pg_form_builder.rb +22 -0
  35. data/pg_engine/app/models/pg_engine/base_record.rb +63 -0
  36. data/{app/policies/pg_rails → pg_engine/app/policies/pg_engine}/application_policy.rb +2 -2
  37. data/pg_engine/app/views/pg_engine/base/download.xlsx.axlsx +14 -0
  38. data/pg_engine/app/views/pg_engine/base/index.html.slim +51 -0
  39. data/pg_engine/config/locales/es.yml +48 -0
  40. data/pg_engine/config/simple_form/simple_form.rb +178 -0
  41. data/pg_engine/config/simple_form/simple_form_bootstrap.rb +371 -0
  42. data/{lib/pg_rails → pg_engine/lib/pg_engine}/configuracion.rb +3 -1
  43. data/pg_engine/lib/pg_engine/engine.rb +57 -0
  44. data/pg_engine/lib/pg_engine/route_helpers.rb +12 -0
  45. data/pg_engine/lib/pg_engine/utils/pg_logger.rb +44 -0
  46. data/{lib/pg_rails.rb → pg_engine/lib/pg_engine.rb} +6 -4
  47. data/{lib → pg_engine/lib}/tasks/auto_anotar_modelos.rake +1 -1
  48. data/pg_engine/lib/templates/activeadmin/audits.rb +53 -0
  49. data/pg_engine/lib/templates/activeadmin/users.rb +54 -0
  50. data/pg_layout/app/assets/stylesheets/sidebar.scss +110 -0
  51. data/pg_layout/app/javascript/cookies.js +23 -0
  52. data/pg_layout/app/javascript/navbar_controller.js +10 -0
  53. data/pg_layout/app/lib/navbar.rb +61 -0
  54. data/pg_layout/app/views/devise/confirmations/new.html.erb +20 -0
  55. data/pg_layout/app/views/devise/mailer/confirmation_instructions.html.erb +5 -0
  56. data/pg_layout/app/views/devise/mailer/email_changed.html.erb +7 -0
  57. data/pg_layout/app/views/devise/mailer/password_change.html.erb +3 -0
  58. data/pg_layout/app/views/devise/mailer/reset_password_instructions.html.erb +8 -0
  59. data/pg_layout/app/views/devise/mailer/unlock_instructions.html.erb +7 -0
  60. data/pg_layout/app/views/devise/passwords/edit.html.erb +27 -0
  61. data/pg_layout/app/views/devise/passwords/new.html.erb +18 -0
  62. data/pg_layout/app/views/devise/registrations/edit.html.erb +35 -0
  63. data/pg_layout/app/views/devise/registrations/new.html.erb +25 -0
  64. data/pg_layout/app/views/devise/sessions/new.html.erb +20 -0
  65. data/pg_layout/app/views/devise/shared/_error_messages.html.erb +15 -0
  66. data/pg_layout/app/views/devise/shared/_links.html.erb +25 -0
  67. data/pg_layout/app/views/devise/unlocks/new.html.erb +19 -0
  68. data/pg_layout/app/views/kaminari/_first_page.html.slim +3 -0
  69. data/pg_layout/app/views/kaminari/_gap.html.slim +2 -0
  70. data/pg_layout/app/views/kaminari/_last_page.html.slim +3 -0
  71. data/pg_layout/app/views/kaminari/_next_page.html.slim +3 -0
  72. data/pg_layout/app/views/kaminari/_page.html.slim +6 -0
  73. data/pg_layout/app/views/kaminari/_paginator.html.slim +12 -0
  74. data/pg_layout/app/views/kaminari/_prev_page.html.slim +3 -0
  75. data/pg_layout/app/views/layouts/pg_layout/devise.html.slim +24 -0
  76. data/pg_layout/app/views/layouts/pg_layout/layout.html.slim +31 -0
  77. data/pg_layout/app/views/pg_layout/_flash.html.slim +10 -0
  78. data/pg_layout/app/views/pg_layout/_navbar.html.erb +35 -0
  79. data/pg_layout/app/views/pg_layout/_sidebar.html.erb +42 -0
  80. data/pg_layout/index.js +35 -0
  81. data/pg_layout/lib/pg_layout/engine.rb +7 -0
  82. data/pg_layout/lib/pg_layout.rb +9 -0
  83. data/pg_rails/js/index.js +2 -0
  84. data/pg_rails/lib/pg_rails.rb +7 -0
  85. data/{lib/pg_rails → pg_rails/lib}/version.rb +1 -1
  86. data/pg_rails/scss/pg_rails.scss +3 -0
  87. data/pg_scaffold/lib/generators/pg_active_record/model/model_generator.rb +34 -0
  88. data/pg_scaffold/lib/generators/pg_active_record/model/templates/admin.rb +19 -0
  89. data/pg_scaffold/lib/generators/pg_active_record/model/templates/create_table_migration.rb.tt +46 -0
  90. data/pg_scaffold/lib/generators/pg_active_record/model/templates/migration.rb.tt +48 -0
  91. data/pg_scaffold/lib/generators/pg_active_record/model/templates/model.rb +46 -0
  92. data/pg_scaffold/lib/generators/pg_active_record/model/templates/module.rb +9 -0
  93. data/pg_scaffold/lib/generators/pg_decorator/USAGE +8 -0
  94. data/pg_scaffold/lib/generators/pg_decorator/pg_decorator_generator.rb +31 -0
  95. data/pg_scaffold/lib/generators/pg_decorator/templates/decorator.rb +22 -0
  96. data/pg_scaffold/lib/generators/pg_factory_bot/model/model_generator.rb +95 -0
  97. data/pg_scaffold/lib/generators/pg_factory_bot/model/templates/factories.erb +14 -0
  98. data/pg_scaffold/lib/generators/pg_pundit/USAGE +8 -0
  99. data/pg_scaffold/lib/generators/pg_pundit/pg_pundit_generator.rb +21 -0
  100. data/pg_scaffold/lib/generators/pg_pundit/templates/policy.rb +37 -0
  101. data/pg_scaffold/lib/generators/pg_rails/instalar/USAGE +8 -0
  102. data/pg_scaffold/lib/generators/pg_rails/instalar/instalar_generator.rb +17 -0
  103. data/pg_scaffold/lib/generators/pg_rails/instalar/templates/pg_rails.rb +10 -0
  104. data/pg_scaffold/lib/generators/pg_resource_route/pg_resource_route_generator.rb +27 -0
  105. data/pg_scaffold/lib/generators/pg_rspec/model/model_generator.rb +30 -0
  106. data/pg_scaffold/lib/generators/pg_rspec/model/templates/model_spec.rb +15 -0
  107. data/pg_scaffold/lib/generators/pg_rspec/scaffold/scaffold_generator.rb +43 -0
  108. data/pg_scaffold/lib/generators/pg_rspec/scaffold/templates/api_controller_spec.rb +167 -0
  109. data/pg_scaffold/lib/generators/pg_rspec/scaffold/templates/controller_spec.rb +276 -0
  110. data/pg_scaffold/lib/generators/pg_rspec/scaffold/templates/edit_spec.rb +34 -0
  111. data/pg_scaffold/lib/generators/pg_rspec/scaffold/templates/index_spec.rb +28 -0
  112. data/pg_scaffold/lib/generators/pg_rspec/scaffold/templates/new_spec.rb +34 -0
  113. data/pg_scaffold/lib/generators/pg_rspec/scaffold/templates/routing_spec.rb +50 -0
  114. data/pg_scaffold/lib/generators/pg_rspec/scaffold/templates/show_spec.rb +26 -0
  115. data/pg_scaffold/lib/generators/pg_scaffold/USAGE +8 -0
  116. data/pg_scaffold/lib/generators/pg_scaffold/pg_scaffold_generator.rb +81 -0
  117. data/pg_scaffold/lib/generators/pg_scaffold/templates/controller.rb +37 -0
  118. data/pg_scaffold/lib/generators/pg_slim/USAGE +8 -0
  119. data/pg_scaffold/lib/generators/pg_slim/pg_slim_generator.rb +31 -0
  120. data/pg_scaffold/lib/generators/pg_slim/templates/_form.html.slim +12 -0
  121. data/pg_scaffold/lib/generators/pg_slim/templates/download.xlsx.axlsx +14 -0
  122. data/pg_scaffold/lib/generators/pg_slim/templates/edit.html.slim +5 -0
  123. data/pg_scaffold/lib/generators/pg_slim/templates/index.html.slim +51 -0
  124. data/pg_scaffold/lib/generators/pg_slim/templates/new.html.slim +5 -0
  125. data/pg_scaffold/lib/generators/pg_slim/templates/partial.html.slim +1 -0
  126. data/pg_scaffold/lib/generators/pg_slim/templates/show.html.slim +38 -0
  127. data/pg_scaffold/lib/pg_scaffold/monkey_patches/mejoras_a_named_base.rb +37 -0
  128. data/pg_scaffold/lib/pg_scaffold/monkey_patches/mejoras_de_atributos.rb +116 -0
  129. data/pg_scaffold/lib/pg_scaffold/railtie.rb +16 -0
  130. data/pg_scaffold/lib/pg_scaffold.rb +4 -0
  131. data/pg_scaffold/spec/generators_spec.rb +55 -0
  132. metadata +138 -48
  133. data/Rakefile +0 -36
  134. data/app/assets/javascripts/pg_rails/asociacion_creable.js +0 -85
  135. data/app/assets/javascripts/pg_rails/best_in_place_datepicker.js +0 -58
  136. data/app/assets/javascripts/pg_rails/librerias.js +0 -13
  137. data/app/assets/javascripts/pg_rails/librerias_b3.js +0 -14
  138. data/app/assets/javascripts/pg_rails/validaciones.js +0 -44
  139. data/app/assets/javascripts/pg_rails.js +0 -318
  140. data/app/assets/stylesheets/pg_rails/librerias.scss +0 -5
  141. data/app/assets/stylesheets/pg_rails/pg_chosen.scss +0 -29
  142. data/app/assets/stylesheets/pg_rails/pg_rails.scss +0 -199
  143. data/app/assets/stylesheets/pg_rails_b3.scss +0 -10
  144. data/app/assets/stylesheets/pg_rails_b4.scss +0 -12
  145. data/app/assets/stylesheets/pg_rails_b5.scss +0 -1
  146. data/app/controllers/pg_rails/application_controller.rb +0 -316
  147. data/app/controllers/pg_rails/editar_en_lugar_controller.rb +0 -24
  148. data/app/helpers/pg_rails/editar_en_lugar_helper.rb +0 -106
  149. data/app/helpers/pg_rails/form_helper.rb +0 -25
  150. data/app/inputs/pg_rails/asociacion_creable_input.rb +0 -72
  151. data/app/inputs/pg_rails/fecha_input.rb +0 -20
  152. data/app/inputs/pg_rails/selects_dependientes_input.rb +0 -9
  153. data/app/lib/pg_form_builder.rb +0 -31
  154. data/app/models/pg_rails/application_record.rb +0 -51
  155. data/app/views/application/_abrir_modal.js.erb +0 -14
  156. data/app/views/application/_actualizar_smart_listing.html.slim +0 -3
  157. data/app/views/application/_cerrar_modal.js.erb +0 -8
  158. data/app/views/application/_modal_ajax_form.js.erb +0 -7
  159. data/config/brakeman.ignore +0 -42
  160. data/config/locales/es.yml +0 -17
  161. data/config/routes.rb +0 -3
  162. data/config/spring.rb +0 -1
  163. data/lib/pg_rails/engine.rb +0 -42
  164. data/lib/pg_rails/simple_form/initializer.rb +0 -583
  165. data/lib/pg_rails/utils/logueador.rb +0 -39
  166. /data/{lib/pg_rails → pg_engine/lib/pg_engine}/core_ext.rb +0 -0
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PgRails
4
+ class InstalarGenerator < Rails::Generators::Base
5
+ source_root File.expand_path('templates', __dir__)
6
+
7
+ def copy_application_policy
8
+ template 'pg_rails.rb', 'config/initializers/pg_rails.rb'
9
+ end
10
+
11
+ private
12
+
13
+ def clase_aplicacion
14
+ 'cosa'
15
+ end
16
+ end
17
+ end
@@ -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,276 @@
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
+ describe 'routing' do
64
+ it 'routes GET index correctly' do
65
+ route = { get: '/<%= controller_file_path %>' }
66
+ expect(route).to route_to(controller: '<%= controller_file_path %>', action: 'index')
67
+ end
68
+ end
69
+
70
+ <% unless options[:singleton] -%>
71
+ describe 'GET #index' do
72
+ subject do
73
+ <% if Rails::VERSION::STRING < '5.0' -%>
74
+ get :index, {}
75
+ <% else -%>
76
+ get :index, params: {}
77
+ <% end -%>
78
+ end
79
+
80
+ let!(:<%= nombre_tabla_completo_singular %>) { create :<%= nombre_tabla_completo_singular %> }
81
+
82
+ it 'returns a success response' do
83
+ subject
84
+ expect(response).to be_successful
85
+ end
86
+
87
+ context 'when user is not logged in' do
88
+ let(:user) { nil }
89
+
90
+ it 'redirects to login path' do
91
+ subject
92
+ expect(response).to redirect_to(new_user_session_path)
93
+ end
94
+ end
95
+ <% if options[:discard] -%>
96
+
97
+ context 'when está descartado' do
98
+ before { <%= nombre_tabla_completo_singular %>.discard! }
99
+
100
+ it do
101
+ subject
102
+ expect(assigns(:collection)).to be_empty
103
+ end
104
+ end
105
+ <% end -%>
106
+
107
+ context 'when se pide el excel' do
108
+ subject do
109
+ get :index, params: {}, format: 'xlsx'
110
+ end
111
+
112
+ it 'returns a success response' do
113
+ subject
114
+ expect(response).to be_successful
115
+ end
116
+ end
117
+ end
118
+
119
+ <% end -%>
120
+ describe 'GET #show' do
121
+ it 'returns a success response' do
122
+ <%= file_name %> = create(:<%= nombre_tabla_completo_singular %>)
123
+ <% if Rails::VERSION::STRING < '5.0' -%>
124
+ get :show, { id: <%= file_name %>.to_param }
125
+ <% else -%>
126
+ get :show, params: { id: <%= file_name %>.to_param }
127
+ <% end -%>
128
+ expect(response).to be_successful
129
+ end
130
+ end
131
+
132
+ describe 'GET #new' do
133
+ it 'returns a success response' do
134
+ <% if Rails::VERSION::STRING < '5.0' -%>
135
+ get :new, {}
136
+ <% else -%>
137
+ get :new, params: {}
138
+ <% end -%>
139
+ expect(response).to be_successful
140
+ end
141
+ end
142
+
143
+ describe 'GET #edit' do
144
+ it 'returns a success response' do
145
+ <%= file_name %> = create(:<%= nombre_tabla_completo_singular %>)
146
+ <% if Rails::VERSION::STRING < '5.0' -%>
147
+ get :edit, { id: <%= file_name %>.to_param }
148
+ <% else -%>
149
+ get :edit, params: { id: <%= file_name %>.to_param }
150
+ <% end -%>
151
+ expect(response).to be_successful
152
+ end
153
+ end
154
+
155
+ describe 'POST #create' do
156
+ context 'with valid params' do
157
+ it 'creates a new <%= class_name %>' do
158
+ expect do
159
+ <% if Rails::VERSION::STRING < '5.0' -%>
160
+ post :create, { <%= nombre_tabla_completo_singular %>: valid_attributes }
161
+ <% else -%>
162
+ post :create, params: { <%= nombre_tabla_completo_singular %>: valid_attributes }
163
+ <% end -%>
164
+ end.to change(<%= class_name %>, :count).by(1)
165
+ end
166
+
167
+ it 'redirects to the created <%= nombre_tabla_completo_singular %>' do
168
+ <% if Rails::VERSION::STRING < '5.0' -%>
169
+ post :create, { <%= nombre_tabla_completo_singular %>: valid_attributes }
170
+ <% else -%>
171
+ post :create, params: { <%= nombre_tabla_completo_singular %>: valid_attributes }
172
+ <% end -%>
173
+ expect(response).to redirect_to(<%= class_name %>.last.decorate.target_object)
174
+ end
175
+ end
176
+ <% if attributes.any? { |at| at.required? } -%>
177
+
178
+ context 'with invalid params' do
179
+ it 'returns a unprocessable_entity response' do
180
+ post :create, params: { <%= nombre_tabla_completo_singular %>: invalid_attributes }
181
+ expect(response).to have_http_status(:unprocessable_entity)
182
+ end
183
+
184
+ it 'renders the new template' do
185
+ post :create, params: { <%= nombre_tabla_completo_singular %>: invalid_attributes }
186
+ expect(response).to render_template(:new)
187
+ end
188
+ end
189
+ <% end -%>
190
+ end
191
+
192
+ describe 'PUT #update' do
193
+ context 'with valid params' do
194
+ let(:new_attributes) do
195
+ attributes_for(:<%= nombre_tabla_completo_singular %>)
196
+ end
197
+
198
+ it 'updates the requested <%= nombre_tabla_completo_singular %>' do
199
+ <%= file_name %> = create(:<%= nombre_tabla_completo_singular %>)
200
+ <% if Rails::VERSION::STRING < '5.0' -%>
201
+ put :update, { id: <%= file_name %>.to_param, <%= nombre_tabla_completo_singular %>: new_attributes }
202
+ <% else -%>
203
+ put :update, params: { id: <%= file_name %>.to_param, <%= nombre_tabla_completo_singular %>: new_attributes }
204
+ <% end -%>
205
+ <%= file_name %>.reload
206
+ <% atributo = attributes.find { |at| !at.reference? && at.required? } -%>
207
+ <% if atributo.present? -%>
208
+ expect(<%= file_name%>.<%= atributo.name %>).to eq new_attributes[:<%= atributo.name %>]
209
+ <% else -%>
210
+ skip('Add assertions for updated state')
211
+ <% end -%>
212
+ end
213
+
214
+ it 'redirects to the <%= nombre_tabla_completo_singular %>' do
215
+ <%= file_name %> = create(:<%= nombre_tabla_completo_singular %>)
216
+ <% if Rails::VERSION::STRING < '5.0' -%>
217
+ put :update, { id: <%= file_name %>.to_param, <%= nombre_tabla_completo_singular %>: valid_attributes }
218
+ <% else -%>
219
+ put :update, params: { id: <%= file_name %>.to_param, <%= nombre_tabla_completo_singular %>: valid_attributes }
220
+ <% end -%>
221
+ expect(response).to redirect_to(<%= file_name %>.decorate.target_object)
222
+ end
223
+ end
224
+ <% if attributes.any? { |at| at.required? } -%>
225
+
226
+ context 'with invalid params' do
227
+ it 'returns a unprocessable_entity response' do
228
+ <%= file_name %> = create(:<%= nombre_tabla_completo_singular %>)
229
+ put :update, params: { id: <%= file_name %>.to_param, <%= nombre_tabla_completo_singular %>: invalid_attributes }
230
+ expect(response).to have_http_status(:unprocessable_entity)
231
+ end
232
+
233
+ it 'renders the edit template' do
234
+ <%= nombre_tabla_completo_singular %> = create(:<%= nombre_tabla_completo_singular %>)
235
+ put :update, params: { id: <%= nombre_tabla_completo_singular %>.to_param, <%= nombre_tabla_completo_singular %>: invalid_attributes }
236
+ expect(response).to render_template(:edit)
237
+ end
238
+ end
239
+ <% end -%>
240
+ end
241
+
242
+ describe 'DELETE #destroy' do
243
+ subject do
244
+ <% if Rails::VERSION::STRING < '5.0' -%>
245
+ delete :destroy, { id: <%= file_name %>.to_param }
246
+ <% else -%>
247
+ delete :destroy, params: { id: <%= file_name %>.to_param }
248
+ <% end -%>
249
+ end
250
+
251
+ let!(:<%= nombre_tabla_completo_singular %>) { create :<%= nombre_tabla_completo_singular %> }
252
+
253
+ it 'destroys the requested <%= nombre_tabla_completo_singular %>' do
254
+ <% if options[:discard] -%>
255
+ expect { subject }.to change(<%= class_name %>.kept, :count).by(-1)
256
+ <% elsif options[:paranoia] -%>
257
+ expect { subject }.to change(<%= class_name %>.without_deleted, :count).by(-1)
258
+ <% else -%>
259
+ expect { subject }.to change(<%= class_name %>, :count).by(-1)
260
+ <% end -%>
261
+ end
262
+
263
+ <% if options[:discard] -%>
264
+ it 'setea el discarded_at' do
265
+ subject
266
+ expect(<%= nombre_tabla_completo_singular %>.reload.discarded_at).to be_present
267
+ end
268
+
269
+ <% end -%>
270
+ it 'redirects to the <%= table_name %> list' do
271
+ subject
272
+ expect(response).to redirect_to(<%= index_helper %>_url)
273
+ end
274
+ end
275
+ end
276
+ <% 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