render_turbo_stream 0.1.36 → 0.1.37
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +6 -10
- data/lib/render_turbo_stream/request_test_helpers.rb +21 -25
- 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: 5aec959a7ad9663de11285bba5734246b90b764235464a41da68e80a35dc2609
|
4
|
+
data.tar.gz: d38bc6507be14b63af99e268cf167c567836cd7021d6777e6c31dac02b73c80e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d0ab474fc5ea832bf2ea135af3696ea0fd3d032cb17ebe8847262d7fbd53ab86e038fa37e28b497b3b7d9892e2c680aa153ba06d9e059b21cff82d682bb18099
|
7
|
+
data.tar.gz: b9954342146266f214581d689fdbd0b1084fd8bb0d4d64e8e08bdbd07c931cb39e950953f6dc56c946941a922a3e39b3eee8401559548a0164ea2185d3f692d6
|
data/README.md
CHANGED
@@ -124,10 +124,7 @@ RSpec.describe "Articles", type: :request do
|
|
124
124
|
|
125
125
|
# ----- BASIC -----
|
126
126
|
|
127
|
-
#
|
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,25 @@ 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 flash[:alert].present?
|
93
|
+
r.push("flash[:alert]: «#{flash[:alert]}»")
|
94
|
+
end
|
95
|
+
if flash[:notice].present?
|
96
|
+
r.push("flash[:notice]: «#{flash[:notice]}»")
|
97
|
+
end
|
98
|
+
if response.status == 302
|
99
|
+
r.push("redirect to #{turbo_redirect_to}")
|
100
|
+
else
|
101
|
+
partials_attributes.map do |a|
|
102
|
+
str = [a['action'], 'id', "«#{a['id']}»", 'by partial', "«#{a['partial']}»"].join(' ')
|
103
|
+
r.push(str)
|
104
|
+
end
|
105
|
+
end
|
106
|
+
r
|
107
|
+
end
|
112
108
|
end
|
113
109
|
end
|