diff options
| author | Luc Donnet | 2017-10-02 23:17:15 +0200 | 
|---|---|---|
| committer | GitHub | 2017-10-02 23:17:15 +0200 | 
| commit | 6ba2b9f05961a33a6936d32e4c28d70149b48342 (patch) | |
| tree | 457ebbf41a48873eb80cf4105bd993e69c8d711d | |
| parent | cba31dc411ceb47f80202c1d3a32a2e031630b13 (diff) | |
| parent | 88567b111cf172e7b4368ffc02cb1e5cf27b4231 (diff) | |
| download | chouette-core-6ba2b9f05961a33a6936d32e4c28d70149b48342.tar.bz2 | |
Merge pull request #82 from af83/4627-compliance-fix-class-vars
4627 compliance fix class vars
67 files changed, 581 insertions, 99 deletions
| diff --git a/app/models/compliance_control.rb b/app/models/compliance_control.rb index 42f45b6ca..0860f07b6 100644 --- a/app/models/compliance_control.rb +++ b/app/models/compliance_control.rb @@ -3,9 +3,6 @@ class ComplianceControl < ActiveRecord::Base    belongs_to :compliance_control_set    belongs_to :compliance_control_block -  @@default_criticity = :warning -  @@default_code = "" -    enumerize :criticity, in: %i(info warning error), scope: true, default: :info    validates :criticity, presence: true @@ -14,24 +11,28 @@ class ComplianceControl < ActiveRecord::Base    validates :origin_code, presence: true    validates :compliance_control_set, presence: true -  def self.policy_class -    ComplianceControlPolicy -  end +  class << self +    def default_criticity; :warning end +    def default_code; "" end + +    def policy_class +      ComplianceControlPolicy +    end -  def self.inherited(child) -    child.instance_eval do -      def model_name -        ComplianceControl.model_name +    def inherited(child) +      child.instance_eval do +        def model_name +          ComplianceControl.model_name +        end        end +      super      end -    super    end    before_validation(on: :create) do     self.name ||= self.class.name -   self.code ||= @@default_code -   self.origin_code ||= @@default_code -   self.criticity ||= @@default_criticity +   self.code ||= self.class.default_code +   self.origin_code ||= self.class.default_code    end  end diff --git a/app/models/generic_attribute_control/min_max.rb b/app/models/generic_attribute_control/min_max.rb index 6a2e1f284..0b0e5a9a7 100644 --- a/app/models/generic_attribute_control/min_max.rb +++ b/app/models/generic_attribute_control/min_max.rb @@ -2,16 +2,18 @@ module GenericAttributeControl    class MinMax < ComplianceControl      hstore_accessor :control_attributes, minimum: :integer, maximum: :integer -    @@default_criticity = :warning -    @@default_code = "3-Generic-2"      validate :min_max_values      def min_max_values        true      end -    def self.dynamic_attributes -      self.hstore_metadata_for_control_attributes.keys +    class << self +      def default_criticity; :warning end +      def default_code; "3-Generic-2" end +      def dynamic_attributes +        hstore_metadata_for_control_attributes.keys +      end      end    end  end diff --git a/app/models/generic_attribute_control/pattern.rb b/app/models/generic_attribute_control/pattern.rb index 5b27da54e..72bb1770a 100644 --- a/app/models/generic_attribute_control/pattern.rb +++ b/app/models/generic_attribute_control/pattern.rb @@ -2,12 +2,14 @@ module GenericAttributeControl    class Pattern < ComplianceControl      hstore_accessor :control_attributes, value: :string, pattern: :string -    @@default_criticity = :warning -    @@default_code = "3-Generic-3" -      validate :pattern_match      def pattern_match        true      end + +    class << self +      def default_criticity; :warning end +      def default_code; "3-Generic-3" end +    end    end -end
\ No newline at end of file +end diff --git a/app/models/generic_attribute_control/uniqueness.rb b/app/models/generic_attribute_control/uniqueness.rb index 4f1a82083..6ffe78565 100644 --- a/app/models/generic_attribute_control/uniqueness.rb +++ b/app/models/generic_attribute_control/uniqueness.rb @@ -2,12 +2,14 @@ module GenericAttributeControl    class Uniqueness < ComplianceControl      hstore_accessor :control_attributes, name: :string -    @@default_criticity = :warning -    @@default_code = "3-Generic-3" -      validate :unique_values      def unique_values        true      end + +    class << self +      def default_criticity; :warning end +      def default_code; "3-Generic-3" end +    end    end -end
\ No newline at end of file +end diff --git a/app/models/journey_pattern_control/duplicates.rb b/app/models/journey_pattern_control/duplicates.rb index d3908cfc0..e06e6021b 100644 --- a/app/models/journey_pattern_control/duplicates.rb +++ b/app/models/journey_pattern_control/duplicates.rb @@ -1,7 +1,6 @@  module JourneyPatternControl    class Duplicates < ComplianceControl -    @@default_criticity = :warning -    @@default_code = "3-JourneyPattern-1" +    def self.default_code; "3-JourneyPattern-1" end    end  end diff --git a/app/models/journey_pattern_control/vehicle_journey.rb b/app/models/journey_pattern_control/vehicle_journey.rb index d7151f147..dfaf42beb 100644 --- a/app/models/journey_pattern_control/vehicle_journey.rb +++ b/app/models/journey_pattern_control/vehicle_journey.rb @@ -1,7 +1,6 @@  module JourneyPatternControl    class VehicleJourney < ComplianceControl -    @@default_criticity = :warning -    @@default_code = "3-JourneyPattern-2" +    def self.default_code; "3-JourneyPattern-2" end    end -end
\ No newline at end of file +end diff --git a/app/models/line_control/route.rb b/app/models/line_control/route.rb index 21c5eca06..aabd2f347 100644 --- a/app/models/line_control/route.rb +++ b/app/models/line_control/route.rb @@ -1,7 +1,6 @@  module LineControl    class Route < ComplianceControl -    @@default_criticity = :warning -    @@default_code = "3-Line-1" +    def self.default_code; "3-Line-1" end    end -end
\ No newline at end of file +end diff --git a/app/models/route_control/duplicates.rb b/app/models/route_control/duplicates.rb index fb9c34e0a..99e3b3aa8 100644 --- a/app/models/route_control/duplicates.rb +++ b/app/models/route_control/duplicates.rb @@ -1,7 +1,6 @@  module RouteControl    class Duplicates < ComplianceControl -    @@default_criticity = :warning -    @@default_code = "3-Route-4" +    def self.default_code; "3-Route-4" end    end  end diff --git a/app/models/route_control/journey_pattern.rb b/app/models/route_control/journey_pattern.rb index 08f603d8f..63cec2a41 100644 --- a/app/models/route_control/journey_pattern.rb +++ b/app/models/route_control/journey_pattern.rb @@ -1,7 +1,6 @@  module RouteControl    class JourneyPattern < ComplianceControl -    @@default_criticity = :warning -    @@default_code = "3-Route-3" +    def self.default_code; "3-Route-3" end    end -end
\ No newline at end of file +end diff --git a/app/models/route_control/minimum_length.rb b/app/models/route_control/minimum_length.rb index f42b88748..56becfb2b 100644 --- a/app/models/route_control/minimum_length.rb +++ b/app/models/route_control/minimum_length.rb @@ -1,7 +1,6 @@  module RouteControl    class MinimumLength < ComplianceControl -    @@default_criticity = :error -    @@default_code = "3-Route-6" +    def self.default_code; "3-Route-6" end    end  end diff --git a/app/models/route_control/omnibus_journey_pattern.rb b/app/models/route_control/omnibus_journey_pattern.rb index 3b9f6d06f..af3004ad7 100644 --- a/app/models/route_control/omnibus_journey_pattern.rb +++ b/app/models/route_control/omnibus_journey_pattern.rb @@ -1,7 +1,6 @@  module RouteControl    class OmnibusJourneyPattern < ComplianceControl -    @@default_criticity = :warning -    @@default_code = "3-Route-9" +    def self.default_code; "3-Route-9" end    end  end diff --git a/app/models/route_control/opposite_route.rb b/app/models/route_control/opposite_route.rb index e91b081e2..0148087ca 100644 --- a/app/models/route_control/opposite_route.rb +++ b/app/models/route_control/opposite_route.rb @@ -1,7 +1,6 @@  module RouteControl    class OppositeRoute < ComplianceControl -    @@default_criticity = :error -    @@default_code = "3-Route-2" +    def self.default_code; "3-Route-2" end    end  end diff --git a/app/models/route_control/opposite_route_terminus.rb b/app/models/route_control/opposite_route_terminus.rb index fd62b7684..e12690d48 100644 --- a/app/models/route_control/opposite_route_terminus.rb +++ b/app/models/route_control/opposite_route_terminus.rb @@ -1,7 +1,6 @@  module RouteControl    class OppositeRouteTerminus < ComplianceControl -    @@default_criticity = :warning -    @@default_code = "3-Route-5" +    def self.default_code; "3-Route-5" end    end -end
\ No newline at end of file +end diff --git a/app/models/route_control/speed.rb b/app/models/route_control/speed.rb index 0a2b6ac76..d5798d153 100644 --- a/app/models/route_control/speed.rb +++ b/app/models/route_control/speed.rb @@ -1,9 +1,8 @@ -module VehicleJourneyControl +module RouteControl    class Speed < ComplianceControl      hstore_accessor :control_attributes, minimum: :integer, maximum: :integer -    @@default_criticity = :warning -    @@default_code = "3-VehicleJourney-2" +    def self.default_code; "3-VehicleJourney-2" end    end  end diff --git a/app/models/route_control/stop_points_in_journey_pattern.rb b/app/models/route_control/stop_points_in_journey_pattern.rb index dced6c005..400bef5ef 100644 --- a/app/models/route_control/stop_points_in_journey_pattern.rb +++ b/app/models/route_control/stop_points_in_journey_pattern.rb @@ -1,7 +1,6 @@  module RouteControl -  class StopPointInJourneyPattern < ComplianceControl +  class StopPointsInJourneyPattern < ComplianceControl -    @@default_criticity = :error -    @@default_code = "3-Route-6" +    def self.default_code; "3-Route-6" end    end  end diff --git a/app/models/route_control/time_table.rb b/app/models/route_control/time_table.rb index 5d0f21b40..069cd0a9e 100644 --- a/app/models/route_control/time_table.rb +++ b/app/models/route_control/time_table.rb @@ -1,7 +1,6 @@ -module VehicleJourneyControl +module RouteControl    class TimeTable < ComplianceControl -    @@default_criticity = :error -    @@default_code = "3-VehicleJourney-4" +    def self.default_code; "3-VehicleJourney-4" end    end  end diff --git a/app/models/route_control/unactivated_stop_points.rb b/app/models/route_control/unactivated_stop_points.rb index dee846cbb..a903fff53 100644 --- a/app/models/route_control/unactivated_stop_points.rb +++ b/app/models/route_control/unactivated_stop_points.rb @@ -1,7 +1,6 @@  module RouteControl -  class UnactivatedStopPoint < ComplianceControl +  class UnactivatedStopPoints < ComplianceControl -    @@default_criticity = :warning -    @@default_code = "3-Route-10" +    def self.default_code; "3-Route-10" end    end  end diff --git a/app/models/route_control/vehicle_journey_at_stops.rb b/app/models/route_control/vehicle_journey_at_stops.rb index 149282fe6..7c376a2da 100644 --- a/app/models/route_control/vehicle_journey_at_stops.rb +++ b/app/models/route_control/vehicle_journey_at_stops.rb @@ -1,7 +1,6 @@ -module VehicleJourneyControl +module RouteControl    class VehicleJourneyAtStops < ComplianceControl -    @@default_criticity = :error -    @@default_code = "3-VehicleJourney-5" +    def self.default_code; "3-VehicleJourney-5" end    end  end diff --git a/app/models/route_control/zdl_stop_area.rb b/app/models/route_control/zdl_stop_area.rb index 088a1d2f2..2efd892df 100644 --- a/app/models/route_control/zdl_stop_area.rb +++ b/app/models/route_control/zdl_stop_area.rb @@ -1,7 +1,6 @@  module RouteControl    class ZDLStopArea < ComplianceControl -    @@default_criticity = :warning -    @@default_code = "3-Route-1" +    def self.default_code; "3-Route-1" end    end  end diff --git a/app/models/routing_constaint_zone_control/maximum_length.rb b/app/models/routing_constaint_zone_control/maximum_length.rb deleted file mode 100644 index 4d289de63..000000000 --- a/app/models/routing_constaint_zone_control/maximum_length.rb +++ /dev/null @@ -1,7 +0,0 @@ -module RoutingConstaintZoneControl -  class MaximumLength < ComplianceControl - -    @@default_criticity = :warning -    @@default_code = "3-ITL-2" -  end -end
\ No newline at end of file diff --git a/app/models/routing_constaint_zone_control/minimum_length.rb b/app/models/routing_constaint_zone_control/minimum_length.rb deleted file mode 100644 index 28f0791a7..000000000 --- a/app/models/routing_constaint_zone_control/minimum_length.rb +++ /dev/null @@ -1,7 +0,0 @@ -module RoutingConstaintZoneControl -  class MinimumLength < ComplianceControl - -    @@default_criticity = :warning -    @@default_code = "3-ITL-3" -  end -end
\ No newline at end of file diff --git a/app/models/routing_constaint_zone_control/unactivated_stop_point.rb b/app/models/routing_constaint_zone_control/unactivated_stop_point.rb deleted file mode 100644 index fe5381a34..000000000 --- a/app/models/routing_constaint_zone_control/unactivated_stop_point.rb +++ /dev/null @@ -1,7 +0,0 @@ -module RoutingConstaintZoneControl -  class UnactivatedStopPoint < ComplianceControl - -    @@default_criticity = :warning -    @@default_code = "3-ITL-1" -  end -end diff --git a/app/models/routing_constraint_zone_control/maximum_length.rb b/app/models/routing_constraint_zone_control/maximum_length.rb new file mode 100644 index 000000000..6b726e38c --- /dev/null +++ b/app/models/routing_constraint_zone_control/maximum_length.rb @@ -0,0 +1,6 @@ +module RoutingConstraintZoneControl +  class MaximumLength < ComplianceControl + +    def self.default_code; "3-ITL-2" end +  end +end diff --git a/app/models/routing_constraint_zone_control/minimum_length.rb b/app/models/routing_constraint_zone_control/minimum_length.rb new file mode 100644 index 000000000..38f583bc5 --- /dev/null +++ b/app/models/routing_constraint_zone_control/minimum_length.rb @@ -0,0 +1,6 @@ +module RoutingConstraintZoneControl +  class MinimumLength < ComplianceControl + +    def self.default_code; "3-ITL-3" end +  end +end diff --git a/app/models/routing_constraint_zone_control/unactivated_stop_point.rb b/app/models/routing_constraint_zone_control/unactivated_stop_point.rb new file mode 100644 index 000000000..c03bb2324 --- /dev/null +++ b/app/models/routing_constraint_zone_control/unactivated_stop_point.rb @@ -0,0 +1,6 @@ +module RoutingConstraintZoneControl +  class UnactivatedStopPoint < ComplianceControl + +    def self.default_code; "3-ITL-1" end +  end +end diff --git a/app/models/vechicle_journey_control/waiting_time.rb b/app/models/vechicle_journey_control/waiting_time.rb deleted file mode 100644 index cbffa5526..000000000 --- a/app/models/vechicle_journey_control/waiting_time.rb +++ /dev/null @@ -1,7 +0,0 @@ -module VehicleJourneyControl -  class WatingTime < ComplianceControl - -    @@default_criticity = :warning -    @@default_code = "3-VehicleJourney-1" -  end -end diff --git a/app/models/vechicle_journey_control/delta.rb b/app/models/vehicle_journey_control/delta.rb index d77eff48a..797072fdd 100644 --- a/app/models/vechicle_journey_control/delta.rb +++ b/app/models/vehicle_journey_control/delta.rb @@ -3,7 +3,6 @@ module VehicleJourneyControl      hstore_accessor :control_attributes, delta: :integer -    @@default_criticity = :warning -    @@default_code = "3-VehicleJourney-3" +    def self.default_code; "3-VehicleJourney-3" end    end  end diff --git a/app/models/vehicle_journey_control/waiting_time.rb b/app/models/vehicle_journey_control/waiting_time.rb new file mode 100644 index 000000000..614f401bb --- /dev/null +++ b/app/models/vehicle_journey_control/waiting_time.rb @@ -0,0 +1,6 @@ +module VehicleJourneyControl +  class WaitingTime < ComplianceControl + +    def self.default_code; "3-VehicleJourney-1" end +  end +end diff --git a/spec/controllers/compliance_controls_controller_spec.rb b/spec/controllers/compliance_controls_controller_spec.rb index e866b037c..e12a75381 100644 --- a/spec/controllers/compliance_controls_controller_spec.rb +++ b/spec/controllers/compliance_controls_controller_spec.rb @@ -1,5 +1,3 @@ -require 'rails_helper' -  RSpec.describe ComplianceControlsController, type: :controller do    login_user diff --git a/spec/factories/compliance_controls/generic_factories.rb b/spec/factories/compliance_controls/generic_factories.rb new file mode 100644 index 000000000..2c961a654 --- /dev/null +++ b/spec/factories/compliance_controls/generic_factories.rb @@ -0,0 +1,20 @@ + +FactoryGirl.define do +  factory :generic_attribute_control_min_max, class: 'GenericAttributeControl::MinMax' do +    sequence(:name) { |n| "MinMax control #{n}" } +    association :compliance_control_set +    association :compliance_control_block +  end + +  factory :generic_attribute_control_pattern, class: 'GenericAttributeControl::Pattern' do +    sequence(:name) { |n| "Pattern control #{n}" } +    association :compliance_control_set +    association :compliance_control_block +  end + +  factory :generic_attribute_control_uniqueness, class: 'GenericAttributeControl::Uniqueness' do +    sequence(:name) { |n| "Uniqueness control #{n}" } +    association :compliance_control_set +    association :compliance_control_block +  end +end diff --git a/spec/factories/compliance_controls/journey_pattern_control_factories.rb b/spec/factories/compliance_controls/journey_pattern_control_factories.rb new file mode 100644 index 000000000..f5d1e76e0 --- /dev/null +++ b/spec/factories/compliance_controls/journey_pattern_control_factories.rb @@ -0,0 +1,14 @@ + +FactoryGirl.define do + +  factory :journey_pattern_control_duplicates, class: 'JourneyPatternControl::Duplicates' do +    association :compliance_control_set +    association :compliance_control_block +  end + +  factory :journey_pattern_control_vehicle_journey, class: 'JourneyPatternControl::VehicleJourney' do +    association :compliance_control_set +    association :compliance_control_block +  end + +end diff --git a/spec/factories/compliance_controls/line_control_factories.rb b/spec/factories/compliance_controls/line_control_factories.rb new file mode 100644 index 000000000..3f5422e8c --- /dev/null +++ b/spec/factories/compliance_controls/line_control_factories.rb @@ -0,0 +1,7 @@ +FactoryGirl.define do +  factory :line_control_route, class: 'LineControl::Route' do +    association :compliance_control_set +    association :compliance_control_block +  end + +end diff --git a/spec/factories/compliance_controls/route_control_factories.rb b/spec/factories/compliance_controls/route_control_factories.rb new file mode 100644 index 000000000..786565bac --- /dev/null +++ b/spec/factories/compliance_controls/route_control_factories.rb @@ -0,0 +1,62 @@ +FactoryGirl.define do + +  factory :route_control_duplicates, class: 'RouteControl::Duplicates' do +    association :compliance_control_set +    association :compliance_control_block +  end + +  factory :route_control_journey_pattern, class: 'RouteControl::JourneyPattern' do +    association :compliance_control_set +    association :compliance_control_block +  end + +  factory :route_control_minimum_length, class: 'RouteControl::MinimumLength' do +    association :compliance_control_set +    association :compliance_control_block +  end + +  factory :route_control_omnibus_journey_pattern, class: 'RouteControl::OmnibusJourneyPattern' do +    association :compliance_control_set +    association :compliance_control_block +  end + +  factory :route_control_opposite_route, class: 'RouteControl::OppositeRoute' do +    association :compliance_control_set +    association :compliance_control_block +  end + +  factory :route_control_opposite_route_terminus, class: 'RouteControl::OppositeRouteTerminus' do +    association :compliance_control_set +    association :compliance_control_block +  end + +  factory :route_control_stop_points_in_journey_pattern, class: 'RouteControl::StopPointsInJourneyPattern' do +    association :compliance_control_set +    association :compliance_control_block +  end + +  factory :route_control_unactivated_stop_points, class: 'RouteControl::UnactivatedStopPoints' do +    association :compliance_control_set +    association :compliance_control_block +  end + +  factory :route_control_zdl_stop_area, class: 'RouteControl::ZDLStopArea' do +    association :compliance_control_set +    association :compliance_control_block +  end + +  factory :route_control_speed, class: 'RouteControl::Speed' do +    association :compliance_control_set +    association :compliance_control_block +  end + +  factory :route_control_time_table, class: 'RouteControl::TimeTable' do +    association :compliance_control_set +    association :compliance_control_block +  end + +  factory :route_control_control_vehicle_journey_at_stops, class: 'RouteControl::VehicleJourneyAtStops' do +    association :compliance_control_set +    association :compliance_control_block +  end +end diff --git a/spec/factories/compliance_controls/routing_constraint_zone_control_factories.rb b/spec/factories/compliance_controls/routing_constraint_zone_control_factories.rb new file mode 100644 index 000000000..8855a9d58 --- /dev/null +++ b/spec/factories/compliance_controls/routing_constraint_zone_control_factories.rb @@ -0,0 +1,17 @@ +FactoryGirl.define do +  factory :routing_constraint_zone_control_unactivated_stop_point, +    class: 'routingConstraintZoneControl::UnactivatedStopPoint' do +      association :compliance_control_set +      association :compliance_control_block +  end + +  factory :routing_constraint_zone_control_minimum_length, class: 'routingConstraintZoneControl::MinimumLength' do +    association :compliance_control_set +    association :compliance_control_block +  end + +  factory :routing_constraint_zone_control_maximum_length, class: 'routingConstraintZoneControl::MaximumLength' do +    association :compliance_control_set +    association :compliance_control_block +  end +end diff --git a/spec/factories/compliance_controls/vehicle_journey_control_factories.rb b/spec/factories/compliance_controls/vehicle_journey_control_factories.rb new file mode 100644 index 000000000..72233d9a0 --- /dev/null +++ b/spec/factories/compliance_controls/vehicle_journey_control_factories.rb @@ -0,0 +1,12 @@ +FactoryGirl.define do + +  factory :vehicle_journey_control_wating_time, class: 'VehicleJourneyControl::WaitingTime' do +    association :compliance_control_set +    association :compliance_control_block +  end + +  factory :vehicle_journey_control_delta, class: 'VehicleJourneyControl::Delta' do +    association :compliance_control_set +    association :compliance_control_block +  end +end diff --git a/spec/models/compliance_control_class_level_defaults/generic_attribute_control/min_max_cccld_spec.rb b/spec/models/compliance_control_class_level_defaults/generic_attribute_control/min_max_cccld_spec.rb new file mode 100644 index 000000000..e39e5e4c0 --- /dev/null +++ b/spec/models/compliance_control_class_level_defaults/generic_attribute_control/min_max_cccld_spec.rb @@ -0,0 +1,7 @@ + +RSpec.describe GenericAttributeControl::MinMax, type: :model do +  let( :default_code ){ "3-Generic-2" } +  let( :factory ){ :generic_attribute_control_min_max } + +  it_behaves_like 'ComplianceControl Class Level Defaults'  +end diff --git a/spec/models/compliance_control_class_level_defaults/generic_attribute_control/parent_class_cccld_spec.rb b/spec/models/compliance_control_class_level_defaults/generic_attribute_control/parent_class_cccld_spec.rb new file mode 100644 index 000000000..f9c4373d5 --- /dev/null +++ b/spec/models/compliance_control_class_level_defaults/generic_attribute_control/parent_class_cccld_spec.rb @@ -0,0 +1,7 @@ +RSpec.describe ComplianceControl do +  context 'class attributes' do  +    it 'are correctly set' do +      expect( described_class ).to respond_to(:default_code) +    end +  end +end diff --git a/spec/models/compliance_control_class_level_defaults/generic_attribute_control/pattern_cccld_spec.rb b/spec/models/compliance_control_class_level_defaults/generic_attribute_control/pattern_cccld_spec.rb new file mode 100644 index 000000000..850cd1d76 --- /dev/null +++ b/spec/models/compliance_control_class_level_defaults/generic_attribute_control/pattern_cccld_spec.rb @@ -0,0 +1,7 @@ + +RSpec.describe GenericAttributeControl::Pattern, type: :model do +  let( :default_code ){ "3-Generic-3" } +  let( :factory ){ :generic_attribute_control_pattern } + +  it_behaves_like 'ComplianceControl Class Level Defaults'  +end diff --git a/spec/models/compliance_control_class_level_defaults/generic_attribute_control/uniqueness_cccld_spec.rb b/spec/models/compliance_control_class_level_defaults/generic_attribute_control/uniqueness_cccld_spec.rb new file mode 100644 index 000000000..e4ab8d2cd --- /dev/null +++ b/spec/models/compliance_control_class_level_defaults/generic_attribute_control/uniqueness_cccld_spec.rb @@ -0,0 +1,7 @@ + +RSpec.describe GenericAttributeControl::Uniqueness, type: :model do +  let( :default_code ){ "3-Generic-3" } +  let( :factory ){ :generic_attribute_control_uniqueness } + +  it_behaves_like 'ComplianceControl Class Level Defaults'  +end diff --git a/spec/models/compliance_control_class_level_defaults/journey_pattern_control/duplicates_cccld_spec.rb b/spec/models/compliance_control_class_level_defaults/journey_pattern_control/duplicates_cccld_spec.rb new file mode 100644 index 000000000..89544937b --- /dev/null +++ b/spec/models/compliance_control_class_level_defaults/journey_pattern_control/duplicates_cccld_spec.rb @@ -0,0 +1,7 @@ + +RSpec.describe JourneyPatternControl::Duplicates, type: :model do +  let( :default_code ){ "3-JourneyPattern-1" } +  let( :factory ){ :journey_pattern_control_duplicates } + +  it_behaves_like 'ComplianceControl Class Level Defaults'  +end diff --git a/spec/models/compliance_control_class_level_defaults/journey_pattern_control/vehicle_journey_cccld_spec.rb b/spec/models/compliance_control_class_level_defaults/journey_pattern_control/vehicle_journey_cccld_spec.rb new file mode 100644 index 000000000..fb254ee31 --- /dev/null +++ b/spec/models/compliance_control_class_level_defaults/journey_pattern_control/vehicle_journey_cccld_spec.rb @@ -0,0 +1,7 @@ + +RSpec.describe JourneyPatternControl::VehicleJourney, type: :model do +  let( :default_code ){ "3-JourneyPattern-2" } +  let( :factory ){ :journey_pattern_control_vehicle_journey } + +  it_behaves_like 'ComplianceControl Class Level Defaults'  +end diff --git a/spec/models/compliance_control_class_level_defaults/line_control/route_cccld_spec.rb b/spec/models/compliance_control_class_level_defaults/line_control/route_cccld_spec.rb new file mode 100644 index 000000000..ab5fb1027 --- /dev/null +++ b/spec/models/compliance_control_class_level_defaults/line_control/route_cccld_spec.rb @@ -0,0 +1,7 @@ + +RSpec.describe LineControl::Route, type: :model do +  let( :default_code ){ "3-Line-1" } +  let( :factory ){ :line_control_route } + +  it_behaves_like 'ComplianceControl Class Level Defaults'  +end diff --git a/spec/models/compliance_control_class_level_defaults/route_control/duplicates_cccld_spec.rb b/spec/models/compliance_control_class_level_defaults/route_control/duplicates_cccld_spec.rb new file mode 100644 index 000000000..46531cc3b --- /dev/null +++ b/spec/models/compliance_control_class_level_defaults/route_control/duplicates_cccld_spec.rb @@ -0,0 +1,7 @@ + +RSpec.describe RouteControl::Duplicates, type: :model do +  let( :default_code ){ "3-Route-4" } +  let( :factory ){ :route_control_duplicates } + +  it_behaves_like 'ComplianceControl Class Level Defaults'  +end diff --git a/spec/models/compliance_control_class_level_defaults/route_control/journey_pattern_cccld_spec.rb b/spec/models/compliance_control_class_level_defaults/route_control/journey_pattern_cccld_spec.rb new file mode 100644 index 000000000..2bdd6e591 --- /dev/null +++ b/spec/models/compliance_control_class_level_defaults/route_control/journey_pattern_cccld_spec.rb @@ -0,0 +1,7 @@ + +RSpec.describe RouteControl::JourneyPattern, type: :model do +  let( :default_code ){ "3-Route-3" } +  let( :factory ){ :route_control_journey_pattern } + +  it_behaves_like 'ComplianceControl Class Level Defaults'  +end diff --git a/spec/models/compliance_control_class_level_defaults/route_control/minimum_length_cccld_spec.rb b/spec/models/compliance_control_class_level_defaults/route_control/minimum_length_cccld_spec.rb new file mode 100644 index 000000000..85bab4ac6 --- /dev/null +++ b/spec/models/compliance_control_class_level_defaults/route_control/minimum_length_cccld_spec.rb @@ -0,0 +1,7 @@ + +RSpec.describe RouteControl::MinimumLength, type: :model do +  let( :default_code ){ "3-Route-6" } +  let( :factory ){ :route_control_minimum_length } + +  it_behaves_like 'ComplianceControl Class Level Defaults'  +end diff --git a/spec/models/compliance_control_class_level_defaults/route_control/omnibus_journey_pattern_cccld_spec.rb b/spec/models/compliance_control_class_level_defaults/route_control/omnibus_journey_pattern_cccld_spec.rb new file mode 100644 index 000000000..3fb782e85 --- /dev/null +++ b/spec/models/compliance_control_class_level_defaults/route_control/omnibus_journey_pattern_cccld_spec.rb @@ -0,0 +1,7 @@ + +RSpec.describe RouteControl::OmnibusJourneyPattern, type: :model do +  let( :default_code ){ "3-Route-9" } +  let( :factory ){ :route_control_omnibus_journey_pattern } + +  it_behaves_like 'ComplianceControl Class Level Defaults'  +end diff --git a/spec/models/compliance_control_class_level_defaults/route_control/opposite_route_cccld_spec.rb b/spec/models/compliance_control_class_level_defaults/route_control/opposite_route_cccld_spec.rb new file mode 100644 index 000000000..7013ae269 --- /dev/null +++ b/spec/models/compliance_control_class_level_defaults/route_control/opposite_route_cccld_spec.rb @@ -0,0 +1,7 @@ + +RSpec.describe RouteControl::OppositeRoute, type: :model do +  let( :default_code ){ "3-Route-2" } +  let( :factory ){ :route_control_opposite_route } + +  it_behaves_like 'ComplianceControl Class Level Defaults'  +end diff --git a/spec/models/compliance_control_class_level_defaults/route_control/opposite_route_terminus_cccld_spec.rb b/spec/models/compliance_control_class_level_defaults/route_control/opposite_route_terminus_cccld_spec.rb new file mode 100644 index 000000000..a3a8d290d --- /dev/null +++ b/spec/models/compliance_control_class_level_defaults/route_control/opposite_route_terminus_cccld_spec.rb @@ -0,0 +1,7 @@ + +RSpec.describe RouteControl::OppositeRouteTerminus, type: :model do +  let( :default_code ){ "3-Route-5" } +  let( :factory ){ :route_control_opposite_route_terminus } + +  it_behaves_like 'ComplianceControl Class Level Defaults'  +end diff --git a/spec/models/compliance_control_class_level_defaults/route_control/speed_cccld_spec.rb b/spec/models/compliance_control_class_level_defaults/route_control/speed_cccld_spec.rb new file mode 100644 index 000000000..ad2b67960 --- /dev/null +++ b/spec/models/compliance_control_class_level_defaults/route_control/speed_cccld_spec.rb @@ -0,0 +1,7 @@ + +RSpec.describe RouteControl::Speed, type: :model do +  let( :default_code ){ "3-VehicleJourney-2" } +  let( :factory ){ :route_control_speed } + +  it_behaves_like 'ComplianceControl Class Level Defaults'  +end diff --git a/spec/models/compliance_control_class_level_defaults/route_control/stop_points_in_journey_pattern_cccld_spec.rb b/spec/models/compliance_control_class_level_defaults/route_control/stop_points_in_journey_pattern_cccld_spec.rb new file mode 100644 index 000000000..62249243d --- /dev/null +++ b/spec/models/compliance_control_class_level_defaults/route_control/stop_points_in_journey_pattern_cccld_spec.rb @@ -0,0 +1,7 @@ + +RSpec.describe RouteControl::StopPointsInJourneyPattern, type: :model do +  let( :default_code ){ "3-Route-6" } +  let( :factory ){ :route_control_stop_points_in_journey_pattern } + +  it_behaves_like 'ComplianceControl Class Level Defaults'  +end diff --git a/spec/models/compliance_control_class_level_defaults/route_control/time_table_cccld_spec.rb b/spec/models/compliance_control_class_level_defaults/route_control/time_table_cccld_spec.rb new file mode 100644 index 000000000..cbe14e4a7 --- /dev/null +++ b/spec/models/compliance_control_class_level_defaults/route_control/time_table_cccld_spec.rb @@ -0,0 +1,7 @@ + +RSpec.describe RouteControl::TimeTable, type: :model do +  let( :default_code ){ "3-VehicleJourney-4" } +  let( :factory ){ :route_control_time_table } + +  it_behaves_like 'ComplianceControl Class Level Defaults'  +end diff --git a/spec/models/compliance_control_class_level_defaults/route_control/unactivated_stop_points_cccld_spec.rb b/spec/models/compliance_control_class_level_defaults/route_control/unactivated_stop_points_cccld_spec.rb new file mode 100644 index 000000000..bf725d743 --- /dev/null +++ b/spec/models/compliance_control_class_level_defaults/route_control/unactivated_stop_points_cccld_spec.rb @@ -0,0 +1,7 @@ + +RSpec.describe RouteControl::UnactivatedStopPoints, type: :model do +  let( :default_code ){ "3-Route-10" } +  let( :factory ){ :route_control_unactivated_stop_points } + +  it_behaves_like 'ComplianceControl Class Level Defaults'  +end diff --git a/spec/models/compliance_control_class_level_defaults/route_control/vehicle_journey_at_stops_cccld_spec.rb b/spec/models/compliance_control_class_level_defaults/route_control/vehicle_journey_at_stops_cccld_spec.rb new file mode 100644 index 000000000..1268dbc98 --- /dev/null +++ b/spec/models/compliance_control_class_level_defaults/route_control/vehicle_journey_at_stops_cccld_spec.rb @@ -0,0 +1,7 @@ + +RSpec.describe RouteControl::VehicleJourneyAtStops, type: :model do +  let( :default_code ){ "3-VehicleJourney-5" } +  let( :factory ){ :route_control_control_vehicle_journey_at_stops } + +  it_behaves_like 'ComplianceControl Class Level Defaults'  +end diff --git a/spec/models/compliance_control_class_level_defaults/route_control/zdl_stop_area_cccld_spec.rb b/spec/models/compliance_control_class_level_defaults/route_control/zdl_stop_area_cccld_spec.rb new file mode 100644 index 000000000..2b8a11bd1 --- /dev/null +++ b/spec/models/compliance_control_class_level_defaults/route_control/zdl_stop_area_cccld_spec.rb @@ -0,0 +1,7 @@ + +RSpec.describe RouteControl::ZDLStopArea, type: :model do +  let( :default_code ){ "3-Route-1" } +  let( :factory ){ :route_control_zdl_stop_area } + +  it_behaves_like 'ComplianceControl Class Level Defaults'  +end diff --git a/spec/models/compliance_control_class_level_defaults/routing_constraint_zone_control/maximum_length_cccld_spec.rb b/spec/models/compliance_control_class_level_defaults/routing_constraint_zone_control/maximum_length_cccld_spec.rb new file mode 100644 index 000000000..61896ef5e --- /dev/null +++ b/spec/models/compliance_control_class_level_defaults/routing_constraint_zone_control/maximum_length_cccld_spec.rb @@ -0,0 +1,7 @@ + +RSpec.describe RoutingConstraintZoneControl::MaximumLength, type: :model do +  let( :default_code ){ "3-ITL-2" } +  let( :factory ){ :routing_constraint_zone_control_maximum_length } + +  it_behaves_like 'ComplianceControl Class Level Defaults'  +end diff --git a/spec/models/compliance_control_class_level_defaults/routing_constraint_zone_control/minimum_length_cccld_spec.rb b/spec/models/compliance_control_class_level_defaults/routing_constraint_zone_control/minimum_length_cccld_spec.rb new file mode 100644 index 000000000..e930c2475 --- /dev/null +++ b/spec/models/compliance_control_class_level_defaults/routing_constraint_zone_control/minimum_length_cccld_spec.rb @@ -0,0 +1,7 @@ + +RSpec.describe RoutingConstraintZoneControl::MinimumLength, type: :model do +  let( :default_code ){ "3-ITL-3" } +  let( :factory ){ :routing_constraint_zone_control_minimum_length } + +  it_behaves_like 'ComplianceControl Class Level Defaults'  +end diff --git a/spec/models/compliance_control_class_level_defaults/routing_constraint_zone_control/unactivated_stop_point_cccld_spec.rb b/spec/models/compliance_control_class_level_defaults/routing_constraint_zone_control/unactivated_stop_point_cccld_spec.rb new file mode 100644 index 000000000..aba9b7fc1 --- /dev/null +++ b/spec/models/compliance_control_class_level_defaults/routing_constraint_zone_control/unactivated_stop_point_cccld_spec.rb @@ -0,0 +1,7 @@ + +RSpec.describe RoutingConstraintZoneControl::UnactivatedStopPoint, type: :model do +  let( :default_code ){ "3-ITL-1" } +  let( :factory ){ :routing_constraint_zone_control_unactivated_stop_point } + +  it_behaves_like 'ComplianceControl Class Level Defaults'  +end diff --git a/spec/models/compliance_control_class_level_defaults/vehicle_journey_control/delta_cccld_spec.rb b/spec/models/compliance_control_class_level_defaults/vehicle_journey_control/delta_cccld_spec.rb new file mode 100644 index 000000000..0d4bce7ca --- /dev/null +++ b/spec/models/compliance_control_class_level_defaults/vehicle_journey_control/delta_cccld_spec.rb @@ -0,0 +1,7 @@ + +RSpec.describe VehicleJourneyControl::Delta, type: :model do +  let( :default_code ){ "3-VehicleJourney-3" } +  let( :factory ){ :vehicle_journey_control_delta } + +  it_behaves_like 'ComplianceControl Class Level Defaults'  +end diff --git a/spec/models/compliance_control_class_level_defaults/vehicle_journey_control/waiting_time_cccld_spec.rb b/spec/models/compliance_control_class_level_defaults/vehicle_journey_control/waiting_time_cccld_spec.rb new file mode 100644 index 000000000..34058ef33 --- /dev/null +++ b/spec/models/compliance_control_class_level_defaults/vehicle_journey_control/waiting_time_cccld_spec.rb @@ -0,0 +1,7 @@ + +RSpec.describe VehicleJourneyControl::WaitingTime, type: :model do +  let( :default_code ){ "3-VehicleJourney-1" } +  let( :factory ){ :vehicle_journey_control_wating_time } + +  it_behaves_like 'ComplianceControl Class Level Defaults'  +end diff --git a/spec/models/compliance_control_spec.rb b/spec/models/compliance_control_spec.rb index 0fc830021..50c2b7b8d 100644 --- a/spec/models/compliance_control_spec.rb +++ b/spec/models/compliance_control_spec.rb @@ -1,5 +1,3 @@ -require 'rails_helper' -  RSpec.describe ComplianceControl, type: :model do    let(:compliance_control) { create :compliance_control } diff --git a/spec/support/data_modifier.rb b/spec/support/data_modifier.rb new file mode 100644 index 000000000..2b3b00ac5 --- /dev/null +++ b/spec/support/data_modifier.rb @@ -0,0 +1,53 @@ +require_relative 'data_modifier/enum' +require_relative 'data_modifier/hash' +module Support +  module DataModifier +    module InstanceMethods +      CannotModify = Class.new RuntimeError + +      def advance_values(atts, *keys) +        keys.inject(atts){ |h, k| h.merge( k => atts[k].next) } +      end + +      # return array of atts wich each value modified, unboxing +      # values if needed +      def modify_atts(base_atts) +        base_atts.keys.map do | key | +          modify_att base_atts, key +        end.compact +      end + +      private +      def modify_att atts, key +        atts.merge(key => modify_value(atts[key])) +      rescue CannotModify +        nil +      end +      def modify_value value +        case value +        when String +          "#{value}." +        when Fixnum +          value + 1 +        when TrueClass +          false +        when FalseClass +          true +        when Float +          value * 1.1 +        when Date +          value + 1.day +        when Box +          value.next.value +        else +          raise CannotModify +        end +      end +    end +  end +end + +RSpec.configure do | c | +  c.include Support::DataModifier::InstanceMethods, type: :checksum +  c.include Support::DataModifier::InstanceMethods, type: :model +end diff --git a/spec/support/data_modifier/bool.rb b/spec/support/data_modifier/bool.rb new file mode 100644 index 000000000..f4be9bd89 --- /dev/null +++ b/spec/support/data_modifier/bool.rb @@ -0,0 +1,18 @@ +require_relative 'box' + +module Support +    module DataModifier + +      class BoolBox +        include Box +        attr_reader :value + +        def initialize value +          @value  = value +        end +        def next +          self.class.new(!value) +        end +      end +    end +end diff --git a/spec/support/data_modifier/box.rb b/spec/support/data_modifier/box.rb new file mode 100644 index 000000000..0847b628c --- /dev/null +++ b/spec/support/data_modifier/box.rb @@ -0,0 +1,21 @@ +require_relative 'hash' +module Support +  module DataModifier +    module Box +      def next +        raise "Need to implement #{__method__} in #{self.class}" +      end + +      class << self +        def unbox atts +          Hash.map_values(atts, method(:value_of)) +        end +        def value_of v +          self === v ? v.value : v +        end +      end +    end + +  end +end + diff --git a/spec/support/data_modifier/enum.rb b/spec/support/data_modifier/enum.rb new file mode 100644 index 000000000..c8a6fe573 --- /dev/null +++ b/spec/support/data_modifier/enum.rb @@ -0,0 +1,19 @@ +require_relative 'box' + +module Support +    module DataModifier + +      class EnumBox +        include Box +        attr_reader :value, :values + +        def initialize *enum_values +          @values = enum_values +          @value  = @values.first +        end +        def next +          self.class.new(*(@values[1..-1] << @values.first)) +        end +      end +    end +end diff --git a/spec/support/data_modifier/hash.rb b/spec/support/data_modifier/hash.rb new file mode 100644 index 000000000..05da3cf4f --- /dev/null +++ b/spec/support/data_modifier/hash.rb @@ -0,0 +1,16 @@ +module Support +  module DataModifier +    module Hash extend self +      def map_values hashy, f=nil, &fn +        raise ArgumentError, "need block or function arg" unless f = fn || f +        hashy.inject({}){ |h, (k,v)| h.merge(k => f.(v)) } +      end +      def first_values ary_hash +        map_values(ary_hash, &:first) +      end +      def last_values ary_hash +        map_values(ary_hash, &:last) +      end +    end +  end +end diff --git a/spec/support/random.rb b/spec/support/random.rb new file mode 100644 index 000000000..59e1a1475 --- /dev/null +++ b/spec/support/random.rb @@ -0,0 +1,30 @@ +module Support +  module Random + +    PRETTY_LARGE_INT = 1 << 30  + +    def random_hex +      SecureRandom.hex +    end + +    def random_element from +      from[random_int(from.size)] +    end + +    def random_int max_plus_one=PRETTY_LARGE_INT +      (random_number * max_plus_one).to_i +    end + +    def random_number +      SecureRandom.random_number +    end + +    def random_string +      SecureRandom.urlsafe_base64 +    end +  end +end + +RSpec.configure do | c | +  c.include Support::Random +end diff --git a/spec/support/shared_examples/compliance_control_class_level_defaults.rb b/spec/support/shared_examples/compliance_control_class_level_defaults.rb new file mode 100644 index 000000000..276ac1ca5 --- /dev/null +++ b/spec/support/shared_examples/compliance_control_class_level_defaults.rb @@ -0,0 +1,42 @@ +require_relative '../data_modifier' + +H = Support::DataModifier::Hash +RSpec.shared_examples_for 'ComplianceControl Class Level Defaults' do +    context 'class attributes' do +      it 'are correctly set' do +        expect( described_class.default_code).to eq(default_code) +      end +    end +    context 'are used in instantiation' do +      let( :record ){ create factory } +      let( :default_att_names ){%w[ code origin_code ]} + +      it 'all defaults' do +        expect( record.attributes.values_at(*default_att_names )) +          .to eq([ default_code, default_code]) +      end +      it 'but provided values are not overwritten by defaults' do +        code        = random_string +        origin_code = random_string +        # Remove each of the attributes from explicit initialisation to see +        # its value provided by CCCWDA. + +        # atts :: Map(String, (explicit_value, default_value)) +        atts = { +          'code'        => [code, default_code], +          'origin_code' => [origin_code, default_code], +        } +        atts.keys.each do |key| +          # Replace key to be tested by default value +          expected = H.first_values(atts).merge(key => atts[key].last) +          expected_values = expected.values_at(*default_att_names) +          # Remove key to be tested from atts passed to `#create` +          construction_atts = H.first_values(atts).merge(key => nil).compact +          explicit = create factory, construction_atts  + +          expect( explicit.attributes.values_at(*default_att_names )) +            .to eq(expected_values) +        end +      end +    end +  end | 
