Sha256: 90b7fba8fbdccc52ee650770fbb0f7e5f5d0051868ab4b355e4cc0ce4632205b

Contents?: true

Size: 958 Bytes

Versions: 5

Compression:

Stored size: 958 Bytes

Contents

require 'spec_helper'
module Alf
  module Engine
    describe Defaults do

      it 'should work on an empty operand' do
        Defaults.new([], TupleComputation[:id => 1]).to_a.should eq([])
      end

      it 'should replace nil by the default value' do
        rel = [
          {:name => "Jones"},
          {:name => nil}
        ]
        exp = [
          {:name => "Jones"},
          {:name => "Smith"}
        ]
        Defaults.new(rel, TupleComputation[:name => "Smith"]).to_a.should eq(exp)
      end

      it 'should add missing attributes and allow computations' do
        rel = [
          {:name => "Jones"},
          {:name => "Smith"}
        ]
        exp = [
          {:name => "Jones", :up => "JONES"},
          {:name => "Smith", :up => "SMITH"}
        ]
        defs = TupleComputation[:up => lambda{ name.upcase }]
        Defaults.new(rel, defs).to_a.should eq(exp)
      end

    end
  end # module Engine
end # module Alf

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
alf-0.12.2 spec/unit/alf-engine/test_defaults.rb
alf-0.12.1 spec/unit/alf-engine/test_defaults.rb
alf-0.12.0 spec/unit/alf-engine/test_defaults.rb
alf-0.11.1 spec/unit/alf-engine/test_defaults.rb
alf-0.11.0 spec/unit/alf-engine/test_defaults.rb