render_turbo_stream 0.1.33 → 0.1.35

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: e7bdbd86f6a632d14466afe180d2a6f75dbf7fa852cc49719deb13bfa740ac74
4
- data.tar.gz: 0bfb9d97fa310d9e1694d1797666424ad74258cbafe1ce53d04007402f79f81b
3
+ metadata.gz: 7009da829a23424793f7a032d3de9600465af5837204c63da84f28818a292aa2
4
+ data.tar.gz: 417b01b78e4939cd175e80a71bd80c593d91ca5c1578479afbe0a62554c0713a
5
5
  SHA512:
6
- metadata.gz: c36293efee4cca99176fbd40806f5d1d945329f86ef9a068d98e8f23945764be5bafabe2ece128a2e4afb41a7c40075ec736030d61f2ac2bbea9eb3b57639972
7
- data.tar.gz: 040f42b9a0eabacc7150872a885b0576c64642016b2a63160ae13278b9a28533f8aa74e97959c5982bcc42b85c7db0091f0e9613f91653aa781b295502ea3bcc
6
+ metadata.gz: bac76150d7cdff0b7f2dcd895f798041e18381fcc0862a4afddbd8c7442a09cdb10dac85b80004d54e4c9c8e87cf99c2a5a20d86ea1f5399026033dd14b5b9ff
7
+ data.tar.gz: e9b03231a29046f79049d53e3c1c1eb2fea122661ce0e5ca28e2988afb507a4f13538b71ccb879f6c7d0ee1ab34727a0d2c9b0b845f307528f26500d35391a3b
data/README.md CHANGED
@@ -113,9 +113,10 @@ RSpec.describe "Articles", type: :request do
113
113
 
114
114
  # --- BASIC TEST ---
115
115
 
116
- # Which partials were rendered
116
+ # Count of rendered partials
117
117
  expect(partials_count).to eq(2)
118
- 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')
119
120
 
120
121
 
121
122
 
@@ -53,8 +53,13 @@ module RenderTurboStream
53
53
  paths
54
54
  end
55
55
 
56
- # array of strings of paths by which partials that are exactly one time rendered, for example: ['articles/form'].
57
- def partials_once
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)
58
63
  ary = partials_attributes
59
64
  paths = []
60
65
  paths_once = []
@@ -66,7 +71,30 @@ module RenderTurboStream
66
71
  paths_once.push(a['partial'])
67
72
  end
68
73
  end
69
- paths_once
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
70
98
  end
71
99
 
72
100
  # returns an array of hashes with the attributes used to call partials and the response (html as string) from the partial.
@@ -1,3 +1,3 @@
1
1
  module RenderTurboStream
2
- VERSION = "0.1.33"
2
+ VERSION = "0.1.35"
3
3
  end
@@ -97,6 +97,7 @@ module RenderTurboStream
97
97
  flash_partial = Rails.configuration.x.render_turbo_stream.flash_partial
98
98
  flash_action = Rails.configuration.x.render_turbo_stream.flash_action
99
99
  flash_notices.each do |notice|
100
+ next unless notice.present?
100
101
  # inside the flash partial has to be a loop that handles all theese flashes
101
102
  flash_stream = {
102
103
  id: flash_id,
@@ -107,6 +108,7 @@ module RenderTurboStream
107
108
  streams.push(flash_stream)
108
109
  end
109
110
  flash_alerts.each do |alert|
111
+ next unless alert.present?
110
112
  # inside the flash partial has to be a loop that handles all theese flashes
111
113
  flash_stream = {
112
114
  id: flash_id,
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.33
4
+ version: 0.1.35
5
5
  platform: ruby
6
6
  authors:
7
7
  - christian