glib-web 5.0.6 → 5.0.7

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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/glib/test_helpers.rb +23 -2
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2e9d0b6eb1a02d147f08a0166a4d67075ebbf903af3601e78ab592c5f9a11808
4
- data.tar.gz: ee0d8980dfa1158fa65126b8d29dad29e2b788f1b51e4fb062a2de306a1d789a
3
+ metadata.gz: 6885a1b150291881895f5b3cdfda3c2424961e5fd953e7faebd2d421242d930c
4
+ data.tar.gz: 2c9b74ee8ac40b6b887d3b14a06915b98b0562a207d578d63b955a12b7e235f9
5
5
  SHA512:
6
- metadata.gz: 21960f43365ee50457f2ad2856d5bf5e6cf6c1a5014332006e9fe43e7f2e6cec9633a35cb5678a34388310d88e69222ab4641d1267125e87e01d822d00fb7e4f
7
- data.tar.gz: cf920f5f56177c092fc2bd84bacf4b096d1b41ae4364b47bcfe3beba1b58bb8afa76883a33210a9f9ad709085c7dc33644933128cddbe93b4ff2251e6f2367b5
6
+ metadata.gz: 67e1d34169a5cea5970378da912372ff6b0c5b1e0b7793c9e05fc50347cd1e118f55d0b9b63a328a60fdff810c913ba94575198eee0cd147d161feb8272c6c27
7
+ data.tar.gz: dadf602d4b72f9c2c2ef4434182c94eb6690f05e1ec934226de01d8c24cef88719f29cba394d12c5e13df93e82144f46ae8425443b4318807780bcde5381d761
@@ -134,8 +134,7 @@ module Glib
134
134
  # submit_form(response.body, { chat: { message_body: 'Hello' } })
135
135
  #
136
136
  def submit_form(page_payload, data, url: nil, method: nil)
137
- json = JSON.parse(page_payload)
138
- form = __find_form(json)
137
+ form = find_form(page_payload)
139
138
 
140
139
  raise 'No form found in page. Ensure the form is rendered properly.' unless form
141
140
 
@@ -173,6 +172,23 @@ module Glib
173
172
  assert_response :success
174
173
  end
175
174
 
175
+ # Locates the form in a rendered page payload without submitting it -- useful for
176
+ # asserting on a form's attributes (e.g. its HTTP method) in a test. Returns the form
177
+ # Hash, or nil when the page renders no form. When several forms are present it returns
178
+ # the one with the most childViews, the same selection submit_form uses internally.
179
+ #
180
+ # @param page_payload [String, Hash] The JSON response body, or an already-parsed Hash
181
+ # @return [Hash, nil] The located form view, or nil if none is rendered
182
+ #
183
+ # @example
184
+ # get new_chat_url(checklist_id: checklist.id), params: json_params
185
+ # assert_equal 'post', find_form(response.body)['method']
186
+ #
187
+ def find_form(page_payload)
188
+ json = page_payload.is_a?(String) ? JSON.parse(page_payload) : page_payload
189
+ __find_form(json)
190
+ end
191
+
176
192
  def glib_travel(*args, &block)
177
193
  Timecop.travel(*args, &block)
178
194
  end
@@ -207,6 +223,11 @@ module Glib
207
223
 
208
224
  def __build_form_params(form, data)
209
225
  params = {}
226
+
227
+ # Skip ALL hidden fields under the same model prefix, not just exact key matches.
228
+ # Hidden fields use flat bracket notation (e.g. "submission[task_id]") while data uses
229
+ # nested hashes (e.g. { submission: { signature_submission_attributes: { ... } } }).
230
+ # Mixing both in params makes Rails misparse them, resulting in 403 Forbidden errors.
210
231
  data_prefixes = data.keys.map { |k| "#{k}[" }
211
232
 
212
233
  __extract_form_fields(form).each do |field|
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: glib-web
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.0.6
4
+ version: 5.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - ''