render_turbo_stream 0.1.43 → 0.1.45

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: b7105e78e4f7d96782d8bb94cdddefdb3698c68855cd16155dd575660095fa83
4
- data.tar.gz: ff253ad1317fe42d6c3c617c7c2bb23933c5101330bcf9d3710cd06d6ae09a97
3
+ metadata.gz: 30eb2a0495b25d67ff59b2194b7b54cf20c8d0f813ade47a6809616d13231ba3
4
+ data.tar.gz: a934e1be22f6610a10fd16ce642a5601d8ef11224bfd1a9d70f1f1d471a83d71
5
5
  SHA512:
6
- metadata.gz: df9dd9941005c649c125778ca0c2d35ba4672f5bb742457040fe16513db1078ab34bc140b859400336aa79cce70e4695ba5a8f91bbd185209535867a2cd9da23
7
- data.tar.gz: 6ef0ec59e35da7fcac18c697bc06c70ca3247107891a9ce02c1ba2f3987d34c439ef97cc18fa5591b7dae441a435a7a0c275e8e4e9ab7d62b548d9da41570762
6
+ metadata.gz: c12cc64cbf409f74a7bf8f2faf6c6aa63fbe063a0bca4d8ec5939fea06b77011f873633e71daa44d6ef518f70686e382a115ac9c0da6b426413fb8665486c770
7
+ data.tar.gz: e6f689292afcc93064d1a67ee5d13a1bcd68a85cfb2b21a600624e5224585c4d5db7d6b21232ee30716924d5de82255ed321cab0a8ccf0d65c048aa7c9228325
data/README.md CHANGED
@@ -32,11 +32,11 @@ spec/rails_helper.rb
32
32
 
33
33
  ```ruby
34
34
  RSpec.configure do |config|
35
- config.include RenderTurboStream::RequestTestHelpers, type: :request
35
+ config.include RenderTurboStream::Test::RequestHelpers, type: :request
36
36
  end
37
37
  ```
38
38
 
39
- Redirection
39
+ **Redirection**
40
40
 
41
41
  For redirection to work, you must follow the installation steps
