Sha256: c20c7728b8e297b2ee5cb534e8e7c9d7562703a7fb3783d307bbcdfb3f823b17

Contents?: true

Size: 1.41 KB

Versions: 2

Compression:

Stored size: 1.41 KB

Contents

require 'spec_helper'

describe Virtus::Attribute::Date do
  it_should_behave_like 'Attribute' do
    let(:attribute_name)        { :created_on }
    let(:attribute_value)       { Date.today }
    let(:attribute_value_other) { (Date.today+1).to_s }
  end

  describe '#typecast' do
    let(:attribute) { Virtus::Attribute::Date.new(:bday) }

    let(:year)  { 2011 }
    let(:month) { 4 }
    let(:day)   { 7 }

    subject { attribute.typecast(value) }

    shared_examples_for "a correct date" do
      it          { should be_kind_of(Date) }
      its(:year)  { should eql(year)  }
      its(:month) { should eql(month) }
      its(:day)   { should eql(day)   }
    end

    context 'with a time' do
      it_should_behave_like "a correct date" do
        let(:value) { Time.local(year, month, day) }
      end
    end

    context 'with a date time' do
      it_should_behave_like "a correct date" do
        let(:value) { DateTime.new(year, month, day) }
      end
    end

    context 'with a hash' do
      it_should_behave_like "a correct date" do
        let(:value) do
          { :year => year, :month => month, :day => day }
        end
      end
    end

    context 'with a string' do
      it_should_behave_like "a correct date" do
        let(:value) { "April #{day}th, #{year}" }
      end
    end

    context 'with a non-date value' do
      let(:value) { 'non-date' }
      it { should equal(value) }
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
virtus-0.0.5 spec/unit/virtus/attribute/date_spec.rb
virtus-0.0.4 spec/unit/virtus/attribute/date_spec.rb