inline_forms_installer 8.1.8 → 8.1.9

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1db2a592daf12e0ddf1b93c67469f400540e58a81b8ca96ee516dccb7a03dc20
4
- data.tar.gz: 4e5abd3355753c8f09d79e16431007a0b268066e1106330c4251649262f92fe2
3
+ metadata.gz: f4163e5ce8733e5d7f2226ce39f9a475a75860497da6d6d0ddf12575deaa661f
4
+ data.tar.gz: 42640181a8f3927a9e70ea3b536dfa3507eb21b0997b1fd5a4a5409668422002
5
5
  SHA512:
6
- metadata.gz: 92c4c50ca28769e76767bcc11fc74c742520386cddf55c4559133b95251161dd71d28e2a9e8d3fbddde62b95d9adf6e72f5666b7893ae9f94374132d66af37b6
7
- data.tar.gz: d71c002620d3959812057383f6714eb01f9863370351d4436cf419e4b7a2ece6f78a2848ca057209fe6b68956fe42e04bdcd1f75731d6880c06d06b960f358b2
6
+ metadata.gz: 7034b106b0c14b639fff1385ef6827f5e3431fe9209e978ea932a65e28a58c97ef8a45e9c66b6cac1bbd8a1c906d8628611127714716f954d75df28ac1c232aa
7
+ data.tar.gz: 70ac2e021ba10ffb43fbae4f7608134b1f25ad0583d6f92658166a963aadcc8a9d7deb25b8d3389cbd575224e95f0698ba470f3b7f26f016d0dc8a03e79542f8
@@ -431,7 +431,16 @@ END_INITIALIZER
431
431
  # Create Locales
432
432
  say "- Create locales"
433
433
  generate "inline_forms", "Locale name:string title:string #{user_cfg.table_name}:has_many _enabled:yes _list_order:title _presentation:\#{title}"
434
- append_to_file "db/seeds.rb", "Locale.create({ id: 1, name: 'en', title: 'English' })\n"
434
+ # Seed four locales so the FormElementShowcase HABTM :locales demo
435
+ # (added under --example) has something to check on/off. `id: 1` (en) is
436
+ # the default the admin user is bound to in the line below; the other
437
+ # three are inert until selected by the showcase rows.
438
+ append_to_file "db/seeds.rb", <<~LOCALE_SEED
439
+ Locale.create({ id: 1, name: 'en', title: 'English' })
440
+ Locale.create({ id: 2, name: 'nl', title: 'Nederlands' })
441
+ Locale.create({ id: 3, name: 'de', title: 'Deutsch' })
442
+ Locale.create({ id: 4, name: 'fr', title: 'Français' })
443
+ LOCALE_SEED
435
444
 
436
445
  # Create Roles
437
446
  say "- Create roles"
@@ -1056,7 +1065,7 @@ if ENV['install_example'] == 'true'
1056
1065
  # ---------------------------------------------------------------------
1057
1066
  say "- Generating FormElementShowcase (one resource per kept Tier 1 form_element)..."
1058
1067
  sleep 1
1059
- run %q{bundle exec rails g inline_forms FormElementShowcase title:string body_plain_area:plain_text_area count:integer_field price:decimal_field amount:money_field meeting_date:date_select meeting_time:time_select birth_month:month_select start_month:month_year_picker is_active:check_box gender:radio_button rating_int:dropdown_with_integers priority:dropdown_with_values priority2:dropdown_with_values stars:dropdown_with_values_with_stars scale_int:scale_with_integers scale_val:scale_with_values attachment:file_field jingle:audio_field cover:image_field description:rich_text roles:has_and_belongs_to_many _enabled:yes _list_order:title _list_search:title _presentation:'#{title}'}
1068
+ run %q{bundle exec rails g inline_forms FormElementShowcase title:string body_plain_area:plain_text_area count:integer_field price:decimal_field amount:money_field meeting_date:date_select meeting_time:time_select birth_month:month_select start_month:month_year_picker is_active:check_box gender:radio_button rating_int:dropdown_with_integers priority:dropdown_with_values priority2:dropdown_with_values stars:dropdown_with_values_with_stars scale_int:scale_with_integers scale_val:scale_with_values attachment:file_field jingle:audio_field cover:image_field description:rich_text locales:has_and_belongs_to_many _enabled:yes _list_order:title _list_search:title _presentation:'#{title}'}
1060
1069
 
