You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
PAY-7046 Fix update on json 3, Ruby 3.3 floor and boolean validator - #82
update on any resource raises JSON::GeneratorError for merchants on json 3. Save#save merges the object's string-keyed attributes with the caller's params, so web_hook.update(name: 'x') builds a payload with both "name" and :name. json 2.x sends both keys and the gateway's parser keeps the last one; json 3 refuses to generate it. Merchants on json 2.x see no change.
Save#save now sends each attribute once, whether it arrives as a string or a symbol, from the stored attributes or the caller (PaymentPlan#suspend!('new_status' => …) used to send both). The caller's value wins, under the caller's key, so a multipart save's :multipart and :file keep working. The id is never sent as "id" or :id.
Test mode replaces a caller's string 'test' with :test instead of adding a second key.
The :boolean validator's /\Atrue|false\z/ anchored only one side of each word, so "trueish" passed. Only Batch.create uses it, and it always sets true, so no request changes.
The gemspec allowed Ruby 3.2, which CI stopped testing in February and which went end of life in March 2026. The floor is now 3.3; merchants on 3.2 keep resolving to 3.3.3.
Drops an unused JSON_ENV_VARS env var from the release job.
Ticket: PAY-7046. Released as 3.4.0, a minor version because of the Ruby floor change.
Security Impact
No new data sent. Save#save now also drops a caller's symbol :id, so an update body never carries the id. No change to authentication, card data handling or the gem's dependencies.
Rollback
Revert and tag a new release. Until then, merchants can pin fat_zebra to 3.2.9. No data involved.
Testing
E2E testing evidence provided in a comment: on Ruby 4 with json 3, update works against a local gateway and raises from main.
New specs on the payload Save#save builds: each attribute once, with the caller's value and no id, a name passed as both a string and a symbol sent once, suspend! with a string new_status sent once, and in test mode test sent once whichever key type the caller used. The first fails on main with the duplicated "name"/:name and the symbol :id in the payload.
New specs for the boolean validator accept true and false and reject "trueish" and "notfalse".
rspec (283 examples) and rubocop pass locally on Ruby 3.3, 3.4 and 4 (json 3.2.0), including the two WebHook#update examples that failed on Ruby 4 before.
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
Key stringification introduces duplicate test-mode keys that fail JSON serialization and breaks multipart instance saves by converting required transport keys to strings.
This PR addresses json 3 compatibility in the FatZebra Ruby client’s instance updates and aligns Ruby support with the tested versions. It complements #77’s Ruby 4 CI fixes.
Changes:
Normalizes save payload keys before merging and removing id, with regression coverage.
Tightens boolean validation to reject partial matches and adds tests.
Raises the Ruby minimum to 3.3 and removes an unused release-job environment variable.
File
Description
spec/lib/fat_zebra/web_hook_spec.rb
Adds assertions for normalized update payloads.
spec/lib/fat_zebra/validation_spec.rb
Covers valid booleans and invalid partial matches.
lib/fat_zebra/validation.rb
Anchors both boolean alternatives fully.
lib/fat_zebra/api_operation/save.rb
Stringifies attribute and parameter keys before merging.
fat_zebra from this branch at c027dc5, on Ruby 4.0.10 with json 3.2.0, against a local Fat Zebra gateway with a test merchant and test_mode on. Scenario 1 runs the same calls from main (5874915) for comparison. Ruby 3.3 and 3.4 with json 2 are covered by CI. This repo is public, so the extracts below are the gem's own output only; gateway's side is summarised in each scenario.
#
Scenario
Result
1
Before: WebHook#update(name:) from main
✅ reproduces the bug: JSON::GeneratorError, no request sent
2
WebHook#update(name:)
✅ 200, name updated
3
WebHook#update(name:, test: true) in test mode
✅ 200, test sent once
4
Batch.create(file:, filename:)
⚠️ passes the :boolean check and is sent; the local test stack couldn't store the upload
5
Ruby floor
✅ refuses to install on Ruby 3.2.2, installs on 3.3.7
1. Before: WebHook#update(name:) from main
Created a web hook, then updated its name, once plainly and once with test: true. Both updates raise in the gem, because the payload has "name" (from the object) and :name (from the caller). Gateway received the two creates and no update.
The caller's :test and the one test mode adds are the same key, so it's sent once. Gateway received test: true and the new name, and answered 200.
Gem output
...
created 010-WH-TLYRVCOY name="e2e hook" accepted=true
update(name:, test: true): accepted=true name="e2e hook test flag"
4. Batch.create(file:, filename:)
Batch.create sets multipart: true and checks it with the :boolean validator this PR tightens. The check passed and the upload was sent, rather than raising RequestValidationError. The local test stack then couldn't store the file, so the upload itself isn't proven here; the Batch.create specs still pass.
Unrelated to this PR: run from a bare script, the multipart code raises NameError for StringIO, which it uses without requiring stringio. Rails and Rack apps load it already. This run loads stringio first, as a host app would.
Gem output
...
Batch.create(file:): FatZebra::RequestError: Status 500: Server Error, please check with service
5. Ruby floor
Built the gem from this branch and installed it locally.
Gem install
$ gem install --local fat_zebra-pr82.gem # on Ruby 3.2.2
...
fat_zebra-0.0.0.pre.build requires Ruby version >= 3.3. The current ruby version is 3.2.2.
$ gem install --local fat_zebra-pr82.gem # on Ruby 3.3.7
Successfully installed fat_zebra-0.0.0.pre.build
1 gem installed
Conclusion
On json 3, update works with this branch and raises without it. Test mode still sends test once, the boolean validator lets Batch.create through, and Ruby 3.2 can't install it.
- An object's attributes are string-keyed (they come from the API's JSON)
but callers pass symbols, so web_hook.update(name: 'x') built a payload
with both "name" and :name. json 2.x sent both keys; json 3 raises
JSON::GeneratorError, so update failed outright for merchants on json 3.
- Normalising both sides to strings makes the caller's value replace the
old one, and lets the existing delete('id') catch a symbol :id too.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- \A and \z bound only one alternative each, so /\Atrue|false\z/ accepted
anything starting with "true" or ending in "false".
- Only Batch.create uses it, and it always sets multipart to true, so no
merchant request changes.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- CI stopped testing Ruby 3.2 in February and 3.2 went end of life in March
2026, but the gemspec still allowed it, so Bundler would install releases
on 3.2 that nobody had run there.
- Merchants still on 3.2 keep resolving to the last release that allowed it.
- rubocop's target follows the floor.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- The base-ref check set JSON_ENV_VARS from inputs.credentials_json, but the
workflow has no inputs (it runs on push) and the step never reads it.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Stringifying every key fixed the "name"/:name duplicate, but made new
ones: in test mode, save(test: true) sent both "test" and the :test that
APIResource.request adds, which json 3 refuses to generate, and a
multipart save lost the symbol :multipart, :file and :filename keys
Request#post and the multipart encoder read.
- Save#save now drops the old value of any attribute the caller sets,
whatever its key type, and sends the caller's keys unchanged.
- The id is still never sent, as "id" or :id.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Remove string-keyed :test conflicts before request serialization
lib/fat_zebra/api_operation/save.rb:57
web_hook.update('test' => true) still retains "test", and APIResource.request adds :test in test mode (lib/fat_zebra/api_resource.rb:29), so json 3 raises before sending the request. An existing "test" attribute causes the same failure even without a test parameter. Remove the string form when injecting :test, and cover string-keyed parameters and stored attributes through request preparation.
json 3 still raised when one name arrived as both a string and a
symbol inside the caller's own params, not just across stored and new
values. PaymentPlan#suspend! and #active! merge a symbol default into
the caller's hash, so suspend!('new_status' => 'Cancelled') sent both,
and in test mode a caller's string 'test' sat beside the :test that
APIResource.request adds.
- Save#save keeps one value per name across the stored attributes and
the caller's params, the last one given, under its own key type, so
multipart's symbol keys still reach Request#post.
- Test mode replaces a string 'test' rather than adding beside it.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
updateon any resource raisesJSON::GeneratorErrorfor merchants on json 3.Save#savemerges the object's string-keyed attributes with the caller's params, soweb_hook.update(name: 'x')builds a payload with both"name"and:name. json 2.x sends both keys and the gateway's parser keeps the last one; json 3 refuses to generate it. Merchants on json 2.x see no change.Save#savenow sends each attribute once, whether it arrives as a string or a symbol, from the stored attributes or the caller (PaymentPlan#suspend!('new_status' => …)used to send both). The caller's value wins, under the caller's key, so a multipart save's:multipartand:filekeep working. The id is never sent as"id"or:id.'test'with:testinstead of adding a second key.:booleanvalidator's/\Atrue|false\z/anchored only one side of each word, so"trueish"passed. OnlyBatch.createuses it, and it always setstrue, so no request changes.JSON_ENV_VARSenv var from the release job.Ticket: PAY-7046. Released as 3.4.0, a minor version because of the Ruby floor change.
Security Impact
No new data sent.
Save#savenow also drops a caller's symbol:id, so an update body never carries the id. No change to authentication, card data handling or the gem's dependencies.Rollback
Revert and tag a new release. Until then, merchants can pin
fat_zebrato3.2.9. No data involved.Testing
E2E testing evidence provided in a comment: on Ruby 4 with json 3,
updateworks against a local gateway and raises from main.Save#savebuilds: each attribute once, with the caller's value and noid, a name passed as both a string and a symbol sent once,suspend!with a stringnew_statussent once, and in test modetestsent once whichever key type the caller used. The first fails on main with the duplicated"name"/:nameand the symbol:idin the payload.trueandfalseand reject"trueish"and"notfalse".WebHook#updateexamples that failed on Ruby 4 before.🤖 Generated with Claude Code
Claude sessions
PR Reviews·57e8f9d7-6655-4c30-84cd-74040767eca2· 2026-11-26PR Reviews·57e8f9d7-6655-4c30-84cd-74040767eca2· 2026-12-01 · owner