Sha256: 5b31d817c56d1b507084104ac200ef37a100cde625f64de5165d731744a53810

Contents?: true

Size: 1010 Bytes

Versions: 13

Compression:

Stored size: 1010 Bytes

Contents

require 'spec_helper'

describe Virtus::Attribute::Date, '#value_coerced?' do
  subject { attribute.value_coerced?(value) }

  let(:attribute) { described_class.new(:bday) }
  let(:year)      { 2011                       }
  let(:month)     { 4                          }
  let(:day)       { 7                          }

  context 'with a Date' do
    let(:value) { Date.new(year, month, day) }

    it { should be(true) }
  end

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

    it { should be(true) }
  end

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

    it { should be(false) }
  end

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

    it { should be(false) }
  end

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

    it { should be(false) }
  end

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

    it { should be(false) }
  end
end

Version data entries

13 entries across 13 versions & 2 rubygems

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