Sha256: 078fa0f47f1f72841b4203ce3b335659b8ebd6c8394a9311e4e8a8e3337bd55c

Contents?: true

Size: 628 Bytes

Versions: 3

Compression:

Stored size: 628 Bytes

Contents

require 'spec_helper'

describe Virtus::Attribute, '#typecast' do
  let(:attribute_class) do
    Class.new(Virtus::Attribute::Integer) do
      def typecast(value)
        super + 1
      end
    end
  end

  let(:model) do
    model = Class.new do
      include Virtus
    end
    model.attribute(:count, attribute_class)
    model
  end

  let(:object) do
    model.new
  end

  context 'when overridden' do
    let(:input_value)  { 1 }
    let(:output_value) { 2   }

    before do
      object.count = input_value
    end

    it "peforms custom typecasting" do
      object.count.should eql(output_value)
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
virtus-0.0.5 spec/integration/virtus/attributes/attribute/typecast_spec.rb
virtus-0.0.4 spec/integration/virtus/attributes/attribute/typecast_spec.rb
virtus-0.0.3 spec/integration/virtus/attributes/attribute/typecast_spec.rb