Sha256: 136327d86a64f452911004661c1368685bbb9027604ba39bb6eb4d4eedcead63

Contents?: true

Size: 1.46 KB

Versions: 1

Compression:

Stored size: 1.46 KB

Contents

require 'spec_helper'

[ :join, :+ ].each do |method|
  describe "Veritas::Algebra::Join::Methods##{method}" do
    let(:klass)  { Relation                                                                                           }
    let(:object) { klass.new([ [ :id, Integer ], [ :name, String  ] ], [ [ 1, 'Dan Kubb' ], [ 2, 'Dan Kubb' ] ].each) }

    context 'without predicate arguments or a block' do
      subject { object.send(method, other) }

      let(:other) { klass.new([ [ :id, Integer ], [ :age, Integer ] ], [ [ 1, 35 ] ]) }

      it { should be_kind_of(Algebra::Join) }
    end

    context 'with predicate arguments' do
      subject { object.send(method, other, predicate) }

      let(:other)     { klass.new([ Attribute::Boolean.new(:active) ], [ [ true ] ]) }
      let(:predicate) { object[:id].eq(1)                                            }

      it { should be_kind_of(Algebra::Restriction) }

      it 'restricts a product' do
        should == [ [ 1, 'Dan Kubb', true ] ]
      end
    end

    context 'with a block' do
      subject { object.send(method, other, &block) }

      let(:other) { klass.new([ Attribute::Boolean.new(:active) ], [ [ true ] ]) }
      let(:block) do
        lambda do |relation|
          relation[:id].eq(1).and(relation[:active].eq(true))
        end
      end

      it { should be_kind_of(Algebra::Restriction) }

      it 'restricts a product' do
        should == [ [ 1, 'Dan Kubb', true ] ]
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
veritas-0.0.2 spec/unit/veritas/algebra/join/methods/join_spec.rb