Sha256: d6f16c4018b3150a89d0e2ebeae58370ae3031de7719033499bcba804c6d67af

Contents?: true

Size: 1.23 KB

Versions: 18

Compression:

Stored size: 1.23 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:00.000Z"}')
      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, use_to_json: true, 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 JSON" do
      allow(JSON).to receive(:parse)

      payload = '{"key":"value"}'

      described_class.parse(payload)

      expect(JSON).to have_received(:parse).with(payload)
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
search_flip-3.9.0 spec/search_flip/json_spec.rb
search_flip-4.0.0.beta16 spec/search_flip/json_spec.rb
search_flip-4.0.0.beta14 spec/search_flip/json_spec.rb
search_flip-3.8.0 spec/search_flip/json_spec.rb
search_flip-4.0.0.beta13 spec/search_flip/json_spec.rb
search_flip-3.7.2 spec/search_flip/json_spec.rb
search_flip-4.0.0.beta12 spec/search_flip/json_spec.rb
search_flip-3.7.1 spec/search_flip/json_spec.rb
search_flip-4.0.0.beta11 spec/search_flip/json_spec.rb
search_flip-3.7.0 spec/search_flip/json_spec.rb
search_flip-4.0.0.beta10 spec/search_flip/json_spec.rb
search_flip-3.6.0 spec/search_flip/json_spec.rb
search_flip-3.5.0 spec/search_flip/json_spec.rb
search_flip-4.0.0.beta9 spec/search_flip/json_spec.rb
search_flip-4.0.0.beta8 spec/search_flip/json_spec.rb
search_flip-3.4.0 spec/search_flip/json_spec.rb
search_flip-3.3.0 spec/search_flip/json_spec.rb
search_flip-4.0.0.beta7 spec/search_flip/json_spec.rb