pg_scaffold 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.md +28 -0
  4. data/Rakefile +3 -0
  5. data/lib/generators/pg_active_record/model/model_generator.rb +23 -0
  6. data/lib/generators/pg_active_record/model/templates/create_table_migration.rb.tt +46 -0
  7. data/lib/generators/pg_active_record/model/templates/migration.rb.tt +48 -0
  8. data/lib/generators/pg_active_record/model/templates/model.rb +46 -0
  9. data/lib/generators/pg_active_record/model/templates/module.rb +9 -0
  10. data/lib/generators/pg_decorator/USAGE +8 -0
  11. data/lib/generators/pg_decorator/pg_decorator_generator.rb +30 -0
  12. data/lib/generators/pg_decorator/templates/decorator.rb +28 -0
  13. data/lib/generators/pg_factory_bot/model/model_generator.rb +93 -0
  14. data/lib/generators/pg_factory_bot/model/templates/factories.erb +14 -0
  15. data/lib/generators/pg_pundit/USAGE +8 -0
  16. data/lib/generators/pg_pundit/pg_pundit_generator.rb +18 -0
  17. data/lib/generators/pg_pundit/templates/policy.rb +37 -0
  18. data/lib/generators/pg_rails/instalar/USAGE +8 -0
  19. data/lib/generators/pg_rails/instalar/instalar_generator.rb +17 -0
  20. data/lib/generators/pg_rails/instalar/templates/pg_rails.rb +10 -0
  21. data/lib/generators/pg_rspec/model/model_generator.rb +27 -0
  22. data/lib/generators/pg_rspec/model/templates/model_spec.rb +15 -0
  23. data/lib/generators/pg_rspec/scaffold/scaffold_generator.rb +43 -0
  24. data/lib/generators/pg_rspec/scaffold/templates/api_controller_spec.rb +167 -0
  25. data/lib/generators/pg_rspec/scaffold/templates/controller_spec.rb +248 -0
  26. data/lib/generators/pg_rspec/scaffold/templates/edit_spec.rb +34 -0
  27. data/lib/generators/pg_rspec/scaffold/templates/index_spec.rb +28 -0
  28. data/lib/generators/pg_rspec/scaffold/templates/new_spec.rb +34 -0
  29. data/lib/generators/pg_rspec/scaffold/templates/routing_spec.rb +50 -0
  30. data/lib/generators/pg_rspec/scaffold/templates/show_spec.rb +26 -0
  31. data/lib/generators/pg_scaffold/USAGE +8 -0
  32. data/lib/generators/pg_scaffold/pg_scaffold_generator.rb +63 -0
  33. data/lib/generators/pg_scaffold/templates/controller.rb +62 -0
  34. data/lib/generators/pg_slim/USAGE +8 -0
  35. data/lib/generators/pg_slim/pg_slim_generator.rb +23 -0
  36. data/lib/generators/pg_slim/templates/_form.html.slim +8 -0
  37. data/lib/generators/pg_slim/templates/download.xlsx.axlsx +14 -0
  38. data/lib/generators/pg_slim/templates/edit.html.slim +5 -0
  39. data/lib/generators/pg_slim/templates/index.html.slim +50 -0
  40. data/lib/generators/pg_slim/templates/new.html.slim +5 -0
  41. data/lib/generators/pg_slim/templates/partial.html.slim +1 -0
  42. data/lib/generators/pg_slim/templates/show.html.slim +39 -0
  43. data/lib/pg_scaffold/monkey_patches/mejoras_a_named_base.rb +37 -0
  44. data/lib/pg_scaffold/monkey_patches/mejoras_de_atributos.rb +116 -0
  45. data/lib/pg_scaffold/railtie.rb +18 -0
  46. data/lib/pg_scaffold/version.rb +3 -0
  47. data/lib/pg_scaffold.rb +6 -0
  48. data/lib/tasks/pg_scaffold_tasks.rake +4 -0
  49. metadata +110 -0
