Sha256: 53f0b570f9d85971d3c59df089477bceed1a9878c1608e79ec2d2320644b6fd2

Contents?: true

Size: 1.32 KB

Versions: 8

Compression:

Stored size: 1.32 KB

Contents

require 'spec_helper'

describe Virtus::AttributeSet, '#<<' do
  subject { object << attribute }

  let(:attributes) { []                                      }
  let(:parent)     { described_class.new                     }
  let(:object)     { described_class.new(parent, attributes) }
  let(:name)       { :name                                   }

  context 'with a new attribute' do
    let(:attribute) { mock('Attribute', :name => name) }

    it { should equal(object) }

    it 'adds an attribute' do
      expect { subject }.to change { object.to_a }.
        from(attributes).
        to([ attribute ])
    end

    it 'indexes the new attribute under its #name property' do
      expect { subject }.to change { object[name] }.
        from(nil).
        to(attribute)
    end

    it 'indexes the new attribute under the string version of its #name property' do
      expect { subject }.to change { object[name.to_s] }.
        from(nil).
        to(attribute)
    end
  end

  context 'with a duplicate attribute' do
    let(:attributes) { [ mock('Attribute', :name => name) ] }
    let(:attribute)  { mock('Duplicate', :name => name)     }

    it { should equal(object) }

    it 'replaces the original attribute' do
      expect { subject }.to change { object.to_a }.
        from(attributes).
        to([ attribute ])
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
virtus-0.5.1 spec/unit/virtus/attribute_set/append_spec.rb
virtus-0.5.0 spec/unit/virtus/attribute_set/append_spec.rb
virtus-0.4.2 spec/unit/virtus/attribute_set/append_spec.rb
virtus-0.4.1 spec/unit/virtus/attribute_set/append_spec.rb
virtus-0.4.0 spec/unit/virtus/attribute_set/append_spec.rb
virtus-0.3.0 spec/unit/virtus/attribute_set/append_spec.rb
virtus-0.2.0 spec/unit/virtus/attribute_set/append_spec.rb
virtus-0.1.0 spec/unit/virtus/attribute_set/append_spec.rb