blob: 70dca3cc6e3e51c257471d4b7098b95a3c9da915 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
RSpec.describe Calendar::DateValue, type: :model do
describe 'DateValue' do
subject { date_value }
def date_value(attributes = {})
@__date_values__ ||= Hash.new
@__date_values__.fetch(attributes) do
@__date_values__[attributes] = Calendar::DateValue.new(attributes)
end
end
it 'should support mark_for_destruction (required by cocoon)' do
date_value.mark_for_destruction
expect(date_value).to be_marked_for_destruction
end
it 'should support _destroy attribute (required by coocon)' do
date_value._destroy = true
expect(date_value).to be_marked_for_destruction
end
it 'should support new_record? (required by cocoon)' do
expect(Calendar::DateValue.new).to be_new_record
expect(date_value(id: 42)).not_to be_new_record
end
it 'should cast value as date attribute' do
expect(date_value(value: '2017-01-03').value).to eq(Date.new(2017,01,03))
end
it 'validates presence' do
is_expected.to validate_presence_of(:value)
end
end
end
|