render_turbo_stream 0.1.19 → 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: f816fb8eab0243274dc8b448982358b90e12fe3d7d431f104dd12d3e56d2aacb
4
- data.tar.gz: 1b515e61a40ac0126aba2cc43940b181f3fca19e3305320d13eb0e5848f4fc7e
3
+ metadata.gz: 9b84c79cfe97c99b55813d6a22ebcf0267e6dc7ee66b9a6c8bb922c8f5cf812b
4
+ data.tar.gz: 420971446a65cbda6c141be9c32941ddf991944cbb3c84f9f2eb259cf077c3b6
5
5
  SHA512:
6
- metadata.gz: a98cc8fff61ac5044c0af6051a59262383b1f41d5b1559bcfc2ccd3b87e46df14a576fd7615286c51617e76b2570046f84c10dade94c71c9757103fe29116a3b
7
- data.tar.gz: c09722e38db120023eb577187ef4f7c1b1e3562a6ab6af6cf9ed3f86f2b8acf36df96d1aa621cbc796ad73cf272d9adbb67d9ebd2f3872cbfcc73447b9041438
6
+ metadata.gz: 3bc0935233cc25323b8f92e12227308d680b24d6ea532786e685c75d6500158d68991dd9babe5d2bc1424ca8c93f43912528cc8a4abac6363c636331d8929fd5
7
+ data.tar.gz: f2ee4939746a8b7d4dc06df81920e55baa3c5bce6ee26b04778b91e5067ffb846e436fddeed2c4868f9ea9b0ca5876a8f4e29a65f146fc438c362bfbc7c13c05
data/README.md CHANGED
@@ -22,7 +22,7 @@ ApplicationController
22
22
  include RenderTurboStream
23
23
  ```
24
24
 
25
- necessary configs for flash partials
25
+ Required Configurations for Flash Partial
26
26
 
27
27
  ```ruby
28
28
  config.x.render_turbo_stream.flash_partial = 'layouts/flash'
