Sha256: 9bca09d0725affe376f1342c9fdfd3f46e4b199a4c518e8e65839b905c5733bb

Contents?: true

Size: 1.15 KB

Versions: 4

Compression:

Stored size: 1.15 KB

Contents

require 'spec_helper'

module Roqua
  module CoreApi
    module Models
      describe ActiveVirtus do
        class Foo < ActiveVirtus
          attribute :datetime, DateTime
          attribute :date, Date
        end

        subject { Foo.new }

        describe 'Date' do
          it 'can be set by date(i1) params' do
            subject.attributes = { 'date(1i)' => '1999', 'date(2i)' => '12', 'date(3i)' => '8'}
            expect(subject.date).to eq Date.new(1999, 12, 8)
          end
          it 'sets an error if the date is invalid' do
            subject.attributes = { 'date(1i)' => '1999', 'date(2i)' => '12', 'date(3i)' => '32'}
            expect(subject.errors[:date][0]).to match 'invalid_date'
          end
        end

        describe 'DateTime' do
          it 'can be set by datetime(i1) params' do
            subject.attributes = { 'datetime(1i)' => '1999', 'datetime(2i)' => '12', 'datetime(3i)' => '8',
                                   'datetime(4i)' => '22', 'datetime(5i)' => '23', 'datetime(6i)' => '24'}
            expect(subject.datetime).to eq DateTime.new(1999, 12, 8, 22, 23, 24)
          end
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
roqua-core-api-0.0.29 spec/lib/roqua/core_api/models/active_virtus_spec.rb
roqua-core-api-0.0.28 spec/lib/roqua/core_api/models/active_virtus_spec.rb
roqua-core-api-0.0.27 spec/lib/roqua/core_api/models/active_virtus_spec.rb
roqua-core-api-0.0.26 spec/lib/roqua/core_api/models/active_virtus_spec.rb