diff options
| author | Xinhui | 2017-07-26 16:17:27 +0200 |
|---|---|---|
| committer | Xinhui | 2017-07-26 16:17:27 +0200 |
| commit | 4cdc8f384e9bf0b794d40d3c9820577aaedc2d17 (patch) | |
| tree | 9faad77aa4c67c5f8db0b4dbfc199524f002d8f7 /spec/models | |
| parent | 33b4fe1f39501ca36b7a32421e9e1fea93f89e12 (diff) | |
| download | chouette-core-4cdc8f384e9bf0b794d40d3c9820577aaedc2d17.tar.bz2 | |
Fix objectid in vehicle journey import & export spec
Diffstat (limited to 'spec/models')
| -rw-r--r-- | spec/models/vehicle_journey_export_spec.rb | 34 | ||||
| -rw-r--r-- | spec/models/vehicle_journey_import_spec.rb | 54 |
2 files changed, 44 insertions, 44 deletions
diff --git a/spec/models/vehicle_journey_export_spec.rb b/spec/models/vehicle_journey_export_spec.rb index 6252a73f9..83b3bbb04 100644 --- a/spec/models/vehicle_journey_export_spec.rb +++ b/spec/models/vehicle_journey_export_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' describe VehicleJourneyExport, :type => :model do - + let!(:line) { create(:line) } let!(:route) { create(:route, :line => line) } let!(:other_route) { create(:route, :line => line) } @@ -10,10 +10,10 @@ describe VehicleJourneyExport, :type => :model do let!(:journey_pattern) { create(:journey_pattern, :route => route) } let!(:other_journey_pattern) { create(:journey_pattern_even, :route => route) } - let!(:vehicle_journey1) { create(:vehicle_journey_common, :objectid => "export:VehicleJourney:1", :route_id => route.id, :journey_pattern_id => journey_pattern.id) } - let!(:vehicle_journey2) { create(:vehicle_journey_common, :objectid => "export:VehicleJourney:2", :route_id => route.id, :journey_pattern_id => other_journey_pattern.id) } - let!(:vehicle_journey3) { create(:vehicle_journey_common, :objectid => "export:VehicleJourney:3", :route_id => route.id, :journey_pattern_id => journey_pattern.id) } - + let!(:vehicle_journey1) { create(:vehicle_journey_common, :objectid => "export:VehicleJourney:1:loc", :route_id => route.id, :journey_pattern_id => journey_pattern.id) } + let!(:vehicle_journey2) { create(:vehicle_journey_common, :objectid => "export:VehicleJourney:2:loc", :route_id => route.id, :journey_pattern_id => other_journey_pattern.id) } + let!(:vehicle_journey3) { create(:vehicle_journey_common, :objectid => "export:VehicleJourney:3:loc", :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] } @@ -21,10 +21,10 @@ describe VehicleJourneyExport, :type => :model do let!(:stop_point4) { route.stop_points[4] } let!(:time_table) { create(:time_table)} - - subject { VehicleJourneyExport.new(:vehicle_journeys => route.vehicle_journeys, :route => route) } - describe ".tt_day_types" do + subject { VehicleJourneyExport.new(:vehicle_journeys => route.vehicle_journeys, :route => route) } + + describe ".tt_day_types" do it "should return no day_type" do time_table.int_day_types = 0 @@ -35,10 +35,10 @@ describe VehicleJourneyExport, :type => :model do time_table.int_day_types = 4|8|16|32|64|128|256 expect(subject.tt_day_types(time_table)).to eq("LuMaMeJeVeSaDi") end - + end - describe ".tt_periods" do + describe ".tt_periods" do it "should return empty period" do time_table.periods.clear @@ -50,10 +50,10 @@ describe VehicleJourneyExport, :type => :model do time_table.periods << Chouette::TimeTablePeriod.new(:period_start => Date.new(2014,8,1), :period_end => Date.new(2014,8,8)) expect(subject.tt_periods(time_table)).to eq("[2014-08-01 -> 2014-08-08] ") end - + end - - describe ".tt_included_days" do + + describe ".tt_included_days" do it "should return empty included dates" do time_table.dates.clear @@ -65,10 +65,10 @@ describe VehicleJourneyExport, :type => :model do time_table.dates << Chouette::TimeTableDate.new(:date => Date.new(2014,8,1), :in_out => true) expect(subject.tt_peculiar_days(time_table)).to eq("2014-08-01 ") end - + end - describe ".tt_excluded_days" do + describe ".tt_excluded_days" do it "should return empty excluded dates" do time_table.dates.clear @@ -80,7 +80,7 @@ describe VehicleJourneyExport, :type => :model do time_table.dates << Chouette::TimeTableDate.new(:date => Date.new(2014,8,1), :in_out => false) expect(subject.tt_excluded_days(time_table)).to eq("2014-08-01 ") end - + end - + end diff --git a/spec/models/vehicle_journey_import_spec.rb b/spec/models/vehicle_journey_import_spec.rb index a743bdecb..e5f4e3b22 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,24 +29,24 @@ describe VehicleJourneyImport, :type => :model do File.open("/tmp/#{filename}") end - + let!(:route) { create(:route) } let!(:other_route) { create(:route) } let!(:journey_pattern) { create(:journey_pattern, :route => route) } let!(:other_journey_pattern) { create(:journey_pattern_even, :route => route) } - 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!(:vehicle_journey1) { create(:vehicle_journey_common, :objectid => "import:VehicleJourney:1:loc", :route_id => route.id, :journey_pattern_id => journey_pattern.id) } + let!(:vehicle_journey2) { create(:vehicle_journey_common, :objectid => "import:VehicleJourney:2:loc", :route_id => route.id, :journey_pattern_id => other_journey_pattern.id) } + let!(:vehicle_journey3) { create(:vehicle_journey_common, :objectid => "import:VehicleJourney:3:loc", :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" 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 |
