Sha256: f4780685f6b86916aabaa5ce09893a0a7ac5238622cc94d531197f7bd4a4dcb9

Contents?: true

Size: 803 Bytes

Versions: 19

Compression:

Stored size: 803 Bytes

Contents

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

19 entries across 19 versions & 1 rubygems

Version Path
lhs-16.1.5 spec/item/map_spec.rb
lhs-16.1.4 spec/item/map_spec.rb
lhs-16.1.3 spec/item/map_spec.rb
lhs-16.1.2 spec/item/map_spec.rb
lhs-16.1.1 spec/item/map_spec.rb
lhs-16.1.0 spec/item/map_spec.rb
lhs-16.0.1 spec/item/map_spec.rb
lhs-16.0.0 spec/item/map_spec.rb
lhs-15.7.0 spec/item/map_spec.rb
lhs-15.6.1 spec/item/map_spec.rb
lhs-15.6.0 spec/item/map_spec.rb
lhs-15.5.1 spec/item/map_spec.rb
lhs-15.5.0 spec/item/map_spec.rb
lhs-15.4.1 spec/item/map_spec.rb
lhs-15.4.0 spec/item/map_spec.rb
lhs-15.4.0.pre.hasone.1 spec/item/map_spec.rb
lhs-15.3.3 spec/item/map_spec.rb
lhs-15.3.3.pre.fixoptions.1 spec/item/map_spec.rb
lhs-15.3.2 spec/item/map_spec.rb