render_turbo_stream 0.1.39 → 0.1.41
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +5 -28
- data/lib/render_turbo_stream/request_test_helpers.rb +42 -45
- data/lib/render_turbo_stream/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9094ebe69f34f4acb61696aff5741b6d1eecaf934b17662bd81d6e5dda8533f9
|
4
|
+
data.tar.gz: b2a90bca1d9489b59a2de3cc4522b35f9ea81298f55472582adfa597a2a5a553
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c486823d9469018277398ee19ab7b95291ad0ed607e0abc6e01d1c1497358e2befca6f4ded2e6272ec86005e07c8eef9de2c66078a3c301300eaafb3d18ed0cb
|
7
|
+
data.tar.gz: a4e3e4cb03a640d6f64b4c4efee892e539c0c5dfd34074be5ee5d0fc6dc259f5707a86cca36fd5e7cfcfdf93cddba91cc4e96b9e209c084eec1d3ab806fcf257
|
data/README.md
CHANGED
@@ -122,37 +122,14 @@ RSpec.describe "Articles", type: :request do
|
|
122
122
|
|
123
123
|
post articles_path(params: invalid_params)
|
124
124
|
|
125
|
-
#
|
126
|
-
|
127
|
-
# Exactly which partials were rendered to which ids
|
128
|
-
expect(
|
129
|
-
partials_once(
|
130
|
-
{ partial: 'layouts/flash', id: 'flash-box' },
|
131
|
-
{ partial: 'articles/form', id: 'form' })
|
132
|
-
).to be_truthy
|
133
|
-
|
134
|
-
# ----- MORE OPTIONS -----
|
135
|
-
|
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
|
137
|
-
r = partial_response(id: 'flash-box')
|
138
|
-
expect(r.css('div.text-content').first.inner_html).to include('Article could not be created')
|
139
|
-
|
140
|
-
# same, but based on path by which partial is rendered to
|
141
|
-
r = partial_response(partial: 'layouts/flash')
|
142
|
-
expect(r.css('div.text-content').first.inner_html).to include('Article could not be created')
|
143
|
-
|
144
|
-
# COUNTS
|
145
|
-
|
146
|
-
# Check how many times a specific ID has been responded to.
|
147
|
-
expect(partials_responses(id: 'flash-box').length).to eq(1)
|
148
|
-
|
149
|
-
# Same with partials
|
150
|
-
expect(partials_responses(partial: 'layouts/flash').length).to eq(1)
|
151
|
-
|
152
|
-
# partials_log: developer info for what the renderer has done and strings for copy and paste into test commands
|
125
|
+
# partials_log: developer information about what the renderer did, and strings to copy and paste into test commands
|
153
126
|
expect(partials_log.join('')).to include('Article could not be created')
|
154
127
|
expect(partials_log.join('')).to include('layouts/flash')
|
155
128
|
|
129
|
+
expect(partials_count).to eq(2) #=> 2 partials (form and a flash) are rendered
|
130
|
+
expect(assert_partials('layouts/flash', id: 'flash-box')).to be_truthy #=> expect flash to render exact one time to html-id 'flash-box' by turbo-stream
|
131
|
+
expect(assert_partials('articles/form', id: 'form')).to be_truthy #=> expect flash to render exact one time to html-id 'form' by turbo-stream
|
132
|
+
|
156
133
|
end
|
157
134
|
end
|
158
135
|
```
|
@@ -15,62 +15,59 @@ module RenderTurboStream
|
|
15
15
|
# like partial_response, but returns an array with length of how many times partial was rendered
|
16
16
|
#
|
17
17
|
|
18
|
-
def partials_responses(id: nil, partial: nil)
|
19
|
-
|
18
|
+
# def partials_responses(id: nil, partial: nil)
|
19
|
+
# ary = partials_attributes
|
20
|
+
# if id && partial
|
21
|
+
# res = ary.select { |a| a['partial'] == partial && a['id'] == id }
|
22
|
+
# elsif id
|
23
|
+
# res = ary.select { |a| a['id'] == id }
|
24
|
+
# elsif partial
|
25
|
+
# res = ary.select { |a| a['partial'] == partial }
|
26
|
+
# else
|
27
|
+
# raise 'missing parameter'
|
28
|
+
# end
|
29
|
+
# res.map { |r| Nokogiri::HTML(r['html_response']) }
|
30
|
+
# end
|
31
|
+
|
32
|
+
# if no count given: expects exactly one match
|
33
|
+
|
34
|
+
def assert_partials(partial, id: nil, count: 1, &block)
|
35
|
+
partials = partials_attributes
|
20
36
|
if id && partial
|
21
|
-
|
37
|
+
part = partials.select { |a| a['partial'] == partial && a['id'] == id }
|
22
38
|
elsif id
|
23
|
-
|
39
|
+
part = partials.select { |a| a['id'] == id }
|
24
40
|
elsif partial
|
25
|
-
|
41
|
+
part = partials.select { |a| a['partial'] == partial }
|
26
42
|
else
|
27
43
|
raise 'missing parameter'
|
28
44
|
end
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
# partials_once({partial: 'articles/flash_box', id: 'flash-box'}) => check flash-box is exactly one time rendered
|
37
|
-
# partials_once({partial: 'articles/flash_box', id: 'flash-box'}) => check flash-box is exactly one time rendered to id 'flash-box'
|
38
|
-
def partials_once(*args)
|
39
|
-
ary = partials_attributes
|
40
|
-
paths = []
|
41
|
-
paths_once = []
|
42
|
-
ary.each do |a|
|
43
|
-
if paths.include?(a['partial'])
|
44
|
-
paths_once.delete(a['partial'])
|
45
|
+
if block_given?
|
46
|
+
part.each do |r|
|
47
|
+
noko = Nokogiri::HTML(r['html_response'])
|
48
|
+
end
|
49
|
+
else
|
50
|
+
if count
|
51
|
+
part.length == count
|
45
52
|
else
|
46
|
-
|
47
|
-
paths_once.push(a['partial'])
|
53
|
+
part.length
|
48
54
|
end
|
49
55
|
end
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
r = ary.select { |a| a['partial'] == _a[:partial] }.first
|
63
|
-
res = r['id'] == _a[:id]
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|
67
|
-
res
|
68
|
-
else
|
69
|
-
false
|
56
|
+
end
|
57
|
+
|
58
|
+
# count of rendered partials
|
59
|
+
# count rendering different partials (example: «customer/form»)
|
60
|
+
# doesnt check how often a specific partial is rendered
|
61
|
+
|
62
|
+
def partials_count
|
63
|
+
part = []
|
64
|
+
partials_attributes.each do |p|
|
65
|
+
_p = p['partial']
|
66
|
+
unless part.include?(_p)
|
67
|
+
part.push(_p)
|
70
68
|
end
|
71
|
-
else
|
72
|
-
paths_once
|
73
69
|
end
|
70
|
+
part.length
|
74
71
|
end
|
75
72
|
|
76
73
|
# returns an array of hashes with the attributes used to call partials and the response (html as string) from the partial.
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: render_turbo_stream
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.41
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- christian
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-04-
|
11
|
+
date: 2023-04-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|