diff --git a/spec/integration/mh_spec.rb b/spec/integration/mh_spec.rb new file mode 100644 index 0000000..ec7347f --- /dev/null +++ b/spec/integration/mh_spec.rb @@ -0,0 +1,30 @@ +require 'spec_helper' + +describe Neography::Rest do + before(:each) do + @neo = Neography::Rest.new + end + + describe "the spatial plugin works" do + it "better work" do + @neo.create_spatial_index("geom", "point", "lat", "lon") + node = @neo.create_node({:lat => 60.1, :lon => 15.2}) + added = @neo.add_node_to_index("geom", "dummy", "dummy", node) + existing_node = @neo.execute_query("start node = node:geom('withinDistance:[60.0,15.0, 100.0]') return node") + puts existing_node.inspect + end + + it "can find a geometry in a bounding box using cypher" do + properties = {:lat => 60.1, :lon => 15.2} + @neo.create_spatial_index("geombbcypher", "point", "lat", "lon") + node = @neo.create_node(properties) + added = @neo.add_node_to_index("geombbcypher", "dummy", "dummy", node) + existing_node = @neo.execute_query("start node = node:geombbcypher('withinDistance:[60.0,15.0, 100.0]') return node") + puts existing_node.inspect + existing_node["data"][0][0]["data"].should_not be_empty + existing_node["data"][0][0]["data"]["lat"].should == properties[:lat] + existing_node["data"][0][0]["data"]["lon"].should == properties[:lon] + end + + end +end \ No newline at end of file diff --git a/spec/integration/rest_spatial_spec.rb b/spec/integration/rest_spatial_spec.rb index a062f1d..3740435 100644 --- a/spec/integration/rest_spatial_spec.rb +++ b/spec/integration/rest_spatial_spec.rb @@ -104,13 +104,14 @@ end it "can find a geometry in a bounding box using cypher" do - node = @neo.execute_query("start n = node:restaurants({bbox}) return n", {:bbox => "bbox:[87.5,87.7,41.7,41.9]"}) - #node = @neo.execute_query("start n = node:restaurants({bbox}) return n", {:bbox => "bbox:[87.6278,41.8819,87.6278,41.8819]"}) - node.should_not be_empty - puts node.inspect - node.first["data"]["lat"].should == properties[:lat] - node.first["data"]["lon"].should == properties[:lon] - node.first["data"]["name"].should == "Max's Restaurant" + properties = {:lat => 60.1, :lon => 15.2} + @neo.create_spatial_index("geombbcypher", "point", "lat", "lon") + node = @neo.create_node(properties) + added = @neo.add_node_to_index("geombbcypher", "dummy", "dummy", node) + existing_node = @neo.execute_query("start node = node:geombbcypher('bbox:[15.0,15.3,60.0,60.2]') return node") + existing_node.should_not be_empty + existing_node["data"][0][0]["data"]["lat"].should == properties[:lat] + existing_node["data"][0][0]["data"]["lon"].should == properties[:lon] end end @@ -125,44 +126,16 @@ end it "can find a geometry within distance using cypher" do - properties = {:name => "Max's Restaurant", :lat => 41.8819, :lon => 87.6278} - node = @neo.execute_query("start n = node:restaurants({bbox}) return n", {:bbox => "withinDistance:[87.6278,41.8819,10.0]"}) - node.should_not be_empty - puts node.inspect - node.first["data"]["lat"].should == properties[:lat] - node.first["data"]["lon"].should == properties[:lon] - node.first["data"]["name"].should == "Max's Restaurant" - end - end - - describe "complete example" do - it "can do what the manual does" do - @neo.add_point_layer("geom", "lat", "lon") - node = @neo.create_node({:lat => 60.1, :lon => 15.2}) - @neo.create_spatial_index("geom", "point", "lat", "lon") - @neo.add_node_to_layer("geom", node) - - existing_node = @neo.find_geometries_in_bbox("geom", 15.0,15.3,60.0,60.3) - existing_node.first["data"]["lat"].should == 60.1 - existing_node.first["data"]["lon"].should == 15.2 - - existing_node = @neo.find_geometries_within_distance("geom", 15.0, 60.0, 100.0) - existing_node.first["data"]["lat"].should == 60.1 - existing_node.first["data"]["lon"].should == 15.2 - - added = @neo.add_node_to_index("geom", "dummy", "dummy", node) - existing_node = @neo.execute_query("start node = node:geom(\'bbox:[15.0,15.3,60.0,60.2]\') return node") - puts existing_node.inspect - existing_node.first["data"]["lat"].should == 60.1 - existing_node.first["data"]["lon"].should == 15.2 - - existing_node = @neo.execute_query("start node = node:geom(\'withinDistance:[60.0,15.0, 100.0]\') return node") - puts existing_node.inspect - existing_node.first["data"]["lat"].should == 60.1 - existing_node.first["data"]["lon"].should == 15.2 - + properties = {:lat => 60.1, :lon => 15.2} + @neo.create_spatial_index("geowdcypher", "point", "lat", "lon") + node = @neo.create_node(properties) + added = @neo.add_node_to_index("geowdcypher", "dummy", "dummy", node) + existing_node = @neo.execute_query("start n = node:geowdcypher({bbox}) return n", {:bbox => "withinDistance:[60.0,15.0,100.0]"}) + existing_node.should_not be_empty + existing_node.should_not be_empty + existing_node["data"][0][0]["data"]["lat"].should == properties[:lat] + existing_node["data"][0][0]["data"]["lon"].should == properties[:lon] end end - - + end \ No newline at end of file