Sha256: afaf70babeb3e4adce15a26c9f415a9d5196f3fc142aff6baaa3fe0e1119b7ff

Contents?: true

Size: 1.66 KB

Versions: 1

Compression:

Stored size: 1.66 KB

Contents

# encoding: utf-8

require 'spec_helper'

describe Relation::Header, '.new' do
  let(:object) { described_class              }
  let(:id)     { Attribute::Integer.new(:id)  }
  let(:name)   { Attribute::String.new(:name) }
  let(:age)    { Attribute::Integer.new(:age) }

  context 'with no arguments' do
    subject { object.new }

    it { should be_instance_of(object) }

    it { should be_empty }
  end

  context 'with attributes' do
    subject { object.new(attributes) }

    let(:attributes) { [ id, name ] }

    it { should be_instance_of(object) }

    it { should == attributes }

    it 'does not freeze the attributes' do
      attributes.should_not be_frozen
      expect { subject }.to_not change(attributes, :frozen?)
    end
  end

  context 'with attributes and options' do
    subject { object.new(attributes, options) }

    let(:attributes) { [ id, name ] }
    let(:options)    { {}           }

    it { should be_instance_of(object) }

    it { should == attributes }

    it 'does not freeze the attributes' do
      attributes.should_not be_frozen
      expect { subject }.to_not change(attributes, :frozen?)
    end

    it 'does not freeze the options' do
      options.should_not be_frozen
      expect { subject }.to_not change(options, :frozen?)
    end
  end

  context 'with attributes that contain duplicates' do
    subject { object.new([ id, id, name, name, name, age ]) }

    specify { expect { subject }.to raise_error(DuplicateNameError, 'duplicate names: [:id, :name]') }
  end

  context 'with an argument that does not respond to #to_ary' do
    subject { object.new(Object.new) }

    specify { expect { subject }.to raise_error(NoMethodError) }
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
axiom-0.1.0 spec/unit/axiom/relation/header/class_methods/new_spec.rb