hot-glue 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 59ec85e7253282cf8d83bc7d8137a787ff33cb617aad95f5752efbb6df68acf4
4
- data.tar.gz: bdbab52ce54a5c1ed52f03753c01c203cce7109dc58fa73e6b9357deee8c83bc
3
+ metadata.gz: d747beed420f47b73a42783e6ae92edd8f4508b13c471a7ae7747a1a7eddfe58
4
+ data.tar.gz: 9feb6afe2493e46d7e4eef0db0c836f3d140e33c20555c5f07e7fbc896fef366
5
5
  SHA512:
6
- metadata.gz: 995f7a97e1b6f1105b9190a19cc0bfa93ed9490c2080c97332ae745326f1cc86da3e9e0abf401510d926a574686728dc848e155aa7a0f12ac53417147c625185
7
- data.tar.gz: b5bda3332c15706e124f577aa77bfaa068d7ad8d45ebe31aacea7cbcf9cb193a20719ff87d8c1b467bfd0162fcbe5ab0e536295849a3f86e30002babe0ad1212
6
+ metadata.gz: cf3dcb49cf4a37919269ff3812d00668e2739830c6f01b1f3cc86a01abc78c3278214bb27e3c3935cf60e640460482c8b79bc1127263790e349bf82f3ea4b443
7
+ data.tar.gz: 7b9576bb6ee658ffb2c05cc7a5f0c77383e70964c174e361d993c5f6f4162b94be69452fceed1fdd1988d8876b43c14c7f16b95d564136b9167604e75ee3a287
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- hot-glue (0.0.5)
4
+ hot-glue (0.0.7)
5
5
  ffaker (~> 2.16)
6
6
  haml-rails (~> 2.0)
7
7
  kaminari (~> 1.2)
data/README.md CHANGED
@@ -233,9 +233,21 @@ You don't need this if the pluralized version is just + "s" of the singular vers
233
233
 
