Sha256: d1e15fd7a335923e93207f5e940655bfa0bc4b59beae6acef1324ebd04e65638

Contents?: true

Size: 1.22 KB

Versions: 5

Compression:

Stored size: 1.22 KB

Contents

RSpec.describe 'Plugins / :auto_wrap' do
  with_adapters do
    include_context 'users and tasks'

    describe '#for_wrap' do
      shared_context 'joined tuple' do
        it 'returns joined tuples' do
          task_with_user = tasks
            .for_wrap({ id: :user_id }, users.name.relation)
            .where(tasks__id: 2)
            .one

          expect(task_with_user).to eql(
            id: 2, user_id: 1, title: "Jane's task", users_name: "Jane", users_id: 1
          )
        end
      end

      context 'when parent relation is registered under dataset name' do
        subject(:tasks) { relations[:tasks] }

        let(:users) { relations[:users] }

        before do
          conf.relation(:tasks) { schema(infer: true) }
          conf.relation(:users) { schema(infer: true) }
        end

        include_context 'joined tuple'
      end

      context 'when parent relation is registered under a custom name' do
        subject(:tasks) { relations[:tasks] }

        let(:users) { relations[:authors] }

        before do
          conf.relation(:tasks) { schema(infer: true) }
          conf.relation(:authors) { schema(:users, infer: true) }
        end

        include_context 'joined tuple'
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
rom-sql-1.0.0.rc2 spec/integration/plugins/auto_wrap_spec.rb
rom-sql-1.0.0.rc1 spec/integration/plugins/auto_wrap_spec.rb
rom-sql-1.0.0.beta3 spec/integration/plugins/auto_wrap_spec.rb
rom-sql-1.0.0.beta2 spec/integration/plugins/auto_wrap_spec.rb
rom-sql-1.0.0.beta1 spec/integration/plugins/auto_wrap_spec.rb