aboutsummaryrefslogtreecommitdiffstats
path: root/spec/models/calendar_spec.rb
diff options
context:
space:
mode:
authorXinhui2017-05-15 11:32:56 +0200
committerXinhui2017-05-15 11:50:25 +0200
commit2c32ac2a3372dfaee531734d3cf94f6b522b7c1b (patch)
treec11ebe9672e36d607e562788b555460ebcadeb39 /spec/models/calendar_spec.rb
parent8cfb32a40ae3f2c48c6a7884a1a8251ee4a48254 (diff)
downloadchouette-core-2c32ac2a3372dfaee531734d3cf94f6b522b7c1b.tar.bz2
Calendar #convert_to_time_tablet
Refs #3372
Diffstat (limited to 'spec/models/calendar_spec.rb')
-rw-r--r--spec/models/calendar_spec.rb16
1 files changed, 12 insertions, 4 deletions
diff --git a/spec/models/calendar_spec.rb b/spec/models/calendar_spec.rb
index 36981961f..33d9676cd 100644
--- a/spec/models/calendar_spec.rb
+++ b/spec/models/calendar_spec.rb
@@ -9,6 +9,18 @@ RSpec.describe Calendar, :type => :model do
it { is_expected.to validate_presence_of(:short_name) }
it { is_expected.to validate_uniqueness_of(:short_name) }
+ describe '#to_time_table' do
+ let(:calendar) { create(:calendar, date_ranges: [Date.today..(Date.today + 1.month)]) }
+
+ it 'should convert calendar to an instance of Chouette::TimeTable' do
+ time_table = calendar.convert_to_time_table
+ expect(time_table).to be_an_instance_of(Chouette::TimeTable)
+ expect(time_table.periods[0].period_start).to eq(calendar.date_ranges[0].begin)
+ expect(time_table.periods[0].period_end).to eq(calendar.date_ranges[0].end)
+ expect(time_table.dates.map(&:date)).to match_array(calendar.dates)
+ end
+ end
+
describe 'validations' do
it 'validates that dates and date_ranges do not overlap' do
calendar = build(:calendar, dates: [Date.today], date_ranges: [Date.today..Date.tomorrow])
@@ -69,7 +81,6 @@ RSpec.describe Calendar, :type => :model do
end
describe 'intersect?' do
-
it 'should detect date in common with other date_ranges' do
november = period(begin: '2016-11-01', end: '2016-11-30')
mid_november_mid_december = period(begin: '2016-11-15', end: '2016-12-15')
@@ -111,7 +122,6 @@ RSpec.describe Calendar, :type => :model do
end
describe 'DateValue' do
-
subject { date_value }
def date_value(attributes = {})
@@ -141,8 +151,6 @@ RSpec.describe Calendar, :type => :model do
end
it { is_expected.to validate_presence_of(:value) }
-
end
-
end