aboutsummaryrefslogtreecommitdiffstats
path: root/spec/models/calendar_spec.rb
diff options
context:
space:
mode:
authorVlatka Pavisic2016-12-30 16:44:30 +0100
committerVlatka Pavisic2016-12-30 16:44:30 +0100
commitad71715b42f5278fb46cedec874cb7e9a4fe3cf3 (patch)
tree67cd1473f7f3c6d7e08401050bceddb16d3daeae /spec/models/calendar_spec.rb
parentadfb4aebfab39b5a7a4b9a70ac62f639567aead6 (diff)
downloadchouette-core-ad71715b42f5278fb46cedec874cb7e9a4fe3cf3.tar.bz2
Refs #2262 Refs #2263 Refs #2264 Refs #2265 : Calendars 80% done
Diffstat (limited to 'spec/models/calendar_spec.rb')
-rw-r--r--spec/models/calendar_spec.rb52
1 files changed, 26 insertions, 26 deletions
diff --git a/spec/models/calendar_spec.rb b/spec/models/calendar_spec.rb
index 1143c6615..6cc256582 100644
--- a/spec/models/calendar_spec.rb
+++ b/spec/models/calendar_spec.rb
@@ -19,70 +19,70 @@ RSpec.describe Calendar, :type => :model do
end
end
- describe 'DateRange' do
+ describe 'Period' do
- subject { date_range }
+ subject { period }
- def date_range(attributes = {})
- return @date_range if attributes.empty? and @date_range
- Calendar::DateRange.new(attributes).tap do |date_range|
- @date_range = date_range if attributes.empty?
+ def period(attributes = {})
+ return @period if attributes.empty? and @period
+ Calendar::Period.new(attributes).tap do |period|
+ @period = period if attributes.empty?
end
end
it 'should support mark_for_destruction (required by cocoon)' do
- date_range.mark_for_destruction
- expect(date_range).to be_marked_for_destruction
+ period.mark_for_destruction
+ expect(period).to be_marked_for_destruction
end
it 'should support _destroy attribute (required by coocon)' do
- date_range._destroy = true
- expect(date_range).to be_marked_for_destruction
+ period._destroy = true
+ expect(period).to be_marked_for_destruction
end
it 'should support new_record? (required by cocoon)' do
- expect(Calendar::DateRange.new).to be_new_record
- expect(date_range(id: 42)).not_to be_new_record
+ expect(Calendar::Period.new).to be_new_record
+ expect(period(id: 42)).not_to be_new_record
end
it 'should cast begin as date attribute' do
- expect(date_range(begin: '2016-11-22').begin).to eq(Date.new(2016,11,22))
+ expect(period(begin: '2016-11-22').begin).to eq(Date.new(2016,11,22))
end
it 'should cast end as date attribute' do
- expect(date_range(end: '2016-11-22').end).to eq(Date.new(2016,11,22))
+ expect(period(end: '2016-11-22').end).to eq(Date.new(2016,11,22))
end
it { is_expected.to validate_presence_of(:begin) }
it { is_expected.to validate_presence_of(:end) }
it 'should validate that end is greather than or equlals to begin' do
- expect(date_range(begin: '2016-11-21', end: '2016-11-22')).to be_valid
- expect(date_range(begin: '2016-11-21', end: '2016-11-21')).to be_valid
- expect(date_range(begin: '2016-11-22', end: '2016-11-21')).to_not be_valid
+ expect(period(begin: '2016-11-21', end: '2016-11-22')).to be_valid
+ expect(period(begin: '2016-11-21', end: '2016-11-21')).to be_valid
+ expect(period(begin: '2016-11-22', end: '2016-11-21')).to_not be_valid
end
describe 'intersect?' do
it 'should detect date in common with other date_ranges' do
- november = date_range(begin: '2016-11-01', end: '2016-11-30')
- mid_november_mid_december = date_range(begin: '2016-11-15', end: '2016-12-15')
+ november = period(begin: '2016-11-01', end: '2016-11-30')
+ mid_november_mid_december = period(begin: '2016-11-15', end: '2016-12-15')
expect(november.intersect?(mid_november_mid_december)).to be(true)
end
it 'should not intersect when no date is in common' do
- november = date_range(begin: '2016-11-01', end: '2016-11-30')
- december = date_range(begin: '2016-12-01', end: '2016-12-31')
+ november = period(begin: '2016-11-01', end: '2016-11-30')
+ december = period(begin: '2016-12-01', end: '2016-12-31')
expect(november.intersect?(december)).to be(false)
- january = date_range(begin: '2017-01-01', end: '2017-01-31')
+ january = period(begin: '2017-01-01', end: '2017-01-31')
expect(november.intersect?(december, january)).to be(false)
end
it 'should not intersect itself' do
- date_range = date_range(id: 42, begin: '2016-11-01', end: '2016-11-30')
- expect(date_range.intersect?(date_range)).to be(false)
+ period = period(id: 42, begin: '2016-11-01', end: '2016-11-30')
+ expect(period.intersect?(period)).to be(false)
end
end
@@ -97,11 +97,11 @@ RSpec.describe Calendar, :type => :model do
Range.new(Date.today, Date.tomorrow)
]
expected_ranges.each_with_index do |range, index|
- calendar.date_ranges << Calendar::DateRange.from_range(index, range)
+ calendar.date_ranges << Calendar::Period.from_range(index, range)
end
calendar.valid?
- expect(calendar.date_ranges.map { |date_range| date_range.begin..date_range.end }).to eq(expected_ranges)
+ expect(calendar.date_ranges.map { |period| period.begin..period.end }).to eq(expected_ranges)
end
end