turbo-rails 2.0.6 → 2.0.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +69 -1
- 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/helpers/turbo/streams_helper.rb +6 -0
- 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 +26 -34
- data/config/routes.rb +3 -3
- data/lib/tasks/turbo_tasks.rake +0 -22
- data/lib/turbo/engine.rb +51 -6
- data/lib/turbo/system_test_helper.rb +128 -0
- data/lib/turbo/version.rb +1 -1
- metadata +3 -17
- data/lib/install/turbo_needs_redis.rb +0 -20
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4727e6617dc1c23ff57cb213e98eb3fd3aa11a364451d10622034c9514cb658a
|
4
|
+
data.tar.gz: d20337dc3363beb18a4c5ef1b57cef22643ba2d654294daa84ce7a447645dc55
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 32987a0bdfce8ac6a2050e7190293f5eddabf9e6349b9d228a557153d27adda86d760dcdf4fdcd3ccc00a8fd8ccb9ed945101898d6c4636cba8289835ea89ed1
|
7
|
+
data.tar.gz: c5382c8d5504679799bdb22c30b73b0f057ac4c1ab818d386a23da0925e2f743f4c5f630fc33c6c9795394ef0f4fef199d661343cc1664e2156edc081ee885b0
|
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
|
@@ -109,7 +167,6 @@ This gem is automatically configured for applications made with Rails 7+ (unless
|
|
109
167
|
1. Add the `turbo-rails` gem to your Gemfile: `gem 'turbo-rails'`
|
110
168
|
2. Run `./bin/bundle install`
|
111
169
|
3. Run `./bin/rails turbo:install`
|
112
|
-
4. Run `./bin/rails turbo:install:redis` to change the development Action Cable adapter from Async (the default one) to Redis. The Async adapter does not support Turbo Stream broadcasting.
|
113
170
|
|
114
171
|
Running `turbo:install` will install through NPM or Bun if a JavaScript runtime is used in the application. Otherwise the asset pipeline version is used. To use the asset pipeline version, you must have `importmap-rails` installed first and listed higher in the Gemfile.
|
115
172
|
|
@@ -125,6 +182,8 @@ import "@hotwired/turbo-rails"
|
|
125
182
|
|
126
183
|
You can watch [the video introduction to Hotwire](https://hotwired.dev/#screencast), which focuses extensively on demonstrating Turbo in a Rails demo. Then you should familiarize yourself with [Turbo handbook](https://turbo.hotwired.dev/handbook/introduction) to understand Drive, Frames, and Streams in-depth. Finally, dive into the code documentation by starting with [`Turbo::FramesHelper`](https://github.com/hotwired/turbo-rails/blob/main/app/helpers/turbo/frames_helper.rb), [`Turbo::StreamsHelper`](https://github.com/hotwired/turbo-rails/blob/main/app/helpers/turbo/streams_helper.rb), [`Turbo::Streams::TagBuilder`](https://github.com/hotwired/turbo-rails/blob/main/app/models/turbo/streams/tag_builder.rb), and [`Turbo::Broadcastable`](https://github.com/hotwired/turbo-rails/blob/main/app/models/concerns/turbo/broadcastable.rb).
|
127
184
|
|
185
|
+
Note that in development, the default Action Cable adapter is the single-process `async` adapter. This means that turbo updates are only broadcast within that same process. So you can't start `bin/rails console` and trigger Turbo broadcasts and expect them to show up in a browser connected to a server running in a separate `bin/dev` or `bin/rails server` process. Instead, you should use the web-console when needing to manaually trigger Turbo broadcasts inside the same process. Add "console" to any action or "<%= console %>" in any view to make the web console appear.
|
186
|
+
|
128
187
|
### RubyDoc Documentation
|
129
188
|
|
130
189
|
For the API documentation covering this gem's classes and packages, [visit the RubyDoc page](https://rubydoc.info/github/hotwired/turbo-rails/main).
|
@@ -139,6 +198,7 @@ Note that this documentation is updated automatically from the main branch, so i
|
|
139
198
|
- [Turbo Test Assertions](https://rubydoc.info/github/hotwired/turbo-rails/main/Turbo/TestAssertions)
|
140
199
|
- [Turbo Integration Test Assertions](https://rubydoc.info/github/hotwired/turbo-rails/main/Turbo/TestAssertions/IntegrationTestAssertions)
|
141
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)
|
142
202
|
|
143
203
|
## Compatibility with Rails UJS
|
144
204
|
|
@@ -194,6 +254,14 @@ yarn build
|
|
194
254
|
|
195
255
|
Now you can reference your version of turbo-rails in your Rails projects packaged with your local version of Turbo.
|
196
256
|
|
257
|
+
## Contributing
|
258
|
+
|
259
|
+
Having a way to reproduce your issue will help people confirm, investigate, and ultimately fix your issue. You can do this by providing an executable test case. To make this process easier, we have prepared an [executable bug report Rails application](./bug_report_template.rb) for you to use as a starting point.
|
260
|
+
|
261
|
+
This template includes the boilerplate code to set up a System Test case. Copy the content of the template into a `.rb` file and make the necessary changes to demonstrate the issue. You can execute it by running `ruby the_file.rb` in your terminal. If all goes well, you should see your test case failing.
|
262
|
+
|
263
|
+
You can then share your executable test case as a gist or paste the content into the issue description.
|
264
|
+
|
197
265
|
## License
|
198
266
|
|
199
267
|
Turbo is released under the [MIT License](https://opensource.org/licenses/MIT).
|