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,203 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
# Boots the test/dummy host app for the engine's integration tests. Fast path
|
|
4
|
-
# (seconds) next to the full release gate (build gems -> inline_forms create
|
|
5
|
-
# MyApp --example -> rails test); catches controller/view/Turbo regressions
|
|
6
|
-
# without an install cycle. See stuff/prompt/test-the-example-app.md for the
|
|
7
|
-
# release gate, which remains authoritative.
|
|
8
|
-
ENV["RAILS_ENV"] = "test"
|
|
9
|
-
|
|
10
|
-
require_relative "dummy/config/environment"
|
|
11
|
-
require "rails/test_help"
|
|
12
|
-
require "minitest/autorun"
|
|
13
|
-
|
|
14
|
-
# In-memory SQLite: define the schema on every boot (maintain_test_schema is
|
|
15
|
-
# off; there are no migration files to run).
|
|
16
|
-
ActiveRecord::Schema.verbose = false
|
|
17
|
-
ActiveRecord::Schema.define do
|
|
18
|
-
create_table :widgets, force: true do |t|
|
|
19
|
-
t.string :name
|
|
20
|
-
t.text :notes
|
|
21
|
-
t.date :released_on
|
|
22
|
-
t.time :meeting_at
|
|
23
|
-
t.date :start_month
|
|
24
|
-
t.integer :priority
|
|
25
|
-
t.boolean :active
|
|
26
|
-
t.integer :kind_id
|
|
27
|
-
t.string :kind_other
|
|
28
|
-
t.integer :rating
|
|
29
|
-
t.string :manual
|
|
30
|
-
t.string :accent
|
|
31
|
-
t.timestamps
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
create_table :kinds, force: true do |t|
|
|
35
|
-
t.string :name
|
|
36
|
-
t.timestamps
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
# Machine has_many :parts with an :associated panel (open-after-create).
|
|
40
|
-
create_table :machines, force: true do |t|
|
|
41
|
-
t.string :name
|
|
42
|
-
t.timestamps
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
# Lookup with a dropdown_order column (InlineForms::DropdownOrder);
|
|
46
|
-
# Part belongs_to it for the dropdown tests.
|
|
47
|
-
create_table :phases, force: true do |t|
|
|
48
|
-
t.string :name
|
|
49
|
-
t.integer :dropdown_order
|
|
50
|
-
t.timestamps
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
create_table :parts, force: true do |t|
|
|
54
|
-
t.string :name
|
|
55
|
-
t.integer :machine_id
|
|
56
|
-
t.integer :phase_id
|
|
57
|
-
t.timestamps
|
|
58
|
-
end
|
|
59
|
-
add_index :parts, :machine_id
|
|
60
|
-
|
|
61
|
-
# DailyReport: a not_accessible_through_html? child of Machine (shaped like
|
|
62
|
-
# StProject's Dagrapportage). See test/integration/html_refusal_test.rb.
|
|
63
|
-
create_table :daily_reports, force: true do |t|
|
|
64
|
-
t.string :name
|
|
65
|
-
t.integer :machine_id
|
|
66
|
-
t.timestamps
|
|
67
|
-
end
|
|
68
|
-
add_index :daily_reports, :machine_id
|
|
69
|
-
|
|
70
|
-
# Gizmo intentionally has NO `pending_note` column: its attribute_list
|
|
71
|
-
# references one, modeling the inline_forms_addto pre-migrate window that
|
|
72
|
-
# InlineForms.attribute_pending_migration? gates. See
|
|
73
|
-
# test/integration/pending_migration_gate_test.rb.
|
|
74
|
-
create_table :gizmos, force: true do |t|
|
|
75
|
-
t.string :name
|
|
76
|
-
t.timestamps
|
|
77
|
-
end
|
|
78
|
-
|
|
79
|
-
# Dossier: `data` is in `has_paper_trail skip:` (file bytes, as in
|
|
80
|
-
# StProject's Client/Attachment); see revert_skipped_columns_test.rb.
|
|
81
|
-
create_table :dossiers, force: true do |t|
|
|
82
|
-
t.string :name
|
|
83
|
-
t.string :data_filename
|
|
84
|
-
t.binary :data
|
|
85
|
-
t.timestamps
|
|
86
|
-
end
|
|
87
|
-
|
|
88
|
-
# Document: declared file slots (InlineForms::StoredFiles); see
|
|
89
|
-
# file_slots_test.rb. The trash tables mirror the inline_forms:file_trash
|
|
90
|
-
# generator's migration.
|
|
91
|
-
create_table :documents, force: true do |t|
|
|
92
|
-
t.string :title
|
|
93
|
-
t.string :filename
|
|
94
|
-
t.binary :data
|
|
95
|
-
t.string :content_type
|
|
96
|
-
t.string :plan_filename
|
|
97
|
-
t.binary :plan_data
|
|
98
|
-
t.string :plan_content_type
|
|
99
|
-
t.timestamps
|
|
100
|
-
end
|
|
101
|
-
|
|
102
|
-
create_table :inline_forms_trashed_files, force: true do |t|
|
|
103
|
-
t.string :record_type, null: false
|
|
104
|
-
t.bigint :record_id, null: false
|
|
105
|
-
t.string :attribute_name, null: false
|
|
106
|
-
t.string :filename
|
|
107
|
-
t.string :content_type
|
|
108
|
-
t.bigint :byte_size
|
|
109
|
-
t.string :checksum, limit: 64
|
|
110
|
-
t.binary :data
|
|
111
|
-
t.string :reason, null: false
|
|
112
|
-
t.boolean :redacted, null: false, default: false
|
|
113
|
-
t.bigint :trashed_by_id
|
|
114
|
-
t.datetime :trashed_at, null: false
|
|
115
|
-
t.bigint :restored_by_id
|
|
116
|
-
t.datetime :restored_at
|
|
117
|
-
t.bigint :purged_by_id
|
|
118
|
-
t.datetime :purged_at
|
|
119
|
-
t.datetime :purge_after
|
|
120
|
-
t.timestamps
|
|
121
|
-
end
|
|
122
|
-
add_index :inline_forms_trashed_files, [ :record_type, :record_id, :attribute_name ]
|
|
123
|
-
add_index :inline_forms_trashed_files, [ :purged_at, :restored_at, :purge_after ]
|
|
124
|
-
|
|
125
|
-
create_table :inline_forms_file_trash_sweeps, force: true do |t|
|
|
126
|
-
t.datetime :ran_at, null: false
|
|
127
|
-
t.integer :purged_count, null: false, default: 0
|
|
128
|
-
t.text :error
|
|
129
|
-
t.timestamps
|
|
130
|
-
end
|
|
131
|
-
|
|
132
|
-
# Schema-GUI batch pipeline (inline_forms_schema_edit). Mirrors the gem's
|
|
133
|
-
# install-generator migration.
|
|
134
|
-
create_table :inline_forms_schema_batches, force: true do |t|
|
|
135
|
-
t.string :status, null: false, default: "draft"
|
|
136
|
-
t.string :requested_by
|
|
137
|
-
t.datetime :submitted_at
|
|
138
|
-
t.datetime :window_at
|
|
139
|
-
t.datetime :applied_at
|
|
140
|
-
t.string :git_sha
|
|
141
|
-
t.string :content_digest
|
|
142
|
-
t.text :error
|
|
143
|
-
t.timestamps
|
|
144
|
-
end
|
|
145
|
-
add_index :inline_forms_schema_batches, :status
|
|
146
|
-
|
|
147
|
-
create_table :inline_forms_schema_intents, force: true do |t|
|
|
148
|
-
t.references :batch, null: false, index: true
|
|
149
|
-
t.string :target_model, null: false
|
|
150
|
-
t.string :attr_name, null: false
|
|
151
|
-
t.string :form_element, null: false
|
|
152
|
-
t.string :after_attr
|
|
153
|
-
t.string :before_attr
|
|
154
|
-
t.string :label
|
|
155
|
-
t.string :locale
|
|
156
|
-
t.integer :position
|
|
157
|
-
t.string :migration_version
|
|
158
|
-
t.timestamps
|
|
159
|
-
end
|
|
160
|
-
|
|
161
|
-
# PaperTrail (paper_trail 17.x shape).
|
|
162
|
-
create_table :versions, force: true do |t|
|
|
163
|
-
t.string :item_type, null: false
|
|
164
|
-
t.bigint :item_id, null: false
|
|
165
|
-
t.string :event, null: false
|
|
166
|
-
t.string :whodunnit
|
|
167
|
-
t.text :object, limit: 1_073_741_823
|
|
168
|
-
t.text :object_changes, limit: 1_073_741_823
|
|
169
|
-
t.datetime :created_at
|
|
170
|
-
end
|
|
171
|
-
add_index :versions, [ :item_type, :item_id ]
|
|
172
|
-
end
|
|
173
|
-
|
|
174
|
-
class InlineFormsIntegrationTestCase < ActionDispatch::IntegrationTest
|
|
175
|
-
# The inline UI drives every request through a <turbo-frame>; the frame
|
|
176
|
-
# layout (turbo_rails/frame) also spares the dummy the full chrome (header
|
|
177
|
-
# needs current_user, assets, ...).
|
|
178
|
-
def frame_headers(frame_id)
|
|
179
|
-
{ "Turbo-Frame" => frame_id, "Accept" => "text/html" }
|
|
180
|
-
end
|
|
181
|
-
|
|
182
|
-
setup do
|
|
183
|
-
Ability.restrictions = nil
|
|
184
|
-
ApplicationController.dummy_user_superadmin = true
|
|
185
|
-
Widget.delete_all
|
|
186
|
-
Kind.delete_all
|
|
187
|
-
Part.delete_all
|
|
188
|
-
DailyReport.delete_all
|
|
189
|
-
Machine.delete_all
|
|
190
|
-
Gizmo.delete_all
|
|
191
|
-
Dossier.delete_all
|
|
192
|
-
Document.delete_all
|
|
193
|
-
Document.require_filename = false
|
|
194
|
-
InlineForms::TrashedFile.delete_all
|
|
195
|
-
InlineForms::FileTrashSweep.delete_all
|
|
196
|
-
InlineForms.file_trash_retention = 30.days
|
|
197
|
-
InlineForms.file_trash_redact_on_purge = false
|
|
198
|
-
InlineForms.max_file_size = nil
|
|
199
|
-
PaperTrail::Version.delete_all
|
|
200
|
-
InlineForms::SchemaIntentRecord.delete_all
|
|
201
|
-
InlineForms::SchemaBatch.delete_all
|
|
202
|
-
end
|
|
203
|
-
end
|
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require_relative "test_helper"
|
|
4
|
-
require "rails"
|
|
5
|
-
require "inline_forms"
|
|
6
|
-
|
|
7
|
-
class PlainTextConfigurationTest < Minitest::Test
|
|
8
|
-
class PlainTextModelWithColumn
|
|
9
|
-
def self.table_exists?
|
|
10
|
-
true
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
def self.column_names
|
|
14
|
-
%w[id description]
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
def self.table_name
|
|
18
|
-
"plain_text_model_with_columns"
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
def inline_forms_attribute_list
|
|
22
|
-
[
|
|
23
|
-
[ :description, :plain_text ]
|
|
24
|
-
]
|
|
25
|
-
end
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
class PlainTextModelWithoutColumn
|
|
29
|
-
def self.table_exists?
|
|
30
|
-
true
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
def self.column_names
|
|
34
|
-
%w[id]
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
def self.table_name
|
|
38
|
-
"plain_text_model_without_columns"
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
def inline_forms_attribute_list
|
|
42
|
-
[
|
|
43
|
-
[ :description, :plain_text ]
|
|
44
|
-
]
|
|
45
|
-
end
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
class RichTextModelWithoutColumn
|
|
49
|
-
def self.table_exists?
|
|
50
|
-
true
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
def self.column_names
|
|
54
|
-
%w[id]
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
def inline_forms_attribute_list
|
|
58
|
-
[
|
|
59
|
-
[ :description, :rich_text ]
|
|
60
|
-
]
|
|
61
|
-
end
|
|
62
|
-
end
|
|
63
|
-
|
|
64
|
-
def test_plain_text_column_check_passes_when_column_exists
|
|
65
|
-
model = PlainTextModelWithColumn.new
|
|
66
|
-
InlineForms.assert_plain_text_column!(object: model, attribute: :description, form_element: :plain_text)
|
|
67
|
-
end
|
|
68
|
-
|
|
69
|
-
def test_plain_text_column_check_raises_when_column_missing
|
|
70
|
-
model = PlainTextModelWithoutColumn.new
|
|
71
|
-
error = assert_raises(InlineForms::PlainTextColumnMissingError) do
|
|
72
|
-
InlineForms.assert_plain_text_column!(object: model, attribute: :description, form_element: :plain_text)
|
|
73
|
-
end
|
|
74
|
-
assert_includes(error.message, "has no DB column")
|
|
75
|
-
end
|
|
76
|
-
|
|
77
|
-
def test_configuration_check_raises_for_plain_text_without_column
|
|
78
|
-
assert_raises(InlineForms::PlainTextColumnMissingError) do
|
|
79
|
-
InlineForms.validate_plain_text_configuration_for!(PlainTextModelWithoutColumn)
|
|
80
|
-
end
|
|
81
|
-
end
|
|
82
|
-
|
|
83
|
-
def test_configuration_check_allows_rich_text_without_column
|
|
84
|
-
InlineForms.validate_plain_text_configuration_for!(RichTextModelWithoutColumn)
|
|
85
|
-
end
|
|
86
|
-
|
|
87
|
-
def test_text_area_alias_is_not_treated_as_plain_text_column_requirement
|
|
88
|
-
refute InlineForms.plain_text_form_element?(:text_area)
|
|
89
|
-
end
|
|
90
|
-
end
|
data/test/schema_apply_test.rb
DELETED
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require_relative "test_helper"
|
|
4
|
-
require "tmpdir"
|
|
5
|
-
require "fileutils"
|
|
6
|
-
|
|
7
|
-
class SchemaApplyTest < Minitest::Test
|
|
8
|
-
def intent(**overrides)
|
|
9
|
-
InlineForms::SchemaIntent.new(
|
|
10
|
-
**{ model_name: "Apartment", attribute: :internal_note, form_element: :text_field }.merge(overrides)
|
|
11
|
-
)
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
def test_generator_command
|
|
15
|
-
apply = InlineForms::SchemaApply.new(intent(after: :name))
|
|
16
|
-
assert_equal(
|
|
17
|
-
%w[bundle exec rails g inline_forms_addto Apartment internal_note:text_field --after=name],
|
|
18
|
-
apply.generator_command
|
|
19
|
-
)
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
def test_commands_are_ordered_generate_then_migrate
|
|
23
|
-
apply = InlineForms::SchemaApply.new(intent)
|
|
24
|
-
assert_equal %i[generate migrate], apply.commands.keys
|
|
25
|
-
assert_equal %w[bundle exec rails db:migrate], apply.commands[:migrate]
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
def test_preview_plan_is_human_readable
|
|
29
|
-
plan = InlineForms::SchemaApply.new(intent).preview_plan
|
|
30
|
-
assert_equal 2, plan.size
|
|
31
|
-
assert_match(/\Agenerate: bundle exec rails g inline_forms_addto Apartment/, plan.first)
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
def test_run_bang_executes_in_order_with_injected_runner
|
|
35
|
-
calls = []
|
|
36
|
-
runner = ->(cmd) { calls << cmd; true }
|
|
37
|
-
result = InlineForms::SchemaApply.new(intent, runner: runner).run!
|
|
38
|
-
assert_nil result, "expected success (nil)"
|
|
39
|
-
assert_equal 2, calls.size
|
|
40
|
-
assert_equal %w[bundle exec rails g inline_forms_addto Apartment internal_note:text_field], calls.first
|
|
41
|
-
assert_equal %w[bundle exec rails db:migrate], calls.last
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
def test_generate_returns_only_a_newly_created_migration
|
|
45
|
-
Dir.mktmpdir("schema_apply_generate") do |root|
|
|
46
|
-
migrate_dir = File.join(root, "db", "migrate")
|
|
47
|
-
FileUtils.mkdir_p(migrate_dir)
|
|
48
|
-
# A pre-existing addto migration must NOT be reported when this run
|
|
49
|
-
# creates nothing (the :header case).
|
|
50
|
-
FileUtils.touch(File.join(migrate_dir, "20200101000000_inline_forms_add_to_widgets_old.rb"))
|
|
51
|
-
|
|
52
|
-
header_executor = ->(_args, _root) { } # header: no migration created
|
|
53
|
-
result = InlineForms::SchemaApply.new(intent(form_element: :header))
|
|
54
|
-
.generate!(destination_root: root, executor: header_executor)
|
|
55
|
-
assert_nil result, "header apply must report no migration, not a stale one"
|
|
56
|
-
|
|
57
|
-
# A run that creates a migration reports that one.
|
|
58
|
-
creating = lambda do |_args, _root|
|
|
59
|
-
FileUtils.touch(File.join(migrate_dir, "20260101000000_inline_forms_add_to_widgets_note.rb"))
|
|
60
|
-
end
|
|
61
|
-
created = InlineForms::SchemaApply.new(intent).generate!(destination_root: root, executor: creating)
|
|
62
|
-
assert_equal "20260101000000_inline_forms_add_to_widgets_note.rb", File.basename(created)
|
|
63
|
-
end
|
|
64
|
-
end
|
|
65
|
-
|
|
66
|
-
def test_run_bang_stops_at_first_failure
|
|
67
|
-
calls = []
|
|
68
|
-
runner = ->(cmd) { calls << cmd; false } # generate fails
|
|
69
|
-
result = InlineForms::SchemaApply.new(intent, runner: runner).run!
|
|
70
|
-
assert_equal :generate, result
|
|
71
|
-
assert_equal 1, calls.size, "must not run migrate after generate failed"
|
|
72
|
-
end
|
|
73
|
-
end
|
data/test/schema_intent_test.rb
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require_relative "test_helper"
|
|
4
|
-
|
|
5
|
-
class SchemaIntentTest < Minitest::Test
|
|
6
|
-
def intent(**overrides)
|
|
7
|
-
InlineForms::SchemaIntent.new(
|
|
8
|
-
**{ model_name: "Apartment", attribute: :internal_note, form_element: :text_field }.merge(overrides)
|
|
9
|
-
)
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
def test_normalizes_types
|
|
13
|
-
i = intent(attribute: "note", form_element: "text_field", after: "name")
|
|
14
|
-
assert_equal "Apartment", i.model_name
|
|
15
|
-
assert_equal :note, i.attribute
|
|
16
|
-
assert_equal :text_field, i.form_element
|
|
17
|
-
assert_equal :name, i.after
|
|
18
|
-
assert_equal :draft, i.status
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
def test_column_token
|
|
22
|
-
assert_equal "internal_note:text_field", intent.column_token
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
def test_generator_args_plain
|
|
26
|
-
assert_equal [ "Apartment", "internal_note:text_field" ], intent.generator_args
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
def test_generator_args_with_after
|
|
30
|
-
assert_equal [ "Apartment", "internal_note:text_field", "--after=name" ],
|
|
31
|
-
intent(after: :name).generator_args
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
def test_generator_args_with_before
|
|
35
|
-
assert_equal [ "Apartment", "internal_note:text_field", "--before=created_at" ],
|
|
36
|
-
intent(before: :created_at).generator_args
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
def test_status_validation
|
|
40
|
-
assert_raises(ArgumentError) { intent(status: :bogus) }
|
|
41
|
-
i = intent
|
|
42
|
-
i.status = :applied
|
|
43
|
-
assert_equal :applied, i.status
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
def test_to_h_round_trips_core_fields
|
|
47
|
-
h = intent(after: :name, values: { 1 => "a" }).to_h
|
|
48
|
-
assert_equal "Apartment", h[:model_name]
|
|
49
|
-
assert_equal :internal_note, h[:attribute]
|
|
50
|
-
assert_equal({ 1 => "a" }, h[:values])
|
|
51
|
-
assert_equal :name, h[:after]
|
|
52
|
-
end
|
|
53
|
-
end
|
data/test/schema_label_test.rb
DELETED
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require_relative "test_helper"
|
|
4
|
-
require "tmpdir"
|
|
5
|
-
require "fileutils"
|
|
6
|
-
|
|
7
|
-
class SchemaLabelTest < Minitest::Test
|
|
8
|
-
# Minimal stand-in for an AR model name (avoids booting ActiveRecord).
|
|
9
|
-
ModelName = Struct.new(:i18n_key)
|
|
10
|
-
class FakeModel
|
|
11
|
-
def self.model_name = ModelName.new(:apartment)
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
def setup
|
|
15
|
-
@root = Dir.mktmpdir("schema_label_test")
|
|
16
|
-
FileUtils.mkdir_p(File.join(@root, "config", "locales"))
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
def teardown
|
|
20
|
-
FileUtils.remove_entry(@root) if @root && Dir.exist?(@root)
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
def read_yaml(path)
|
|
24
|
-
YAML.safe_load(File.read(path))
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
def test_writes_label_under_the_human_attribute_name_key
|
|
28
|
-
path = InlineForms::SchemaLabel.write(
|
|
29
|
-
destination_root: @root, model_class: FakeModel,
|
|
30
|
-
attribute: :internal_note, label: "Internal note", locale: :en
|
|
31
|
-
)
|
|
32
|
-
assert_equal File.join(@root, "config/locales/inline_forms_labels.en.yml"), path
|
|
33
|
-
doc = read_yaml(path)
|
|
34
|
-
assert_equal "Internal note",
|
|
35
|
-
doc.dig("en", "activerecord", "attributes", "apartment", "internal_note")
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
def test_merges_without_clobbering_existing_labels
|
|
39
|
-
InlineForms::SchemaLabel.write(destination_root: @root, model_class: FakeModel,
|
|
40
|
-
attribute: :first_field, label: "First", locale: :en)
|
|
41
|
-
InlineForms::SchemaLabel.write(destination_root: @root, model_class: FakeModel,
|
|
42
|
-
attribute: :second_field, label: "Second", locale: :en)
|
|
43
|
-
|
|
44
|
-
attrs = read_yaml(InlineForms::SchemaLabel.file_path(@root, :en))
|
|
45
|
-
.dig("en", "activerecord", "attributes", "apartment")
|
|
46
|
-
assert_equal "First", attrs["first_field"]
|
|
47
|
-
assert_equal "Second", attrs["second_field"]
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
def test_separate_file_per_locale
|
|
51
|
-
InlineForms::SchemaLabel.write(destination_root: @root, model_class: FakeModel,
|
|
52
|
-
attribute: :note, label: "Note", locale: :en)
|
|
53
|
-
InlineForms::SchemaLabel.write(destination_root: @root, model_class: FakeModel,
|
|
54
|
-
attribute: :note, label: "Notitie", locale: :nl)
|
|
55
|
-
|
|
56
|
-
assert_equal "Note", read_yaml(InlineForms::SchemaLabel.file_path(@root, :en))
|
|
57
|
-
.dig("en", "activerecord", "attributes", "apartment", "note")
|
|
58
|
-
assert_equal "Notitie", read_yaml(InlineForms::SchemaLabel.file_path(@root, :nl))
|
|
59
|
-
.dig("nl", "activerecord", "attributes", "apartment", "note")
|
|
60
|
-
end
|
|
61
|
-
end
|
data/test/tabs_test.rb
DELETED
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require "test_helper"
|
|
4
|
-
require "action_view"
|
|
5
|
-
require "inline_forms/tabs"
|
|
6
|
-
require "inline_forms/turbo_tabs_builder"
|
|
7
|
-
|
|
8
|
-
# Unit coverage for the vendored tabs support (InlineForms::Tabs, 8.1.23 —
|
|
9
|
-
# replaces the tabs_on_rails gem). Uses a minimal view-context double; the
|
|
10
|
-
# rendered-through-Rails path is covered by the example app's owner tabs
|
|
11
|
-
# integration test.
|
|
12
|
-
class TabsTest < Minitest::Test
|
|
13
|
-
# Quacks like the slice of ActionView the builders touch, with a fixed
|
|
14
|
-
# current tab.
|
|
15
|
-
class FakeContext
|
|
16
|
-
include ActionView::Helpers::TagHelper
|
|
17
|
-
include ActionView::Helpers::UrlHelper
|
|
18
|
-
include ActionView::Helpers::CaptureHelper
|
|
19
|
-
|
|
20
|
-
attr_accessor :output_buffer
|
|
21
|
-
|
|
22
|
-
def initialize(current_tab_name)
|
|
23
|
-
@current_tab_name = current_tab_name
|
|
24
|
-
@output_buffer = ActionView::OutputBuffer.new
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
def current_tab(_namespace = nil)
|
|
28
|
-
@current_tab_name
|
|
29
|
-
end
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
def test_default_builder_marks_active_tab_with_current_class_and_span
|
|
33
|
-
builder = InlineForms::Tabs::TabsBuilder.new(FakeContext.new(:home))
|
|
34
|
-
|
|
35
|
-
active = builder.tab_for(:home, "Home", "/home")
|
|
36
|
-
other = builder.tab_for(:away, "Away", "/away")
|
|
37
|
-
|
|
38
|
-
assert_includes active, %(class="current")
|
|
39
|
-
assert_includes active, "<span>Home</span>"
|
|
40
|
-
refute_includes active, "<a"
|
|
41
|
-
assert_includes other, %(<a href="/away">Away</a>)
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
def test_default_builder_honors_custom_active_class
|
|
45
|
-
builder = InlineForms::Tabs::TabsBuilder.new(FakeContext.new(:home), active_class: "is-active")
|
|
46
|
-
assert_includes builder.tab_for(:home, "Home", "/home"), %(class="is-active")
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
def test_turbo_builder_threads_link_options_and_aria_state
|
|
50
|
-
builder = InlineForms::TurboTabsBuilder.new(FakeContext.new(:naw), active_class: "is-active")
|
|
51
|
-
|
|
52
|
-
active = builder.tab_for(:naw, "NAW", "/owners/1?tab=naw",
|
|
53
|
-
class: "tabs-title",
|
|
54
|
-
link_options: { data: { turbo_frame: "owner_1" } })
|
|
55
|
-
other = builder.tab_for(:apartments, "Apartments", "/owners/1?tab=apartments",
|
|
56
|
-
class: "tabs-title",
|
|
57
|
-
link_options: { data: { turbo_frame: "owner_1" } })
|
|
58
|
-
|
|
59
|
-
# Active: li gets both classes, anchor has no href, aria advertises state.
|
|
60
|
-
assert_includes active, %(class="tabs-title is-active")
|
|
61
|
-
assert_includes active, %(aria-current="page")
|
|
62
|
-
assert_includes active, %(aria-selected="true")
|
|
63
|
-
refute_includes active, "href="
|
|
64
|
-
|
|
65
|
-
# Inactive: real link with the turbo-frame data attribute threaded through.
|
|
66
|
-
assert_includes other, %(href="/owners/1?tab=apartments")
|
|
67
|
-
assert_includes other, %(data-turbo-frame="owner_1")
|
|
68
|
-
assert_includes other, %(aria-selected="false")
|
|
69
|
-
end
|
|
70
|
-
|
|
71
|
-
def test_controller_mixin_set_and_query_tabs
|
|
72
|
-
# Exercise the instance methods directly through a bare object.
|
|
73
|
-
holder = Object.new
|
|
74
|
-
holder.extend(instance_methods_module)
|
|
75
|
-
|
|
76
|
-
holder.send(:set_tab, :owner)
|
|
77
|
-
holder.send(:set_tab, :naw, :subtabs)
|
|
78
|
-
|
|
79
|
-
assert_equal :owner, holder.send(:current_tab)
|
|
80
|
-
assert_equal :naw, holder.send(:current_tab, :subtabs)
|
|
81
|
-
assert holder.send(:current_tab?, :owner)
|
|
82
|
-
assert holder.send(:current_tab?, "owner")
|
|
83
|
-
refute holder.send(:current_tab?, :other)
|
|
84
|
-
assert holder.send(:current_tab?, :naw, :subtabs)
|
|
85
|
-
end
|
|
86
|
-
|
|
87
|
-
private
|
|
88
|
-
|
|
89
|
-
# The Concern's `included` hook calls before_action/helper machinery that a
|
|
90
|
-
# plain Object lacks; grab just the protected instance methods.
|
|
91
|
-
def instance_methods_module
|
|
92
|
-
mod = Module.new
|
|
93
|
-
%i[set_tab current_tab current_tab? tab_stack].each do |name|
|
|
94
|
-
mod.define_method(name, InlineForms::Tabs::Controller.instance_method(name))
|
|
95
|
-
end
|
|
96
|
-
mod
|
|
97
|
-
end
|
|
98
|
-
end
|
data/test/test_helper.rb
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
# -*- encoding : utf-8 -*-
|
|
2
|
-
|
|
3
|
-
require "minitest/autorun"
|
|
4
|
-
require "inline_forms_installer/user_model_config"
|
|
5
|
-
|
|
6
|
-
class UserModelConfigTest < Minitest::Test
|
|
7
|
-
def test_default_user
|
|
8
|
-
cfg = InlineFormsInstaller::UserModelConfig.from_name("User")
|
|
9
|
-
assert cfg.default?
|
|
10
|
-
assert_equal "users", cfg.table_name
|
|
11
|
-
assert_equal 'devise_for :users, path_prefix: "auth"', cfg.devise_route_line
|
|
12
|
-
assert_equal "/auth/users/sign_in", cfg.sign_in_path_fragment
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
def test_member
|
|
16
|
-
cfg = InlineFormsInstaller::UserModelConfig.from_name("Member")
|
|
17
|
-
refute cfg.default?
|
|
18
|
-
assert_equal "Member", cfg.class_name
|
|
19
|
-
assert_equal "members", cfg.table_name
|
|
20
|
-
assert_equal "member_id", cfg.foreign_key
|
|
21
|
-
assert_equal "members_roles", cfg.join_table
|
|
22
|
-
assert_equal "MembersController", cfg.controller_name
|
|
23
|
-
assert_includes cfg.devise_route_line, 'class_name: "Member"'
|
|
24
|
-
assert_includes cfg.devise_route_line, 'path: "members"'
|
|
25
|
-
assert_equal "/auth/members/sign_in", cfg.sign_in_path_fragment
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
def test_adapts_example_tests
|
|
29
|
-
cfg = InlineFormsInstaller::UserModelConfig.from_name("Member")
|
|
30
|
-
src = "user = User.find_or_initialize_by(email: \"admin@example.com\")\n"
|
|
31
|
-
assert_includes cfg.adapt_example_test_source(src), "Member.find_or_initialize_by"
|
|
32
|
-
guest = "assert_match %r{/auth/users/sign_in}, @response.redirect_url\n"
|
|
33
|
-
assert_includes cfg.adapt_example_test_source(guest), "/auth/members/sign_in"
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
def test_rejects_invalid_constant
|
|
37
|
-
assert_raises(ArgumentError) { InlineFormsInstaller::UserModelConfig.from_name("not-a-class") }
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
def test_from_env_defaults_to_user
|
|
41
|
-
env = { "user_model" => "" }
|
|
42
|
-
assert InlineFormsInstaller::UserModelConfig.from_env(env).default?
|
|
43
|
-
end
|
|
44
|
-
end
|