render_turbo_stream 0.1.32 → 0.1.34

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: 7b206d8b440a99024e367f647d886ec496c58965d343dfc6a7652d4d1e92a296
4
- data.tar.gz: e4a1528314a586060ed43a425445eb0a72e5dd4266142455983d97dd70e4dffc
3
+ metadata.gz: 95e94563d2f1c54311f3755286e2ace6f4f258c63f443b305043cf2c7611cd4f
4
+ data.tar.gz: e7deed853515642b52503f1f870e436ad4870359320b7fc88d179e10b9d60943
5
5
  SHA512:
6
- metadata.gz: aa70109f94e3e5eb963c7e0c45846d8686ee683e6bb0b6df2dff17b27f9d932a1d95e5c08221e931d190cf65cc85ddb81529580e07ef6e6295b2252d2815361e
7
- data.tar.gz: c0ea50d8d082b7797c11f0b0e6b0d807aaf5ea736c60b11a079305ae02260eec216c08cdf71a499d419300982860ac0dca352b2166274381f5ea56ac73dede10
6
+ metadata.gz: a34007581d53530c7f96f1aff79af28594303c856dea1913708d913794a4020f8203c98ffd8a6538446e1a85295436a7d466ff1e09f3171615af7eac6afff781
7
+ data.tar.gz: f7fa39fbd0932a58112168abe638f323f1f3a3ae98d1ddd9fc700e504d741dfbc04dfb666ecd34cff42ff6b6ca0ab236ad94fbd05e48f55c8b75b5da19593c10
data/README.md CHANGED
@@ -111,14 +111,17 @@ RSpec.describe "Articles", type: :request do
111
111
 
112
112
  post articles_path(params: invalid_params)
113
113
 
114
- # Which partials were rendered
114
+ # --- BASIC TEST ---
115
+
116
+ # Count of rendered partials
115
117
  expect(partials_count).to eq(2)
116
- expect(partials).to include('layouts/flash', 'articles/form')
118
+ # Make sure that each of these partials is rendered exactly once.
119
+ expect(partials_once).to include('layouts/flash', 'articles/form')
117
120
 
118
121
 
119
122
 
120
123
 
121
- # ----- MORE OPTIONS -----
124
+ # --- MORE OPTIONS ---
122
125
 
123
126
  # to which html-ids turbo-stream would point
124
127
  expect(partials_ids).to include('flash-box', 'form')
@@ -26,7 +26,7 @@ module RenderTurboStream
26
26
  else
27
27
  raise 'missing parameter'
28
28
  end
29
- res.map{|r| Nokogiri::HTML(r['html_response']) }
29
+ res.map { |r| Nokogiri::HTML(r['html_response']) }
30
30
  end
31
31
 
32
32
  def partials_ids_count
@@ -41,7 +41,7 @@ module RenderTurboStream
41
41
  def partials_ids
42
42
  ary = partials_attributes
43
43
  ids = []
44
- ary.each {|a| ids.push(a['id']) unless ids.include?(a['id']) }
44
+ ary.each { |a| ids.push(a['id']) unless ids.include?(a['id']) }
45
45
  ids
46
46
  end
47
47
 
@@ -49,10 +49,54 @@ module RenderTurboStream
49
49
  def partials
50
50
  ary = partials_attributes
51
51
  paths = []
52
- ary.each {|a| paths.push(a['partial']) unless paths.include?(a['partial']) }
52
+ ary.each { |a| paths.push(a['partial']) unless paths.include?(a['partial']) }
53
53
  paths
54
54
  end
55
55
 
56
+ # without arguments: returns array of strings of paths by which partials that are exactly one time rendered, for example: ['articles/form'].
57
+ # if arguments provided: compares with result and returns boolean
58
+ # examples:
59
+ # partials_once('articles/flash_box') => check flash-box is exactly one time rendered and no others
60
+ # partials_once({partial: 'articles/flash_box', id: 'flash-box'}) => check flash-box is exactly one time rendered
61
+ # partials_once({partial: 'articles/flash_box', id: 'flash-box'}) => check flash-box is exactly one time rendered to id 'flash-box'
62
+ def partials_once(*args)
63
+ ary = partials_attributes
64
+ paths = []
65
+ paths_once = []
66
+ ary.each do |a|
67
+ if paths.include?(a['partial'])
68
+ paths_once.delete(a['partial'])
69
+ else
70
+ paths.push(a['partial'])
71
+ paths_once.push(a['partial'])
72
+ end
73
+ end
74
+ if args.present?
75
+ paths_once
76
+ if args.length == paths_once.length
77
+ res = true
78
+ args.each do |a|
79
+ if a.is_a?(String) && !paths_once.include?(a)
80
+ res = false
81
+ elsif a.is_a?(Hash)
82
+ _a = a.symbolize_keys
83
+ if !paths_once.include?(_a[:partial])
84
+ res = false
85
+ elsif _a.key?(:id)
86
+ r = ary.select{|a|a['partial'] == _a[:partial]}.first
87
+ res = r['id'] == _a[:id]
88
+ end
89
+ end
90
+ end
91
+ res
92
+ else
93
+ false
94
+ end
95
+ else
96
+ paths_once
97
+ end
98
+ end
99
+
56
100
  # returns an array of hashes with the attributes used to call partials and the response (html as string) from the partial.
57
101
  def partials_attributes
58
102
  e = Nokogiri::HTML(response.body).search('#rendered-partials').first
@@ -1,3 +1,3 @@
1
1
  module RenderTurboStream
2
- VERSION = "0.1.32"
2
+ VERSION = "0.1.34"
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.32
4
+ version: 0.1.34
5
5
  platform: ruby
6
6
  authors:
7
7
  - christian