Sha256: c1593d1e94169f7c269e2dd90bb04d2dcf7d7f0bcc13898845e4444af9c45889

Contents?: true

Size: 1.05 KB

Versions: 1

Compression:

Stored size: 1.05 KB

Contents

require 'spec_helper'

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

  specify 'defining a grouped relation' do
    setup.relation(:users) do
      include ROM::RA

      def with_tasks
        group(join(tasks), tasks: [:title, :priority])
      end

      def by_name(name)
        restrict(name: name)
      end

    end

    users = rom.relations.users

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

    expect(users.with_tasks.by_name("Jane").to_a).to eql(
      [
        { name: "Jane", email: "jane@doe.org", tasks: [{ title: "be cool", priority: 2 }] }
      ]
    )

    expect(users.by_name("Jane").with_tasks.to_a).to eql(
      [
        { name: "Jane", email: "jane@doe.org", tasks: [{ title: "be cool", priority: 2 }] }
      ]
    )
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rom-0.4.2 spec/integration/ra/group_spec.rb