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
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: be584e1438bc8ed756bb2e21c5bca90219d1f86d9831cfba0e47dda2b3d030d6
4
+ data.tar.gz: 3e7d8bcfdbc072b647d984e7ca6aaaedfe8e5e0f51c05af68015cfd663a10909
5
+ SHA512:
6
+ metadata.gz: 93f78f44c14d68de6a5706fab890b2f0913838f79f1a20e455b9672ef0f4e7cafd9bc1921e19e54c8352c2fdf836ef8f25849b4b9a18d6a43a40d978f155608e
7
+ data.tar.gz: 1745e48cd3ccc7915bfb7a929393f46f232e9f2721218b85309f46f74028246658dc8c9a6f33afa8652b0d35ba596dad33a59f0dd6a8bb09e373321f23dd1c42
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright Martín Rosso
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,28 @@
1
+ # PgScaffold
2
+ Short description and motivation.
3
+
4
+ ## Usage
5
+ How to use my plugin.
6
+
7
+ ## Installation
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem "pg_scaffold"
12
+ ```
13
+
14
+ And then execute:
15
+ ```bash
16
+ $ bundle
17
+ ```
18
+
19
+ Or install it yourself as:
20
+ ```bash
21
+ $ gem install pg_scaffold
22
+ ```
23
+
24
+ ## Contributing
25
+ Contribution directions go here.
26
+
27
+ ## License
28
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,3 @@
1
+ require "bundler/setup"
2
+
3
+ require "bundler/gem_tasks"
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rails/generators/active_record/model/model_generator'
4
+
5
+ module PgActiveRecord
6
+ class ModelGenerator < ActiveRecord::Generators::ModelGenerator
7
+ source_paths << File.expand_path('templates', __dir__)
8
+
9
+ class_option :paranoia, type: :boolean, default: false, desc: 'Paranoid y deleted_at.'
10
+ class_option :discard, type: :boolean, default: false, desc: 'Discard y discarded_at.'
11
+ class_option :trackeo_de_usuarios, type: :boolean, default: true,
12
+ desc: 'Genera campos creado_por y actualizado_por.'
13
+
14
+ def namespace # :doc:
15
+ nil
16
+ end
17
+ def class_path # :doc:
18
+ []
19
+ end
20
+ def create_module_file
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,46 @@
1
+ # generado con pg_rails
2
+
3
+ class <%= migration_class_name %> < ActiveRecord::Migration[<%= ActiveRecord::Migration.current_version %>]
4
+ def change
5
+ create_table :<%= table_name %><%= primary_key_type %> do |t|
6
+ <% attributes.each do |attribute| -%>
7
+ <% if attribute.password_digest? -%>
8
+ t.string :password_digest<%= attribute.inject_options %>
9
+ <% elsif attribute.token? -%>
10
+ t.string :<%= attribute.name %><%= attribute.inject_options %>
11
+ <% else -%>
12
+ t.<%= attribute.type %> :<%= attribute.name %><%= attribute.inject_options %>
13
+ <% end -%>
14
+ <% end -%>
15
+
16
+ <% if options[:trackeo_de_usuarios] %>
17
+ t.references :creado_por, index: true
18
+ t.references :actualizado_por, index: true
19
+
20
+ <% end -%>
21
+ <% if options[:paranoia] %>
22
+ t.datetime :deleted_at
23
+ <% end -%>
24
+ <% if options[:discard] %>
25
+ t.datetime :discarded_at
26
+ <% end -%>
27
+ <% if options[:timestamps] %>
28
+ t.timestamps
29
+ <% end -%>
30
+ end
31
+ <% attributes.select(&:token?).each do |attribute| -%>
32
+ add_index :<%= table_name %>, :<%= attribute.index_name %><%= attribute.inject_index_options %>, unique: true
33
+ <% end -%>
34
+ <% attributes_with_index.each do |attribute| -%>
35
+ add_index :<%= table_name %>, :<%= attribute.index_name %><%= attribute.inject_index_options %>
36
+ <% end -%>
37
+ <% attributes.select(&:tiene_nombre_de_clase_explicito?).each do |attribute| -%>
38
+ add_foreign_key :<%= table_name %>, :<%= attribute.tabla_referenciada %>, column: '<%= attribute.name %>_id'
39
+ <% end -%>
40
+
41
+ <% if options[:trackeo_de_usuarios] %>
42
+ add_foreign_key :<%= table_name %>, :users, column: 'creado_por_id'
43
+ add_foreign_key :<%= table_name %>, :users, column: 'actualizado_por_id'
44
+ <% end -%>
45
+ end
46
+ end
@@ -0,0 +1,48 @@
1
+ # generado con pg_rails
2
+
3
+ class <%= migration_class_name %> < ActiveRecord::Migration[<%= ActiveRecord::Migration.current_version %>]
4
+ <%- if migration_action == 'add' -%>
5
+ def change
6
+ <% attributes.each do |attribute| -%>
7
+ <%- if attribute.reference? -%>
8
+ add_reference :<%= table_name %>, :<%= attribute.name %><%= attribute.inject_options %>
9
+ <%- elsif attribute.token? -%>
10
+ add_column :<%= table_name %>, :<%= attribute.name %>, :string<%= attribute.inject_options %>
11
+ add_index :<%= table_name %>, :<%= attribute.index_name %><%= attribute.inject_index_options %>, unique: true
12
+ <%- else -%>
13
+ add_column :<%= table_name %>, :<%= attribute.name %>, :<%= attribute.type %><%= attribute.inject_options %>
14
+ <%- if attribute.has_index? -%>
15
+ add_index :<%= table_name %>, :<%= attribute.index_name %><%= attribute.inject_index_options %>
16
+ <%- end -%>
17
+ <%- end -%>
18
+ <%- end -%>
19
+ end
20
+ <%- elsif migration_action == 'join' -%>
21
+ def change
22
+ create_join_table :<%= join_tables.first %>, :<%= join_tables.second %> do |t|
23
+ <%- attributes.each do |attribute| -%>
24
+ <%- if attribute.reference? -%>
25
+ t.references :<%= attribute.name %><%= attribute.inject_options %>
26
+ <%- else -%>
27
+ <%= '# ' unless attribute.has_index? -%>t.index <%= attribute.index_name %><%= attribute.inject_index_options %>
28
+ <%- end -%>
29
+ <%- end -%>
30
+ end
31
+ end
32
+ <%- else -%>
33
+ def change
34
+ <% attributes.each do |attribute| -%>
35
+ <%- if migration_action -%>
36
+ <%- if attribute.reference? -%>
37
+ remove_reference :<%= table_name %>, :<%= attribute.name %><%= attribute.inject_options %>
38
+ <%- else -%>
39
+ <%- if attribute.has_index? -%>
40
+ remove_index :<%= table_name %>, :<%= attribute.index_name %><%= attribute.inject_index_options %>
41
+ <%- end -%>
42
+ remove_column :<%= table_name %>, :<%= attribute.name %>, :<%= attribute.type %><%= attribute.inject_options %>
43
+ <%- end -%>
44
+ <%- end -%>
45
+ <%- end -%>
46
+ end
47
+ <%- end -%>
48
+ end
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ # generado con pg_rails
4
+
5
+ <% if namespaced? -%>
6
+ require_dependency "<%= namespaced_path %>/application_record"
7
+
8
+ <% end -%>
9
+ <% module_namespacing do -%>
10
+ class <%= class_name %> < <%= parent_class_name.classify %>
11
+ audited
12
+ <%- if options[:paranoia] -%>
13
+ acts_as_paranoid without_default_scope: true
14
+ <%- end -%>
15
+ <%- if options[:discard] -%>
16
+ include Discard::Model
17
+ <%- end -%>
18
+ <%- if attributes.any?(&:reference?) -%>
19
+
20
+ <%- attributes.select(&:reference?).each do |attribute| -%>
21
+ belongs_to :<%= attribute.name %><%= ', polymorphic: true' if attribute.polymorphic? %><%= ', optional: true' unless attribute.required? %><%= ", class_name: '#{attribute.clase_con_modulo}'" if attribute.tiene_nombre_de_clase_explicito? %>
22
+ <%- end -%>
23
+ <%- end -%>
24
+ <%- if options[:trackeo_de_usuarios] -%>
25
+
26
+ belongs_to :creado_por, optional: true, class_name: 'User'
27
+ belongs_to :actualizado_por, optional: true, class_name: 'User'
28
+ <%- end -%>
29
+ <%- if attributes.any?(&:es_enum?) -%>
30
+
31
+ <%- attributes.select(&:es_enum?).each do |attribute| -%>
32
+ enumerize :<%= attribute.name %>, in: { completar: 0, los: 1, valores: 2 }
33
+ <%- end -%>
34
+ <%- end -%>
35
+ <%- if attributes.any?(&:required?) -%>
36
+
37
+ validates <%= attributes.select(&:required?).map { |at| ":#{at.name}" }.join(', ') %>, presence: true
38
+ <%- end -%>
39
+ <%- attributes.select(&:token?).each do |attribute| -%>
40
+ has_secure_token<% if attribute.name != "token" %> :<%= attribute.name %><% end %>
41
+ <%- end -%>
42
+ <%- if attributes.any?(&:password_digest?) -%>
43
+ has_secure_password
44
+ <%- end -%>
45
+ end
46
+ <% end -%>
@@ -0,0 +1,9 @@
1
+ # generado con pg_rails
2
+
3
+ <% module_namespacing do -%>
4
+ module <%= class_path.map(&:camelize).join('::') %>
5
+ def self.table_name_prefix
6
+ '<%= namespaced? ? namespaced_class_path.join('_') : class_path.join('_') %>_'
7
+ end
8
+ end
9
+ <% end -%>
@@ -0,0 +1,8 @@
1
+ Description:
2
+ Explain the generator
3
+
4
+ Example:
5
+ rails generate pg_decorator Thing
6
+
7
+ This will create:
8
+ what/will/it/create
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'generators/rails/decorator_generator'
4
+
5
+ class PgDecoratorGenerator < Rails::Generators::DecoratorGenerator
6
+ source_root File.expand_path('templates', __dir__)
7
+
8
+ remove_hook_for :test_framework
9
+
10
+ def namespace # :doc:
11
+ nil
12
+ end
13
+
14
+ def class_path # :doc:
15
+ []
16
+ end
17
+ def create_module_file
18
+ end
19
+
20
+ private
21
+
22
+ def class_path_original
23
+ @class_path.first
24
+ end
25
+
26
+
27
+ def parent_class_name
28
+ 'PgRails::BaseDecorator'
29
+ end
30
+ end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ # generado con pg_rails
4
+
5
+ <%- module_namespacing do -%>
6
+ <%- if parent_class_name.present? -%>
7
+ class <%= class_name %>Decorator < <%= parent_class_name %>
8
+ <%- else -%>
9
+ class <%= class_name %>
10
+ <%- end -%>
11
+ delegate_all
12
+
13
+ <%- if class_path_original.present? -%>
14
+ def default_module
15
+ :admin
16
+ end
17
+ <%- end -%>
18
+
19
+ # Define presentation-specific methods here. Helpers are accessed through
20
+ # `helpers` (aka `h`). You can override attributes, for example:
21
+ #
22
+ # def created_at
23
+ # helpers.content_tag :span, class: 'time' do
24
+ # object.created_at.strftime("%a %m/%d/%y")
25
+ # end
26
+ # end
27
+ end
28
+ <% end -%>
@@ -0,0 +1,93 @@
1
+ # frozen_string_literal: true
2
+
3
+ # este generator tiene que llamarse ModelGenerator para que funcione el hook_to
4
+ # del ModelGenerator de rails
5
+
6
+ require 'generators/factory_bot/model/model_generator'
7
+
8
+ module PgFactoryBot
9
+ module Generators
10
+ class ModelGenerator < FactoryBot::Generators::ModelGenerator
11
+ # piso el método de FactoryBot::Generators::Base con el método original
12
+ # de Rails::Generators::Base
13
+
14
+ # rubocop:disable Naming/MemoizedInstanceVariableName
15
+ def self.source_root(path = nil)
16
+ @_source_root = path if path
17
+ @_source_root ||= default_source_root
18
+ end
19
+ # rubocop:enable Naming/MemoizedInstanceVariableName
20
+
21
+ source_root File.expand_path('templates', __dir__)
22
+
23
+ class_option(
24
+ :dir,
25
+ type: :string,
26
+ default: 'spec/factories',
27
+ desc: 'The directory or file root where factories belong'
28
+ )
29
+
30
+ # Los modelos nunca tienen modulo
31
+ def explicit_class_option
32
+ end
33
+
34
+ def namespace # :doc:
35
+ nil
36
+ end
37
+ def class_path # :doc:
38
+ []
39
+ end
40
+ def create_module_file
41
+ end
42
+
43
+ private
44
+
45
+ #{factory_attributes.gsub(/^/, ' ')}#{los_traits.gsub(/^/, ' ')}
46
+ def factory_definition
47
+ <<~RUBY
48
+ factory :#{singular_table_name}#{explicit_class_option} do
49
+ #{factory_attributes}#{los_traits}
50
+ end
51
+ RUBY
52
+ end
53
+
54
+ def los_traits
55
+ ret = attributes.select(&:reference?).map do |atributo|
56
+ {
57
+ clase: atributo.clase_con_modulo,
58
+ atributo_name: atributo.name,
59
+ }
60
+ end
61
+ end
62
+
63
+ # Genero los valores de las factories con los helpers de Faker
64
+
65
+ def factory_attributes
66
+ attributes.map do |attribute|
67
+ if attribute.reference?
68
+ # "association :#{attribute.name}, factory: :#{attribute.tabla_referenciada_singular}"
69
+ attribute.name
70
+ else
71
+ "#{attribute.name} { #{valor_atributo(attribute)} }"
72
+ end
73
+ end
74
+ end
75
+
76
+ def valor_atributo(attribute)
77
+ if attribute.es_enum?
78
+ "#{nombre_clase_completo}.#{attribute.name}.values.sample"
79
+ elsif attribute.type == :string
80
+ 'Faker::Lorem.sentence'
81
+ elsif attribute.type == :date
82
+ 'Faker::Date.backward'
83
+ elsif attribute.type == :float || attribute.type == :decimal
84
+ 'Faker::Number.decimal(l_digits: 3, r_digits: 2)'
85
+ elsif attribute.type == :integer
86
+ 'rand(1..9999)'
87
+ else
88
+ attribute.default.inspect
89
+ end
90
+ end
91
+ end
92
+ end
93
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ # generado con pg_rails
4
+
5
+ FactoryBot.define do
6
+ factory :<%= singular_table_name %> do<% factory_attributes.each do |a| %>
7
+ <%= a %><% end %><% los_traits.each do |trait| %>
8
+
9
+ trait :<%= trait[:atributo_name] %>_existente do
10
+ <%= trait[:atributo_name] %> { nil }
11
+ <%= trait[:atributo_name] %>_id { <%= trait[:clase] %>.pluck(:id).sample }
12
+ end<% end %>
13
+ end
14
+ end
@@ -0,0 +1,8 @@
1
+ Description:
2
+ Explain the generator
3
+
4
+ Example:
5
+ rails generate pg_pundit Thing
6
+
7
+ This will create:
8
+ what/will/it/create
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'generators/pundit/policy/policy_generator'
4
+
5
+ class PgPunditGenerator < Pundit::Generators::PolicyGenerator
6
+ source_root File.expand_path('templates', __dir__)
7
+
8
+ remove_hook_for :test_framework
9
+
10
+ def namespace # :doc:
11
+ nil
12
+ end
13
+ def class_path # :doc:
14
+ []
15
+ end
16
+ def create_module_file
17
+ end
18
+ end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ # generado con pg_rails
4
+
5
+ <% if namespaced? -%>
6
+ require_dependency "<%= namespaced_path %>/application_policy"
7
+
8
+ <% end -%>
9
+ <% module_namespacing do -%>
10
+ class <%= class_name %>Policy < ApplicationPolicy
11
+ class Scope < ApplicationPolicy::Scope
12
+ # def resolve
13
+ # if policy.acceso_total?
14
+ # scope.all
15
+ # else
16
+ # scope.none
17
+ # end
18
+ # end
19
+ end
20
+
21
+ # def puede_editar?
22
+ # acceso_total? && !record.readonly?
23
+ # end
24
+
25
+ # def puede_crear?
26
+ # acceso_total? || user.asesor?
27
+ # end
28
+
29
+ # def puede_borrar?
30
+ # acceso_total? && !record.readonly?
31
+ # end
32
+
33
+ # def acceso_total?
34
+ # user.admin?
35
+ # end
36
+ end
37
+ <% end -%>
@@ -0,0 +1,8 @@
1
+ Description:
2
+ Explain the generator
3
+
4
+ Example:
5
+ rails generate instalar Thing
6
+
7
+ This will create:
8
+ what/will/it/create
@@ -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/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
+ def namespace # Esto quizas no es necesario
18
+ nil
19
+ end
20
+ def class_path # :doc:
21
+ []
22
+ end
23
+ def create_module_file
24
+ end
25
+ end
26
+ end
27
+ 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 unless referencias_requeridas.present?
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