diff options
| -rw-r--r-- | app/models/chouette/time_table.rb | 11 | ||||
| -rw-r--r-- | spec/models/chouette/time_table_spec.rb | 11 |
2 files changed, 16 insertions, 6 deletions
diff --git a/app/models/chouette/time_table.rb b/app/models/chouette/time_table.rb index 151570f20..4186af6d2 100644 --- a/app/models/chouette/time_table.rb +++ b/app/models/chouette/time_table.rb @@ -477,17 +477,18 @@ class Chouette::TimeTable < Chouette::TridentActiveRecord # merge effective days from another timetable def merge!(another_tt) transaction do + # merge dates + self.dates ||= [] + another_tt.included_days.each do |d| + add_included_day d + end + # if one tt has no period, just merge lists if self.periods.empty? || another_tt.periods.empty? if !another_tt.periods.empty? # copy periods self.periods = another_tt.clone_periods end - # merge dates - self.dates ||= [] - another_tt.included_days.each do |d| - add_included_day d - end else # check if periods can be kept common_day_types = self.int_day_types & another_tt.int_day_types & 508 diff --git a/spec/models/chouette/time_table_spec.rb b/spec/models/chouette/time_table_spec.rb index 1e5972c04..7a8863cb3 100644 --- a/spec/models/chouette/time_table_spec.rb +++ b/spec/models/chouette/time_table_spec.rb @@ -1,12 +1,21 @@ require 'spec_helper' describe Chouette::TimeTable, :type => :model do - subject { create(:time_table) } it { is_expected.to validate_presence_of :comment } it { is_expected.to validate_uniqueness_of :objectid } + context "merge with calendar" do + let(:calendar) { create(:calendar) } + + it 'should add calendar dates to time_table' do + subject.dates.clear + subject.merge!(calendar.convert_to_time_table) + expect(subject.dates.map(&:date)).to include(*calendar.dates) + end + end + describe "actualize" do let(:calendar) { create(:calendar) } let(:int_day_types) { 508 } |
