Sha256: d9189588bc2729224ce5ee1f3d05e7daff16ae4e88dad733392e32ca471a41dc

Contents?: true

Size: 1.94 KB

Versions: 11

Compression:

Stored size: 1.94 KB

Contents

require 'spec_helper'

shared_examples_for 'a correct date time' do
  it { should be_kind_of(DateTime) }

  its(:year)  { should eql(year)  }
  its(:month) { should eql(month) }
  its(:day)   { should eql(day)   }
  its(:hour)  { should eql(hour)  }
  its(:min)   { should eql(min)   }
  its(:sec)   { should eql(sec)   }
end

describe Virtus::Attribute::DateTime, '#coerce' do
  subject { attribute.coerce(value) }

  let(:attribute) { described_class.new(:bday) }
  let(:year)      { 2011                       }
  let(:month)     { 4                          }
  let(:day)       { 7                          }
  let(:hour)      { 1                          }
  let(:min)       { 26                         }
  let(:sec)       { 49                         }

  context 'with a date' do
    let(:hour)  { 0                          }
    let(:min)   { 0                          }
    let(:sec)   { 0                          }
    let(:value) { Date.new(year, month, day) }

    it_should_behave_like 'a correct date time'
  end

  context 'with a time' do
    let(:value) { Time.local(year, month, day, hour, min, sec) }

    it_should_behave_like 'a correct date time'
  end

  context 'with a hash' do
    let(:value) { { :year => year, :month => month, :day => day, :hour => hour, :min => min, :sec => sec } }

    it_should_behave_like 'a correct date time'
  end

  context 'with a string' do
    context 'without hour, min and sec' do
      let(:hour)  { 0                         }
      let(:min)   { 0                         }
      let(:sec)   { 0                         }
      let(:value) { "April #{day}th, #{year}" }

      it_should_behave_like 'a correct date time'
    end

    context 'with hour, min and sec' do
      let(:value) { "April #{day}th, #{year}, #{hour}:#{min}:#{sec}" }

      it_should_behave_like 'a correct date time'
    end
  end

  context 'with a on-date value' do
    let(:value) { 'non-date' }

    it { should equal(value) }
  end
end

Version data entries

11 entries across 11 versions & 2 rubygems

Version Path
virtus-0.5.3 spec/unit/virtus/attribute/date_time/coerce_spec.rb
fragrant-0.0.5 vendor/bundle/ruby/1.9.1/gems/virtus-0.5.2/spec/unit/virtus/attribute/date_time/coerce_spec.rb
virtus-0.5.2 spec/unit/virtus/attribute/date_time/coerce_spec.rb
virtus-0.5.1 spec/unit/virtus/attribute/date_time/coerce_spec.rb
virtus-0.5.0 spec/unit/virtus/attribute/date_time/coerce_spec.rb
virtus-0.4.2 spec/unit/virtus/attribute/date_time/coerce_spec.rb
virtus-0.4.1 spec/unit/virtus/attribute/date_time/coerce_spec.rb
virtus-0.4.0 spec/unit/virtus/attribute/date_time/coerce_spec.rb
virtus-0.3.0 spec/unit/virtus/attribute/date_time/coerce_spec.rb
virtus-0.2.0 spec/unit/virtus/attribute/date_time/coerce_spec.rb
virtus-0.1.0 spec/unit/virtus/attribute/date_time/coerce_spec.rb