Sha256: 2f90dcbdac08f847b2bdf67fbe63bd1846bad78f9d655b6bd1b9c1480ca96f7f

Contents?: true

Size: 986 Bytes

Versions: 11

Compression:

Stored size: 986 Bytes

Contents

require 'spec_helper'

describe 'custom attributes' do

  module Virtus
    class Coercion
      class String < Virtus::Coercion::Object
        def self.to_upcase(value)
          value.upcase
        end
      end
    end
  end

  before do
    module Examples
      class UpperCase < Virtus::Attribute::Object
        primitive String
        coercion_method :to_upcase
      end

      class RegularExpression < Virtus::Attribute::Object
        primitive Regexp
      end

      class User
        include Virtus

        attribute :name, String
        attribute :scream, UpperCase
        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 & 2 rubygems

Version Path
virtus-0.5.5 spec/integration/custom_attributes_spec.rb
virtus-0.5.4 spec/integration/custom_attributes_spec.rb
virtus-0.5.3 spec/integration/custom_attributes_spec.rb
fragrant-0.0.5 vendor/bundle/ruby/1.9.1/gems/virtus-0.5.2/spec/integration/custom_attributes_spec.rb
virtus-0.5.2 spec/integration/custom_attributes_spec.rb
virtus-0.5.1 spec/integration/custom_attributes_spec.rb
virtus-0.5.0 spec/integration/custom_attributes_spec.rb
virtus-0.4.2 spec/integration/custom_attributes_spec.rb
virtus-0.4.1 spec/integration/custom_attributes_spec.rb
virtus-0.4.0 spec/integration/custom_attributes_spec.rb
virtus-0.3.0 spec/integration/custom_attributes_spec.rb