1061
1070
  say "- Generating Attachment + Jingle uploaders (Cover reuses ImageUploader)..."
1062
1071
  run "bundle exec rails generate uploader Attachment"
@@ -1101,8 +1110,24 @@ if ENV['install_example'] == 'true'
1101
1110
  # keeps PaperTrail revert paths (and the seeded second row, which leaves
1102
1111
  # count nil) valid. The integration test covers the explicit error
1103
1112
  # path by POSTing `count: "abc"` to /form_element_showcases.
1113
+ #
1114
+ # `locales_display` is a virtual alias for the HABTM :locales association
1115
+ # so the same association can render twice in the attribute list: once
1116
+ # editable (`[:locales, :check_list]`) and once read-only
1117
+ # (`[:locales_display, :info_list]`). Inline-forms keys turbo frames by
1118
+ # attribute name, so we need a distinct name for the second row — info_list
1119
+ # has no `_update` method, hence the wrapper rather than a separate column.
1120
+ #
1121
+ # NOTE: this has to be `def locales_display; locales; end`, not
1122
+ # `alias_method :locales_display, :locales`. `alias_method` resolves the
1123
+ # source method at class-load time, but the `has_and_belongs_to_many
1124
+ # :locales` declaration that defines `#locales` is injected lower in the
1125
+ # file (line ~12), so an alias_method here raises
1126
+ # `NameError: undefined method 'locales' for class 'FormElementShowcase'`.
1127
+ # A `def` body is parsed but only resolved at call time, side-stepping
1128
+ # the ordering hazard.
1104
1129
  inject_into_file "app/models/form_element_showcase.rb",
1105
- "\n validates :count, numericality: { only_integer: true }, allow_blank: true\n mount_uploader :attachment, AttachmentUploader\n monetize :amount_cents\n",
1130
+ "\n validates :count, numericality: { only_integer: true }, allow_blank: true\n mount_uploader :attachment, AttachmentUploader\n monetize :amount_cents\n\n def locales_display\n locales\n end\n",
1106
1131
  after: "class FormElementShowcase < ApplicationRecord\n"
1107
1132
 
1108
1133
  # Value-bearing rows for every form_element that needs a values hash
@@ -1139,13 +1164,18 @@ if ENV['install_example'] == 'true'
1139
1164
  gsub_file "app/models/form_element_showcase.rb", from, to
1140
1165
  end
1141
1166
 
1142
- # Insert :roles (info_list), :header_meta, and the timestamps after
1143
- # the rich_text row. The generator does not emit a row for
1144
- # `roles:has_and_belongs_to_many` (relation? is true), so we add it
1145
- # manually here.
1167
+ # Insert :locales (editable check_list), :locales_display (read-only
1168
+ # info_list mirror of the same association see the alias_method
1169
+ # above), :header_meta, and the timestamps after the rich_text row.
1170
+ # The generator does not emit a row for `locales:has_and_belongs_to_many`
1171
+ # (relation? is true), so we add the rows manually here. Locale (not
1172
+ # Role) was chosen because Role is reserved for the user/Member model
1173
+ # in the inline_forms example app (the join sits under roles_users);
1174
+ # Locale already has a `_presentation` returning `title`, which is
1175
+ # exactly what `info_list_show` renders per row.
1146
1176
  gsub_file "app/models/form_element_showcase.rb",
1147
1177
  "[ :description, :rich_text ], \n",
1148
- "[ :description, :rich_text ], \n [ :roles, :info_list ], \n [ :header_meta, :header ], \n [ :created_at, :info ], \n [ :updated_at, :info ], \n"
1178
+ "[ :description, :rich_text ], \n [ :locales, :check_list ], \n [ :locales_display, :info_list ], \n [ :header_meta, :header ], \n [ :created_at, :info ], \n [ :updated_at, :info ], \n"
1149
1179
 
