Sha256: 3b70474f1daf2b24b29990d04e6451f45ad9916275810e210ae764ed59e411ce

Contents?: true

Size: 1.12 KB

Versions: 3

Compression:

Stored size: 1.12 KB

Contents

require "spec_helper"

describe 'Join operation' do
  include_context 'users and tasks'

  specify 'defining a joined one-to-many relation' do
    setup.relation(:users) do
      def with_tasks
        in_memory { join(tasks) }
      end
    end

    setup.relation(:tasks)

    users = rom.relations.users

    expect(users.with_tasks.to_a).to eql(
      [
        { name: 'Joe', email: 'joe@doe.org', title: 'be nice', priority: 1 },
        { name: 'Joe', email: 'joe@doe.org', title: 'sleep well', priority: 2 },
        { name: 'Jane', email: 'jane@doe.org', title: 'be cool', priority: 2 }
      ]
    )
  end

  specify 'defining a joined many-to-one relation' do
    setup.relation(:users)

    setup.relation(:tasks) do
      def with_user
        in_memory { join(users) }
      end
    end

    tasks = rom.relations.tasks

    expect(tasks.with_user.to_a).to eql(
      [
        { title: 'be nice', priority: 1, name: 'Joe', email: 'joe@doe.org' },
        { title: 'sleep well', priority: 2, name: 'Joe', email: 'joe@doe.org' },
        { title: 'be cool', priority: 2, name: 'Jane', email: 'jane@doe.org' }
      ]
    )
  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
rom-0.4.1 spec/integration/ra/join_spec.rb
rom-0.4.0 spec/integration/ra/join_spec.rb
rom-0.3.1 spec/integration/ra/join_spec.rb