render_turbo_stream 0.1.20 → 0.1.21

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: 5c9a8ce6edc86ce1bf4adb28042784f90665fb915d32c663899fa66fa6f6a764
4
- data.tar.gz: cb31e25e686751127e6eb21562ab31bb0a15c25a7760691be2ace27fd32872a2
3
+ metadata.gz: 9b84c79cfe97c99b55813d6a22ebcf0267e6dc7ee66b9a6c8bb922c8f5cf812b
4
+ data.tar.gz: 420971446a65cbda6c141be9c32941ddf991944cbb3c84f9f2eb259cf077c3b6
5
5
  SHA512:
6
- metadata.gz: 073a9bd4038390487978547dfd72e566744bba02032b7fc43989a5914b5dcde55612009774828101f88467ba37b86bb73693d0819441f6ddf7f3bc5fbd0b5736
7
- data.tar.gz: 41836ea59255674882a518e861526d9d9460bb786943e5651304f48670e7af2cf7feedc5a6a7c2ae924b45f785f3b2e957afe4cb5bd454ab06869c5781dfa6af
6
+ metadata.gz: 3bc0935233cc25323b8f92e12227308d680b24d6ea532786e685c75d6500158d68991dd9babe5d2bc1424ca8c93f43912528cc8a4abac6363c636331d8929fd5
7
+ data.tar.gz: f2ee4939746a8b7d4dc06df81920e55baa3c5bce6ee26b04778b91e5067ffb846e436fddeed2c4868f9ea9b0ca5876a8f4e29a65f146fc438c362bfbc7c13c05
data/README.md CHANGED
@@ -93,22 +93,25 @@ RSpec.describe "Articles", type: :request do
93
93
  let(:invalid_params) { { article: { title: '', desciption: 'abc' } } }
94
94
  it 'create failed' do
95
95
  post articles_path(params: invalid_params)
96
+
96
97
  expect(response.status).to eq(422)
97
- expect(rendered_partials_count).to eq(2)
98
+ expect(partials_count).to eq(2)
98
99
 
99
100
  # .._params means: check the params used to generate the partials.
100
- expect(rendered_partials_paths).to include('articles/form', 'layouts/flash')
101
- expect(rendered_ids).to include('form', 'flash-box')
102
- expect(rendered_partials_params_find_id('flash-box')['partial']).to eq('layouts/flash')
103
- expect(rendered_partials_params_where_id('flash-box').first['partial']).to eq('layouts/flash')
104
- expect(rendered_partials_params_where_id('flash-box').is_a?(Array)).to eq(true)
105
-
106
- # check html (returned as string) resulting from the rendered partials
107
- h = rendered_partials_html
108
- expect(h.join('')).to include('Article could not be created')
109
- h = rendered_partials_html_by_id
110
- expect(h['flash-box'].first).to include('Article could not be created')
111
- expect(h['flash-box'].length).to eq(1)
101
+ expect(partials_paths).to include('articles/form', 'layouts/flash')
102
+ expect(partials_ids).to include('form', 'flash-box')
103
+
104
+ expect(partials_params_by_id['flash-box'].length).to eq(1)
105
+ expect(partials_params_by_id['flash-box'].first['partial']).to eq('layouts/flash')
106
+
107
+ expect(partials_html_by_id['flash-box'].length).to eq(1)
108
+ expect(partials_html_by_id['flash-box'].first).to include('Article could not be created')
109
+
110
+ expect(partials_params_by_path['layouts/flash'].length).to eq(1)
111
+ expect(partials_params_by_path['layouts/flash'].first['partial']).to eq('layouts/flash')
112
+
113
+ expect(partials_html_by_path['layouts/flash'].length).to eq(1)
114
+ expect(partials_html_by_path['layouts/flash'].first).to include('Article could not be created')
112
115
  end
113
116
  end
