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,301 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require_relative "test_helper"
|
|
4
|
-
require "tmpdir"
|
|
5
|
-
require "fileutils"
|
|
6
|
-
require "logger"
|
|
7
|
-
require "rails"
|
|
8
|
-
require "rails/generators"
|
|
9
|
-
require "inline_forms"
|
|
10
|
-
require_relative "../lib/generators/inline_forms_generator"
|
|
11
|
-
|
|
12
|
-
class InlineFormsGeneratorTest < Minitest::Test
|
|
13
|
-
def setup
|
|
14
|
-
@destination_root = Dir.mktmpdir("inline_forms_generator_test")
|
|
15
|
-
build_destination_skeleton!
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
def teardown
|
|
19
|
-
FileUtils.remove_entry(@destination_root) if @destination_root && Dir.exist?(@destination_root)
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
def test_generates_model_controller_route_migration_and_tab_injection
|
|
23
|
-
run_generator(
|
|
24
|
-
"Thing",
|
|
25
|
-
"name:string",
|
|
26
|
-
"category:dropdown",
|
|
27
|
-
"photos:has_many",
|
|
28
|
-
"_enabled:yes",
|
|
29
|
-
"_presentation:\\#{name}"
|
|
30
|
-
)
|
|
31
|
-
|
|
32
|
-
model = read("app/models/thing.rb")
|
|
33
|
-
controller = read("app/controllers/things_controller.rb")
|
|
34
|
-
routes = read("config/routes.rb")
|
|
35
|
-
inline_forms_initializer = read("config/initializers/inline_forms.rb")
|
|
36
|
-
migration = read_single_migration_for("things")
|
|
37
|
-
|
|
38
|
-
assert_includes(model, "class Thing < ApplicationRecord")
|
|
39
|
-
refute_includes(model, "has_paper_trail")
|
|
40
|
-
refute_includes(model, "attr_reader :per_page")
|
|
41
|
-
refute_includes(model, 'def self.not_accessible_through_html?')
|
|
42
|
-
refute_includes(model, "def self.order_by_clause")
|
|
43
|
-
refute_includes(model, "scope :inline_forms_list")
|
|
44
|
-
refute_includes(model, "scope :inline_forms_search")
|
|
45
|
-
assert_includes(model, "belongs_to :category")
|
|
46
|
-
assert_includes(model, "has_many :photos")
|
|
47
|
-
assert_includes(model, "[ :name, :text_field ]")
|
|
48
|
-
assert_includes(model, "[ :category, :dropdown ]")
|
|
49
|
-
|
|
50
|
-
assert_includes(controller, "class ThingsController < InlineFormsController")
|
|
51
|
-
assert_includes(controller, "set_tab :thing")
|
|
52
|
-
|
|
53
|
-
assert_includes(routes, "resources :things do")
|
|
54
|
-
assert_includes(routes, 'post "revert", on: :member')
|
|
55
|
-
assert_includes(routes, 'get "list_versions", on: :member')
|
|
56
|
-
|
|
57
|
-
assert_includes(inline_forms_initializer, "MODEL_TABS = %w[things ")
|
|
58
|
-
|
|
59
|
-
assert_includes(migration, "class InlineFormsCreateThings < ActiveRecord::Migration[8.1]")
|
|
60
|
-
assert_includes(migration, "create_table :things do |t|")
|
|
61
|
-
assert_includes(migration, "t.string :name")
|
|
62
|
-
assert_includes(migration, "t.belongs_to :category")
|
|
63
|
-
refute_includes(migration, "photos")
|
|
64
|
-
end
|
|
65
|
-
|
|
66
|
-
def test_skips_model_controller_and_routes_when_no_model_flag_is_present
|
|
67
|
-
run_generator("AuditLog", "message:string", "_no_model:yes")
|
|
68
|
-
|
|
69
|
-
refute_exist("app/models/audit_log.rb")
|
|
70
|
-
refute_exist("app/controllers/audit_logs_controller.rb")
|
|
71
|
-
|
|
72
|
-
routes = read("config/routes.rb")
|
|
73
|
-
refute_includes(routes, "resources :audit_logs")
|
|
74
|
-
end
|
|
75
|
-
|
|
76
|
-
def test_fails_fast_for_unknown_types_by_default
|
|
77
|
-
stdout, stderr = capture_io do
|
|
78
|
-
run_generator("Mystery", "payload:not_a_real_type", "--no-allow-unknown")
|
|
79
|
-
end
|
|
80
|
-
output = "#{stdout}#{stderr}"
|
|
81
|
-
|
|
82
|
-
assert_includes(output, "Unknown field type(s): payload:not_a_real_type")
|
|
83
|
-
assert_includes(output, "--allow-unknown")
|
|
84
|
-
refute_exist("app/models/mystery.rb")
|
|
85
|
-
assert_equal([], Dir.glob(File.join(@destination_root, "db/migrate/*_inline_forms_create_mysteries.rb")))
|
|
86
|
-
end
|
|
87
|
-
|
|
88
|
-
def test_allow_unknown_keeps_legacy_commented_output
|
|
89
|
-
run_generator("Mystery", "payload:not_a_real_type", "--allow-unknown")
|
|
90
|
-
|
|
91
|
-
model = read("app/models/mystery.rb")
|
|
92
|
-
migration = read_single_migration_for("mysteries")
|
|
93
|
-
|
|
94
|
-
assert_includes(model, "# [ :payload, :unknown ]")
|
|
95
|
-
assert_includes(migration, "# t.unknown :payload")
|
|
96
|
-
end
|
|
97
|
-
|
|
98
|
-
def test_rich_text_adds_has_rich_text_without_migration_column
|
|
99
|
-
run_generator("Article", "title:string", "content:rich_text")
|
|
100
|
-
|
|
101
|
-
model = read("app/models/article.rb")
|
|
102
|
-
migration = read_single_migration_for("articles")
|
|
103
|
-
|
|
104
|
-
assert_includes(model, "has_rich_text :content")
|
|
105
|
-
refute_includes(migration, "t.no_migration :content")
|
|
106
|
-
refute_includes(migration, "t.text :content")
|
|
107
|
-
end
|
|
108
|
-
|
|
109
|
-
def test_not_accessible_and_list_order_emits_scope_and_spaceship
|
|
110
|
-
run_generator(
|
|
111
|
-
"Photo",
|
|
112
|
-
"name:string",
|
|
113
|
-
"album:belongs_to",
|
|
114
|
-
"_presentation:\\#{name}",
|
|
115
|
-
"_list_order:caption"
|
|
116
|
-
)
|
|
117
|
-
|
|
118
|
-
model = read("app/models/photo.rb")
|
|
119
|
-
assert_includes(model, "def self.not_accessible_through_html?\n true")
|
|
120
|
-
assert_includes(model, "scope :inline_forms_list, -> { order(:caption, :id) }")
|
|
121
|
-
assert_includes(model, "def <=>(other)")
|
|
122
|
-
assert_includes(model, "self.caption <=> other.caption")
|
|
123
|
-
refute_includes(model, "def self.order_by_clause")
|
|
124
|
-
refute_includes(model, "has_paper_trail")
|
|
125
|
-
end
|
|
126
|
-
|
|
127
|
-
def test_legacy_order_alias_still_emits_scope_with_deprecation_warning
|
|
128
|
-
stdout, stderr = capture_io do
|
|
129
|
-
run_generator(
|
|
130
|
-
"Photo",
|
|
131
|
-
"name:string",
|
|
132
|
-
"_presentation:\\#{name}",
|
|
133
|
-
"_order:caption"
|
|
134
|
-
)
|
|
135
|
-
end
|
|
136
|
-
|
|
137
|
-
output = "#{stdout}#{stderr}"
|
|
138
|
-
assert_includes(output, "_order:caption is deprecated")
|
|
139
|
-
assert_includes(output, "_list_order:caption")
|
|
140
|
-
|
|
141
|
-
model = read("app/models/photo.rb")
|
|
142
|
-
assert_includes(model, "scope :inline_forms_list, -> { order(:caption, :id) }")
|
|
143
|
-
refute_includes(model, "def self.order_by_clause")
|
|
144
|
-
end
|
|
145
|
-
|
|
146
|
-
def test_list_search_emits_search_scope
|
|
147
|
-
run_generator(
|
|
148
|
-
"Apartment",
|
|
149
|
-
"name:string",
|
|
150
|
-
"_enabled:yes",
|
|
151
|
-
"_list_order:name",
|
|
152
|
-
"_list_search:name",
|
|
153
|
-
"_presentation:\\#{name}"
|
|
154
|
-
)
|
|
155
|
-
|
|
156
|
-
model = read("app/models/apartment.rb")
|
|
157
|
-
assert_includes(model, "scope :inline_forms_list, -> { order(:name, :id) }")
|
|
158
|
-
assert_includes(model, "inline_forms_search_on :name")
|
|
159
|
-
migration = read_single_migration_for("apartments")
|
|
160
|
-
refute_includes(migration, "_list_order")
|
|
161
|
-
refute_includes(migration, "_list_search")
|
|
162
|
-
end
|
|
163
|
-
|
|
164
|
-
def test_plain_text_generates_text_column_and_plain_text_form_element
|
|
165
|
-
run_generator("Note", "title:string", "description:plain_text")
|
|
166
|
-
|
|
167
|
-
model = read("app/models/note.rb")
|
|
168
|
-
migration = read_single_migration_for("notes")
|
|
169
|
-
|
|
170
|
-
assert_includes(model, "[ :description, :plain_text ]")
|
|
171
|
-
assert_includes(migration, "t.text :description")
|
|
172
|
-
end
|
|
173
|
-
|
|
174
|
-
def test_simple_file_field_declares_a_file_slot_with_its_columns_and_routes
|
|
175
|
-
run_generator("Folder", "title:string", "plan_filename:simple_file_field", "_enabled:yes")
|
|
176
|
-
|
|
177
|
-
model = read("app/models/folder.rb")
|
|
178
|
-
routes = read("config/routes.rb")
|
|
179
|
-
migration = read_single_migration_for("folders")
|
|
180
|
-
|
|
181
|
-
assert_includes(model, "include InlineForms::StoredFiles")
|
|
182
|
-
assert_includes(model, "inline_forms_file :plan_filename")
|
|
183
|
-
assert_operator(model.index("include InlineForms::StoredFiles"), :<, model.index("inline_forms_file :plan_filename"))
|
|
184
|
-
assert_includes(model, "[ :plan_filename, :simple_file_field ]")
|
|
185
|
-
assert_includes(migration, "t.string :plan_filename")
|
|
186
|
-
assert_includes(migration, "t.binary :plan_data")
|
|
187
|
-
assert_includes(migration, "t.string :plan_content_type")
|
|
188
|
-
assert_includes(routes, "InlineForms.file_routes(self)")
|
|
189
|
-
end
|
|
190
|
-
|
|
191
|
-
# RuboCop omakase, which generated apps run in bin/ci.
|
|
192
|
-
def test_model_and_migration_follow_the_style_of_a_generated_app
|
|
193
|
-
run_generator(
|
|
194
|
-
"Thing",
|
|
195
|
-
"name:string",
|
|
196
|
-
"category:dropdown",
|
|
197
|
-
"photos:has_many_destroy",
|
|
198
|
-
"_enabled:yes",
|
|
199
|
-
"_list_order:name",
|
|
200
|
-
"_presentation:\\#{name}"
|
|
201
|
-
)
|
|
202
|
-
|
|
203
|
-
model = read("app/models/thing.rb")
|
|
204
|
-
assert_includes(model, " [ :name, :text_field ],\n [ :category, :dropdown ]\n ]\n")
|
|
205
|
-
assert_includes(model, "has_many :photos, dependent: :destroy")
|
|
206
|
-
[ model, read_single_migration_for("things"), read("test/unit/thing_test.rb") ].each do |content|
|
|
207
|
-
refute_match(/[ \t]$/, content)
|
|
208
|
-
refute_match(/\Aclass [^\n]*\n\n/, content)
|
|
209
|
-
refute_match(/\n\nend\n\z/, content)
|
|
210
|
-
refute_match(/\n{3}/, content)
|
|
211
|
-
assert(content.end_with?("end\n"))
|
|
212
|
-
end
|
|
213
|
-
end
|
|
214
|
-
|
|
215
|
-
def test_a_commented_out_row_leaves_the_last_real_row_without_a_comma
|
|
216
|
-
run_generator("Mystery", "name:string", "payload:not_a_real_type", "--allow-unknown")
|
|
217
|
-
|
|
218
|
-
model = read("app/models/mystery.rb")
|
|
219
|
-
assert_includes(model, " [ :name, :text_field ]\n# [ :payload, :unknown ],\n ]")
|
|
220
|
-
RubyVM::InstructionSequence.compile(model)
|
|
221
|
-
end
|
|
222
|
-
|
|
223
|
-
def test_tab_injection_into_an_initializer_from_before_8_1_72
|
|
224
|
-
write("config/initializers/inline_forms.rb", "MODEL_TABS = %w(users )\n")
|
|
225
|
-
|
|
226
|
-
run_generator("Thing", "name:string", "_enabled:yes")
|
|
227
|
-
|
|
228
|
-
assert_equal("MODEL_TABS = %w(things users )\n", read("config/initializers/inline_forms.rb"))
|
|
229
|
-
end
|
|
230
|
-
|
|
231
|
-
def test_no_file_routes_without_a_file_field
|
|
232
|
-
run_generator("Thing", "name:string", "_enabled:yes")
|
|
233
|
-
|
|
234
|
-
refute_includes(read("config/routes.rb"), "file_routes")
|
|
235
|
-
refute_includes(read("app/models/thing.rb"), "StoredFiles")
|
|
236
|
-
end
|
|
237
|
-
|
|
238
|
-
private
|
|
239
|
-
|
|
240
|
-
def build_destination_skeleton!
|
|
241
|
-
mkdir_p("config")
|
|
242
|
-
mkdir_p("config/initializers")
|
|
243
|
-
mkdir_p("app/controllers")
|
|
244
|
-
mkdir_p("app/models")
|
|
245
|
-
mkdir_p("db/migrate")
|
|
246
|
-
mkdir_p("test/unit")
|
|
247
|
-
|
|
248
|
-
write(
|
|
249
|
-
"config/routes.rb",
|
|
250
|
-
<<~RUBY
|
|
251
|
-
Rails.application.routes.draw do
|
|
252
|
-
end
|
|
253
|
-
RUBY
|
|
254
|
-
)
|
|
255
|
-
|
|
256
|
-
write(
|
|
257
|
-
"app/controllers/application_controller.rb",
|
|
258
|
-
<<~RUBY
|
|
259
|
-
class ApplicationController < ActionController::Base
|
|
260
|
-
end
|
|
261
|
-
RUBY
|
|
262
|
-
)
|
|
263
|
-
|
|
264
|
-
# Matches the file the installer writes; the generator's `add_tab` step
|
|
265
|
-
# injects `<plural_route> ` tokens after the `MODEL_TABS = %w[` marker.
|
|
266
|
-
write(
|
|
267
|
-
"config/initializers/inline_forms.rb",
|
|
268
|
-
<<~RUBY
|
|
269
|
-
Rails.application.reloader.to_prepare do
|
|
270
|
-
MODEL_TABS = %w[]
|
|
271
|
-
end
|
|
272
|
-
RUBY
|
|
273
|
-
)
|
|
274
|
-
end
|
|
275
|
-
|
|
276
|
-
def run_generator(*args)
|
|
277
|
-
InlineForms::InlineFormsGenerator.start(args, destination_root: @destination_root)
|
|
278
|
-
end
|
|
279
|
-
|
|
280
|
-
def read(relative_path)
|
|
281
|
-
File.read(File.join(@destination_root, relative_path))
|
|
282
|
-
end
|
|
283
|
-
|
|
284
|
-
def read_single_migration_for(table_name)
|
|
285
|
-
migration_files = Dir.glob(File.join(@destination_root, "db/migrate/*_inline_forms_create_#{table_name}.rb"))
|
|
286
|
-
assert_equal(1, migration_files.size, "Expected one migration for #{table_name}, got #{migration_files.inspect}")
|
|
287
|
-
File.read(migration_files.first)
|
|
288
|
-
end
|
|
289
|
-
|
|
290
|
-
def refute_exist(relative_path)
|
|
291
|
-
refute(File.exist?(File.join(@destination_root, relative_path)), "Expected #{relative_path} to not exist")
|
|
292
|
-
end
|
|
293
|
-
|
|
294
|
-
def mkdir_p(relative_path)
|
|
295
|
-
FileUtils.mkdir_p(File.join(@destination_root, relative_path))
|
|
296
|
-
end
|
|
297
|
-
|
|
298
|
-
def write(relative_path, content)
|
|
299
|
-
File.write(File.join(@destination_root, relative_path), content)
|
|
300
|
-
end
|
|
301
|
-
end
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require_relative "../integration_test_helper"
|
|
4
|
-
|
|
5
|
-
# Host apps run a CSP with script-src 'nonce-…' (StProject; the dummy app is
|
|
6
|
-
# configured the same way, report-only). Every inline <script> the gem's
|
|
7
|
-
# layouts render carries the request's nonce, and the nonce is published in
|
|
8
|
-
# a csp-nonce meta tag for the scripts Turbo inserts. The unused
|
|
9
|
-
# inline_forms/_flash partial (an inline jQuery <script>) is gone.
|
|
10
|
-
class CspNonceTest < InlineFormsIntegrationTestCase
|
|
11
|
-
def header_nonce
|
|
12
|
-
policy = response.headers["Content-Security-Policy-Report-Only"].to_s
|
|
13
|
-
policy[/'nonce-([^']+)'/, 1]
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
def inline_scripts(html)
|
|
17
|
-
html.scan(/<script\b[^>]*>/).reject { |tag| tag.include?(" src=") }
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
def assert_inline_scripts_nonced(html, nonce)
|
|
21
|
-
scripts = inline_scripts(html)
|
|
22
|
-
assert_predicate scripts, :any?, "the layout's Turbo module script"
|
|
23
|
-
scripts.each { |tag| assert_includes tag, %(nonce="#{nonce}"), tag }
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
test "the inline_forms layout nonces its inline script and publishes the nonce" do
|
|
27
|
-
get widgets_path
|
|
28
|
-
|
|
29
|
-
assert_response :success
|
|
30
|
-
nonce = header_nonce
|
|
31
|
-
assert nonce, "precondition: the dummy sends a nonce-based CSP"
|
|
32
|
-
assert_inline_scripts_nonced(response.body, nonce)
|
|
33
|
-
assert_match %r{<script type="module" nonce="#{Regexp.escape(nonce)}" data-turbo-eval="false">\s*import \{ Turbo \}}, response.body
|
|
34
|
-
assert_includes response.body, %(<meta name="csp-nonce" content="#{nonce}" />)
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
test "the application layout nonces its inline script too" do
|
|
38
|
-
get widgets_path
|
|
39
|
-
nonce = header_nonce
|
|
40
|
-
html = controller.render_to_string(template: "stats/show", layout: "application")
|
|
41
|
-
|
|
42
|
-
assert_inline_scripts_nonced(html, nonce)
|
|
43
|
-
assert_includes html, %(<meta name="csp-nonce" content="#{nonce}" />)
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
test "the unused inline_forms/_flash partial with its inline script is gone" do
|
|
47
|
-
get widgets_path
|
|
48
|
-
refute controller.lookup_context.exists?("flash", [ "inline_forms" ], true)
|
|
49
|
-
end
|
|
50
|
-
end
|
|
@@ -1,186 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require_relative "../integration_test_helper"
|
|
4
|
-
|
|
5
|
-
# Order of the records table-backed form elements offer
|
|
6
|
-
# (InlineForms::DropdownOrder): the model's inline_forms_dropdown_order, else
|
|
7
|
-
# a dropdown_order column, else inline_forms_list, else database order.
|
|
8
|
-
class DropdownTest < InlineFormsIntegrationTestCase
|
|
9
|
-
teardown do
|
|
10
|
-
[ Phase, Machine, Kind, Part ].each do |klass|
|
|
11
|
-
klass.remove_instance_variable(:@inline_forms_dropdown_order) if klass.instance_variable_defined?(:@inline_forms_dropdown_order)
|
|
12
|
-
end
|
|
13
|
-
# Back to ApplicationRecord's `inline_forms_list -> { all }`.
|
|
14
|
-
[ Kind, Part ].each do |klass|
|
|
15
|
-
klass.singleton_class.remove_method(:inline_forms_list) if klass.singleton_class.method_defined?(:inline_forms_list, false)
|
|
16
|
-
end
|
|
17
|
-
Phase.remove_method(:disabled_for_dropdown?) if Phase.method_defined?(:disabled_for_dropdown?, false)
|
|
18
|
-
Kind.default_scopes = []
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
def view
|
|
22
|
-
get machines_path
|
|
23
|
-
controller.view_context
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
def option_texts(html)
|
|
27
|
-
html.scan(%r{<option(?: [^>]*)?>([^<]*)</option>}).flatten
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
def create_phases
|
|
31
|
-
Phase.create!(name: "admittance", dropdown_order: 30)
|
|
32
|
-
Phase.create!(name: "nieuw")
|
|
33
|
-
Phase.create!(name: "decision", dropdown_order: 20)
|
|
34
|
-
Phase.create!(name: "---", dropdown_order: 0)
|
|
35
|
-
Phase.create!(name: "helprequest", dropdown_order: 10)
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
test "a dropdown_order column orders the dropdown, NULLs last" do
|
|
39
|
-
create_phases
|
|
40
|
-
|
|
41
|
-
html = view.dropdown_edit(Part.create!(name: "Gear"), :phase)
|
|
42
|
-
|
|
43
|
-
assert_equal [ "---", "helprequest", "decision", "admittance", "nieuw" ], option_texts(html)
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
test "the model's declared direction applies to the dropdown_order column" do
|
|
47
|
-
create_phases
|
|
48
|
-
Phase.inline_forms_dropdown_order :dropdown_order, :desc
|
|
49
|
-
|
|
50
|
-
html = view.dropdown_edit(Part.create!(name: "Gear"), :phase)
|
|
51
|
-
|
|
52
|
-
assert_equal [ "admittance", "decision", "helprequest", "---", "nieuw" ], option_texts(html)
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
test "a declared column wins over the dropdown_order column" do
|
|
56
|
-
create_phases
|
|
57
|
-
Phase.inline_forms_dropdown_order :name, :desc
|
|
58
|
-
|
|
59
|
-
html = view.dropdown_edit(Part.create!(name: "Gear"), :phase)
|
|
60
|
-
|
|
61
|
-
assert_equal [ "nieuw", "helprequest", "decision", "admittance", "---" ], option_texts(html)
|
|
62
|
-
end
|
|
63
|
-
|
|
64
|
-
test "without a declaration or column, the list order applies" do
|
|
65
|
-
%w[Zeta Alpha Mu].each { |name| Machine.create!(name: name) } # inline_forms_list: order(:name, :id)
|
|
66
|
-
|
|
67
|
-
html = view.dropdown_edit(Part.create!(name: "Gear"), :machine)
|
|
68
|
-
|
|
69
|
-
assert_equal %w[Alpha Mu Zeta], option_texts(html)
|
|
70
|
-
end
|
|
71
|
-
|
|
72
|
-
test "ties on the declared column break on id" do
|
|
73
|
-
first = Phase.create!(name: "same", dropdown_order: 5)
|
|
74
|
-
second = Phase.create!(name: "same", dropdown_order: 5)
|
|
75
|
-
|
|
76
|
-
assert_equal [ first.id, second.id ], InlineForms::DropdownOrder.apply(Phase.all).map(&:id)
|
|
77
|
-
end
|
|
78
|
-
|
|
79
|
-
test "without anything declared, records come in database order" do
|
|
80
|
-
%w[Zeta Alpha].each { |name| Kind.create!(name: name) } # inline_forms_list: all
|
|
81
|
-
|
|
82
|
-
assert_equal %w[Zeta Alpha], InlineForms::DropdownOrder.apply(Kind.all).map(&:name)
|
|
83
|
-
end
|
|
84
|
-
|
|
85
|
-
test "a filtering inline_forms_list only orders a dropdown, it hides no records" do
|
|
86
|
-
%w[Zeta Hidden Alpha].each { |name| Kind.create!(name: name) }
|
|
87
|
-
Kind.define_singleton_method(:inline_forms_list) { where.not(name: "Hidden").order(:name, :id) }
|
|
88
|
-
|
|
89
|
-
html = view.dropdown_with_other_edit(Widget.create!(name: "W"), :kind)
|
|
90
|
-
|
|
91
|
-
assert_equal %w[Alpha Hidden Zeta], html.scan(/<option value="([^"]*)">/).flatten
|
|
92
|
-
end
|
|
93
|
-
|
|
94
|
-
test "a reorder in inline_forms_list replaces a default_scope order" do
|
|
95
|
-
Kind.send(:default_scope) { order(:name) }
|
|
96
|
-
%w[Alpha Otro Zeta].each { |name| Kind.create!(name: name) }
|
|
97
|
-
Kind.define_singleton_method(:inline_forms_list) { reorder(Arel::Nodes::Descending.new(arel_table[:name].eq("Otro")), :name) }
|
|
98
|
-
|
|
99
|
-
assert_equal %w[Otro Alpha Zeta], InlineForms::DropdownOrder.apply(Kind.all).map(&:name)
|
|
100
|
-
end
|
|
101
|
-
|
|
102
|
-
test "the list order follows a default_scope order, without repeating it" do
|
|
103
|
-
Kind.send(:default_scope) { order(:name) }
|
|
104
|
-
Kind.define_singleton_method(:inline_forms_list) { order(:id) }
|
|
105
|
-
|
|
106
|
-
sql = InlineForms::DropdownOrder.apply(Kind.all).to_sql
|
|
107
|
-
|
|
108
|
-
assert_equal 1, sql.scan('"kinds"."name"').size, sql
|
|
109
|
-
assert_operator sql.index('"kinds"."name"'), :<, sql.index('"kinds"."id"')
|
|
110
|
-
end
|
|
111
|
-
|
|
112
|
-
test "an inline_forms_list order on a joined table hides no records" do
|
|
113
|
-
Part.create!(name: "Axle", phase: Phase.create!(name: "z"))
|
|
114
|
-
Part.create!(name: "Bolt", phase: Phase.create!(name: "a"))
|
|
115
|
-
Part.create!(name: "Free")
|
|
116
|
-
Part.define_singleton_method(:inline_forms_list) { joins(:phase).order("phases.name DESC") }
|
|
117
|
-
|
|
118
|
-
assert_equal %w[Axle Bolt Free], InlineForms::DropdownOrder.apply(Part.all).map(&:name)
|
|
119
|
-
end
|
|
120
|
-
|
|
121
|
-
test "check_list keeps a joining inline_forms_list filter and its order" do
|
|
122
|
-
machine = Machine.create!(name: "Press")
|
|
123
|
-
Part.create!(name: "Axle", phase: Phase.create!(name: "z"))
|
|
124
|
-
Part.create!(name: "Bolt", phase: Phase.create!(name: "a"))
|
|
125
|
-
Part.create!(name: "Hidden")
|
|
126
|
-
Part.define_singleton_method(:inline_forms_list) { joins(:phase).order("phases.name") }
|
|
127
|
-
|
|
128
|
-
html = view.check_list_edit(machine, :parts)
|
|
129
|
-
|
|
130
|
-
assert_equal %w[Bolt Axle], html.scan(%r{<label for=[^>]*>([^<]*)</label>}).flatten.reject(&:empty?)
|
|
131
|
-
end
|
|
132
|
-
|
|
133
|
-
test "disabled_for_dropdown? and the options come from one query" do
|
|
134
|
-
create_phases
|
|
135
|
-
Phase.define_method(:disabled_for_dropdown?) { name == "decision" }
|
|
136
|
-
selects = []
|
|
137
|
-
counter = ->(*, payload) { selects << payload[:sql] if payload[:sql].match?(/\ASELECT .*FROM "phases"/) }
|
|
138
|
-
|
|
139
|
-
view_context, part = view, Part.create!(name: "Gear")
|
|
140
|
-
|
|
141
|
-
html = ActiveSupport::Notifications.subscribed(counter, "sql.active_record") do
|
|
142
|
-
view_context.dropdown_edit(part, :phase)
|
|
143
|
-
end
|
|
144
|
-
|
|
145
|
-
assert_equal 1, selects.size, selects.join("\n")
|
|
146
|
-
assert_match(/<option disabled="disabled" value="\d+">decision</, html)
|
|
147
|
-
assert_equal [ "---", "helprequest", "decision", "admittance", "nieuw" ], option_texts(html)
|
|
148
|
-
end
|
|
149
|
-
|
|
150
|
-
test "dropdown_with_other offers its datalist in the dropdown order" do
|
|
151
|
-
%w[Zeta Alpha Mu].each { |name| Kind.create!(name: name) }
|
|
152
|
-
Kind.inline_forms_dropdown_order :name
|
|
153
|
-
|
|
154
|
-
html = view.dropdown_with_other_edit(Widget.create!(name: "W"), :kind)
|
|
155
|
-
|
|
156
|
-
assert_equal %w[Alpha Mu Zeta], html.scan(/<option value="([^"]*)">/).flatten
|
|
157
|
-
end
|
|
158
|
-
|
|
159
|
-
test "check_list lists its records in the dropdown order" do
|
|
160
|
-
machine = Machine.create!(name: "Press")
|
|
161
|
-
%w[Bolt Nut Axle].each { |name| Part.create!(name: name) }
|
|
162
|
-
Part.inline_forms_dropdown_order :name, :desc
|
|
163
|
-
|
|
164
|
-
html = view.check_list_edit(machine, :parts)
|
|
165
|
-
|
|
166
|
-
assert_equal %w[Nut Bolt Axle], html.scan(%r{<label for=[^>]*>([^<]*)</label>}).flatten.reject(&:empty?)
|
|
167
|
-
end
|
|
168
|
-
|
|
169
|
-
test "check_list keeps the inline_forms_list filter under a declared order" do
|
|
170
|
-
machine = Machine.create!(name: "Press")
|
|
171
|
-
%w[Bolt Hidden Nut Axle].each { |name| Part.create!(name: name) }
|
|
172
|
-
Part.define_singleton_method(:inline_forms_list) { where.not(name: "Hidden").order(:name) }
|
|
173
|
-
Part.inline_forms_dropdown_order :name, :desc
|
|
174
|
-
|
|
175
|
-
html = view.check_list_edit(machine, :parts)
|
|
176
|
-
|
|
177
|
-
assert_equal %w[Nut Bolt Axle], html.scan(%r{<label for=[^>]*>([^<]*)</label>}).flatten.reject(&:empty?)
|
|
178
|
-
end
|
|
179
|
-
|
|
180
|
-
test "an unknown direction or column is refused" do
|
|
181
|
-
assert_raises(ArgumentError) { Phase.inline_forms_dropdown_order :name, :up }
|
|
182
|
-
|
|
183
|
-
Phase.inline_forms_dropdown_order :position
|
|
184
|
-
assert_raises(ArgumentError) { InlineForms::DropdownOrder.apply(Phase.all).to_a }
|
|
185
|
-
end
|
|
186
|
-
end
|
|
@@ -1,131 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require_relative "../integration_test_helper"
|
|
4
|
-
|
|
5
|
-
# Server-side guard on the single-field actions (edit / update / show with an
|
|
6
|
-
# attribute). The UI only hides the edit link for an attribute the user may
|
|
7
|
-
# not update; before 8.1.48 a hand-made request still went through, because
|
|
8
|
-
# load_and_authorize_resource authorizes the record only (CanCanCan passes
|
|
9
|
-
# attribute-scoped rules when no attribute is given) and `form_element` was
|
|
10
|
-
# dispatched as `send("#{form_element}_update")` unchecked.
|
|
11
|
-
class FieldAuthorizationTest < InlineFormsIntegrationTestCase
|
|
12
|
-
setup do
|
|
13
|
-
@widget = Widget.create!(name: "Alpha", accent: "#112233")
|
|
14
|
-
@frame = "widget_#{@widget.id}_accent"
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
def patch_field(attribute, form_element, params = {})
|
|
18
|
-
patch widget_path(@widget, attribute: attribute, form_element: form_element,
|
|
19
|
-
update: "widget_#{@widget.id}_#{attribute}"),
|
|
20
|
-
params: params, headers: frame_headers("widget_#{@widget.id}_#{attribute}")
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
test "the dummy runs with CanCanCan enabled" do
|
|
24
|
-
assert InlineFormsController.cancan_enabled?
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
test "crafted PATCH on an attribute-scoped `cannot :update` is refused" do
|
|
28
|
-
Ability.restrictions = -> { cannot :update, Widget, [ :accent ] }
|
|
29
|
-
|
|
30
|
-
patch_field "accent", "color_field", accent: "#ff0000"
|
|
31
|
-
|
|
32
|
-
assert_response :forbidden
|
|
33
|
-
assert_equal "#112233", @widget.reload.accent
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
test "other attributes of the same record stay updatable" do
|
|
37
|
-
Ability.restrictions = -> { cannot :update, Widget, [ :accent ] }
|
|
38
|
-
|
|
39
|
-
patch_field "name", "text_field", name: "Renamed"
|
|
40
|
-
|
|
41
|
-
assert_response :success
|
|
42
|
-
assert_equal "Renamed", @widget.reload.name
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
test "an attribute-scoped `can :update` only covers the listed attributes" do
|
|
46
|
-
Ability.restrictions = lambda do
|
|
47
|
-
cannot :update, Widget
|
|
48
|
-
can :update, Widget, [ :name ]
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
patch_field "accent", "color_field", accent: "#ff0000"
|
|
52
|
-
assert_response :forbidden
|
|
53
|
-
assert_equal "#112233", @widget.reload.accent
|
|
54
|
-
|
|
55
|
-
patch_field "name", "text_field", name: "Renamed"
|
|
56
|
-
assert_response :success
|
|
57
|
-
assert_equal "Renamed", @widget.reload.name
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
test "edit of a `cannot :update` attribute is refused" do
|
|
61
|
-
Ability.restrictions = -> { cannot :update, Widget, [ :accent ] }
|
|
62
|
-
|
|
63
|
-
get edit_widget_path(@widget, attribute: "accent", form_element: "color_field", update: @frame),
|
|
64
|
-
headers: frame_headers(@frame)
|
|
65
|
-
|
|
66
|
-
assert_response :forbidden
|
|
67
|
-
end
|
|
68
|
-
|
|
69
|
-
test "single-field show of a `cannot :read` attribute is refused" do
|
|
70
|
-
Ability.restrictions = -> { cannot :read, Widget, [ :accent ] }
|
|
71
|
-
|
|
72
|
-
get widget_path(@widget, attribute: "accent", form_element: "color_field", update: @frame),
|
|
73
|
-
headers: frame_headers(@frame)
|
|
74
|
-
|
|
75
|
-
assert_response :forbidden
|
|
76
|
-
end
|
|
77
|
-
|
|
78
|
-
test "a form_element that does not match the attribute's row is rejected" do
|
|
79
|
-
patch_field "accent", "text_field", accent: "not a color"
|
|
80
|
-
|
|
81
|
-
assert_response :bad_request
|
|
82
|
-
assert_equal "#112233", @widget.reload.accent
|
|
83
|
-
end
|
|
84
|
-
|
|
85
|
-
test "an unknown form_element is rejected before it is dispatched" do
|
|
86
|
-
patch_field "name", "nonexistent", name: "Renamed"
|
|
87
|
-
|
|
88
|
-
assert_response :bad_request
|
|
89
|
-
assert_equal "Alpha", @widget.reload.name
|
|
90
|
-
end
|
|
91
|
-
|
|
92
|
-
test "an attribute outside the attribute list is rejected" do
|
|
93
|
-
patch_field "kind_id", "text_field", kind_id: "42"
|
|
94
|
-
|
|
95
|
-
assert_response :bad_request
|
|
96
|
-
assert_nil @widget.reload.kind_id
|
|
97
|
-
end
|
|
98
|
-
|
|
99
|
-
test "missing attribute or form_element is rejected" do
|
|
100
|
-
patch widget_path(@widget, update: @frame), params: { name: "x" }, headers: frame_headers(@frame)
|
|
101
|
-
assert_response :bad_request
|
|
102
|
-
|
|
103
|
-
get edit_widget_path(@widget, attribute: "name", update: @frame), headers: frame_headers(@frame)
|
|
104
|
-
assert_response :bad_request
|
|
105
|
-
end
|
|
106
|
-
|
|
107
|
-
test "show cannot be used to send an arbitrary method to the record" do
|
|
108
|
-
get widget_path(@widget, attribute: "destroy", form_element: "has_one", update: @frame),
|
|
109
|
-
headers: frame_headers(@frame)
|
|
110
|
-
|
|
111
|
-
assert_response :bad_request
|
|
112
|
-
assert Widget.exists?(@widget.id)
|
|
113
|
-
end
|
|
114
|
-
|
|
115
|
-
test "a delegating element's link name (plain_text_area -> plain_text) is accepted" do
|
|
116
|
-
patch_field "notes", "plain_text", notes: "Long enough notes"
|
|
117
|
-
|
|
118
|
-
assert_response :success
|
|
119
|
-
assert_equal "Long enough notes", @widget.reload.notes
|
|
120
|
-
end
|
|
121
|
-
|
|
122
|
-
test "attribute_list_row_for honours the declared element and its delegate only" do
|
|
123
|
-
list = Widget.new.inline_forms_attribute_list
|
|
124
|
-
|
|
125
|
-
assert_equal [ :notes, :plain_text_area ], InlineForms.attribute_list_row_for(list, "notes", "plain_text_area")
|
|
126
|
-
assert_equal [ :notes, :plain_text_area ], InlineForms.attribute_list_row_for(list, "notes", "plain_text")
|
|
127
|
-
assert_nil InlineForms.attribute_list_row_for(list, "notes", "rich_text")
|
|
128
|
-
assert_nil InlineForms.attribute_list_row_for(list, "name", nil)
|
|
129
|
-
assert_nil InlineForms.attribute_list_row_for(list, nil, "text_field")
|
|
130
|
-
end
|
|
131
|
-
end
|