Sha256: aa6554c7b4b33cfdab019e11864340276b59d4aefa6a892d2c638fb4c35b2a88

Contents?: true

Size: 834 Bytes

Versions: 76

Compression:

Stored size: 834 Bytes

Contents

# frozen_string_literal: true

require 'rails_helper'

describe LHS::Item do
  before 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

76 entries across 76 versions & 1 rubygems

Version Path
lhs-21.0.0 spec/item/map_spec.rb
lhs-20.1.4 spec/item/map_spec.rb
lhs-20.1.3.pre.paginationfix.3 spec/item/map_spec.rb
lhs-20.1.3.pre.paginationfix.2 spec/item/map_spec.rb
lhs-20.1.3.pre.paginationfix.1 spec/item/map_spec.rb
lhs-20.1.2 spec/item/map_spec.rb
lhs-20.1.1 spec/item/map_spec.rb
lhs-20.0.0 spec/item/map_spec.rb
lhs-19.10.0 spec/item/map_spec.rb
lhs-19.9.0 spec/item/map_spec.rb
lhs-19.8.2 spec/item/map_spec.rb
lhs-19.8.1 spec/item/map_spec.rb
lhs-19.8.0 spec/item/map_spec.rb
lhs-19.7.0 spec/item/map_spec.rb
lhs-19.6.0 spec/item/map_spec.rb
lhs-19.5.0 spec/item/map_spec.rb
lhs-19.5.0.pre.wherehref.1 spec/item/map_spec.rb
lhs-19.4.1 spec/item/map_spec.rb
lhs-19.4.0 spec/item/map_spec.rb
lhs-19.3.1 spec/item/map_spec.rb