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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2c7532451ee9d808af49593c554e304f1f4de4f82f561378bf449ae7e9933722
4
- data.tar.gz: c967685bd9bb8476536af267ad2e9fe24b66ef5ca63ba48b6aef6501621c6cf4
3
+ metadata.gz: 5aec959a7ad9663de11285bba5734246b90b764235464a41da68e80a35dc2609
4
+ data.tar.gz: d38bc6507be14b63af99e268cf167c567836cd7021d6777e6c31dac02b73c80e
5
5
  SHA512:
6
- metadata.gz: 293fdcc0dff25264324482dd433a31507756b73526edc0ab31786e9b08a9e4a86e18cc82b932065b0ff329cded36439cdee2944dbc99440c77359714615f8f73
7
- data.tar.gz: edde20365f6a575f4dafde9166100b4e3ff4d54cd72ac0f4e767d9b67fb798e7923fe0b906b0f8d3976227f035bcc70cf9d51d1cc408581048083cdaa2219366
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
- # 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,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
@@ -1,3 +1,3 @@
1
1
  module RenderTurboStream
2
- VERSION = "0.1.36"
2
+ VERSION = "0.1.37"
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.37
5
5
  platform: ruby
6
6
  authors:
7
7
  - christian