diff options
| author | Luc Donnet | 2017-09-07 16:28:32 +0200 | 
|---|---|---|
| committer | Luc Donnet | 2017-09-07 16:28:32 +0200 | 
| commit | 99aff9c3e63fb15b555806847bc14fbf56eeef2a (patch) | |
| tree | 339ca9b884504c19cecc0956c629614ace926901 | |
| parent | 8b5a3e68c37a9331f47608faaa6903a01c390861 (diff) | |
| parent | 01b0d19c329810a083153efbf040911e4079f6ef (diff) | |
| download | chouette-core-99aff9c3e63fb15b555806847bc14fbf56eeef2a.tar.bz2 | |
Merge branch 'master' of github.com:AF83/stif-boiv
| -rw-r--r-- | app/controllers/autocomplete_time_tables_controller.rb | 5 | ||||
| -rw-r--r-- | app/models/chouette/active_record.rb | 13 | ||||
| -rw-r--r-- | app/models/referential.rb | 6 | ||||
| -rw-r--r-- | app/views/calendars/index.html.slim | 4 | ||||
| -rw-r--r-- | app/views/time_table_combinations/_form.html.slim | 2 | ||||
| -rw-r--r-- | config/locales/calendars.en.yml | 1 | ||||
| -rw-r--r-- | config/locales/calendars.fr.yml | 1 | ||||
| -rw-r--r-- | db/migrate/20170907082913_add_data_source_ref.rb | 10 | ||||
| -rw-r--r-- | db/schema.rb | 10 | ||||
| -rw-r--r-- | lib/stif/reflex_synchronization.rb | 16 | ||||
| -rw-r--r-- | spec/models/chouette/footnote_spec.rb | 14 | ||||
| -rw-r--r-- | spec/workers/referential_cloning_worker_spec.rb | 18 | 
12 files changed, 84 insertions, 16 deletions
| diff --git a/app/controllers/autocomplete_time_tables_controller.rb b/app/controllers/autocomplete_time_tables_controller.rb index d0cd94e26..f65f5b9f6 100644 --- a/app/controllers/autocomplete_time_tables_controller.rb +++ b/app/controllers/autocomplete_time_tables_controller.rb @@ -22,7 +22,12 @@ class AutocompleteTimeTablesController < InheritedResources::Base      scope.distinct    end +  def split_params! search +    params[:q][search] = params[:q][search].split(" ") if params[:q][search] +  end +    def collection +    split_params! :comment_or_objectid_cont_any      @time_tables = select_time_tables.search(params[:q]).result.paginate(page: params[:page])    end  end diff --git a/app/models/chouette/active_record.rb b/app/models/chouette/active_record.rb index 1862319af..e12f30266 100644 --- a/app/models/chouette/active_record.rb +++ b/app/models/chouette/active_record.rb @@ -2,10 +2,8 @@  require 'deep_cloneable'  module Chouette    class ActiveRecord < ::ActiveRecord::Base -      self.abstract_class = true - -    before_save :nil_if_blank +    before_save :nil_if_blank, :set_data_source_ref      # to be overridden to set nullable attrs when empty      def self.nullable_attributes @@ -16,17 +14,22 @@ module Chouette        self.class.nullable_attributes.each { |attr| self[attr] = nil if self[attr].blank? }      end -      def human_attribute_name(*args)        self.class.human_attribute_name(*args)      end +    def set_data_source_ref +      if self.respond_to?(:data_source_ref) +        self.data_source_ref ||= 'DATASOURCEREF_EDITION_BOIV' +      end +    end +      # TODO: Can we remove this?      # class << self      #   alias_method :create_reflection_without_chouette_naming, :create_reflection      #   def create_reflection(macro, name, options, active_record) -    #     options =  +    #     options =      #       Reflection.new(macro, name, options, active_record).options_with_default      #     create_reflection_without_chouette_naming(macro, name, options, active_record) diff --git a/app/models/referential.rb b/app/models/referential.rb index ecfc69c4a..65e203f9f 100644 --- a/app/models/referential.rb +++ b/app/models/referential.rb @@ -1,3 +1,4 @@ +# coding: utf-8  class Referential < ActiveRecord::Base    include DataFormatEnumerations @@ -185,7 +186,6 @@ class Referential < ActiveRecord::Base    before_validation :assign_slug, :on => :create    before_validation :assign_prefix, :on => :create    before_create :create_schema -    after_create :clone_schema, if: :created_from    before_destroy :destroy_schema @@ -289,7 +289,9 @@ class Referential < ActiveRecord::Base    end    def create_schema -    Apartment::Tenant.create slug +    unless created_from +      Apartment::Tenant.create slug +    end    end    def assign_slug diff --git a/app/views/calendars/index.html.slim b/app/views/calendars/index.html.slim index 56232b0af..24ed15484 100644 --- a/app/views/calendars/index.html.slim +++ b/app/views/calendars/index.html.slim @@ -31,6 +31,10 @@                  attribute: 'short_name' \                ), \                TableBuilderHelper::Column.new( \ +                key: :organisation, \ +                attribute: Proc.new { |c| c.organisation.name } \ +              ), \ +              TableBuilderHelper::Column.new( \                  key: :shared, \                  attribute: Proc.new { |c| t("#{c.try(:shared)}") } \                ) \ diff --git a/app/views/time_table_combinations/_form.html.slim b/app/views/time_table_combinations/_form.html.slim index 8e2d77d46..426624ee3 100644 --- a/app/views/time_table_combinations/_form.html.slim +++ b/app/views/time_table_combinations/_form.html.slim @@ -7,7 +7,7 @@            abbr title='Champ requis' *          = f.input :combined_type, as: :boolean, checked_value: 'time_table', unchecked_value: 'calendar', required: false, label: content_tag(:span, t("time_table_combinations.combined_type.#{@combination.combined_type}"), class: 'switch-label', data: { checkedValue: 'Calendriers', uncheckedValue: 'Modèles de calendriers' }), wrapper_html: { class: 'col-sm-8 col-xs-7' } -      = f.input :time_table_id, as: :select, input_html: {class: 'tt_combination_target', style: "width: 100%", data: { 'select2-ajax': 'true', 'select2ed-placeholder': 'Indiquez un calendrier...', term: 'comment_cont_or_objectid_cont', url: referential_autocomplete_time_tables_path(@referential, format: :json, :source_id => @combination.source_id)}}, wrapper_html: {class: @combination.combined_type != 'time_table' ? 'hidden' : ''} +      = f.input :time_table_id, as: :select, input_html: {class: 'tt_combination_target', style: "width: 100%", data: { 'select2-ajax': 'true', 'select2ed-placeholder': 'Indiquez un calendrier...', term: 'comment_or_objectid_cont_any', url: referential_autocomplete_time_tables_path(@referential, format: :json, :source_id => @combination.source_id)}}, wrapper_html: {class: @combination.combined_type != 'time_table' ? 'hidden' : ''}        = f.input :calendar_id, as: :select, input_html: { class: 'tt_combination_target', style: "width: 100%", data: { 'select2-ajax': 'true', 'select2ed-placeholder': 'Indiquez un modèle de calendrier...', term: 'name_cont', url: autocomplete_calendars_path}}, wrapper_html: {class: @combination.combined_type != 'calendar' ? 'hidden' : ''} diff --git a/config/locales/calendars.en.yml b/config/locales/calendars.en.yml index cb1ede4c7..42e26e995 100644 --- a/config/locales/calendars.en.yml +++ b/config/locales/calendars.en.yml @@ -64,6 +64,7 @@ en:          date_ranges: Date ranges          dates: Dates          shared: Shared +        organisation: Organisation      errors:        models:          calendar: diff --git a/config/locales/calendars.fr.yml b/config/locales/calendars.fr.yml index 1b403c3f2..63f6465d9 100644 --- a/config/locales/calendars.fr.yml +++ b/config/locales/calendars.fr.yml @@ -64,6 +64,7 @@ fr:          date_ranges: Intervalles de dates          dates: Dates          shared: Partagé +        organisation: Organisation      errors:        models:          calendar: diff --git a/db/migrate/20170907082913_add_data_source_ref.rb b/db/migrate/20170907082913_add_data_source_ref.rb new file mode 100644 index 000000000..93ca8eb5f --- /dev/null +++ b/db/migrate/20170907082913_add_data_source_ref.rb @@ -0,0 +1,10 @@ +class AddDataSourceRef < ActiveRecord::Migration +  def change +    add_column :routes, :data_source_ref, :string +    add_column :journey_patterns, :data_source_ref, :string +    add_column :routing_constraint_zones, :data_source_ref, :string +    add_column :vehicle_journeys, :data_source_ref, :string +    add_column :time_tables, :data_source_ref, :string +    add_column :footnotes, :data_source_ref, :string +  end +end diff --git a/db/schema.rb b/db/schema.rb index d1bd3bc2b..98e60c909 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@  #  # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20170901132253) do +ActiveRecord::Schema.define(version: 20170907082913) do    # These are extensions that must be enabled in order to support this database    enable_extension "plpgsql" @@ -221,6 +221,7 @@ ActiveRecord::Schema.define(version: 20170901132253) do      t.datetime "updated_at"      t.string   "checksum"      t.text     "checksum_source" +    t.string   "data_source_ref"    end    create_table "footnotes_vehicle_journeys", id: false, force: :cascade do |t| @@ -292,9 +293,9 @@ ActiveRecord::Schema.define(version: 20170901132253) do      t.string   "type"      t.integer  "parent_id",             limit: 8      t.string   "parent_type" +    t.datetime "notified_parent_at"      t.integer  "current_step",                    default: 0      t.integer  "total_steps",                     default: 0 -    t.datetime "notified_parent_at"      t.string   "creator"    end @@ -343,6 +344,7 @@ ActiveRecord::Schema.define(version: 20170901132253) do      t.datetime "updated_at"      t.string   "checksum"      t.text     "checksum_source" +    t.string   "data_source_ref"    end    add_index "journey_patterns", ["objectid"], name: "journey_patterns_objectid_key", unique: true, using: :btree @@ -553,6 +555,7 @@ ActiveRecord::Schema.define(version: 20170901132253) do      t.datetime "updated_at"      t.string   "checksum"      t.text     "checksum_source" +    t.string   "data_source_ref"    end    add_index "routes", ["objectid"], name: "routes_objectid_key", unique: true, using: :btree @@ -568,6 +571,7 @@ ActiveRecord::Schema.define(version: 20170901132253) do      t.integer  "stop_point_ids",  limit: 8,              array: true      t.string   "checksum"      t.text     "checksum_source" +    t.string   "data_source_ref"    end    create_table "routing_constraints_lines", id: false, force: :cascade do |t| @@ -733,6 +737,7 @@ ActiveRecord::Schema.define(version: 20170901132253) do      t.integer  "created_from_id"      t.string   "checksum"      t.text     "checksum_source" +    t.string   "data_source_ref"    end    add_index "time_tables", ["calendar_id"], name: "index_time_tables_on_calendar_id", using: :btree @@ -838,6 +843,7 @@ ActiveRecord::Schema.define(version: 20170901132253) do      t.datetime "updated_at"      t.string   "checksum"      t.text     "checksum_source" +    t.string   "data_source_ref"    end    add_index "vehicle_journeys", ["objectid"], name: "vehicle_journeys_objectid_key", unique: true, using: :btree diff --git a/lib/stif/reflex_synchronization.rb b/lib/stif/reflex_synchronization.rb index fe372f0b9..b3f474221 100644 --- a/lib/stif/reflex_synchronization.rb +++ b/lib/stif/reflex_synchronization.rb @@ -34,6 +34,14 @@ module Stif          Chouette::StopArea.find_by(objectid: objectid)        end +      def save_if_valid object +        if object.valid? +          object.save +        else +          Rails.logger.error "Reflex:sync - #{object.class.model_name} with objectid #{object.objectid} and name #{object.name} can't be saved" +        end +      end +        def synchronize          reset_counts          ['getOR', 'getOP'].each do |method| @@ -99,7 +107,7 @@ module Stif          if entry['parent']            stop.parent = self.find_by_object_id entry['parent'] -          stop.save if stop.changed && stop.valid? +          save_if_valid(stop) if stop.changed?          end          if entry['quays'] @@ -107,7 +115,7 @@ module Stif              children = self.find_by_object_id id              next unless children              children.parent = stop -            children.save if children.changed? && children.valid? +            save_if_valid(children) if children.changed?            end          end        end @@ -138,7 +146,7 @@ module Stif            access['longitude'] = entry['gml:pos'][:lng]            access['latitude']  = entry['gml:pos'][:lat]          end -        access.save if access.valid? && access.changed? +        save_if_valid(access) if access.changed?        end        def create_or_update_stop_area entry @@ -166,7 +174,7 @@ module Stif            stop.import_xml = entry[:xml]            prop = stop.new_record? ? :imported_count : :updated_count            increment_counts prop, 1 -          stop.save if stop.valid? +          save_if_valid(stop)          end          # Create AccessPoint from StopPlaceEntrance          if entry[:stop_place_entrances] diff --git a/spec/models/chouette/footnote_spec.rb b/spec/models/chouette/footnote_spec.rb index 98d751499..fc5e5f306 100644 --- a/spec/models/chouette/footnote_spec.rb +++ b/spec/models/chouette/footnote_spec.rb @@ -2,9 +2,21 @@ require 'spec_helper'  describe Chouette::Footnote, type: :model do    let(:footnote) { create(:footnote) } -    it { should validate_presence_of :line } +  describe 'data_source_ref' do +    it 'should set default if omitted' do +      expect(footnote.data_source_ref).to eq "DATASOURCEREF_EDITION_BOIV" +    end + +    it 'should not set default if not omitted' do +      source = "RANDOM_DATASOURCE" +      object = build(:footnote, data_source_ref: source) +      object.save +      expect(object.data_source_ref).to eq source +    end +  end +    describe 'checksum' do      it_behaves_like 'checksum support', :footnote diff --git a/spec/workers/referential_cloning_worker_spec.rb b/spec/workers/referential_cloning_worker_spec.rb index 52ed8913b..7e4a2357a 100644 --- a/spec/workers/referential_cloning_worker_spec.rb +++ b/spec/workers/referential_cloning_worker_spec.rb @@ -3,7 +3,7 @@ require 'ostruct'  RSpec.describe ReferentialCloningWorker do -  context "given a refererntial cloning" do +  context "given a referential cloning" do      let( :id ){ double } @@ -34,4 +34,20 @@ RSpec.describe ReferentialCloningWorker do      end    end +  it "should clone an existing Referential" do +    source_referential = create :referential + +    source_referential.switch +    source_time_table = create :time_table + +    target_referential = create :referential, created_from: source_referential + +    cloning = ReferentialCloning.create source_referential: source_referential, target_referential: target_referential +    ReferentialCloningWorker.new.perform(cloning) + +    target_referential.switch +    expect(Chouette::TimeTable.where(objectid: source_time_table.objectid).exists?) +  end + +  end | 
