diff options
| author | cedricnjanga | 2018-03-11 21:34:42 -0700 | 
|---|---|---|
| committer | Johan Van Ryseghem | 2018-03-29 11:28:28 +0200 | 
| commit | 23318bbe07b73cef50ec69d5e597386a116e2b82 (patch) | |
| tree | 9f5a8c6d5338a9efeb19903b17f43ef9a38cc190 | |
| parent | 501ac1902cfa3f9163cbabbb9bca66ac22a059b8 (diff) | |
| download | chouette-core-23318bbe07b73cef50ec69d5e597386a116e2b82.tar.bz2 | |
Refs #6075 Replace after_commit callback to after_create for the set_defaults method
| -rw-r--r-- | app/models/chouette/stop_point.rb | 12 | ||||
| -rw-r--r-- | spec/models/chouette/route/route_stop_points_spec.rb | 6 | 
2 files changed, 8 insertions, 10 deletions
| diff --git a/app/models/chouette/stop_point.rb b/app/models/chouette/stop_point.rb index 8d341c435..42a207774 100644 --- a/app/models/chouette/stop_point.rb +++ b/app/models/chouette/stop_point.rb @@ -30,15 +30,11 @@ module Chouette      delegate :name, to: :stop_area -    after_commit :set_defaults +    after_create :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 +      value = stop_area.kind == 'commercial' ? 'normal' : 'forbidden' +      update_attribute :for_boarding, value +      update_attribute :for_alighting, value      end      before_destroy :remove_dependent_journey_pattern_stop_points diff --git a/spec/models/chouette/route/route_stop_points_spec.rb b/spec/models/chouette/route/route_stop_points_spec.rb index 037c22f7e..f8edadfee 100644 --- a/spec/models/chouette/route/route_stop_points_spec.rb +++ b/spec/models/chouette/route/route_stop_points_spec.rb @@ -88,10 +88,12 @@ RSpec.describe Chouette::Route, :type => :model do      end      context 'defaults attributes' do +      let(:new_stop_area) { create :stop_area, kind: 'non_commercial', area_type: 'deposit' } +      let(:new_stop_point) { create :stop_point, stop_area_id: new_stop_area.id }        it 'should have the correct default attributes' do -        first_stop_point.stop_area.update_attributes(kind: 'non_commercial') +        subject.stop_points << new_stop_point          subject.stop_points.each do |sp| -          sp.run_callbacks(:commit) +          # binding.pry            if sp.stop_area.commercial?              expect(sp.for_boarding).to eq('normal')              expect(sp.for_alighting).to eq('normal') | 
