Sha256: 2db8d4e0071453226b2373036924a1fbc0734052d2c75e68df8559abfd0b86f8

Contents?: true

Size: 1.11 KB

Versions: 2

Compression:

Stored size: 1.11 KB

Contents

# encoding: utf-8

require 'spec_helper'

describe Optimizer::Algebra::Rename::RenameOperandAndEmptyAliases, '#optimizable?' do
  subject { object.optimizable? }

  let(:header)   { Relation::Header.coerce([[:id, Integer], [:name, String]])  }
  let(:base)     { Relation.new(header, LazyEnumerable.new([[1, 'Dan Kubb']])) }
  let(:relation) { operand.rename(aliases)                                     }
  let(:object)   { described_class.new(relation)                               }

  before do
    expect(object.operation).to be_kind_of(Algebra::Rename)
  end

  context 'when the operand is a rename and there are aliases' do
    let(:aliases) { { id: :other_id }              }
    let(:operand) { base.rename(name: :other_name) }

    it { should be(false) }
  end

  context 'when the operand is a rename and there no aliases' do
    let(:aliases) { { other_id: :id }          }
    let(:operand) { base.rename(id: :other_id) }

    it { should be(true) }
  end

  context 'when the operand is not a rename' do
    let(:aliases) { { id: :other_id } }
    let(:operand) { base              }

    it { should be(false) }
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
axiom-optimizer-0.2.0 spec/unit/axiom/optimizer/algebra/rename/rename_operand_and_empty_aliases/optimizable_predicate_spec.rb
axiom-optimizer-0.1.1 spec/unit/axiom/optimizer/algebra/rename/rename_operand_and_empty_aliases/optimizable_predicate_spec.rb