Sha256: 01bae34355cb03ba0afec5fc65d6ae6d17f87b680c113cab04145ae93a00e3b6

Contents?: true

Size: 808 Bytes

Versions: 19

Compression:

Stored size: 808 Bytes

Contents

require 'rails_helper'

describe LHS::Item do
  before(:each) do
    class Record < LHS::Record
      endpoint ':datastore/records'
    end
  end

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

  let(:item) do
    LHS::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

19 entries across 19 versions & 1 rubygems

Version Path
lhs-14.6.5 spec/item/map_spec.rb
lhs-14.6.4 spec/item/map_spec.rb
lhs-14.6.3 spec/item/map_spec.rb
lhs-14.6.2 spec/item/map_spec.rb
lhs-14.6.1 spec/item/map_spec.rb
lhs-14.6.0 spec/item/map_spec.rb
lhs-14.5.0 spec/item/map_spec.rb
lhs-14.4.0 spec/item/map_spec.rb
lhs-14.3.4 spec/item/map_spec.rb
lhs-14.3.3 spec/item/map_spec.rb
lhs-14.3.2 spec/item/map_spec.rb
lhs-14.3.1 spec/item/map_spec.rb
lhs-14.3.0 spec/item/map_spec.rb
lhs-14.2.0 spec/item/map_spec.rb
lhs-14.1.1 spec/item/map_spec.rb
lhs-14.1.0 spec/item/map_spec.rb
lhs-14.0.3 spec/item/map_spec.rb
lhs-14.0.2 spec/item/map_spec.rb
lhs-14.0.1 spec/item/map_spec.rb