diff options
| author | Luc Donnet | 2017-07-31 22:48:52 +0200 |
|---|---|---|
| committer | Luc Donnet | 2017-07-31 22:48:52 +0200 |
| commit | 5dda0f5286043823acab68a73d84437a3cbd803f (patch) | |
| tree | 3fd060f806e831dd035af4757e2bc0ec7e48508c /spec | |
| parent | 3b617583e24ee9096360d0f7434cfdb3f36f0980 (diff) | |
| parent | 6291e883bc30ccdeaf37338febea9a640467f5d7 (diff) | |
| download | chouette-core-5dda0f5286043823acab68a73d84437a3cbd803f.tar.bz2 | |
Merge branch 'master' into staging
Diffstat (limited to 'spec')
| -rw-r--r-- | spec/factories/chouette_access_points.rb | 2 | ||||
| -rw-r--r-- | spec/factories/chouette_lines.rb | 2 | ||||
| -rw-r--r-- | spec/factories/chouette_stop_areas.rb | 2 | ||||
| -rw-r--r-- | spec/models/chouette/access_point_spec.rb | 11 | ||||
| -rw-r--r-- | spec/models/chouette/stop_area_spec.rb | 4 | ||||
| -rw-r--r-- | spec/models/chouette/time_table_spec.rb | 13 | ||||
| -rw-r--r-- | spec/models/chouette/vehicle_journey_at_stops_are_in_increasing_time_order_validator_spec.rb | 8 | ||||
| -rw-r--r-- | spec/models/chouette/vehicle_journey_spec.rb | 8 | ||||
| -rw-r--r-- | spec/models/time_table_combination_spec.rb | 54 | ||||
| -rw-r--r-- | spec/models/vehicle_journey_import_spec.rb | 48 |
10 files changed, 49 insertions, 103 deletions
diff --git a/spec/factories/chouette_access_points.rb b/spec/factories/chouette_access_points.rb index 06d1da779..38ad76363 100644 --- a/spec/factories/chouette_access_points.rb +++ b/spec/factories/chouette_access_points.rb @@ -5,7 +5,7 @@ FactoryGirl.define do longitude {10.0 * rand} sequence(:name) { |n| "AccessPoint #{n}" } access_type "InOut" - sequence(:objectid) { |n| "test:AccessPoint:#{n}" } + sequence(:objectid) { |n| "FR:#{n}:ADL:#{n}:STIF" } association :stop_area, :factory => :stop_area end diff --git a/spec/factories/chouette_lines.rb b/spec/factories/chouette_lines.rb index 24b182b83..423ab99f2 100644 --- a/spec/factories/chouette_lines.rb +++ b/spec/factories/chouette_lines.rb @@ -2,7 +2,7 @@ FactoryGirl.define do factory :line, :class => Chouette::Line do sequence(:name) { |n| "Line #{n}" } - sequence(:objectid) { |n| "chouette:test:Line:#{n}" } + sequence(:objectid) { |n| "STIF:CODIFLIGNE:Line:#{n}" } sequence(:transport_mode) { |n| "bus" } sequence(:number, 1) diff --git a/spec/factories/chouette_stop_areas.rb b/spec/factories/chouette_stop_areas.rb index 8e92b024b..8b64c227b 100644 --- a/spec/factories/chouette_stop_areas.rb +++ b/spec/factories/chouette_stop_areas.rb @@ -1,6 +1,6 @@ FactoryGirl.define do factory :stop_area, :class => Chouette::StopArea do - sequence(:objectid) { |n| "test:StopArea:#{n}" } + sequence(:objectid) { |n| "FR:#{n}:ZDE:#{n}:STIF" } sequence(:name) { |n| "stop_area_#{n}" } sequence(:registration_number) { |n| "test-#{n}" } area_type { Chouette::StopArea.area_type.values.sample } diff --git a/spec/models/chouette/access_point_spec.rb b/spec/models/chouette/access_point_spec.rb index 02b1621e3..e0f4b1501 100644 --- a/spec/models/chouette/access_point_spec.rb +++ b/spec/models/chouette/access_point_spec.rb @@ -1,10 +1,11 @@ require 'spec_helper' describe Chouette::AccessPoint, :type => :model do + subject { create(:access_point) } describe '#objectid' do subject { super().objectid } - it { is_expected.to be_kind_of(Chouette::ObjectId) } + it { is_expected.to be_kind_of(Chouette::StifReflexObjectid) } end it { is_expected.to validate_presence_of :name } @@ -109,7 +110,6 @@ describe Chouette::AccessPoint, :type => :model do end describe "#to_lat_lng" do - it "should return nil if latitude is nil" do subject.latitude = nil expect(subject.to_lat_lng).to be_nil @@ -123,12 +123,13 @@ describe Chouette::AccessPoint, :type => :model do end describe "#geometry" do + let(:access_point) { create(:access_point) } it "should be nil when to_lat_lng is nil" do - allow(subject).to receive_messages :to_lat_lng => nil - expect(subject.geometry).to be_nil + allow(access_point).to receive_messages :longitude => nil + allow(access_point).to receive_messages :latitude => nil + expect(access_point.geometry).to be_nil end - end describe "#generic_access_link_matrix" do diff --git a/spec/models/chouette/stop_area_spec.rb b/spec/models/chouette/stop_area_spec.rb index 293ae5202..a3a398bfb 100644 --- a/spec/models/chouette/stop_area_spec.rb +++ b/spec/models/chouette/stop_area_spec.rb @@ -1,9 +1,9 @@ require 'spec_helper' describe Chouette::StopArea, :type => :model do - # FIXME !!!!!!!! + subject { create(:stop_area) } + let!(:quay) { create :stop_area, :area_type => "zdep" } - # let!(:boarding_position) { create :stop_area, :area_type => "BoardingPosition" } let!(:commercial_stop_point) { create :stop_area, :area_type => "lda" } let!(:stop_place) { create :stop_area, :area_type => "zdlp" } diff --git a/spec/models/chouette/time_table_spec.rb b/spec/models/chouette/time_table_spec.rb index 304cb0184..f13e13d52 100644 --- a/spec/models/chouette/time_table_spec.rb +++ b/spec/models/chouette/time_table_spec.rb @@ -52,20 +52,19 @@ describe Chouette::TimeTable, :type => :model do expect(subject.int_day_types).to eq int_day_types end - it 'should merge date in_out false' do + it 'should not merge date in_out false' do another_tt.dates.last.in_out = false another_tt.save subject.merge!(another_tt) - expect(subject.dates.map(&:date)).to include(another_tt.dates.last.date) + expect(subject.dates.map(&:date)).not_to include(another_tt.dates.last.date) end - it 'should remove date in_out false if other tt doesnt have them' do + it 'should remove all date in_out false' do subject.dates.create(in_out: false, date: Date.today + 5.day + 1.year) - - expect { - subject.merge!(another_tt) - }.to change {subject.reload.excluded_days.count}.by(-1) + another_tt.dates.last.in_out = false + subject.merge!(another_tt) + expect(subject.reload.excluded_days.count).to eq(0) end end diff --git a/spec/models/chouette/vehicle_journey_at_stops_are_in_increasing_time_order_validator_spec.rb b/spec/models/chouette/vehicle_journey_at_stops_are_in_increasing_time_order_validator_spec.rb index c30e0dbd8..d0a15788d 100644 --- a/spec/models/chouette/vehicle_journey_at_stops_are_in_increasing_time_order_validator_spec.rb +++ b/spec/models/chouette/vehicle_journey_at_stops_are_in_increasing_time_order_validator_spec.rb @@ -13,7 +13,7 @@ describe Chouette::VehicleJourneyAtStopsAreInIncreasingTimeOrderValidator do subject.vehicle_journey_at_stops[1].departure_time end - it "should make instance invalid if departure time exceeds gap" do + it "should make instance invalid if departure time exceeds gap", :skip => "Time gap validation is in pending status" do subject.validate expect( @@ -31,7 +31,7 @@ describe Chouette::VehicleJourneyAtStopsAreInIncreasingTimeOrderValidator do let(:vjas2) { vehicle_journey.vehicle_journey_at_stops[1] } context "when vjas#arrival_time exceeds gap" do - it "should add errors on arrival_time" do + it "should add errors on arrival_time", :skip => "Time gap validation is in pending status" do vjas1.arrival_time = vjas2.arrival_time - 5.hour expect( Chouette::VehicleJourneyAtStopsAreInIncreasingTimeOrderValidator @@ -43,7 +43,7 @@ describe Chouette::VehicleJourneyAtStopsAreInIncreasingTimeOrderValidator do end context "when vjas#departure_time exceeds gap" do - it "should add errors on departure_time" do + it "should add errors on departure_time", :skip => "Time gap validation is in pending status" do vjas1.departure_time = vjas2.departure_time - 5.hour expect( Chouette::VehicleJourneyAtStopsAreInIncreasingTimeOrderValidator @@ -55,7 +55,7 @@ describe Chouette::VehicleJourneyAtStopsAreInIncreasingTimeOrderValidator do end context "when vjas doesn't exceed gap" do - it "should not add errors" do + it "should not add errors", :skip => "Time gap validation is in pending status" do expect( Chouette::VehicleJourneyAtStopsAreInIncreasingTimeOrderValidator .validate_at_stop_times_must_increase(vjas2, vjas1) diff --git a/spec/models/chouette/vehicle_journey_spec.rb b/spec/models/chouette/vehicle_journey_spec.rb index 645513735..3c04a77cc 100644 --- a/spec/models/chouette/vehicle_journey_spec.rb +++ b/spec/models/chouette/vehicle_journey_spec.rb @@ -558,18 +558,18 @@ describe Chouette::VehicleJourney, :type => :model do "0"=>{"id" => subject.vehicle_journey_at_stops[0].id ,"arrival_time" => 1.minutes.ago,"departure_time" => 1.minutes.ago}, "1"=>{"id" => subject.vehicle_journey_at_stops[1].id, "arrival_time" => (1.minutes.ago + 4.hour),"departure_time" => (1.minutes.ago + 4.hour)} }}} - it "should return false" do + it "should return false", :skip => "Time gap validation is in pending status" do expect(subject.update_attributes(params)).to be_falsey end - it "should make instance invalid" do + it "should make instance invalid", :skip => "Time gap validation is in pending status" do subject.update_attributes(params) expect(subject).not_to be_valid end - it "should let first vjas without any errors" do + it "should let first vjas without any errors", :skip => "Time gap validation is in pending status" do subject.update_attributes(params) expect(subject.vehicle_journey_at_stops[0].errors).to be_empty end - it "should add an error on second vjas" do + it "should add an error on second vjas", :skip => "Time gap validation is in pending status" do subject.update_attributes(params) expect(subject.vehicle_journey_at_stops[1].errors[:departure_time]).not_to be_blank end diff --git a/spec/models/time_table_combination_spec.rb b/spec/models/time_table_combination_spec.rb index ee934f50d..81f9dd7a6 100644 --- a/spec/models/time_table_combination_spec.rb +++ b/spec/models/time_table_combination_spec.rb @@ -44,60 +44,6 @@ describe TimeTableCombination, :type => :model do end end - describe '#continuous_periods' do - it 'should group continuous periods' do - source.periods.clear - - start_date = Date.today + 1.year - end_date = start_date + 10 - - # 6 more continuous dates, 2 isolated dates - 0.upto(4) do |i| - source.periods.create(period_start: start_date, period_end: end_date) - start_date = end_date + 1 - end_date = start_date + 10 - end - - expect(source.reload.continuous_periods.flatten.count).to eq(5) - end - end - - describe '#convert_continuous_periods_into_one' do - it 'should convert continuous periods into one' do - source.periods.clear - - start_date = Date.today + 1.year - end_date = start_date + 10 - - # 6 more continuous dates, 2 isolated dates - 0.upto(4) do |i| - source.periods.create(period_start: start_date, period_end: end_date) - start_date = end_date + 1 - end_date = start_date + 10 - end - - expect { - source.reload.convert_continuous_periods_into_one - }.to change {source.periods.count}.by(-4) - end - end - - describe '#optimize_continuous_dates_and_periods' do - it 'should update period if timetable has in_date just before or after ' do - source.dates.clear - source.periods.clear - - source.periods.create(period_start: Date.today, period_end: Date.today + 10.day) - source.dates.create(date: Date.today - 1.day, in_out: true) - - expect { - source.periods = source.optimize_continuous_dates_and_periods - }.to change {source.dates.count}.by(-1) - - expect(source.reload.periods.first.period_start).to eq(Date.today - 1.day) - end - end - describe "#combine" do context "when operation is union" do before(:each) do diff --git a/spec/models/vehicle_journey_import_spec.rb b/spec/models/vehicle_journey_import_spec.rb index a743bdecb..b01523dd9 100644 --- a/spec/models/vehicle_journey_import_spec.rb +++ b/spec/models/vehicle_journey_import_spec.rb @@ -11,16 +11,16 @@ describe VehicleJourneyImport, :type => :model do if counter == 0 row2 = [] row.each do |cell| - cell = vehicle_journey1.id.to_s if cell == "import:VehicleJourney:1" - cell = vehicle_journey2.id.to_s if cell == "import:VehicleJourney:2" - cell = vehicle_journey3.id.to_s if cell == "import:VehicleJourney:3" + cell = vehicle_journey1.id.to_s if cell == "import:VehicleJourney:1" + cell = vehicle_journey2.id.to_s if cell == "import:VehicleJourney:2" + cell = vehicle_journey3.id.to_s if cell == "import:VehicleJourney:3" row2 << cell end csv << row2 elsif counter < 8 csv << row else - csv << ( row[0] = route.stop_points[counter - 8].id; row) + csv << ( row[0] = route.stop_points[counter - 8].id; row) end counter += 1 end @@ -29,7 +29,7 @@ describe VehicleJourneyImport, :type => :model do File.open("/tmp/#{filename}") end - + let!(:route) { create(:route) } let!(:other_route) { create(:route) } @@ -39,14 +39,14 @@ describe VehicleJourneyImport, :type => :model do let!(:vehicle_journey1) { create(:vehicle_journey_common, :objectid => "import:VehicleJourney:1", :route_id => route.id, :journey_pattern_id => journey_pattern.id) } let!(:vehicle_journey2) { create(:vehicle_journey_common, :objectid => "import:VehicleJourney:2", :route_id => route.id, :journey_pattern_id => other_journey_pattern.id) } let!(:vehicle_journey3) { create(:vehicle_journey_common, :objectid => "import:VehicleJourney:3", :route_id => route.id, :journey_pattern_id => journey_pattern.id) } - + let!(:stop_point0) { route.stop_points[0] } let!(:stop_point1) { route.stop_points[1] } let!(:stop_point2) { route.stop_points[2] } let!(:stop_point3) { route.stop_points[3] } let!(:stop_point4) { route.stop_points[4] } - + # Must use uploaded file and not classical ruby File! let(:valid_file) { csv_file = update_csv_file_with_factory_data("vehicle_journey_imports_valid.csv") @@ -67,8 +67,8 @@ describe VehicleJourneyImport, :type => :model do csv_file = update_csv_file_with_factory_data("vehicle_journey_imports_with_vjas_bad_order.csv") double("CSV", :tempfile => csv_file, :original_filename => File.basename(csv_file), :path => File.path(csv_file) ) } - - subject { VehicleJourneyImport.new(:route => route, :file => valid_file) } + + subject { VehicleJourneyImport.new(:route => route, :file => valid_file) } describe ".save" do @@ -86,33 +86,33 @@ describe VehicleJourneyImport, :type => :model do expect(Chouette::VehicleJourneyAtStop.all.size).to eq(17) end - it "should not import vehicle_journeys and not create objects when vehicle journey at stops are not in ascendant order" do + it "should not import vehicle_journeys and not create objects when vehicle journey at stops are not in ascendant order", :skip => "Time gap validation is in pending status" do expect(VehicleJourneyImport.new(:route => route, :file => invalid_file_on_vjas_object).save).to be_falsey expect(Chouette::VehicleJourney.all.size).to eq(3) expect(Chouette::VehicleJourneyAtStop.all.size).to eq(0) end - + # it "should not import vehicle_journeys and not create objects with invalid file" do # expect(VehicleJourneyImport.new(:file => invalid_file_on_vj, :route => route).save).to be_false # expect(Chouette::VehicleJourney.all.size).to eq(3) # expect(Chouette::VehicleJourneyAtStop.all.size).to eq(0) # end - + end - describe ".find_journey_pattern_schedule" do + describe ".find_journey_pattern_schedule" do - it "should return journey pattern with same stop points" do + it "should return journey pattern with same stop points" do expect(subject.find_journey_pattern_schedule( 1, { stop_point0.id => "9:00", stop_point1.id => "9:05", stop_point2.id => "9:10", stop_point3.id => "9:15", stop_point4.id => "9:20"} )).to eq(journey_pattern) expect(subject.find_journey_pattern_schedule( 1, { stop_point1.id => "9:00", stop_point3.id => "9:10" } )).to eq(other_journey_pattern) end - it "should return new journey_pattern if no journey pattern with same stop points is founded" do + it "should return new journey_pattern if no journey pattern with same stop points is founded" do expect(subject.find_journey_pattern_schedule( 1, { stop_point0.id => "9:00", stop_point1.id => "9:05", stop_point2.id => nil, stop_point3.id => "9:15", stop_point4.id => "9:20"} )).to be_truthy expect(subject.find_journey_pattern_schedule( 1, { stop_point0.id => "9:00", stop_point1.id => "9:05", stop_point2.id => nil, stop_point3.id => "9:15", stop_point4.id => "9:20"} ).id).not_to eq(journey_pattern.id) expect(subject.find_journey_pattern_schedule( 1, { stop_point0.id => "9:00", stop_point1.id => "9:05", stop_point2.id => nil, stop_point3.id => "9:15", stop_point4.id => "9:20"} ).id).not_to eq(other_journey_pattern.id) end - + end describe ".load_imported_vehicle_journeys" do @@ -122,30 +122,30 @@ describe VehicleJourneyImport, :type => :model do expect { vehicle_journey_import.load_imported_vehicle_journeys }.to raise_error(RuntimeError) end - # it "should return errors when vehicle journeys in file are invalid" do + # it "should return errors when vehicle journeys in file are invalid" do # vehicle_journey_import = VehicleJourneyImport.new(:route => route, :file => invalid_file_on_vj) - + # expect { vehicle_journey_import.load_imported_vehicle_journeys }.to raise_error # end - it "should return errors when vehicle journey at stops in file are invalid" do + it "should return errors when vehicle journey at stops in file are invalid" do vehicle_journey_import = VehicleJourneyImport.new(:route => route, :file => invalid_file_on_vjas) expect { vehicle_journey_import.load_imported_vehicle_journeys }.to raise_error(ArgumentError) end - it "should return errors when vehicle journey at stops are not in ascendant order" do + it "should return errors when vehicle journey at stops are not in ascendant order" do vehicle_journey_import = VehicleJourneyImport.new(:route => route, :file => invalid_file_on_vjas_object) expect(vehicle_journey_import.load_imported_vehicle_journeys.size).to eq(3) expect(vehicle_journey_import.errors.messages).to be_empty end - + it "should load vehicle journeys" do expect(subject.load_imported_vehicle_journeys.size).to eq(4) expect(subject.errors.messages).to eq({}) end - + end - - + + end |
