inline_forms 8.1.75 → 8.1.76
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 +25 -1
- data/README.rdoc +1 -1
- data/inline_forms.gemspec +0 -1
- data/lib/generators/USAGE +1 -1
- data/lib/generators/inline_forms_addto/USAGE +1 -1
- data/lib/generators/inline_forms_addto_generator.rb +30 -139
- data/lib/generators/inline_forms_attribute_list_editor.rb +211 -0
- data/lib/generators/inline_forms_attribute_overrides.rb +9 -0
- data/lib/generators/inline_forms_generator.rb +16 -35
- data/lib/inline_forms/gem_files.rb +20 -17
- data/lib/inline_forms/version.rb +1 -1
- metadata +3 -142
- data/.document +0 -5
- data/.forgejo/brakeman-engine.sh +0 -51
- data/.forgejo/brakeman.ignore +0 -211
- data/.forgejo/workflows/ci.yml +0 -74
- data/.forgejo/workflows/full-gate.yml +0 -104
- data/.gitignore +0 -39
- data/.rubocop.yml +0 -31
- data/.rubocop_todo.yml +0 -151
- data/.ruby-version +0 -1
- data/Gemfile +0 -28
- data/Rakefile +0 -103
- data/script/migrate_form_elements.rb +0 -62
- data/test/archived_form_elements_test.rb +0 -101
- data/test/attribute_list_test.rb +0 -165
- data/test/dummy/app/controllers/application_controller.rb +0 -32
- data/test/dummy/app/controllers/daily_reports_controller.rb +0 -4
- data/test/dummy/app/controllers/documents_controller.rb +0 -4
- data/test/dummy/app/controllers/dossiers_controller.rb +0 -4
- data/test/dummy/app/controllers/gizmos_controller.rb +0 -4
- data/test/dummy/app/controllers/machines_controller.rb +0 -4
- data/test/dummy/app/controllers/parts_controller.rb +0 -4
- data/test/dummy/app/controllers/stats_controller.rb +0 -10
- data/test/dummy/app/controllers/widgets_controller.rb +0 -4
- data/test/dummy/app/helpers/application_helper.rb +0 -13
- data/test/dummy/app/models/ability.rb +0 -15
- data/test/dummy/app/models/application_record.rb +0 -27
- data/test/dummy/app/models/daily_report.rb +0 -21
- data/test/dummy/app/models/document.rb +0 -33
- data/test/dummy/app/models/dossier.rb +0 -38
- data/test/dummy/app/models/gizmo.rb +0 -25
- data/test/dummy/app/models/kind.rb +0 -8
- data/test/dummy/app/models/machine.rb +0 -24
- data/test/dummy/app/models/part.rb +0 -17
- data/test/dummy/app/models/phase.rb +0 -9
- data/test/dummy/app/models/widget.rb +0 -40
- data/test/dummy/app/views/_gizmos_search.html.erb +0 -3
- data/test/dummy/app/views/stats/show.html.erb +0 -1
- data/test/dummy/config/application.rb +0 -49
- data/test/dummy/config/database.yml +0 -3
- data/test/dummy/config/environment.rb +0 -5
- data/test/dummy/config/initializers/inline_forms.rb +0 -6
- data/test/dummy/config/initializers/paper_trail_yaml_safe_load.rb +0 -28
- data/test/dummy/config/routes.rb +0 -51
- data/test/form_element_from_callee_test.rb +0 -73
- data/test/gem_package_modes_test.rb +0 -86
- data/test/inline_edit_polymorphic_path_test.rb +0 -81
- data/test/inline_forms_addto_generator_test.rb +0 -584
- data/test/inline_forms_generator_test.rb +0 -301
- data/test/integration/csp_nonce_test.rb +0 -50
- data/test/integration/dropdown_test.rb +0 -186
- data/test/integration/field_authorization_test.rb +0 -131
- data/test/integration/file_slots_test.rb +0 -665
- data/test/integration/html_refusal_test.rb +0 -152
- data/test/integration/inline_forms_crud_test.rb +0 -165
- data/test/integration/layout_title_test.rb +0 -56
- data/test/integration/legacy_elements_test.rb +0 -99
- data/test/integration/list_params_test.rb +0 -200
- data/test/integration/locale_test.rb +0 -234
- data/test/integration/model_top_bar_test.rb +0 -85
- data/test/integration/native_inputs_test.rb +0 -138
- data/test/integration/open_after_create_test.rb +0 -85
- data/test/integration/pending_migration_gate_test.rb +0 -75
- data/test/integration/presentation_escaping_test.rb +0 -80
- data/test/integration/revert_skipped_columns_test.rb +0 -59
- data/test/integration/schema_batch_pipeline_test.rb +0 -189
- data/test/integration/schema_edit_test.rb +0 -141
- data/test/integration/schema_preview_test.rb +0 -65
- data/test/integration/turbo_menu_test.rb +0 -60
- data/test/integration_test_helper.rb +0 -203
- data/test/plain_text_configuration_test.rb +0 -90
- data/test/schema_apply_test.rb +0 -73
- data/test/schema_intent_test.rb +0 -53
- data/test/schema_label_test.rb +0 -61
- data/test/tabs_test.rb +0 -98
- data/test/test_helper.rb +0 -10
- data/test/user_model_config_test.rb +0 -44
|
@@ -1,234 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require_relative "../integration_test_helper"
|
|
4
|
-
|
|
5
|
-
# The gem's own strings resolve in en and nl, also under
|
|
6
|
-
# raise_on_missing_translations (StProject switched to :nl with :strict):
|
|
7
|
-
# the create flash (`success`, misspelled `succes` in both locale files), the
|
|
8
|
-
# versions panel (was hard-coded English), the nl view keys that were missing
|
|
9
|
-
# (restore, list_versions, close_versions_list, undelete), localized version
|
|
10
|
-
# timestamps, the Devise layout's lang and the sign-in button.
|
|
11
|
-
class LocaleTest < InlineFormsIntegrationTestCase
|
|
12
|
-
KEYS = %w[
|
|
13
|
-
success
|
|
14
|
-
inline_forms.view.restore inline_forms.view.list_versions inline_forms.view.close_versions_list
|
|
15
|
-
inline_forms.view.undelete inline_forms.view.versions inline_forms.view.versions_event
|
|
16
|
-
inline_forms.view.versions_when inline_forms.view.versions_done_by inline_forms.view.versions_changeset
|
|
17
|
-
inline_forms.view.versions_old_value inline_forms.view.versions_new_value inline_forms.view.versions_empty
|
|
18
|
-
inline_forms.view.versions_rich_text inline_forms.view.version_events.create
|
|
19
|
-
inline_forms.view.version_events.update inline_forms.view.version_events.destroy
|
|
20
|
-
inline_forms.devise.login common.more common.logout inline_forms.view.create_failed
|
|
21
|
-
inline_forms.files.preview inline_forms.files.download_pdf
|
|
22
|
-
inline_forms.search.placeholder inline_forms.search.submit inline_forms.search.reset
|
|
23
|
-
inline_forms.devise.welcome_to time.formats.inline_forms
|
|
24
|
-
].freeze
|
|
25
|
-
|
|
26
|
-
setup do
|
|
27
|
-
@machine = Machine.create!(name: "Press")
|
|
28
|
-
@machine.update!(name: "Press 2")
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
teardown do
|
|
32
|
-
I18n.backend.reload!
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
# Every translation the request looks up must exist: a missing one raises,
|
|
36
|
-
# in the views and in the controller (create's flash).
|
|
37
|
-
def strictly(locale)
|
|
38
|
-
original_view = ActionView::Helpers::TranslationHelper.raise_on_missing_translations
|
|
39
|
-
original_handler = I18n.exception_handler
|
|
40
|
-
original_default = I18n.default_locale
|
|
41
|
-
ActionView::Helpers::TranslationHelper.raise_on_missing_translations = true
|
|
42
|
-
I18n.exception_handler = ->(exception, *) { raise exception.respond_to?(:to_exception) ? exception.to_exception : exception }
|
|
43
|
-
# with_locale first: it restores the locale it found, so the thread's
|
|
44
|
-
# locale must not be read after default_locale changed (it would then
|
|
45
|
-
# restore :nl for every later test).
|
|
46
|
-
I18n.with_locale(locale) do
|
|
47
|
-
I18n.default_locale = locale
|
|
48
|
-
yield
|
|
49
|
-
end
|
|
50
|
-
ensure
|
|
51
|
-
I18n.default_locale = original_default
|
|
52
|
-
ActionView::Helpers::TranslationHelper.raise_on_missing_translations = original_view
|
|
53
|
-
I18n.exception_handler = original_handler
|
|
54
|
-
end
|
|
55
|
-
|
|
56
|
-
test "the gem's keys exist in en and nl, and the misspelled succes is gone" do
|
|
57
|
-
%i[en nl].each do |locale|
|
|
58
|
-
KEYS.each { |key| assert I18n.exists?(key, locale), "#{locale}.#{key}" }
|
|
59
|
-
refute I18n.exists?("succes", locale), "#{locale}.succes"
|
|
60
|
-
end
|
|
61
|
-
assert_equal "Machine created.", I18n.t("success", message: "Machine", locale: :en)
|
|
62
|
-
assert_equal "Machine is aangemaakt.", I18n.t("success", message: "Machine", locale: :nl)
|
|
63
|
-
end
|
|
64
|
-
|
|
65
|
-
test "create's success flash translates in nl" do
|
|
66
|
-
# The model top bar shows t(controller_name): host-supplied, like
|
|
67
|
-
# StProject's `clients: cliënten`.
|
|
68
|
-
I18n.backend.store_translations(:nl, machines: "machines")
|
|
69
|
-
strictly(:nl) do
|
|
70
|
-
post machines_path(update: "machines_list"), params: { name: "Lathe" }, headers: frame_headers("machines_list")
|
|
71
|
-
end
|
|
72
|
-
|
|
73
|
-
assert_response :success
|
|
74
|
-
assert_equal "Machine is aangemaakt.", controller.flash[:success]
|
|
75
|
-
end
|
|
76
|
-
|
|
77
|
-
# The failure header was hard-coded Dutch with the underscored class name
|
|
78
|
-
# ("Kan machine niet aanmaken.") in every locale.
|
|
79
|
-
test "create's failure flash header translates, with the human model name" do
|
|
80
|
-
I18n.backend.store_translations(:nl, machines: "machines",
|
|
81
|
-
activerecord: { models: { machine: "Werkbank" } })
|
|
82
|
-
strictly(:nl) do
|
|
83
|
-
post machines_path(update: "machines_list"), params: { name: "" }, headers: frame_headers("machines_list")
|
|
84
|
-
end
|
|
85
|
-
assert_equal [ "Kan Werkbank niet aanmaken." ], controller.flash[:header]
|
|
86
|
-
|
|
87
|
-
I18n.backend.store_translations(:en, machines: "machines")
|
|
88
|
-
strictly(:en) do
|
|
89
|
-
post machines_path(update: "machines_list"), params: { name: "" }, headers: frame_headers("machines_list")
|
|
90
|
-
end
|
|
91
|
-
assert_equal [ "Could not create Machine." ], controller.flash[:header]
|
|
92
|
-
assert_includes response.body, "Could not create Machine."
|
|
93
|
-
end
|
|
94
|
-
|
|
95
|
-
test "the versions panel and list are translated, with localized timestamps" do
|
|
96
|
-
row = "machine_#{@machine.id}"
|
|
97
|
-
strictly(:nl) do
|
|
98
|
-
get machine_path(@machine, update: row), headers: frame_headers(row)
|
|
99
|
-
assert_response :success
|
|
100
|
-
assert_includes response.body, "Versies (2)"
|
|
101
|
-
|
|
102
|
-
get list_versions_machine_path(@machine, update: row), headers: frame_headers(row)
|
|
103
|
-
end
|
|
104
|
-
|
|
105
|
-
assert_response :success
|
|
106
|
-
body = response.body
|
|
107
|
-
%w[Versies Gebeurtenis Wanneer Door Wijzigingen aangemaakt gewijzigd terugzetten].each do |text|
|
|
108
|
-
assert_includes body, text
|
|
109
|
-
end
|
|
110
|
-
refute_includes body, "<strong>Event</strong>"
|
|
111
|
-
version = @machine.versions.last
|
|
112
|
-
assert_includes body, ERB::Util.h(I18n.l(version.created_at, format: :inline_forms, locale: :nl))
|
|
113
|
-
end
|
|
114
|
-
|
|
115
|
-
# rails-i18n's :short ("%d %b %H:%M") has no year: edits years apart read
|
|
116
|
-
# the same next to Restore.
|
|
117
|
-
test "version timestamps show the year, and the exact time on hover" do
|
|
118
|
-
version = @machine.versions.last
|
|
119
|
-
version.update_columns(created_at: Time.zone.local(2019, 3, 5, 14, 7))
|
|
120
|
-
row = "machine_#{@machine.id}"
|
|
121
|
-
strictly(:nl) do
|
|
122
|
-
get list_versions_machine_path(@machine, update: row), headers: frame_headers(row)
|
|
123
|
-
end
|
|
124
|
-
|
|
125
|
-
assert_response :success
|
|
126
|
-
iso = version.reload.created_at.iso8601
|
|
127
|
-
assert_includes response.body, %(<time datetime="#{iso}" title="#{iso}">05 mrt 2019 14:07</time>)
|
|
128
|
-
end
|
|
129
|
-
|
|
130
|
-
test "the generic search box is translated" do
|
|
131
|
-
I18n.backend.store_translations(:en, widgets: "widgets")
|
|
132
|
-
I18n.backend.store_translations(:nl, widgets: "widgets")
|
|
133
|
-
{ en: [ "search...", "search", "reset" ], nl: [ "zoeken...", "zoek", "wissen" ] }.each do |locale, (placeholder, submit, reset)|
|
|
134
|
-
strictly(locale) { get widgets_path }
|
|
135
|
-
|
|
136
|
-
assert_response :success
|
|
137
|
-
assert_includes response.body, %(placeholder="#{placeholder}")
|
|
138
|
-
assert_includes response.body, %(value="#{submit}")
|
|
139
|
-
assert_includes response.body, %(title="#{reset}")
|
|
140
|
-
refute_includes response.body, "zoek op naam" if locale == :en
|
|
141
|
-
end
|
|
142
|
-
end
|
|
143
|
-
|
|
144
|
-
# The gem shipped "Application Title" / "Title for Devise" / "Welcome for
|
|
145
|
-
# Devise" in en and nl; any locale the host did not override showed them.
|
|
146
|
-
# The keys now resolve to the application's name, also when a host view
|
|
147
|
-
# calls them bare.
|
|
148
|
-
test "the gem's title keys resolve to the application's name" do
|
|
149
|
-
get widgets_path
|
|
150
|
-
I18n.backend.store_translations(:nl, application_name: "Werkplaats")
|
|
151
|
-
strictly(:nl) do
|
|
152
|
-
assert_equal "Werkplaats", I18n.t("inline_forms.general.application_title")
|
|
153
|
-
assert_equal "Werkplaats", I18n.t("inline_forms.devise.title_for_devise")
|
|
154
|
-
assert_equal "Welkom bij Werkplaats!", I18n.t("inline_forms.devise.welcome")
|
|
155
|
-
devise = controller.render_to_string(template: "stats/show", layout: "devise")
|
|
156
|
-
assert_includes devise, "Werkplaats v#{InlineForms::VERSION}"
|
|
157
|
-
top_bar = controller.render_to_string(partial: "devise/sessions/top-bar")
|
|
158
|
-
assert_includes top_bar, "Werkplaats #{InlineForms::VERSION}"
|
|
159
|
-
end
|
|
160
|
-
I18n.with_locale(:en) do
|
|
161
|
-
# No en application_name translation here: the host's
|
|
162
|
-
# ApplicationHelper#application_name.
|
|
163
|
-
assert_equal "Dummy", I18n.t("inline_forms.general.application_title")
|
|
164
|
-
assert_equal "Welcome to Dummy!", I18n.t("inline_forms.devise.welcome")
|
|
165
|
-
assert_includes controller.render_to_string(template: "stats/show", layout: "application"), "Dummy v#{InlineForms::VERSION}"
|
|
166
|
-
end
|
|
167
|
-
ensure
|
|
168
|
-
I18n.backend.reload!
|
|
169
|
-
end
|
|
170
|
-
|
|
171
|
-
test "a host translation of a title key wins" do
|
|
172
|
-
I18n.t("inline_forms.general.application_title") # loads the gem's files first, as a host app does
|
|
173
|
-
I18n.backend.store_translations(:nl, inline_forms: { general: { application_title: "Banko" } })
|
|
174
|
-
|
|
175
|
-
assert_equal "Banko", I18n.t("inline_forms.general.application_title", locale: :nl)
|
|
176
|
-
ensure
|
|
177
|
-
I18n.backend.reload!
|
|
178
|
-
end
|
|
179
|
-
|
|
180
|
-
# time.formats.inline_forms is defined in en and nl only; a bare
|
|
181
|
-
# l(format: :inline_forms) raises in any other locale without fallbacks.
|
|
182
|
-
test "version and trash timestamps render in a locale without the gem's format" do
|
|
183
|
-
original = I18n.available_locales
|
|
184
|
-
I18n.available_locales = original + [ :de ]
|
|
185
|
-
months = %w[Jan Feb Mär Apr Mai Jun Jul Aug Sep Okt Nov Dez]
|
|
186
|
-
I18n.backend.store_translations(:de, date: { abbr_month_names: [ nil, *months ] })
|
|
187
|
-
time = Time.zone.local(2019, 3, 5, 14, 7)
|
|
188
|
-
|
|
189
|
-
I18n.with_locale(:de) do
|
|
190
|
-
assert_raises(I18n::MissingTranslationData) { I18n.l(time, format: :inline_forms, raise: true) }
|
|
191
|
-
assert_equal "05 Mär 2019 14:07", ApplicationController.helpers.send(:inline_forms_time_text, time)
|
|
192
|
-
end
|
|
193
|
-
ensure
|
|
194
|
-
I18n.available_locales = original
|
|
195
|
-
I18n.backend.reload!
|
|
196
|
-
end
|
|
197
|
-
|
|
198
|
-
test "the versions list in en keeps its English labels" do
|
|
199
|
-
row = "machine_#{@machine.id}"
|
|
200
|
-
strictly(:en) do
|
|
201
|
-
get list_versions_machine_path(@machine, update: row), headers: frame_headers(row)
|
|
202
|
-
end
|
|
203
|
-
|
|
204
|
-
assert_response :success
|
|
205
|
-
assert_includes response.body, "Versions (2)"
|
|
206
|
-
assert_includes response.body, "<strong>Event</strong>"
|
|
207
|
-
assert_includes response.body, "old value"
|
|
208
|
-
end
|
|
209
|
-
|
|
210
|
-
test "pdf_link reads Dutch" do
|
|
211
|
-
original_default = I18n.default_locale
|
|
212
|
-
widget = Widget.create!(name: "Rapport")
|
|
213
|
-
frame = "widget_#{widget.id}"
|
|
214
|
-
|
|
215
|
-
# Not strictly: the dummy's dropdown values have no nl texts.
|
|
216
|
-
I18n.with_locale(:nl) do
|
|
217
|
-
I18n.default_locale = :nl
|
|
218
|
-
get widget_path(widget, update: frame), headers: frame_headers(frame)
|
|
219
|
-
end
|
|
220
|
-
|
|
221
|
-
assert_response :success
|
|
222
|
-
assert_match %r{>voorbeeld</a> \| <a[^>]*>pdf downloaden</a>}, response.body
|
|
223
|
-
ensure
|
|
224
|
-
I18n.default_locale = original_default
|
|
225
|
-
end
|
|
226
|
-
|
|
227
|
-
test "the devise and application layouts declare the page language" do
|
|
228
|
-
get widgets_path
|
|
229
|
-
I18n.with_locale(:nl) do
|
|
230
|
-
assert_includes controller.render_to_string(template: "stats/show", layout: "devise"), %(<html lang="nl">)
|
|
231
|
-
assert_includes controller.render_to_string(template: "stats/show", layout: "application"), %(<html lang="nl">)
|
|
232
|
-
end
|
|
233
|
-
end
|
|
234
|
-
end
|
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require_relative "../integration_test_helper"
|
|
4
|
-
|
|
5
|
-
# Engine-owned model top bar: title + new-record + optional search region.
|
|
6
|
-
class ModelTopBarTest < InlineFormsIntegrationTestCase
|
|
7
|
-
setup do
|
|
8
|
-
@widget = Widget.create!(name: "Alpha")
|
|
9
|
-
@machine = Machine.create!(name: "Press")
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
test "searchable model renders the engine generic search box" do
|
|
13
|
-
get widgets_path
|
|
14
|
-
|
|
15
|
-
assert_response :success
|
|
16
|
-
assert_includes response.body, %(id="input_search")
|
|
17
|
-
assert_includes response.body, %(id="inline_forms_model_top_bar")
|
|
18
|
-
refute_includes response.body, "bespoke gizmo search"
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
test "non-searchable model renders no search box" do
|
|
22
|
-
get machines_path
|
|
23
|
-
|
|
24
|
-
assert_response :success
|
|
25
|
-
assert_includes response.body, %(id="inline_forms_model_top_bar")
|
|
26
|
-
refute_includes response.body, %(id="input_search")
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
test "bespoke _<model>_search partial wins over generic search" do
|
|
30
|
-
get gizmos_path
|
|
31
|
-
|
|
32
|
-
assert_response :success
|
|
33
|
-
assert_includes response.body, %(id="bespoke_gizmo_search")
|
|
34
|
-
refute_includes response.body, %(id="input_search")
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
test "generic search box filters the list via inline_forms_search_on" do
|
|
38
|
-
Widget.create!(name: "Beta")
|
|
39
|
-
|
|
40
|
-
get widgets_path(search: "Alp")
|
|
41
|
-
|
|
42
|
-
assert_response :success
|
|
43
|
-
assert_includes response.body, "Alpha"
|
|
44
|
-
refute_includes response.body, "Beta"
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
test "no schema GUI link in the engine top bar, even with the schema routes drawn" do
|
|
48
|
-
assert respond_to?(:inline_forms_schema_new_path), "precondition: the dummy draws the schema routes"
|
|
49
|
-
get widgets_path
|
|
50
|
-
|
|
51
|
-
assert_response :success
|
|
52
|
-
refute_includes response.body, "+ field"
|
|
53
|
-
refute_includes response.body, %(href="#{inline_forms_schema_new_path}")
|
|
54
|
-
end
|
|
55
|
-
|
|
56
|
-
test "non-model page with no @Klass renders title only, no new-record link" do
|
|
57
|
-
get stats_path
|
|
58
|
-
|
|
59
|
-
assert_response :success
|
|
60
|
-
assert_includes response.body, %(id="inline_forms_model_top_bar")
|
|
61
|
-
assert_includes response.body, %(id="stats_report")
|
|
62
|
-
refute_includes response.body, "new_button"
|
|
63
|
-
refute_includes response.body, %(id="input_search")
|
|
64
|
-
end
|
|
65
|
-
|
|
66
|
-
# The class body runs whenever the model loads (eager loading,
|
|
67
|
-
# assets:precompile with no database); quoting there needed a connection.
|
|
68
|
-
test "inline_forms_search_on needs no database connection until the search runs" do
|
|
69
|
-
model = Class.new(ApplicationRecord) do
|
|
70
|
-
self.table_name = "widgets"
|
|
71
|
-
def self.name = "OfflineWidget"
|
|
72
|
-
end
|
|
73
|
-
no_db = ->(*) { raise "database touched at declaration" }
|
|
74
|
-
%i[connection lease_connection with_connection].each { |m| model.define_singleton_method(m, &no_db) }
|
|
75
|
-
|
|
76
|
-
model.inline_forms_search_on :name
|
|
77
|
-
|
|
78
|
-
assert model.inline_forms_searchable?
|
|
79
|
-
%i[connection lease_connection with_connection].each { |m| model.singleton_class.remove_method(m) }
|
|
80
|
-
Widget.create!(name: "Gamma")
|
|
81
|
-
assert_equal [ "Gamma" ], model.inline_forms_search("amm").pluck(:name)
|
|
82
|
-
# Built once, on the first search.
|
|
83
|
-
assert_same model.inline_forms_search_clause, model.inline_forms_search_clause
|
|
84
|
-
end
|
|
85
|
-
end
|
|
@@ -1,138 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require_relative "../integration_test_helper"
|
|
4
|
-
|
|
5
|
-
# Engine-level render coverage for the native-input form elements introduced
|
|
6
|
-
# in 8.1.25/8.1.26 (previously only covered by the example-app gate).
|
|
7
|
-
class NativeInputsTest < InlineFormsIntegrationTestCase
|
|
8
|
-
setup do
|
|
9
|
-
@widget = Widget.create!(
|
|
10
|
-
name: "Native",
|
|
11
|
-
released_on: Date.new(2026, 5, 17),
|
|
12
|
-
meeting_at: Time.utc(2000, 1, 1, 9, 15),
|
|
13
|
-
start_month: Date.new(2026, 5, 1),
|
|
14
|
-
priority: 2,
|
|
15
|
-
rating: 3
|
|
16
|
-
)
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
def edit_attribute(attribute, form_element)
|
|
20
|
-
frame = "widget_#{@widget.id}_#{attribute}"
|
|
21
|
-
get edit_widget_path(@widget, attribute: attribute, form_element: form_element,
|
|
22
|
-
update: frame),
|
|
23
|
-
headers: frame_headers(frame)
|
|
24
|
-
assert_response :success
|
|
25
|
-
response.body
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
test "date_select renders a native date input with ISO value" do
|
|
29
|
-
body = edit_attribute("released_on", "date_select")
|
|
30
|
-
assert_includes body, %(type="date")
|
|
31
|
-
assert_includes body, %(value="2026-05-17")
|
|
32
|
-
refute_includes body, "<script"
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
test "time_select renders a native time input with HH:MM value" do
|
|
36
|
-
body = edit_attribute("meeting_at", "time_select")
|
|
37
|
-
assert_includes body, %(type="time")
|
|
38
|
-
assert_includes body, %(value="09:15")
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
test "month_year_picker renders a native month input with YYYY-MM value" do
|
|
42
|
-
body = edit_attribute("start_month", "month_year_picker")
|
|
43
|
-
assert_includes body, %(type="month")
|
|
44
|
-
assert_includes body, %(value="2026-05")
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
test "month_year_picker update accepts native and legacy formats" do
|
|
48
|
-
frame = "widget_#{@widget.id}_start_month"
|
|
49
|
-
|
|
50
|
-
put widget_path(@widget, attribute: "start_month",
|
|
51
|
-
form_element: "month_year_picker", update: frame),
|
|
52
|
-
params: { start_month: "2026-09" }, headers: frame_headers(frame)
|
|
53
|
-
assert_equal Date.new(2026, 9, 1), @widget.reload.start_month
|
|
54
|
-
|
|
55
|
-
put widget_path(@widget, attribute: "start_month",
|
|
56
|
-
form_element: "month_year_picker", update: frame),
|
|
57
|
-
params: { start_month: "November 2027" }, headers: frame_headers(frame)
|
|
58
|
-
assert_equal Date.new(2027, 11, 1), @widget.reload.start_month
|
|
59
|
-
end
|
|
60
|
-
|
|
61
|
-
test "dropdown_with_other renders a datalist-backed combobox without inline scripts" do
|
|
62
|
-
Kind.create!(name: "Gadget")
|
|
63
|
-
Kind.create!(name: "Gizmo")
|
|
64
|
-
|
|
65
|
-
body = edit_attribute("kind", "dropdown_with_other")
|
|
66
|
-
assert_includes body, "<datalist"
|
|
67
|
-
assert_includes body, %(<option value="Gadget">)
|
|
68
|
-
assert_includes body, %(<option value="Gizmo">)
|
|
69
|
-
assert_includes body, %(name="_widget[kind_other]")
|
|
70
|
-
refute_includes body, "<script"
|
|
71
|
-
end
|
|
72
|
-
|
|
73
|
-
test "dropdown_with_other update matches an existing record by name" do
|
|
74
|
-
kind = Kind.create!(name: "Gadget")
|
|
75
|
-
frame = "widget_#{@widget.id}_kind"
|
|
76
|
-
|
|
77
|
-
put widget_path(@widget, attribute: "kind",
|
|
78
|
-
form_element: "dropdown_with_other", update: frame),
|
|
79
|
-
params: { _widget: { kind_other: "Gadget" } }, headers: frame_headers(frame)
|
|
80
|
-
|
|
81
|
-
assert_response :success
|
|
82
|
-
@widget.reload
|
|
83
|
-
assert_equal kind.id, @widget.kind_id
|
|
84
|
-
assert_nil @widget.kind_other
|
|
85
|
-
end
|
|
86
|
-
|
|
87
|
-
test "dropdown_with_other update stores unmatched text as the other value" do
|
|
88
|
-
Kind.create!(name: "Gadget")
|
|
89
|
-
frame = "widget_#{@widget.id}_kind"
|
|
90
|
-
|
|
91
|
-
put widget_path(@widget, attribute: "kind",
|
|
92
|
-
form_element: "dropdown_with_other", update: frame),
|
|
93
|
-
params: { _widget: { kind_other: "Completely new thing" } },
|
|
94
|
-
headers: frame_headers(frame)
|
|
95
|
-
|
|
96
|
-
assert_response :success
|
|
97
|
-
@widget.reload
|
|
98
|
-
assert_equal 0, @widget.kind_id
|
|
99
|
-
assert_equal "Completely new thing", @widget.kind_other
|
|
100
|
-
end
|
|
101
|
-
|
|
102
|
-
test "slider_with_values renders a native range input with label data" do
|
|
103
|
-
body = edit_attribute("rating", "slider_with_values")
|
|
104
|
-
assert_includes body, %(type="range")
|
|
105
|
-
assert_includes body, "slider_with_values"
|
|
106
|
-
assert_includes body, "data-slider-values"
|
|
107
|
-
assert_includes body, %(<output)
|
|
108
|
-
refute_includes body, "<script"
|
|
109
|
-
end
|
|
110
|
-
|
|
111
|
-
test "slider_with_values show renders a progress bar (clickable, non-interactive)" do
|
|
112
|
-
frame = "widget_#{@widget.id}"
|
|
113
|
-
get widget_path(@widget, update: frame), headers: frame_headers(frame)
|
|
114
|
-
|
|
115
|
-
assert_response :success
|
|
116
|
-
assert_includes response.body, "<progress"
|
|
117
|
-
end
|
|
118
|
-
|
|
119
|
-
test "color_field renders a native color input and round-trips a hex value" do
|
|
120
|
-
@widget.update!(accent: "#a3381e")
|
|
121
|
-
body = edit_attribute("accent", "color_field")
|
|
122
|
-
assert_includes body, %(type="color")
|
|
123
|
-
assert_includes body, %(value="#a3381e")
|
|
124
|
-
|
|
125
|
-
frame = "widget_#{@widget.id}_accent"
|
|
126
|
-
put widget_path(@widget, attribute: "accent", form_element: "color_field",
|
|
127
|
-
update: frame),
|
|
128
|
-
params: { accent: "#2563EB" }, headers: frame_headers(frame)
|
|
129
|
-
assert_response :success
|
|
130
|
-
assert_equal "#2563eb", @widget.reload.accent, "hex is normalized to lowercase"
|
|
131
|
-
|
|
132
|
-
# Junk input is rejected server-side (stored as nil), not persisted raw.
|
|
133
|
-
put widget_path(@widget, attribute: "accent", form_element: "color_field",
|
|
134
|
-
update: frame),
|
|
135
|
-
params: { accent: "red; background:url(x)" }, headers: frame_headers(frame)
|
|
136
|
-
assert_nil @widget.reload.accent
|
|
137
|
-
end
|
|
138
|
-
end
|
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require_relative "../integration_test_helper"
|
|
4
|
-
|
|
5
|
-
# "Open after create" (stuff/2026-07-10-nested-creation-options.md, Option A):
|
|
6
|
-
# a successful top-level create of a class with an :associated (has_many)
|
|
7
|
-
# panel responds with Turbo Streams that refresh the list and open the new
|
|
8
|
-
# record's row, so the nested panel is immediately usable. Everything else
|
|
9
|
-
# (classes without :associated, nested creates, failed saves, non-stream
|
|
10
|
-
# clients) keeps the plain frame responses.
|
|
11
|
-
class OpenAfterCreateTest < InlineFormsIntegrationTestCase
|
|
12
|
-
# Turbo form submissions advertise turbo-stream before text/html.
|
|
13
|
-
def stream_headers(frame_id)
|
|
14
|
-
{ "Turbo-Frame" => frame_id,
|
|
15
|
-
"Accept" => "text/vnd.turbo-stream.html, text/html" }
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
test "top-level create with an associated panel streams the list and the opened row" do
|
|
19
|
-
assert_difference -> { Machine.count }, +1 do
|
|
20
|
-
post machines_path(update: "machines_list"),
|
|
21
|
-
params: { name: "Lathe" },
|
|
22
|
-
headers: stream_headers("machines_list")
|
|
23
|
-
end
|
|
24
|
-
assert_response :success
|
|
25
|
-
assert_equal "text/vnd.turbo-stream.html", response.media_type
|
|
26
|
-
|
|
27
|
-
machine = Machine.find_by!(name: "Lathe")
|
|
28
|
-
assert_includes response.body,
|
|
29
|
-
%(<turbo-stream action="replace" target="machines_list">)
|
|
30
|
-
assert_includes response.body,
|
|
31
|
-
%(<turbo-stream action="replace" target="machine_#{machine.id}">)
|
|
32
|
-
|
|
33
|
-
# The opened row exposes the parts panel with its "new part" link,
|
|
34
|
-
# carrying the freshly created parent's id.
|
|
35
|
-
assert_includes response.body, %(id="machine_#{machine.id}_parts_list_auto_header")
|
|
36
|
-
assert_match(
|
|
37
|
-
%r{/parts/new\?[^"]*parent_id=#{machine.id}},
|
|
38
|
-
response.body,
|
|
39
|
-
"expected the associated panel's new-record link for the created parent"
|
|
40
|
-
)
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
test "top-level create without turbo-stream accept keeps the list frame response" do
|
|
44
|
-
post machines_path(update: "machines_list"),
|
|
45
|
-
params: { name: "Mill" },
|
|
46
|
-
headers: frame_headers("machines_list")
|
|
47
|
-
assert_response :success
|
|
48
|
-
assert_equal "text/html", response.media_type
|
|
49
|
-
assert_includes response.body, %(<turbo-frame id="machines_list">)
|
|
50
|
-
end
|
|
51
|
-
|
|
52
|
-
test "create of a class without an associated panel is unchanged" do
|
|
53
|
-
post parts_path(update: "parts_list"),
|
|
54
|
-
params: { name: "Plain" },
|
|
55
|
-
headers: stream_headers("parts_list")
|
|
56
|
-
assert_response :success
|
|
57
|
-
assert_equal "text/html", response.media_type
|
|
58
|
-
assert_includes response.body, %(<turbo-frame id="parts_list">)
|
|
59
|
-
end
|
|
60
|
-
|
|
61
|
-
test "nested create under a parent keeps the frame response" do
|
|
62
|
-
machine = Machine.create!(name: "Host")
|
|
63
|
-
frame = "machine_#{machine.id}_parts"
|
|
64
|
-
|
|
65
|
-
assert_difference -> { Part.count }, +1 do
|
|
66
|
-
post parts_path(update: frame, parent_class: "Machine", parent_id: machine.id),
|
|
67
|
-
params: { name: "Bolt" },
|
|
68
|
-
headers: stream_headers(frame)
|
|
69
|
-
end
|
|
70
|
-
assert_response :success
|
|
71
|
-
assert_equal "text/html", response.media_type
|
|
72
|
-
assert_equal machine.id, Part.find_by!(name: "Bolt").machine_id
|
|
73
|
-
end
|
|
74
|
-
|
|
75
|
-
test "failed top-level create re-renders the new form, not streams" do
|
|
76
|
-
assert_no_difference -> { Machine.count } do
|
|
77
|
-
post machines_path(update: "machines_list"),
|
|
78
|
-
params: { name: "" },
|
|
79
|
-
headers: stream_headers("machines_list")
|
|
80
|
-
end
|
|
81
|
-
assert_response :success
|
|
82
|
-
assert_equal "text/html", response.media_type
|
|
83
|
-
assert_includes response.body, 'class="edit_form"'
|
|
84
|
-
end
|
|
85
|
-
end
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require_relative "../integration_test_helper"
|
|
4
|
-
|
|
5
|
-
# Covers the pending-migration gate: an attribute_list row whose column does
|
|
6
|
-
# not exist yet (the inline_forms_addto window between the model edit and
|
|
7
|
-
# `rails db:migrate`) must render a read-only placeholder and be skipped on
|
|
8
|
-
# write, instead of 500ing on the missing column. Gizmo's list references
|
|
9
|
-
# :pending_note, which has no column on the gizmos table (see
|
|
10
|
-
# test/integration_test_helper.rb and test/dummy/app/models/gizmo.rb).
|
|
11
|
-
class PendingMigrationGateTest < InlineFormsIntegrationTestCase
|
|
12
|
-
setup do
|
|
13
|
-
@gizmo = Gizmo.create!(name: "Gadget")
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
test "predicate flags a phantom column and only that" do
|
|
17
|
-
g = @gizmo
|
|
18
|
-
# phantom scalar column -> pending
|
|
19
|
-
assert InlineForms.attribute_pending_migration?(g, :pending_note, :text_field)
|
|
20
|
-
# real column -> not pending
|
|
21
|
-
refute InlineForms.attribute_pending_migration?(g, :name, :text_field)
|
|
22
|
-
# header is a label, never gated
|
|
23
|
-
refute InlineForms.attribute_pending_migration?(g, :section, :header)
|
|
24
|
-
# info bound to a real column
|
|
25
|
-
refute InlineForms.attribute_pending_migration?(g, :created_at, :info)
|
|
26
|
-
# relation dropdown backed by a missing foreign key -> pending
|
|
27
|
-
assert InlineForms.attribute_pending_migration?(g, :vendor, :dropdown)
|
|
28
|
-
# no-column elements are never gated
|
|
29
|
-
refute InlineForms.attribute_pending_migration?(g, :parts, :has_many)
|
|
30
|
-
refute InlineForms.attribute_pending_migration?(g, :body, :rich_text)
|
|
31
|
-
refute InlineForms.attribute_pending_migration?(g, :report, :pdf_link)
|
|
32
|
-
# exempt virtual-backed elements (column name != attribute)
|
|
33
|
-
refute InlineForms.attribute_pending_migration?(g, :amount, :money_field)
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
test "row show renders a pending placeholder and does not raise" do
|
|
37
|
-
frame = "gizmo_#{@gizmo.id}"
|
|
38
|
-
get gizmo_path(@gizmo, update: frame), headers: frame_headers(frame)
|
|
39
|
-
|
|
40
|
-
assert_response :success
|
|
41
|
-
assert_includes response.body, "pending migration"
|
|
42
|
-
# the real field still renders its own edit frame
|
|
43
|
-
assert_includes response.body, %(<turbo-frame id="gizmo_#{@gizmo.id}_name">)
|
|
44
|
-
# the phantom field is NOT rendered as an editable field frame
|
|
45
|
-
refute_includes response.body, %(<turbo-frame id="gizmo_#{@gizmo.id}_pending_note">)
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
test "new form renders a pending placeholder instead of an input" do
|
|
49
|
-
get new_gizmo_path(update: "gizmos_list"), headers: frame_headers("gizmos_list")
|
|
50
|
-
|
|
51
|
-
assert_response :success
|
|
52
|
-
assert_includes response.body, "pending migration"
|
|
53
|
-
refute_includes response.body, %(name="pending_note")
|
|
54
|
-
end
|
|
55
|
-
|
|
56
|
-
test "create skips the pending column and still saves" do
|
|
57
|
-
assert_difference -> { Gizmo.count }, +1 do
|
|
58
|
-
post gizmos_path(update: "gizmos_list"),
|
|
59
|
-
params: { name: "Fresh", pending_note: "ignored — no column yet" },
|
|
60
|
-
headers: frame_headers("gizmos_list")
|
|
61
|
-
end
|
|
62
|
-
assert_response :success
|
|
63
|
-
assert Gizmo.exists?(name: "Fresh")
|
|
64
|
-
end
|
|
65
|
-
|
|
66
|
-
test "forced update of a pending field is refused, not a 500" do
|
|
67
|
-
frame = "gizmo_#{@gizmo.id}_pending_note"
|
|
68
|
-
put gizmo_path(@gizmo, attribute: "pending_note", form_element: "text_field",
|
|
69
|
-
update: frame),
|
|
70
|
-
params: { pending_note: "x" }, headers: frame_headers(frame)
|
|
71
|
-
|
|
72
|
-
assert_response :unprocessable_entity
|
|
73
|
-
assert_includes response.body, "pending migration"
|
|
74
|
-
end
|
|
75
|
-
end
|