render_turbo_stream 3.0.0 → 3.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 733ef3518b8c95cb2f5162d0abb6d6278e653219bf5a99b502159fa52e884be8
4
- data.tar.gz: b526a407a00b9dee9e5e543a48d80d14c073d87bf2397ea9bf2c0027a3366527
3
+ metadata.gz: 9cac5d85adc90498652f200358ead49b5e70b19f1f4aa9579a17e25ace0bf88b
4
+ data.tar.gz: a326254219215b12c385db45dc8fab88e08d4fe225386f136d02c8366fa21260
5
5
  SHA512:
6
- metadata.gz: edf51ffaf2a192f7eb65f6147ba3d2b64cbb07d0c444a4bc00ec2d7a145cceaac943704ec1b50199e0ac1b4f42e3f524386679d682af728ca0f577b865dc72d9
7
- data.tar.gz: '09e87e2f74275a48a459d47dac942c66787e2127d9cf61e08ff16a3e7dcf5cc63708d4c1b0d4d7fba89a429a0ff76f5e95a491906650ba167bf27bde82784afd'
6
+ metadata.gz: b9d78b3c8e4921c51156c0a2171d016a36e7cef143ca0c9040eb33930f1e6ba2536e6c693764efc84943396a10a327c6f63293b7783666b5d6a592976252b750
7
+ data.tar.gz: ce6336c3c1e3b81af1930e4c50a6c2b4752f207dbcd6da39debbd19ce294b32447a24b5c7be02b1f7bfa3369759bd90ec1659413bc28154b680dfa74ca880ad2
data/README.md CHANGED
@@ -33,7 +33,6 @@ ApplicationController
33
33
 
34
34
  ```ruby
35
35
  include RenderTurboStream::ControllerHelpers
36
- include RenderTurboStream::ControllerChannelHelpers
37
36
  ```
38
37
 
39
38
  spec/rails_helper.rb
@@ -54,7 +53,7 @@ Required Configurations for Flash Partial
54
53
  config.x.render_turbo_stream.flash_partial = 'layouts/flash'
55
54
  config.x.render_turbo_stream.flash_id = 'flash-box'
56
55
  config.x.render_turbo_stream.flash_action = 'prepend'
57
- config.x.render_turbo_stream.use_cable_for_turbo_stream_save = true
56
+ config.x.render_turbo_stream.use_channel_for_turbo_stream_save = true
58
57
  ```
59
58
 
60
59
  The corresponding partials for flashes could look [like this](https://gitlab.com/sedl/renderturbostream/-/wikis/Flashes-example)
@@ -82,7 +81,7 @@ A comprehensive tutorial on turbo and how to check that it is working properly c
82
81
 
83
82
  **Turbo::StreamsChannel**
84
83
 
85
- The Rails team has integrated `ActionCable` as `Turbo::StreamsChannel` into `Turbo Rails`. For installation along with this gem, see the [README](https://gitlab.com/sedl/renderturbostream/-/blob/main/README-channels.md).
84
+ The Rails team has integrated `ActionCable` as `Turbo::StreamsChannel` into `Turbo Rails`. For installation along with this gem, see the [README-channels](https://gitlab.com/sedl/renderturbostream/-/blob/main/README-channels.md).
86
85
 
87
86
  # Usage
88
87
 
@@ -159,7 +158,7 @@ Suppose you have a CRUD controller that should do all its actions inside a turbo
159
158
  There are two workarounds:
160
159
 
161
160
  ```ruby
