Sha256: 8ee289bdc533ea1528405dc03935f907ff2e3af398168c0c548d607a671767f8

Contents?: true

Size: 1.84 KB

Versions: 1

Compression:

Stored size: 1.84 KB

Contents

require 'spec_helper'

describe 'Veritas::Algebra::Rename::Aliases.coerce' do
  subject { object.coerce(attributes, aliases) }

  let(:attribute)  { Attribute::Integer.new(:id)         }
  let(:attributes) { Relation::Header.new([ attribute ]) }
  let(:object)     { Algebra::Rename::Aliases            }

  context 'the aliases are an Alias object' do
    let(:old_attr) { attribute                        }
    let(:new_attr) { attribute.rename(:other_id)      }
    let(:aliases)  { object.new(old_attr => new_attr) }

    it { should equal(aliases) }
  end

  context 'the old and new attributes are Symbols' do
    let(:old_attr) { :id                      }
    let(:new_attr) { :other_id                }
    let(:aliases)  { { old_attr => new_attr } }

    it { should be_kind_of(object) }

    it { should == { attribute => attribute.rename(:other_id) } }
  end

  context 'the old attribute is a Symbol, and the new attribute is an Attribute' do
    let(:old_attr) { :id                         }
    let(:new_attr) { attribute.rename(:other_id) }
    let(:aliases)  { { old_attr => new_attr }    }

    it { should be_kind_of(object) }

    it { should == { attribute => attribute.rename(:other_id) } }
  end

  context 'the old attribute is an Attribute, and the new attribute is a Symbol' do
    let(:old_attr) { attribute                }
    let(:new_attr) { :other_id                }
    let(:aliases)  { { old_attr => new_attr } }

    it { should be_kind_of(object) }

    it { should == { attribute => attribute.rename(:other_id) } }
  end

  context 'the old and new attributes are Attributes' do
    let(:old_attr) { attribute                   }
    let(:new_attr) { attribute.rename(:other_id) }
    let(:aliases)  { { old_attr => new_attr }    }

    it { should be_kind_of(object) }

    it { should == { attribute => attribute.rename(:other_id) } }
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
veritas-0.0.2 spec/unit/veritas/algebra/rename/aliases/class_methods/coerce_spec.rb