diff options
| -rw-r--r-- | app/javascript/packs/routes/edit.js | 4 | ||||
| -rw-r--r-- | app/models/chouette/stop_point.rb | 11 | ||||
| -rw-r--r-- | spec/models/chouette/route/route_stop_points_spec.rb | 19 |
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)} |
