Sha256: 7a6e3fb8a1abaae009dd64513d7a654783ef151e602f190d0be099f802e993aa

Contents?: true

Size: 1.32 KB

Versions: 2

Compression:

Stored size: 1.32 KB

Contents

require 'pr/fields/invalid_value'
require 'pr/fields/date_field'

describe 'a date field' do
  let(:klass)   { PR::Fields::DateField }
  let(:value)   { double "value" }
  let(:options) { Hash.new }
  let(:field)   { klass.new value, options }

  describe "default value" do
    specify { expect(klass.new.raw).to eq '' }
    specify { expect { klass.new.convert }.to raise_error PR::Fields::InvalidValue }
    specify { expect(klass.new.options).to eq({}) }
  end

  describe '#options' do
    it 'has retrievable options' do
      expect(field.options).to eq options
    end
  end

  describe "raw" do
    it "returns the value the field was initialized with" do
      expect(field.raw).to eq(value)
    end
  end

  describe "#populate" do
    let(:value) { Date.civil 2011, 6, 1 }

    subject { field.populate value }
    specify { subject; expect(field.raw).to eq('01/06/2011') }
  end

  describe "convert" do

    it "should attempt to parse the value as a uk formatted date" do
      expect(Date).to receive(:strptime).with(value,'%d/%m/%Y')
      field.convert
    end

    context "where value is not a valid date" do
      it "should raise an InvalidFieldValueError" do
        expect(Date).to receive(:strptime).and_raise(ArgumentError)
        expect { field.convert }.to raise_error PR::Fields::InvalidValue
      end
    end
  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
pr-1.0.0 spec/unit/pr/fields/date_field_spec.rb
pr-0.0.7 spec/unit/pr/fields/date_field_spec.rb