Sha256: 22bbb435c202bfb28802edc93ccb7691c62c138323ab45355cb70bb927e590ea

Contents?: true

Size: 681 Bytes

Versions: 5

Compression:

Stored size: 681 Bytes

Contents

require 'rom/elasticsearch/relation'

RSpec.describe ROM::Elasticsearch::Relation, '#to_a' do
  subject(:relation) { relations[:users] }

  include_context 'users'

  before do
    relation.command(:create).(id: 1, name: 'Jane')
    relation.command(:create).(id: 2, name: 'John')

    relation.refresh
  end

  it 'returns user tuples' do
    expect(relation).to match_array([{ id: 1, name: 'Jane' }, { id: 2, name: 'John' }])
  end

  it 'returns user structs' do
    jane, john = relation.with(auto_struct: true).to_a.sort_by(&:name)

    expect(jane.id).to be(1)
    expect(jane.name).to eql('Jane')

    expect(john.id).to be(2)
    expect(john.name).to eql('John')
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
rom-elasticsearch-0.3.0 spec/unit/rom/elasticsearch/relation/to_a_spec.rb
rom-elasticsearch-0.2.1 spec/unit/rom/elasticsearch/relation/to_a_spec.rb
rom-elasticsearch-0.2.0 spec/unit/rom/elasticsearch/relation/to_a_spec.rb
rom-elasticsearch-0.1.1 spec/unit/rom/elasticsearch/relation/to_a_spec.rb
rom-elasticsearch-0.1.0 spec/unit/rom/elasticsearch/relation/to_a_spec.rb