Sha256: 460f378357b2fbef86ebce41350c8d42780886bf2f5555da05c3bf055a344ff7

Contents?: true

Size: 825 Bytes

Versions: 5

Compression:

Stored size: 825 Bytes

Contents

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 (only possible if column has a default)" do
      let(:raw) { "" }
      it { is_expected.to eq(nil) }
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
vault-rails-0.8.0 spec/lib/vault/rails/json_serializer_spec.rb
vault-rails-0.7.1 spec/lib/vault/rails/json_serializer_spec.rb
vault-rails-0.7.0 spec/lib/vault/rails/json_serializer_spec.rb
vault-rails-0.6.0 spec/lib/vault/rails/json_serializer_spec.rb
vault-rails-0.5.0 spec/lib/vault/rails/json_serializer_spec.rb