aboutsummaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
authorZog2018-03-05 09:11:34 +0100
committerZog2018-03-05 09:11:34 +0100
commitea3de6035cdf9fbbcd92f51c90e5a2c5c3400cb3 (patch)
treed35feb918791f94d69ebb97bf1224d8a96b60796 /spec
parentc1ac12174b9aff7535a84af9f76d1cda95b750f4 (diff)
downloadchouette-core-ea3de6035cdf9fbbcd92f51c90e5a2c5c3400cb3.tar.bz2
Refs #6068; Export VehicleJourneys
Add a mechanism to allow for several rows in the csv per single object in the collection.
Diffstat (limited to 'spec')
-rw-r--r--spec/models/simple_exporter_spec.rb86
1 files changed, 66 insertions, 20 deletions
diff --git a/spec/models/simple_exporter_spec.rb b/spec/models/simple_exporter_spec.rb
index 395cb1034..18cdc55e8 100644
--- a/spec/models/simple_exporter_spec.rb
+++ b/spec/models/simple_exporter_spec.rb
@@ -44,29 +44,75 @@ RSpec.describe SimpleExporter do
let(:filename){ "stop_area.csv" }
# let(:stop_area_referential){ create(:stop_area_referential, objectid_format: :stif_netex) }
- before(:each) do
- @stop_area = create :stop_area
- SimpleExporter.define :test do |config|
- config.collection = ->{ Chouette::StopArea.all }
- config.separator = ";"
- config.add_column :name
- config.add_column :lat, attribute: :latitude
- config.add_column :lng, attribute: :latitude, value: ->(raw){ raw.to_f + 1 }
- config.add_column :type, attribute: :area_type
- config.add_column :street_name, value: "Lil Exporter"
+ context "with one row per item" do
+ before(:each) do
+ @stop_area = create :stop_area
+ SimpleExporter.define :test do |config|
+ config.collection = ->{ Chouette::StopArea.all }
+ config.separator = ";"
+ config.add_column :name
+ config.add_column :lat, attribute: :latitude
+ config.add_column :lng, attribute: [:latitude, :to_i, :next]
+ config.add_column :type, attribute: :area_type
+ config.add_column :street_name, value: "Lil Exporter"
+ config.on_relation :stop_area_referential do
+ config.add_column :stop_area_referential_id, attribute: :id
+ config.add_column :stop_area_referential_id_other, value: ->(item){ item.id }
+ end
+ config.add_column :forty_two, value: 42
+ end
+ end
+
+ it "should export the given file" do
+ expect{exporter.export verbose: true}.to_not raise_error
+ expect(exporter.status).to eq "success"
+ expect(File.exists?(filepath)).to be_truthy
+ csv = CSV.read(filepath, headers: true, col_sep: ";")
+ row = csv.by_row.values_at(0).last
+ expect(row["name"]).to eq @stop_area.name
+ expect(row["lat"]).to eq @stop_area.latitude.to_s
+ expect(row["lng"]).to eq (@stop_area.latitude.to_i + 1).to_s
+ expect(row["street_name"]).to eq "Lil Exporter"
+ expect(row["stop_area_referential_id"]).to eq @stop_area.stop_area_referential_id.to_s
+ expect(row["stop_area_referential_id_other"]).to eq @stop_area.stop_area_referential_id.to_s
+ expect(row["forty_two"]).to eq "42"
end
end
- it "should export the given file" do
- expect{exporter.export verbose: true}.to_not raise_error
- expect(exporter.status).to eq "success"
- expect(File.exists?(filepath)).to be_truthy
- csv = CSV.read(filepath, headers: true, col_sep: ";")
- row = csv.by_row.values_at(0).last
- expect(row["name"]).to eq @stop_area.name
- expect(row["lat"]).to eq @stop_area.latitude.to_s
- expect(row["lng"]).to eq (@stop_area.latitude.to_f + 1).to_s
- expect(row["street_name"]).to eq "Lil Exporter"
+ context "with several rows for the same object" do
+ before(:each) do
+ @stop_area = create :stop_area
+ @stop_1 = create :stop_point, stop_area: @stop_area
+ @stop_2 = create :stop_point, stop_area: @stop_area
+ SimpleExporter.define :test do |config|
+ config.collection = ->{ Chouette::StopArea.all }
+ config.map_item_to_rows do |stop_area|
+ stop_area.stop_points.map do |sp|
+ {
+ id: sp.id,
+ stop_area: stop_area
+ }
+ end
+ end
+ config.add_column :id
+ config.on_relation :stop_area do
+ config.add_column :stop_area_name, attribute: :name
+ end
+ end
+ end
+
+ it "should export the given file" do
+ expect{exporter.export verbose: true}.to_not raise_error
+ expect(exporter.status).to eq "success"
+ expect(File.exists?(filepath)).to be_truthy
+ csv = CSV.read(filepath, headers: true)
+ row = csv.by_row.values_at(0).last
+ expect(row["id"]).to eq @stop_1.id.to_s
+ expect(row["stop_area_name"]).to eq @stop_area.name
+ row = csv.by_row.values_at(1).last
+ expect(row["id"]).to eq @stop_2.id.to_s
+ expect(row["stop_area_name"]).to eq @stop_area.name
+ end
end
end
end