Sha256: 30da758aa15fbada4face5e7c50b607ab63b5ed776f3d82152d7d9988a29da28

Contents?: true

Size: 1.44 KB

Versions: 10

Compression:

Stored size: 1.44 KB

Contents

require 'spec_helper'
module Alf
  describe Relation do
    
    let(:tuples_by_sid){[
      {:sid => 'S1', :name => 'Smith', :status => 20, :city => 'London'},
      {:sid => 'S2', :name => 'Jones', :status => 10, :city => 'Paris'},
      {:sid => 'S3', :name => 'Blake', :status => 30, :city => 'Paris'}
    ]}
    let(:rel){ Relation.new tuples_by_sid.to_set }
    let(:tuples_by_name){ tuples_by_sid.sort{|t1,t2| t1[:name] <=> t2[:name]} }
    
    describe "coerce" do
      
      subject{ Relation.coerce(arg) }
      
      describe "with a Relation" do
        let(:arg){ rel }
        it{ should be_a(Relation) }
        it{ should == rel } 
      end
    
      describe "with a set of tuples" do
        let(:arg){ tuples_by_name.to_set }
        it{ should be_a(Relation) }
        it{ should == rel }
      end
    
      describe "with an array of tuples" do
        let(:arg){ tuples_by_name }
        it{ should be_a(Relation) }
        it{ should == rel }
      end
      
      describe "with an iterator" do
        let(:arg){ Lispy.restrict(tuples_by_name, lambda{ true }) }
        it{ should be_a(Relation) }
        it{ should == rel }
      end
      
      describe "with unrecognized arg" do
        let(:arg){ nil }
        specify{ lambda{ subject }.should raise_error(ArgumentError) } 
      end
      
      it "should be semi-aliased as []" do
        Alf::Relation[*tuples_by_name].should == rel
      end

    end # coerce
      
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
alf-0.12.2 spec/unit/alf-core/relation/test_coerce.rb
alf-0.12.1 spec/unit/alf-core/relation/test_coerce.rb
alf-0.12.0 spec/unit/alf-core/relation/test_coerce.rb
alf-0.11.1 spec/unit/alf-core/relation/test_coerce.rb
alf-0.11.0 spec/unit/alf-core/relation/test_coerce.rb
alf-0.10.1 spec/unit/relation/test_coerce.rb
alf-0.10.0 spec/unit/relation/test_coerce.rb
alf-0.9.3 spec/unit/relation/test_coerce.rb
alf-0.9.2 spec/unit/relation/test_coerce.rb
alf-0.9.1 spec/unit/relation/test_coerce.rb