@@ -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,248 @@
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
+ <% if mountable_engine? -%>
33
+ routes { <%= mountable_engine? %>::Engine.routes }
34
+
35
+ <% end -%>
36
+ <% referencias_requeridas.each do |atributo| -%>
37
+ let(:<%= atributo.name %>) { create :<%= atributo.name %> }
38
+
39
+ <% end -%>
40
+ # This should return the minimal set of attributes required to create a valid
41
+ # <%= class_name %>. As you add validations to <%= class_name %>, be sure to
42
+ # adjust the attributes here as well.
43
+ let(:valid_attributes) do
44
+ attributes_for(:<%= nombre_tabla_completo_singular %>)<%= merge_referencias %>
45
+ end
46
+ <% if attributes.any? { |at| at.required? } -%>
47
+ <% required_att = attributes.select { |at| at.required? }.first -%>
48
+
49
+ let(:invalid_attributes) do
50
+ {
51
+ <%= "#{required_att.name}: nil" %>
52
+ }
53
+ end
54
+ <% end -%>
55
+
56
+ let(:user) { create :user, :admin }
57
+
58
+ before do
59
+ sign_in user
60
+ end
61
+
62
+ <% unless options[:singleton] -%>
63
+ describe 'GET #index' do
64
+ subject do
65
+ <% if Rails::VERSION::STRING < '5.0' -%>
66
+ get :index, {}
67
+ <% else -%>
68
+ get :index, params: {}
69
+ <% end -%>
70
+ end
71
+
72
+ before { create :<%= nombre_tabla_completo_singular %> }
73
+
74
+ it 'returns a success response' do
75
+ subject
76
+ expect(response).to be_successful
77
+ end
78
+ <% if options[:discard] -%>
79
+
80
+ context 'when está descartado' do
81
+ before { <%= nombre_tabla_completo_singular %>.discard! }
82
+
83
+ it do
84
+ subject
85
+ expect(assigns(:<%= table_name %>)).to be_empty
86
+ end
87
+ end
88
+ <% end -%>
89
+ end
90
+
91
+ <% end -%>
92
+ describe 'GET #show' do
93
+ it 'returns a success response' do
94
+ <%= file_name %> = create(:<%= nombre_tabla_completo_singular %>)
95
+ <% if Rails::VERSION::STRING < '5.0' -%>
96
+ get :show, { id: <%= file_name %>.to_param }
97
+ <% else -%>
98
+ get :show, params: { id: <%= file_name %>.to_param }
99
+ <% end -%>
100
+ expect(response).to be_successful
101
+ end
102
+ end
103
+
104
+ describe 'GET #new' do
105
+ it 'returns a success response' do
106
+ <% if Rails::VERSION::STRING < '5.0' -%>
107
+ get :new, {}
108
+ <% else -%>
109
+ get :new, params: {}
110
+ <% end -%>
111
+ expect(response).to be_successful
112
+ end
113
+ end
114
+
115
+ describe 'GET #edit' do
116
+ it 'returns a success response' do
117
+ <%= file_name %> = create(:<%= nombre_tabla_completo_singular %>)
118
+ <% if Rails::VERSION::STRING < '5.0' -%>
119
+ get :edit, { id: <%= file_name %>.to_param }
120
+ <% else -%>
121
+ get :edit, params: { id: <%= file_name %>.to_param }
122
+ <% end -%>
123
+ expect(response).to be_successful
124
+ end
125
+ end
126
+
127
+ describe 'POST #create' do
128
+ context 'with valid params' do
129
+ it 'creates a new <%= class_name %>' do
130
+ expect do
131
+ <% if Rails::VERSION::STRING < '5.0' -%>
132
+ post :create, { <%= nombre_tabla_completo_singular %>: valid_attributes }
133
+ <% else -%>
134
+ post :create, params: { <%= nombre_tabla_completo_singular %>: valid_attributes }
135
+ <% end -%>
136
+ end.to change(<%= class_name %>, :count).by(1)
137
+ end
138
+
139
+ it 'redirects to the created <%= nombre_tabla_completo_singular %>' do
140
+ <% if Rails::VERSION::STRING < '5.0' -%>
141
+ post :create, { <%= nombre_tabla_completo_singular %>: valid_attributes }
142
+ <% else -%>
143
+ post :create, params: { <%= nombre_tabla_completo_singular %>: valid_attributes }
144
+ <% end -%>
145
+ expect(response).to redirect_to(<%= class_name %>.last.decorate.target_object)
146
+ end
147
+ end
148
+ <% if attributes.any? { |at| at.required? } -%>
149
+
150
+ context 'with invalid params' do
151
+ it 'returns a unprocessable_entity response' do
152
+ post :create, params: { <%= nombre_tabla_completo_singular %>: invalid_attributes }
153
+ expect(response).to have_http_status(:unprocessable_entity)
154
+ end
155
+
156
+ it 'renders the new template' do
157
+ post :create, params: { <%= nombre_tabla_completo_singular %>: invalid_attributes }
158
+ expect(response).to render_template(:new)
159
+ end
160
+ end
161
+ <% end -%>
162
+ end
163
+
164
+ describe 'PUT #update' do
165
+ context 'with valid params' do
166
+ let(:new_attributes) do
167
+ attributes_for(:<%= nombre_tabla_completo_singular %>)
168
+ end
169
+
170
+ it 'updates the requested <%= nombre_tabla_completo_singular %>' do
171
+ <%= file_name %> = create(:<%= nombre_tabla_completo_singular %>)
172
+ <% if Rails::VERSION::STRING < '5.0' -%>
173
+ put :update, { id: <%= file_name %>.to_param, <%= nombre_tabla_completo_singular %>: new_attributes }
174
+ <% else -%>
175
+ put :update, params: { id: <%= file_name %>.to_param, <%= nombre_tabla_completo_singular %>: new_attributes }
176
+ <% end -%>
177
+ <%= file_name %>.reload
178
+ <% atributo = attributes.find { |at| !at.reference? && at.required? } -%>
179
+ <% if atributo.present? -%>
180
+ expect(<%= file_name%>.<%= atributo.name %>).to eq new_attributes[:<%= atributo.name %>]
181
+ <% else -%>
182
+ skip("Add assertions for updated state")
183
+ <% end -%>
184
+ end
185
+
186
+ it 'redirects to the <%= nombre_tabla_completo_singular %>' do
187
+ <%= file_name %> = create(:<%= nombre_tabla_completo_singular %>)
188
+ <% if Rails::VERSION::STRING < '5.0' -%>
189
+ put :update, { id: <%= file_name %>.to_param, <%= nombre_tabla_completo_singular %>: valid_attributes }
190
+ <% else -%>
191
+ put :update, params: { id: <%= file_name %>.to_param, <%= nombre_tabla_completo_singular %>: valid_attributes }
192
+ <% end -%>
193
+ expect(response).to redirect_to(<%= file_name %>.decorate.target_object)
194
+ end
195
+ end
196
+ <% if attributes.any? { |at| at.required? } -%>
197
+
198
+ context 'with invalid params' do
199
+ it 'returns a unprocessable_entity response' do
200
+ <%= file_name %> = create(:<%= nombre_tabla_completo_singular %>)
201
+ put :update, params: { id: <%= file_name %>.to_param, <%= nombre_tabla_completo_singular %>: invalid_attributes }
202
+ expect(response).to have_http_status(:unprocessable_entity)
203
+ end
204
+
205
+ it 'renders the edit template' do
206
+ <%= nombre_tabla_completo_singular %> = create(:<%= nombre_tabla_completo_singular %>)
207
+ put :update, params: { id: <%= nombre_tabla_completo_singular %>.to_param, <%= nombre_tabla_completo_singular %>: invalid_attributes }
208
+ expect(response).to render_template(:edit)
209
+ end
210
+ end
211
+ <% end -%>
212
+ end
213
+
214
+ describe 'DELETE #destroy' do
215
+ subject do
216
+ <% if Rails::VERSION::STRING < '5.0' -%>
217
+ delete :destroy, { id: <%= file_name %>.to_param }
218
+ <% else -%>
219
+ delete :destroy, params: { id: <%= file_name %>.to_param }
220
+ <% end -%>
221
+ end
222
+
223
+ let!(:<%= nombre_tabla_completo_singular %>) { create :<%= nombre_tabla_completo_singular %> }
224
+
225
+ it 'destroys the requested <%= nombre_tabla_completo_singular %>' do
226
+ <% if options[:discard] -%>
227
+ expect { subject }.to change(<%= class_name %>.kept, :count).by(-1)
228
+ <% elsif options[:paranoia] -%>
229
+ expect { subject }.to change(<%= class_name %>.without_deleted, :count).by(-1)
230
+ <% else -%>
231
+ expect { subject }.to change(<%= class_name %>, :count).by(-1)
232
+ <% end -%>
233
+ end
234
+
235
+ <% if options[:discard] -%>
236
+ it 'setea el discarded_at' do
237
+ subject
238
+ expect(<%= nombre_tabla_completo_singular %>.reload.discarded_at).to be_present
239
+ end
240
+
241
+ <% end -%>
242
+ it 'redirects to the <%= table_name %> list' do
243
+ subject
244
+ expect(response).to redirect_to(<%= index_helper %>_url)
245
+ end
246
+ end
247
+ end
248
+ <% 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, PgRails::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
+ 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 %>, 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
@@ -0,0 +1,50 @@
1
+ # generado con pg_rails
2
+
3
+ require "rails_helper"
4
+
5
+ <% module_namespacing do -%>
6
+ RSpec.describe <%= controller_class_name %>Controller, <%= type_metatag(:routing) %> do
7
+ describe "routing" do
8
+ <% unless options[:singleton] -%>
9
+ it "routes to #index" do
10
+ expect(:get => "/<%= ns_table_name %>").to route_to("<%= ns_table_name %>#index")
11
+ end
12
+
13
+ <% end -%>
14
+ <% unless options[:api] -%>
15
+ it "routes to #new" do
16
+ expect(:get => "/<%= ns_table_name %>/new").to route_to("<%= ns_table_name %>#new")
17
+ end
18
+
19
+ <% end -%>
20
+ it "routes to #show" do
21
+ expect(:get => "/<%= ns_table_name %>/1").to route_to("<%= ns_table_name %>#show", :id => "1")
22
+ end
23
+
24
+ <% unless options[:api] -%>
25
+ it "routes to #edit" do
26
+ expect(:get => "/<%= ns_table_name %>/1/edit").to route_to("<%= ns_table_name %>#edit", :id => "1")
27
+ end
28
+
29
+ <% end -%>
30
+
31
+ it "routes to #create" do
32
+ expect(:post => "/<%= ns_table_name %>").to route_to("<%= ns_table_name %>#create")
33
+ end
34
+
35
+ it "routes to #update via PUT" do
36
+ expect(:put => "/<%= ns_table_name %>/1").to route_to("<%= ns_table_name %>#update", :id => "1")
37
+ end
38
+
39
+ <% if Rails::VERSION::STRING > '4' -%>
40
+ it "routes to #update via PATCH" do
41
+ expect(:patch => "/<%= ns_table_name %>/1").to route_to("<%= ns_table_name %>#update", :id => "1")
42
+ end
43
+
44
+ <% end -%>
45
+ it "routes to #destroy" do
46
+ expect(:delete => "/<%= ns_table_name %>/1").to route_to("<%= ns_table_name %>#destroy", :id => "1")
47
+ end
48
+ end
49
+ end
50
+ <% end -%>
@@ -0,0 +1,26 @@
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 %>/show", <%= 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 attributes in <p>" do
21
+ render
22
+ <% for attribute in output_attributes -%>
23
+ expect(rendered).to match(/<%= raw_value_for(attribute).try :capitalize %>/)
24
+ <% end -%>
25
+ end
26
+ end
@@ -0,0 +1,8 @@
1
+ Description:
2
+ Explain the generator
3
+
4
+ Example:
5
+ rails generate mi_scaffold Thing
6
+
7
+ This will create:
8
+ what/will/it/create
@@ -0,0 +1,63 @@
1
+ # frozen_string_literal: true
2
+
3
+ class PgScaffoldGenerator < Rails::Generators::NamedBase
4
+ source_root File.expand_path('templates', __dir__)
5
+
6
+ include Rails::Generators::ResourceHelpers
7
+
8
+ class_option :orm, banner: 'NAME', type: :string, required: true,
9
+ desc: 'ORM to generate the controller for'
10
+
11
+ class_option :decorator, type: :boolean, default: true, desc: 'Generate view specs'
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
+ argument :attributes, type: :array, default: [], banner: 'field:type field:type'
19
+
20
+ def create_controller_files
21
+ template 'controller.rb',
22
+ File.join('app/controllers', controller_class_path,
23
+ "#{controller_file_name}_controller.rb")
24
+ end
25
+
26
+ hook_for :test_framework, as: :scaffold
27
+
28
+ invoke :model
29
+ invoke :resource_route
30
+ invoke :pg_slim
31
+
32
+ def decorator
33
+ invoke :pg_decorator if options[:decorator]
34
+ end
35
+
36
+ invoke :pg_pundit
37
+
38
+ def print_output
39
+ puts "
40
+ !!! Agregar al locale: es.yml:
41
+ #{singular_table_name}:
42
+ one: #{singular_table_name.titleize}
43
+ other: #{plural_table_name.titleize}
44
+ "
45
+ end
46
+
47
+ private
48
+
49
+ def atributos_a_filtrar
50
+ attributes
51
+ end
52
+
53
+ def module_namespacing_2(&block) # :doc:
54
+ content = capture(&block)
55
+ content = wrap_with_namespace_2(content)
56
+ concat(content)
57
+ end
58
+
59
+ def wrap_with_namespace_2(content) # :doc:
60
+ content = indent(content).chomp
61
+ "module #{controller_class_name.split('::').first}\n#{content}\nend\n"
62
+ end
63
+ end