Sha256: fe66c284137947c87f7442ab2fa61593e52b3e64b7dda03a0adf61dab8e05744

Contents?: true

Size: 566 Bytes

Versions: 3

Compression:

Stored size: 566 Bytes

Contents

require 'spec_helper'

describe 'Defining one-to-many association' do
  include_context 'users and tasks'

  it 'extends relation with association methods' do
    setup.relation(:tasks)

    setup.relation(:users) do
      one_to_many :tasks, key: :user_id

      def by_name(name)
        where(name: name)
      end

      def with_tasks
        association_join(:tasks)
      end
    end

    users = rom.relations.users

    expect(users.with_tasks.by_name("Piotr").to_a).to eql(
      [{ id: 1, user_id: 1, name: 'Piotr', title: 'Finish ROM' }]
    )
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
rom-sql-0.2.0 spec/unit/one_to_many_spec.rb
rom-sql-0.1.1 spec/unit/one_to_many_spec.rb
rom-sql-0.1.0 spec/unit/one_to_many_spec.rb