Sha256: 731accefeeac89b9d699571d5b9d3ac4a92017e1bb19ce043c3207aedb86da46

Contents?: true

Size: 834 Bytes

Versions: 12

Compression:

Stored size: 834 Bytes

Contents

# frozen_string_literal: true

require 'rails_helper'

describe DHS::Item do
  before do
    class Record < DHS::Record
      endpoint '{+datastore}/records'
    end
  end

  let(:json) do
    {
      key: 'value'
    }
  end

  let(:item) do
    DHS::Data.new(json, nil, Record)
  end

  it 'is possible to map' do
    mapped_data = item.map do |key, value|
      { value => key }
    end
    expect(mapped_data).to eq([{ 'value' => :key }])
  end

  context 'nested' do
    let(:json) do
      {
        languages: {
          de: { key: 'german value' },
          en: { key: 'english value' }
        }
      }
    end

    it 'also maps nested data' do
      mapped_data = item.languages.map do |_language, value|
        value[:key]
      end
      expect(mapped_data).to eq(['german value', 'english value'])
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
dhs-1.6.0 spec/item/map_spec.rb
dhs-1.5.0 spec/item/map_spec.rb
dhs-1.4.2 spec/item/map_spec.rb
dhs-1.4.1 spec/item/map_spec.rb
dhs-1.4.0 spec/item/map_spec.rb
dhs-1.3.0 spec/item/map_spec.rb
dhs-1.2.0 spec/item/map_spec.rb
dhs-1.1.0 spec/item/map_spec.rb
dhs-1.0.3 spec/item/map_spec.rb
dhs-1.0.2 spec/item/map_spec.rb
dhs-1.0.1 spec/item/map_spec.rb
dhs-1.0.0 spec/item/map_spec.rb