1150
1180
  # Locale keys for the showcase attributes. Headers + the timestamps
1151
1181
  # need explicit labels so `human_attribute_name` does not fall back to
@@ -1170,7 +1200,7 @@ if ENV['install_example'] == 'true'
1170
1200
  meeting_date: Meeting date
1171
1201
  meeting_time: Meeting time
1172
1202
  birth_month: Birth month
1173
- start_month: Start month
1203
+ start_month: Start month and year
1174
1204
  is_active: Is active
1175
1205
  gender: Gender
1176
1206
  rating_int: Rating
@@ -1183,7 +1213,8 @@ if ENV['install_example'] == 'true'
1183
1213
  jingle: Jingle
1184
1214
  cover: Cover
1185
1215
  description: Description
1186
- roles: Roles
1216
+ locales: Locales (editable)
1217
+ locales_display: Locales (read-only)
1187
1218
  created_at: Created at
1188
1219
  updated_at: Updated at
1189
1220
  END_SHOWCASE_LOCALE
@@ -1199,22 +1230,36 @@ if ENV['install_example'] == 'true'
1199
1230
  copy_file src, File.join("app/assets/images", "#{n}stars.png") if File.exist?(src)
1200
1231
  end
1201
1232
 
1202
- # Join table for has_and_belongs_to_many :roles. Mirrors the
1203
- # roles_users join migration created for the user model above.
1204
- say "- Creating form_element_showcases_roles join migration..."
1233
+ # File/audio/image upload sample assets for the full-demo seed. Copied
1234
+ # under db/seed_uploads so the seed migration can read them at
1235
+ # db:migrate time and store them through CarrierWave. Mirrors the
1236
+ # db/seed_images convention used for the Photo gallery seed above.
1237
+ %w[sample.txt sample.wav sample_cover.png].each do |basename|
1238
+ src = File.join(showcase_assets_root, basename)
1239
+ copy_file src, File.join("db/seed_uploads", basename) if File.exist?(src)
1240
+ end
1241
+
1242
+ # Join table for has_and_belongs_to_many :locales. Mirrors the
1243
+ # roles_users join migration created for the user model above. Locale
1244
+ # (not Role) was chosen because Role is reserved for the Member/User
1245
+ # auth model; using it here would coincidentally share the same join
1246
+ # row pool as roles_users which is confusing for the demo. The four
1247
+ # locales seeded above (en/nl/de/fr) give the editable check_list
1248
+ # something interesting to toggle.
1249
+ say "- Creating form_element_showcases_locales join migration..."
1205
1250
  sleep 1
1206
1251
  habtm_ts = Time.now.utc.strftime("%Y%m%d%H%M%S")
1207
- create_file "db/migrate/#{habtm_ts}_create_join_table_form_element_showcases_roles.rb", <<-HABTM_MIGRATION.strip_heredoc
1208
- class CreateJoinTableFormElementShowcasesRoles < ActiveRecord::Migration[8.1]
1252
+ create_file "db/migrate/#{habtm_ts}_create_join_table_form_element_showcases_locales.rb", <<-HABTM_MIGRATION.strip_heredoc
1253
+ class CreateJoinTableFormElementShowcasesLocales < ActiveRecord::Migration[8.1]
1209
1254
  def self.up
1210
- create_table :form_element_showcases_roles, id: false, force: true do |t|
1255
+ create_table :form_element_showcases_locales, id: false, force: true do |t|
1211
1256
  t.integer :form_element_showcase_id
1212
- t.integer :role_id
1257
+ t.integer :locale_id
1213
1258
  end
1214
1259
  end
1215
1260
 
1216
1261
  def self.down
1217
- drop_table :form_element_showcases_roles
1262
+ drop_table :form_element_showcases_locales
1218
1263
  end
1219
1264
  end
1220
1265
  HABTM_MIGRATION
@@ -1249,9 +1294,30 @@ if ENV['install_example'] == 'true'
1249
1294
  s.scale_val = 2
