Sha256: 24c198ed87c3c8fde0ad6ce13386f8f74151d870eec89909880ccfc174620ac9
Contents?: true
Size: 1.27 KB
Versions: 1
Compression:
Stored size: 1.27 KB
Contents
require File.expand_path("../spec_helper", __dir__) RSpec.describe SearchFlip::JSON do describe ".generate" do it "encodes timestamps correctly" do Timecop.freeze "2020-06-01 12:00:00 UTC" do expect(described_class.generate(timestamp: Time.now.utc)).to eq('{"timestamp":"2020-06-01T12:00:00Z"}') end end it "encodes bigdecimals as string" do expect(described_class.generate(value: BigDecimal(1))).to eq('{"value":"1.0"}') end it "delegates to Oj" do allow(Oj).to receive(:dump) payload = { key: "value" } described_class.generate(payload) expect(Oj).to have_received(:dump).with(payload, mode: :custom, time_format: :xmlschema, bigdecimal_as_decimal: false) end it "generates json" do expect(described_class.generate(key: "value")).to eq('{"key":"value"}') end end describe ".parse" do it "returns the parsed json payload" do expect(described_class.parse('{"key":"value"}')).to eq("key" => "value") end it "delegates to Oj" do allow(Oj).to receive(:load) payload = '{"key":"value"}' described_class.parse(payload) expect(Oj).to have_received(:load).with(payload, mode: :custom, time_format: :xmlschema, bigdecimal_as_decimal: false) end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
search_flip-4.0.0.beta4 | spec/search_flip/json_spec.rb |