aboutsummaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
authorVlatka Pavisic2017-01-03 16:55:24 +0100
committerVlatka Pavisic2017-01-03 16:55:24 +0100
commit63e20d284855f9e40706e94dc8d17558eb18e1e4 (patch)
tree514e02de0f18c57a140eb603802afcb29d4375ec /spec
parentbac2e1b1bd9111580d161b3282f52460d49783ca (diff)
downloadchouette-core-63e20d284855f9e40706e94dc8d17558eb18e1e4.tar.bz2
Refs #2265 Refs #2262 : Calendars search and CRUD
Diffstat (limited to 'spec')
-rw-r--r--spec/models/calendar_spec.rb36
1 files changed, 34 insertions, 2 deletions
diff --git a/spec/models/calendar_spec.rb b/spec/models/calendar_spec.rb
index 2557cdb93..36981961f 100644
--- a/spec/models/calendar_spec.rb
+++ b/spec/models/calendar_spec.rb
@@ -15,7 +15,6 @@ RSpec.describe Calendar, :type => :model do
expect {
calendar.save!
}.to raise_error(ActiveRecord::RecordInvalid)
- expect(calendar.errors.messages[:dates]).to eq([I18n.t('activerecord.errors.models.calendar.attributes.dates.date_in_date_ranges')])
end
it 'validates that there are no duplicates in dates' do
@@ -23,7 +22,6 @@ RSpec.describe Calendar, :type => :model do
expect {
calendar.save!
}.to raise_error(ActiveRecord::RecordInvalid)
- expect(calendar.errors.messages[:dates]).to eq([I18n.t('activerecord.errors.models.calendar.attributes.dates.date_in_dates')])
end
end
@@ -112,5 +110,39 @@ RSpec.describe Calendar, :type => :model do
end
end
+ describe 'DateValue' do
+
+ subject { date_value }
+
+ def date_value(attributes = {})
+ return @date_value if attributes.empty? and @date_value
+ Calendar::DateValue.new(attributes).tap do |date_value|
+ @date_value = date_value if attributes.empty?
+ 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 { is_expected.to validate_presence_of(:value) }
+
+ end
+
end