1250
1295
  s.description = "<p>A rich-text paragraph for the showcase.</p>"
1251
1296
  end
1252
- if defined?(Role) && Role.exists?(1) && full.roles.empty?
1253
- full.roles << Role.find(1)
1297
+ # Attach the default locale (en) so the editable check_list and the
1298
+ # paired read-only info_list both have something to show. The other
1299
+ # seeded locales (nl/de/fr) stay unchecked so the toggle UX is
1300
+ # exercised when the user opens the check_list.
1301
+ if defined?(Locale) && Locale.exists?(1) && full.locales.empty?
1302
+ full.locales << Locale.find(1)
1303
+ end
1304
+
1305
+ # File/audio/image uploads for the full demo. The asset files are
1306
+ # copied into db/seed_uploads/ from lib/installer_templates/example_app_assets/
1307
+ # at install time (see the asset-copy block above), so this
1308
+ # migration can open them at db:migrate time and hand File handles
1309
+ # to CarrierWave for storage in public/uploads/.
1310
+ seed_uploads = Rails.root.join("db", "seed_uploads")
1311
+ {
1312
+ attachment: seed_uploads.join("sample.txt"),
1313
+ jingle: seed_uploads.join("sample.wav"),
1314
+ cover: seed_uploads.join("sample_cover.png"),
1315
+ }.each do |attr, path|
1316
+ next unless path.file?
1317
+ next if full.public_send(attr).present?
1318
+ File.open(path, "rb") { |io| full.public_send("\#{attr}=", io) }
1254
1319
  end
1320
+ full.save! if full.changed?
1255
1321
 
1256
1322
  # "Empty" refers to the role and uploader fields (their empty
1257
1323
  # branches need to render). The other fields keep valid values
@@ -1,6 +1,6 @@
1
1
  # -*- encoding : utf-8 -*-
2
2
  module InlineFormsInstaller
3
- VERSION = "8.1.8"
3
+ VERSION = "8.1.9"
4
4
 
5
5
  # Written into generated apps' `.ruby-version` (must match gemspec `required_ruby_version`).
6
6
  TARGET_RUBY_VERSION = "ruby-4.0.4"
