render_turbo_stream 0.1.36 → 0.1.38

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: 2c7532451ee9d808af49593c554e304f1f4de4f82f561378bf449ae7e9933722
4
- data.tar.gz: c967685bd9bb8476536af267ad2e9fe24b66ef5ca63ba48b6aef6501621c6cf4
3
+ metadata.gz: cc560017c111220d13b4d93d5b75a2dd6861ddb47279dfa274c198a139e0f570
4
+ data.tar.gz: 11412706a617e448b463d5f1c8ccfed8e78478ff326d76941aa3743e40c80310
5
5
  SHA512:
6
- metadata.gz: 293fdcc0dff25264324482dd433a31507756b73526edc0ab31786e9b08a9e4a86e18cc82b932065b0ff329cded36439cdee2944dbc99440c77359714615f8f73
7
- data.tar.gz: edde20365f6a575f4dafde9166100b4e3ff4d54cd72ac0f4e767d9b67fb798e7923fe0b906b0f8d3976227f035bcc70cf9d51d1cc408581048083cdaa2219366
6
+ metadata.gz: e45b9be258303328b2271fb401a2553725f80626160fd9b3f0dbefbf9475d342cd2e1192406544b8d2a8bce3b05c693b085edeef5d1e936b76c55b26a0df50a3
7
+ data.tar.gz: 444fb5821a42d2beee1860413da811b1f70b9cee8573e93694fba3a0351860a93c2015985637a78e695f9d73cd66e6804d13c729493e47b5ba8d1efe2726cd6d
data/README.md CHANGED
@@ -124,10 +124,7 @@ RSpec.describe "Articles", type: :request do
124
124
 
125
125
  # ----- BASIC -----
126
126
 
127
- # Which partials were rendered
128
- expect(partials).to include('layouts/flash', 'articles/form')
129
-
130
- # Exactly Which partials were rendered to which ids
127
+ # Exactly which partials were rendered to which ids
131
128
  expect(
132
129
  partials_once(
133
130
  { partial: 'layouts/flash', id: 'flash-box' },
@@ -136,9 +133,6 @@ RSpec.describe "Articles", type: :request do
136
133
 
137
134
  # ----- MORE OPTIONS -----
138
135
 
139
- # to which html-ids turbo-stream would point
140
- expect(partials_ids).to include('flash-box', 'form')
141
-
142
136
  # partial_response (singular) returns false unless partial responded exactly one time, otherwise the content in nokogiri format: https://nokogiri.org/tutorials/searching_a_xml_html_document.html#basic-searching
143
137
  r = partial_response(id: 'flash-box')
144
138
  expect(r.css('div.text-content').first.inner_html).to include('Article could not be created')
@@ -149,15 +143,17 @@ RSpec.describe "Articles", type: :request do
149
143
 
150
144
  # COUNTS
151
145
 
152
- # Check the number of ids responded to
153
- expect(partials_ids_count).to eq(2)
154
-
155
146
  # Check how many times a specific ID has been responded to.
156
147
  expect(partials_responses(id: 'flash-box').length).to eq(1)
157
148
 
158
149
  # Same with partials
159
150
 
160
151
  expect(partials_responses(partial: 'layouts/flash').length).to eq(1)
152
+
153
+ # little helper for showing a array of prepared flashes and all what the renderer has done
154
+ expect(partials_log.join('')).to include('Article could not be created')
155
+ expect(partials_log.join('')).to include('layouts/flash')
156
+
161
157
  end
162
158
  end
163
159
  ```
@@ -29,30 +29,6 @@ module RenderTurboStream
29
29
  res.map { |r| Nokogiri::HTML(r['html_response']) }
30
30
  end
31
31
 
32
- def partials_ids_count
33
- partials_ids.length
34
- end
35
-
36
- def partials_count
37
- partials.length
38
- end
39
-
40
- # array of strings of ids of rendered partials that turbo_stream pointed to
41
- def partials_ids
42
- ary = partials_attributes
43
- ids = []
44
- ary.each { |a| ids.push(a['id']) unless ids.include?(a['id']) }
45
- ids
46
- end
47
-
48
- # array of strings of paths by which partials are rendered, for example: ['articles/form'].
49
- def partials
50
- ary = partials_attributes
51
- paths = []
52
- ary.each { |a| paths.push(a['partial']) unless paths.include?(a['partial']) }
53
- paths
54
- end
55
-
56
32
  # without arguments: returns array of strings of paths by which partials that are exactly one time rendered, for example: ['articles/form'].
57
33
  # if arguments provided: compares with result and returns boolean
58
34
  # examples:
@@ -83,7 +59,7 @@ module RenderTurboStream
83
59
  if !paths_once.include?(_a[:partial])
84
60
  res = false
85
61
  elsif _a.key?(:id)
86
- r = ary.select{|a|a['partial'] == _a[:partial]}.first
62
+ r = ary.select { |a| a['partial'] == _a[:partial] }.first
87
63
  res = r['id'] == _a[:id]
88
64
  end
89
65
  end
@@ -109,5 +85,26 @@ module RenderTurboStream
109
85
  r = JSON.parse(response.body)
110
86
  r['redirected_to']
111
87
  end
88
+
89
+ # log as helper for the developer to see which flash is set and which partials are rendered to wich ids
90
+ def partials_log
91
+ r = []
92
+ if response.status == 302
93
+ r.push("redirect to #{turbo_redirect_to}")
94
+ else
95
+ partials_attributes.map do |a|
96
+ str = [
97
+ a['action'],
98
+ 'id',
99
+ "«#{a['id']}»",
100
+ 'by partial',
101
+ "«#{a['partial']}»",
102
+ (a['locals'].present? ? "locals: «#{a['locals']}»" : nil)
103
+ ].compact.join(' ')
104
+ r.push(str)
105
+ end
106
+ end
107
+ r
108
+ end
112
109
  end
113
110
  end
@@ -1,3 +1,3 @@
1
1
  module RenderTurboStream
2
- VERSION = "0.1.36"
2
+ VERSION = "0.1.38"
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.36
4
+ version: 0.1.38
5
5
  platform: ruby
6
6
  authors:
7
7
  - christian