turbo_form 0.0.1 → 0.2.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/README.md +12 -10
- data/app/assets/javascripts/turbo_form.js +2 -1
- data/lib/turbo_form/engine.rb +23 -0
- data/lib/turbo_form/form_builder.rb +1 -1
- data/lib/turbo_form/system_test_helper.rb +23 -0
- data/lib/turbo_form/version.rb +1 -1
- data/lib/turbo_form.rb +1 -0
- metadata +2 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 887edabc903374a74393c5a9f2b04e70c78d421a17e893355f9b2f985404a7da
|
|
4
|
+
data.tar.gz: 11cbdfb726a72675d6980e373001ca40de5a9258f2329b2391992779a5eebfa7
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 0431310fcc0bb70e96b71336275a63889b7746b79d4ba4ca64fb36358beff818d56d5b7b05f50663875371771a8e33c85fdb6b1a68e60228a7fcfeaf8a0760e9
|
|
7
|
+
data.tar.gz: 56831a247fe03fd5bc540a2a44c6fde0a8a4dc2ac64a4f8b8a9dca712ba5134fd8ac79cced5b8e12e78e93e7daa7f427bad683fa56e1729bd59fbe212eb55197
|
data/README.md
CHANGED
|
@@ -139,27 +139,29 @@ application.register("turbo-form", TurboFormController)
|
|
|
139
139
|
the same version, and register it:
|
|
140
140
|
|
|
141
141
|
```bash
|
|
142
|
-
yarn add turbo_form
|
|
142
|
+
yarn add @rolemodel/turbo_form
|
|
143
143
|
```
|
|
144
144
|
```js
|
|
145
|
-
import TurboFormController from "turbo_form"
|
|
145
|
+
import TurboFormController from "@rolemodel/turbo_form"
|
|
146
146
|
application.register("turbo-form", TurboFormController)
|
|
147
147
|
```
|
|
148
148
|
|
|
149
149
|
### Testing against it
|
|
150
150
|
|
|
151
|
-
|
|
152
|
-
|
|
151
|
+
A re-render is a round trip, so the line after a trigger is racing it. Wrap the
|
|
152
|
+
trigger and the wait comes with it:
|
|
153
153
|
|
|
154
154
|
```ruby
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
before = form["data-turbo-form-requests-value"].to_i
|
|
158
|
-
yield
|
|
159
|
-
assert_selector "[data-turbo-form-requests-value='#{before + 1}']"
|
|
160
|
-
end
|
|
155
|
+
expect_dynamic_form_request { select "Bourbon", from: "Category" }
|
|
156
|
+
select "Barrel Aged", from: "Flavor"
|
|
161
157
|
```
|
|
162
158
|
|
|
159
|
+
`expect_dynamic_form_request` is available in system tests with nothing to
|
|
160
|
+
require or include — Minitest and RSpec both. It waits on the controller's
|
|
161
|
+
count of completed round trips rather than on the fields that came back, so it
|
|
162
|
+
doesn't care what the response changed. Scope it with Capybara's `within` when
|
|
163
|
+
a page carries more than one dynamic form.
|
|
164
|
+
|
|
163
165
|
## What this deliberately doesn't do
|
|
164
166
|
|
|
165
167
|
It handles the common case well and gets out of the way otherwise. There is no
|
|
@@ -9,7 +9,8 @@ import { Turbo } from "@hotwired/turbo-rails"
|
|
|
9
9
|
export default class extends Controller {
|
|
10
10
|
static values = { url: String, requests: Number }
|
|
11
11
|
|
|
12
|
-
async
|
|
12
|
+
async perform() {
|
|
13
|
+
this.trigger
|
|
13
14
|
const response = await fetch(this.urlValue, {
|
|
14
15
|
method: "PATCH",
|
|
15
16
|
headers: this.#headers,
|
data/lib/turbo_form/engine.rb
CHANGED
|
@@ -30,6 +30,29 @@ module TurboForm
|
|
|
30
30
|
app.config.assets.precompile << "turbo_form.js"
|
|
31
31
|
end
|
|
32
32
|
|
|
33
|
+
# Minitest's system tests descend from ActionDispatch::SystemTestCase, so
|
|
34
|
+
# the load hook reaches them. RSpec's don't -- RSpec::Rails::SystemExampleGroup
|
|
35
|
+
# assembles itself from Action Dispatch's parts instead of inheriting the
|
|
36
|
+
# case -- so they need telling separately, once RSpec is loaded but before
|
|
37
|
+
# any example group has been defined.
|
|
38
|
+
initializer "turbo_form.system_test_helper" do
|
|
39
|
+
ActiveSupport.on_load(:action_dispatch_system_test_case) do
|
|
40
|
+
require "turbo_form/system_test_helper"
|
|
41
|
+
|
|
42
|
+
include TurboForm::SystemTestHelper
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
config.after_initialize do
|
|
47
|
+
next unless defined?(RSpec.configure)
|
|
48
|
+
|
|
49
|
+
require "turbo_form/system_test_helper"
|
|
50
|
+
|
|
51
|
+
RSpec.configure do |config|
|
|
52
|
+
config.include TurboForm::SystemTestHelper, type: :system
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
|
|
33
56
|
# Deliberately eager rather than `ActiveSupport.on_load(:action_view)`: that
|
|
34
57
|
# hook doesn't fire until Action View is first loaded, which in an app that
|
|
35
58
|
# isn't eager loading is partway through rendering the first view -- late
|
|
@@ -84,7 +84,7 @@ module TurboForm
|
|
|
84
84
|
# own default: `change` for a select, `input` for a text field, `click` for
|
|
85
85
|
# a button. Anything else is taken as the event name.
|
|
86
86
|
def stimulus_action_for(trigger)
|
|
87
|
-
trigger == true ? "turbo-form#
|
|
87
|
+
trigger == true ? "turbo-form#perform" : "#{trigger}->turbo-form#perform"
|
|
88
88
|
end
|
|
89
89
|
end
|
|
90
90
|
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
module TurboForm::SystemTestHelper
|
|
2
|
+
# Waits for a dynamic form to finish re-rendering itself.
|
|
3
|
+
#
|
|
4
|
+
# A trigger sends the form to the server and swaps part of it out when the
|
|
5
|
+
# response lands, so anything a test does on the next line is racing that
|
|
6
|
+
# response -- and loses often enough to be flaky rather than broken. The
|
|
7
|
+
# Stimulus controller counts completed round trips; waiting on that count is
|
|
8
|
+
# both cheaper and steadier than waiting on whichever field came back.
|
|
9
|
+
#
|
|
10
|
+
# expect_dynamic_form_request { select "Bourbon", from: "Category" }
|
|
11
|
+
# select "Barrel Aged", from: "Flavor"
|
|
12
|
+
#
|
|
13
|
+
# Scope it with Capybara's own `within` when a page carries more than one
|
|
14
|
+
# dynamic form.
|
|
15
|
+
def expect_dynamic_form_request
|
|
16
|
+
form = page.find("[data-controller~='turbo-form']")
|
|
17
|
+
completed = form["data-turbo-form-requests-value"].to_i + 1
|
|
18
|
+
|
|
19
|
+
yield
|
|
20
|
+
|
|
21
|
+
page.assert_selector "[data-turbo-form-requests-value='#{completed}']"
|
|
22
|
+
end
|
|
23
|
+
end
|
data/lib/turbo_form/version.rb
CHANGED
data/lib/turbo_form.rb
CHANGED
|
@@ -12,6 +12,7 @@ module TurboForm
|
|
|
12
12
|
# Set to false to keep the engine out of the host's route set and draw its
|
|
13
13
|
# route yourself.
|
|
14
14
|
mattr_accessor :draw_routes, default: true
|
|
15
|
+
# mattr_accessor :authorize, default: ->(controller) { true }
|
|
15
16
|
|
|
16
17
|
class << self
|
|
17
18
|
attr_writer :verifier
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: turbo_form
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0
|
|
4
|
+
version: 0.2.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Andy Cohen
|
|
@@ -85,6 +85,7 @@ files:
|
|
|
85
85
|
- lib/turbo_form/form_builder.rb
|
|
86
86
|
- lib/turbo_form/form_helper.rb
|
|
87
87
|
- lib/turbo_form/signature.rb
|
|
88
|
+
- lib/turbo_form/system_test_helper.rb
|
|
88
89
|
- lib/turbo_form/version.rb
|
|
89
90
|
homepage: https://github.com/outlawandy/turbo_form
|
|
90
91
|
licenses:
|