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.
Files changed (89) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +25 -1
  3. data/README.rdoc +1 -1
  4. data/inline_forms.gemspec +0 -1
  5. data/lib/generators/USAGE +1 -1
  6. data/lib/generators/inline_forms_addto/USAGE +1 -1
  7. data/lib/generators/inline_forms_addto_generator.rb +30 -139
  8. data/lib/generators/inline_forms_attribute_list_editor.rb +211 -0
  9. data/lib/generators/inline_forms_attribute_overrides.rb +9 -0
  10. data/lib/generators/inline_forms_generator.rb +16 -35
  11. data/lib/inline_forms/gem_files.rb +20 -17
  12. data/lib/inline_forms/version.rb +1 -1
  13. metadata +3 -142
  14. data/.document +0 -5
  15. data/.forgejo/brakeman-engine.sh +0 -51
  16. data/.forgejo/brakeman.ignore +0 -211
  17. data/.forgejo/workflows/ci.yml +0 -74
  18. data/.forgejo/workflows/full-gate.yml +0 -104
  19. data/.gitignore +0 -39
  20. data/.rubocop.yml +0 -31
  21. data/.rubocop_todo.yml +0 -151
  22. data/.ruby-version +0 -1
  23. data/Gemfile +0 -28
  24. data/Rakefile +0 -103
  25. data/script/migrate_form_elements.rb +0 -62
  26. data/test/archived_form_elements_test.rb +0 -101
  27. data/test/attribute_list_test.rb +0 -165
  28. data/test/dummy/app/controllers/application_controller.rb +0 -32
  29. data/test/dummy/app/controllers/daily_reports_controller.rb +0 -4
  30. data/test/dummy/app/controllers/documents_controller.rb +0 -4
  31. data/test/dummy/app/controllers/dossiers_controller.rb +0 -4
  32. data/test/dummy/app/controllers/gizmos_controller.rb +0 -4
  33. data/test/dummy/app/controllers/machines_controller.rb +0 -4
  34. data/test/dummy/app/controllers/parts_controller.rb +0 -4
  35. data/test/dummy/app/controllers/stats_controller.rb +0 -10
  36. data/test/dummy/app/controllers/widgets_controller.rb +0 -4
  37. data/test/dummy/app/helpers/application_helper.rb +0 -13
  38. data/test/dummy/app/models/ability.rb +0 -15
  39. data/test/dummy/app/models/application_record.rb +0 -27
  40. data/test/dummy/app/models/daily_report.rb +0 -21
  41. data/test/dummy/app/models/document.rb +0 -33
  42. data/test/dummy/app/models/dossier.rb +0 -38
  43. data/test/dummy/app/models/gizmo.rb +0 -25
  44. data/test/dummy/app/models/kind.rb +0 -8
  45. data/test/dummy/app/models/machine.rb +0 -24
  46. data/test/dummy/app/models/part.rb +0 -17
  47. data/test/dummy/app/models/phase.rb +0 -9
  48. data/test/dummy/app/models/widget.rb +0 -40
  49. data/test/dummy/app/views/_gizmos_search.html.erb +0 -3
  50. data/test/dummy/app/views/stats/show.html.erb +0 -1
  51. data/test/dummy/config/application.rb +0 -49
  52. data/test/dummy/config/database.yml +0 -3
  53. data/test/dummy/config/environment.rb +0 -5
  54. data/test/dummy/config/initializers/inline_forms.rb +0 -6
  55. data/test/dummy/config/initializers/paper_trail_yaml_safe_load.rb +0 -28
  56. data/test/dummy/config/routes.rb +0 -51
  57. data/test/form_element_from_callee_test.rb +0 -73
  58. data/test/gem_package_modes_test.rb +0 -86
  59. data/test/inline_edit_polymorphic_path_test.rb +0 -81
  60. data/test/inline_forms_addto_generator_test.rb +0 -584
  61. data/test/inline_forms_generator_test.rb +0 -301
  62. data/test/integration/csp_nonce_test.rb +0 -50
  63. data/test/integration/dropdown_test.rb +0 -186
  64. data/test/integration/field_authorization_test.rb +0 -131
  65. data/test/integration/file_slots_test.rb +0 -665
  66. data/test/integration/html_refusal_test.rb +0 -152
  67. data/test/integration/inline_forms_crud_test.rb +0 -165
  68. data/test/integration/layout_title_test.rb +0 -56
  69. data/test/integration/legacy_elements_test.rb +0 -99
  70. data/test/integration/list_params_test.rb +0 -200
  71. data/test/integration/locale_test.rb +0 -234
  72. data/test/integration/model_top_bar_test.rb +0 -85
  73. data/test/integration/native_inputs_test.rb +0 -138
  74. data/test/integration/open_after_create_test.rb +0 -85
  75. data/test/integration/pending_migration_gate_test.rb +0 -75
  76. data/test/integration/presentation_escaping_test.rb +0 -80
  77. data/test/integration/revert_skipped_columns_test.rb +0 -59
  78. data/test/integration/schema_batch_pipeline_test.rb +0 -189
  79. data/test/integration/schema_edit_test.rb +0 -141
  80. data/test/integration/schema_preview_test.rb +0 -65
  81. data/test/integration/turbo_menu_test.rb +0 -60
  82. data/test/integration_test_helper.rb +0 -203
  83. data/test/plain_text_configuration_test.rb +0 -90
  84. data/test/schema_apply_test.rb +0 -73
  85. data/test/schema_intent_test.rb +0 -53
  86. data/test/schema_label_test.rb +0 -61
  87. data/test/tabs_test.rb +0 -98
  88. data/test/test_helper.rb +0 -10
  89. data/test/user_model_config_test.rb +0 -44
