diff options
| author | Xinhui | 2017-07-12 14:27:17 +0200 |
|---|---|---|
| committer | Xinhui | 2017-07-13 17:33:21 +0200 |
| commit | be8c8c2b9d04175977b216a04ec03a2d8c52fbaf (patch) | |
| tree | 2e75225f10b524f4fac27418eb01a737ddc49ac5 | |
| parent | f446e30a4cbee93d7472ea3663e20d6553853cab (diff) | |
| download | chouette-core-be8c8c2b9d04175977b216a04ec03a2d8c52fbaf.tar.bz2 | |
RoutingConstraintZone implementation of checksum concerns
| -rw-r--r-- | app/models/chouette/routing_constraint_zone.rb | 6 | ||||
| -rw-r--r-- | spec/models/chouette/footnote_spec.rb | 2 | ||||
| -rw-r--r-- | spec/models/chouette/routing_constraint_zone_spec.rb | 4 | ||||
| -rw-r--r-- | spec/models/chouette/vehicle_journey_at_stop_spec.rb | 2 |
4 files changed, 12 insertions, 2 deletions
diff --git a/app/models/chouette/routing_constraint_zone.rb b/app/models/chouette/routing_constraint_zone.rb index 77f51c466..b4c27803b 100644 --- a/app/models/chouette/routing_constraint_zone.rb +++ b/app/models/chouette/routing_constraint_zone.rb @@ -1,4 +1,6 @@ class Chouette::RoutingConstraintZone < Chouette::TridentActiveRecord + include ChecksumSupport + belongs_to :route has_array_of :stop_points, class_name: 'Chouette::StopPoint' @@ -6,6 +8,10 @@ class Chouette::RoutingConstraintZone < Chouette::TridentActiveRecord validates :stop_point_ids, length: { minimum: 2, too_short: I18n.t('activerecord.errors.models.routing_constraint_zone.attributes.stop_points.not_enough_stop_points') } validate :stop_points_belong_to_route, :not_all_stop_points_selected + def checksum_attributes + self.stop_points.map(&:stop_area).map(&:user_objectid) + end + def stop_points_belong_to_route errors.add(:stop_point_ids, I18n.t('activerecord.errors.models.routing_constraint_zone.attributes.stop_points.stop_points_not_from_route')) unless stop_points.all? { |sp| route.stop_points.include? sp } end diff --git a/spec/models/chouette/footnote_spec.rb b/spec/models/chouette/footnote_spec.rb index bf1018593..98d751499 100644 --- a/spec/models/chouette/footnote_spec.rb +++ b/spec/models/chouette/footnote_spec.rb @@ -5,7 +5,7 @@ describe Chouette::Footnote, type: :model do it { should validate_presence_of :line } - context 'checksum' do + describe 'checksum' do it_behaves_like 'checksum support', :footnote context '#checksum_attributes' do diff --git a/spec/models/chouette/routing_constraint_zone_spec.rb b/spec/models/chouette/routing_constraint_zone_spec.rb index 87ee9e9ac..22947f4f6 100644 --- a/spec/models/chouette/routing_constraint_zone_spec.rb +++ b/spec/models/chouette/routing_constraint_zone_spec.rb @@ -9,6 +9,10 @@ describe Chouette::RoutingConstraintZone, type: :model do # shoulda matcher to validate length of array ? xit { is_expected.to validate_length_of(:stop_point_ids).is_at_least(2) } + describe 'checksum' do + it_behaves_like 'checksum support', :routing_constraint_zone + end + describe 'validations' do it 'validates the presence of route_id' do expect { diff --git a/spec/models/chouette/vehicle_journey_at_stop_spec.rb b/spec/models/chouette/vehicle_journey_at_stop_spec.rb index e6c6542f0..3094005f7 100644 --- a/spec/models/chouette/vehicle_journey_at_stop_spec.rb +++ b/spec/models/chouette/vehicle_journey_at_stop_spec.rb @@ -3,7 +3,7 @@ require 'rails_helper' RSpec.describe Chouette::VehicleJourneyAtStop, type: :model do let(:subject) { create(:vehicle_journey_at_stop) } - context 'checksum' do + describe 'checksum' do it_behaves_like 'checksum support', :vehicle_journey_at_stop context '#checksum_attributes' do |
