render_turbo_stream 1.1.0 → 1.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
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1299653f6a308796e690ca3929cd4c1580f707604913583e223a4bf4d398f889
|
4
|
+
data.tar.gz: d6228eb9aeb0e64591b1a066d1007ab665ab634788f8645ad7124063c9ef2c0e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d660266f923b6e6efa8225162b9eab8f0eb56eb0ed9f289601106bc661abd74f2dd6832021133c5b9031314475c657c27a1d34388e2c063fbb84a65cb4680b40
|
7
|
+
data.tar.gz: c511dfd6b6799a9075ab594aa60d806c428cf63abfb42cc6f4cbcdcd718197e67f840e89a799a789375f21dd10bd4c78e7fe3c7e933dd132637a900ff2477909
|
data/README.md
CHANGED
@@ -28,6 +28,7 @@ spec/rails_helper.rb
|
|
28
28
|
```ruby
|
29
29
|
RSpec.configure do |config|
|
30
30
|
config.include RenderTurboStream::Test::RequestHelpers, type: :request
|
31
|
+
config.include RenderTurboStream::Test::RspecRequestHelpers, type: :request #=> if you are on rspec
|
31
32
|
end
|
32
33
|
```
|
33
34
|
|
@@ -100,19 +101,25 @@ If the request format is not `turbo_stream`, which is the case on request specs,
|
|
100
101
|
that contains the medadata that is interesting for our tests and is parsed by included test helpers. So tests could look
|
101
102
|
like this:
|
102
103
|
|
103
|
-
**The
|
104
|
+
**The fastest**
|
104
105
|
|
105
|
-
If you want to check if a controller action succeeded, just check for `response.status`.
|
106
|
+
If you want to check if a controller action succeeded, just check for `response.status`. The `turbo_stream_save` method returns three statuses: `200` if `save_action` is true, otherwise `422` and `302` for redirect. If one of the declared partials does not exist or breaks, the server will respond with exception anyway.
|
107
|
+
|
108
|
+
**rspec**
|
109
|
+
|
110
|
+
For rspec there is a special helper, for a successful save action:
|
106
111
|
|
107
|
-
The `turbo_stream_save` method returns three statuses: `200` if `save_action` is true, otherwise `422` and `302` for redirect. If one of the declared partials does not exist or breaks, the server will respond with exception anyway. So a test might look like this:
|
108
112
|
```ruby
|
109
113
|
it 'update failed' do
|
110
|
-
patch article_path(article, params:
|
111
|
-
|
114
|
+
patch article_path(article, params: valid_params)
|
115
|
+
expect_successful_saved('form', 'flash-box')
|
116
|
+
# expects response.status 200
|
117
|
+
# Make sure that the responses point to exactly these 2 IDs ('form' and 'flash-box').
|
118
|
+
# Make sure that each ID is responded to exactly once.
|
112
119
|
end
|
113
120
|
```
|
114
121
|
|
115
|
-
**
|
122
|
+
**Redirection**
|
116
123
|
```ruby
|
117
124
|
it 'update success' do
|
118
125
|
patch article_path(article, params: valid_params)
|
@@ -134,7 +141,7 @@ expect(partial_response('articles/form', id: 'form', css: '.field_with_errors',
|
|
134
141
|
# Check the content inside at least one in any of the elements that match the given css and check the id that turbo has pointed to..
|
135
142
|
```
|
136
143
|
|
137
|
-
**More detailed
|
144
|
+
**More detailed**
|
138
145
|
|
139
146
|
Consider a controller action that should respond in 2 flashes.
|
140
147
|
|
@@ -155,6 +162,9 @@ expect(
|
|
155
162
|
end
|
156
163
|
).to eq(1)
|
157
164
|
```
|
165
|
+
`partial_response_count` always returns the number of matched responses.
|
166
|
+
|
167
|
+
Possible matches can be found at [Nokogiri](https://nokogiri.org/tutorials/searching_a_xml_html_document.html)
|
158
168
|
|
159
169
|
P.S.:
|
160
170
|
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module RenderTurboStream
|
2
|
+
module Test
|
3
|
+
module RspecRequestHelpers
|
4
|
+
|
5
|
+
|
6
|
+
# expect status 200 and a each one time response to given ids
|
7
|
+
|
8
|
+
def expect_successful_saved(*ids)
|
9
|
+
responses = RenderTurboStream::Libs.all_responses(response)
|
10
|
+
counts = {}
|
11
|
+
responses.each do |r|
|
12
|
+
counts[r['id']] ||= 0
|
13
|
+
counts[r['id']] +=1
|
14
|
+
end
|
15
|
+
|
16
|
+
expect(response.status).to eq(200)
|
17
|
+
expect(counts.keys.length).to eq(ids.length)
|
18
|
+
ids.each do |id|
|
19
|
+
expect(counts.key?(id)).to be_truthy
|
20
|
+
expect(counts[id]).to eq(1)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
data/lib/render_turbo_stream.rb
CHANGED
@@ -2,6 +2,7 @@ require "render_turbo_stream/version"
|
|
2
2
|
require "render_turbo_stream/railtie"
|
3
3
|
require 'render_turbo_stream/engine'
|
4
4
|
require 'render_turbo_stream/test/request_helpers'
|
5
|
+
require 'render_turbo_stream/test/rspec_request_helpers'
|
5
6
|
|
6
7
|
module RenderTurboStream
|
7
8
|
|
@@ -233,6 +234,18 @@ module RenderTurboStream
|
|
233
234
|
part.length
|
234
235
|
end
|
235
236
|
|
237
|
+
def self.partial_ids(response)
|
238
|
+
all = all_responses(response)
|
239
|
+
ids = []
|
240
|
+
all.each do |p|
|
241
|
+
_p = p['id']
|
242
|
+
unless ids.include?(_p)
|
243
|
+
ids.push(_p)
|
244
|
+
end
|
245
|
+
end
|
246
|
+
ids
|
247
|
+
end
|
248
|
+
|
236
249
|
def self.partial_response_count(response, partial, id, total, &block)
|
237
250
|
responses = select_responses(response, partial, id)
|
238
251
|
|
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: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- christian
|
@@ -44,6 +44,7 @@ files:
|
|
44
44
|
- lib/render_turbo_stream/engine.rb
|
45
45
|
- lib/render_turbo_stream/railtie.rb
|
46
46
|
- lib/render_turbo_stream/test/request_helpers.rb
|
47
|
+
- lib/render_turbo_stream/test/rspec_request_helpers.rb
|
47
48
|
- lib/render_turbo_stream/version.rb
|
48
49
|
- lib/tasks/render_turbo_stream_tasks.rake
|
49
50
|
homepage: https://gitlab.com/sedl/renderturbostream
|
@@ -71,5 +72,5 @@ requirements: []
|
|
71
72
|
rubygems_version: 3.4.12
|
72
73
|
signing_key:
|
73
74
|
specification_version: 4
|
74
|
-
summary: Render turbo-stream partials directly from the controller. Test helpers included
|
75
|
+
summary: Render turbo-stream partials directly from the controller. Test helpers included.
|
75
76
|
test_files: []
|