aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorXinhui2017-06-13 16:38:11 +0200
committerXinhui2017-06-13 16:38:16 +0200
commitf1714bc046dd187883197371e5c8641dbdc5e17f (patch)
tree65d6898113b503bb71d88060ea29a2c98d071c7b
parent238cce6d229c0f46b5ea6731e80af1bafe952726 (diff)
downloadchouette-core-f1714bc046dd187883197371e5c8641dbdc5e17f.tar.bz2
Fix merge time_table with calendar should copy calendar dates
Refs #3705
-rw-r--r--app/models/chouette/time_table.rb11
-rw-r--r--spec/models/chouette/time_table_spec.rb11
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 }