inline_forms 7.10.2 → 7.11.0
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 +11 -0
- data/Rakefile +18 -1
- data/docs/prompt/test-the-example-app.md +3 -3
- data/inline_forms.gemspec +6 -21
- data/lib/inline_forms/gem_files.rb +39 -0
- data/lib/inline_forms/version.rb +1 -1
- metadata +10 -76
- data/bin/inline_forms +0 -141
- data/bin/inline_forms_app_template.rb +0 -22
- data/bin/inline_forms_installer_core.rb +0 -886
- data/lib/generators/templates/capistrano/Capfile +0 -39
- data/lib/generators/templates/capistrano/deploy.rb +0 -59
- data/lib/generators/templates/capistrano/production.rb +0 -7
- data/lib/generators/templates/unicorn/production.rb +0 -39
- data/lib/installer_templates/dartsass/devise_main.scss +0 -2
- data/lib/installer_templates/dartsass/inline_forms_dartsass_builds.rb +0 -14
- data/lib/installer_templates/dartsass/inline_forms_main.scss +0 -2
- data/lib/installer_templates/example_app_tests/test/example_app/example_integration_test_case.rb +0 -36
- data/lib/installer_templates/example_app_tests/test/integration/example_app_apartment_field_turbo_test.rb +0 -73
- data/lib/installer_templates/example_app_tests/test/integration/example_app_apartment_name_list_test.rb +0 -73
- data/lib/installer_templates/example_app_tests/test/integration/example_app_apartment_name_required_test.rb +0 -21
- data/lib/installer_templates/example_app_tests/test/integration/example_app_apartment_opening_date_test.rb +0 -49
- data/lib/installer_templates/example_app_tests/test/integration/example_app_apartment_photos_pagination_test.rb +0 -440
- data/lib/installer_templates/example_app_tests/test/integration/example_app_apartment_row_turbo_test.rb +0 -103
- data/lib/installer_templates/example_app_tests/test/integration/example_app_apartment_top_level_new_test.rb +0 -70
- data/lib/installer_templates/example_app_tests/test/integration/example_app_apartment_top_level_pagination_test.rb +0 -40
- data/lib/installer_templates/example_app_tests/test/integration/example_app_apartment_versions_turbo_test.rb +0 -120
- data/lib/installer_templates/example_app_tests/test/integration/example_app_guest_access_test.rb +0 -21
- data/lib/installer_templates/example_app_tests/test/integration/example_app_photo_revert_test.rb +0 -94
- data/lib/installer_templates/example_app_tests/test/integration/example_app_photos_test.rb +0 -22
- data/lib/installer_templates/example_app_tests/test/integration/example_app_routing_test.rb +0 -15
- data/lib/installer_templates/example_app_tests/test/integration/example_app_turbo_layout_test.rb +0 -25
- data/lib/installer_templates/example_app_tests/test/integration/example_app_validation_hints_test.rb +0 -40
- data/lib/installer_templates/example_app_tests/test/models/example_app_apartment_name_validation_test.rb +0 -16
- data/lib/installer_templates/example_app_tests/test/models/example_app_apartment_photo_test.rb +0 -26
- data/lib/installer_templates/example_app_tests/test/models/example_app_paper_trail_changeset_test.rb +0 -78
- data/lib/installer_templates/example_app_tests/test/models/example_app_plain_text_rich_text_edge_cases_test.rb +0 -46
- data/lib/installer_templates/example_app_views/apartments/name_list.html.erb +0 -26
- data/lib/installer_templates/example_app_views/inline_forms/_header.html.erb +0 -45
|
@@ -1,440 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require_relative "../example_app/example_integration_test_case"
|
|
4
|
-
|
|
5
|
-
# Smoke test for rollout step 2 of stuff/ujs-to-turbo.md (gem-side):
|
|
6
|
-
# the nested has_many list (apartments -> photos) is now wrapped in a
|
|
7
|
-
# <turbo-frame> and pagination is no longer remote: true. Relies on
|
|
8
|
-
# the SeedKonferenshaPhotos migration that the inline_forms installer
|
|
9
|
-
# generates when invoked with --example: it creates a "Konferensha"
|
|
10
|
-
# Apartment with one Photo per file in db/seed_images/, and the gem
|
|
11
|
-
# ships 12 sample jpgs in pics/, so combined with `Photo.per_page = 5`
|
|
12
|
-
# (also set by the installer) this gallery paginates 5 / 5 / 2.
|
|
13
|
-
class ExampleAppApartmentPhotosPaginationTest < ExampleAppIntegrationTestCase
|
|
14
|
-
# `bundle exec rails test` loads the test DB from db/schema.rb, which is
|
|
15
|
-
# DDL-only -- the SeedKonferenshaPhotos migration's row inserts never
|
|
16
|
-
# land in db/test.sqlite3. We re-seed here from the same db/seed_images/
|
|
17
|
-
# the installer copied into the app so the test asserts against real
|
|
18
|
-
# records (and real CarrierWave file mounts) without depending on
|
|
19
|
-
# development-DB state.
|
|
20
|
-
setup do
|
|
21
|
-
@apartment = Apartment.find_or_create_by!(name: "Konferensha") do |a|
|
|
22
|
-
a.title = "Konferensha sobre Papiamentu"
|
|
23
|
-
end
|
|
24
|
-
seed_dir = Rails.root.join("db", "seed_images")
|
|
25
|
-
if seed_dir.directory?
|
|
26
|
-
Dir.glob(seed_dir.join("*.{jpg,jpeg,png,gif}"), File::FNM_CASEFOLD).sort.each do |abs|
|
|
27
|
-
base = File.basename(abs)
|
|
28
|
-
next if Photo.exists?(name: base, apartment_id: @apartment.id)
|
|
29
|
-
File.open(abs, "rb") do |io|
|
|
30
|
-
Photo.create!(
|
|
31
|
-
name: base,
|
|
32
|
-
caption: "Konferensha foto #{base}",
|
|
33
|
-
apartment: @apartment,
|
|
34
|
-
image: io
|
|
35
|
-
)
|
|
36
|
-
end
|
|
37
|
-
end
|
|
38
|
-
end
|
|
39
|
-
@update_span = "apartment_#{@apartment.id}_photos_list"
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
test "seed migration left at least 6 photos under Konferensha so pagination triggers" do
|
|
43
|
-
assert @apartment.photos.count >= 6,
|
|
44
|
-
"expected SeedKonferenshaPhotos to seed >= 6 photos for Konferensha; " \
|
|
45
|
-
"got #{@apartment.photos.count}. Check db/seed_images/ and the migration."
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
test "Photo.per_page is overridden so will_paginate splits the gallery" do
|
|
49
|
-
assert_equal 5, Photo.per_page,
|
|
50
|
-
"expected the installer to set `self.per_page = 5` on Photo so the seeded gallery paginates"
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
test "nested photos index without Turbo-Frame header renders full inline_forms layout (bookmark / full navigation)" do
|
|
54
|
-
get photos_path(
|
|
55
|
-
parent_class: "Apartment",
|
|
56
|
-
parent_id: @apartment.id,
|
|
57
|
-
update: @update_span,
|
|
58
|
-
ul_needed: true
|
|
59
|
-
)
|
|
60
|
-
assert_response :success
|
|
61
|
-
|
|
62
|
-
assert_match(
|
|
63
|
-
/id="outer_container"/,
|
|
64
|
-
@response.body,
|
|
65
|
-
"direct or full-page GET /photos?... must use the inline_forms layout " \
|
|
66
|
-
"so the page is styled; `layout: false` used to emit only a bare <turbo-frame> " \
|
|
67
|
-
"which looks broken in the address bar."
|
|
68
|
-
)
|
|
69
|
-
assert_match(
|
|
70
|
-
%r{<turbo-frame\s+id="#{Regexp.escape(@update_span)}"},
|
|
71
|
-
@response.body,
|
|
72
|
-
"expected the gallery frame inside the layout body"
|
|
73
|
-
)
|
|
74
|
-
end
|
|
75
|
-
|
|
76
|
-
test "nested photos index with Turbo-Frame header uses minimal layout without app chrome" do
|
|
77
|
-
get photos_path(
|
|
78
|
-
parent_class: "Apartment",
|
|
79
|
-
parent_id: @apartment.id,
|
|
80
|
-
update: @update_span,
|
|
81
|
-
ul_needed: true
|
|
82
|
-
),
|
|
83
|
-
headers: { "Turbo-Frame" => @update_span }
|
|
84
|
-
assert_response :success
|
|
85
|
-
|
|
86
|
-
assert_match(
|
|
87
|
-
%r{<turbo-frame\s+id="#{Regexp.escape(@update_span)}"},
|
|
88
|
-
@response.body,
|
|
89
|
-
"expected Turbo frame navigation to receive a matching <turbo-frame id=\"#{@update_span}\">"
|
|
90
|
-
)
|
|
91
|
-
refute_match(
|
|
92
|
-
/id="outer_container"/,
|
|
93
|
-
@response.body,
|
|
94
|
-
"frame requests should not pay for the full inline_forms chrome; use turbo_rails/frame layout"
|
|
95
|
-
)
|
|
96
|
-
end
|
|
97
|
-
|
|
98
|
-
test "nested photos index is wrapped in a <turbo-frame> instead of remote-UJS <div>" do
|
|
99
|
-
get photos_path(
|
|
100
|
-
parent_class: "Apartment",
|
|
101
|
-
parent_id: @apartment.id,
|
|
102
|
-
update: @update_span,
|
|
103
|
-
ul_needed: true
|
|
104
|
-
)
|
|
105
|
-
assert_response :success
|
|
106
|
-
|
|
107
|
-
assert_match(
|
|
108
|
-
%r{<turbo-frame\s+id="#{Regexp.escape(@update_span)}"},
|
|
109
|
-
@response.body,
|
|
110
|
-
"expected the nested photos list to render as <turbo-frame id=\"#{@update_span}\">"
|
|
111
|
-
)
|
|
112
|
-
|
|
113
|
-
refute_match(
|
|
114
|
-
%r{<div[^>]+class="list_container"[^>]+id="#{Regexp.escape(@update_span)}"},
|
|
115
|
-
@response.body,
|
|
116
|
-
"nested photos list should no longer use the legacy <div class=\"list_container\"> wrapper"
|
|
117
|
-
)
|
|
118
|
-
end
|
|
119
|
-
|
|
120
|
-
test "nested photos pagination renders will_paginate links inside the frame" do
|
|
121
|
-
get photos_path(
|
|
122
|
-
parent_class: "Apartment",
|
|
123
|
-
parent_id: @apartment.id,
|
|
124
|
-
update: @update_span,
|
|
125
|
-
ul_needed: true
|
|
126
|
-
)
|
|
127
|
-
assert_response :success
|
|
128
|
-
|
|
129
|
-
assert_match(
|
|
130
|
-
/<(?:div|nav)[^>]+class="[^"]*\bpagination\b[^"]*"/,
|
|
131
|
-
@response.body,
|
|
132
|
-
"expected will_paginate to render a .pagination element (gallery has more rows than Photo.per_page)"
|
|
133
|
-
)
|
|
134
|
-
|
|
135
|
-
refute_match(
|
|
136
|
-
/class="next_page"[^>]*data-remote="true"/,
|
|
137
|
-
@response.body,
|
|
138
|
-
"pagination links should no longer carry data-remote=\"true\" (Turbo Frame handles in-frame nav)"
|
|
139
|
-
)
|
|
140
|
-
end
|
|
141
|
-
|
|
142
|
-
test "pagination links carry the same update= as the surrounding turbo-frame id" do
|
|
143
|
-
# This is the regression class that broke "Next" in 7.2.1: the
|
|
144
|
-
# legacy UJS pagination passed `update=apartment_<id>_photos`
|
|
145
|
-
# (the OUTER wrapper id from _show.html.erb, which list.js.erb
|
|
146
|
-
# used as the swap target). Turbo Frames swaps by id-match between
|
|
147
|
-
# the frame in the DOM and a frame in the response, so when a Next
|
|
148
|
-
# click re-rendered _list with update_span derived from the URL,
|
|
149
|
-
# the response contained `<turbo-frame id="apartment_<id>_photos">`
|
|
150
|
-
# while the page held `<turbo-frame id="apartment_<id>_photos_list">`,
|
|
151
|
-
# and Turbo logged "the response did not contain the expected
|
|
152
|
-
# <turbo-frame>" and dropped the swap. The `update=` param on every
|
|
153
|
-
# pagination link must be the same id as the surrounding frame.
|
|
154
|
-
get photos_path(
|
|
155
|
-
parent_class: "Apartment",
|
|
156
|
-
parent_id: @apartment.id,
|
|
157
|
-
update: @update_span,
|
|
158
|
-
ul_needed: true
|
|
159
|
-
)
|
|
160
|
-
assert_response :success
|
|
161
|
-
|
|
162
|
-
page_link_updates =
|
|
163
|
-
@response.body.scan(/href="[^"]*\?[^"]*update=([^&"]+)[^"]*"/).flatten
|
|
164
|
-
|
|
165
|
-
assert page_link_updates.any? { |u| u == @update_span },
|
|
166
|
-
"expected at least one pagination link to carry update=#{@update_span} " \
|
|
167
|
-
"(matching the <turbo-frame id=\"#{@update_span}\">), got updates=#{page_link_updates.inspect}"
|
|
168
|
-
|
|
169
|
-
refute page_link_updates.any? { |u| u == @update_span.sub(/_list\z/, "") },
|
|
170
|
-
"no pagination link should still carry the legacy outer-wrapper id " \
|
|
171
|
-
"(#{@update_span.sub(/_list\z/, "")}) -- Turbo Frame can't swap on that id"
|
|
172
|
-
end
|
|
173
|
-
|
|
174
|
-
test "top-level apartment rows do NOT carry data-turbo=\"false\" (would poison nested frames)" do
|
|
175
|
-
# 7.2.2 broke pagination of the inner photos <turbo-frame> because
|
|
176
|
-
# the top-level apartment row was emitting data-turbo="false" too.
|
|
177
|
-
# When show.js.erb swaps the inline edit (containing the nested
|
|
178
|
-
# <turbo-frame>) into that row, every link inside the nested frame
|
|
179
|
-
# -- including pagination links -- has the row as an ancestor.
|
|
180
|
-
# Turbo's Session.elementIsNavigatable does
|
|
181
|
-
# `findClosestRecursively(link, "[data-turbo]")` and does NOT stop
|
|
182
|
-
# at the intervening <turbo-frame>; it picks up the row's
|
|
183
|
-
# data-turbo="false" and refuses to intercept the click, so the
|
|
184
|
-
# browser does a full-page navigation to /photos?page=N&... and
|
|
185
|
-
# the user sees the bare partial without a layout. The attribute
|
|
186
|
-
# must stay scoped to NESTED rows (which need the opt-out for
|
|
187
|
-
# their swapped-in inline-edit forms); top-level rows must NOT
|
|
188
|
-
# carry it.
|
|
189
|
-
get apartments_path
|
|
190
|
-
assert_response :success
|
|
191
|
-
|
|
192
|
-
refute_match(
|
|
193
|
-
/<div[^>]+class="[^"]*\btop-level\b[^"]*"[^>]*data-turbo="false"|<div[^>]+data-turbo="false"[^>]*class="[^"]*\btop-level\b[^"]*"/,
|
|
194
|
-
@response.body,
|
|
195
|
-
"top-level list rows must not carry data-turbo=\"false\"; that attribute would " \
|
|
196
|
-
"be inherited by every link inside any nested <turbo-frame> swapped into the row"
|
|
197
|
-
)
|
|
198
|
-
end
|
|
199
|
-
|
|
200
|
-
test "nested photo rows are turbo-framed with Turbo presentation links (no data-turbo false on row)" do
|
|
201
|
-
get photos_path(
|
|
202
|
-
parent_class: "Apartment",
|
|
203
|
-
parent_id: @apartment.id,
|
|
204
|
-
update: @update_span,
|
|
205
|
-
ul_needed: true
|
|
206
|
-
)
|
|
207
|
-
assert_response :success
|
|
208
|
-
|
|
209
|
-
sample_row_id = "apartment_#{@apartment.id}_photo_#{@apartment.photos.first.id}"
|
|
210
|
-
assert_match(
|
|
211
|
-
%r{<turbo-frame[^>]*\bid="#{Regexp.escape(sample_row_id)}"},
|
|
212
|
-
@response.body,
|
|
213
|
-
"expected each nested photo row to be a <turbo-frame id=\"#{sample_row_id}\">"
|
|
214
|
-
)
|
|
215
|
-
refute_match(
|
|
216
|
-
%r{<turbo-frame[^>]*id="#{Regexp.escape(sample_row_id)}"[^>]*data-turbo="false"},
|
|
217
|
-
@response.body,
|
|
218
|
-
"nested turbo-frame rows must not opt out of Turbo (field cancel / pagination live inside frames)"
|
|
219
|
-
)
|
|
220
|
-
assert_select %(turbo-frame##{sample_row_id} a[data-turbo='true'][data-turbo-frame='#{sample_row_id}']), minimum: 1
|
|
221
|
-
end
|
|
222
|
-
|
|
223
|
-
test "nested Photo versions restore targets nested row turbo-frame not bare photo id" do
|
|
224
|
-
photo = @apartment.photos.first!
|
|
225
|
-
original_name = photo.name
|
|
226
|
-
photo.update!(name: "#{original_name}-changed")
|
|
227
|
-
row_id = "apartment_#{@apartment.id}_photo_#{photo.id}"
|
|
228
|
-
versions_frame = "#{row_id}_versions"
|
|
229
|
-
version = photo.versions.where(event: "update").order(:id).last
|
|
230
|
-
assert version, "expected an update version to revert"
|
|
231
|
-
|
|
232
|
-
get list_versions_photo_path(photo, update: versions_frame),
|
|
233
|
-
headers: { "Turbo-Frame" => versions_frame, "Accept" => "text/html" }
|
|
234
|
-
assert_response :success
|
|
235
|
-
assert_includes @response.body, "data-turbo-frame=\"#{row_id}\"",
|
|
236
|
-
"restore must target the nested row frame (#{row_id}), not photo_#{photo.id}"
|
|
237
|
-
|
|
238
|
-
# 7.9.0: revert always responds with turbo-stream (the legacy
|
|
239
|
-
# `format.html` fallback was dropped).
|
|
240
|
-
post revert_photo_path(version.id, update: row_id),
|
|
241
|
-
headers: {
|
|
242
|
-
"Turbo-Frame" => versions_frame,
|
|
243
|
-
"Accept" => "text/vnd.turbo-stream.html"
|
|
244
|
-
}
|
|
245
|
-
assert_response :success
|
|
246
|
-
assert_includes @response.body, %(action="replace")
|
|
247
|
-
assert_includes @response.body, %(target="#{row_id}")
|
|
248
|
-
assert_equal original_name, photo.reload.name
|
|
249
|
-
end
|
|
250
|
-
|
|
251
|
-
test "nested Photo row opens and closes via Turbo HTML (not_accessible_through_html model)" do
|
|
252
|
-
photo = @apartment.photos.first!
|
|
253
|
-
row_id = "apartment_#{@apartment.id}_photo_#{photo.id}"
|
|
254
|
-
row_headers = { "Turbo-Frame" => row_id, "Accept" => "text/html" }
|
|
255
|
-
|
|
256
|
-
get photo_path(photo, update: row_id), headers: row_headers
|
|
257
|
-
assert_response :success
|
|
258
|
-
assert_includes @response.body, %(<turbo-frame id="#{row_id}">)
|
|
259
|
-
assert_includes @response.body, "object_presentation"
|
|
260
|
-
|
|
261
|
-
get photo_path(photo, update: row_id, close: true), headers: row_headers
|
|
262
|
-
assert_response :success
|
|
263
|
-
assert_includes @response.body, %(<turbo-frame id="#{row_id}">)
|
|
264
|
-
refute_includes @response.body, "object_presentation"
|
|
265
|
-
end
|
|
266
|
-
|
|
267
|
-
test "nested Photo name field cancel returns field show HTML (Turbo)" do
|
|
268
|
-
photo = @apartment.photos.first!
|
|
269
|
-
frame_id = "apartment_#{@apartment.id}_photo_#{photo.id}_name"
|
|
270
|
-
turbo_headers = { "Turbo-Frame" => frame_id, "Accept" => "text/html" }
|
|
271
|
-
|
|
272
|
-
get edit_photo_path(
|
|
273
|
-
photo,
|
|
274
|
-
attribute: "name",
|
|
275
|
-
form_element: "text_field",
|
|
276
|
-
update: frame_id
|
|
277
|
-
), headers: turbo_headers
|
|
278
|
-
assert_response :success
|
|
279
|
-
|
|
280
|
-
get photo_path(
|
|
281
|
-
photo,
|
|
282
|
-
attribute: "name",
|
|
283
|
-
form_element: "text_field",
|
|
284
|
-
update: frame_id
|
|
285
|
-
), headers: turbo_headers
|
|
286
|
-
assert_response :success
|
|
287
|
-
assert_includes @response.body, %(<turbo-frame id="#{frame_id}">)
|
|
288
|
-
refute_includes @response.body, 'name="name"',
|
|
289
|
-
"cancel must return read-only field, not the edit form"
|
|
290
|
-
end
|
|
291
|
-
|
|
292
|
-
# Step 3 (ujs-to-turbo.md): nested `not_accessible_through_html?` Photo + CarrierWave
|
|
293
|
-
# `image` must accept Turbo-driven multipart PUT inside the field `<turbo-frame>`
|
|
294
|
-
# (no `UnknownFormat` / 406 after DB write — regression class from 7.2.0).
|
|
295
|
-
test "nested Photo image field updates via Turbo multipart PUT inside field frame" do
|
|
296
|
-
photo = @apartment.photos.first!
|
|
297
|
-
frame_id = "apartment_#{@apartment.id}_photo_#{photo.id}_image"
|
|
298
|
-
turbo_headers = { "Turbo-Frame" => frame_id, "Accept" => "text/html" }
|
|
299
|
-
|
|
300
|
-
get edit_photo_path(
|
|
301
|
-
photo,
|
|
302
|
-
attribute: "image",
|
|
303
|
-
form_element: "image_field",
|
|
304
|
-
update: frame_id
|
|
305
|
-
), headers: turbo_headers
|
|
306
|
-
assert_response :success
|
|
307
|
-
assert_includes @response.body, %(enctype="multipart/form-data"),
|
|
308
|
-
"image edit form must stay multipart when Turbo omits remote: true"
|
|
309
|
-
assert_includes @response.body, %(<turbo-frame id="#{frame_id}">)
|
|
310
|
-
|
|
311
|
-
seed_dir = Rails.root.join("db", "seed_images")
|
|
312
|
-
jpgs = Dir.glob(seed_dir.join("*.{jpg,jpeg}"), File::FNM_CASEFOLD).sort
|
|
313
|
-
assert_operator jpgs.size, :>=, 2,
|
|
314
|
-
"need at least two seed jpgs so replacement can differ from current mount"
|
|
315
|
-
|
|
316
|
-
replacement = jpgs.find { |abs| File.basename(abs) != photo.name } || jpgs.last
|
|
317
|
-
uploaded = Rack::Test::UploadedFile.new(replacement, "image/jpeg")
|
|
318
|
-
|
|
319
|
-
put photo_path(
|
|
320
|
-
photo,
|
|
321
|
-
attribute: "image",
|
|
322
|
-
form_element: "image_field",
|
|
323
|
-
update: frame_id
|
|
324
|
-
),
|
|
325
|
-
params: { image: uploaded },
|
|
326
|
-
headers: turbo_headers
|
|
327
|
-
|
|
328
|
-
assert_response :success,
|
|
329
|
-
"multipart image update must respond with HTML (not 406 UnknownFormat)"
|
|
330
|
-
assert_includes @response.body, %(<turbo-frame id="#{frame_id}">)
|
|
331
|
-
refute_match(/UnknownFormat|406/, @response.body)
|
|
332
|
-
|
|
333
|
-
photo.reload
|
|
334
|
-
assert photo.image.present?, "expected CarrierWave mount after Turbo multipart PUT"
|
|
335
|
-
end
|
|
336
|
-
|
|
337
|
-
# 7.5.2 regression: after cancel / update on a field, the swapped
|
|
338
|
-
# `<turbo-frame id="…">` must contain a Turbo link
|
|
339
|
-
# (`data-turbo="true" data-turbo-frame="_self"`) so the user can re-open
|
|
340
|
-
# the editor. 7.5.1 emitted `data-remote="true"`, which jquery_ujs
|
|
341
|
-
# intercepts as a JS request the controller does not register, so the
|
|
342
|
-
# second click silently fails (no swap, no edit form).
|
|
343
|
-
test "nested Photo image field show after update has Turbo (not data-remote) link" do
|
|
344
|
-
photo = @apartment.photos.first!
|
|
345
|
-
frame_id = "apartment_#{@apartment.id}_photo_#{photo.id}_image"
|
|
346
|
-
turbo_headers = { "Turbo-Frame" => frame_id, "Accept" => "text/html" }
|
|
347
|
-
|
|
348
|
-
seed_dir = Rails.root.join("db", "seed_images")
|
|
349
|
-
jpgs = Dir.glob(seed_dir.join("*.{jpg,jpeg}"), File::FNM_CASEFOLD).sort
|
|
350
|
-
replacement = jpgs.find { |abs| File.basename(abs) != photo.name } || jpgs.last
|
|
351
|
-
uploaded = Rack::Test::UploadedFile.new(replacement, "image/jpeg")
|
|
352
|
-
|
|
353
|
-
put photo_path(
|
|
354
|
-
photo,
|
|
355
|
-
attribute: "image",
|
|
356
|
-
form_element: "image_field",
|
|
357
|
-
update: frame_id
|
|
358
|
-
),
|
|
359
|
-
params: { image: uploaded },
|
|
360
|
-
headers: turbo_headers
|
|
361
|
-
assert_response :success
|
|
362
|
-
refute_match(
|
|
363
|
-
/data-remote="true"/,
|
|
364
|
-
@response.body,
|
|
365
|
-
"field_show after Turbo update must use Turbo data attributes; " \
|
|
366
|
-
"data-remote=\"true\" hits jquery_ujs (no JS responder) and the " \
|
|
367
|
-
"second click silently fails."
|
|
368
|
-
)
|
|
369
|
-
assert_match(
|
|
370
|
-
/data-turbo="true"/,
|
|
371
|
-
@response.body,
|
|
372
|
-
"expected Turbo data attribute on the inline-edit link inside the swapped field frame"
|
|
373
|
-
)
|
|
374
|
-
end
|
|
375
|
-
|
|
376
|
-
# Same regression on the cancel path (no DB write): clicking the field
|
|
377
|
-
# cancel returns the read-only field; the link inside must be a Turbo link
|
|
378
|
-
# so the user can re-open the editor.
|
|
379
|
-
test "nested Photo image field show after cancel has Turbo (not data-remote) link" do
|
|
380
|
-
photo = @apartment.photos.first!
|
|
381
|
-
frame_id = "apartment_#{@apartment.id}_photo_#{photo.id}_image"
|
|
382
|
-
turbo_headers = { "Turbo-Frame" => frame_id, "Accept" => "text/html" }
|
|
383
|
-
|
|
384
|
-
get photo_path(
|
|
385
|
-
photo,
|
|
386
|
-
attribute: "image",
|
|
387
|
-
form_element: "image_field",
|
|
388
|
-
update: frame_id
|
|
389
|
-
), headers: turbo_headers
|
|
390
|
-
assert_response :success
|
|
391
|
-
refute_match(/data-remote="true"/, @response.body,
|
|
392
|
-
"cancel-side field_show must not regress to UJS data-remote=\"true\"")
|
|
393
|
-
assert_match(/data-turbo="true"/, @response.body)
|
|
394
|
-
end
|
|
395
|
-
|
|
396
|
-
test "nested Photo new cancel and create via Turbo inside associated list frame" do
|
|
397
|
-
frame = "apartment_#{@apartment.id}_photos"
|
|
398
|
-
headers = { "Turbo-Frame" => frame, "Accept" => "text/html" }
|
|
399
|
-
|
|
400
|
-
get new_photo_path(update: frame, parent_class: "Apartment", parent_id: @apartment.id),
|
|
401
|
-
headers: headers
|
|
402
|
-
assert_response :success
|
|
403
|
-
assert_includes @response.body, %(<turbo-frame id="#{frame}">)
|
|
404
|
-
assert_includes @response.body, "stylesheet", "new form must use inline_forms layout (styled)"
|
|
405
|
-
assert_includes @response.body, %(enctype="multipart/form-data")
|
|
406
|
-
assert_includes @response.body, 'class="edit_form"'
|
|
407
|
-
assert_includes @response.body, 'name="name"'
|
|
408
|
-
|
|
409
|
-
get photos_path(
|
|
410
|
-
parent_class: "Apartment",
|
|
411
|
-
parent_id: @apartment.id,
|
|
412
|
-
update: frame,
|
|
413
|
-
ul_needed: true
|
|
414
|
-
), headers: headers
|
|
415
|
-
assert_response :success
|
|
416
|
-
assert_match %r{<turbo-frame id="#{frame}"}, @response.body
|
|
417
|
-
assert_match %r{<turbo-frame id="#{@update_span}"}, @response.body
|
|
418
|
-
|
|
419
|
-
seed = Rails.root.join("db/seed_images/dsc00099.jpg")
|
|
420
|
-
uploaded = Rack::Test::UploadedFile.new(seed, "image/jpeg")
|
|
421
|
-
|
|
422
|
-
assert_difference("Photo.count", 1) do
|
|
423
|
-
post photos_path(
|
|
424
|
-
update: frame,
|
|
425
|
-
parent_class: "Apartment",
|
|
426
|
-
parent_id: @apartment.id
|
|
427
|
-
),
|
|
428
|
-
params: {
|
|
429
|
-
name: "curl_new_photo.jpg",
|
|
430
|
-
caption: "from turbo test",
|
|
431
|
-
image: uploaded
|
|
432
|
-
},
|
|
433
|
-
headers: headers
|
|
434
|
-
end
|
|
435
|
-
assert_response :success
|
|
436
|
-
assert_match %r{<turbo-frame id="#{frame}"}, @response.body
|
|
437
|
-
assert_match %r{<turbo-frame id="#{@update_span}"}, @response.body
|
|
438
|
-
assert_includes @response.body, "curl_new_photo.jpg"
|
|
439
|
-
end
|
|
440
|
-
end
|
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require_relative "../example_app/example_integration_test_case"
|
|
4
|
-
|
|
5
|
-
# Stock `/apartments` index: each row is `<turbo-frame id="apartment_<id>">`;
|
|
6
|
-
# opening/closing the inline panel uses Turbo GET `show` + `close` (HTML), not UJS.
|
|
7
|
-
class ExampleAppApartmentRowTurboTest < ExampleAppIntegrationTestCase
|
|
8
|
-
setup do
|
|
9
|
-
@apartment = Apartment.first || Apartment.create!(name: "Row Turbo Apt", title: "T")
|
|
10
|
-
@row_frame = "apartment_#{@apartment.id}"
|
|
11
|
-
@row_headers = { "Turbo-Frame" => @row_frame, "Accept" => "text/html" }
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
test "apartments index wraps each row in a turbo-frame" do
|
|
15
|
-
get apartments_path
|
|
16
|
-
assert_response :success
|
|
17
|
-
assert_includes @response.body, %(<turbo-frame id="#{@row_frame}">),
|
|
18
|
-
"expected top-level list row inside turbo-frame"
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
test "row presentation link uses turbo navigation not UJS remote" do
|
|
22
|
-
get apartments_path
|
|
23
|
-
assert_response :success
|
|
24
|
-
assert_select "turbo-frame##{@row_frame} div.small-11.column > a", count: 1 do |elements|
|
|
25
|
-
el = elements.first
|
|
26
|
-
assert_equal "true", el["data-turbo"]
|
|
27
|
-
assert_equal @row_frame, el["data-turbo-frame"]
|
|
28
|
-
assert_nil el["data-remote"]
|
|
29
|
-
end
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
test "row open show returns full panel inside matching turbo-frame" do
|
|
33
|
-
get apartment_path(@apartment, update: @row_frame), headers: @row_headers
|
|
34
|
-
assert_response :success
|
|
35
|
-
assert_includes @response.body, %(<turbo-frame id="#{@row_frame}">)
|
|
36
|
-
assert_includes @response.body, "object_presentation",
|
|
37
|
-
"expected expanded _show panel"
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
test "row close returns collapsed row inside matching turbo-frame" do
|
|
41
|
-
get apartment_path(@apartment, update: @row_frame, close: true), headers: @row_headers
|
|
42
|
-
assert_response :success
|
|
43
|
-
assert_includes @response.body, %(<turbo-frame id="#{@row_frame}">)
|
|
44
|
-
refute_includes @response.body, "object_presentation",
|
|
45
|
-
"expected _close row, not full panel"
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
test "row close responds to html without Turbo-Frame header" do
|
|
49
|
-
get apartment_path(
|
|
50
|
-
@apartment,
|
|
51
|
-
update: @row_frame,
|
|
52
|
-
close: true
|
|
53
|
-
), headers: { "Accept" => "text/html, application/xhtml+xml" }
|
|
54
|
-
|
|
55
|
-
assert_response :success
|
|
56
|
-
assert_includes @response.body, %(<turbo-frame id="#{@row_frame}">)
|
|
57
|
-
end
|
|
58
|
-
|
|
59
|
-
test "row toolbar trash and destroy links use Turbo not UJS remote" do
|
|
60
|
-
get apartments_path
|
|
61
|
-
assert_response :success
|
|
62
|
-
assert_select "turbo-frame##{@row_frame} a[data-turbo='true'][data-turbo-frame='#{@row_frame}']", minimum: 1
|
|
63
|
-
refute_select "turbo-frame##{@row_frame} a[data-remote='true']"
|
|
64
|
-
end
|
|
65
|
-
|
|
66
|
-
test "destroy via Turbo DELETE returns undo inside matching turbo-frame" do
|
|
67
|
-
doomed = Apartment.create!(name: "Turbo Destroy Me", title: "X")
|
|
68
|
-
frame = "apartment_#{doomed.id}"
|
|
69
|
-
headers = { "Turbo-Frame" => frame, "Accept" => "text/html" }
|
|
70
|
-
|
|
71
|
-
delete apartment_path(doomed, update: frame), headers: headers
|
|
72
|
-
assert_response :success
|
|
73
|
-
assert_includes @response.body, %(<turbo-frame id="#{frame}">)
|
|
74
|
-
assert_includes @response.body, "undo"
|
|
75
|
-
assert_not Apartment.exists?(doomed.id)
|
|
76
|
-
end
|
|
77
|
-
|
|
78
|
-
test "revert via Turbo POST restores row as collapsed turbo-frame" do
|
|
79
|
-
doomed = Apartment.create!(name: "Turbo Revert Me", title: "Y")
|
|
80
|
-
apt_id = doomed.id
|
|
81
|
-
frame = "apartment_#{apt_id}"
|
|
82
|
-
delete_headers = { "Turbo-Frame" => frame, "Accept" => "text/html" }
|
|
83
|
-
|
|
84
|
-
delete apartment_path(doomed, update: frame), headers: delete_headers
|
|
85
|
-
assert_response :success
|
|
86
|
-
|
|
87
|
-
# 7.9.0 dropped the `format.html` fallback in `revert`; restore links
|
|
88
|
-
# always request a turbo-stream now (the response replaces both the
|
|
89
|
-
# row and the versions panel in one stream).
|
|
90
|
-
versions_frame = "#{frame}_versions"
|
|
91
|
-
destroy_version = PaperTrail::Version.where(item_type: "Apartment", item_id: apt_id).order(:id).last
|
|
92
|
-
post revert_apartment_path(destroy_version.id, update: frame),
|
|
93
|
-
headers: {
|
|
94
|
-
"Turbo-Frame" => versions_frame,
|
|
95
|
-
"Accept" => "text/vnd.turbo-stream.html"
|
|
96
|
-
}
|
|
97
|
-
assert_response :success
|
|
98
|
-
assert Apartment.where(name: "Turbo Revert Me").exists?
|
|
99
|
-
assert_includes @response.body, %(action="replace")
|
|
100
|
-
assert_includes @response.body, %(target="#{frame}")
|
|
101
|
-
assert_includes @response.body, %(target="#{versions_frame}")
|
|
102
|
-
end
|
|
103
|
-
end
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require_relative "../example_app/example_integration_test_case"
|
|
4
|
-
|
|
5
|
-
# Step 4: top-level `/apartments` list, +new, cancel, and create use Turbo Frames
|
|
6
|
-
# (`<turbo-frame id="apartments_list">`) instead of UJS + new.js.erb / list.js.erb.
|
|
7
|
-
class ExampleAppApartmentTopLevelNewTest < ExampleAppIntegrationTestCase
|
|
8
|
-
setup do
|
|
9
|
-
@frame = "apartments_list"
|
|
10
|
-
@frame_headers = { "Turbo-Frame" => @frame, "Accept" => "text/html" }
|
|
11
|
-
@apartment = Apartment.find_or_create_by!(name: "Top Level List Apt") do |a|
|
|
12
|
-
a.title = "Top level list seed"
|
|
13
|
-
end
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
test "top-level apartments index wraps list in turbo-frame" do
|
|
17
|
-
get apartments_path
|
|
18
|
-
assert_response :success
|
|
19
|
-
assert_match(
|
|
20
|
-
%r{<turbo-frame[^>]+id="#{Regexp.escape(@frame)}"[^>]*class="list_container"},
|
|
21
|
-
@response.body
|
|
22
|
-
)
|
|
23
|
-
refute_match(
|
|
24
|
-
%r{<div[^>]+id="#{Regexp.escape(@frame)}"[^>]*class="list_container"},
|
|
25
|
-
@response.body,
|
|
26
|
-
"list root must be turbo-frame, not legacy div"
|
|
27
|
-
)
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
test "top-level + new link uses Turbo not UJS remote" do
|
|
31
|
-
get apartments_path
|
|
32
|
-
assert_response :success
|
|
33
|
-
assert_match(
|
|
34
|
-
%r{<a [^>]*class="button new_button"[^>]*data-turbo="true"[^>]*data-turbo-frame="#{Regexp.escape(@frame)}"[^>]*href="/apartments/new\?update=apartments_list"},
|
|
35
|
-
@response.body
|
|
36
|
-
)
|
|
37
|
-
refute_match(
|
|
38
|
-
%r{<a [^>]*class="button new_button"[^>]*data-remote="true"},
|
|
39
|
-
@response.body
|
|
40
|
-
)
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
test "top-level new returns new form inside matching turbo-frame" do
|
|
44
|
-
get new_apartment_path(update: @frame), headers: @frame_headers
|
|
45
|
-
assert_response :success
|
|
46
|
-
assert_includes @response.body, %(<turbo-frame id="#{@frame}">)
|
|
47
|
-
assert_includes @response.body, 'name="name"'
|
|
48
|
-
assert_includes @response.body, 'class="edit_form"'
|
|
49
|
-
refute_includes @response.content_type.to_s, "javascript"
|
|
50
|
-
end
|
|
51
|
-
|
|
52
|
-
test "top-level cancel returns list inside matching turbo-frame" do
|
|
53
|
-
get apartments_path(update: @frame, ul_needed: true), headers: @frame_headers
|
|
54
|
-
assert_response :success
|
|
55
|
-
assert_includes @response.body, %(<turbo-frame id="#{@frame}")
|
|
56
|
-
assert_includes @response.body, "<turbo-frame id=\"apartment_"
|
|
57
|
-
end
|
|
58
|
-
|
|
59
|
-
test "top-level create via Turbo persists and returns the list frame" do
|
|
60
|
-
name = "TopLevelNewApt-#{SecureRandom.hex(4)}"
|
|
61
|
-
assert_difference("Apartment.count", 1) do
|
|
62
|
-
post apartments_path(update: @frame),
|
|
63
|
-
params: { name: name, title: "Top level new test" },
|
|
64
|
-
headers: @frame_headers
|
|
65
|
-
end
|
|
66
|
-
assert_response :success
|
|
67
|
-
assert_includes @response.body, %(<turbo-frame id="#{@frame}">)
|
|
68
|
-
assert_includes @response.body, name
|
|
69
|
-
end
|
|
70
|
-
end
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require_relative "../example_app/example_integration_test_case"
|
|
4
|
-
|
|
5
|
-
# Step 4: top-level index pagination swaps `<turbo-frame id="apartments_list">`.
|
|
6
|
-
class ExampleAppApartmentTopLevelPaginationTest < ExampleAppIntegrationTestCase
|
|
7
|
-
setup do
|
|
8
|
-
@frame = "apartments_list"
|
|
9
|
-
@frame_headers = { "Turbo-Frame" => @frame, "Accept" => "text/html" }
|
|
10
|
-
@original_per_page = Apartment.per_page
|
|
11
|
-
Apartment.per_page = 3
|
|
12
|
-
6.times do |i|
|
|
13
|
-
Apartment.find_or_create_by!(name: "Paginate Apt #{i}") do |a|
|
|
14
|
-
a.title = "Pagination seed #{i}"
|
|
15
|
-
end
|
|
16
|
-
end
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
teardown do
|
|
20
|
-
Apartment.per_page = @original_per_page
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
test "top-level pagination links target apartments_list frame id" do
|
|
24
|
-
get apartments_path
|
|
25
|
-
assert_response :success
|
|
26
|
-
assert_match %r{class="pagination"}, @response.body
|
|
27
|
-
assert_match(
|
|
28
|
-
/update=apartments_list/,
|
|
29
|
-
@response.body,
|
|
30
|
-
"pagination must pass update=apartments_list for Turbo frame swap"
|
|
31
|
-
)
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
test "top-level page 2 returns matching turbo-frame with Turbo-Frame header" do
|
|
35
|
-
get apartments_path(page: 2, update: @frame, ul_needed: true), headers: @frame_headers
|
|
36
|
-
assert_response :success
|
|
37
|
-
assert_includes @response.body, %(<turbo-frame id="#{@frame}")
|
|
38
|
-
refute_match(/id="outer_container"/, @response.body)
|
|
39
|
-
end
|
|
40
|
-
end
|