162
- config.x.render_turbo_stream.use_cable_for_turbo_stream_save = true
161
+ config.x.render_turbo_stream.use_channel_for_turbo_stream_save = true
163
162
  ```
164
163
 
165
164
  With this config, the `turbo_stream_save` method will send flash messages through `Turbo::StreamsChannel` (if installed as described above) to a channel to the currently logged in user in parallel with the redirect.
@@ -1,5 +1,6 @@
1
1
  module RenderTurboStream
2
2
  class ChannelLibs
3
+
3
4
  def self.render_to_channel(response, channel, target_id, action, partial: nil, template: nil, locals: nil)
4
5
 
5
6
  locals = {} unless locals # prevent error missing keys for nil
@@ -1,6 +1,10 @@
1
1
  module RenderTurboStream
2
2
  module ControllerHelpers
3
3
 
4
+ # Handles translated flash messages as defined in translations and configs.
5
+ # If :redirect_on_success_to and channel set up and use_channel_for_turbo_stream_save are configured, sends flash message by channel_to_me.
6
+ # you can add more stream actions to the same response
7
+
4
8
  def turbo_stream_save(
5
9
  save_action,
6
10
  redirect_on_success_to: nil, # does a regular redirect. Works if you are inside a turbo_frame and just want to redirect inside that frame BUT CANNOT STREAM OTHERS ACTIONS ON THE SAME RESPONSE https://github.com/rails/rails/issues/48056
@@ -151,7 +155,7 @@ module RenderTurboStream
151
155
  ])
152
156
  elsif save_action && redirect_on_success_to.present?
153
157
  response.status = 302
154
- if Rails.configuration.x.render_turbo_stream.use_cable_for_turbo_stream_save && helpers.user_signed_in?
158
+ if Rails.configuration.x.render_turbo_stream.use_channel_for_turbo_stream_save && helpers.user_signed_in?
155
159
  streams.each do |s|
156
160
  next unless s.is_a?(Hash)
157
161
  Rails.logger.debug(" • Send by Cable => «#{s}»")
@@ -178,6 +182,8 @@ module RenderTurboStream
178
182
  end
179
183
  end
180
184
 
185
+
186
+ # renders a array of partials to send by turbo-stream and / or actions like turbo_power gem includes, to turbo_stream
181
187
  def render_turbo_stream(array)
182
188
 
183
189
  ary = []
@@ -211,6 +217,8 @@ module RenderTurboStream
211
217
 
212
218
  end
213
219
 
220
+ # renders a partial to turbo_stream
221
+
214
222
  def stream_partial(
215
223
  id,
216
224
  partial: nil, #=> default: id
@@ -3,6 +3,8 @@ module RenderTurboStream
3
3
  module Request
4
4
  module ChannelHelpers
5
5
 
6
+ # Assert a action by turbo streams channel to the current_user
7
+
6
8
  def assert_channel_to_me(user, target_id, action: nil, count: 1, &block)
7
9
 
8
10
  channel = "authenticated-user-#{user.id}"
@@ -17,6 +19,8 @@ module RenderTurboStream
17
19
  )
18
20
  end
19
21
 
22
+ # Assert a action by turbo streams channel to a group of authenticated users
23
+
20
24
  def assert_channel_to_authenticated_group(group, target_id, action: nil, count: 1, &block)
21
25
 
22
26
  channel = "authenticated-group-#{group}"
@@ -31,6 +35,8 @@ module RenderTurboStream
31
35
  )
32
36
  end
33
37
 
38
+ # Assert a action by turbo streams channel to all visitors of the page
39
+
34
40
  def assert_channel_to_all(target_id, action: nil, count: 1, &block)
35
41
 
36
42
  libs = RenderTurboStream::Test::Request::Libs
@@ -3,6 +3,8 @@ module RenderTurboStream
3
3
  module Request
4
4
  module Helpers
5
5
 
6
+ # Assert that each of given target_ids is targeted exactly once
7
+
6
8
  def assert_once_targeted(*target_ids)
7
9
  responses = RenderTurboStream::Test::Request::Libs.all_turbo_responses(response)
8
10
  id_counts = {}
@@ -28,27 +30,18 @@ module RenderTurboStream
28
30
  end
29
31
  end
30
32
 
33
+ # Helper for the developer for writing tests: Array with all attributes of all turbo-stream and turbo-channel actions that runned on the last request
34
+
31
35
  def all_turbo_responses
32
36
  RenderTurboStream::Test::Request::Libs.all_turbo_responses(response)
33
37
  end
34
38
 
39
+ # Returns Array of all target_ids that arre affected at least once on the last response
35
40
  def turbo_targets
36
41
  RenderTurboStream::Test::Request::Libs.turbo_targets(response)
37
42
  end
38
43
 
39
- def assert_response(target_id, type = nil, action: nil, count: 1, &block)
40
-
41
- libs = RenderTurboStream::Test::Request::Libs
42
-
43
- r = libs.select_responses(response, false, target_id, action, type: type, &block)
44
-
45
- assert(
46
- r[:responses].length == count,
47
- libs.assert_error_message(count, r[:responses].length, r[:log])
48
- )
49
- end
50
-
51
- # Returns the path to which turbo_stream.redirect_to would be applied.
44
+ # Returns the path sent to turbo_stream.redirect_to.
52
45
  def turbo_redirect_to
53
46
  resps = RenderTurboStream::Test::Request::Libs.all_turbo_responses(response)
54
47
  url = nil
@@ -66,11 +59,12 @@ module RenderTurboStream
66
59
  url
67
60
  end
68
61
 
69
- def assert_stream_response(target_id, action: nil, count: 1, &block)
62
+ # assert one or more specific actions to a target_id
63
+ def assert_stream_response(target_id, action: nil, count: 1, type: :stream, &block)
70
64
 
71
65
  libs = RenderTurboStream::Test::Request::Libs
72
66
 
73
- r = libs.select_responses(response, false, target_id, action, type: :stream, &block)
67
+ r = libs.select_responses(response, false, target_id, action, type: type, &block)
74
68
 
75
69
  assert(
76
70
  r[:responses].length == count,
@@ -149,6 +149,7 @@ module RenderTurboStream
149
149
  ]
150
150
  (config.present? ? config : default).map { |m| m.to_sym }.include?(method.to_sym)
151
151
  end
152
+
152
153
  end
153
154
  end
154
155
  end
@@ -1,3 +1,3 @@
1
1
  module RenderTurboStream
2
- VERSION = "3.0.0"
2
+ VERSION = "3.0.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: render_turbo_stream
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.0
4
+ version: 3.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - christian
@@ -80,6 +80,6 @@ requirements: []
80
80
  rubygems_version: 3.4.12
81
81
  signing_key:
82
82
  specification_version: 4
83
- summary: Complete rails-like workflow for turbo streams and channels. With testing
84
- strategy.
83
+ summary: Complete workflow for turbo streams and channels. With testing strategy.
84
+ Rails like.
85
85
  test_files: []