Sha256: f7fa63bfb10a023e3910e7fa27711dcbbf5a79405ab983b6fbc73d0fcfe427e2
Contents?: true
Size: 1.87 KB
Versions: 12
Compression:
Stored size: 1.87 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) expect(subject.errors).to be_empty 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 'Niet een bestaande datum' end it 'can create new with date(i1) params' do foo = Foo.new('date(1i)' => '1999', 'date(2i)' => '12', 'date(3i)' => '8') expect(foo.date).to eq Date.new(1999, 12, 8) expect(foo.errors).to be_empty end it 'allows for a date not to be set' do foo = Foo.new expect(foo.date).to be_nil expect(foo.errors).to be_empty end it 'sets date to nil if date params are empty strings' do foo = Foo.new('date(1i)' => '', 'date(2i)' => '', 'date(3i)' => '') expect(foo.date).to be_nil expect(foo.errors).to be_empty 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).utc end end end end end end
Version data entries
12 entries across 12 versions & 1 rubygems