diff options
| author | Xinhui | 2017-05-31 11:26:22 +0200 |
|---|---|---|
| committer | Xinhui | 2017-05-31 11:26:29 +0200 |
| commit | b7ed505e00a26ebcf3c1e564cd32abaafee02e38 (patch) | |
| tree | c96b8c72c7a39ba77e3de18765ee5047121d7fee | |
| parent | 8eb1c7fc424d0801e9322a0c0cfffb6346fe6fc4 (diff) | |
| download | chouette-core-b7ed505e00a26ebcf3c1e564cd32abaafee02e38.tar.bz2 | |
Fix time_table should keep int_day_types on #actualize
Refs #3445
| -rw-r--r-- | app/models/chouette/time_table.rb | 5 | ||||
| -rw-r--r-- | spec/models/chouette/time_table_spec.rb | 26 |
2 files changed, 30 insertions, 1 deletions
diff --git a/app/models/chouette/time_table.rb b/app/models/chouette/time_table.rb index 42879c6d5..85f1e8c6e 100644 --- a/app/models/chouette/time_table.rb +++ b/app/models/chouette/time_table.rb @@ -138,7 +138,10 @@ class Chouette::TimeTable < Chouette::TridentActiveRecord def actualize self.dates.clear self.periods.clear - self.merge! self.calendar.convert_to_time_table + from = self.calendar.convert_to_time_table + self.dates = from.dates + self.periods = from.periods + self.save end def month_inspect(date) diff --git a/spec/models/chouette/time_table_spec.rb b/spec/models/chouette/time_table_spec.rb index 3d45bd346..de3e8e07d 100644 --- a/spec/models/chouette/time_table_spec.rb +++ b/spec/models/chouette/time_table_spec.rb @@ -7,6 +7,32 @@ describe Chouette::TimeTable, :type => :model do it { is_expected.to validate_presence_of :comment } it { is_expected.to validate_uniqueness_of :objectid } + describe "actualize" do + let(:calendar) { create(:calendar) } + let(:int_day_types) { 508 } + + before do + subject.int_day_types = int_day_types + subject.calendar = calendar + subject.save + subject.actualize + end + + it 'should override dates' do + expect(subject.dates.map(&:date)).to match_array calendar.dates + end + + it 'should override periods' do + [:period_start, :period_end].each do |key| + expect(subject.periods.map(&key)).to match_array calendar.convert_to_time_table.periods.map(&key) + end + end + + it 'should not change int_day_types' do + expect(subject.int_day_types).to eq(int_day_types) + end + end + describe "Update state" do def time_table_to_state time_table time_table.slice('id', 'comment').tap do |item| |
