Sha256: b000bc2e509ac115a572c21ab3ca9866237e8b57b5436989186db2a41ff192a4

Contents?: true

Size: 1.15 KB

Versions: 17

Compression:

Stored size: 1.15 KB

Contents

require 'spec_helper'

describe Acfs::Resource::Attributes::DateTime do
  let(:type) { Acfs::Resource::Attributes::DateTime.new }

  describe '#cast' do
    subject { -> { type.cast value } }

    context 'with nil' do
      let(:value) { nil }
      it { expect(subject.call).to eq nil }
    end

    context 'with empty string' do
      let(:value) { '' }
      it { expect(subject.call).to eq nil }
    end

    context 'with blank string' do
      let(:value) { "  \t" }
      it { expect(subject.call).to eq nil }
    end

    context 'with DateTime' do
      let(:value) { DateTime.now }
      it { expect(subject.call).to eq value }
    end

    context 'with Time' do
      let(:value) { Time.now }
      it { expect(subject.call).to eq value.to_datetime }
    end

    context 'with Date' do
      let(:value) { Date.today }
      it { expect(subject.call).to eq value.to_datetime }
    end

    context 'with ISO8601' do
      let(:value) { DateTime.now.iso8601 }
      it { expect(subject.call.iso8601).to eq value }
    end

    context 'with invalid string' do
      let(:value) { 'qwe123' }
      it { is_expected.to raise_error ArgumentError }
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
acfs-1.3.2 spec/acfs/resource/attributes/date_time_spec.rb
acfs-1.3.1 spec/acfs/resource/attributes/date_time_spec.rb
acfs-1.3.0 spec/acfs/resource/attributes/date_time_spec.rb
acfs-1.2.1 spec/acfs/resource/attributes/date_time_spec.rb
acfs-0.50.0 spec/acfs/resource/attributes/date_time_spec.rb
acfs-1.2.0 spec/acfs/resource/attributes/date_time_spec.rb
acfs-0.49.1 spec/acfs/resource/attributes/date_time_spec.rb
acfs-1.1.1 spec/acfs/resource/attributes/date_time_spec.rb
acfs-0.49.0 spec/acfs/resource/attributes/date_time_spec.rb
acfs-1.1.0 spec/acfs/resource/attributes/date_time_spec.rb
acfs-0.48.2 spec/acfs/resource/attributes/date_time_spec.rb
acfs-1.0.1 spec/acfs/resource/attributes/date_time_spec.rb
acfs-0.48.1 spec/acfs/resource/attributes/date_time_spec.rb
acfs-1.0.0 spec/acfs/resource/attributes/date_time_spec.rb
acfs-0.48.0 spec/acfs/resource/attributes/date_time_spec.rb
acfs-0.47.0 spec/acfs/resource/attributes/date_time_spec.rb
acfs-0.46.0 spec/acfs/resource/attributes/date_time_spec.rb