@@ -0,0 +1 @@
1
+ Sample attachment file generated by inline_forms_installer for the FormElementShowcase demo. You can replace this with any file.
@@ -0,0 +1,86 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "../example_app/example_integration_test_case"
4
+
5
+ # HABTM helpers on FormElementShowcase:
6
+ # check_list (locales) -- editable multi-select
7
+ # info_list (locales_display) -- read-only mirror of the same association
8
+ # via `alias_method :locales_display, :locales`
9
+ #
10
+ # Locale (not Role) is the showcase association because Role is reserved
11
+ # for the auth Member/User model in this example app; reusing it on
12
+ # FormElementShowcase would coincidentally share rows with roles_users
13
+ # which is confusing.
14
+ class ExampleAppShowcaseLocalesAssociationsTest < ExampleAppIntegrationTestCase
15
+ setup do
16
+ @en = Locale.find_or_create_by!(name: "en") { |l| l.title = "English" }
17
+ @nl = Locale.find_or_create_by!(name: "nl") { |l| l.title = "Nederlands" }
18
+ @de = Locale.find_or_create_by!(name: "de") { |l| l.title = "Deutsch" }
19
+
20
+ @showcase = FormElementShowcase.find_or_create_by!(title: "Locales demo")
21
+ @showcase.locales.clear
22
+ end
23
+
24
+ def field_frame(attr)
25
+ "form_element_showcase_#{@showcase.id}_#{attr}"
26
+ end
27
+
28
+ def field_headers(attr)
29
+ { "Turbo-Frame" => field_frame(attr), "Accept" => "text/html" }
30
+ end
31
+
32
+ test "check_list locales toggles the HABTM association" do
33
+ frame = field_frame(:locales)
34
+
35
+ # Initially empty; PUT with two locales checked.
36
+ put form_element_showcase_path(
37
+ @showcase,
38
+ attribute: "locales",
39
+ form_element: "check_list",
40
+ update: frame
41
+ ), params: { locales: { @en.id.to_s => 1, @de.id.to_s => 1 } }, headers: field_headers(:locales)
42
+
43
+ assert_response :success
44
+ assert_equal [@en.id, @de.id].sort, @showcase.reload.locale_ids.sort
45
+
46
+ # PUT again with only one locale; the missing one is uncoupled.
47
+ put form_element_showcase_path(
48
+ @showcase,
49
+ attribute: "locales",
50
+ form_element: "check_list",
51
+ update: frame
52
+ ), params: { locales: { @nl.id.to_s => 1 } }, headers: field_headers(:locales)
53
+
54
+ assert_response :success
55
+ assert_equal [@nl.id], @showcase.reload.locale_ids
56
+ end
57
+
58
+ test "info_list locales_display mirrors the locales association read-only" do
59
+ @showcase.locales << @en unless @showcase.locales.where(id: @en.id).exists?
60
+
61
+ row_frame = "form_element_showcase_#{@showcase.id}"
62
+ get form_element_showcase_path(@showcase, update: row_frame),
63
+ headers: { "Turbo-Frame" => row_frame, "Accept" => "text/html" }
64
+
65
+ assert_response :success
66
+ info_frame = field_frame(:locales_display)
67
+ assert_includes @response.body, %(<turbo-frame id="#{info_frame}">),
68
+ "expected info_list frame for :locales_display"
69
+ # info_list_show renders each item's `_presentation`. Locale's is `title`.
70
+ assert_match(/<turbo-frame id="#{info_frame}">.*#{Regexp.escape(@en.title)}/m, @response.body,
71
+ "expected #{@en.title.inspect} inside the locales_display info_list frame")
72
+ end
73
+
74
+ test "info_list locales_display empty-state renders the -- placeholder" do
75
+ @showcase.locales.clear
76
+
77
+ row_frame = "form_element_showcase_#{@showcase.id}"
78
+ get form_element_showcase_path(@showcase, update: row_frame),
79
+ headers: { "Turbo-Frame" => row_frame, "Accept" => "text/html" }
80
+
81
+ assert_response :success
82
+ info_frame = field_frame(:locales_display)
83
+ assert_match(/<turbo-frame id="#{info_frame}">[^<]*<div class='row [^']+'>--<\/div>/m, @response.body,
84
+ "expected empty `--` placeholder inside the locales_display frame")
85
+ end
86
+ end
@@ -30,7 +30,8 @@ class ExampleAppShowcasePageRenderTest < ExampleAppIntegrationTestCase
30
30
  jingle
31
31
  cover
32
32
  description
33
- roles
33
+ locales
34
+ locales_display
34
35
  created_at
35
36
  updated_at
36
37
  ].freeze
@@ -46,8 +47,7 @@ class ExampleAppShowcasePageRenderTest < ExampleAppIntegrationTestCase
46
47
  ].freeze
47
48
 
48
49
  setup do
49
- locale = Locale.find_or_create_by!(name: "en") { |l| l.title = "English" }
50
- @role = Role.find_or_create_by!(name: "superadmin") { |r| r.description = "Super Admin" }
50
+ @locale = Locale.find_or_create_by!(name: "en") { |l| l.title = "English" }
51
51
 
52
52
  @full = FormElementShowcase.find_or_create_by!(title: "Full demo") do |s|
53
53
  s.body_plain_area = "Plain text body"
@@ -68,12 +68,12 @@ class ExampleAppShowcasePageRenderTest < ExampleAppIntegrationTestCase
68
68
  s.amount = Money.from_amount(99.95, "USD") if s.respond_to?(:amount=) && defined?(Money)
69
69
  s.description = "<p>A rich-text body.</p>"
70
70
  end
71
- @full.roles << @role unless @full.roles.where(id: @role.id).exists?
71
+ @full.locales << @locale unless @full.locales.where(id: @locale.id).exists?
72
72
 
73
73
  @empty = FormElementShowcase.find_or_create_by!(title: "Empty demo") do |s|
74
74
  # Keep dropdown/scale integers at valid indices so the show helpers
