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-26.2.0 spec/item/map_spec.rb
lhs-26.1.0 spec/item/map_spec.rb
lhs-26.0.1 spec/item/map_spec.rb
lhs-26.0.0 spec/item/map_spec.rb
lhs-25.2.0 spec/item/map_spec.rb
lhs-25.1.0 spec/item/map_spec.rb
lhs-25.0.4 spec/item/map_spec.rb
lhs-25.0.3 spec/item/map_spec.rb
lhs-25.0.2 spec/item/map_spec.rb
lhs-25.0.1 spec/item/map_spec.rb
lhs-25.0.0 spec/item/map_spec.rb
lhs-24.1.2 spec/item/map_spec.rb
lhs-24.1.1 spec/item/map_spec.rb
lhs-24.1.0 spec/item/map_spec.rb
lhs-24.1.0.pre.2 spec/item/map_spec.rb
lhs-24.1.0.pre.1 spec/item/map_spec.rb
lhs-24.0.0 spec/item/map_spec.rb
lhs-23.0.2 spec/item/map_spec.rb
lhs-23.0.1 spec/item/map_spec.rb
lhs-23.0.0 spec/item/map_spec.rb