Sha256: 9e705fbaafedbed717e966a397d065aeab9d60ac73079b5747af37c0f1045fff

Contents?: true

Size: 817 Bytes

Versions: 6

Compression:

Stored size: 817 Bytes

Contents

require 'spec_helper'

describe Virtus::ClassMethods, '#attribute' do
  subject { object.attribute(name, type) }

  let(:object)     { Class.new { include Virtus } }
  let(:descendant) { Class.new(object)            }
  let(:name)       { :name                        }
  let(:type)       { Virtus::Attribute::String    }

  def assert_attribute_added(klass, name, attribute_class)
    attributes = klass.attributes
    attributes[name].should be_nil
    subject
    attribute = attributes[name]
    attribute.name.should be(name)
    attribute.class.should be(attribute_class)
  end

  it { should be(object) }

  it 'adds the attribute to the class' do
    assert_attribute_added(object, name, type)
  end

  it 'adds the attribute to the descendant' do
    assert_attribute_added(descendant, name, type)
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
virtus-0.4.2 spec/unit/virtus/class_methods/attribute_spec.rb
virtus-0.4.1 spec/unit/virtus/class_methods/attribute_spec.rb
virtus-0.4.0 spec/unit/virtus/class_methods/attribute_spec.rb
virtus-0.3.0 spec/unit/virtus/class_methods/attribute_spec.rb
virtus-0.2.0 spec/unit/virtus/class_methods/attribute_spec.rb
virtus-0.1.0 spec/unit/virtus/class_methods/attribute_spec.rb