diff options
Diffstat (limited to 'spec')
| -rw-r--r-- | spec/fixtures/stop_area_import_invalid.csv | 7 | ||||
| -rw-r--r-- | spec/fixtures/stop_area_import_valid.csv | 7 | ||||
| -rw-r--r-- | spec/fixtures/vehicle_journey_imports_valid.csv | 17 | ||||
| -rw-r--r-- | spec/fixtures/vehicle_journey_imports_with_vj_invalid.csv | 17 | ||||
| -rw-r--r-- | spec/fixtures/vehicle_journey_imports_with_vjas_bad_order.csv | 17 | ||||
| -rw-r--r-- | spec/fixtures/vehicle_journey_imports_with_vjas_invalid.csv | 17 | ||||
| -rw-r--r-- | spec/models/stop_area_import_spec.rb | 50 | ||||
| -rw-r--r-- | spec/models/vehicle_journey_import_spec.rb | 18 | ||||
| -rw-r--r-- | spec/requests/stop_area_imports_spec.rb | 34 | ||||
| -rw-r--r-- | spec/requests/vehicle_journey_imports_spec.rb | 8 |
10 files changed, 57 insertions, 135 deletions
diff --git a/spec/fixtures/stop_area_import_invalid.csv b/spec/fixtures/stop_area_import_invalid.csv deleted file mode 100644 index 379c33012..000000000 --- a/spec/fixtures/stop_area_import_invalid.csv +++ /dev/null @@ -1,7 +0,0 @@ -"id","name","longitude","latitude","area_type","parent_id","comment","country_code","street_name","mobility_restricted_suitability","stairs_availability","lift_availability","int_user_needs" -,"StopArea1","0.1","0.1",,,"Comment",,,,,, -,"StopArea2","0.2","0.2",,,"Comment",,,,,, -,"StopArea3","0.3","0.3",,,"Comment",,,,,, -,"StopArea4","0.4","0.4",,,"Comment",,,,,, -,"StopArea5","0.5","0.5",,,"Comment",,,,,, -,"StopArea6","0.6","0.6",,,"Comment",,,,,, diff --git a/spec/fixtures/stop_area_import_valid.csv b/spec/fixtures/stop_area_import_valid.csv deleted file mode 100644 index d3d2c6974..000000000 --- a/spec/fixtures/stop_area_import_valid.csv +++ /dev/null @@ -1,7 +0,0 @@ -"id","name","longitude","latitude","area_type","parent_id","comment","country_code","street_name","mobility_restricted_suitability","stairs_availability","lift_availability","int_user_needs" -,"StopArea1","0.1","0.1","Quay",,"Comment",,,,,, -,"StopArea2","0.2","0.2","Quay",,"Comment",,,,,, -,"StopArea3","0.3","0.3","Quay",,"Comment",,,,,, -,"StopArea4","0.4","0.4","Quay",,"Comment",,,,,, -,"StopArea5","0.5","0.5","Quay",,"Comment",,,,,, -,"StopArea6","0.6","0.6","Quay",,"Comment",,,,,, diff --git a/spec/fixtures/vehicle_journey_imports_valid.csv b/spec/fixtures/vehicle_journey_imports_valid.csv index b20d58ab5..15f66a26f 100644 --- a/spec/fixtures/vehicle_journey_imports_valid.csv +++ b/spec/fixtures/vehicle_journey_imports_valid.csv @@ -1,6 +1,11 @@ -"stop area id","stop area name","import:VehicleJourney:1","import:VehicleJourney:2","import:VehicleJourney:3","" -1,"Arrêt 1","9:00:00",,"11:10:00","12:10:00" -2,"Arrêt 2","9:05:00","10:05:00","11:15:00","12:15:00" -3,"Arrêt 3","9:10:00",,"11:20:00","12:20:00" -4,"Arrêt 4","9:15:00","10:20:00","11:25:00","12:25:00" -5,"Arrêt 5","9:20:00",,"11:30:00","12:30:00" +;id course;import:VehicleJourney:1;import:VehicleJourney:2;import:VehicleJourney:3; +;numéro;1;2;3;4 +;PMR (O(ui)|N(on)|vide si inconnu);Oui;;; +;TAD (O(ui)|N(on)|vide si inconnu);Oui;;; +;calendriers;;;; +id arrêt;nom arrêt;;;; +1;Arrêt 1;9:00:00;;11:10:00;12:10:00 +2;Arrêt 2;9:05:00;10:05:00;11:15:00;12:15:00 +3;Arrêt 3;9:10:00;;11:20:00;12:20:00 +4;Arrêt 4;9:15:00;10:20:00;11:25:00;12:25:00 +5;Arrêt 5;9:20:00;;11:30:00;12:30:00 diff --git a/spec/fixtures/vehicle_journey_imports_with_vj_invalid.csv b/spec/fixtures/vehicle_journey_imports_with_vj_invalid.csv index 1b7aeb731..6ed6d90b2 100644 --- a/spec/fixtures/vehicle_journey_imports_with_vj_invalid.csv +++ b/spec/fixtures/vehicle_journey_imports_with_vj_invalid.csv @@ -1,6 +1,11 @@ -"stop area id","stop area name",invalid vj,"import:VehicleJourney:2","import:VehicleJourney:3" -1,"Arrêt 1","9:00:00","10:05:00","11:10:00" -2,"Arrêt 2","11:05:00",,"11:15:00" -3,"Arrêt 3","11:10:00","10:20:00","11:20:00" -4,"Arrêt 4","11:15:00",,"11:25:00" -5,"Arrêt 5","9:20:00","10:30:00","11:30:00" +;id course;invalid vj;import:VehicleJourney:2;import:VehicleJourney:3 +;numéro;1;2;3 +;PMR (O(ui)|N(on)|vide si inconnu);Oui;; +;TAD (O(ui)|N(on)|vide si inconnu);Oui;; +;calendriers;;; +id arrêt;nom arrêt;;; +1;Arrêt 1;9:00:00;10:05:00;11:10:00 +2;Arrêt 2;11:05:00;;11:15:00 +3;Arrêt 3;11:10:00;10:20:00;11:20:00 +4;Arrêt 4;11:15:00;;11:25:00 +5;Arrêt 5;9:20:00;10:30:00;11:30:00 diff --git a/spec/fixtures/vehicle_journey_imports_with_vjas_bad_order.csv b/spec/fixtures/vehicle_journey_imports_with_vjas_bad_order.csv index 4096616ab..d4da585d0 100644 --- a/spec/fixtures/vehicle_journey_imports_with_vjas_bad_order.csv +++ b/spec/fixtures/vehicle_journey_imports_with_vjas_bad_order.csv @@ -1,6 +1,11 @@ -"stop area id","stop area name","import:VehicleJourney:1","import:VehicleJourney:2","" -1,"Arrêt 1","9:05:00","10:05:00","11:10:00" -2,"Arrêt 2","11:05:00",,"11:15:00" -3,"Arrêt 3","9:10:00","10:20:00","11:20:00" -4,"Arrêt 4","9:15:00","10:25:00","11:25:00" -5,"Arrêt 5","9:20:00","10:30:00","11:30:00" +;id course;import:VehicleJourney:1;import:VehicleJourney:2; +;numéro;1;2;3 +;PMR (O(ui)|N(on)|vide si inconnu);Oui;; +;TAD (O(ui)|N(on)|vide si inconnu);Oui;; +;calendriers;;; +id arrêt;nom arrêt;;; +1;Arrêt 1;9:05:00;10:05:00;11:10:00 +2;Arrêt 2;11:05:00;;11:15:00 +3;Arrêt 3;9:10:00;10:20:00;11:20:00 +4;Arrêt 4;9:15:00;10:25:00;11:25:00 +5;Arrêt 5;9:20:00;10:30:00;11:30:00 diff --git a/spec/fixtures/vehicle_journey_imports_with_vjas_invalid.csv b/spec/fixtures/vehicle_journey_imports_with_vjas_invalid.csv index c5e9e32b1..687f6b09a 100644 --- a/spec/fixtures/vehicle_journey_imports_with_vjas_invalid.csv +++ b/spec/fixtures/vehicle_journey_imports_with_vjas_invalid.csv @@ -1,6 +1,11 @@ -"stop area id","stop area name","import:VehicleJourney:1","import:VehicleJourney:2","" -1,"Arrêt 1",invalid time,"10:05:00","11:10:00" -2,"Arrêt 2","9:05:00",,"11:15:00" -3,"Arrêt 3","9:10:00","10:20:00","11:20:00" -4,"Arrêt 4","9:15:00",,"11:25:00" -5,"Arrêt 5","9:20:00","10:30:00","11:30:00" +;id course;import:VehicleJourney:1;import:VehicleJourney:2; +;numéro;1;2;3 +;PMR (O(ui)|N(on)|vide si inconnu);Oui;; +;TAD (O(ui)|N(on)|vide si inconnu);Oui;; +;calendriers;;;; +id arrêt;nom arrêt;;; +1;Arrêt 1;invalid time;10:05:00;11:10:00 +2;Arrêt 2;9:05:00;;11:15:00 +3;Arrêt 3;9:10:00;10:20:00;11:20:00 +4;Arrêt 4;9:15:00;;11:25:00 +5;Arrêt 5;9:20:00;10:30:00;11:30:00 diff --git a/spec/models/stop_area_import_spec.rb b/spec/models/stop_area_import_spec.rb deleted file mode 100644 index 07f3a111b..000000000 --- a/spec/models/stop_area_import_spec.rb +++ /dev/null @@ -1,50 +0,0 @@ -# -*- coding: utf-8 -*- -require 'spec_helper' - -describe StopAreaImport do - - let(:valid_file) { - csv_file = File.open(Rails.root.join("spec", "fixtures", "stop_area_import_valid.csv").to_s, "r") - mock("CSV", :tempfile => csv_file, :original_filename => File.basename(csv_file), :path => File.path(csv_file) ) - } - - let(:invalid_file) { - csv_file = File.open(Rails.root.join("spec", "fixtures", "stop_area_import_invalid.csv").to_s, "r") - mock("CSV", :tempfile => csv_file, :original_filename => File.basename(csv_file), :path => File.path(csv_file) ) - } - - subject { StopAreaImport.new(:file => valid_file) } - - describe ".save" do - - it "should validate presence of file" do - expect(StopAreaImport.new.save).to be_false - end - - it "should import stop areas and create the right number of objects" do - expect(StopAreaImport.new(:file => valid_file).save).to be_true - expect(Chouette::StopArea.all.size).to eq(6) - end - - it "should not import vehicle_journeys and not create objects when vehicle journey at stops are not in ascendant order" do - expect(StopAreaImport.new(:file => invalid_file).save).to be_false - expect(Chouette::StopArea.all.size).to eq(0) - end - - end - - describe ".load_imported_stop_areas" do - - # it "should return errors when stop_areas in file are invalid" do - # stop_area_import = StopAreaImport.new(:referential => referential, :file => invalid_file) - # expect { stop_area_import.load_imported_stop_areas }.to raise_exception - # end - - it "should load stop ateas" do - expect(subject.load_imported_stop_areas.size).to eq(6) - expect(subject.errors.messages).to eq({}) - end - - end - -end diff --git a/spec/models/vehicle_journey_import_spec.rb b/spec/models/vehicle_journey_import_spec.rb index 07cd921bb..f6e82bccb 100644 --- a/spec/models/vehicle_journey_import_spec.rb +++ b/spec/models/vehicle_journey_import_spec.rb @@ -4,13 +4,13 @@ require 'spec_helper' describe VehicleJourneyImport do def update_csv_file_with_factory_data(filename) - csv_file = CSV.open("/tmp/#{filename}", "wb") do |csv| + csv_file = CSV.open("/tmp/#{filename}", "wb",{ :col_sep => ";"}) do |csv| counter = 0 - CSV.foreach( Rails.root.join("spec", "fixtures", "#{filename}").to_s ) do |row| - if counter == 0 + CSV.foreach( Rails.root.join("spec", "fixtures", "#{filename}").to_s , {:col_sep => ";"}) do |row| + if counter < 6 csv << row else - csv << ( row[0] = route.stop_points[counter - 1].id; row) + csv << ( row[0] = route.stop_points[counter - 6].id; row) end counter += 1 end @@ -93,14 +93,14 @@ describe VehicleJourneyImport do describe ".find_journey_pattern_schedule" do it "should return journey pattern with same stop points" do - expect(subject.find_journey_pattern_schedule( { 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( { stop_point1.id => "9:00", stop_point3.id => "9:10" } )).to eq(other_journey_pattern) + 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 - expect(subject.find_journey_pattern_schedule( { 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_true - expect(subject.find_journey_pattern_schedule( { 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( { 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) + 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_true + 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 diff --git a/spec/requests/stop_area_imports_spec.rb b/spec/requests/stop_area_imports_spec.rb deleted file mode 100644 index c0da1edac..000000000 --- a/spec/requests/stop_area_imports_spec.rb +++ /dev/null @@ -1,34 +0,0 @@ -# -*- coding: utf-8 -*- -require 'spec_helper' - -describe "StopAreaImports" do - login_user - - let!(:line) { create :line } - let!(:valid_file_path) { Rails.root + "spec/fixtures/stop_area_import_valid.csv" } - let!(:invalid_file_path) { Rails.root + "spec/fixtures/stop_area_import_invalid.csv" } - - describe "new" do - it "should create stop areas and return to stop areas index page" do - visit new_referential_stop_area_import_path(referential) - attach_file('Fichier', valid_file_path) - click_button "Lancer l'import" - expect(page).to have_content(I18n.t("stop_area_imports.new.success")) - expect(page).to have_content("StopArea1") - end - - it "should return error messages when file is invalid" do - visit new_referential_stop_area_import_path(referential) - attach_file('Fichier', invalid_file_path) - click_button "Lancer l'import" - expect(page).to have_content(I18n.t("stop_area_imports.errors.import_aborted")) - end - - it "should return error message when file missing on upload" do - visit new_referential_stop_area_import_path(referential) - click_button "Lancer l'import" - expect(page).to have_content(I18n.t("stop_area_imports.errors.import_aborted")) - end - end - -end diff --git a/spec/requests/vehicle_journey_imports_spec.rb b/spec/requests/vehicle_journey_imports_spec.rb index c7a772fd3..5197d4c70 100644 --- a/spec/requests/vehicle_journey_imports_spec.rb +++ b/spec/requests/vehicle_journey_imports_spec.rb @@ -17,13 +17,13 @@ describe "VehicleJourneyImports" do } def update_csv_file_with_factory_data(filename) - csv_file = CSV.open("/tmp/#{filename}", "wb") do |csv| + csv_file = CSV.open("/tmp/#{filename}", "wb",{ :col_sep => ";"}) do |csv| counter = 0 - CSV.foreach( Rails.root.join("spec", "fixtures", "#{filename}").to_s ) do |row| - if counter == 0 + CSV.foreach( Rails.root.join("spec", "fixtures", "#{filename}").to_s , {:col_sep => ";"}) do |row| + if counter < 6 csv << row else - csv << ( row[0] = route.stop_points[counter - 1].id; row) + csv << ( row[0] = route.stop_points[counter - 6].id; row) end counter += 1 end |
