spec/import_spec.rb in cartodb-importer-0.2.14 vs spec/import_spec.rb in cartodb-importer-0.2.15

- old
+ new

@@ -252,11 +252,11 @@ db_connection = Sequel.connect("postgres://#{options[:username]}:#{options[:password]}@#{options[:host]}:#{options[:port]}/#{options[:database]}") db_connection.tables.should include(:vizzuality) columns = db_connection.schema(:vizzuality).map{|s| s[0].to_s} expected_columns = ["gid", "subclass", "x", "y", "length", "area", "angle", "name", - "pid", "lot_navteq", "version_na", "vitesse_sp", "id", "nombrerest", "tipocomida", "the_geom"] + "pid", "lot_navteq", "version_na", "vitesse_sp", "id", "nombrerest", "tipocomida"] (columns & expected_columns).sort.should == expected_columns.sort end it "should import SHP file TM_WORLD_BORDERS_SIMPL-0.3.zip" do importer = CartoDB::Importer.new :import_from_file => File.expand_path("../support/data/TM_WORLD_BORDERS_SIMPL-0.3.zip", __FILE__), @@ -344,11 +344,11 @@ #result.import_type.should == '.shp' end end describe "Import CSV with latidude/logitude" do - it "should import estaciones2.csv" do + it "should import walmart.csv" do importer = CartoDB::Importer.new :import_from_file => File.expand_path("../support/data/walmart.csv", __FILE__), :database => "cartodb_importer_test", :username => 'postgres', :password => '', :host => 'localhost', :port => 5432, :suggested_name => 'walmart' result = importer.import! result.name.should == 'walmart' @@ -356,18 +356,64 @@ result.import_type.should == '.csv' end end describe "Import CSV with lat/lon" do - it "should import estaciones2.csv" do + it "should import walmart.csv" do importer = CartoDB::Importer.new :import_from_file => File.expand_path("../support/data/walmart_latlon.csv", __FILE__), :database => "cartodb_importer_test", :username => 'postgres', :password => '', :host => 'localhost', :port => 5432, :suggested_name => 'walmart_latlon' result = importer.import! result.name.should == 'walmart_latlon' #result.rows_imported.should == 30 result.import_type.should == '.csv' end end + + describe "Import CartoDB CSV export with lat/lon" do + it "should import CartoDB_csv_export.zip" do + importer = CartoDB::Importer.new :import_from_file => File.expand_path("../support/data/CartoDB_csv_export.zip", __FILE__), + :database => "cartodb_importer_test", :username => 'postgres', :password => '', + :host => 'localhost', :port => 5432, :suggested_name => 'cartodb_csv_export' + result = importer.import! + result.name.should == 'cartodb_csv_export' + result.rows_imported.should == 155 + result.import_type.should == '.csv' + end + end + + # TODO: check that the_geom is now a real geometry built from geojson. + describe "Import CartoDB CSV export with the_geom in geojson" do + it "should import CartoDB_csv_multipoly_export.zip" do + opt = {:import_from_file => File.expand_path("../support/data/CartoDB_csv_multipoly_export.zip", __FILE__), + :database => "cartodb_importer_test", :username => 'postgres', :password => '', + :host => 'localhost', :port => 5432, :suggested_name => 'cartodb_csv_multipoly_export'} + importer = CartoDB::Importer.new opt + result = importer.import! + result.name.should == 'cartodb_csv_multipoly_export' + result.rows_imported.should == 601 + result.import_type.should == '.csv' + + # test geometry returned is legit + pg = "postgres://#{opt[:username]}:#{opt[:password]}@#{opt[:host]}:#{opt[:port]}/#{opt[:database]}" + sql = "select ST_AsGeoJSON(the_geom,0) as geom from cartodb_csv_multipoly_export limit 1" + db_connection = Sequel.connect(pg) + res = db_connection[sql].first[:geom] + res.should == '{"type":"MultiPolygon","coordinates":[[[[2,39],[2,39],[2,39],[2,39],[2,39]]]]}' + end + end + + describe "Import CartoDB SHP export with lat/lon" do + it "should import CartoDB_shp_export.zip" do + importer = CartoDB::Importer.new :import_from_file => File.expand_path("../support/data/CartoDB_shp_export.zip", __FILE__), + :database => "cartodb_importer_test", :username => 'postgres', :password => '', + :host => 'localhost', :port => 5432, :suggested_name => 'cartodb_shp_export' + result = importer.import! + result.name.should == 'cartodb_shp_export' + result.rows_imported.should == 155 + result.import_type.should == '.shp' + end + end + end