turbo-rails 2.0.7 → 2.0.9
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 +59 -0
- data/app/assets/javascripts/turbo.js +1991 -1914
- data/app/assets/javascripts/turbo.min.js +6 -6
- data/app/assets/javascripts/turbo.min.js.map +1 -1
- data/app/javascript/turbo/cable_stream_source_element.js +10 -0
- data/app/models/concerns/turbo/broadcastable.rb +32 -22
- data/app/models/turbo/streams/tag_builder.rb +30 -12
- data/lib/turbo/engine.rb +48 -3
- data/lib/turbo/system_test_helper.rb +128 -0
- data/lib/turbo/version.rb +1 -1
- metadata +3 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 16246f1521d9dec7821e162a414cc4060317a927872652df246ba973303e8709
|
4
|
+
data.tar.gz: 635c7ff230d7e088424d6d7e9f5731c31d580a71e3ff6c37075e6a2ff3e4c51b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e16526bdf7567af85ca9827a88468ee954541edace0b1dbcbd85b1c524edb00565f37af2d10410c7022ad3c63680bcac478608d0e3484405118c5b435334a168
|
7
|
+
data.tar.gz: 076dcce9163bc6fd1ae92c74636820c4d0577db52cee4a4af29f6f3a3f0c69d75e25e9820b38408c788c5cce24f30856f9f15d6e6455dcf52d28cc6916337a79
|
data/README.md
CHANGED
@@ -100,6 +100,64 @@ This gem provides a `turbo_stream_from` helper to create a turbo stream.
|
|
100
100
|
<%# Rest of show here %>
|
101
101
|
```
|
102
102
|
|
103
|
+
### Testing Turbo Stream Broadcasts
|
104
|
+
|
105
|
+
Receiving server-generated Turbo Broadcasts requires a connected Web Socket.
|
106
|
+
Views that render `<turbo-cable-stream-source>` elements with the
|
107
|
+
`#turbo_stream_from` view helper incur a slight delay before they're ready to
|
108
|
+
receive broadcasts. In System Tests, that delay can disrupt Capybara's built-in
|
109
|
+
synchronization mechanisms that wait for or assert on content that's broadcast
|
110
|
+
over Web Sockets. For example, consider a test that navigates to a page and then
|
111
|
+
immediately asserts that broadcast content is present:
|
112
|
+
|
113
|
+
```ruby
|
114
|
+
test "renders broadcasted Messages" do
|
115
|
+
message = Message.new content: "Hello, from Action Cable"
|
116
|
+
|
117
|
+
visit "/"
|
118
|
+
click_link "All Messages"
|
119
|
+
message.save! # execute server-side code to broadcast a Message
|
120
|
+
|
121
|
+
assert_text message.content
|
122
|
+
end
|
123
|
+
```
|
124
|
+
|
125
|
+
If the call to `Message#save!` executes quickly enough, it might beat-out any
|
126
|
+
`<turbo-cable-stream-source>` elements rendered by the call to `click_link "All
|
127
|
+
Messages"`.
|
128
|
+
|
129
|
+
To wait for any disconnected `<turbo-cable-stream-source>` elements to connect,
|
130
|
+
call [`#connect_turbo_cable_stream_sources`](turbo-rails/blob/wait-for-cable-stream-sourceshttps://github.com/hotwired/turbo-rails/blob/main/lib/turbo/system_test_helper.rb):
|
131
|
+
|
132
|
+
```diff
|
133
|
+
test "renders broadcasted Messages" do
|
134
|
+
message = Message.new content: "Hello, from Action Cable"
|
135
|
+
|
136
|
+
visit "/"
|
137
|
+
click_link "All Messages"
|
138
|
+
+ connect_turbo_cable_stream_sources
|
139
|
+
message.save! # execute server-side code to broadcast a Message
|
140
|
+
|
141
|
+
assert_text message.content
|
142
|
+
end
|
143
|
+
```
|
144
|
+
|
145
|
+
By default, calls to [`#visit`](https://rubydoc.info/github/teamcapybara/capybara/master/Capybara/Session:visit) will wait for all `<turbo-cable-stream-source>` elements to connect. You can control this by modifying the `config.turbo.test_connect_after_actions`. For example, to wait after calls to [`#click_link`](https://rubydoc.info/github/teamcapybara/capybara/master/Capybara/Node/Actions:click_link), add the following to `config/environments/test.rb`:
|
146
|
+
|
147
|
+
```ruby
|
148
|
+
# config/environments/test.rb
|
149
|
+
|
150
|
+
config.turbo.test_connect_after_actions << :click_link
|
151
|
+
```
|
152
|
+
|
153
|
+
To disable automatic connecting, set the configuration to `[]`:
|
154
|
+
|
155
|
+
```ruby
|
156
|
+
# config/environments/test.rb
|
157
|
+
|
158
|
+
config.turbo.test_connect_after_actions = []
|
159
|
+
```
|
160
|
+
|
103
161
|
[See documentation](https://turbo.hotwired.dev/handbook/streams).
|
104
162
|
|
105
163
|
## Installation
|
@@ -140,6 +198,7 @@ Note that this documentation is updated automatically from the main branch, so i
|
|
140
198
|
- [Turbo Test Assertions](https://rubydoc.info/github/hotwired/turbo-rails/main/Turbo/TestAssertions)
|
141
199
|
- [Turbo Integration Test Assertions](https://rubydoc.info/github/hotwired/turbo-rails/main/Turbo/TestAssertions/IntegrationTestAssertions)
|
142
200
|
- [Turbo Broadcastable Test Helper](https://rubydoc.info/github/hotwired/turbo-rails/main/Turbo/Broadcastable/TestHelper)
|
201
|
+
- [Turbo System Test Helper](https://rubydoc.info/github/hotwired/turbo-rails/main/Turbo/SystemTestHelper)
|
143
202
|
|
144
203
|
## Compatibility with Rails UJS
|
145
204
|
|