require 'spec_helper'

describe Relation::Header, '.new' do
  subject { object.new(argument) }

  let(:object) { described_class }

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

    it { should be_kind_of(object) }

    it { should be_empty }
  end

  context 'with an argument that responds to #to_ary and do not contain duplicates' do
    let(:argument) { [ [ :id ], [ :name ] ] }

    it { should be_kind_of(object) }

    it { should == argument }
  end

  context 'with an argument that responds to #to_ary and contain duplicates' do
    let(:argument) { [ [ :id ], [ :id ], [ :name ], [ :name ] ] }

    specify { expect { subject }.to raise_error(DuplicateAttributeError, 'duplicate attributes: id, name') }
  end

  context 'with an argument that does not respond to #to_ary' do
    let(:argument) { { :id => Integer } }

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

require 'spec_helper'

describe Relation::Header, '.new' do
  subject { object.new(argument) }

  let(:object) { described_class }

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

    it { should be_kind_of(object) }

    it { should be_empty }
  end

  context 'with an argument that responds to #to_ary and do not contain duplicates' do
    let(:argument) { [ [ :id ], [ :name ] ] }

    it { should be_kind_of(object) }

    it { should == argument }
  end

  context 'with an argument that responds to #to_ary and contain duplicates' do
    let(:argument) { [ [ :id ], [ :id ], [ :name ], [ :name ], [ :age ] ] }

    specify { expect { subject }.to raise_error(DuplicateAttributeError, 'duplicate attributes: id, name') }
  end

  context 'with an argument that does not respond to #to_ary' do
    let(:argument) { { :id => Integer } }

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

Cover a missing spec mutation
Cover a missing spec mutation

* The code needs to be tested with a mix of unique and duplicate attributes
  otherwise some branches of the code are not tested.
