aboutsummaryrefslogtreecommitdiffstats
path: root/spec/models
diff options
context:
space:
mode:
authorMichel Etienne2014-09-09 17:19:31 +0200
committerMichel Etienne2014-09-09 17:19:31 +0200
commit298a091329613f2515da94f99678157e75c07063 (patch)
treee1b57b49fd5e99794ce4fbc6e8ef03d0a8d70a73 /spec/models
parent06da44f2fbcda37e7fc7178799452d49e6d60c8b (diff)
downloadchouette-core-298a091329613f2515da94f99678157e75c07063.tar.bz2
vehicle journey imports enhancement
Diffstat (limited to 'spec/models')
-rw-r--r--spec/models/stop_area_import_spec.rb50
-rw-r--r--spec/models/vehicle_journey_import_spec.rb18
2 files changed, 9 insertions, 59 deletions
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