42
42
  from [turbo_power](https://github.com/marcoroth/turbo_power).
@@ -122,18 +122,24 @@ RSpec.describe "Articles", type: :request do
122
122
  expect(partials_log.join('')).to include('Article could not be created')
123
123
  expect(partials_log.join('')).to include('layouts/flash')
124
124
 
125
- expect(partials_count).to eq(2)
126
- #=> 2 partials in total: form, flash, no matter how many times each is rendered (example «flash»: a flash partial can be rendered several times)
125
+ # THERE ARE 3 COUNTS
127
126
 
128
- expect(partial_response('form')).to eq(true)
129
- expect(partial_response('layouts/flash')).to eq(true)
130
- expect(partial_response('flash', id: 'flash-wrapper', count: 1)).to eq(true)
131
- #=> id is the ID that turbo-stream pointed to (for replace/append/... an item)
127
+ # A) Number of partials: "form" and "flash" are 2 partials
128
+
129
+ expect(partials_count).to eq(2)
132
130
 
133
- expect(partial_response('flash'){|r|r.inner_html.include?('Article could not be created')}).to eq(true)
134
- expect(partial_response('flash'){|r|r.css('div').inner_html.include?('Article could not be created')}).to eq(true)
131
+ # B) Total count of responses per partial (1 => is default)
132
+
133
+ expect(partial_response_count('articles/form', total: 1, id: 'form')).to be_truthy
134
+ # id is the html id to which turbo-stream is pointing.
135
+
136
+ # C) If a block is given: the number of matching responses returned by "partial_response_count".
137
+
138
+ expect(partial_response_count('flash'){|r|r.inner_html.include?('Article could not be created')}).to eq(1)
139
+ # result is either nil (if 0 matched) or a integer >= 1
140
+
141
+ expect(partial_response_count('flash'){|r|r.css('div').inner_html.include?('Article could not be created')}).to eq(1)
135
142
  #=> you can use the validators of nokogiri, check: https://nokogiri.org/tutorials/parsing_an_html_xml_document.html
136
- #=> if a partial was rendered more than once: at least one response must match
137
143
  end
138
144
 
139
145
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  <% streams.each do |s| %>
4
4
 
5
- <% html = (render s[:partial], locals: s[:locals], formats: [:html]) %>
5
+ <% html = (render s[:partial], locals: s[:locals].symbolize_keys, formats: [:html]) %>
6
6
 
7
7
  <% rendered_partials.push({ html_response: html }.merge(s)) %>
8
8
 
@@ -17,21 +17,21 @@
17
17
  <% ctl[:action] = :replace %>
18
18
  <% Rails.logger.debug(" • render-turbo-stream REPLACE => #{info}") %>
19
19
  <%= turbo_stream.replace s[:id] do %>
20
- <%= render s[:partial], locals: s[:locals] %>
20
+ <%= render s[:partial], locals: s[:locals].symbolize_keys %>
21
21
  <% end %>
22
22
 
23
23
  <% elsif s[:action].to_sym == :prepend %>
24
24
  <% ctl[:action] = :prepend %>
25
25
  <% Rails.logger.debug(" • render-turbo-stream PREPEND => #{info}") %>
26
26
  <%= turbo_stream.prepend s[:id] do %>
27
- <%= render s[:partial], locals: s[:locals] %>
27
+ <%= render s[:partial], locals: s[:locals].symbolize_keys %>
28
28
  <% end %>
29
29
 
30
30
  <% elsif s[:action].to_sym == :append %>
31
31
  <% ctl[:action] = :append %>
32
32
  <% Rails.logger.debug(" • render-turbo-stream APPEND => #{info}") %>
33
33
  <%= turbo_stream.prepend s[:id] do %>
34
- <%= render s[:partial], locals: s[:locals] %>
34
+ <%= render s[:partial], locals: s[:locals].symbolize_keys %>
35
35
  <% end %>
36
36
 
37
37
  <% else %>
@@ -43,8 +43,8 @@ module RenderTurboStream
43
43
  end
44
44
 
45
45
 
46
- def partial_response(partial, id: nil, count: 1, &block)
47
- RenderTurboStream::Libs.partial_response(response, partial, id, count, &block )
46
+ def partial_response_count(partial, id: nil, total: 1, &block)
47
+ RenderTurboStream::Libs.partial_response_count(response, partial, id, total, &block )
48
48
  end
49
49
 
50
50
  end
@@ -1,3 +1,3 @@
1
1
  module RenderTurboStream
2
- VERSION = "0.1.43"
2
+ VERSION = "0.1.45"
3
3
  end
@@ -216,7 +216,7 @@ module RenderTurboStream
216
216
  else
217
217
  a['id'] == id
218
218
  end
219
- partial_matched || id_matched
219
+ partial_matched && (id.present? ? id_matched : true)
220
220
  end
221
221
 
222
222
  end
@@ -233,26 +233,22 @@ module RenderTurboStream
233
233
  part.length
234
234
  end
235
235
 
236
- def self.partial_response(response, partial, id, count, &block)
236
+ def self.partial_response_count(response, partial, id, total, &block)
237
237
  responses = select_responses(response, partial, id)
238
- if block_given?
239
238
 
240
- success = false
241
-
242
- responses.each do |r|
239
+ if total && responses.count != total
240
+ false
241
+ elsif block_given?
242
+ res = responses.select do |r|
243
243
  parsed = Nokogiri::HTML(r['html_response'])
244
244
  r = yield parsed
245
- success = true if r.present?
246
- end
247
- success
248
-
245
+ r.present?
246
+ end.length
247
+ (res == 0 ? nil : res)
249
248
  else
250
- if count
251
- responses.length == count
252
- else
253
- nil
254
- end
249
+ responses.length
255
250
  end
251
+
256
252
  end
257
253
 
258
254
  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.43
4
+ version: 0.1.45
5
5
  platform: ruby
6
6
  authors:
7
7
  - christian