234
234
  By default, all fields are included unless they are on the exclude list. (The default for the exclude list is `id`, `created_at`, and `updated_at` so you don't need to exclude those-- they are added.)
235
235
 
236
- If you specify an exclude list, those fields + id, created_at, and updated_at will be excluded.
236
+ If you specify an exclude list, those and the default excluded list will be excluded.
237
237
 
238
238
 
239
+ `rails generate hot_glue:scaffold Account --exclude=password`
240
+
241
+ (The default excluded list is: :id, :created_at, :updated_at, :encrypted_password, :reset_password_token, :reset_password_sent_at, :remember_created_at, :confirmation_token, :confirmed_at, :confirmation_sent_at, :unconfirmed_email. If you want to edit any fields with the same name, you must use the include flag instead.)
242
+
243
+
244
+ ### `--include=`
245
+ (separate field names by COMMA)
246
+
247
+ You may not specify both include and exclude. If you specify an include list, it will be treated as a whitelist: no fields will be included unless specified on the include list.
248
+
249
+ `rails generate hot_glue:scaffold Account --include=first_name,last_name,company_name,created_at,kyc_verified_at`
250
+
239
251
 
240
252
  ### `--god` or `--gd`
241
253
 
@@ -277,12 +289,17 @@ Omits create action.
277
289
 
278
290
  Omits delete action.
279
291
 
292
+ ### `--big-edit`
293
+
294
+ If you do not want inline editing of your list items but instead to fall back to old fashioned new page behavior for your edit views, use `--big-edit`.
280
295
 
281
296
 
282
297
 
283
298
  # VERSION HISTORY
284
299
 
285
- #### 2021-03-08 - v0.1 - testing, testing, testing
300
+ #### 2021-03-20 - v0.0.7 - adds lots of spec coverage; cleans up generated cruft code on each run; adds no-delete, no-create; a working --big-edit with basic data-turbo false to disable inline editing
301
+
302
+ #### 2021-03-06 - v0.0.6 - internal specs test the error catches and cover basic code generation (dummy testing only)
286
303
 
287
304
  #### 2021-03-01 - v0.0.5 - Validation magic; refactors the options to the correct Rails::Generators syntax
288
305
 
@@ -2,7 +2,7 @@ class CreateDefs < ActiveRecord::Migration[6.1]
2
2
  def change
3
3
  create_table :defs do |t|
4
4
  t.integer :user_id
5
-
5
+ t.string :name
6
6
  t.timestamps
7
7
  end
8
8
  end
data/db/schema.rb CHANGED
@@ -22,6 +22,7 @@ ActiveRecord::Schema.define(version: 2021_03_06_225506) do
22
22
 
23
23
  create_table "defs", force: :cascade do |t|
24
24
  t.integer "user_id"
25
+ t.string "name"
25
26
  t.datetime "created_at", precision: 6, null: false
26
27
  t.datetime "updated_at", precision: 6, null: false
27
28
  end
@@ -52,12 +52,15 @@ module HotGlue
52
52
  class_option :auth, type: :string, default: nil
53
53
  class_option :auth_identifier, type: :string, default: nil
54
54
  class_option :exclude, type: :string, default: ""
55
+ class_option :include, type: :string, default: ""
55
56
  class_option :god, type: :boolean, default: false
57
+ class_option :gd, type: :boolean, default: false # alias for god
56
58
  class_option :spacs_only, type: :boolean, default: false
57
59
  class_option :no_specs, type: :boolean, default: false
58
60
  class_option :no_delete, type: :boolean, default: false
59
61
  class_option :no_create, type: :boolean, default: false
60
62
  class_option :no_paginate, type: :boolean, default: false
63
+ class_option :big_edit, type: :boolean, default: false
61
64
 
62
65
  def initialize(*meta_args) #:nodoc:
63
66
  super
@@ -84,13 +87,21 @@ module HotGlue
84
87
  @singular_class = @singular.titleize.gsub(" ", "")
85
88
  @exclude_fields = []
86
89
  @exclude_fields += options['exclude'].split(",").collect(&:to_sym)
90
+
91
+ if options['include']
92
+ @include_fields = []
93
+ @include_fields += options['include'].split(",").collect(&:to_sym)
94
+ end
87
95
  auth_assoc = @auth.gsub("current_","")
96
+
88
97
  @god = options['god'] || options['gd'] || false
89
- @specs_only = options['specs-only'] || false
90
- @no_specs = options['no-specs'] || false
91
- @no_delete = options['no-delete'] || false
92
- @no_create = options['no-create'] || false
93
- @no_paginate = options['no-paginate'] || false
98
+ @specs_only = options['specs_only'] || false
99
+ @no_specs = options['no_specs'] || false
100
+ @no_delete = options['no_delete'] || false
101
+
102
+ @no_create = options['no_create'] || false
103
+ @no_paginate = options['no_paginate'] || false
104
+ @big_edit = options['big_edit']
94
105
 
95
106
  if @god
96
107
  @auth = nil
@@ -144,15 +155,26 @@ module HotGlue
144
155
  end
145
156
  end
146
157
 
147
- @exclude_fields.push :id, :created_at, :updated_at, :encrypted_password,
148
- :reset_password_token,
149
- :reset_password_sent_at, :remember_created_at,
150
- :confirmation_token, :confirmed_at,
151
- :confirmation_sent_at, :unconfirmed_email
152
158
 
153
- @exclude_fields.push(auth_assoc_field.to_sym) if !auth_assoc_field.nil?
154
- @exclude_fields.push(ownership_field.to_sym) if !ownership_field.nil?
155
- @columns = object.columns.map(&:name).map(&:to_sym).reject{|field| @exclude_fields.include?(field) }
159
+ if !@include_fields
160
+ @exclude_fields.push :id, :created_at, :updated_at, :encrypted_password,
161
+ :reset_password_token,
162
+ :reset_password_sent_at, :remember_created_at,
163
+ :confirmation_token, :confirmed_at,
164
+ :confirmation_sent_at, :unconfirmed_email
165
+
166
+ @exclude_fields.push(auth_assoc_field.to_sym) if !auth_assoc_field.nil?
167
+ @exclude_fields.push(ownership_field.to_sym) if !ownership_field.nil?
168
+
169
+
170
+ @columns = object.columns.map(&:name).map(&:to_sym).reject{|field| @exclude_fields.include?(field) }
171
+
172
+ else
173
+ @columns = object.columns.map(&:name).map(&:to_sym).reject{|field| !@include_fields.include?(field) }
174
+
175
+ end
176
+
177
+
156
178
 
157
179
  @columns.each do |col|
158
180
  if object.columns_hash[col.to_s].type == :integer
@@ -175,6 +197,7 @@ module HotGlue
175
197
  exit_message= "*** Oops. on the #{singular_class} object, there doesn't seem to be an association called '#{assoc_name}'"
176
198
  raise(HotGlue::Error,exit_message)
177
199
  end
200
+
178
201
  assoc_class = eval(assoc.class_name)
179
202
  if assoc_class.column_names.include?("name")
180
203
  # display_column = "name"
@@ -210,14 +233,16 @@ module HotGlue
210
233
  @default_colspan = @columns.size
211
234
 
212
235
  unless @specs_only
213
- template "controller.rb", File.join("#{'spec/dummy/' if Rails.env.test?}app/controllers#{namespace_with_dash}", "#{plural}_controller.rb")
236
+ template "controller.rb.erb", File.join("#{'spec/dummy/' if Rails.env.test?}app/controllers#{namespace_with_dash}", "#{plural}_controller.rb")
214
237
  if @namespace && defined?(controller_descends_from) == nil
215
- template "base_controller.rb", File.join("#{'spec/dummy/' if Rails.env.test?}app/controllers#{namespace_with_dash}", "base_controller.rb")
238
+ template "base_controller.rb.erb", File.join("#{'spec/dummy/' if Rails.env.test?}app/controllers#{namespace_with_dash}", "base_controller.rb")
216
239
  end
217
240
  end
218
241
 
219
242
  unless @no_specs
220
- template "controller_spec.rb", File.join("#{'spec/dummy/' if Rails.env.test?}spec/controllers#{namespace_with_dash}", "#{plural}_controller_spec.rb")
243
+ template "request_spec.rb.erb", File.join("#{'spec/dummy/' if Rails.env.test?}spec/request#{namespace_with_dash}", "#{plural}_spec.rb")
244
+ template "system_spec.rb.erb", File.join("#{'spec/dummy/' if Rails.env.test?}spec/system#{namespace_with_dash}", "#{plural}_spec.rb")
245
+
221
246
  end
222
247
 
223
248
  template "_errors.haml", File.join("#{'spec/dummy/' if Rails.env.test?}app/views#{namespace_with_dash}", "_errors.haml")
@@ -444,13 +469,21 @@ module HotGlue
444
469
  end
445
470
 
446
471
  def haml_views
447
- res = %w(index edit new _form _new_form _line _list _new_button _show _errors)
472
+ res = %w(index edit _form _line _list _show _errors)
473
+
474
+ unless @no_create
475
+ res += %w(new _new_form _new_button)
476
+ end
448
477
 
449
478
  res
450
479
  end
451
480
 
452
481
  def turbo_stream_views
453
- res = %w(create destroy edit update)
482
+ res = %w(create edit update)
483
+ unless @no_delete
484
+ res << 'destroy'
485
+ end
486
+ res
454
487
  end
455
488
 
456
489
  def handler
@@ -678,18 +711,19 @@ module HotGlue
678
711
 
679
712
  def display_class
680
713
  me = eval(singular_class)
714
+
681
715
  @display_class ||=
682
- if me.column_names.include?("name")
716
+ if me.respond_to?("name")
683
717
  "name"
684
- elsif me.column_names.include?("to_label")
718
+ elsif me.respond_to?("to_label")
685
719
  "to_label"
686
- elsif me.column_names.include?("full_name")
720
+ elsif me.respond_to?("full_name")
687
721
  "full_name"
688
- elsif me.column_names.include?("display_name")
722
+ elsif me.respond_to?("display_name")
689
723
  "display_name"
690
- elsif me.column_names.include?("email")
724
+ elsif me.respond_to?("email")
691
725
  "email"
692
- elsif me.column_names.include?("number")
726
+ elsif me.respond_to?("number")
693
727
  display_column = "number"
694
728
 
695
729
  else
@@ -4,4 +4,4 @@
4
4
  = link_to "Delete <i class='fa fa-1x fa-remove'></i>".html_safe, <%= path_helper_full %>(<%= path_helper_args %>), method: :delete, data: {confirm: 'Are you sure?'}, disable_with: "Loading...", class: "delete-<%= singular %>-button btn btn-primary "
5
5
  <% end %>
6
6
  &nbsp;
7
- = link_to "Edit <i class='fa fa-1x fa-list-alt'></i>".html_safe, edit_<%= path_helper_full %>(<%= path_helper_args %>), disable_with: "Loading...", class: "edit-<%= singular %>-button btn btn-primary "
7
+ = link_to "Edit <i class='fa fa-1x fa-list-alt'></i>".html_safe, edit_<%= path_helper_full %>(<%= path_helper_args %>), <% if @big_edit %>'data-turbo' => 'false', <% end %>disable_with: "Loading...", class: "edit-<%= singular %>-button btn btn-primary "
@@ -46,6 +46,7 @@ class <%= controller_class_name %> < <%= controller_descends_from %>
46
46
  format.html
47
47
  end
48
48
  end
49
+
49
50
  def create
50
51
  modified_params = modify_date_inputs_on_params(<%=singular_name %>_params.dup<% if !@object_owner_sym.empty? %>.merge!(<%= @object_owner_sym %>: <%= @object_owner_eval %> )<% end %> <%= @auth ? ', ' + @auth : '' %>)
51
52
  @<%=singular_name %> = <%=class_name %>.create(modified_params)
@@ -1,3 +1,5 @@
1
+ = link_to "<i class='fa fa-arrow-circle-left 2x'></i> Back to list".html_safe, <%= path_helper_plural %>
2
+
1
3
  = turbo_frame_tag "<%= singular %>__#{<%= "@" + singular %>.id}" do
2
4
  .cell.editable{style: "position: relative;"}
3
5
  - if <%="@" + singular%>.errors.any?
@@ -0,0 +1,109 @@
1
+ require 'rails_helper'
2
+
3
+ describe "interaction for <%= controller_class_name %>", type: :feature do
4
+ <% unless @auth.nil? %> let(:<%= @auth %>) {create(:<%= @auth.gsub('current_', '') %>)}<%end%>
5
+ let(:<%= singular %>) {create(:<%= singular %><%= object_parent_mapping_as_argument_for_specs %> )}
6
+
7
+ <%= objest_nest_factory_setup %>
8
+
9
+ before(:each) do
10
+ @request.env["devise.mapping"] = Devise.mappings[:account]
11
+
12
+ sign_in <%= @auth %>, scope: :<%= @auth %>
13
+ end
14
+
15
+ describe "index" do
16
+ it "should respond" do
17
+ get :index, xhr: true, format: 'js', params: {
18
+ <%= objest_nest_params_by_id_for_specs %>
19
+ }
20
+ end
21
+ end
22
+
23
+ describe "new" do
24
+ it "should show form" do
25
+ get :new, xhr: true, format: 'js', params: {
26
+ <%= objest_nest_params_by_id_for_specs %>
27
+ }
28
+ end
29
+ end
30
+
31
+ describe "create" do
32
+ it "should create a new <%= singular %>" do
33
+ expect {
34
+ post :create, xhr: true, format: 'js', params: {
35
+ <%= (@nested_args.empty? ? "" : objest_nest_params_by_id_for_specs + ",") %>
36
+ <%= singular %>: {
37
+ <%= columns_spec_with_sample_data %>
38
+ }}
39
+ }.to change { <%= @singular_class %>.all.count }.by(1)
40
+ assert_response :ok
41
+ end
42
+
43
+ # it "should not create if there are errors" do
44
+ # post :create, xhr: true, format: 'js', params: {id: <%= singular %>.id,
45
+ # <%= singular %>: {skin_id: nil}}
46
+ #
47
+ # expect(controller).to set_flash.now[:alert].to(/Oops, your <%= singular %> could not be saved/)
48
+ # end
49
+ end
50
+
51
+ describe "edit" do
52
+ it "should return an editable form" do
53
+ get :edit, xhr: true, format: 'js', params: {
54
+ <%= (@nested_args.empty? ? "" : objest_nest_params_by_id_for_specs + ",") %>
55
+ id: <%= singular %>.id
56
+ }
57
+ assert_response :ok
58
+ end
59
+ end
60
+
61
+ describe "show" do
62
+ it "should return a view form" do
63
+ get :show, xhr: true, format: 'js', params: {
64
+ <%= (@nested_args.empty? ? "" : objest_nest_params_by_id_for_specs + ",") %>
65
+ id: <%= singular %>.id
66
+ }
67
+ assert_response :ok
68
+ end
69
+ end
70
+
71
+ describe "update" do
72
+ it "should update" do
73
+ put :update, xhr: true, format: 'js',
74
+ params: {
75
+ <%= (@nested_args.empty? ? "" : objest_nest_params_by_id_for_specs + ",") %>
76
+ id: <%= singular %>.id,
77
+ <%= singular %>: {
78
+ <%= columns_spec_with_sample_data %>
79
+ }}
80
+
81
+ assert_response :ok
82
+ end
83
+
84
+ # it "should not update if invalid" do
85
+ # put :update, xhr: true, format: 'js',
86
+ # params: {
87
+ # id: <%= singular %>.id,
88
+ # <%= singular %>: {
89
+ # <%= columns_spec_with_sample_data %>
90
+ # }}
91
+ #
92
+ # assert_response :ok
93
+ #
94
+ # expect(controller).to set_flash.now[:alert].to(/Oops, your <%= singular %> could not be saved/)
95
+ # end
96
+ end
97
+
98
+ describe "#destroy" do
99
+ it "should destroy" do
100
+ post :destroy, format: 'js', params: {
101
+ <%= (@nested_args.empty? ? "" : objest_nest_params_by_id_for_specs + ",") %>
102
+ id: <%= singular %>.id
103
+ }
104
+ assert_response :ok
105
+ expect(<%= @singular_class %>.count).to be(0)
106
+ end
107
+ end
108
+ end
109
+
@@ -1,3 +1,3 @@
1
1
  module HotGlue
2
- VERSION = '0.0.6'
2
+ VERSION = '0.0.7'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hot-glue
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jason Fleetwood-Boldt
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-03-06 00:00:00.000000000 Z
11
+ date: 2021-03-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -132,13 +132,14 @@ files:
132
132
  - lib/generators/hot_glue/templates/_show.haml
133
133
  - lib/generators/hot_glue/templates/base_controller.rb.erb
134
134
  - lib/generators/hot_glue/templates/controller.rb.erb
135
- - lib/generators/hot_glue/templates/controller_spec.rb.erb
136
135
  - lib/generators/hot_glue/templates/create.turbo_stream.haml
137
136
  - lib/generators/hot_glue/templates/destroy.turbo_stream.haml
138
137
  - lib/generators/hot_glue/templates/edit.haml
139
138
  - lib/generators/hot_glue/templates/edit.turbo_stream.haml
140
139
  - lib/generators/hot_glue/templates/index.haml
141
140
  - lib/generators/hot_glue/templates/new.haml
141
+ - lib/generators/hot_glue/templates/request_spec.rb.erb
142
+ - lib/generators/hot_glue/templates/system_spec.rb.erb
142
143
  - lib/generators/hot_glue/templates/update.turbo_stream.haml
143
144
  - lib/hot-glue.rb
144
145
  - lib/hotglue/engine.rb
@@ -181,7 +182,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
181
182
  - !ruby/object:Gem::Version
182
183
  version: '0'
183
184
  requirements: []
184
- rubygems_version: 3.0.8
185
+ rubygems_version: 3.2.11
185
186
  signing_key:
186
187
  specification_version: 4
187
188
  summary: A gem build scaffolding.