From fea3d9f9ed8cfd71b01f75218655957b2589a47c Mon Sep 17 00:00:00 2001 From: Xinhui Date: Mon, 19 Sep 2016 14:52:28 +0200 Subject: Fix store reflex objectid without referential prefix Refs #1627 --- app/models/chouette/stop_area.rb | 3 ++- app/models/concerns/stop_area_restrictions.rb | 1 - lib/stif/reflex_synchronization.rb | 10 ++++------ spec/tasks/reflex_rake_spec.rb | 2 +- 4 files changed, 7 insertions(+), 9 deletions(-) diff --git a/app/models/chouette/stop_area.rb b/app/models/chouette/stop_area.rb index 3be815499..c396a8c0f 100644 --- a/app/models/chouette/stop_area.rb +++ b/app/models/chouette/stop_area.rb @@ -8,7 +8,8 @@ class Chouette::StopArea < Chouette::ActiveRecord include ProjectionFields include StopAreaRestrictions - include DefaultAttributesSupport + # Refs #1627 + # include DefaultAttributesSupport include StopAreaReferentialSupport has_many :stop_points, :dependent => :destroy diff --git a/app/models/concerns/stop_area_restrictions.rb b/app/models/concerns/stop_area_restrictions.rb index 38a57b55a..96f0507d6 100644 --- a/app/models/concerns/stop_area_restrictions.rb +++ b/app/models/concerns/stop_area_restrictions.rb @@ -23,7 +23,6 @@ module StopAreaRestrictions included do include ObjectidRestrictions - with_options if: :commercial_and_physical_hub_restricted? do |sa| # HUB-23 sa.validate :specific_objectid diff --git a/lib/stif/reflex_synchronization.rb b/lib/stif/reflex_synchronization.rb index eab86caf1..b68fd6fc5 100644 --- a/lib/stif/reflex_synchronization.rb +++ b/lib/stif/reflex_synchronization.rb @@ -5,9 +5,8 @@ module Stif StopAreaReferential.find_by(name: "Reflex") end - # Todo remove dummy objectid def find_by_object_id objectid - Chouette::StopArea.find_by(objectid: "dummy:StopArea:#{objectid.tr(':', '')}") + Chouette::StopArea.find_by(objectid: objectid) end def synchronize @@ -45,7 +44,7 @@ module Stif self.defaut_referential.stop_area_referential_sync.record_status :ok, I18n.t('synchronization.reflex.message.success', time: Time.now - tstart, imported: processed.uniq.size, deleted: deleted.size) rescue Exception => e Rails.logger.error "Reflex:sync - Error: #{e}, ended after #{Time.now - tstart} seconds" - LineReferential.first.line_referential_sync.record_status :ko, I18n.t('synchronization.reflex.message.failure', time: Time.now - tstart) + self.defaut_referential.stop_area_referential_sync.record_status :ko, I18n.t('synchronization.reflex.message.failure', time: Time.now - tstart) end end @@ -81,6 +80,7 @@ module Stif def create_or_update_access_point entry, stop_area access = Chouette::AccessPoint.find_or_create_by(objectid: "dummy:AccessPoint:#{entry.id.tr(':', '')}") + # Hack, on save object_version will be incremented by 1 entry.version = entry.version.to_i + 1 if access.persisted? access.stop_area = stop_area { @@ -95,9 +95,7 @@ module Stif end def create_or_update_stop_area entry - stop = Chouette::StopArea.find_or_create_by(objectid: "dummy:StopArea:#{entry.id.tr(':', '')}") - # Hack, on save object_version will be incremented by 1 - entry.version = entry.version.to_i + 1 if stop.persisted? + stop = Chouette::StopArea.find_or_create_by(objectid: entry.id) stop.deleted_at = nil stop.stop_area_referential = self.defaut_referential { diff --git a/spec/tasks/reflex_rake_spec.rb b/spec/tasks/reflex_rake_spec.rb index 3a0ce0632..ff9a555ef 100644 --- a/spec/tasks/reflex_rake_spec.rb +++ b/spec/tasks/reflex_rake_spec.rb @@ -29,7 +29,7 @@ describe 'reflex:sync' do end it 'should map xml data to StopArea attribute' do - stop_area = Chouette::StopArea.find_by(name: 'First stopPlace') + stop_area = Chouette::StopArea.find_by(objectid: 'FR:77153:LDA:69325:STIF') expect(stop_area.city_name).to eq 'Dammartin-en-Goƫle' expect(stop_area.zip_code).to eq '77153' expect(stop_area.area_type).to eq 'StopPlace' -- cgit v1.2.3