Sha256: 9b6db52653c7bb7d37cb27e2de95eca484b235dcbb105015bbacc2e987336b55

Contents?: true

Size: 1.24 KB

Versions: 4

Compression:

Stored size: 1.24 KB

Contents

require 'spec_helper'

describe 'Group operation' do
  subject(:group) { opts = options; relation.in_memory { group(opts) } }

  let(:relation) do
    ROM::Relation.new(dataset, header)
  end

  let(:header) do
    [:name, :email, :street, :zipcode, :city]
  end

  let(:options) do
    { addresses: [:street, :zipcode, :city] }
  end

  context 'when group values are present' do
    let(:dataset) do
      [{ name: 'Jane',
       email: 'jane@doe.org',
       street: 'Street 1',
       zipcode: '1234',
       city: 'Cracow' }]
    end

    it 'groups given attributes under specified key' do
      expect(group.to_a).to eql(
        [{ name: 'Jane',
           email: 'jane@doe.org',
           addresses: [{ street: 'Street 1', zipcode: '1234', city: 'Cracow' }] }]
      )
    end

    it 'exposes the header' do
      expect(group.header).to eql([:name, :email, :addresses])
    end
  end

  context 'when group values are not present' do
    let(:dataset) do
      [{ name: 'Jane',
       email: 'jane@doe.org',
       street: nil,
       zipcode: nil,
       city: nil }]
    end

    it 'sets empty array for grouped attributes' do
      expect(group.to_a).to eql(
        [{ name: 'Jane', email: 'jane@doe.org', addresses: [] }]
      )
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
rom-0.4.1 spec/unit/rom/ra/operation/group_spec.rb
rom-0.4.0 spec/unit/rom/ra/operation/group_spec.rb
rom-0.3.1 spec/unit/rom/ra/operation/group_spec.rb
rom-0.3.0 spec/unit/rom/ra/operation/group_spec.rb