aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Dockerfile4
-rw-r--r--app/controllers/referentials_controller.rb1
-rw-r--r--app/models/chouette/vehicle_journey.rb52
-rw-r--r--app/models/referential.rb5
-rw-r--r--app/models/referential_cloning.rb4
-rw-r--r--app/policies/referential_policy.rb2
-rw-r--r--app/views/workbenches/show.html.slim5
-rw-r--r--db/migrate/20180502075142_revert_routing_constraint_zones_stop_ids_type.rb8
-rw-r--r--spec/controllers/referentials_controller_spec.rb1
-rw-r--r--spec/features/workbenches/workbenches_show_spec.rb21
-rw-r--r--spec/models/chouette/vehicle_journey_spec.rb8
-rw-r--r--spec/models/referential/referential_oid_format_from_wkbch_spec.rb3
-rw-r--r--spec/models/referential_spec.rb1
-rw-r--r--spec/support/pundit/shared_examples.rb6
14 files changed, 85 insertions, 36 deletions
diff --git a/Dockerfile b/Dockerfile
index e484de431..084a046c4 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -2,9 +2,9 @@ FROM debian:stable-slim
ENV RAILS_ENV=production RAILS_SERVE_STATIC_FILES=true RAILS_LOG_TO_STDOUT=true SIDEKIQ_REDIS_URL=redis://redis:6379/12
-RUN apt-get update && \
+RUN apt-get update && mkdir -p /usr/share/man/man1 /usr/share/man/man7 && \
apt-get install -y --no-install-recommends ruby2.3 && \
- apt-get install -y --no-install-recommends libpq5 libxml2 zlib1g imagemagick libproj12 && \
+ apt-get install -y --no-install-recommends libpq5 libxml2 zlib1g imagemagick libproj12 postgresql-client-common postgresql-client-9.6 && \
apt-get install -y --no-install-recommends cron && \
apt-get clean && rm -rf /var/lib/apt/lists/* && \
gem2.3 install bundler
diff --git a/app/controllers/referentials_controller.rb b/app/controllers/referentials_controller.rb
index 8addfbc32..80f954cde 100644
--- a/app/controllers/referentials_controller.rb
+++ b/app/controllers/referentials_controller.rb
@@ -136,7 +136,6 @@ class ReferentialsController < ChouetteController
def create_resource(referential)
referential.organisation = current_organisation
- referential.ready = true
super
end
diff --git a/app/models/chouette/vehicle_journey.rb b/app/models/chouette/vehicle_journey.rb
index 8b5354863..818287b04 100644
--- a/app/models/chouette/vehicle_journey.rb
+++ b/app/models/chouette/vehicle_journey.rb
@@ -355,32 +355,48 @@ module Chouette
end
end
- def fill_passing_time_at_borders
- encountered_borders = []
+ def fill_passing_times!
+ encountered_empty_vjas = []
previous_stop = nil
vehicle_journey_at_stops.each do |vjas|
sp = vjas.stop_point
- if sp.stop_area.area_type == "border"
- encountered_borders << vjas
+ if vjas.arrival_time.nil? && vjas.departure_time.nil?
+ encountered_empty_vjas << vjas
else
- if encountered_borders.any?
- before_cost = journey_pattern.costs_between previous_stop.stop_point, encountered_borders.first.stop_point
- after_cost = journey_pattern.costs_between encountered_borders.last.stop_point, sp
- if before_cost && before_cost[:distance] && after_cost && after_cost[:distance]
- before_distance = before_cost[:distance].to_f
- after_distance = after_cost[:distance].to_f
+ if encountered_empty_vjas.any?
+ raise "Cannot extrapolate passing times without an initial time" if previous_stop.nil?
+ distance_between_known = 0
+ distance_from_last_known = 0
+ cost = journey_pattern.costs_between previous_stop.stop_point, encountered_empty_vjas.first.stop_point
+ raise "MISSING cost between #{previous_stop.stop_point.stop_area.registration_number} AND #{encountered_empty_vjas.first.stop_point.stop_area.registration_number}" unless cost.present?
+ distance_between_known += cost[:distance].to_f
+ cost = journey_pattern.costs_between encountered_empty_vjas.last.stop_point, sp
+ raise "MISSING cost between #{encountered_empty_vjas.last.stop_point.stop_area.registration_number} AND #{sp.stop_area.registration_number}" unless cost.present?
+ distance_between_known += cost[:distance].to_f
+ distance_between_known += encountered_empty_vjas.each_slice(2).inject(0) do |sum, slice|
+ cost = journey_pattern.costs_between slice.first.stop_point, slice.last.stop_point
+ raise "MISSING cost between #{slice.first.stop_point.stop_area.registration_number} AND #{slice.last.stop_point.stop_area.registration_number}" unless cost.present?
+ sum + cost[:distance].to_f
+ end
+
+ previous = previous_stop
+ encountered_empty_vjas.each do |empty_vjas|
+ cost = journey_pattern.costs_between previous.stop_point, empty_vjas.stop_point
+ raise "MISSING cost between #{previous.stop_point.stop_area.registration_number} AND #{empty_vjas.stop_point.stop_area.registration_number}" unless cost.present?
+ distance_from_last_known += cost[:distance]
+
arrival_time = vjas.arrival_time + (vjas.arrival_day_offset - previous_stop.departure_day_offset)*24.hours
- time = previous_stop.departure_time + before_distance / (before_distance+after_distance) * (arrival_time - previous_stop.departure_time)
+ time = previous_stop.departure_time + distance_from_last_known.to_f / distance_between_known.to_f * (arrival_time - previous_stop.departure_time)
day_offset = time.day - 1
time -= day_offset*24.hours
- encountered_borders.each do |b|
- b.update_attribute :arrival_time, time
- b.update_attribute :arrival_day_offset, previous_stop.arrival_day_offset + day_offset
- b.update_attribute :departure_time, time
- b.update_attribute :departure_day_offset, previous_stop.departure_day_offset + day_offset
- end
+
+ empty_vjas.update_attribute :arrival_time, time
+ empty_vjas.update_attribute :arrival_day_offset, previous_stop.arrival_day_offset + day_offset
+ empty_vjas.update_attribute :departure_time, time
+ empty_vjas.update_attribute :departure_day_offset, previous_stop.departure_day_offset + day_offset
+ previous = empty_vjas
end
- encountered_borders = []
+ encountered_empty_vjas = []
end
previous_stop = vjas
end
diff --git a/app/models/referential.rb b/app/models/referential.rb
index 933bc78e3..b4f64fad1 100644
--- a/app/models/referential.rb
+++ b/app/models/referential.rb
@@ -59,7 +59,6 @@ class Referential < ApplicationModel
belongs_to :referential_suite
-
scope :pending, -> { where(ready: false, failed_at: nil, archived_at: nil) }
scope :active, -> { where(ready: true, failed_at: nil, archived_at: nil) }
scope :failed, -> { where.not(failed_at: nil) }
@@ -271,7 +270,8 @@ class Referential < ApplicationModel
stop_area_referential: from.stop_area_referential,
created_from: from,
objectid_format: from.objectid_format,
- metadatas: from.metadatas.map { |m| ReferentialMetadata.new_from(m, organisation) }
+ metadatas: from.metadatas.map { |m| ReferentialMetadata.new_from(m, organisation) },
+ ready: false
)
end
@@ -471,6 +471,7 @@ class Referential < ApplicationModel
end
def destroy_schema
+ return unless ActiveRecord::Base.connection.schema_names.include?(slug)
Apartment::Tenant.drop slug
end
diff --git a/app/models/referential_cloning.rb b/app/models/referential_cloning.rb
index 4179ba312..cb8ad3630 100644
--- a/app/models/referential_cloning.rb
+++ b/app/models/referential_cloning.rb
@@ -54,7 +54,7 @@ class ReferentialCloning < ApplicationModel
end
def dump_command
- "PGPASSWORD=#{password} pg_dump --host #{host} --username #{username} --schema=#{source_schema} #{database}"
+ "PGPASSWORD='#{password}' pg_dump --host #{host} --username #{username} --schema=#{source_schema} #{database}"
end
def sed_command
@@ -62,7 +62,7 @@ class ReferentialCloning < ApplicationModel
end
def restore_command
- "PGPASSWORD=#{password} psql -q --host #{host} --username #{username} #{database}"
+ "PGPASSWORD='#{password}' psql -q --host #{host} --username #{username} #{database}"
end
def clean
diff --git a/app/policies/referential_policy.rb b/app/policies/referential_policy.rb
index 14f81cf5c..4b8b40b36 100644
--- a/app/policies/referential_policy.rb
+++ b/app/policies/referential_policy.rb
@@ -34,7 +34,7 @@ class ReferentialPolicy < ApplicationPolicy
end
def unarchive?
- !referential_read_only? && record.archived? && !record.merged? && organisation_match? && user.has_permission?('referentials.update')
+ record.ready? && record.archived? && !record.merged? && organisation_match? && user.has_permission?('referentials.update')
end
def common_lines?
diff --git a/app/views/workbenches/show.html.slim b/app/views/workbenches/show.html.slim
index b0276c5ce..213c9e5f2 100644
--- a/app/views/workbenches/show.html.slim
+++ b/app/views/workbenches/show.html.slim
@@ -62,7 +62,10 @@
attribute: Proc.new {|w| w.merged_at ? l(w.merged_at, format: :short) : '-'} \
) \
],
- selectable: ->(ref){ @workbench.referentials.include?(ref) },
+ selectable: ->(ref) { \
+ @workbench.referentials.include?(ref) && \
+ !ref.pending? \
+ },
cls: 'table has-filter has-search',
action: :index
diff --git a/db/migrate/20180502075142_revert_routing_constraint_zones_stop_ids_type.rb b/db/migrate/20180502075142_revert_routing_constraint_zones_stop_ids_type.rb
new file mode 100644
index 000000000..e5213a520
--- /dev/null
+++ b/db/migrate/20180502075142_revert_routing_constraint_zones_stop_ids_type.rb
@@ -0,0 +1,8 @@
+class RevertRoutingConstraintZonesStopIdsType < ActiveRecord::Migration
+ def change
+ reversible do |dir|
+ dir.up { change_column :routing_constraint_zones, :stop_point_ids, :bigint, array: true }
+ dir.down { change_column :routing_constraint_zones, :stop_point_ids, :integer, array: true }
+ end
+ end
+end
diff --git a/spec/controllers/referentials_controller_spec.rb b/spec/controllers/referentials_controller_spec.rb
index acab3abd9..8edd8699f 100644
--- a/spec/controllers/referentials_controller_spec.rb
+++ b/spec/controllers/referentials_controller_spec.rb
@@ -119,6 +119,7 @@ describe ReferentialsController, :type => :controller do
it "creates the new referential" do
expect{request}.to change{Referential.count}.by 1
expect(Referential.last.name).to eq "Duplicated"
+ expect(Referential.last.state).to eq :pending
end
it "displays a flash message" do
diff --git a/spec/features/workbenches/workbenches_show_spec.rb b/spec/features/workbenches/workbenches_show_spec.rb
index 441f829a1..427b526cf 100644
--- a/spec/features/workbenches/workbenches_show_spec.rb
+++ b/spec/features/workbenches/workbenches_show_spec.rb
@@ -64,6 +64,27 @@ RSpec.describe 'Workbenches', type: :feature do
"Couldn't find `hidden_referential`: `#{hidden_referential.inspect}`"
end
+ it "prevents pending referentials from being selected" do
+ line = create(:line, line_referential: line_ref)
+ metadata = create(:referential_metadata, lines: [line])
+ pending_referential = create(
+ :workbench_referential,
+ workbench: workbench,
+ metadatas: [metadata],
+ organisation: @user.organisation,
+ ready: false
+ )
+
+ visit workbench_path(workbench)
+
+ expect(
+ find("input[type='checkbox'][value='#{referential.id}']")
+ ).not_to be_disabled
+ expect(
+ find("input[type='checkbox'][value='#{pending_referential.id}']")
+ ).to be_disabled
+ end
+
context 'filtering' do
let!(:another_organisation) { create :organisation }
let(:another_line) { create :line, line_referential: line_ref }
diff --git a/spec/models/chouette/vehicle_journey_spec.rb b/spec/models/chouette/vehicle_journey_spec.rb
index e1cbb57cb..0fc75bec9 100644
--- a/spec/models/chouette/vehicle_journey_spec.rb
+++ b/spec/models/chouette/vehicle_journey_spec.rb
@@ -923,7 +923,7 @@ describe Chouette::VehicleJourney, :type => :model do
"2000-01-01 #{new_time.hour}:#{new_time.min}:#{new_time.sec} UTC".to_time
end
- describe "#fill_passing_time_at_borders" do
+ describe "#fill_passing_times!" do
before do
start = create :stop_area
border = create :stop_area, kind: :non_commercial, area_type: :border
@@ -952,7 +952,7 @@ describe Chouette::VehicleJourney, :type => :model do
@journey = create :vehicle_journey, journey_pattern: journey_pattern
@journey.vehicle_journey_at_stops.destroy_all
departure_time = Time.now.noon
- @start = create :vehicle_journey_at_stop, stop_point: start_point, vehicle_journey: @journey, departure_time: departure_time
+ @start = create :vehicle_journey_at_stop, stop_point: start_point, vehicle_journey: @journey, departure_time: departure_time, arrival_time: departure_time
@target = create :vehicle_journey_at_stop, stop_point: border_point, vehicle_journey: @journey, arrival_time: nil, departure_time: nil
@target_2 = create :vehicle_journey_at_stop, stop_point: border_point_2, vehicle_journey: @journey, arrival_time: nil, departure_time: nil
@middle = create :vehicle_journey_at_stop, stop_point: middle_point, vehicle_journey: @journey, arrival_time: @start.arrival_time + 4.hours, departure_time: @start.departure_time + 4.hours
@@ -962,7 +962,7 @@ describe Chouette::VehicleJourney, :type => :model do
end
it "should compute passing time" do
- @journey.reload.fill_passing_time_at_borders
+ @journey.reload.fill_passing_times!
expect(@target.reload.arrival_time.to_i).to eq offset_passing_time(@start.reload.departure_time, 1.0/3 * (@middle.reload.arrival_time - @start.departure_time)).to_i
expect(@target_2.reload.arrival_time).to eq @target.arrival_time
expect(@target.departure_time).to eq @target.arrival_time
@@ -979,7 +979,7 @@ describe Chouette::VehicleJourney, :type => :model do
end
it "should compute passing time" do
- @journey.reload.fill_passing_time_at_borders
+ @journey.reload.fill_passing_times!
expect(@target.reload.arrival_time.to_i).to eq offset_passing_time(@start.reload.departure_time, 1.0/3 * (@middle.reload.arrival_time - @start.departure_time)).to_i
expect(@target_2.reload.arrival_time).to eq @target.arrival_time
expect(@target.departure_time).to eq @target.arrival_time
diff --git a/spec/models/referential/referential_oid_format_from_wkbch_spec.rb b/spec/models/referential/referential_oid_format_from_wkbch_spec.rb
index 6783ab55d..a693e80c9 100644
--- a/spec/models/referential/referential_oid_format_from_wkbch_spec.rb
+++ b/spec/models/referential/referential_oid_format_from_wkbch_spec.rb
@@ -58,7 +58,8 @@ RSpec.describe Referential do
stop_area_referential: source.stop_area_referential,
created_from: source,
objectid_format: source.objectid_format,
- metadatas: source.metadatas.map { |m| ReferentialMetadata.new_from(m, functional_scope) })
+ metadatas: source.metadatas.map { |m| ReferentialMetadata.new_from(m, functional_scope) },
+ ready: false)
described_class.new_from( source, functional_scope )
end
diff --git a/spec/models/referential_spec.rb b/spec/models/referential_spec.rb
index eb9c2e338..720cec48c 100644
--- a/spec/models/referential_spec.rb
+++ b/spec/models/referential_spec.rb
@@ -203,6 +203,7 @@ describe Referential, :type => :model do
it 'should create a Referential' do
ref
expect { saved_clone }.to change{Referential.count}.by(1)
+ expect(saved_clone.state).to eq :pending
end
xit 'should create a ReferentialCloning' do
diff --git a/spec/support/pundit/shared_examples.rb b/spec/support/pundit/shared_examples.rb
index 8592ef29f..0ac1d3503 100644
--- a/spec/support/pundit/shared_examples.rb
+++ b/spec/support/pundit/shared_examples.rb
@@ -111,10 +111,8 @@ RSpec.shared_examples 'permitted policy and same organisation' do
if archived_and_finalised
it 'removes the permission for archived referentials' do
user.organisation_id = referential.organisation_id
- record.archived_at = 42.seconds.ago
- record.ready = true
- expect(record).to be_archived
- expect(record).to be_referential_read_only
+ referential.archived_at = 42.seconds.ago
+ referential.ready = true
expect_it.not_to permit(user_context, record)
end