fix: stringify js options when serialized for the payload #1089
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.
Description of the change
Background
Rollbar-gem includes middleware that configures Rollbar.js for the javascript client. The Rollbar.js options are passed as part of the Rollbar-gem config. Some valid js options are javascript functions that by default, the Ruby JSON serializer will convert to strings, however the js config needs these as functions not strings.
In #821 a custom type was added that allows these to be passed to the js config correctly as functions. When serializing the same options to the payload (for the diagnostic
configured_options
key) these were passed as strings.In #890 the payload serialization was refactored, and the js functions were no longer stringified correctly in the payload. The test automation didn't cover this case and it went unnoticed.
The fix
This PR signals to the custom data type whether it should stringify the js functions by optionally sending a subclassed state object when calling
JSON.generate
. The subclass is necessary because the state class doesn't allow custom attributes to be added.This PR also adds a test to confirm the payload serialization.
Type of change
Related issues
Fixes #1086
Development
Code review