114
117
  ```
@@ -1,19 +1,34 @@
1
1
  <% partials_count = 0 %>
2
2
  <% rendered_partials = [] %>
3
- <% htmls = [] %>
3
+ <%# htmls = [] %>
4
4
  <% htmls_by_id = {} %>
5
+ <% params_by_id = {} %>
6
+ <% htmls_by_path = {} %>
7
+ <% params_by_path = {} %>
5
8
  <% streams.each do |s| %>
6
9
  <% html = (render s[:partial], locals: s[:locals], formats: [:html ]) %>
7
- <% htmls.push(html) %>
10
+ <%# htmls.push(html) %>
8
11
  <% htmls_by_id[s[:id]] ||= [] %>
9
12
  <% htmls_by_id[s[:id]].push(html) %>
13
+ <% params_by_id[s[:id]] ||= [] %>
14
+ <% params_by_id[s[:id]].push(s) %>
15
+
16
+ <% htmls_by_path[s[:partial]] ||= [] %>
17
+ <% htmls_by_path[s[:partial]].push(html) %>
18
+ <% params_by_path[s[:partial]] ||= [] %>
19
+ <% params_by_path[s[:partial]].push(s) %>
20
+
10
21
  <% partials_count += 1 %>
11
22
  <% rendered_partials.push(s[:partial]) %>
12
23
  <% end %>
13
24
 
25
+ <%= content_tag :div, htmls_by_id.to_json, id: 'htmls_by_id' %>
26
+ <%= content_tag :div, params_by_id.to_json, id: 'params_by_id' %>
27
+
28
+ <%= content_tag :div, htmls_by_path.to_json, id: 'htmls_by_path' %>
29
+ <%= content_tag :div, params_by_path.to_json, id: 'params_by_path' %>
14
30
 
15
31
  <%= content_tag :div, check.to_json, id: 'check-json' %>
16
- <%= content_tag :div, htmls.to_json, id: 'htmls' %>
17
- <%= content_tag :div, htmls_by_id.to_json, id: 'htmls_by_id' %>
32
+ <%#= content_tag :div, htmls.to_json, id: 'htmls' %>
18
33
  <%= content_tag :div, rendered_partials.to_json, id: 'rendered-partials' %>
19
- <%= content_tag :div, streams.to_json, id: 'streams' %>
34
+ <%#= content_tag :div, streams.to_json, id: 'streams' %>
@@ -1,44 +1,47 @@
1
1
  module RenderTurboStream
2
2
  module TestHelpers
3
- def rendered_ids
4
- e = Nokogiri::HTML(response.body).search('#check-json').first
5
- JSON.parse(e.inner_html).keys
3
+
4
+ # returns hash of arrays with responded html(as string) contents by ID
5
+ def partials_html_by_id
6
+ e = Nokogiri::HTML(response.body).search('#htmls_by_id').first
7
+ JSON.parse(e.inner_html)
6
8
  end
7
9
 
8
- # returns array of strings of rendered partials inner-html
9
- def rendered_partials_html
10
- e = Nokogiri::HTML(response.body).search('#htmls').first
10
+ def partials_params_by_id
11
+ e = Nokogiri::HTML(response.body).search('#params_by_id').first
11
12
  JSON.parse(e.inner_html)
12
13
  end
13
14
 
14
- # returns hash of arrays with responded html(as string) contents by ID
15
- def rendered_partials_html_by_id
16
- e = Nokogiri::HTML(response.body).search('#htmls_by_id').first
15
+ # returns hash of arrays with responded html(as string) contents by partial-path
16
+ def partials_html_by_path
17
+ e = Nokogiri::HTML(response.body).search('#htmls_by_path').first
17
18
  JSON.parse(e.inner_html)
18
19
  end
19
20
 
20
- # array of strings of paths by them rendered partials are called, example: ['articles/form']
21
- def rendered_partials_paths
22
- e = Nokogiri::HTML(response.body).search('#rendered-partials').first
21
+ # returns hash of arrays with params by them rendered partials are called
22
+ def partials_params_by_path
23
+ e = Nokogiri::HTML(response.body).search('#params_by_path').first
23
24
  JSON.parse(e.inner_html)
24
25
  end
25
26
 
26
- # returns all partials that would be streamed to a given ID
27
- # note: if more than one partial by turbo_stream.replace are streamed to same ID, render_turbo_stream, in test mode already throws a error
28
- def rendered_partials_params_where_id(id)
29
- partials = Nokogiri::HTML(response.body).search('#streams').first
30
- h = JSON.parse(partials.inner_html)
31
- h.select{|e| e['id'] == id}
27
+ # count of rendered parials
28
+ def partials_count
29
+ partials_paths.length
32
30
  end
33
31
 
34
- # returns the first partial that would be streamed to a given ID
35
- def rendered_partials_params_find_id(id)
36
- rendered_partials_params_where_id(id).first
32
+ # array of strings of rendered partial ids
33
+ def partials_ids
34
+ e = Nokogiri::HTML(response.body).search('#check-json').first
35
+ JSON.parse(e.inner_html).keys
37
36
  end
38
37
 
39
- def rendered_partials_count
40
- rendered_partials_paths.length
38
+ # array of strings of paths by them rendered partials are called, example: ['articles/form']
39
+ def partials_paths
40
+ e = Nokogiri::HTML(response.body).search('#rendered-partials').first
41
+ JSON.parse(e.inner_html)
41
42
  end
43
+
44
+ # check response status and return redirected_to path
42
45
  def turbo_redirected_to
43
46
  expect(response.status).to eq(302)
44
47
  r = JSON.parse(response.body)
@@ -1,3 +1,3 @@
1
1
  module RenderTurboStream
2
- VERSION = "0.1.20"
2
+ VERSION = "0.1.21"
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: 0.1.20
4
+ version: 0.1.21
5
5
  platform: ruby
6
6
  authors:
7
7
  - christian