aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZog2018-04-25 18:40:25 +0200
committerZog2018-04-25 18:40:25 +0200
commit6c61ffc242a562aeac83317c756e09d8ad210815 (patch)
tree4beac3f794b3b42f60517647fb157c706dce2b4b
parent53990515457b7618e9b2b36832751ad8622fd56e (diff)
downloadchouette-core-6c61ffc242a562aeac83317c756e09d8ad210815.tar.bz2
Refs #6762; Fix bug on RoutingConstraintsZone merge
And add some specs
-rw-r--r--app/models/chouette/route.rb6
-rw-r--r--app/models/merge.rb2
-rw-r--r--db/migrate/20180425160730_change_routing_constraint_zones_stop_ids_type.rb8
-rw-r--r--spec/models/merge_spec.rb35
4 files changed, 49 insertions, 2 deletions
diff --git a/app/models/chouette/route.rb b/app/models/chouette/route.rb
index 928b65f13..0fac53ec0 100644
--- a/app/models/chouette/route.rb
+++ b/app/models/chouette/route.rb
@@ -148,11 +148,15 @@ module Chouette
values = self.slice(*['name', 'published_name', 'wayback']).values
values.tap do |attrs|
attrs << self.stop_points.sort_by(&:position).map{|sp| [sp.stop_area.user_objectid, sp.for_boarding, sp.for_alighting]}
- attrs << self.routing_constraint_zones.map(&:checksum).sort
+
+ routing_constraint_zones = self.routing_constraint_zones
+ routing_constraint_zones += Chouette::RoutingConstraintZone.with_stop_points_contained_in(self.stop_points) unless self.new_record?
+ attrs << routing_constraint_zones.uniq.map(&:checksum).sort
end
end
has_checksum_children StopPoint
+ has_checksum_children RoutingConstraintZone
def geometry
points = stop_areas.map(&:to_lat_lng).compact.map do |loc|
diff --git a/app/models/merge.rb b/app/models/merge.rb
index eadeccaa7..69749d105 100644
--- a/app/models/merge.rb
+++ b/app/models/merge.rb
@@ -212,7 +212,7 @@ class Merge < ApplicationModel
end
new_route.routing_constraint_zones.each do |new_routing_constraint_zone|
- routing_constraint_zone = routing_constraint_zones.find { |c| c.checksum = new_routing_constraint_zone.checksum }
+ routing_constraint_zone = routing_constraint_zones.find { |c| c.checksum == new_routing_constraint_zone.checksum }
if routing_constraint_zone
referential_routing_constraint_zones_new_ids[routing_constraint_zone.id] = new_routing_constraint_zone.id
else
diff --git a/db/migrate/20180425160730_change_routing_constraint_zones_stop_ids_type.rb b/db/migrate/20180425160730_change_routing_constraint_zones_stop_ids_type.rb
new file mode 100644
index 000000000..1e4224186
--- /dev/null
+++ b/db/migrate/20180425160730_change_routing_constraint_zones_stop_ids_type.rb
@@ -0,0 +1,8 @@
+class ChangeRoutingConstraintZonesStopIdsType < ActiveRecord::Migration
+ def change
+ reversible do |dir|
+ dir.up { change_column :routing_constraint_zones, :stop_point_ids, :integer, array: true }
+ dir.down { change_column :routing_constraint_zones, :stop_point_ids, :bigint, array: true }
+ end
+ end
+end
diff --git a/spec/models/merge_spec.rb b/spec/models/merge_spec.rb
index 95181a80e..685e675cd 100644
--- a/spec/models/merge_spec.rb
+++ b/spec/models/merge_spec.rb
@@ -22,6 +22,8 @@ RSpec.describe Merge do
factor = 1
stop_points_positions = {}
+ routing_constraint_zones = {}
+
referential.switch do
line_referential.lines.each do |line|
factor.times do
@@ -35,6 +37,16 @@ RSpec.describe Merge do
sp.set_list_position 0
end
route.reload.update_checksum!
+ checksum = route.checksum
+ routing_constraint_zones[route.id] = {}
+ 2.times do |i|
+ constraint_zone = create(:routing_constraint_zone, route: route)
+ if i > 0
+ constraint_zone.update stop_points: constraint_zone.stop_points[0...-1]
+ end
+ routing_constraint_zones[route.id][constraint_zone.checksum] = constraint_zone
+ end
+ expect(route.reload.checksum).to_not eq checksum
factor.times do
FactoryGirl.create :journey_pattern, route: route, stop_points: route.stop_points.sample(3)
end
@@ -54,7 +66,9 @@ RSpec.describe Merge do
specific_time_table = FactoryGirl.create :time_table
vehicle_journey.time_tables << specific_time_table
+ vehicle_journey.update ignored_routing_contraint_zone_ids: routing_constraint_zones[vehicle_journey.route.id].values.map(&:id)
end
+
end
merge = Merge.create!(workbench: referential.workbench, referentials: [referential, referential])
@@ -63,6 +77,27 @@ RSpec.describe Merge do
output = merge.output.current
output.switch
+ output.routes.each do |route|
+ stop_points = nil
+ old_route = nil
+ referential.switch do
+ old_route = Chouette::Route.find_by(checksum: route.checksum)
+ stop_points = {}
+ old_route.routing_constraint_zones.each do |constraint_zone|
+ stop_points[constraint_zone.checksum] = constraint_zone.stop_points.map(&:registration_number)
+ end
+ end
+ routing_constraint_zones[old_route.id].each do |checksum, constraint_zone|
+ new_constraint_zone = route.routing_constraint_zones.where(checksum: checksum).last
+ expect(new_constraint_zone).to be_present
+ expect(new_constraint_zone.stop_points.map(&:registration_number)).to eq stop_points[checksum]
+ end
+
+ route.vehicle_journeys.each do |vehicle_journey|
+ expect(vehicle_journey.ignored_routing_contraint_zones.size).to eq vehicle_journey.ignored_routing_contraint_zone_ids.size
+ end
+ end
+
# Let's check stop_point positions are respected
# This should be enforced by the checksum preservation though
output.journey_patterns.each do |journey_pattern|