render_turbo_stream 0.1.15 → 0.1.17
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +19 -17
- data/app/views/render_turbo_stream_partials.html.erb +11 -0
- data/lib/render_turbo_stream/test_helpers.rb +21 -0
- data/lib/render_turbo_stream/version.rb +1 -1
- data/lib/render_turbo_stream.rb +3 -1
- metadata +7 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: da571baa70cde46b6b14ba89a0a03f03077c0793b10859635fbdaf63b6a3cfe9
|
4
|
+
data.tar.gz: 3693163b941c92eb9c2c7db6039b466bfeb89ab964653ab1c96ef76c41f035f9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 36c87925c827b81a718e0d97cf302f31530541f359474d31a4ad3dc76012f3bd6d075d27b9f0d1d006033011d2096184264169988b87403de20080058b1877e8
|
7
|
+
data.tar.gz: bad186cba162fea280c24dfc14b9438b8bf60ce913fc97cb3571c0a0ac5de9432aa8bd1e58d86b8cb9991774a027fc7c61c64d97fa94127481124792e8e25d5d
|
data/README.md
CHANGED
@@ -79,22 +79,26 @@ stream_partial(
|
|
79
79
|
|
80
80
|
## Testing
|
81
81
|
|
82
|
-
For system testing
|
82
|
+
For system testing there is capybara.
|
83
83
|
|
84
|
-
For
|
84
|
+
For Tests on request level there are some helpers:
|
85
85
|
|
86
|
-
If
|
87
|
-
`response.body` returns a `json` where the key is the `html-ID` that is used by turbo-stream with the properties of the partials. Testing by rspec could look like this:
|
86
|
+
If request format is not `turbo_stream`, which is the case on request specs, the method responds in a html by a special format that can easily be checked by included test-helpers. So, tests could look like this:
|
88
87
|
|
89
88
|
```ruby
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
89
|
+
require 'rails_helper'
|
90
|
+
include RenderTurboStream::TestHelpers
|
91
|
+
|
92
|
+
RSpec.describe "Articles", type: :request do
|
93
|
+
let(:invalid_params) { { article: { title: '', desciption: 'abc' } } }
|
94
|
+
it 'update failed' do
|
95
|
+
a = FactoryBot.create(:article)
|
96
|
+
patch article_path(a, params: invalid_params)
|
97
|
+
expect(response.status).to eq(422)
|
98
|
+
expect(rendered_partials_count).to eq(2)
|
99
|
+
expect(rendered_partials).to include('articles/form', 'layouts/flash')
|
100
|
+
expect(streamed_ids).to include('form', 'flash-box')
|
101
|
+
end
|
98
102
|
end
|
99
103
|
```
|
100
104
|
|
@@ -102,11 +106,9 @@ Test for a redirection could look like this:
|
|
102
106
|
|
103
107
|
```ruby
|
104
108
|
it 'update success' do
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
r = JSON.parse(response.body)
|
109
|
-
expect(r['redirected_to']).to eq(articles_path)
|
109
|
+
a = FactoryBot.create(:article)
|
110
|
+
patch article_path(a, params: valid_params)
|
111
|
+
expect(turbo_redirected_to).to eq(articles_path) #=> turbo_redirected_to includes a «expect(response.status).to eq(302)»
|
110
112
|
end
|
111
113
|
```
|
112
114
|
|
@@ -0,0 +1,11 @@
|
|
1
|
+
<% partials_count = 0 %>
|
2
|
+
<% rendered_partials = [] %>
|
3
|
+
<% streams.each do |s| %>
|
4
|
+
<% render s[:partial], locals: s[:locals], formats: [:html ] %>
|
5
|
+
<% partials_count += 1 %>
|
6
|
+
<% rendered_partials.push(s[:partial]) %>
|
7
|
+
<% end %>
|
8
|
+
|
9
|
+
|
10
|
+
<%= content_tag :div, check.to_json, id: 'check-json' %>
|
11
|
+
<%= content_tag :div, rendered_partials.to_json, id: 'rendered-partials' %>
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module RenderTurboStream
|
2
|
+
module TestHelpers
|
3
|
+
def streamed_ids
|
4
|
+
e = Nokogiri::HTML(response.body).search('#check-json').first
|
5
|
+
JSON.parse(e.inner_html).keys
|
6
|
+
end
|
7
|
+
def rendered_partials
|
8
|
+
e = Nokogiri::HTML(response.body).search('#rendered-partials').first
|
9
|
+
JSON.parse(e.inner_html)
|
10
|
+
end
|
11
|
+
|
12
|
+
def rendered_partials_count
|
13
|
+
rendered_partials.length
|
14
|
+
end
|
15
|
+
def turbo_redirected_to
|
16
|
+
expect(response.status).to eq(302)
|
17
|
+
r = JSON.parse(response.body)
|
18
|
+
r['redirected_to']
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/lib/render_turbo_stream.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require "render_turbo_stream/version"
|
2
2
|
require "render_turbo_stream/railtie"
|
3
3
|
require 'render_turbo_stream/engine'
|
4
|
+
require 'render_turbo_stream/test_helpers'
|
4
5
|
|
5
6
|
module RenderTurboStream
|
6
7
|
|
@@ -155,7 +156,8 @@ module RenderTurboStream
|
|
155
156
|
b.delete(:id)
|
156
157
|
check[a[:id]] = b
|
157
158
|
end
|
158
|
-
render json: check
|
159
|
+
#render json: check
|
160
|
+
render template: 'render_turbo_stream_partials', locals: { check: check, streams: ary }, layout: false, formats: :html
|
159
161
|
end
|
160
162
|
end
|
161
163
|
|
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: 0.1.
|
4
|
+
version: 0.1.17
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- christian
|
@@ -25,9 +25,9 @@ dependencies:
|
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: 7.0.4.3
|
27
27
|
description: 'Writing views like (create|update).turbo_stream.haml annoyed me. This
|
28
|
-
gem handles translated flash messages, sets status, and renders turbo-stream
|
29
|
-
You can control
|
30
|
-
|
28
|
+
gem handles translated flash messages, sets status, and renders partials by turbo-stream.
|
29
|
+
You can control them directly from the controller. It also handles redirection:
|
30
|
+
turbo_power is included.'
|
31
31
|
email:
|
32
32
|
- christian@sedlmair.ch
|
33
33
|
executables: []
|
@@ -37,11 +37,13 @@ files:
|
|
37
37
|
- README.md
|
38
38
|
- Rakefile
|
39
39
|
- app/controllers/render_turbo_stream/application_controller.rb
|
40
|
+
- app/views/render_turbo_stream_partials.html.erb
|
40
41
|
- app/views/render_turbo_stream_partials.turbo_stream.erb
|
41
42
|
- app/views/render_turbo_stream_redirect.turbo_stream.erb
|
42
43
|
- lib/render_turbo_stream.rb
|
43
44
|
- lib/render_turbo_stream/engine.rb
|
44
45
|
- lib/render_turbo_stream/railtie.rb
|
46
|
+
- lib/render_turbo_stream/test_helpers.rb
|
45
47
|
- lib/render_turbo_stream/version.rb
|
46
48
|
- lib/tasks/render_turbo_stream_tasks.rake
|
47
49
|
homepage: https://gitlab.com/sedl/renderturbostream
|
@@ -69,5 +71,5 @@ requirements: []
|
|
69
71
|
rubygems_version: 3.4.12
|
70
72
|
signing_key:
|
71
73
|
specification_version: 4
|
72
|
-
summary:
|
74
|
+
summary: Render turbo-stream partials directly from the controller
|
73
75
|
test_files: []
|