@@ -34,7 +34,7 @@ The corresponding partials for flashes could look [like this](https://gitlab.com
34
34
 
35
35
  ## Usage
36
36
 
37
- `turbo_stream_save` is a special method for streamline `update` or `create` functions for `turbo_stream`, which could look like so:
37
+ `turbo_stream_save` is a special method for streamlining `update` or `create` functions for `turbo_stream`, which might look like this:
38
38
 
39
39
  ```ruby
40
40
  def create
@@ -48,7 +48,7 @@ The corresponding partials for flashes could look [like this](https://gitlab.com
48
48
  end
49
49
  ```
50
50
 
51
- This sets a status, generates a flash message and performs `stream_partials`, which could result like that:
51
+ This will set a status, generate a flash message and perform `stream_partials', which could result in something like this:
52
52
 
53
53
  ```ruby
54
54
  stream_partials(
@@ -66,7 +66,7 @@ stream_partials(
66
66
  )
67
67
  ```
68
68
 
69
- The `stream_partial` method is nothing else than a singular of `stream_partials`
69
+ The `stream_partial' method is nothing more than a singular of `stream_partials'.
70
70
 
71
71
  ```ruby
72
72
  stream_partial(
@@ -79,11 +79,11 @@ stream_partial(
79
79
 
80
80
  ## Testing
81
81
 
82
- For system testing there is capybara.
82
+ For system testing, there is Capybara.
83
83
 
84
- For Tests on request level there are some helpers:
84
+ For request-level tests, there are some helpers:
85
85
 
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:
86
+ If the request format is not `turbo_stream`, which is the case on request specs, the method responds in a special format html that can be easily checked by included test helpers. So tests could look like this:
87
87
 
88
88
  ```ruby
89
89
  require 'rails_helper'
@@ -91,18 +91,32 @@ include RenderTurboStream::TestHelpers
91
91
 
92
92
  RSpec.describe "Articles", type: :request do
93
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)
94
+ it 'create failed' do
95
+ post articles_path(params: invalid_params)
96
+
97
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')
98
+ expect(partials_count).to eq(2)
99
+
100
+ # .._params means: check the params used to generate the partials.
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')
101
115
  end
102
116
  end
103
117
  ```
104
118
 
105
- Test for a redirection could look like this:
119
+ The test for a redirection might look something like this:
106
120
 
107
121
  ```ruby
108
122
  it 'update success' do
@@ -112,6 +126,10 @@ it 'update success' do
112
126
  end
113
127
  ```
114
128
 
129
+ P.S.:
130
+
131
+ Testing the plugin itself: There is a [quick-and-dirty app](https://gitlab.com/sedl/renderturbostream_railsapp) which includes the plugin and has tests done by rspec/request and capybara.
132
+
115
133
  ## Parameters
116
134
 
117
135
  `save_action` (first parameter, boolean) true if successful
@@ -1,11 +1,34 @@
1
1
  <% partials_count = 0 %>
2
2
  <% rendered_partials = [] %>
3
+ <%# htmls = [] %>
4
+ <% htmls_by_id = {} %>
5
+ <% params_by_id = {} %>
6
+ <% htmls_by_path = {} %>
7
+ <% params_by_path = {} %>
3
8
  <% streams.each do |s| %>
4
- <% render s[:partial], locals: s[:locals], formats: [:html ] %>
9
+ <% html = (render s[:partial], locals: s[:locals], formats: [:html ]) %>
10
+ <%# htmls.push(html) %>
11
+ <% htmls_by_id[s[:id]] ||= [] %>
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
+
5
21
  <% partials_count += 1 %>
6
22
  <% rendered_partials.push(s[:partial]) %>
7
23
  <% end %>
8
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' %>
9
30
 
10
31
  <%= content_tag :div, check.to_json, id: 'check-json' %>
11
- <%= content_tag :div, rendered_partials.to_json, id: 'rendered-partials' %>
32
+ <%#= content_tag :div, htmls.to_json, id: 'htmls' %>
33
+ <%= content_tag :div, rendered_partials.to_json, id: 'rendered-partials' %>
34
+ <%#= content_tag :div, streams.to_json, id: 'streams' %>
@@ -1,32 +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
- def rendered_partials
8
- e = Nokogiri::HTML(response.body).search('#rendered-partials').first
9
+
10
+ def partials_params_by_id
11
+ e = Nokogiri::HTML(response.body).search('#params_by_id').first
9
12
  JSON.parse(e.inner_html)
10
13
  end
11
14
 
12
- # returns all partials that would be streamed to a given ID
13
- # 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
14
- def rendered_partials_where_id(id)
15
- partials = Nokogiri::HTML(response.body).search('#rendered-partials').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
16
18
  JSON.parse(e.inner_html)
17
- partials.select{|p| p[id] == id }
18
19
  end
19
20
 
20
- # returns the first partial that would be streamed to a given ID
21
- def rendered_partials_find_id(id)
22
- partials = 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
- partials.select{|p| p[id] == id }.first
25
25
  end
26
26
 
27
- def rendered_partials_count
28
- rendered_partials.length
27
+ # count of rendered parials
28
+ def partials_count
29
+ partials_paths.length
29
30
  end
31
+
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
36
+ end
37
+
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)
42
+ end
43
+
44
+ # check response status and return redirected_to path
30
45
  def turbo_redirected_to
31
46
  expect(response.status).to eq(302)
32
47
  r = JSON.parse(response.body)
@@ -1,3 +1,3 @@
1
1
  module RenderTurboStream
2
- VERSION = "0.1.19"
2
+ VERSION = "0.1.21"
3
3
  end
@@ -138,7 +138,8 @@ module RenderTurboStream
138
138
  def stream_partials(array)
139
139
 
140
140
  ary = []
141
- array.dup.each do |props|
141
+ array.dup.each do |pr|
142
+ props = pr.symbolize_keys
142
143
  part = (props[:partial].present? ? props[:partial] : props[:id]).gsub('-', '_')
143
144
  partial = (part.to_s.include?('/') ? part : [controller_path, part].join('/'))
144
145
  r = props
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.19
4
+ version: 0.1.21
5
5
  platform: ruby
6
6
  authors:
7
7
  - christian