Sha256: b6aadaa8dc7f6d8242e866cc7d1a6584491fcbb3ad5ddbd667902887b4008ec0

Contents?: true

Size: 1.29 KB

Versions: 18

Compression:

Stored size: 1.29 KB

Contents

require 'spec_helper'

RSpec.describe ROM::Relation::Loaded do
  include_context 'no container'
  include_context 'users and tasks'

  subject(:users) { ROM::Relation::Loaded.new(users_relation) }

  describe '#each' do
    it 'yields tuples from relation' do
      result = []

      users.each do |tuple|
        result << tuple
      end

      expect(result).to match_array([
        { name: 'Jane', email: 'jane@doe.org' },
        { name: 'Joe', email: 'joe@doe.org' }
      ])
    end

    it 'returns enumerator when block is not provided' do
      expect(users.each.to_a).to eql(users.collection.to_a)
    end
  end

  describe '#to_ary' do
    it 'coerces to an array' do
      expect(users.to_ary).to match_array([
        { name: 'Jane', email: 'jane@doe.org' },
        { name: 'Joe', email: 'joe@doe.org' }
      ])
    end
  end

  describe '#pluck' do
    it 'returns a list of values under provided key' do
      expect(users.pluck(:email)).to eql(%w(joe@doe.org jane@doe.org))
    end
  end

  describe '#primary_keys' do
    it 'returns a list of primary key values' do
      expect(users.source).to receive(:primary_key).and_return(:name)
      expect(users.primary_keys).to eql(%w(Joe Jane))
    end
  end

  it_behaves_like 'a relation that returns one tuple' do
    let(:relation) { users }
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
rom-3.3.3 spec/unit/rom/relation/loaded_spec.rb
rom-3.3.2 spec/unit/rom/relation/loaded_spec.rb
rom-3.3.1 spec/unit/rom/relation/loaded_spec.rb
rom-3.3.0 spec/unit/rom/relation/loaded_spec.rb
rom-3.2.3 spec/unit/rom/relation/loaded_spec.rb
rom-3.2.2 spec/unit/rom/relation/loaded_spec.rb
rom-3.2.1 spec/unit/rom/relation/loaded_spec.rb
rom-3.2.0 spec/unit/rom/relation/loaded_spec.rb
rom-3.1.0 spec/unit/rom/relation/loaded_spec.rb
rom-3.0.3 spec/unit/rom/relation/loaded_spec.rb
rom-3.0.2 spec/unit/rom/relation/loaded_spec.rb
rom-3.0.1 spec/unit/rom/relation/loaded_spec.rb
rom-3.0.0 spec/unit/rom/relation/loaded_spec.rb
rom-3.0.0.rc2 spec/unit/rom/relation/loaded_spec.rb
rom-3.0.0.rc1 spec/unit/rom/relation/loaded_spec.rb
rom-3.0.0.beta3 spec/unit/rom/relation/loaded_spec.rb
rom-3.0.0.beta2 spec/unit/rom/relation/loaded_spec.rb
rom-3.0.0.beta1 spec/unit/rom/relation/loaded_spec.rb