diff options
| author | Alban Peignier | 2018-04-02 23:19:48 +0200 | 
|---|---|---|
| committer | Alban Peignier | 2018-04-02 23:19:48 +0200 | 
| commit | 1e9ed69dc7509ffc6c0ae1a401c04d57dbbea45a (patch) | |
| tree | ed5eabf542ba844eafd605620cbc35dd72e4134f | |
| parent | ecba5b99bb8eae41507d1040f32584472b740d26 (diff) | |
| download | chouette-core-1e9ed69dc7509ffc6c0ae1a401c04d57dbbea45a.tar.bz2 | |
Import TimeTableDates from calendar dates. Refs #6368
| -rw-r--r-- | app/models/import/gtfs.rb | 13 | ||||
| -rw-r--r-- | app/models/referential.rb | 4 | ||||
| -rw-r--r-- | spec/models/import/gtfs_spec.rb | 25 | 
3 files changed, 42 insertions, 0 deletions
| diff --git a/app/models/import/gtfs.rb b/app/models/import/gtfs.rb index e6552f936..b0c1070bd 100644 --- a/app/models/import/gtfs.rb +++ b/app/models/import/gtfs.rb @@ -254,6 +254,19 @@ class Import::Gtfs < Import::Base      end    end +  def import_calendar_dates +    source.calendar_dates.each_slice(500) do |slice| +      Chouette::TimeTable.transaction do +        slice.each do |calendar_date| +          time_table = referential.time_tables.find time_tables_by_service_id[calendar_date.service_id] +          date = time_table.dates.build date: Date.parse(calendar_date.date), in_out: calendar_date.exception_type == "1" + +          save_model date +        end +      end +    end +  end +    def save_model(model)      unless model.save        Rails.logger.info "Can't save #{model.class.name} : #{model.errors.inspect}" diff --git a/app/models/referential.rb b/app/models/referential.rb index 65af58873..70148aa8e 100644 --- a/app/models/referential.rb +++ b/app/models/referential.rb @@ -168,6 +168,10 @@ class Referential < ActiveRecord::Base      Chouette::TimeTable.all    end +  def time_table_dates +    Chouette::TimeTableDate.all +  end +    def timebands      Chouette::Timeband.all    end diff --git a/spec/models/import/gtfs_spec.rb b/spec/models/import/gtfs_spec.rb index 934f13c1d..f2404b771 100644 --- a/spec/models/import/gtfs_spec.rb +++ b/spec/models/import/gtfs_spec.rb @@ -220,6 +220,31 @@ RSpec.describe Import::Gtfs do      end    end +  describe "#import_calendar_dates" do +    let(:import) { create_import "google-sample-feed.zip" } + +    before do +      import.prepare_referential +      import.import_calendars +    end + +    it "should create a Timetable::Date for each calendar date" do +      import.import_calendar_dates + +      def d(value) +        Date.parse(value) +      end + +      defined_attributes = ->(d) { +        [d.time_table.comment, d.date, d.in_out] +      } +      expected_attributes = [ +        ["Calendar FULLW", d("Mon, 04 Jun 2007"), false] +      ] +      expect(referential.time_table_dates.map(&defined_attributes)).to eq(expected_attributes) +    end +  end +    describe "#download_local_file" do      let(:file) { "google-sample-feed.zip" } | 
