-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The existing behavior when specifying `serializer: :json` was to store and return an empty Hash (`{}`) for null or empty values, including empty arrays. This changes the encode logic to store the JSON representation of any given value. During decode, any valid JSON string can be decoded. We special case `nil` or `""` (empty string) to return `nil` (instead of `{}` previously). This could be a breaking for applications that depend on the empty hash == nil behavior.
- Loading branch information
1 parent
414f1bd
commit 43b7fd1
Showing
2 changed files
with
44 additions
and
3 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
require 'spec_helper' | ||
|
||
RSpec.describe Vault::Rails::JSONSerializer do | ||
[ | ||
nil, | ||
false, | ||
true, | ||
"", | ||
"foo", | ||
{}, | ||
{ "foo" => "bar" }, | ||
[], | ||
["foo", "bar"], | ||
0, | ||
123, | ||
0.0, | ||
0.123, | ||
0xff, | ||
123e123 | ||
].each do |object| | ||
it "encodes and decodes #{object.inspect}" do | ||
encoded = described_class.encode(object) | ||
expect(encoded).to be_a(String) | ||
decoded = described_class.decode(encoded) | ||
expect(decoded).to eq(object) | ||
end | ||
end | ||
|
||
describe ".decode" do | ||
subject(:decoded) { described_class.decode(raw) } | ||
|
||
context "with nil" do | ||
let(:raw) { nil } | ||
it { is_expected.to eq(nil) } | ||
end | ||
|
||
context "with an empty string" do | ||
let(:raw) { "" } | ||
it { is_expected.to eq(nil) } | ||
end | ||
end | ||
end |