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,80 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require_relative "../integration_test_helper"
|
|
4
|
-
|
|
5
|
-
# Model data that a helper concatenates into a string it marks html_safe must
|
|
6
|
-
# be escaped first. info_list_show did `out << item._presentation`, so a
|
|
7
|
-
# _presentation built from user input (StProject: User#name listed on a Role)
|
|
8
|
-
# ran as markup on every page that showed the list (stored XSS). Same audit:
|
|
9
|
-
# file_field_show (stored file name / url) and the rich-text changeset in the
|
|
10
|
-
# versions list (was `raw`).
|
|
11
|
-
class PresentationEscapingTest < InlineFormsIntegrationTestCase
|
|
12
|
-
MARKUP = "<img src=x onerror=alert(1)>"
|
|
13
|
-
ESCAPED = "<img src=x onerror=alert(1)>"
|
|
14
|
-
|
|
15
|
-
# A view context of a real request: helpers, can?, url helpers.
|
|
16
|
-
def view
|
|
17
|
-
@view ||= begin
|
|
18
|
-
get widgets_path
|
|
19
|
-
controller.view_context
|
|
20
|
-
end
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
test "info_list escapes each item's _presentation" do
|
|
24
|
-
machine = Machine.create!(name: "Press")
|
|
25
|
-
Part.create!(name: MARKUP, machine: machine)
|
|
26
|
-
Part.create!(name: "Gear", machine: machine)
|
|
27
|
-
|
|
28
|
-
html = view.info_list_show(machine, :parts)
|
|
29
|
-
|
|
30
|
-
refute_includes html, "<img"
|
|
31
|
-
assert_includes html, ESCAPED
|
|
32
|
-
assert_includes html, "Gear"
|
|
33
|
-
assert_includes html, "<div class='row", "the row markup itself is kept"
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
test "file_field escapes the stored file name and url" do
|
|
37
|
-
widget = Widget.create!(name: "Manual")
|
|
38
|
-
stored = Struct.new(:url, :path) do
|
|
39
|
-
def present? = true
|
|
40
|
-
def to_s = url
|
|
41
|
-
end.new(%(/uploads/x'><img src=x onerror=alert(1)>.pdf), %(/uploads/#{MARKUP}.pdf))
|
|
42
|
-
widget.define_singleton_method(:manual) { stored }
|
|
43
|
-
|
|
44
|
-
html = view.file_field_show(widget, :manual)
|
|
45
|
-
|
|
46
|
-
refute_includes html, "<img"
|
|
47
|
-
assert_includes html, ESCAPED
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
test "dropdown_with_other and the list rows escape _presentation" do
|
|
51
|
-
kind = Kind.create!(name: MARKUP)
|
|
52
|
-
widget = Widget.create!(name: MARKUP, kind: kind)
|
|
53
|
-
|
|
54
|
-
refute_includes view.dropdown_with_other_show(widget, :kind), "<img"
|
|
55
|
-
|
|
56
|
-
get widgets_path(update: "widgets_list"), headers: frame_headers("widgets_list")
|
|
57
|
-
assert_response :success
|
|
58
|
-
refute_includes response.body, "<img"
|
|
59
|
-
assert_includes response.body, ESCAPED
|
|
60
|
-
end
|
|
61
|
-
|
|
62
|
-
test "a rich-text changeset in the versions list is sanitized, not raw" do
|
|
63
|
-
machine = Machine.create!(name: "Press")
|
|
64
|
-
version = Struct.new(:id, :event, :changeset, :created_at, :whodunnit) do
|
|
65
|
-
def to_param = id.to_s
|
|
66
|
-
end.new(1, "update", { "body" => [ "<p>old</p><script>alert(1)</script>", "<p>new</p>#{MARKUP}" ] }, Time.current, nil)
|
|
67
|
-
context = view
|
|
68
|
-
context.instance_variable_set(:@object, machine)
|
|
69
|
-
context.define_singleton_method(:inline_forms_history_for) do |_object|
|
|
70
|
-
[ { version: version, kind: :rich_text, rich_text_name: "description", at: version.created_at } ]
|
|
71
|
-
end
|
|
72
|
-
|
|
73
|
-
html = context.render(partial: "inline_forms/versions_list")
|
|
74
|
-
|
|
75
|
-
refute_includes html, "<script"
|
|
76
|
-
refute_includes html, "onerror"
|
|
77
|
-
assert_includes html, "<p>old</p>"
|
|
78
|
-
assert_includes html, "<p>new</p>"
|
|
79
|
-
end
|
|
80
|
-
end
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require_relative "../integration_test_helper"
|
|
4
|
-
|
|
5
|
-
# Reverting a version must leave columns excluded via `has_paper_trail skip:`
|
|
6
|
-
# alone. PaperTrail's reify defaults to `unversioned_attributes: :nil`, which
|
|
7
|
-
# set every skipped column to nil on the live record; revert's save! then
|
|
8
|
-
# persisted that, so in StProject reverting any Client edit NULLed the file
|
|
9
|
-
# bytes (`*_data`) while keeping `*_filename` (downloads returned empty files).
|
|
10
|
-
class RevertSkippedColumnsTest < InlineFormsIntegrationTestCase
|
|
11
|
-
BYTES = "%PDF-1.4 fake bytes \x00\x01\x02".b
|
|
12
|
-
|
|
13
|
-
setup do
|
|
14
|
-
@dossier = Dossier.create!(name: "Original", data_filename: "plan.pdf", data: BYTES)
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
def turbo_stream_headers(frame_id)
|
|
18
|
-
frame_headers(frame_id).merge("Accept" => "text/vnd.turbo-stream.html")
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
def versions_for(event)
|
|
22
|
-
PaperTrail::Version.where(item_type: "Dossier", item_id: @dossier.id, event: event)
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
test "the skipped column is really not versioned" do
|
|
26
|
-
refute_includes versions_for("create").last.object_changes.to_s, "fake bytes"
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
test "reverting an unrelated update keeps the skipped column's bytes" do
|
|
30
|
-
@dossier.update!(name: "Renamed")
|
|
31
|
-
update_version = versions_for("update").last
|
|
32
|
-
frame = "dossier_#{@dossier.id}"
|
|
33
|
-
|
|
34
|
-
post revert_dossier_path(update_version.id, update: frame),
|
|
35
|
-
headers: turbo_stream_headers(frame)
|
|
36
|
-
|
|
37
|
-
assert_response :success
|
|
38
|
-
@dossier.reload
|
|
39
|
-
assert_equal "Original", @dossier.name, "revert must restore the versioned attribute"
|
|
40
|
-
assert_equal "plan.pdf", @dossier.data_filename
|
|
41
|
-
assert_equal BYTES, @dossier.data, "revert must not NULL a has_paper_trail skip: column"
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
test "replaying a destroy revert on an existing row keeps the skipped column's bytes" do
|
|
45
|
-
frame = "dossier_#{@dossier.id}"
|
|
46
|
-
delete dossier_path(@dossier, update: frame), headers: frame_headers(frame)
|
|
47
|
-
destroy_version = versions_for("destroy").last
|
|
48
|
-
# The destroy snapshot cannot hold the bytes (skipped); put the row back
|
|
49
|
-
# with its file, as the user would after the first undo + re-upload.
|
|
50
|
-
Dossier.create!(id: @dossier.id, name: "Original", data_filename: "plan.pdf", data: BYTES)
|
|
51
|
-
|
|
52
|
-
post revert_dossier_path(destroy_version.id, update: "dossiers_list"),
|
|
53
|
-
headers: turbo_stream_headers("dossiers_list")
|
|
54
|
-
|
|
55
|
-
assert_response :success
|
|
56
|
-
assert_equal BYTES, Dossier.find(@dossier.id).data,
|
|
57
|
-
"idempotent destroy revert must not copy a nil skipped column onto the live row"
|
|
58
|
-
end
|
|
59
|
-
end
|
|
@@ -1,189 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require_relative "../integration_test_helper"
|
|
4
|
-
|
|
5
|
-
# The batch pipeline (phases 1-3): drafting intents into a batch, freeze on
|
|
6
|
-
# submit, token-authenticated export + status callback, and import/replay
|
|
7
|
-
# via a recording executor (never mutates the dummy tree).
|
|
8
|
-
class SchemaBatchPipelineTest < InlineFormsIntegrationTestCase
|
|
9
|
-
def teardown
|
|
10
|
-
InlineFormsSchemaEdit.export_token = nil
|
|
11
|
-
super
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
def draft_widget_field!(attribute: "warehouse_note", label: "Warehouse note")
|
|
15
|
-
post inline_forms_schema_draft_path,
|
|
16
|
-
params: { model_name: "Widget", attribute: attribute,
|
|
17
|
-
form_element: "text_field", after: "name", label: label, locale: "en" }
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
# -- phase 1: drafting + freeze ------------------------------------------
|
|
21
|
-
|
|
22
|
-
test "drafting an intent creates a draft batch (the cart) and index shows it" do
|
|
23
|
-
draft_widget_field!
|
|
24
|
-
assert_response :redirect
|
|
25
|
-
|
|
26
|
-
batch = InlineForms::SchemaBatch.with_status(:draft).first
|
|
27
|
-
assert batch, "draft batch created"
|
|
28
|
-
assert_equal 1, batch.intents.count
|
|
29
|
-
intent = batch.intents.first
|
|
30
|
-
assert_equal %w[Widget warehouse_note text_field name], [
|
|
31
|
-
intent.target_model, intent.attr_name, intent.form_element, intent.after_attr
|
|
32
|
-
]
|
|
33
|
-
|
|
34
|
-
get inline_forms_schema_index_path
|
|
35
|
-
assert_response :success
|
|
36
|
-
assert_includes response.body, "warehouse_note"
|
|
37
|
-
assert_includes response.body, "Submit batch"
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
test "invalid intents are rejected at drafting time" do
|
|
41
|
-
post inline_forms_schema_draft_path,
|
|
42
|
-
params: { model_name: "Widget", attribute: "name", form_element: "text_field" }
|
|
43
|
-
assert_response :success # renders :new with the error
|
|
44
|
-
assert_includes response.body, "already has a name column"
|
|
45
|
-
assert_equal 0, InlineForms::SchemaIntentRecord.count
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
test "submit freezes the batch: no more adds, edits or removals; digest sealed" do
|
|
49
|
-
draft_widget_field!
|
|
50
|
-
post inline_forms_schema_submit_batch_path
|
|
51
|
-
assert_response :redirect
|
|
52
|
-
|
|
53
|
-
batch = InlineForms::SchemaBatch.last
|
|
54
|
-
assert_equal "submitted", batch.status
|
|
55
|
-
assert batch.submitted_at
|
|
56
|
-
assert_match(/\Asha256:/, batch.content_digest)
|
|
57
|
-
|
|
58
|
-
intent = batch.intents.first
|
|
59
|
-
intent.label = "changed"
|
|
60
|
-
refute intent.save, "frozen intent must not save"
|
|
61
|
-
refute intent.destroy, "frozen intent must not be destroyed"
|
|
62
|
-
|
|
63
|
-
refute batch.intents.create(target_model: "Widget", attr_name: "late_one",
|
|
64
|
-
form_element: "text_field").persisted?,
|
|
65
|
-
"no new intents into a frozen batch"
|
|
66
|
-
|
|
67
|
-
batch.window_at = 2.days.from_now
|
|
68
|
-
refute batch.save, "frozen batch attributes must not change"
|
|
69
|
-
|
|
70
|
-
# A new draft goes into a NEW batch.
|
|
71
|
-
draft_widget_field!(attribute: "second_note")
|
|
72
|
-
assert_equal 2, InlineForms::SchemaBatch.count
|
|
73
|
-
end
|
|
74
|
-
|
|
75
|
-
test "submitting an empty batch is refused" do
|
|
76
|
-
post inline_forms_schema_submit_batch_path
|
|
77
|
-
assert_redirected_to inline_forms_schema_index_path
|
|
78
|
-
assert_equal 0, InlineForms::SchemaBatch.where(status: "submitted").count
|
|
79
|
-
end
|
|
80
|
-
|
|
81
|
-
test "status transitions follow the pipeline; illegal jumps raise" do
|
|
82
|
-
draft_widget_field!
|
|
83
|
-
batch = InlineForms::SchemaBatch.last.submit!
|
|
84
|
-
|
|
85
|
-
batch.transition!(:processing)
|
|
86
|
-
batch.transition!(:ready, git_sha: "abc123")
|
|
87
|
-
assert_equal "abc123", batch.git_sha
|
|
88
|
-
assert_raises(ArgumentError) { batch.transition!(:submitted) }
|
|
89
|
-
batch.transition!(:applied)
|
|
90
|
-
assert batch.applied_at
|
|
91
|
-
end
|
|
92
|
-
|
|
93
|
-
# -- phase 3: machine endpoints ------------------------------------------
|
|
94
|
-
|
|
95
|
-
test "export 404s without a configured token and 401s with a wrong one" do
|
|
96
|
-
draft_widget_field!
|
|
97
|
-
batch = InlineForms::SchemaBatch.last.submit!
|
|
98
|
-
|
|
99
|
-
get inline_forms_schema_export_path(batch)
|
|
100
|
-
assert_response :not_found
|
|
101
|
-
|
|
102
|
-
InlineFormsSchemaEdit.export_token = "sekret"
|
|
103
|
-
get inline_forms_schema_export_path(batch), headers: { "Authorization" => "Bearer wrong" }
|
|
104
|
-
assert_response :unauthorized
|
|
105
|
-
end
|
|
106
|
-
|
|
107
|
-
test "export returns the sealed payload; draft batches are refused" do
|
|
108
|
-
InlineFormsSchemaEdit.export_token = "sekret"
|
|
109
|
-
draft_widget_field!
|
|
110
|
-
batch = InlineForms::SchemaBatch.last
|
|
111
|
-
|
|
112
|
-
get inline_forms_schema_export_path(batch), headers: { "Authorization" => "Bearer sekret" }
|
|
113
|
-
assert_response :conflict
|
|
114
|
-
|
|
115
|
-
batch.submit!
|
|
116
|
-
get inline_forms_schema_export_path(batch), headers: { "Authorization" => "Bearer sekret" }
|
|
117
|
-
assert_response :success
|
|
118
|
-
payload = JSON.parse(response.body)
|
|
119
|
-
assert_equal 1, payload["format"]
|
|
120
|
-
assert_equal batch.content_digest, payload["digest"]
|
|
121
|
-
assert_equal "warehouse_note", payload["intents"].first["attribute"]
|
|
122
|
-
end
|
|
123
|
-
|
|
124
|
-
test "status callback drives the batch through the pipeline" do
|
|
125
|
-
InlineFormsSchemaEdit.export_token = "sekret"
|
|
126
|
-
draft_widget_field!
|
|
127
|
-
batch = InlineForms::SchemaBatch.last.submit!
|
|
128
|
-
|
|
129
|
-
post inline_forms_schema_batch_status_path(batch),
|
|
130
|
-
params: { status: "processing" }, headers: { "Authorization" => "Bearer sekret" }
|
|
131
|
-
assert_response :success
|
|
132
|
-
assert_equal "processing", batch.reload.status
|
|
133
|
-
|
|
134
|
-
post inline_forms_schema_batch_status_path(batch),
|
|
135
|
-
params: { status: "applied" }, headers: { "Authorization" => "Bearer sekret" }
|
|
136
|
-
assert_response :unprocessable_entity, "processing -> applied skips ready"
|
|
137
|
-
|
|
138
|
-
post inline_forms_schema_batch_status_path(batch),
|
|
139
|
-
params: { status: "failed", error: "test gate red" },
|
|
140
|
-
headers: { "Authorization" => "Bearer sekret" }
|
|
141
|
-
assert_equal "failed", batch.reload.status
|
|
142
|
-
assert_equal "test gate red", batch.error
|
|
143
|
-
end
|
|
144
|
-
|
|
145
|
-
# -- phase 2: export/import round trip -----------------------------------
|
|
146
|
-
|
|
147
|
-
test "import verifies the digest and replays intents through the executor" do
|
|
148
|
-
draft_widget_field!
|
|
149
|
-
batch = InlineForms::SchemaBatch.last.submit!
|
|
150
|
-
|
|
151
|
-
payload = InlineFormsSchemaEdit::BatchExport.payload(batch)
|
|
152
|
-
|
|
153
|
-
recorded = []
|
|
154
|
-
labels = []
|
|
155
|
-
import = InlineFormsSchemaEdit::BatchImport.new(
|
|
156
|
-
payload,
|
|
157
|
-
executor: ->(args, _root) { recorded << args },
|
|
158
|
-
label_writer: ->(**kwargs) { labels << kwargs; "/dev/null/labels.yml" }
|
|
159
|
-
)
|
|
160
|
-
result = import.apply!(destination_root: Dir.tmpdir)
|
|
161
|
-
|
|
162
|
-
assert_equal 1, result.applied
|
|
163
|
-
assert_equal [ "Widget", "warehouse_note:text_field", "--after=name" ], recorded.first
|
|
164
|
-
assert_equal "Warehouse note", labels.first[:label]
|
|
165
|
-
assert_includes result.plan.join("\n"), "inline_forms_addto Widget warehouse_note:text_field"
|
|
166
|
-
end
|
|
167
|
-
|
|
168
|
-
test "import rejects a tampered payload (digest mismatch) and stale intents" do
|
|
169
|
-
draft_widget_field!
|
|
170
|
-
batch = InlineForms::SchemaBatch.last.submit!
|
|
171
|
-
payload = InlineFormsSchemaEdit::BatchExport.payload(batch)
|
|
172
|
-
|
|
173
|
-
tampered = payload.deep_dup
|
|
174
|
-
tampered["intents"].first["attribute"] = "evil_column"
|
|
175
|
-
error = assert_raises(InlineFormsSchemaEdit::BatchImport::ImportError) do
|
|
176
|
-
InlineFormsSchemaEdit::BatchImport.new(tampered).verify!
|
|
177
|
-
end
|
|
178
|
-
assert_match(/digest mismatch/, error.message)
|
|
179
|
-
|
|
180
|
-
# A column that already exists in THIS checkout fails per-intent validation.
|
|
181
|
-
stale = InlineFormsSchemaEdit::BatchExport.payload(batch)
|
|
182
|
-
stale["intents"].first["attribute"] = "name"
|
|
183
|
-
stale["digest"] = "sha256:#{Digest::SHA256.hexdigest(JSON.generate(stale['intents']))}"
|
|
184
|
-
error = assert_raises(InlineFormsSchemaEdit::BatchImport::ImportError) do
|
|
185
|
-
InlineFormsSchemaEdit::BatchImport.new(stale).verify!
|
|
186
|
-
end
|
|
187
|
-
assert_match(/already has a name column/, error.message)
|
|
188
|
-
end
|
|
189
|
-
end
|
|
@@ -1,141 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require_relative "../integration_test_helper"
|
|
4
|
-
|
|
5
|
-
# The dev-only schema-change GUI (InlineForms::SchemaController): new -> preview
|
|
6
|
-
# (no migration) -> apply (runs the addto generator, no db:migrate). Apply is
|
|
7
|
-
# exercised with a RECORDING executor so the suite never mutates the dummy tree.
|
|
8
|
-
class SchemaEditTest < InlineFormsIntegrationTestCase
|
|
9
|
-
def teardown
|
|
10
|
-
InlineForms::SchemaController.generator_executor = nil
|
|
11
|
-
InlineForms::SchemaController.label_writer = nil
|
|
12
|
-
super
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
test "new renders the form with supported elements" do
|
|
16
|
-
get inline_forms_schema_new_path
|
|
17
|
-
assert_response :success
|
|
18
|
-
assert_includes response.body, "Model"
|
|
19
|
-
assert_includes response.body, "Form element"
|
|
20
|
-
assert_includes response.body, "text_field"
|
|
21
|
-
assert_includes response.body, "Preview"
|
|
22
|
-
# data-turbo opt-out so the standalone utility navigates on POST
|
|
23
|
-
assert_includes response.body, %(data-turbo="false")
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
test "info is not offered and is rejected; header is not a scalar field" do
|
|
27
|
-
refute_includes InlineForms::SchemaPreview.supported_form_elements, :header
|
|
28
|
-
refute_includes InlineForms::SchemaPreview.supported_form_elements, :info
|
|
29
|
-
|
|
30
|
-
post inline_forms_schema_preview_path,
|
|
31
|
-
params: { model_name: "Widget", attribute: "meta", form_element: "info" }
|
|
32
|
-
assert_response :success
|
|
33
|
-
assert_includes response.body, "Unsupported form element"
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
test "header preview adds a no-column row (no migration, no widget)" do
|
|
37
|
-
post inline_forms_schema_preview_path,
|
|
38
|
-
params: { model_name: "Widget", attribute: "section_title",
|
|
39
|
-
form_element: "header", after: "name", label: "Section" }
|
|
40
|
-
assert_response :success
|
|
41
|
-
assert_includes response.body, "no column, no migration"
|
|
42
|
-
assert_includes response.body, "section_title (new)"
|
|
43
|
-
# header shows its label, not an input widget
|
|
44
|
-
assert_includes response.body, "Section"
|
|
45
|
-
refute_includes response.body, %(name="section_title")
|
|
46
|
-
refute_includes Widget.column_names, "section_title"
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
test "header apply invokes the generator without a column (no migration)" do
|
|
50
|
-
recorded = []
|
|
51
|
-
InlineForms::SchemaController.generator_executor = ->(args, _root) { recorded << args }
|
|
52
|
-
|
|
53
|
-
post inline_forms_schema_path,
|
|
54
|
-
params: { model_name: "Widget", attribute: "section_title", form_element: "header" }
|
|
55
|
-
assert_response :success
|
|
56
|
-
assert_includes response.body, "header"
|
|
57
|
-
assert_includes response.body, "no migration"
|
|
58
|
-
assert_equal [ "Widget", "section_title:header" ], recorded.first
|
|
59
|
-
end
|
|
60
|
-
|
|
61
|
-
test "a label is written through the injected label writer" do
|
|
62
|
-
recorded = []
|
|
63
|
-
InlineForms::SchemaController.generator_executor = ->(_args, _root) { }
|
|
64
|
-
InlineForms::SchemaController.label_writer = ->(**kw) { recorded << kw; "/tmp/inline_forms_labels.en.yml" }
|
|
65
|
-
|
|
66
|
-
post inline_forms_schema_path,
|
|
67
|
-
params: { model_name: "Widget", attribute: "section_title", form_element: "header",
|
|
68
|
-
label: "Section", locale: "en" }
|
|
69
|
-
assert_response :success
|
|
70
|
-
assert_includes response.body, "Wrote label"
|
|
71
|
-
assert_equal 1, recorded.size
|
|
72
|
-
assert_equal :section_title, recorded.first[:attribute]
|
|
73
|
-
assert_equal "Section", recorded.first[:label]
|
|
74
|
-
assert_equal "en", recorded.first[:locale]
|
|
75
|
-
end
|
|
76
|
-
|
|
77
|
-
test "preview shows the field at the right position with no migration" do
|
|
78
|
-
post inline_forms_schema_preview_path,
|
|
79
|
-
params: { model_name: "Widget", attribute: "internal_note",
|
|
80
|
-
form_element: "text_field", after: "name" }
|
|
81
|
-
assert_response :success
|
|
82
|
-
assert_includes response.body, "internal_note (new)"
|
|
83
|
-
# rendered live widget for the new field
|
|
84
|
-
assert_includes response.body, %(name="internal_note")
|
|
85
|
-
# placement: internal_note appears after name in the rendered order
|
|
86
|
-
assert response.body.index("name (new)").nil?
|
|
87
|
-
assert response.body.index(">name<") < response.body.index("internal_note (new)")
|
|
88
|
-
|
|
89
|
-
# No schema change happened.
|
|
90
|
-
refute_includes Widget.column_names, "internal_note"
|
|
91
|
-
assert_empty Dir.glob(Rails.root.join("db/migrate/*_inline_forms_add_to_*.rb"))
|
|
92
|
-
end
|
|
93
|
-
|
|
94
|
-
test "an unsupported (non-scalar) element is rejected with an error" do
|
|
95
|
-
post inline_forms_schema_preview_path,
|
|
96
|
-
params: { model_name: "Widget", attribute: "vendor", form_element: "dropdown" }
|
|
97
|
-
assert_response :success
|
|
98
|
-
assert_includes response.body, "Unsupported form element"
|
|
99
|
-
end
|
|
100
|
-
|
|
101
|
-
test "a value-bearing element previews with a placeholder values hash (no raise)" do
|
|
102
|
-
post inline_forms_schema_preview_path,
|
|
103
|
-
params: { model_name: "Widget", attribute: "rank",
|
|
104
|
-
form_element: "dropdown_with_values_with_stars", after: "name" }
|
|
105
|
-
assert_response :success
|
|
106
|
-
assert_includes response.body, "rank (new)"
|
|
107
|
-
assert_includes response.body, "placeholder values hash"
|
|
108
|
-
end
|
|
109
|
-
|
|
110
|
-
test "invalid input re-renders the form with an error" do
|
|
111
|
-
post inline_forms_schema_preview_path,
|
|
112
|
-
params: { model_name: "Widget", attribute: "Bad Name", form_element: "text_field" }
|
|
113
|
-
assert_response :success
|
|
114
|
-
assert_includes response.body, "lowercase letters"
|
|
115
|
-
end
|
|
116
|
-
|
|
117
|
-
test "apply invokes the generator (no db:migrate) via the injected executor" do
|
|
118
|
-
recorded = []
|
|
119
|
-
InlineForms::SchemaController.generator_executor = ->(args, _root) { recorded << args }
|
|
120
|
-
|
|
121
|
-
post inline_forms_schema_path,
|
|
122
|
-
params: { model_name: "Widget", attribute: "internal_note",
|
|
123
|
-
form_element: "text_field", after: "name" }
|
|
124
|
-
assert_response :success
|
|
125
|
-
assert_includes response.body, "Applied"
|
|
126
|
-
assert_includes response.body, "db:migrate" # the "you run this" instruction
|
|
127
|
-
assert_equal 1, recorded.size
|
|
128
|
-
assert_equal [ "Widget", "internal_note:text_field", "--after=name" ], recorded.first
|
|
129
|
-
# The generator never wrote a migration (recorder), and we never migrated.
|
|
130
|
-
refute_includes Widget.column_names, "internal_note"
|
|
131
|
-
end
|
|
132
|
-
|
|
133
|
-
test "reachable only outside production" do
|
|
134
|
-
original = Rails.env
|
|
135
|
-
Rails.env = ActiveSupport::StringInquirer.new("production")
|
|
136
|
-
get inline_forms_schema_new_path
|
|
137
|
-
assert_response :not_found
|
|
138
|
-
ensure
|
|
139
|
-
Rails.env = original
|
|
140
|
-
end
|
|
141
|
-
end
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require_relative "../integration_test_helper"
|
|
4
|
-
|
|
5
|
-
# Cheap preview of a SchemaIntent against the dummy app: a virtual typed
|
|
6
|
-
# attribute on a throwaway subclass + an AttributeList with the proposed row
|
|
7
|
-
# spliced in — no migration, no column, real class/table untouched.
|
|
8
|
-
class SchemaPreviewTest < InlineFormsIntegrationTestCase
|
|
9
|
-
def scalar_intent(**overrides)
|
|
10
|
-
InlineForms::SchemaIntent.new(
|
|
11
|
-
**{ model_name: "Widget", attribute: :internal_note, form_element: :text_field }.merge(overrides)
|
|
12
|
-
)
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
test "supported? is true for scalar elements, false for relations/uploaders/virtuals" do
|
|
16
|
-
assert InlineForms::SchemaPreview.supported?(scalar_intent(form_element: :text_field))
|
|
17
|
-
assert InlineForms::SchemaPreview.supported?(scalar_intent(form_element: :integer_field))
|
|
18
|
-
assert InlineForms::SchemaPreview.supported?(scalar_intent(form_element: :date_select))
|
|
19
|
-
assert InlineForms::SchemaPreview.supported?(scalar_intent(form_element: :check_box))
|
|
20
|
-
refute InlineForms::SchemaPreview.supported?(scalar_intent(form_element: :dropdown))
|
|
21
|
-
refute InlineForms::SchemaPreview.supported?(scalar_intent(form_element: :rich_text))
|
|
22
|
-
refute InlineForms::SchemaPreview.supported?(scalar_intent(form_element: :image_field))
|
|
23
|
-
refute InlineForms::SchemaPreview.supported?(scalar_intent(form_element: :money_field))
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
test "preview object carries the proposed attribute as a virtual, no column" do
|
|
27
|
-
object, = InlineForms::SchemaPreview.build(scalar_intent)
|
|
28
|
-
|
|
29
|
-
assert object.respond_to?(:internal_note), "preview should expose the virtual attribute"
|
|
30
|
-
assert_nil object.internal_note, "virtual attribute defaults to nil with no column"
|
|
31
|
-
object.internal_note = "boiler serviced"
|
|
32
|
-
assert_equal "boiler serviced", object.internal_note, "virtual attribute is writable in memory"
|
|
33
|
-
|
|
34
|
-
# The real class/table are untouched.
|
|
35
|
-
refute_includes Widget.column_names, "internal_note"
|
|
36
|
-
assert_equal "Widget", object.class.name, "preview masquerades as the base class"
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
test "preview attribute_list splices the row at --after" do
|
|
40
|
-
_, list = InlineForms::SchemaPreview.build(scalar_intent(after: :name))
|
|
41
|
-
assert_kind_of InlineForms::AttributeList, list
|
|
42
|
-
assert_equal :internal_note, list.names[list.index_of(:name) + 1]
|
|
43
|
-
# original rows are preserved
|
|
44
|
-
assert list.include_attribute?(:priority)
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
test "preview attribute_list appends when no anchor given" do
|
|
48
|
-
_, list = InlineForms::SchemaPreview.build(scalar_intent)
|
|
49
|
-
assert_equal :internal_note, list.names.last
|
|
50
|
-
end
|
|
51
|
-
|
|
52
|
-
test "preview seeds existing attributes from a base record" do
|
|
53
|
-
widget = Widget.create!(name: "Base", priority: 2)
|
|
54
|
-
object, = InlineForms::SchemaPreview.build(scalar_intent, widget)
|
|
55
|
-
assert_equal "Base", object.name, "existing data is carried into the preview"
|
|
56
|
-
assert_nil object.internal_note
|
|
57
|
-
end
|
|
58
|
-
|
|
59
|
-
test "building a preview does not add a column to the real table" do
|
|
60
|
-
before = Widget.column_names.dup
|
|
61
|
-
InlineForms::SchemaPreview.build(scalar_intent(after: :name))
|
|
62
|
-
Widget.reset_column_information
|
|
63
|
-
assert_equal before, Widget.column_names
|
|
64
|
-
end
|
|
65
|
-
end
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require_relative "../integration_test_helper"
|
|
4
|
-
|
|
5
|
-
# Top-bar submenus after a Turbo Drive visit. The bundle sat in <body>, so
|
|
6
|
-
# Turbo re-ran it on every visit (a fresh jQuery, its own Foundation plugin
|
|
7
|
-
# data), and until that finished the new body's submenus showed as plain
|
|
8
|
-
# lists; StProject, Scouting and Papiamentu each carried the same layout copy
|
|
9
|
-
# to hide them (html.no-js, a turbo:load re-init, a CSS rule). Now the gem
|
|
10
|
-
# loads the bundle in <head>, which Turbo runs once.
|
|
11
|
-
class TurboMenuTest < InlineFormsIntegrationTestCase
|
|
12
|
-
ROOT = File.expand_path("../..", __dir__)
|
|
13
|
-
|
|
14
|
-
def boot_block
|
|
15
|
-
js = File.read(File.join(ROOT, "app/assets/javascripts/inline_forms/inline_forms.js"))
|
|
16
|
-
js[/^if \(!window\.inlineFormsBooted\) \{.*?\n\}\n/m]
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
test "the layout starts as no-js and loads the bundle in head" do
|
|
20
|
-
get widgets_path
|
|
21
|
-
|
|
22
|
-
assert_response :success
|
|
23
|
-
assert_match %r{<html lang="en" class="no-js">}, response.body
|
|
24
|
-
head = response.body[%r{<head>.*</head>}m]
|
|
25
|
-
scripts = %w[popper.min tippy-bundle.umd.min inline_forms/inline_forms].map { |name|
|
|
26
|
-
head.index(%r{<script src="[^"]*/#{Regexp.escape(name)}[^"]*\.js"></script>})
|
|
27
|
-
}
|
|
28
|
-
assert scripts.all?, "popper, tippy and inline_forms.js are in <head>"
|
|
29
|
-
assert_equal scripts.sort, scripts, "in that order"
|
|
30
|
-
refute_match %r{<body.*inline_forms/inline_forms[^"]*\.js}m, response.body
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
test "inline_forms.js wires every document listener once, and boots once per body" do
|
|
34
|
-
boot = boot_block
|
|
35
|
-
|
|
36
|
-
assert boot, "the listeners sit behind the once-guard"
|
|
37
|
-
rest = File.read(File.join(ROOT, "app/assets/javascripts/inline_forms/inline_forms.js")).sub(boot, "")
|
|
38
|
-
refute_match(/addEventListener|\$\(document\)|\.ready\(/, rest.gsub(%r{^\s*//.*$}, "").gsub(/el\.addEventListener\("input"/, ""),
|
|
39
|
-
"no document listener outside the guard: a host layout with the bundle in <body> re-runs it on every visit")
|
|
40
|
-
%w[turbo:load turbo:frame-load mouseover].each do |event|
|
|
41
|
-
assert_includes boot, "document.addEventListener(\"#{event}\""
|
|
42
|
-
end
|
|
43
|
-
assert_includes boot, "document.body === inlineFormsBootedBody"
|
|
44
|
-
assert_includes boot, "window.jQuery(document).foundation();"
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
test "uninitialised dropdown submenus stay hidden, drilldown menus are left alone" do
|
|
48
|
-
scss = File.read(File.join(ROOT, "app/assets/stylesheets/inline_forms/inline_forms.scss"))
|
|
49
|
-
|
|
50
|
-
assert_match(/^\.dropdown\.menu\[data-dropdown-menu\] > li > ul\.menu:not\(\.is-dropdown-submenu\) \{\n display: none;\n\}/, scss)
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
# Compiled CSS is checked in the example app (example_app_stylesheet_test).
|
|
54
|
-
test "tippy.css is inlined, not left as a plain CSS @import the browser 404s on" do
|
|
55
|
-
scss = File.read(File.join(ROOT, "app/assets/stylesheets/inline_forms/foundation_and_overrides.scss"))
|
|
56
|
-
|
|
57
|
-
refute_match(/^\s*@import\s+['"][^'"]*tippy\.css['"]/, scss)
|
|
58
|
-
assert_includes scss, "@include meta.load-css('../../../vendor/assets/stylesheets/tippy');"
|
|
59
|
-
end
|
|
60
|
-
end
|