Sha256: 4397abf71040861c86517929948bcd76798ad3d7f6ced9406f36844231adc602

Contents?: true

Size: 1.65 KB

Versions: 9

Compression:

Stored size: 1.65 KB

Contents

require 'spec_helper'
module Alf
  module Engine
    describe Join::Hash do

      let(:suppliers) {[
        {:sid => 'S1', :city => 'London'},
        {:sid => 'S2', :city => 'Paris'},
        {:sid => 'S3', :city => 'Paris'}
      ]}

      let(:statuses) {[
        {:sid => 'S1', :status => 20},
        {:sid => 'S2', :status => 10},
        {:sid => 'S3', :status => 30}
      ]}

      let(:countries) {[
        {:city => 'London',    :country => 'England'},
        {:city => 'Paris',     :country => 'France'},
        {:city => 'Bruxelles', :country => 'Belgium'}
      ]}

      context "when applied on candidate keys on both sides" do
        subject{ Join::Hash.new(suppliers, statuses).to_a }
        let(:expected){[
          {:sid => 'S1', :city => 'London', :status => 20},
          {:sid => 'S2', :city => 'Paris', :status => 10},
          {:sid => 'S3', :city => 'Paris', :status => 30}
        ]}
        it { should == expected }
      end

      context "when applied on a typical foreign key" do
        subject{ Join::Hash.new(suppliers, countries).to_a }
        let(:expected){[
          {:sid => 'S1', :city => 'London', :country => 'England'},
          {:sid => 'S2', :city => 'Paris',  :country => 'France'},
          {:sid => 'S3', :city => 'Paris',  :country => 'France'}
        ]}
        it { should == expected }
      end

      context "when applied with no attributes in common" do
        subject{ Join::Hash.new(statuses, countries).to_a }
        let(:expected){
          statuses.collect{|s| countries.collect{|c| c.merge(s)}}.flatten
        }
        it { should == expected }
      end

    end
  end # module Engine
end # module Alf    

Version data entries

9 entries across 9 versions & 2 rubygems

Version Path
alf-core-0.15.0 spec/unit/alf-engine/join/test_hash.rb
alf-core-0.14.0 spec/unit/alf-engine/join/test_hash.rb
alf-core-0.13.1 spec/unit/alf-engine/join/test_hash.rb
alf-core-0.13.0 spec/unit/alf-engine/join/test_hash.rb
alf-0.12.2 spec/unit/alf-engine/join/test_hash.rb
alf-0.12.1 spec/unit/alf-engine/join/test_hash.rb
alf-0.12.0 spec/unit/alf-engine/join/test_hash.rb
alf-0.11.1 spec/unit/alf-engine/join/test_hash.rb
alf-0.11.0 spec/unit/alf-engine/join/test_hash.rb