75
- # do not crash on nil. The point of "empty demo" is that roles and
76
- # uploads are blank, not every integer attribute.
75
+ # do not crash on nil. The point of "empty demo" is that locales
76
+ # and uploads are blank, not every integer attribute.
77
77
  s.gender = 1
78
78
  s.rating_int = 1
79
79
  s.priority = 1
@@ -103,22 +103,21 @@ class ExampleAppShowcasePageRenderTest < ExampleAppIntegrationTestCase
103
103
  "expected header label for #{attr} (#{label.inspect})"
104
104
  end
105
105
 
106
- assert_includes @response.body, @role.name,
107
- "expected info_list to render the role's _presentation"
106
+ assert_includes @response.body, @locale.title,
107
+ "expected info_list to render the locale's _presentation"
108
108
  end
109
109
 
110
- test "empty showcase info_list renders the no-roles placeholder" do
110
+ test "empty showcase info_list renders the no-locales placeholder" do
111
111
  row_frame = "form_element_showcase_#{@empty.id}"
112
112
  get form_element_showcase_path(@empty, update: row_frame),
113
113
  headers: { "Turbo-Frame" => row_frame, "Accept" => "text/html" }
114
114
 
115
115
  assert_response :success
116
- frame = "form_element_showcase_#{@empty.id}_roles"
116
+ frame = "form_element_showcase_#{@empty.id}_locales_display"
117
117
  body = @response.body
118
118
  assert_includes body, %(<turbo-frame id="#{frame}">)
119
- frame_block = body[body.index(%(<turbo-frame id="#{frame}">"))..-1] rescue nil
120
119
  # info_list_show emits a `--` placeholder for empty associations.
121
120
  assert_match(/<turbo-frame id="#{frame}">[^<]*<div class='row [^']+'>--<\/div>/m, body,
122
- "expected info_list empty placeholder `--` inside roles frame")
121
+ "expected info_list empty placeholder `--` inside locales_display frame")
123
122
  end
124
123
  end
@@ -36,7 +36,8 @@ class ExampleAppFormElementShowcaseTest < ActiveSupport::TestCase
36
36
  cover
37
37
  header_rich
38
38
  description
39
- roles
39
+ locales
40
+ locales_display
40
41
  header_meta
41
42
  created_at
42
43
  updated_at
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: inline_forms_installer
3
3
  version: !ruby/object:Gem::Version
4
- version: 8.1.8
4
+ version: 8.1.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ace Suares
@@ -94,6 +94,9 @@ files:
94
94
  - lib/installer_templates/example_app_assets/3stars.png
95
95
  - lib/installer_templates/example_app_assets/4stars.png
96
96
  - lib/installer_templates/example_app_assets/5stars.png
97
+ - lib/installer_templates/example_app_assets/sample.txt
98
+ - lib/installer_templates/example_app_assets/sample.wav
99
+ - lib/installer_templates/example_app_assets/sample_cover.png
97
100
  - lib/installer_templates/example_app_tests/test/example_app/example_integration_test_case.rb
98
101
  - lib/installer_templates/example_app_tests/test/integration/example_app_apartment_field_turbo_test.rb
99
102
  - lib/installer_templates/example_app_tests/test/integration/example_app_apartment_name_list_test.rb
@@ -111,6 +114,7 @@ files:
111
114
  - lib/installer_templates/example_app_tests/test/integration/example_app_routing_test.rb
112
115
  - lib/installer_templates/example_app_tests/test/integration/example_app_showcase_choice_scale_fields_test.rb
113
116
  - lib/installer_templates/example_app_tests/test/integration/example_app_showcase_date_time_fields_test.rb
117
+ - lib/installer_templates/example_app_tests/test/integration/example_app_showcase_locales_associations_test.rb
114
118
  - lib/installer_templates/example_app_tests/test/integration/example_app_showcase_numeric_fields_test.rb
115
119
  - lib/installer_templates/example_app_tests/test/integration/example_app_showcase_page_render_test.rb
116
120
  - lib/installer_templates/example_app_tests/test/integration/example_app_showcase_text_fields_test.rb