aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorcedricnjanga2017-07-25 15:22:11 +0200
committercedricnjanga2017-07-25 15:22:25 +0200
commit2555152d66b5189350f4bfdc9b4b0658d959b5be (patch)
tree4efca5fa44a84df1dce167861c2bc7db50d6dbe6
parentee252340561ef9338d8c0aa454d256ec58a0e296 (diff)
downloadchouette-core-2555152d66b5189350f4bfdc9b4b0658d959b5be.tar.bz2
Add tests for Timetable#merge
-rw-r--r--app/models/chouette/time_table.rb2
-rw-r--r--spec/models/chouette/time_table_spec.rb10
-rw-r--r--spec/models/time_table_combination_spec.rb54
3 files changed, 64 insertions, 2 deletions
diff --git a/app/models/chouette/time_table.rb b/app/models/chouette/time_table.rb
index 8e8e31d9e..713ce0b21 100644
--- a/app/models/chouette/time_table.rb
+++ b/app/models/chouette/time_table.rb
@@ -542,7 +542,7 @@ class Chouette::TimeTable < Chouette::TridentActiveRecord
another_tt.excluded_days.each do |d|
unless self.reload.excluded_date?(d)
- self.dates.create!(:date => d, :in_out => false)
+ self.dates << Chouette::TimeTableDate.new(date: d, in_out: false)
end
self.save!
end
diff --git a/spec/models/chouette/time_table_spec.rb b/spec/models/chouette/time_table_spec.rb
index fb59a75be..304cb0184 100644
--- a/spec/models/chouette/time_table_spec.rb
+++ b/spec/models/chouette/time_table_spec.rb
@@ -59,6 +59,14 @@ describe Chouette::TimeTable, :type => :model do
subject.merge!(another_tt)
expect(subject.dates.map(&:date)).to include(another_tt.dates.last.date)
end
+
+ it 'should remove date in_out false if other tt doesnt have them' do
+ subject.dates.create(in_out: false, date: Date.today + 5.day + 1.year)
+
+ expect {
+ subject.merge!(another_tt)
+ }.to change {subject.reload.excluded_days.count}.by(-1)
+ end
end
context "#merge! with calendar" do
@@ -1124,7 +1132,7 @@ end
- describe "#optimize_periods" do
+ describe "#optimize_overlapping_periods" do
before do
subject.periods.clear
subject.periods << Chouette::TimeTablePeriod.new(
diff --git a/spec/models/time_table_combination_spec.rb b/spec/models/time_table_combination_spec.rb
index 81f9dd7a6..ee934f50d 100644
--- a/spec/models/time_table_combination_spec.rb
+++ b/spec/models/time_table_combination_spec.rb
@@ -44,6 +44,60 @@ describe TimeTableCombination, :type => :model do
end
end
+ describe '#continuous_periods' do
+ it 'should group continuous periods' do
+ source.periods.clear
+
+ start_date = Date.today + 1.year
+ end_date = start_date + 10
+
+ # 6 more continuous dates, 2 isolated dates
+ 0.upto(4) do |i|
+ source.periods.create(period_start: start_date, period_end: end_date)
+ start_date = end_date + 1
+ end_date = start_date + 10
+ end
+
+ expect(source.reload.continuous_periods.flatten.count).to eq(5)
+ end
+ end
+
+ describe '#convert_continuous_periods_into_one' do
+ it 'should convert continuous periods into one' do
+ source.periods.clear
+
+ start_date = Date.today + 1.year
+ end_date = start_date + 10
+
+ # 6 more continuous dates, 2 isolated dates
+ 0.upto(4) do |i|
+ source.periods.create(period_start: start_date, period_end: end_date)
+ start_date = end_date + 1
+ end_date = start_date + 10
+ end
+
+ expect {
+ source.reload.convert_continuous_periods_into_one
+ }.to change {source.periods.count}.by(-4)
+ end
+ end
+
+ describe '#optimize_continuous_dates_and_periods' do
+ it 'should update period if timetable has in_date just before or after ' do
+ source.dates.clear
+ source.periods.clear
+
+ source.periods.create(period_start: Date.today, period_end: Date.today + 10.day)
+ source.dates.create(date: Date.today - 1.day, in_out: true)
+
+ expect {
+ source.periods = source.optimize_continuous_dates_and_periods
+ }.to change {source.dates.count}.by(-1)
+
+ expect(source.reload.periods.first.period_start).to eq(Date.today - 1.day)
+ end
+ end
+
describe "#combine" do
context "when operation is union" do
before(:each) do