aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorcedricnjanga2018-03-07 07:42:56 -0800
committerJohan Van Ryseghem2018-03-29 11:28:28 +0200
commit501ac1902cfa3f9163cbabbb9bca66ac22a059b8 (patch)
treef8f29f1b83aafb834191d27d89f4203a8ecb07a3
parentdca8f770251cae1fda3a1bca1d06210f8e55ddcf (diff)
downloadchouette-core-501ac1902cfa3f9163cbabbb9bca66ac22a059b8.tar.bz2
Refs #6075 Set defaults attributes for stop point depending on stop area kind
-rw-r--r--app/javascript/packs/routes/edit.js4
-rw-r--r--app/models/chouette/stop_point.rb11
-rw-r--r--spec/models/chouette/route/route_stop_points_spec.rb19
3 files changed, 31 insertions, 3 deletions
diff --git a/app/javascript/packs/routes/edit.js b/app/javascript/packs/routes/edit.js
index b787bec97..81745ad23 100644
--- a/app/javascript/packs/routes/edit.js
+++ b/app/javascript/packs/routes/edit.js
@@ -39,8 +39,8 @@ const getInitialState = () => {
name: v.name ? v.name.replace("'", "\'") : '',
registration_number: v.registration_number,
text: fancyText,
- for_boarding: v.for_boarding || "normal",
- for_alighting: v.for_alighting || "normal",
+ for_boarding: v.for_boarding,
+ for_alighting: v.for_alighting,
longitude: v.longitude || 0,
latitude: v.latitude || 0,
comment: v.comment ? v.comment.replace("'", "\'") : '',
diff --git a/app/models/chouette/stop_point.rb b/app/models/chouette/stop_point.rb
index 6b363cd93..8d341c435 100644
--- a/app/models/chouette/stop_point.rb
+++ b/app/models/chouette/stop_point.rb
@@ -30,6 +30,17 @@ module Chouette
delegate :name, to: :stop_area
+ after_commit :set_defaults
+ def set_defaults
+ if stop_area.kind == 'commercial'
+ update_attribute :for_boarding, 'normal'
+ update_attribute :for_alighting, 'normal'
+ else
+ update_attribute :for_boarding, 'forbidden'
+ update_attribute :for_alighting, 'forbidden'
+ end
+ end
+
before_destroy :remove_dependent_journey_pattern_stop_points
def remove_dependent_journey_pattern_stop_points
route.journey_patterns.each do |jp|
diff --git a/spec/models/chouette/route/route_stop_points_spec.rb b/spec/models/chouette/route/route_stop_points_spec.rb
index 03c53b4cf..037c22f7e 100644
--- a/spec/models/chouette/route/route_stop_points_spec.rb
+++ b/spec/models/chouette/route/route_stop_points_spec.rb
@@ -78,15 +78,32 @@ RSpec.describe Chouette::Route, :type => :model do
end
describe "#stop_points" do
+ let(:first_stop_point) { subject.stop_points.first}
context "#find_by_stop_area" do
context "when arg is first quay id" do
- let(:first_stop_point) { subject.stop_points.first}
it "should return first quay" do
expect(subject.stop_points.find_by_stop_area( first_stop_point.stop_area_id)).to eq( first_stop_point)
end
end
end
+
+ context 'defaults attributes' do
+ it 'should have the correct default attributes' do
+ first_stop_point.stop_area.update_attributes(kind: 'non_commercial')
+ subject.stop_points.each do |sp|
+ sp.run_callbacks(:commit)
+ if sp.stop_area.commercial?
+ expect(sp.for_boarding).to eq('normal')
+ expect(sp.for_alighting).to eq('normal')
+ else
+ expect(sp.for_boarding).to eq('forbidden')
+ expect(sp.for_alighting).to eq('forbidden')
+ end
+ end
+ end
+ end
end
+
describe "#stop_areas" do
let(:line){ create(:line)}
let(:route_1){ create(:route, :line => line)}