Sha256: e341a1b74ed4b11e473e2962c8d8b913bc9dfbf546df03bc938730c6a9fb364d

Contents?: true

Size: 824 Bytes

Versions: 11

Compression:

Stored size: 824 Bytes

Contents

require 'spec_helper'

describe 'custom attributes' do

  before do
    module Examples
      class NoisyString < Virtus::Attribute
        lazy true

        def coerce(input)
          input.to_s.upcase
        end
      end

      class RegularExpression < Virtus::Attribute
        primitive Regexp
      end

      class User
        include Virtus

        attribute :name, String
        attribute :scream, NoisyString
        attribute :expression, RegularExpression
      end
    end
  end

  subject { Examples::User.new }

  specify 'allows you to define custom attributes' do
    regexp = /awesome/
    subject.expression = regexp
    subject.expression.should == regexp
  end

  specify 'allows you to define coercion methods' do
    subject.scream = 'welcome'
    subject.scream.should == 'WELCOME'
  end

end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
virtus-1.0.2 spec/integration/custom_attributes_spec.rb
virtus-1.0.1 spec/integration/custom_attributes_spec.rb
virtus-1.0.0 spec/integration/custom_attributes_spec.rb
virtus-1.0.0.rc2 spec/integration/custom_attributes_spec.rb
virtus-1.0.0.rc1 spec/integration/custom_attributes_spec.rb
virtus-1.0.0.beta8 spec/integration/custom_attributes_spec.rb
virtus-1.0.0.beta7 spec/integration/custom_attributes_spec.rb
virtus-1.0.0.beta6 spec/integration/custom_attributes_spec.rb
virtus-1.0.0.beta5 spec/integration/custom_attributes_spec.rb
virtus-1.0.0.beta4 spec/integration/custom_attributes_spec.rb
virtus-1.0.0.beta3 spec/integration/custom_attributes_spec.rb