render_turbo_stream 0.1.21 → 0.1.23
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +11 -3
- data/app/views/render_turbo_stream_partials.html.erb +3 -4
- data/lib/render_turbo_stream/test_helpers.rb +10 -0
- data/lib/render_turbo_stream/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '069a772b55fc6e97d5f2531266ef3f0a970dbed0b57aa644bf695842a27c270d'
|
4
|
+
data.tar.gz: 052fde88674234ea7201071bb167ee9a41f561b1e40e462fe05b67806b082825
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cf48a259accc4c6e05e17ddba1bb2ec5d43420e88543ac75249d0fcd38dd5237d86eee3bef77413a46a9f5b12a864a450bcfba9c1887a5c863b11280a428b127
|
7
|
+
data.tar.gz: 0b4faa3880918c36be6015811e3fd689330f36890f7d43a48119f2737cc3d6ab0bfd23466efd17a1073bbd260bc8a10def8f22b0ca942d4d58890c820a0d7f7f
|
data/README.md
CHANGED
@@ -79,34 +79,42 @@ stream_partial(
|
|
79
79
|
|
80
80
|
## Testing
|
81
81
|
|
82
|
-
For system testing,
|
82
|
+
For system testing we have Capybara. This works great and is necessary, but it is good practice to break tests into smaller pieces.
|
83
83
|
|
84
84
|
For request-level tests, there are some helpers:
|
85
85
|
|
86
|
-
If the request format is not `turbo_stream`, which is the case on request specs, the method responds in a special
|
86
|
+
If the request format is not `turbo_stream`, which is the case on request specs, the method responds in a special html that contains the medadata that is interesting for our tests and is parsed by included test helpers. So tests could look like this:
|
87
87
|
|
88
88
|
```ruby
|
89
89
|
require 'rails_helper'
|
90
90
|
include RenderTurboStream::TestHelpers
|
91
91
|
|
92
92
|
RSpec.describe "Articles", type: :request do
|
93
|
+
|
93
94
|
let(:invalid_params) { { article: { title: '', desciption: 'abc' } } }
|
95
|
+
|
94
96
|
it 'create failed' do
|
95
97
|
post articles_path(params: invalid_params)
|
96
98
|
|
97
99
|
expect(response.status).to eq(422)
|
98
100
|
expect(partials_count).to eq(2)
|
99
101
|
|
100
|
-
# .._params means: check the params used to generate the partials.
|
101
102
|
expect(partials_paths).to include('articles/form', 'layouts/flash')
|
102
103
|
expect(partials_ids).to include('form', 'flash-box')
|
103
104
|
|
105
|
+
# ..partials_params_* are the params by what partials are called
|
106
|
+
# id is the id where, by example, a turbo_stream.replace points to
|
104
107
|
expect(partials_params_by_id['flash-box'].length).to eq(1)
|
105
108
|
expect(partials_params_by_id['flash-box'].first['partial']).to eq('layouts/flash')
|
106
109
|
|
110
|
+
# ..partials_html_* is the html returned from the partial as string
|
107
111
|
expect(partials_html_by_id['flash-box'].length).to eq(1)
|
108
112
|
expect(partials_html_by_id['flash-box'].first).to include('Article could not be created')
|
109
113
|
|
114
|
+
# unique_partial returns false if this ID is cero or multiple times rendered to
|
115
|
+
expect(partial_html_by_id_unique('flash-box')).to include('Article could not be created')
|
116
|
+
|
117
|
+
# *_path is the controller_path for calling the partial
|
110
118
|
expect(partials_params_by_path['layouts/flash'].length).to eq(1)
|
111
119
|
expect(partials_params_by_path['layouts/flash'].first['partial']).to eq('layouts/flash')
|
112
120
|
|
@@ -1,13 +1,13 @@
|
|
1
1
|
<% partials_count = 0 %>
|
2
2
|
<% rendered_partials = [] %>
|
3
|
-
<%# htmls = [] %>
|
4
3
|
<% htmls_by_id = {} %>
|
5
4
|
<% params_by_id = {} %>
|
6
5
|
<% htmls_by_path = {} %>
|
7
6
|
<% params_by_path = {} %>
|
7
|
+
|
8
8
|
<% streams.each do |s| %>
|
9
|
+
|
9
10
|
<% html = (render s[:partial], locals: s[:locals], formats: [:html ]) %>
|
10
|
-
<%# htmls.push(html) %>
|
11
11
|
<% htmls_by_id[s[:id]] ||= [] %>
|
12
12
|
<% htmls_by_id[s[:id]].push(html) %>
|
13
13
|
<% params_by_id[s[:id]] ||= [] %>
|
@@ -20,6 +20,7 @@
|
|
20
20
|
|
21
21
|
<% partials_count += 1 %>
|
22
22
|
<% rendered_partials.push(s[:partial]) %>
|
23
|
+
|
23
24
|
<% end %>
|
24
25
|
|
25
26
|
<%= content_tag :div, htmls_by_id.to_json, id: 'htmls_by_id' %>
|
@@ -29,6 +30,4 @@
|
|
29
30
|
<%= content_tag :div, params_by_path.to_json, id: 'params_by_path' %>
|
30
31
|
|
31
32
|
<%= content_tag :div, check.to_json, id: 'check-json' %>
|
32
|
-
<%#= content_tag :div, htmls.to_json, id: 'htmls' %>
|
33
33
|
<%= content_tag :div, rendered_partials.to_json, id: 'rendered-partials' %>
|
34
|
-
<%#= content_tag :div, streams.to_json, id: 'streams' %>
|
@@ -7,6 +7,16 @@ module RenderTurboStream
|
|
7
7
|
JSON.parse(e.inner_html)
|
8
8
|
end
|
9
9
|
|
10
|
+
# returns false if id is cero or multiple times rendered to
|
11
|
+
def partial_html_by_id_unique(id)
|
12
|
+
p = partials_html_by_id[id]
|
13
|
+
if p.length != 1
|
14
|
+
false
|
15
|
+
else
|
16
|
+
p.first
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
10
20
|
def partials_params_by_id
|
11
21
|
e = Nokogiri::HTML(response.body).search('#params_by_id').first
|
12
22
|
JSON.parse(e.inner_html)
|