diff options
| author | Luc Donnet | 2017-10-16 23:52:06 +0200 |
|---|---|---|
| committer | Luc Donnet | 2017-10-16 23:52:06 +0200 |
| commit | f480ad0739e5c0ec2c0c8bb890344b9c4777ba35 (patch) | |
| tree | a19bc6b43449b8b978a53c33476fb3eb571d4dda /spec/models | |
| parent | b611a84ed724036c4929bd4c3eaa7e23ea314f45 (diff) | |
| parent | 51a1ea5b141032121913f807a162d305828bec54 (diff) | |
| download | chouette-core-f480ad0739e5c0ec2c0c8bb890344b9c4777ba35.tar.bz2 | |
Merge branch 'master' into staging
Diffstat (limited to 'spec/models')
40 files changed, 310 insertions, 84 deletions
diff --git a/spec/models/chouette/transport_mode_spec.rb b/spec/models/chouette/transport_mode_spec.rb deleted file mode 100644 index 8f2b2eddb..000000000 --- a/spec/models/chouette/transport_mode_spec.rb +++ /dev/null @@ -1,64 +0,0 @@ -require 'spec_helper' - -describe Chouette::TransportMode, :type => :model do - - def mode(text_code = "test", numerical_code = nil) - numerical_code ||= 1 if text_code == "test" - Chouette::TransportMode.new(text_code, numerical_code) - end - - describe "#to_i" do - - it "should return numerical code" do - expect(mode("test", 1).to_i).to eq(1) - end - - end - - it "should return true to #test? when text code is 'test'" do - expect(mode("test")).to be_test - end - - it "should be equal when text codes are identical" do - expect(mode("test",1)).to eq(mode("test", 2)) - end - - describe ".new" do - - it "should find numerical code from text code" do - expect(mode("unknown").to_i).to eq(0) - end - - it "should find text code from numerical code" do - expect(mode(0)).to be_unknown - end - - it "should accept another mode" do - expect(Chouette::TransportMode.new(mode("test"))).to eq(mode("test")) - end - - end - - describe "#public_transport?" do - - it "should return false for interchange" do - expect(mode("interchange")).not_to be_public_transport - end - - it "should return true for other modes" do - expect(mode("unknown")).to be_public_transport - end - - end - - describe ".all" do - - Chouette::TransportMode.definitions.each do |text_code, numerical_code| - it "should include a TransportMode #{text_code}" do - expect(Chouette::TransportMode.all).to include(Chouette::TransportMode.new(text_code)) - end - end - - end - -end diff --git a/spec/models/compliance_check_block_spec.rb b/spec/models/compliance_check_block_spec.rb index f581d5085..a3d98d459 100644 --- a/spec/models/compliance_check_block_spec.rb +++ b/spec/models/compliance_check_block_spec.rb @@ -6,4 +6,5 @@ RSpec.describe ComplianceCheckBlock, type: :model do end it { should belong_to :compliance_check_set } + it { should have_many :compliance_checks } end diff --git a/spec/models/compliance_check_message_spec.rb b/spec/models/compliance_check_message_spec.rb index 8b424595e..b55537f95 100644 --- a/spec/models/compliance_check_message_spec.rb +++ b/spec/models/compliance_check_message_spec.rb @@ -1,5 +1,3 @@ -require 'rails_helper' - RSpec.describe ComplianceCheckMessage, type: :model do it 'should have a valid factory' do expect(FactoryGirl.build(:compliance_check_message)).to be_valid @@ -7,4 +5,5 @@ RSpec.describe ComplianceCheckMessage, type: :model do it { should belong_to :compliance_check } it { should belong_to :compliance_check_resource } + it { should belong_to :compliance_check_set } end diff --git a/spec/models/compliance_check_resource_spec.rb b/spec/models/compliance_check_resource_spec.rb index a9366bea2..40e209db0 100644 --- a/spec/models/compliance_check_resource_spec.rb +++ b/spec/models/compliance_check_resource_spec.rb @@ -4,4 +4,6 @@ RSpec.describe ComplianceCheckResource, type: :model do it 'should have a valid factory' do expect(FactoryGirl.build(:compliance_check_resource)).to be_valid end + + it { should validate_presence_of(:compliance_check_set) } end diff --git a/spec/models/compliance_check_set_spec.rb b/spec/models/compliance_check_set_spec.rb index 6e53c9def..8afea5b3e 100644 --- a/spec/models/compliance_check_set_spec.rb +++ b/spec/models/compliance_check_set_spec.rb @@ -9,4 +9,7 @@ RSpec.describe ComplianceCheckSet, type: :model do it { should belong_to :workbench } it { should belong_to :compliance_control_set } it { should belong_to :parent } + + it { should have_many :compliance_checks } + it { should have_many :compliance_check_blocks } end diff --git a/spec/models/compliance_check_spec.rb b/spec/models/compliance_check_spec.rb index 4fbc23d42..bd797ab09 100644 --- a/spec/models/compliance_check_spec.rb +++ b/spec/models/compliance_check_spec.rb @@ -1,14 +1,17 @@ -require 'rails_helper' - RSpec.describe ComplianceCheck, type: :model do it 'should have a valid factory' do expect(FactoryGirl.build(:compliance_check)).to be_valid end + it 'has STI disabled' do + expect( described_class.inheritance_column ).to be_blank + end + it { should belong_to :compliance_check_set } it { should belong_to :compliance_check_block } it { should validate_presence_of :criticity } it { should validate_presence_of :name } it { should validate_presence_of :code } + it { should validate_presence_of :origin_code } end diff --git a/spec/models/compliance_control_block_spec.rb b/spec/models/compliance_control_block_spec.rb index 248049b0c..c7440a5eb 100644 --- a/spec/models/compliance_control_block_spec.rb +++ b/spec/models/compliance_control_block_spec.rb @@ -1,9 +1,13 @@ require 'rails_helper' RSpec.describe ComplianceControlBlock, type: :model do + subject { create(:compliance_control_block) } + it 'should have a valid factory' do expect(FactoryGirl.build(:compliance_control_block)).to be_valid end it { should belong_to :compliance_control_set } + it { should have_many(:compliance_controls).dependent(:destroy) } + it { should validate_presence_of(:transport_mode) } 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..9610cc796 --- /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-1" } + 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/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..f8533aa06 --- /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-8" } + 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/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/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/speed_cccld_spec.rb b/spec/models/compliance_control_class_level_defaults/vehicle_journey_control/speed_cccld_spec.rb new file mode 100644 index 000000000..2a3cae9ff --- /dev/null +++ b/spec/models/compliance_control_class_level_defaults/vehicle_journey_control/speed_cccld_spec.rb @@ -0,0 +1,7 @@ + +RSpec.describe VehicleJourneyControl::Speed, type: :model do + let( :default_code ){ "3-VehicleJourney-2" } + let( :factory ){ :vehicle_journey_control_speed } + + it_behaves_like 'ComplianceControl Class Level Defaults' +end diff --git a/spec/models/compliance_control_class_level_defaults/vehicle_journey_control/time_table_cccld_spec.rb b/spec/models/compliance_control_class_level_defaults/vehicle_journey_control/time_table_cccld_spec.rb new file mode 100644 index 000000000..19dfe871d --- /dev/null +++ b/spec/models/compliance_control_class_level_defaults/vehicle_journey_control/time_table_cccld_spec.rb @@ -0,0 +1,7 @@ + +RSpec.describe VehicleJourneyControl::TimeTable, type: :model do + let( :default_code ){ "3-VehicleJourney-4" } + let( :factory ){ :vehicle_journey_control_time_table } + + it_behaves_like 'ComplianceControl Class Level Defaults' +end diff --git a/spec/models/compliance_control_class_level_defaults/vehicle_journey_control/vehicle_journey_at_stops_cccld_spec.rb b/spec/models/compliance_control_class_level_defaults/vehicle_journey_control/vehicle_journey_at_stops_cccld_spec.rb new file mode 100644 index 000000000..30b5893d5 --- /dev/null +++ b/spec/models/compliance_control_class_level_defaults/vehicle_journey_control/vehicle_journey_at_stops_cccld_spec.rb @@ -0,0 +1,7 @@ + +RSpec.describe VehicleJourneyControl::VehicleJourneyAtStops, type: :model do + let( :default_code ){ "3-VehicleJourney-5" } + let( :factory ){ :vehicle_journey_control_vehicle_journey_at_stops } + + 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_set_spec.rb b/spec/models/compliance_control_set_spec.rb index ededec5e0..04d1c418c 100644 --- a/spec/models/compliance_control_set_spec.rb +++ b/spec/models/compliance_control_set_spec.rb @@ -6,7 +6,8 @@ RSpec.describe ComplianceControlSet, type: :model do end it { should belong_to :organisation } - it { should have_many :compliance_controls } + it { should have_many(:compliance_controls).dependent(:destroy) } + it { should have_many(:compliance_control_blocks).dependent(:destroy) } it { should validate_presence_of :name } end diff --git a/spec/models/compliance_control_spec.rb b/spec/models/compliance_control_spec.rb index b00ff4c5a..db73dab21 100644 --- a/spec/models/compliance_control_spec.rb +++ b/spec/models/compliance_control_spec.rb @@ -1,14 +1,59 @@ -require 'rails_helper' - RSpec.describe ComplianceControl, type: :model do - it 'should have a valid factory' do - expect(FactoryGirl.build(:compliance_control)).to be_valid + + context 'standard validation' do + + let(:compliance_control) { build_stubbed :compliance_control } + + it 'should have a valid factory' do + expect(compliance_control).to be_valid + end + + it { should belong_to :compliance_control_set } + it { should belong_to :compliance_control_block } + + + it { should validate_presence_of :criticity } + it 'should validate_presence_of :name' do + expect( build :compliance_control, name: '' ).to_not be_valid + end + it { should validate_presence_of :code } + it { should validate_presence_of :origin_code } + end - it { should belong_to :compliance_control_set } - it { should belong_to :compliance_control_block } + context 'validates that direct and indirect (via control_block) control_set are not different instances' do + + it 'not attached to control_block -> valid' do + compliance_control = create :compliance_control, compliance_control_block_id: nil + expect(compliance_control).to be_valid + end + + it 'attached to a control_block belonging to the same control_set -> valid' do + compliance_control_block = create :compliance_control_block + compliance_control = create :compliance_control, + compliance_control_block_id: compliance_control_block.id, + compliance_control_set_id: compliance_control_block.compliance_control_set.id # DO NOT change the last . to _ + # We need to be sure that is is not nil + expect(compliance_control).to be_valid + end - it { should validate_presence_of :criticity } - it { should validate_presence_of :name } - it { should validate_presence_of :code } + it 'attached to a control_block **not** belonging to the same control_set -> invalid' do + compliance_control_block = create :compliance_control_block + compliance_control = build :compliance_control, + compliance_control_block_id: compliance_control_block.id, + compliance_control_set_id: create( :compliance_control_set ).id + expect(compliance_control).to_not be_valid + + direct_name = compliance_control.compliance_control_set.name + indirect_name = compliance_control_block.compliance_control_set.name + expected_message = "Le contrôle ne peut pas être associé à un jeu de contrôle (id: #{direct_name}) différent de celui de son groupe (id: #{indirect_name})" + + selected_error_message = + compliance_control + .errors + .messages[:coherent_control_set] + .first + expect( selected_error_message ).to eq(expected_message) + end + end end diff --git a/spec/models/compliance_control_validations/genric_attribute_validation/min_max_validation_spec.rb b/spec/models/compliance_control_validations/genric_attribute_validation/min_max_validation_spec.rb new file mode 100644 index 000000000..276d09a92 --- /dev/null +++ b/spec/models/compliance_control_validations/genric_attribute_validation/min_max_validation_spec.rb @@ -0,0 +1,8 @@ +# RSpec.describe GenericAttributeControl::MinMax do + +# let( :factory ){ :generic_attribute_control_min_max } +# subject{ build factory } + +# it_behaves_like 'has min_max_values' + +# end diff --git a/spec/models/compliance_control_validations/genric_attribute_validation/pattern_validation_spec.rb b/spec/models/compliance_control_validations/genric_attribute_validation/pattern_validation_spec.rb new file mode 100644 index 000000000..f2814bfd4 --- /dev/null +++ b/spec/models/compliance_control_validations/genric_attribute_validation/pattern_validation_spec.rb @@ -0,0 +1,24 @@ +RSpec.describe GenericAttributeControl::Pattern do + + let( :factory ){ :generic_attribute_control_pattern } + subject{ build factory } + + context "is valid" do + it 'if the pattern contains a basic regex' do + subject.pattern = 'hel+o?' + expect_it.to be_valid + end + end + + context "is invalid" do + pending "Behavior to be defined" + # it 'if no pattern has been provided' do + # expect_it.not_to be_valid + # end + # it 'if the pattern is empty' do + # subject.pattern = ' ' + # expect_it.not_to be_valid + # end + + end +end diff --git a/spec/models/compliance_control_validations/vehicle_journey_validation/speed_validation_spec.rb b/spec/models/compliance_control_validations/vehicle_journey_validation/speed_validation_spec.rb new file mode 100644 index 000000000..88316ab37 --- /dev/null +++ b/spec/models/compliance_control_validations/vehicle_journey_validation/speed_validation_spec.rb @@ -0,0 +1,8 @@ +RSpec.describe VehicleJourneyControl::Speed do + + let( :factory ){ :vehicle_journey_control_speed } + subject{ build factory } + + it_behaves_like 'has min_max_values' + +end diff --git a/spec/models/line_referential_spec.rb b/spec/models/line_referential_spec.rb index 8472faaa0..8c6cb018b 100644 --- a/spec/models/line_referential_spec.rb +++ b/spec/models/line_referential_spec.rb @@ -12,7 +12,7 @@ RSpec.describe LineReferential, :type => :model do describe "#transport_modes" do it 'returns a list of all transport modes' do - expect(FactoryGirl.create(:line_referential).transport_modes).to eq( Chouette::TransportMode.all.select { |tm| tm.to_i > 0 } ) + expect(FactoryGirl.create(:line_referential).class.transport_modes).to match_array(StifTransportModeEnumerations.transport_modes ) end end end diff --git a/spec/models/organisation_spec.rb b/spec/models/organisation_spec.rb index b16324a56..1217666f7 100644 --- a/spec/models/organisation_spec.rb +++ b/spec/models/organisation_spec.rb @@ -6,10 +6,10 @@ describe Organisation, :type => :model do expect(FactoryGirl.build(:organisation)).to be_valid end - it "create a rule_parameter_set" do - organisation = create(:organisation) - expect(organisation.rule_parameter_sets.size).to eq(1) - end + # it "create a rule_parameter_set" do + # organisation = create(:organisation) + # expect(organisation.rule_parameter_sets.size).to eq(1) + # end describe "Portail sync" do let(:conf) { Rails.application.config.stif_portail_api } diff --git a/spec/models/vehicle_translation_spec.rb b/spec/models/vehicle_translation_spec.rb index d30cfa03e..4bbff7f49 100644 --- a/spec/models/vehicle_translation_spec.rb +++ b/spec/models/vehicle_translation_spec.rb @@ -9,7 +9,7 @@ describe VehicleTranslation, :type => :model do :journey_pattern => journey_pattern, :route => journey_pattern.route, # :company => company, - :transport_mode => Chouette::TransportMode.new("metro"), + :transport_mode => "metro", :published_journey_name => "dummy" )} subject {build(:vehicle_translation, diff --git a/spec/models/workbench_spec.rb b/spec/models/workbench_spec.rb index 84149ddb0..037537b60 100644 --- a/spec/models/workbench_spec.rb +++ b/spec/models/workbench_spec.rb @@ -11,6 +11,7 @@ RSpec.describe Workbench, :type => :model do it { should belong_to(:organisation) } it { should belong_to(:line_referential) } it { should belong_to(:stop_area_referential) } + it { should belong_to(:output).class_name('ReferentialSuite') } it { should have_many(:lines).through(:line_referential) } it { should have_many(:networks).through(:line_referential) } @@ -19,6 +20,15 @@ RSpec.describe Workbench, :type => :model do it { should have_many(:stop_areas).through(:stop_area_referential) } + it do + # This callback interferes with the validation test + Workbench.skip_callback(:validation, :before, :initialize_output) + + should validate_presence_of(:output) + + Workbench.set_callback(:validation, :before, :initialize_output) + end + context '.lines' do let!(:ids) { ['STIF:CODIFLIGNE:Line:C00840', 'STIF:CODIFLIGNE:Line:C00086'] } let!(:organisation) { create :organisation, sso_attributes: { functional_scope: ids.to_json } } @@ -33,4 +43,18 @@ RSpec.describe Workbench, :type => :model do expect(lines.map(&:objectid)).to include(*ids) end end + + describe ".create" do + it "must automatically create a ReferentialSuite when being created" do + workbench = Workbench.create + expect(workbench.output).to be_an_instance_of(ReferentialSuite) + end + + it "must not overwrite a given ReferentialSuite" do + referential_suite = create(:referential_suite) + workbench = create(:workbench, output: referential_suite) + + expect(workbench.output).to eq(referential_suite) + end + end end |
