Sha256: 0d04d40720863b4372f85807da7de176cc586822e3d432ef4eb28d4158afebd6

Contents?: true

Size: 905 Bytes

Versions: 9

Compression:

Stored size: 905 Bytes

Contents

require 'spec_helper'

describe 'Eager loading' do
  include_context 'users and tasks'

  before do
    setup.relation(:users) do
      def by_name(name)
        where(name: name)
      end
    end

    setup.relation(:tasks) do
      def for_users(users)
        where(user_id: users.map { |tuple| tuple[:id] })
      end
    end

    setup.relation(:tags) do
      def for_tasks(tasks)
        inner_join(:task_tags, task_id: :id)
          .where(task_id: tasks.map { |tuple| tuple[:id] })
      end
    end
  end

  it 'issues 3 queries for 3 combined relations' do
    users = rom.relation(:users).by_name('Piotr')
    tasks = rom.relation(:tasks)
    tags = rom.relation(:tags)

    relation = users.combine(tasks.for_users.combine(tags.for_tasks))

    # TODO: figure out a way to assert correct number of issued queries
    expect(relation.call).to be_instance_of(ROM::Relation::Loaded)
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
rom-sql-0.6.1 spec/integration/combine_spec.rb
rom-sql-0.6.0 spec/integration/combine_spec.rb
rom-sql-0.6.0.rc1 spec/integration/combine_spec.rb
rom-sql-0.6.0.beta1 spec/integration/combine_spec.rb
rom-sql-0.5.3 spec/integration/combine_spec.rb
rom-sql-0.5.2 spec/integration/combine_spec.rb
rom-sql-0.5.1 spec/integration/combine_spec.rb
rom-sql-0.5.0 spec/integration/combine_spec.rb
rom-sql-0.4.3 spec/integration/combine_spec.rb