Sha256: 2380a4e9ae5a5bb815a0882018a700704155f239b5ce4d0ec50e9ced73ebeea1

Contents?: true

Size: 1.47 KB

Versions: 1

Compression:

Stored size: 1.47 KB

Contents

require 'spec_helper'

module ReplayApi
  describe CompactAttributes do
    subject(:container_class) { Struct.new(:attributes) }
    let(:container) { container_class.new(attributes) }
    let(:attributes) { {} }
    before do
      container_class.include CompactAttributes
    end

    describe '#compact_attributes' do
      test_cases = {
        {} => {},
        { attribute1: nil } => {},
        { attribute1: :value1 } => { attribute1: :value1 },
        { attribute1: :value1, attribute2: nil } => { attribute1: :value1 },
        { attribute1: :value1, attribute2: {} } => { attribute1: :value1 },
        { attribute1: :value1, attribute2: { attribute3: :value3 } } => { attribute1: :value1, attribute2: { attribute3: :value3 } },
        { attribute1: :value1, attribute2: { attribute3: nil } } => { attribute1: :value1 },
        { attribute1: :value1, attribute2: { attribute3: :value3, attribute4: nil } } => { attribute1: :value1, attribute2: { attribute3: :value3 } },
        { attribute1: :value1, attribute2: Event.new(event_name: 'Test Event', properties: { timestamp: 12345 }) } => { attribute1: :value1, attribute2: { event_name: 'Test Event', properties: { event_category: 'general', past_event: 0, timestamp: 12345 } } },
      }

      test_cases.each do |input, output|
        context "when attributes is #{input.inspect}" do
          let(:attributes) { input }

          specify { expect(container.compact_attributes).to eq output }
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
replay_api-0.0.3 spec/replay_api/compact_attributes_spec.rb