@@ -1,152 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "../integration_test_helper"
4
-
5
- # Every HTML request the engine decides not to serve gets an explicit answer:
6
- # a top-level list of a not_accessible_through_html? model is a 404, a
7
- # new/create/show/destroy/revert without the frame context the gem needs is a
8
- # 400. Before, the format.html block rendered nothing (or was not registered),
9
- # so Rails fell through to implicit rendering: ActionController::
10
- # MissingExactTemplate (500; StProject's GET /dagrapportages) or UnknownFormat
11
- # (406). create, destroy and revert also refuse before writing anything.
12
- #
13
- # DailyReport is the not_accessible_through_html? child of Machine; Machine is
14
- # a normal (accessible) model.
15
- class HtmlRefusalTest < InlineFormsIntegrationTestCase
16
- setup do
17
- @machine = Machine.create!(name: "Press")
18
- @report = DailyReport.create!(name: "Monday", machine: @machine)
19
- @list_frame = "machine_#{@machine.id}_daily_reports"
20
- @row_frame = "machine_#{@machine.id}_daily_report_#{@report.id}"
21
- end
22
-
23
- def nested_params(update = @list_frame)
24
- { update: update, parent_class: "Machine", parent_id: @machine.id }
25
- end
26
-
27
- def stream_headers(frame_id)
28
- frame_headers(frame_id).merge("Accept" => "text/vnd.turbo-stream.html")
29
- end
30
-
31
- # The refusal ran after authorization, so CanCan's check_authorization (an
32
- # after_action in host apps) is satisfied.
33
- def assert_refused(status)
34
- assert_response status
35
- assert controller.instance_variable_defined?(:@_authorized),
36
- "the refused request must still count as authorized (check_authorization)"
37
- end
38
-
39
- # ---- not_accessible_through_html? model, top level -----------------------
40
-
41
- test "the top-level list of a not_accessible_through_html? model is a 404" do
42
- get daily_reports_path
43
- assert_refused :not_found
44
- end
45
-
46
- test "show without a nested row frame is a 400" do
47
- get daily_report_path(@report)
48
- assert_refused :bad_request
49
- end
50
-
51
- test "new without update and parent_class is a 400" do
52
- get new_daily_report_path
53
- assert_refused :bad_request
54
- end
55
-
56
- test "create without update and parent_class is a 400 and creates nothing" do
57
- assert_no_difference -> { DailyReport.count } do
58
- post daily_reports_path, params: { name: "Tuesday" }
59
- end
60
- assert_refused :bad_request
61
- end
62
-
63
- test "destroy without a nested row frame is a 400 and keeps the record" do
64
- delete daily_report_path(@report)
65
- assert_refused :bad_request
66
- assert DailyReport.exists?(@report.id)
67
- end
68
-
69
- test "revert without a nested row frame is a 400 and changes nothing" do
70
- @report.update!(name: "Changed")
71
- version = @report.versions.where(event: "update").last
72
-
73
- post revert_daily_report_path(version.id, update: "daily_report_#{@report.id}"),
74
- headers: stream_headers("daily_report_#{@report.id}")
75
- assert_refused :bad_request
76
- assert_equal "Changed", @report.reload.name
77
- end
78
-
79
- # ---- the nested forms still work (regression guard) ----------------------
80
-
81
- test "the nested list, new form, create, row and destroy still render" do
82
- get daily_reports_path(nested_params), headers: frame_headers(@list_frame)
83
- assert_response :success
84
- assert_includes response.body, "Monday"
85
-
86
- get new_daily_report_path(nested_params), headers: frame_headers(@list_frame)
87
- assert_response :success
88
-
89
- assert_difference -> { DailyReport.count }, +1 do
90
- post daily_reports_path(nested_params), params: { name: "Tuesday" }, headers: frame_headers(@list_frame)
91
- end
92
- assert_response :success
93
- assert_equal @machine.id, DailyReport.find_by!(name: "Tuesday").machine_id
94
-
95
- get daily_report_path(@report, update: @row_frame), headers: frame_headers(@row_frame)
96
- assert_response :success
97
- assert_includes response.body, %(<turbo-frame id="#{@row_frame}">)
98
-
99
- delete daily_report_path(@report, update: @row_frame), headers: frame_headers(@row_frame)
100
- assert_response :success
101
- refute DailyReport.exists?(@report.id)
102
- end
103
-
104
- test "a nested revert still restores the record" do
105
- @report.update!(name: "Changed")
106
- version = @report.versions.where(event: "update").last
107
-
108
- post revert_daily_report_path(version.id, update: @row_frame), headers: stream_headers(@row_frame)
109
- assert_response :success
110
- assert_equal "Monday", @report.reload.name
111
- end
112
-
113
- # ---- accessible model ------------------------------------------------------
114
-
115
- test "an accessible model's list and row still render" do
116
- get machines_path
117
- assert_response :success
118
- assert_includes response.body, "Press"
119
-
120
- get machine_path(@machine)
121
- assert_response :success
122
- end
123
-
124
- test "an accessible model's new and create without update are a 400; nothing is created" do
125
- get new_machine_path
126
- assert_refused :bad_request
127
-
128
- assert_no_difference -> { Machine.count } do
129
- post machines_path, params: { name: "Lathe" }
130
- end
131
- assert_refused :bad_request
132
- end
133
-
134
- test "destroy by a user who may not hard-destroy is a 403 and keeps the record" do
135
- ApplicationController.dummy_user_superadmin = false
136
- frame = "machine_#{@machine.id}"
137
-
138
- delete machine_path(@machine, update: frame), headers: frame_headers(frame)
139
- assert_refused :forbidden
140
- assert Machine.exists?(@machine.id)
141
- end
142
-
143
- # ---- file slots ------------------------------------------------------------
144
-
145
- test "a refused file-slot request still counts as authorized" do
146
- document = Document.create!(title: "Plan")
147
- frame = "document_#{document.id}_filename"
148
-
149
- post remove_file_document_path(document, attribute: "title", update: frame), headers: stream_headers(frame)
150
- assert_refused :bad_request
151
- end
152
- end
@@ -1,165 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "../integration_test_helper"
4
-
5
- # End-to-end (controller + views + Turbo frames) CRUD through the engine's
6
- # InlineFormsController, running against the test/dummy host app.
7
- class InlineFormsCrudTest < InlineFormsIntegrationTestCase
8
- setup do
9
- @widget = Widget.create!(name: "Alpha", priority: 2)
10
- end
11
-
12
- test "index lists rows inside the list turbo-frame" do
13
- get widgets_path(update: "widgets_list"), headers: frame_headers("widgets_list")
14
-
15
- assert_response :success
16
- assert_includes response.body, %(<turbo-frame id="widgets_list" class="list_container">)
17
- assert_includes response.body, %(<turbo-frame id="widget_#{@widget.id}">)
18
- assert_includes response.body, "Alpha"
19
- end
20
-
21
- test "index applies inline_forms_search when ?search= is passed" do
22
- Widget.create!(name: "Beta")
23
-
24
- get widgets_path(update: "widgets_list", search: "Alp"),
25
- headers: frame_headers("widgets_list")
26
-
27
- assert_response :success
28
- assert_includes response.body, "Alpha"
29
- refute_includes response.body, "Beta"
30
- end
31
-
32
- test "row show renders attribute frames" do
33
- frame = "widget_#{@widget.id}"
34
- get widget_path(@widget, update: frame), headers: frame_headers(frame)
35
-
36
- assert_response :success
37
- assert_includes response.body, %(<turbo-frame id="#{frame}">)
38
- assert_includes response.body, %(<turbo-frame id="widget_#{@widget.id}_name">)
39
- end
40
-
41
- test "attribute edit renders the input in its frame" do
42
- frame = "widget_#{@widget.id}_name"
43
- get edit_widget_path(@widget, attribute: "name", form_element: "text_field",
44
- update: frame),
45
- headers: frame_headers(frame)
46
-
47
- assert_response :success
48
- assert_includes response.body, %(<turbo-frame id="#{frame}">)
49
- assert_includes response.body, %(name="name")
50
- assert_includes response.body, %(value="Alpha")
51
- end
52
-
53
- test "attribute update persists and renders the show state" do
54
- frame = "widget_#{@widget.id}_name"
55
- put widget_path(@widget, attribute: "name", form_element: "text_field",
56
- update: frame),
57
- params: { name: "Renamed" }, headers: frame_headers(frame)
58
-
59
- assert_response :success
60
- assert_equal "Renamed", @widget.reload.name
61
- assert_includes response.body, "Renamed"
62
- end
63
-
64
- test "failed save re-renders the edit state, not a fake show (8.1.19)" do
65
- frame = "widget_#{@widget.id}_name"
66
- put widget_path(@widget, attribute: "name", form_element: "text_field",
67
- update: frame),
68
- params: { name: "" }, headers: frame_headers(frame)
69
-
70
- assert_response :success
71
- assert_equal "Alpha", @widget.reload.name, "blank name must not persist"
72
- assert_includes response.body, %(name="name"),
73
- "expected the edit input to be re-rendered after a failed save"
74
- assert_includes response.body, "inline_forms_field_error"
75
- assert_includes response.body, "can&#39;t be blank"
76
- end
77
-
78
- test "failed save with invalid value shows validation errors in the editor" do
79
- frame = "widget_#{@widget.id}_notes"
80
- put widget_path(@widget, attribute: "notes", form_element: "plain_text_area",
81
- update: frame),
82
- params: { notes: "short" }, headers: frame_headers(frame)
83
-
84
- assert_response :success
85
- assert_nil @widget.reload.notes
86
- assert_includes response.body, "inline_forms_field_error"
87
- assert_includes response.body, "is too short"
88
- end
89
-
90
- test "edit render shows no field error when flash is empty" do
91
- frame = "widget_#{@widget.id}_name"
92
- get edit_widget_path(@widget, attribute: "name", form_element: "text_field",
93
- update: frame),
94
- headers: frame_headers(frame)
95
-
96
- assert_response :success
97
- refute_includes response.body, "inline_forms_field_error"
98
- end
99
-
100
- test "destroy responds with the destroyed-row state and an undo pointing at the destroy version" do
101
- frame = "widget_#{@widget.id}"
102
- assert_difference -> { Widget.count }, -1 do
103
- delete widget_path(@widget, update: frame), headers: frame_headers(frame)
104
- end
105
- assert_response :success
106
-
107
- destroy_version = PaperTrail::Version.where(item_type: "Widget",
108
- item_id: @widget.id,
109
- event: "destroy").last
110
- assert destroy_version, "expected a PaperTrail destroy version"
111
- assert_includes response.body, "/widgets/#{destroy_version.id}/revert",
112
- "undo link must target the destroy version (8.1.13)"
113
- end
114
-
115
- # revert responds with turbo_stream (replaces row + versions panel at once,
116
- # see render_revert_response); the undo/Restore links request that format.
117
- def turbo_stream_headers(frame_id)
118
- frame_headers(frame_id).merge("Accept" => "text/vnd.turbo-stream.html")
119
- end
120
-
121
- test "revert of a destroy version restores the row (undo)" do
122
- frame = "widget_#{@widget.id}"
123
- delete widget_path(@widget, update: frame), headers: frame_headers(frame)
124
- destroy_version = PaperTrail::Version.where(item_type: "Widget",
125
- item_id: @widget.id,
126
- event: "destroy").last
127
-
128
- assert_difference -> { Widget.count }, +1 do
129
- post revert_widget_path(destroy_version.id, update: "widgets_list"),
130
- headers: turbo_stream_headers("widgets_list")
131
- end
132
- assert_response :success
133
- assert Widget.exists?(@widget.id), "undo must restore the destroyed row"
134
- assert_equal "Alpha", Widget.find(@widget.id).name
135
- end
136
-
137
- test "revert of a destroy version is idempotent when the row already exists (8.1.17)" do
138
- frame = "widget_#{@widget.id}"
139
- delete widget_path(@widget, update: frame), headers: frame_headers(frame)
140
- destroy_version = PaperTrail::Version.where(item_type: "Widget",
141
- item_id: @widget.id,
142
- event: "destroy").last
143
-
144
- post revert_widget_path(destroy_version.id, update: "widgets_list"),
145
- headers: turbo_stream_headers("widgets_list")
146
- assert Widget.exists?(@widget.id)
147
-
148
- # Replaying the same restore must not raise RecordNotUnique.
149
- post revert_widget_path(destroy_version.id, update: "widgets_list"),
150
- headers: turbo_stream_headers("widgets_list")
151
- assert_response :success
152
- assert_equal 1, Widget.where(id: @widget.id).count
153
- end
154
-
155
- test "versions panel lists an update event" do
156
- @widget.update!(name: "Renamed once")
157
- frame = "widget_#{@widget.id}"
158
-
159
- get list_versions_widget_path(@widget, update: frame),
160
- headers: frame_headers(frame)
161
-
162
- assert_response :success
163
- assert_includes response.body, "Renamed once"
164
- end
165
- end
@@ -1,56 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "../integration_test_helper"
4
-
5
- # layouts/inline_forms <title>: t('application_name') used to render the
6
- # html_safe <span class="translation_missing"> into <title> when the host had
7
- # no translation (every page of a fresh example app). It now falls back to
8
- # ApplicationHelper#application_name ("Dummy" here) and is always plain text.
9
- class LayoutTitleTest < InlineFormsIntegrationTestCase
10
- teardown do
11
- I18n.backend.reload!
12
- end
13
-
14
- def page_title
15
- response.body[%r{<title>(.*?)</title>}m, 1]
16
- end
17
-
18
- test "title falls back to the application_name helper without a translation" do
19
- get widgets_path
20
-
21
- assert_response :success
22
- assert_equal "Dummy v#{InlineForms::VERSION}", page_title
23
- refute_includes page_title, "translation_missing"
24
- end
25
-
26
- test "title uses the application_name translation when the host defines one" do
27
- I18n.backend.store_translations(:en, application_name: "Widget Works")
28
-
29
- get widgets_path
30
-
31
- assert_response :success
32
- assert_equal "Widget Works v#{InlineForms::VERSION}", page_title
33
- end
34
-
35
- test "title in nl does not show the gem's old placeholder" do
36
- I18n.with_locale(:nl) do
37
- original = I18n.default_locale
38
- I18n.default_locale = :nl
39
- get widgets_path
40
- ensure
41
- I18n.default_locale = original
42
- end
43
-
44
- assert_response :success
45
- assert_equal "Dummy v#{InlineForms::VERSION}", page_title
46
- end
47
-
48
- test "markup in the translation is escaped, never rendered into the title" do
49
- I18n.backend.store_translations(:en, application_name: "<b>Bold</b>")
50
-
51
- get widgets_path
52
-
53
- assert_response :success
54
- assert_equal "&lt;b&gt;Bold&lt;/b&gt; v#{InlineForms::VERSION}", page_title
55
- end
56
- end
@@ -1,99 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "../integration_test_helper"
4
-
5
- # First-ever render coverage for two legacy display elements that no example
6
- # app exercises (see stuff/improvement-plan.md §4): simple_file_field (raw
7
- # filename column + host-provided download route) and pdf_link (host-provided
8
- # /:attribute/:id report route).
9
- class LegacyElementsTest < InlineFormsIntegrationTestCase
10
- setup do
11
- @widget = Widget.create!(name: "Legacy")
12
- end
13
-
14
- test "simple_file_field blank state renders the inline-edit plus link" do
15
- frame = "widget_#{@widget.id}"
16
- get widget_path(@widget, update: frame), headers: frame_headers(frame)
17
-
18
- assert_response :success
19
- assert_includes response.body, %(<turbo-frame id="widget_#{@widget.id}_manual">)
20
- assert_includes response.body, "fi-plus"
21
- end
22
-
23
- test "simple_file_field present state download link bypasses Turbo" do
24
- @widget.update!(manual: "Lida.png")
25
- frame = "widget_#{@widget.id}"
26
- get widget_path(@widget, update: frame), headers: frame_headers(frame)
27
-
28
- assert_response :success
29
- # The download link must carry data-turbo="false" so the browser handles
30
- # the send_data response natively instead of Turbo loading the binary into
31
- # the frame (a no-op). The route method comes from the values entry.
32
- assert_match %r{<a[^>]*data-turbo="false"[^>]*href="/widgets/download/#{@widget.id}"}, response.body
33
- end
34
-
35
- test "simple_file_field edit renders a file input" do
36
- frame = "widget_#{@widget.id}_manual"
37
- get edit_widget_path(@widget, attribute: "manual",
38
- form_element: "simple_file_field", update: frame),
39
- headers: frame_headers(frame)
40
-
41
- assert_response :success
42
- assert_includes response.body, %(type="file")
43
- assert_includes response.body, %(name="manual")
44
- end
45
-
46
- test "pdf_link show renders preview and pdf links for the attribute route" do
47
- frame = "widget_#{@widget.id}"
48
- get widget_path(@widget, update: frame), headers: frame_headers(frame)
49
-
50
- assert_response :success
51
- assert_includes response.body, %(href="/report/#{@widget.id}")
52
- assert_includes response.body, %(href="/report/#{@widget.id}.pdf")
53
- end
54
-
55
- test "pdf_link reads preview | download pdf" do
56
- frame = "widget_#{@widget.id}"
57
- get widget_path(@widget, update: frame), headers: frame_headers(frame)
58
-
59
- assert_response :success
60
- assert_select %(a[href="/report/#{@widget.id}"]), text: "preview"
61
- assert_select %(a[href="/report/#{@widget.id}.pdf"]), text: "download pdf"
62
- assert_match %r{>preview</a> \| <a[^>]*>download pdf</a>}, response.body
63
- end
64
-
65
- test "pdf_link needs no model method in the new form" do
66
- assert_not Widget.new.respond_to?(:report)
67
-
68
- get new_widget_path(update: "widgets_list"), headers: frame_headers("widgets_list")
69
-
70
- assert_response :success
71
- end
72
-
73
- test "pdf_link links keep the app's sub-path" do
74
- frame = "widget_#{@widget.id}"
75
- get widget_path(@widget, update: frame), headers: frame_headers(frame), env: { "SCRIPT_NAME" => "/portal" }
76
-
77
- assert_response :success
78
- assert_select %(a.pdf_preview[href="/portal/report/#{@widget.id}"])
79
- assert_select %(a.pdf_open[href="/portal/report/#{@widget.id}.pdf"])
80
- end
81
-
82
- test "pdf_link links leave the field's turbo frame" do
83
- frame = "widget_#{@widget.id}"
84
- get widget_path(@widget, update: frame), headers: frame_headers(frame)
85
-
86
- assert_response :success
87
- assert_select %(a[href="/report/#{@widget.id}"][data-turbo="false"])
88
- assert_select %(a[href="/report/#{@widget.id}.pdf"][data-turbo="false"])
89
- end
90
-
91
- test "pdf_link preview opens in a new tab, the pdf link does not" do
92
- frame = "widget_#{@widget.id}"
93
- get widget_path(@widget, update: frame), headers: frame_headers(frame)
94
-
95
- assert_response :success
96
- assert_select %(a[href="/report/#{@widget.id}"][target="_blank"])
97
- assert_select %(a[href="/report/#{@widget.id}.pdf"][target]), false
98
- end
99
- end
@@ -1,200 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "../integration_test_helper"
4
-
5
- # Request params that end up in a list's markup.
6
- #
7
- # * parent_class / parent_id: _list built the nested frame as
8
- # `raw "<turbo-frame id=\"#{update_span}\" …>"` with update_span made from
9
- # params[:parent_id], and constantized params[:parent_class]; nothing found
10
- # the parent before the render, so a crafted parent_id was reflected into
11
- # the page. The controller now refuses malformed parent params (400) in
12
- # index/new/create/show, and the frame is built with tag.turbo_frame.
13
- # * pagination: the page links carry every filter of the query string, not
14
- # just `search`.
15
- #
16
- # Part and DailyReport belong to Machine; Widget is a top-level list
17
- # (per_page 7, see ApplicationRecord).
18
- class ListParamsTest < InlineFormsIntegrationTestCase
19
- PAYLOAD = %("><img src=x onerror=alert(1)>)
20
-
21
- setup do
22
- @machine = Machine.create!(name: "Press")
23
- @part = Part.create!(name: "Gear", machine: @machine)
24
- @list_frame = "machine_#{@machine.id}_parts_list"
25
- end
26
-
27
- def assert_refused_without_payload
28
- assert_response :bad_request
29
- assert controller.instance_variable_defined?(:@_authorized),
30
- "the refusal runs after authorization (check_authorization stays satisfied)"
31
- refute_includes response.body, "<img"
32
- end
33
-
34
- def nested(parent_id: @machine.id, parent_class: "Machine", update: @list_frame)
35
- { parent_class: parent_class, parent_id: parent_id, update: update, ul_needed: 1 }
36
- end
37
-
38
- # ---- malformed parent params --------------------------------------------
39
-
40
- test "a crafted parent_id on the nested list is a 400 and never rendered" do
41
- get parts_path(nested(parent_id: PAYLOAD, update: "x")), headers: frame_headers("x")
42
- assert_refused_without_payload
43
- end
44
-
45
- test "a crafted parent_id is refused on a full-page visit too" do
46
- get parts_path(nested(parent_id: PAYLOAD, update: "x"))
47
- assert_refused_without_payload
48
- end
49
-
50
- test "a parent_class that is not an association of the model is a 400" do
51
- %w[Widget Kernel machine Machines ActiveRecord::Base].each do |parent_class|
52
- get parts_path(nested(parent_class: parent_class)), headers: frame_headers(@list_frame)
53
- assert_response :bad_request, "parent_class=#{parent_class}"
54
- end
55
- end
56
-
57
- test "a non-integer parent_id is a 400, with or without parent_class" do
58
- [ "1 OR 1=1", "-1", "1.5", "" ].each do |parent_id|
59
- get parts_path(nested(parent_id: parent_id)), headers: frame_headers(@list_frame)
60
- assert_response :bad_request, "parent_id=#{parent_id.inspect}"
61
- end
62
- get parts_path(parent_id: PAYLOAD, update: "x")
63
- assert_refused_without_payload
64
- end
65
-
66
- test "new with crafted parent params is a 400" do
67
- get new_part_path(nested(parent_id: PAYLOAD, update: "machine_#{@machine.id}_parts")),
68
- headers: frame_headers("machine_#{@machine.id}_parts")
69
- assert_refused_without_payload
70
-
71
- get new_part_path(nested(parent_class: "Widget", update: "machine_#{@machine.id}_parts")),
72
- headers: frame_headers("machine_#{@machine.id}_parts")
73
- assert_response :bad_request
74
- end
75
-
76
- test "create with crafted parent params is a 400 and creates nothing" do
77
- frame = "machine_#{@machine.id}_parts"
78
- assert_no_difference -> { Part.count } do
79
- post parts_path(nested(parent_id: PAYLOAD, update: frame)), params: { name: "Bolt" }, headers: frame_headers(frame)
80
- assert_refused_without_payload
81
- post parts_path(nested(parent_class: "Widget", update: frame)), params: { name: "Bolt" }, headers: frame_headers(frame)
82
- assert_response :bad_request
83
- end
84
- end
85
-
86
- test "show with a crafted parent_id is a 400" do
87
- row = "machine_#{@machine.id}_part_#{@part.id}"
88
- get part_path(@part, update: row, parent_class: "Machine", parent_id: PAYLOAD), headers: frame_headers(row)
89
- assert_refused_without_payload
90
- end
91
-
92
- # ---- well-formed nested lists still work --------------------------------
93
-
94
- test "a well-formed nested list renders its frame and rows" do
95
- get parts_path(nested), headers: frame_headers(@list_frame)
96
-
97
- assert_response :success
98
- assert_includes response.body, %(<turbo-frame id="#{@list_frame}" class="list_container">)
99
- assert_includes response.body, "Gear"
100
- end
101
-
102
- test "well-formed nested new and create still work" do
103
- frame = "machine_#{@machine.id}_parts"
104
- get new_part_path(nested(update: frame)), headers: frame_headers(frame)
105
- assert_response :success
106
-
107
- assert_difference -> { @machine.parts.count }, 1 do
108
- post parts_path(nested(update: frame)), params: { name: "Bolt" }, headers: frame_headers(frame)
109
- end
110
- assert_response :success
111
- end
112
-
113
- test "the nested list of a not_accessible_through_html? child still renders" do
114
- DailyReport.create!(name: "Monday", machine: @machine)
115
- frame = "machine_#{@machine.id}_daily_reports_list"
116
- get daily_reports_path(parent_class: "Machine", parent_id: @machine.id, update: frame, ul_needed: 1),
117
- headers: frame_headers(frame)
118
-
119
- assert_response :success
120
- assert_includes response.body, "Monday"
121
- end
122
-
123
- test "the list frame id is attribute-escaped by the partial itself" do
124
- html = PartsController.render(
125
- partial: "inline_forms/list",
126
- assigns: { Klass: Part, parent_class: "Machine", parent_id: PAYLOAD, ul_needed: "1",
127
- objects: Part.where(id: @part.id).paginate(page: 1) }
128
- )
129
-
130
- refute_includes html, "<img"
131
- assert_includes html, %(<turbo-frame id="machine_&quot;&gt;&lt;img src=x onerror=alert(1)&gt;_parts_list" class="list_container">)
132
- end
133
-
134
- # ---- pagination keeps the filters ---------------------------------------
135
-
136
- test "page links of a filtered list carry every filter" do
137
- 9.times { |i| Widget.create!(name: "Match #{i}") }
138
- Widget.create!(name: "Other")
139
-
140
- get widgets_path(search: "Match", sorteer: "name", first_name: "An", group: { id: 3 }, status: { id: 4 },
141
- update: "widgets_list"),
142
- headers: frame_headers("widgets_list")
143
-
144
- assert_response :success
145
- page_link = response.body[/href="([^"]*page=2[^"]*)"/, 1]
146
- assert page_link, "a link to page 2"
147
- query = Rack::Utils.parse_nested_query(URI.parse(CGI.unescapeHTML(page_link)).query)
148
- assert_equal "Match", query["search"]
149
- assert_equal "name", query["sorteer"]
150
- assert_equal "An", query["first_name"]
151
- assert_equal({ "id" => "3" }, query["group"])
152
- assert_equal({ "id" => "4" }, query["status"])
153
- assert_equal "widgets_list", query["update"]
154
- assert_equal "2", query["page"]
155
-
156
- get CGI.unescapeHTML(page_link), headers: frame_headers("widgets_list")
157
- assert_response :success
158
- back = response.body[/href="([^"]*page=1[^"]*)"/, 1]
159
- assert back, "a link back to page 1"
160
- back_query = Rack::Utils.parse_nested_query(URI.parse(CGI.unescapeHTML(back)).query)
161
- assert_equal "Match", back_query["search"]
162
- assert_equal({ "id" => "3" }, back_query["group"])
163
- refute_includes response.body, "Other"
164
- end
165
-
166
- test "page links of a list rendered after create keep the request's filters" do
167
- 9.times { |i| Machine.create!(name: "Match #{i}") }
168
-
169
- post machines_path(update: "machines_list", search: "Match", sorteer: "name"),
170
- params: { name: "Match 9" }, headers: frame_headers("machines_list")
171
-
172
- assert_response :success
173
- page_link = response.body[/href="([^"]*page=2[^"]*)"/, 1]
174
- assert page_link, "a link to page 2"
175
- query = Rack::Utils.parse_nested_query(URI.parse(CGI.unescapeHTML(page_link)).query)
176
- assert_equal "Match", query["search"]
177
- assert_equal "name", query["sorteer"]
178
- end
179
-
180
- # url_for options in the query string must not shape the page links.
181
- # will_paginate leaves out script_name / original_script_name; merging
182
- # request.query_parameters into the links bypassed that, so the payload
183
- # became the start of every page link's href, and controller= raised.
184
- test "url options in the query string never reach the page links" do
185
- 9.times { |i| Widget.create!(name: "W #{i}") }
186
-
187
- %w[script_name original_script_name].each do |option|
188
- get "/widgets?update=widgets_list&#{option}=javascript:alert(1)//", headers: frame_headers("widgets_list")
189
- assert_response :success
190
- page_link = response.body[/href="([^"]*page=2[^"]*)"/, 1]
191
- assert page_link, "a link to page 2"
192
- assert page_link.start_with?("/widgets?"), "#{option} shaped the page link: #{page_link}"
193
- refute_includes response.body, "javascript:alert"
194
- end
195
-
196
- get "/widgets?update=widgets_list&controller=widgets_x", headers: frame_headers("widgets_list")
197
- assert_response :success
198
- assert_match %r{href="/widgets\?[^"]*page=2}, response.body
199
- end
200
- end