inline_forms 8.1.70 → 8.1.75
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +57 -0
- data/README.rdoc +2 -2
- data/lib/generators/inline_forms_addto/templates/add_columns_migration.erb +0 -2
- data/lib/generators/inline_forms_addto_generator.rb +42 -14
- data/lib/generators/inline_forms_generator.rb +27 -15
- data/lib/generators/templates/migration.erb +0 -2
- data/lib/generators/templates/test.erb +1 -1
- data/lib/inline_forms/version.rb +1 -1
- data/test/inline_forms_addto_generator_test.rb +67 -1
- data/test/inline_forms_generator_test.rb +45 -5
- data/test/user_model_config_test.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: d69ec6821783dbbfd063d6da1f553bd14db6340d5e32e0603d4e7b20ac460715
|
|
4
|
+
data.tar.gz: a5c49b819eb32b2926ae306970747a6c1c42427246323bebd058282ff253b460
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 9235600ce6dc610d52de4d092b16cad9e7b795074d7659dab9f468bf59bf72950959541ed2f2d9e989e38c8613c7ee251c6336ef8f8f2a285d2435eeef6997be
|
|
7
|
+
data.tar.gz: 9d058e992f4eec4ed8965406d1fbd526e241daa1ac7f4a83ba05e8ce23b479e20e1ab4dc4e9b4e1ed16d1aed356e49d72faca54cc9980764b47e29eb12b4184f
|
data/CHANGELOG.md
CHANGED
|
@@ -8,6 +8,63 @@ All notable changes to this project are documented in this file.
|
|
|
8
8
|
|
|
9
9
|
- Known issues, parked (local note `stuff/2026-10-31-dropdown-rule-3-parked.md`) with dropdown order rule 3: `includes`, `group` or `select` in `inline_forms_list` make `dropdown` and `dropdown_with_other` raise while `/index` works, so 8.1.65's fix for a list order on a joined table holds only for `joins`, `left_joins` and `eager_load`; a has_many join gives duplicate options. Present since 8.1.60. No host's list scope has these today. Parked; not changed.
|
|
10
10
|
|
|
11
|
+
## [8.1.75] - 2026-11-22
|
|
12
|
+
|
|
13
|
+
### Removed
|
|
14
|
+
|
|
15
|
+
- **Installer: no importmap in generated apps.** `importmap-rails`, and 8.1.73's `bin/importmap` and `config/importmap.rb`, are gone, and `rails new` runs with `--skip-javascript`, so `bin/ci` has no importmap audit. Nothing used it (JavaScript comes from gems through Sprockets), and `bin/importmap pin` downloads npm packages. Existing apps are not changed.
|
|
16
|
+
|
|
17
|
+
### Tests
|
|
18
|
+
|
|
19
|
+
- The example app checks that importmap is not there, instead of running its audit.
|
|
20
|
+
|
|
21
|
+
## [8.1.74] - 2026-11-22
|
|
22
|
+
|
|
23
|
+
### Fixed
|
|
24
|
+
|
|
25
|
+
- **Installer: the users/roles join table migration rolls back.** Its `down` said `drop_table roles_users`, without the colon, and raised `NoMethodError`. An existing app can correct that line in its own `db/migrate/*_inline_forms_create_join_table_*_role.rb`.
|
|
26
|
+
|
|
27
|
+
### Tests
|
|
28
|
+
|
|
29
|
+
- The example app rolls that migration back and runs it again (`example_app_roles_join_table_rollback_test.rb`).
|
|
30
|
+
|
|
31
|
+
## [8.1.73] - 2026-11-22
|
|
32
|
+
|
|
33
|
+
### Fixed
|
|
34
|
+
|
|
35
|
+
- **Installer: generated apps have `bin/importmap`** and a `config/importmap.rb` without pins. `bin/ci` runs `bin/importmap audit`, which failed because the file was missing; the app's JavaScript still comes from Sprockets. Existing apps are not changed.
|
|
36
|
+
|
|
37
|
+
### Tests
|
|
38
|
+
|
|
39
|
+
- The example app runs `bin/importmap audit`.
|
|
40
|
+
|
|
41
|
+
## [8.1.72] - 2026-11-22
|
|
42
|
+
|
|
43
|
+
### Changed
|
|
44
|
+
|
|
45
|
+
- **Installer: generated apps have `rubocop-rails-omakase`** (development and test groups), the gem behind `bin/rubocop`, which `bin/ci` runs. The generated app had 335 offenses (all style); it now has none. Existing apps are not changed.
|
|
46
|
+
- **Generators write RuboCop's style:** double quotes and new hash syntax, no trailing spaces, no blank line at the start or end of a class, and no comma after the last `inline_forms_attribute_list` row. `inline_forms_addto` adds that comma when it appends a row, also before a trailing comment. Lists with the comma keep working, as does `MODEL_TABS = %w( )`, which is now written as `%w[ ]`. Re-running `inline_forms_addto` recognises the `:dependent => :destroy` line it wrote before.
|
|
47
|
+
- The installer runs `bin/rubocop -a` on the files Devise's and PaperTrail's generators write (`config/initializers/devise.rb` and the versions migrations).
|
|
48
|
+
|
|
49
|
+
### Fixed
|
|
50
|
+
|
|
51
|
+
- The installer's Devise mailer settings are indented and on their own lines in `config/environments/*.rb`; in development.rb the first line was glued to Rails' last comment.
|
|
52
|
+
|
|
53
|
+
### Tests
|
|
54
|
+
|
|
55
|
+
- The example app's suite runs `bin/rubocop` on the whole app.
|
|
56
|
+
- Generator tests for the style of the model and migration, lists with and without the last comma, and the pre-8.1.72 `MODEL_TABS` and `has_many` lines.
|
|
57
|
+
|
|
58
|
+
## [8.1.71] - 2026-11-22
|
|
59
|
+
|
|
60
|
+
### Fixed
|
|
61
|
+
|
|
62
|
+
- **Installer: generated apps have `brakeman` and `bundler-audit`** (development and test groups, `require: false`). `rails new` writes `bin/brakeman` and `bin/bundler-audit`, and `bin/ci` runs them, but the installer's own Gemfile left the gems out, so both failed. Existing apps are not changed.
|
|
63
|
+
|
|
64
|
+
### Tests
|
|
65
|
+
|
|
66
|
+
- The example app runs both binstubs (`example_app_security_tools_test.rb`).
|
|
67
|
+
|
|
11
68
|
## [8.1.70] - 2026-11-22
|
|
12
69
|
|
|
13
70
|
### Changed
|
data/README.rdoc
CHANGED
|
@@ -279,8 +279,8 @@ LONGBLOB column plus a content-type column). Declare the slot on the model:
|
|
|
279
279
|
|
|
280
280
|
# routes.rb
|
|
281
281
|
resources :clients do
|
|
282
|
-
post
|
|
283
|
-
get
|
|
282
|
+
post "revert", on: :member
|
|
283
|
+
get "list_versions", on: :member
|
|
284
284
|
InlineForms.file_routes(self)
|
|
285
285
|
end
|
|
286
286
|
InlineForms.draw_file_trash_routes(self) # global trash page, /file_trash
|
|
@@ -157,7 +157,7 @@ class InlineFormsAddtoGenerator < Rails::Generators::NamedBase
|
|
|
157
157
|
when :has_many
|
|
158
158
|
inject_class_line!(" has_many :#{attribute.name}\n")
|
|
159
159
|
when :has_many_destroy
|
|
160
|
-
inject_class_line!(" has_many :#{attribute.name}, :
|
|
160
|
+
inject_class_line!(" has_many :#{attribute.name}, dependent: :destroy\n")
|
|
161
161
|
when :has_one
|
|
162
162
|
inject_class_line!(" has_one :#{attribute.name}\n")
|
|
163
163
|
when :habtm, :has_and_belongs_to_many, :check_list
|
|
@@ -277,7 +277,8 @@ class InlineFormsAddtoGenerator < Rails::Generators::NamedBase
|
|
|
277
277
|
def inject_class_line!(line)
|
|
278
278
|
content = File.read(File.join(destination_root, model_file_path))
|
|
279
279
|
probe = line.rstrip
|
|
280
|
-
|
|
280
|
+
# `:dependent => :destroy` is what this generator wrote before 8.1.72.
|
|
281
|
+
if content.gsub(":dependent => ", "dependent: ").include?(probe)
|
|
281
282
|
say_status :identical, "#{model_file_path}: #{probe.strip}", :blue
|
|
282
283
|
return
|
|
283
284
|
end
|
|
@@ -309,11 +310,10 @@ class InlineFormsAddtoGenerator < Rails::Generators::NamedBase
|
|
|
309
310
|
bounds = attribute_list_bounds(content)
|
|
310
311
|
unless bounds
|
|
311
312
|
say_status :warn, "#{model_file_path}: no inline_forms_attribute_list found, appending a fresh method", :yellow
|
|
312
|
-
body = <<~RUBY.gsub(
|
|
313
|
-
|
|
313
|
+
body = <<~RUBY.gsub(/^(?=.)/, " ")
|
|
314
314
|
def inline_forms_attribute_list
|
|
315
315
|
@inline_forms_attribute_list ||= [
|
|
316
|
-
#{attribute_row_literal(attribute)}
|
|
316
|
+
#{attribute_row_literal(attribute)}
|
|
317
317
|
]
|
|
318
318
|
end
|
|
319
319
|
RUBY
|
|
@@ -327,16 +327,18 @@ class InlineFormsAddtoGenerator < Rails::Generators::NamedBase
|
|
|
327
327
|
inner = content[(open_idx + 1)...close_idx]
|
|
328
328
|
lines = inner.lines
|
|
329
329
|
indent = detect_row_indent(lines)
|
|
330
|
-
new_line = "#{indent}#{attribute_row_literal(attribute)},\n"
|
|
331
330
|
|
|
332
331
|
insert_at, note = insertion_index(lines, attribute)
|
|
333
332
|
|
|
333
|
+
# A comma only when a row follows (RuboCop omakase wants none after the
|
|
334
|
+
# last one).
|
|
335
|
+
comma = lines.drop(insert_at).any? { |l| l.match?(/\A\s*\[/) } ? "," : ""
|
|
336
|
+
new_line = "#{indent}#{attribute_row_literal(attribute)}#{comma}\n"
|
|
337
|
+
|
|
334
338
|
# Keep the array valid: ensure the row we insert after ends with a comma.
|
|
335
339
|
if insert_at.positive?
|
|
336
340
|
prev = lines[insert_at - 1]
|
|
337
|
-
|
|
338
|
-
lines[insert_at - 1] = prev.sub(/(\S)(\s*)\z/, "\\1,\\2")
|
|
339
|
-
end
|
|
341
|
+
lines[insert_at - 1] = with_trailing_comma(prev) if prev
|
|
340
342
|
end
|
|
341
343
|
|
|
342
344
|
lines.insert(insert_at, new_line)
|
|
@@ -345,6 +347,32 @@ class InlineFormsAddtoGenerator < Rails::Generators::NamedBase
|
|
|
345
347
|
say_status :insert, "#{model_file_path}: row :#{attribute.name}#{note}", :green
|
|
346
348
|
end
|
|
347
349
|
|
|
350
|
+
# `line` with a comma after its row, before a trailing comment if it has
|
|
351
|
+
# one. Blank and comment lines, and rows that have their comma, unchanged.
|
|
352
|
+
def with_trailing_comma(line)
|
|
353
|
+
row = line.match(/\A(\s*)\[/)
|
|
354
|
+
return line if line.match?(/\A\s*(#|\z)/)
|
|
355
|
+
|
|
356
|
+
if row
|
|
357
|
+
depth = 0
|
|
358
|
+
ending = nil
|
|
359
|
+
line.each_char.with_index do |char, index|
|
|
360
|
+
depth += 1 if char == "["
|
|
361
|
+
depth -= 1 if char == "]"
|
|
362
|
+
if char == "]" && depth.zero?
|
|
363
|
+
ending = index
|
|
364
|
+
break
|
|
365
|
+
end
|
|
366
|
+
end
|
|
367
|
+
end
|
|
368
|
+
# Not a whole row on one line (the end of a longer one): its last `]`
|
|
369
|
+
# outside a comment.
|
|
370
|
+
ending ||= line.sub(/\s#.*/, "").rindex("]")
|
|
371
|
+
return line if ending.nil? || line[(ending + 1)..].match?(/\A\s*,/)
|
|
372
|
+
|
|
373
|
+
line.dup.insert(ending + 1, ",")
|
|
374
|
+
end
|
|
375
|
+
|
|
348
376
|
# Returns [open_bracket_index, close_bracket_index] for the
|
|
349
377
|
# `@inline_forms_attribute_list ||= [ ... ]` array literal, or nil when the
|
|
350
378
|
# model has no such list. Bracket-depth scan; nested `[ ]` (e.g. an
|
|
@@ -433,12 +461,12 @@ class InlineFormsAddtoGenerator < Rails::Generators::NamedBase
|
|
|
433
461
|
" " # 6 spaces, matching the create-time template
|
|
434
462
|
end
|
|
435
463
|
|
|
436
|
-
# `[ :name, :element ]`, or `[ :name, :element, { 1 =>
|
|
464
|
+
# `[ :name, :element ]`, or `[ :name, :element, { 1 => "one", 2 => "two" } ]`
|
|
437
465
|
# for value-bearing choice elements (a placeholder the user then edits).
|
|
438
466
|
def attribute_row_literal(attribute)
|
|
439
467
|
el = attribute.attribute_type
|
|
440
468
|
if VALUE_BEARING_ELEMENTS.include?(el)
|
|
441
|
-
"[ :#{attribute.name}, :#{el}, { 1 =>
|
|
469
|
+
"[ :#{attribute.name}, :#{el}, { 1 => \"one\", 2 => \"two\" } ]"
|
|
442
470
|
else
|
|
443
471
|
"[ :#{attribute.name}, :#{el} ]"
|
|
444
472
|
end
|
|
@@ -449,7 +477,7 @@ class InlineFormsAddtoGenerator < Rails::Generators::NamedBase
|
|
|
449
477
|
|
|
450
478
|
say_status :warn,
|
|
451
479
|
"#{model_file_path}: :#{attribute.name} is a #{attribute.attribute_type}; " \
|
|
452
|
-
"edit the placeholder values hash { 1 =>
|
|
480
|
+
"edit the placeholder values hash { 1 => \"one\", ... }",
|
|
453
481
|
:yellow
|
|
454
482
|
end
|
|
455
483
|
|
|
@@ -471,7 +499,7 @@ class InlineFormsAddtoGenerator < Rails::Generators::NamedBase
|
|
|
471
499
|
/ def _presentation\b.*?\n end\n/m,
|
|
472
500
|
new_method
|
|
473
501
|
else
|
|
474
|
-
inject_into_class model_file_path, model_class_name, "
|
|
502
|
+
inject_into_class model_file_path, model_class_name, "#{new_method}\n"
|
|
475
503
|
end
|
|
476
504
|
when "_list_order", "_order"
|
|
477
505
|
col = attribute.type
|
|
@@ -487,7 +515,7 @@ class InlineFormsAddtoGenerator < Rails::Generators::NamedBase
|
|
|
487
515
|
if content.match?(/def <=>\(other\)/)
|
|
488
516
|
gsub_file model_file_path, / def <=>\(other\).*?\n end\n/m, new_spaceship
|
|
489
517
|
else
|
|
490
|
-
inject_into_class model_file_path, model_class_name, "
|
|
518
|
+
inject_into_class model_file_path, model_class_name, "#{new_spaceship}\n"
|
|
491
519
|
end
|
|
492
520
|
when "_list_search"
|
|
493
521
|
col = attribute.type
|
|
@@ -68,6 +68,7 @@ module InlineForms
|
|
|
68
68
|
@carrierwave_mounters = "\n"
|
|
69
69
|
@stored_files = String.new
|
|
70
70
|
@inline_forms_attribute_list = String.new
|
|
71
|
+
rows = []
|
|
71
72
|
|
|
72
73
|
for attribute in attributes
|
|
73
74
|
if attribute.column_type == :belongs_to
|
|
@@ -81,7 +82,7 @@ module InlineForms
|
|
|
81
82
|
if attribute.type == :has_many ||
|
|
82
83
|
attribute.type == :has_many_destroy
|
|
83
84
|
@has_many << ' has_many :' + attribute.name
|
|
84
|
-
@has_many << ', :
|
|
85
|
+
@has_many << ', dependent: :destroy' if attribute.type == :has_many_destroy
|
|
85
86
|
@has_many << "\n"
|
|
86
87
|
end
|
|
87
88
|
if attribute.type == :has_one
|
|
@@ -126,15 +127,17 @@ module InlineForms
|
|
|
126
127
|
@list_scopes << " inline_forms_search_on :#{attribute.type}\n"
|
|
127
128
|
end
|
|
128
129
|
if attribute.attribute?
|
|
129
|
-
attribute.attribute_type == :unknown ?
|
|
130
|
-
|
|
131
|
-
' [ :' +
|
|
132
|
-
attribute.name +
|
|
133
|
-
', :' + attribute.attribute_type.to_s +
|
|
134
|
-
" ], \n"
|
|
130
|
+
commenter = attribute.attribute_type == :unknown ? '#' : ' '
|
|
131
|
+
rows << "#{commenter} [ :#{attribute.name}, :#{attribute.attribute_type} ]"
|
|
135
132
|
end
|
|
136
133
|
end
|
|
137
|
-
unless
|
|
134
|
+
unless rows.empty?
|
|
135
|
+
# No comma after the last row that is not commented out (RuboCop
|
|
136
|
+
# omakase); inline_forms_addto adds it when it appends a row.
|
|
137
|
+
last_row = rows.rindex { |row| !row.start_with?('#') }
|
|
138
|
+
rows.each_with_index do |row, index|
|
|
139
|
+
@inline_forms_attribute_list << row << (index == last_row ? "\n" : ",\n")
|
|
140
|
+
end
|
|
138
141
|
@inline_forms_attribute_list = "\n" +
|
|
139
142
|
" def inline_forms_attribute_list\n" +
|
|
140
143
|
" @inline_forms_attribute_list ||= [\n" +
|
|
@@ -143,7 +146,7 @@ module InlineForms
|
|
|
143
146
|
" end\n" +
|
|
144
147
|
"\n"
|
|
145
148
|
end
|
|
146
|
-
template
|
|
149
|
+
template("model.erb", "app/models/#{model_file_name}.rb") { |content| tidy_class_body(content) }
|
|
147
150
|
end
|
|
148
151
|
end
|
|
149
152
|
|
|
@@ -152,8 +155,8 @@ module InlineForms
|
|
|
152
155
|
file_routes = file_slot_attributes.any? ? "\n InlineForms.file_routes(self)" : ""
|
|
153
156
|
route <<-ROUTE.strip_heredoc
|
|
154
157
|
resources :#{resource_name} do
|
|
155
|
-
post
|
|
156
|
-
get
|
|
158
|
+
post "revert", on: :member
|
|
159
|
+
get "list_versions", on: :member#{file_routes}
|
|
157
160
|
end
|
|
158
161
|
ROUTE
|
|
159
162
|
end
|
|
@@ -200,7 +203,7 @@ module InlineForms
|
|
|
200
203
|
" :" +
|
|
201
204
|
attribute.name +
|
|
202
205
|
column_opts +
|
|
203
|
-
"
|
|
206
|
+
"\n"
|
|
204
207
|
end
|
|
205
208
|
end
|
|
206
209
|
end
|
|
@@ -212,7 +215,8 @@ module InlineForms
|
|
|
212
215
|
def add_tab
|
|
213
216
|
return if @flag_not_accessible_through_html
|
|
214
217
|
|
|
215
|
-
# The installer seeds `MODEL_TABS = %w
|
|
218
|
+
# The installer seeds `MODEL_TABS = %w[<user_model_route> ]` (`%w( )`
|
|
219
|
+
# before 8.1.72) in
|
|
216
220
|
# `config/initializers/inline_forms.rb` before any `rails g inline_forms`
|
|
217
221
|
# runs. Inject each generated model's pluralised route token into that
|
|
218
222
|
# list so the inline_forms top-bar dropdown (rendered by
|
|
@@ -221,13 +225,13 @@ module InlineForms
|
|
|
221
225
|
# consumer running `rails g inline_forms` in a non-installer-shaped app)
|
|
222
226
|
# or when the token is already present (idempotent re-run).
|
|
223
227
|
relative_path = "config/initializers/inline_forms.rb"
|
|
224
|
-
marker =
|
|
228
|
+
marker = /MODEL_TABS = %w[\[(]/
|
|
225
229
|
tab_token = "#{name.pluralize.underscore} "
|
|
226
230
|
full_path = File.join(destination_root, relative_path)
|
|
227
231
|
return unless File.exist?(full_path)
|
|
228
232
|
|
|
229
233
|
content = File.read(full_path)
|
|
230
|
-
return unless content.
|
|
234
|
+
return unless content.match?(marker)
|
|
231
235
|
return if content.include?(tab_token.rstrip)
|
|
232
236
|
|
|
233
237
|
inject_into_file relative_path, tab_token, after: marker
|
|
@@ -243,6 +247,14 @@ module InlineForms
|
|
|
243
247
|
|
|
244
248
|
|
|
245
249
|
private
|
|
250
|
+
# The optional parts of model.erb each bring their own blank lines: none
|
|
251
|
+
# right after `class` or before its `end`, and never two in a row.
|
|
252
|
+
def tidy_class_body(content)
|
|
253
|
+
content.gsub(/\n{3,}/, "\n\n")
|
|
254
|
+
.sub(/\A(class [^\n]*\n)\n+/, '\1')
|
|
255
|
+
.sub(/\n+end\s*\z/, "\nend\n")
|
|
256
|
+
end
|
|
257
|
+
|
|
246
258
|
def file_slot_attributes
|
|
247
259
|
attributes.select { |attribute| attribute.type == :simple_file_field }
|
|
248
260
|
end
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
class InlineFormsCreate<%= table_name.camelize %> < ActiveRecord::Migration[8.1]
|
|
2
|
-
|
|
3
2
|
def self.up
|
|
4
3
|
create_table :<%= table_name + @primary_key_option %> do |t|
|
|
5
4
|
<%= @columns -%>
|
|
@@ -10,5 +9,4 @@ class InlineFormsCreate<%= table_name.camelize %> < ActiveRecord::Migration[8.1]
|
|
|
10
9
|
def self.down
|
|
11
10
|
drop_table :<%= table_name %>
|
|
12
11
|
end
|
|
13
|
-
|
|
14
12
|
end
|
data/lib/inline_forms/version.rb
CHANGED
|
@@ -331,6 +331,55 @@ class InlineFormsAddtoGeneratorTest < Minitest::Test
|
|
|
331
331
|
assert(model.index("[ :occupation") < model.index("[ :category"))
|
|
332
332
|
end
|
|
333
333
|
|
|
334
|
+
# What `rails g inline_forms` writes: no comma after the last row.
|
|
335
|
+
def test_list_without_a_trailing_comma
|
|
336
|
+
write_model("widget.rb", widget_with_rows("[ :name, :text_field ],", "[ :size, :integer_field ]"))
|
|
337
|
+
|
|
338
|
+
capture_io { run_generator("Widget", "color:string") }
|
|
339
|
+
|
|
340
|
+
assert_includes(read("app/models/widget.rb"),
|
|
341
|
+
" [ :size, :integer_field ],\n [ :color, :text_field ]\n ]")
|
|
342
|
+
assert_valid_ruby("app/models/widget.rb")
|
|
343
|
+
end
|
|
344
|
+
|
|
345
|
+
def test_last_row_with_a_trailing_comment
|
|
346
|
+
write_model("widget.rb", widget_with_rows("[ :size, :dropdown_with_values, { 1 => \"a\" }, [ 1 ] ] # see [x], y"))
|
|
347
|
+
|
|
348
|
+
capture_io { run_generator("Widget", "color:string") }
|
|
349
|
+
|
|
350
|
+
assert_includes(read("app/models/widget.rb"),
|
|
351
|
+
"[ 1 ] ], # see [x], y\n [ :color, :text_field ]\n ]")
|
|
352
|
+
assert_valid_ruby("app/models/widget.rb")
|
|
353
|
+
end
|
|
354
|
+
|
|
355
|
+
def test_row_that_already_has_its_comma_before_a_comment
|
|
356
|
+
write_model("widget.rb", widget_with_rows("[ :size, :integer_field ], # cm"))
|
|
357
|
+
|
|
358
|
+
capture_io { run_generator("Widget", "color:string") }
|
|
359
|
+
|
|
360
|
+
assert_includes(read("app/models/widget.rb"), "[ :size, :integer_field ], # cm\n [ :color, :text_field ]\n")
|
|
361
|
+
assert_valid_ruby("app/models/widget.rb")
|
|
362
|
+
end
|
|
363
|
+
|
|
364
|
+
def test_row_before_another_gets_a_comma
|
|
365
|
+
write_model("widget.rb", widget_with_rows("[ :name, :text_field ],", "[ :size, :integer_field ]"))
|
|
366
|
+
|
|
367
|
+
capture_io { run_generator("Widget", "color:string", "--before=size") }
|
|
368
|
+
|
|
369
|
+
assert_includes(read("app/models/widget.rb"),
|
|
370
|
+
" [ :color, :text_field ],\n [ :size, :integer_field ]\n ]")
|
|
371
|
+
assert_valid_ruby("app/models/widget.rb")
|
|
372
|
+
end
|
|
373
|
+
|
|
374
|
+
def test_rerun_recognises_the_has_many_destroy_line_from_before_8_1_72
|
|
375
|
+
write_model("widget.rb", widget_with_rows("[ :name, :text_field ]")
|
|
376
|
+
.sub("ApplicationRecord\n", "ApplicationRecord\n has_many :parts, :dependent => :destroy\n"))
|
|
377
|
+
|
|
378
|
+
capture_io { run_generator("Widget", "parts:has_many_destroy") }
|
|
379
|
+
|
|
380
|
+
assert_equal(1, read("app/models/widget.rb").scan("has_many :parts").size)
|
|
381
|
+
end
|
|
382
|
+
|
|
334
383
|
def test_missing_anchor_warns_and_falls_back_to_default
|
|
335
384
|
write_model("widget.rb", GENERATOR_SHAPED_MODEL)
|
|
336
385
|
|
|
@@ -351,7 +400,7 @@ class InlineFormsAddtoGeneratorTest < Minitest::Test
|
|
|
351
400
|
end
|
|
352
401
|
|
|
353
402
|
model = read("app/models/widget.rb")
|
|
354
|
-
assert_includes(model,
|
|
403
|
+
assert_includes(model, '[ :status, :dropdown_with_values, { 1 => "one", 2 => "two" } ]')
|
|
355
404
|
assert_includes(out, "values hash")
|
|
356
405
|
end
|
|
357
406
|
|
|
@@ -493,6 +542,23 @@ class InlineFormsAddtoGeneratorTest < Minitest::Test
|
|
|
493
542
|
end
|
|
494
543
|
end
|
|
495
544
|
|
|
545
|
+
def widget_with_rows(*rows)
|
|
546
|
+
list = rows.map { |row| " #{row}\n" }.join
|
|
547
|
+
<<~RUBY
|
|
548
|
+
class Widget < ApplicationRecord
|
|
549
|
+
def inline_forms_attribute_list
|
|
550
|
+
@inline_forms_attribute_list ||= [
|
|
551
|
+
#{list.chomp}
|
|
552
|
+
]
|
|
553
|
+
end
|
|
554
|
+
end
|
|
555
|
+
RUBY
|
|
556
|
+
end
|
|
557
|
+
|
|
558
|
+
def assert_valid_ruby(path)
|
|
559
|
+
assert(RubyVM::InstructionSequence.compile(read(path)))
|
|
560
|
+
end
|
|
561
|
+
|
|
496
562
|
def write_model(file, content)
|
|
497
563
|
File.write(File.join(@destination_root, "app/models", file), content)
|
|
498
564
|
end
|
|
@@ -51,10 +51,10 @@ class InlineFormsGeneratorTest < Minitest::Test
|
|
|
51
51
|
assert_includes(controller, "set_tab :thing")
|
|
52
52
|
|
|
53
53
|
assert_includes(routes, "resources :things do")
|
|
54
|
-
assert_includes(routes,
|
|
55
|
-
assert_includes(routes,
|
|
54
|
+
assert_includes(routes, 'post "revert", on: :member')
|
|
55
|
+
assert_includes(routes, 'get "list_versions", on: :member')
|
|
56
56
|
|
|
57
|
-
assert_includes(inline_forms_initializer, "MODEL_TABS = %w
|
|
57
|
+
assert_includes(inline_forms_initializer, "MODEL_TABS = %w[things ")
|
|
58
58
|
|
|
59
59
|
assert_includes(migration, "class InlineFormsCreateThings < ActiveRecord::Migration[8.1]")
|
|
60
60
|
assert_includes(migration, "create_table :things do |t|")
|
|
@@ -188,6 +188,46 @@ class InlineFormsGeneratorTest < Minitest::Test
|
|
|
188
188
|
assert_includes(routes, "InlineForms.file_routes(self)")
|
|
189
189
|
end
|
|
190
190
|
|
|
191
|
+
# RuboCop omakase, which generated apps run in bin/ci.
|
|
192
|
+
def test_model_and_migration_follow_the_style_of_a_generated_app
|
|
193
|
+
run_generator(
|
|
194
|
+
"Thing",
|
|
195
|
+
"name:string",
|
|
196
|
+
"category:dropdown",
|
|
197
|
+
"photos:has_many_destroy",
|
|
198
|
+
"_enabled:yes",
|
|
199
|
+
"_list_order:name",
|
|
200
|
+
"_presentation:\\#{name}"
|
|
201
|
+
)
|
|
202
|
+
|
|
203
|
+
model = read("app/models/thing.rb")
|
|
204
|
+
assert_includes(model, " [ :name, :text_field ],\n [ :category, :dropdown ]\n ]\n")
|
|
205
|
+
assert_includes(model, "has_many :photos, dependent: :destroy")
|
|
206
|
+
[ model, read_single_migration_for("things"), read("test/unit/thing_test.rb") ].each do |content|
|
|
207
|
+
refute_match(/[ \t]$/, content)
|
|
208
|
+
refute_match(/\Aclass [^\n]*\n\n/, content)
|
|
209
|
+
refute_match(/\n\nend\n\z/, content)
|
|
210
|
+
refute_match(/\n{3}/, content)
|
|
211
|
+
assert(content.end_with?("end\n"))
|
|
212
|
+
end
|
|
213
|
+
end
|
|
214
|
+
|
|
215
|
+
def test_a_commented_out_row_leaves_the_last_real_row_without_a_comma
|
|
216
|
+
run_generator("Mystery", "name:string", "payload:not_a_real_type", "--allow-unknown")
|
|
217
|
+
|
|
218
|
+
model = read("app/models/mystery.rb")
|
|
219
|
+
assert_includes(model, " [ :name, :text_field ]\n# [ :payload, :unknown ],\n ]")
|
|
220
|
+
RubyVM::InstructionSequence.compile(model)
|
|
221
|
+
end
|
|
222
|
+
|
|
223
|
+
def test_tab_injection_into_an_initializer_from_before_8_1_72
|
|
224
|
+
write("config/initializers/inline_forms.rb", "MODEL_TABS = %w(users )\n")
|
|
225
|
+
|
|
226
|
+
run_generator("Thing", "name:string", "_enabled:yes")
|
|
227
|
+
|
|
228
|
+
assert_equal("MODEL_TABS = %w(things users )\n", read("config/initializers/inline_forms.rb"))
|
|
229
|
+
end
|
|
230
|
+
|
|
191
231
|
def test_no_file_routes_without_a_file_field
|
|
192
232
|
run_generator("Thing", "name:string", "_enabled:yes")
|
|
193
233
|
|
|
@@ -222,12 +262,12 @@ class InlineFormsGeneratorTest < Minitest::Test
|
|
|
222
262
|
)
|
|
223
263
|
|
|
224
264
|
# Matches the file the installer writes; the generator's `add_tab` step
|
|
225
|
-
# injects `<plural_route> ` tokens after the `MODEL_TABS = %w
|
|
265
|
+
# injects `<plural_route> ` tokens after the `MODEL_TABS = %w[` marker.
|
|
226
266
|
write(
|
|
227
267
|
"config/initializers/inline_forms.rb",
|
|
228
268
|
<<~RUBY
|
|
229
269
|
Rails.application.reloader.to_prepare do
|
|
230
|
-
MODEL_TABS = %w
|
|
270
|
+
MODEL_TABS = %w[]
|
|
231
271
|
end
|
|
232
272
|
RUBY
|
|
233
273
|
)
|
|
@@ -8,7 +8,7 @@ class UserModelConfigTest < Minitest::Test
|
|
|
8
8
|
cfg = InlineFormsInstaller::UserModelConfig.from_name("User")
|
|
9
9
|
assert cfg.default?
|
|
10
10
|
assert_equal "users", cfg.table_name
|
|
11
|
-
assert_equal
|
|
11
|
+
assert_equal 'devise_for :users, path_prefix: "auth"', cfg.devise_route_line
|
|
12
12
|
assert_equal "/auth/users/sign_in", cfg.sign_in_path_fragment
|
|
13
13
|
end
|
|
14
14
|
|