neography 1.3.14 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. checksums.yaml +4 -4
  2. data/lib/neography/rest.rb +29 -472
  3. data/lib/neography/rest/batch.rb +80 -87
  4. data/lib/neography/rest/clean.rb +8 -10
  5. data/lib/neography/rest/constraints.rb +15 -25
  6. data/lib/neography/rest/cypher.rb +2 -6
  7. data/lib/neography/rest/extensions.rb +4 -8
  8. data/lib/neography/rest/gremlin.rb +2 -6
  9. data/lib/neography/rest/helpers.rb +58 -0
  10. data/lib/neography/rest/node_auto_indexes.rb +54 -8
  11. data/lib/neography/rest/node_indexes.rb +92 -17
  12. data/lib/neography/rest/node_labels.rb +15 -26
  13. data/lib/neography/rest/node_paths.rb +8 -16
  14. data/lib/neography/rest/node_properties.rb +45 -4
  15. data/lib/neography/rest/node_relationships.rb +8 -17
  16. data/lib/neography/rest/node_traversal.rb +7 -63
  17. data/lib/neography/rest/nodes.rb +21 -29
  18. data/lib/neography/rest/other_node_relationships.rb +6 -13
  19. data/lib/neography/rest/relationship_auto_indexes.rb +54 -8
  20. data/lib/neography/rest/relationship_indexes.rb +104 -14
  21. data/lib/neography/rest/relationship_properties.rb +45 -4
  22. data/lib/neography/rest/relationship_types.rb +4 -11
  23. data/lib/neography/rest/relationships.rb +6 -13
  24. data/lib/neography/rest/schema_indexes.rb +8 -16
  25. data/lib/neography/rest/spatial.rb +16 -33
  26. data/lib/neography/rest/transactions.rb +25 -26
  27. data/lib/neography/tasks.rb +2 -2
  28. data/lib/neography/version.rb +1 -1
  29. data/spec/unit/rest/batch_spec.rb +49 -50
  30. data/spec/unit/rest/clean_spec.rb +3 -4
  31. data/spec/unit/rest/constraints_spec.rb +12 -13
  32. data/spec/unit/rest/cypher_spec.rb +3 -4
  33. data/spec/unit/rest/extensions_spec.rb +5 -6
  34. data/spec/unit/rest/gremlin_spec.rb +5 -6
  35. data/spec/unit/rest/helpers_spec.rb +124 -0
  36. data/spec/unit/rest/labels_spec.rb +21 -22
  37. data/spec/unit/rest/node_auto_indexes_spec.rb +23 -24
  38. data/spec/unit/rest/node_indexes_spec.rb +42 -43
  39. data/spec/unit/rest/node_paths_spec.rb +10 -13
  40. data/spec/unit/rest/node_properties_spec.rb +22 -23
  41. data/spec/unit/rest/node_relationships_spec.rb +18 -39
  42. data/spec/unit/rest/node_traversal_spec.rb +4 -97
  43. data/spec/unit/rest/nodes_spec.rb +47 -48
  44. data/spec/unit/rest/relationship_auto_indexes_spec.rb +23 -24
  45. data/spec/unit/rest/relationship_indexes_spec.rb +42 -43
  46. data/spec/unit/rest/relationship_properties_spec.rb +22 -23
  47. data/spec/unit/rest/relationship_types_spec.rb +3 -4
  48. data/spec/unit/rest/relationships_spec.rb +5 -6
  49. data/spec/unit/rest/schema_index_spec.rb +7 -8
  50. data/spec/unit/rest/transactions_spec.rb +10 -11
  51. metadata +27 -31
  52. data/lib/neography/rest/auto_indexes.rb +0 -64
  53. data/lib/neography/rest/indexes.rb +0 -102
  54. data/lib/neography/rest/paths.rb +0 -46
  55. data/lib/neography/rest/properties.rb +0 -56
  56. data/spec/unit/rest/paths_spec.rb +0 -69
@@ -4,12 +4,11 @@ module Neography
4
4
  class Rest
5
5
  describe Clean do
6
6
 
7
- let(:connection) { double }
8
- subject { Clean.new(connection) }
7
+ subject { Neography::Rest.new }
9
8
 
10
9
  it "cleans the database" do
11
- connection.should_receive(:delete).with("/cleandb/secret-key")
12
- subject.execute
10
+ subject.connection.should_receive(:delete).with("/cleandb/secret-key")
11
+ subject.clean_database("yes_i_really_want_to_clean_the_database")
13
12
  end
14
13
 
15
14
  end
@@ -4,17 +4,16 @@ module Neography
4
4
  class Rest
5
5
  describe Constraints do
6
6
 
7
- let(:connection) { double }
8
- subject { Constraints.new(connection) }
7
+ subject { Neography::Rest.new }
9
8
 
10
9
  it "list constraints" do
11
- connection.should_receive(:get).with("/schema/constraint/")
12
- subject.list
10
+ subject.connection.should_receive(:get).with("/schema/constraint/")
11
+ subject.get_constraints
13
12
  end
14
13
 
15
14
  it "get constraints for a label" do
16
- connection.should_receive(:get).with("/schema/constraint/label")
17
- subject.get("label")
15
+ subject.connection.should_receive(:get).with("/schema/constraint/label")
16
+ subject.get_constraints("label")
18
17
  end
19
18
 
20
19
  it "create a unique constraint for a label" do
@@ -22,23 +21,23 @@ module Neography
22
21
  :body => '{"property_keys":["property"]}',
23
22
  :headers => json_content_type
24
23
  }
25
- connection.should_receive(:post).with("/schema/constraint/label/uniqueness/", options)
26
- subject.create_unique("label", "property")
24
+ subject.connection.should_receive(:post).with("/schema/constraint/label/uniqueness/", options)
25
+ subject.create_unique_constraint("label", "property")
27
26
  end
28
27
 
29
28
  it "get unique constraints for a label" do
30
- connection.should_receive(:get).with("/schema/constraint/label/uniqueness/")
29
+ subject.connection.should_receive(:get).with("/schema/constraint/label/uniqueness/")
31
30
  subject.get_uniqueness("label")
32
31
  end
33
32
 
34
33
  it "get a specific unique constraint for a label" do
35
- connection.should_receive(:get).with("/schema/constraint/label/uniqueness/property")
36
- subject.get_unique("label", "property")
34
+ subject.connection.should_receive(:get).with("/schema/constraint/label/uniqueness/property")
35
+ subject.get_unique_constraint("label", "property")
37
36
  end
38
37
 
39
38
  it "can delete a constraint for a label" do
40
- connection.should_receive(:delete).with("/schema/constraint/label/uniqueness/property")
41
- subject.drop("label","property")
39
+ subject.connection.should_receive(:delete).with("/schema/constraint/label/uniqueness/property")
40
+ subject.drop_constraint("label","property")
42
41
  end
43
42
 
44
43
  end
@@ -4,16 +4,15 @@ module Neography
4
4
  class Rest
5
5
  describe Cypher do
6
6
 
7
- let(:connection) { double(:cypher_path => "/cypher") }
8
- subject { Cypher.new(connection) }
7
+ subject { Neography::Rest.new }
9
8
 
10
9
  it "executes a cypher query" do
11
10
  options = {
12
11
  :body=>"{\"query\":\"SOME QUERY\",\"params\":{\"foo\":\"bar\",\"baz\":\"qux\"}}",
13
12
  :headers=>{"Content-Type"=>"application/json", "Accept"=>"application/json;stream=true;charset=UTF-8"}
14
13
  }
15
- connection.should_receive(:post).with("/cypher", options)
16
- subject.query("SOME QUERY", { :foo => "bar", :baz => "qux" })
14
+ subject.connection.should_receive(:post).with("/cypher", options)
15
+ subject.execute_query("SOME QUERY", { :foo => "bar", :baz => "qux" })
17
16
  end
18
17
 
19
18
  end
@@ -4,14 +4,13 @@ module Neography
4
4
  class Rest
5
5
  describe Extensions do
6
6
 
7
- let(:connection) { double }
8
- subject { Extensions.new(connection) }
7
+ subject { Neography::Rest.new }
9
8
 
10
9
  it "executes an extensions get query" do
11
10
  path = "/unmanaged_extension/test"
12
11
 
13
- connection.should_receive(:get).with(path)
14
- subject.get("/unmanaged_extension/test")
12
+ subject.connection.should_receive(:get).with(path)
13
+ subject.get_extension("/unmanaged_extension/test")
15
14
  end
16
15
 
17
16
  it "executes an extensions post query" do
@@ -20,8 +19,8 @@ module Neography
20
19
  :body=>"{\"foo\":\"bar\",\"baz\":\"qux\"}",
21
20
  :headers=>{"Content-Type"=>"application/json", "Accept"=>"application/json;stream=true"}
22
21
  }
23
- connection.should_receive(:post).with(path, options)
24
- subject.post("/unmanaged_extension/test", { :foo => "bar", :baz => "qux" })
22
+ subject.connection.should_receive(:post).with(path, options)
23
+ subject.post_extension("/unmanaged_extension/test", { :foo => "bar", :baz => "qux" })
25
24
  end
26
25
 
27
26
  end
@@ -4,21 +4,20 @@ module Neography
4
4
  class Rest
5
5
  describe Gremlin do
6
6
 
7
- let(:connection) { double(:gremlin_path => "/gremlin") }
8
- subject { Gremlin.new(connection) }
7
+ subject { Neography::Rest.new }
9
8
 
10
9
  it "executes a gremlin script" do
11
10
  options = {
12
11
  :body=>"{\"script\":\"SOME SCRIPT\",\"params\":{\"foo\":\"bar\",\"baz\":\"qux\"}}",
13
12
  :headers=>{"Content-Type"=>"application/json"}
14
13
  }
15
- connection.should_receive(:post).with("/gremlin", options)
16
- subject.execute("SOME SCRIPT", { :foo => "bar", :baz => "qux" })
14
+ subject.connection.should_receive(:post).with("/ext/GremlinPlugin/graphdb/execute_script", options)
15
+ subject.execute_script("SOME SCRIPT", { :foo => "bar", :baz => "qux" })
17
16
  end
18
17
 
19
18
  it "returns nil if script result is null" do
20
- connection.stub(:post).and_return("null")
21
- subject.execute("", {}).should be_nil
19
+ subject.connection.stub(:post).and_return("null")
20
+ subject.execute_script("", {}).should be_nil
22
21
  end
23
22
 
24
23
  end
@@ -0,0 +1,124 @@
1
+ require 'spec_helper'
2
+
3
+ module Neography
4
+ class Rest
5
+ describe Helpers do
6
+
7
+ subject { Neography::Rest.new }
8
+
9
+ context "directions" do
10
+
11
+ [ :incoming, "incoming", :in, "in" ].each do |direction|
12
+ it "parses 'in' direction" do
13
+ subject.parse_direction(direction).should == "in"
14
+ end
15
+ end
16
+
17
+ [ :outgoing, "outgoing", :out, "out" ].each do |direction|
18
+ it "parses 'out' direction" do
19
+ subject.parse_direction(direction).should == "out"
20
+ end
21
+ end
22
+
23
+ it "parses 'all' direction by default" do
24
+ subject.parse_direction("foo").should == "all"
25
+ end
26
+
27
+ end
28
+
29
+ context "options" do
30
+ let(:traversal) { NodeTraversal.new(nil) }
31
+
32
+ context "order" do
33
+ [ :breadth, "breadth", "breadth first", "breadthFirst", :wide, "wide" ].each do |order|
34
+ it "parses breadth first" do
35
+ subject.send(:parse_order, order).should == "breadth first"
36
+ end
37
+ end
38
+
39
+ it "parses depth first by default" do
40
+ subject.send(:parse_order, "foo").should == "depth first"
41
+ end
42
+ end
43
+
44
+ context "uniqueness" do
45
+ [ :nodeglobal, "node global", "nodeglobal", "node_global" ].each do |order|
46
+ it "parses node global" do
47
+ subject.send(:parse_uniqueness, order).should == "node global"
48
+ end
49
+ end
50
+
51
+ [ :nodepath, "node path", "nodepath", "node_path" ].each do |order|
52
+ it "parses node path" do
53
+ subject.send(:parse_uniqueness, order).should == "node path"
54
+ end
55
+ end
56
+
57
+ [ :noderecent, "node recent", "noderecent", "node_recent" ].each do |order|
58
+ it "parses node recent" do
59
+ subject.send(:parse_uniqueness, order).should == "node recent"
60
+ end
61
+ end
62
+
63
+ [ :relationshipglobal, "relationship global", "relationshipglobal", "relationship_global" ].each do |order|
64
+ it "parses relationship global" do
65
+ subject.send(:parse_uniqueness, order).should == "relationship global"
66
+ end
67
+ end
68
+
69
+ [ :relationshippath, "relationship path", "relationshippath", "relationship_path" ].each do |order|
70
+ it "parses relationship path" do
71
+ subject.send(:parse_uniqueness, order).should == "relationship path"
72
+ end
73
+ end
74
+
75
+ [ :relationshiprecent, "relationship recent", "relationshiprecent", "relationship_recent" ].each do |order|
76
+ it "parses relationship recent" do
77
+ subject.send(:parse_uniqueness, order).should == "relationship recent"
78
+ end
79
+ end
80
+
81
+ it "parses none by default" do
82
+ subject.send(:parse_uniqueness, "foo").should == "none"
83
+ end
84
+ end
85
+
86
+ context "depth" do
87
+ it "parses nil as nil" do
88
+ subject.send(:parse_depth, nil).should be_nil
89
+ end
90
+ it "parses 0 as 1" do
91
+ subject.send(:parse_depth, "0").should == 1
92
+ end
93
+ it "parses integers" do
94
+ subject.send(:parse_depth, "42").should == 42
95
+ end
96
+ end
97
+
98
+ context "type" do
99
+ [ :relationship, "relationship", :relationships, "relationships" ].each do |type|
100
+ it "parses relationship" do
101
+ subject.send(:parse_type, type).should == "relationship"
102
+ end
103
+ end
104
+ [ :path, "path", :paths, "paths" ].each do |type|
105
+ it "parses path" do
106
+ subject.send(:parse_type, type).should == "path"
107
+ end
108
+ end
109
+ [ :fullpath, "fullpath", :fullpaths, "fullpaths" ].each do |type|
110
+ it "parses fullpath" do
111
+ subject.send(:parse_type, type).should == "fullpath"
112
+ end
113
+ end
114
+
115
+ it "parses node by default" do
116
+ subject.send(:parse_type, "foo").should == "node"
117
+ end
118
+ end
119
+ end
120
+
121
+
122
+ end
123
+ end
124
+ end
@@ -4,32 +4,31 @@ module Neography
4
4
  class Rest
5
5
  describe NodeLabels do
6
6
 
7
- let(:connection) { double }
8
- subject { NodeLabels.new(connection) }
7
+ subject { Neography::Rest.new }
9
8
 
10
9
  it "list node labels" do
11
- connection.should_receive(:get).with("/labels")
12
- subject.list
10
+ subject.connection.should_receive(:get).with("/labels")
11
+ subject.list_labels
13
12
  end
14
13
 
15
14
  it "get labels for node" do
16
- connection.should_receive(:get).with("/node/0/labels")
17
- subject.get(0)
15
+ subject.connection.should_receive(:get).with("/node/0/labels")
16
+ subject.get_node_labels(0)
18
17
  end
19
18
 
20
19
  it "get nodes for labels" do
21
- connection.should_receive(:get).with("/label/person/nodes")
22
- subject.get_nodes("person")
20
+ subject.connection.should_receive(:get).with("/label/person/nodes")
21
+ subject.get_nodes_labeled("person")
23
22
  end
24
23
 
25
24
  it "find nodes for labels and property string" do
26
- connection.should_receive(:get).with("/label/person/nodes?name=%22max%22")
27
- subject.find_nodes("person", {:name => "max"})
25
+ subject.connection.should_receive(:get).with("/label/person/nodes?name=%22max%22")
26
+ subject.find_nodes_labeled("person", {:name => "max"})
28
27
  end
29
28
 
30
29
  it "find nodes for labels and property integer" do
31
- connection.should_receive(:get).with("/label/person/nodes?age=26")
32
- subject.find_nodes("person", {:age => 26})
30
+ subject.connection.should_receive(:get).with("/label/person/nodes?age=26")
31
+ subject.find_nodes_labeled("person", {:age => 26})
33
32
  end
34
33
 
35
34
  it "can add a label to a node" do
@@ -37,8 +36,8 @@ module Neography
37
36
  :body => '["Actor"]',
38
37
  :headers => json_content_type
39
38
  }
40
- connection.should_receive(:post).with("/node/0/labels", options)
41
- subject.add(0, ["Actor"])
39
+ subject.connection.should_receive(:post).with("/node/0/labels", options)
40
+ subject.add_label(0, ["Actor"])
42
41
  end
43
42
 
44
43
  it "can add labels to a node" do
@@ -46,8 +45,8 @@ module Neography
46
45
  :body => '["Actor","Director"]',
47
46
  :headers => json_content_type
48
47
  }
49
- connection.should_receive(:post).with("/node/0/labels", options)
50
- subject.add(0, ["Actor", "Director"])
48
+ subject.connection.should_receive(:post).with("/node/0/labels", options)
49
+ subject.add_label(0, ["Actor", "Director"])
51
50
  end
52
51
 
53
52
  it "can set a label to a node" do
@@ -55,8 +54,8 @@ module Neography
55
54
  :body => '["Actor"]',
56
55
  :headers => json_content_type
57
56
  }
58
- connection.should_receive(:put).with("/node/0/labels", options)
59
- subject.set(0, ["Actor"])
57
+ subject.connection.should_receive(:put).with("/node/0/labels", options)
58
+ subject.set_label(0, ["Actor"])
60
59
  end
61
60
 
62
61
  it "can add labels to a node" do
@@ -64,13 +63,13 @@ module Neography
64
63
  :body => '["Actor","Director"]',
65
64
  :headers => json_content_type
66
65
  }
67
- connection.should_receive(:put).with("/node/0/labels", options)
68
- subject.set(0, ["Actor", "Director"])
66
+ subject.connection.should_receive(:put).with("/node/0/labels", options)
67
+ subject.set_label(0, ["Actor", "Director"])
69
68
  end
70
69
 
71
70
  it "can delete a label from a node" do
72
- connection.should_receive(:delete).with("/node/0/labels/Actor")
73
- subject.delete(0,"Actor")
71
+ subject.connection.should_receive(:delete).with("/node/0/labels/Actor")
72
+ subject.delete_label(0,"Actor")
74
73
  end
75
74
 
76
75
  end
@@ -4,62 +4,61 @@ module Neography
4
4
  class Rest
5
5
  describe NodeAutoIndexes do
6
6
 
7
- let(:connection) { double }
8
- subject { NodeAutoIndexes.new(connection) }
7
+ subject { Neography::Rest.new }
9
8
 
10
9
  it "gets a node from an auto index" do
11
- connection.should_receive(:get).with("/index/auto/node/some_key/some_value")
12
- subject.get("some_key", "some_value")
10
+ subject.connection.should_receive(:get).with("/index/auto/node/some_key/some_value")
11
+ subject.get_node_auto_index("some_key", "some_value")
13
12
  end
14
13
 
15
14
  it "returns nil if nothing was found in the auto index" do
16
- connection.stub(:get).and_return(nil)
17
- subject.get("some_key", "some_value").should be_nil
15
+ subject.connection.stub(:get).and_return(nil)
16
+ subject.get_node_auto_index("some_key", "some_value").should be_nil
18
17
  end
19
18
 
20
19
  it "finds by key and value if value passed to #find_or_query" do
21
- connection.should_receive(:get).with("/index/auto/node/some_key/some_value")
22
- subject.find_or_query("some_key", "some_value")
20
+ subject.connection.should_receive(:get).with("/index/auto/node/some_key/some_value")
21
+ subject.find_node_auto_index("some_key", "some_value")
23
22
  end
24
23
 
25
24
  it "finds by query if no value passed to #find_or_query" do
26
- connection.should_receive(:get).with("/index/auto/node/?query=some_query")
27
- subject.find_or_query("some_query")
25
+ subject.connection.should_receive(:get).with("/index/auto/node/?query=some_query")
26
+ subject.find_node_auto_index("some_query")
28
27
  end
29
28
 
30
29
  it "finds by key and value" do
31
- connection.should_receive(:get).with("/index/auto/node/some_key/some_value")
32
- subject.find("some_key", "some_value")
30
+ subject.connection.should_receive(:get).with("/index/auto/node/some_key/some_value")
31
+ subject.find_node_auto_index("some_key", "some_value")
33
32
  end
34
33
 
35
34
  it "finds by query" do
36
- connection.should_receive(:get).with("/index/auto/node/?query=some_query")
37
- subject.query("some_query")
35
+ subject.connection.should_receive(:get).with("/index/auto/node/?query=some_query")
36
+ subject.find_node_auto_index("some_query")
38
37
  end
39
38
 
40
39
  it "gets the status" do
41
- connection.should_receive(:get).with("/index/auto/node/status")
42
- subject.status
40
+ subject.connection.should_receive(:get).with("/index/auto/node/status")
41
+ subject.get_node_auto_index_status
43
42
  end
44
43
 
45
44
  it "sets the status" do
46
- connection.should_receive(:put).with("/index/auto/node/status", hash_match(:body, '"foo"'))
47
- subject.status = "foo"
45
+ subject.connection.should_receive(:put).with("/index/auto/node/status", hash_match(:body, '"foo"'))
46
+ subject.set_node_auto_index_status("foo")
48
47
  end
49
48
 
50
49
  it "gets auto index properties" do
51
- connection.should_receive(:get).with("/index/auto/node/properties")
52
- subject.properties
50
+ subject.connection.should_receive(:get).with("/index/auto/node/properties")
51
+ subject.get_node_auto_index_properties
53
52
  end
54
53
 
55
54
  it "adds a property to an auto index" do
56
- connection.should_receive(:post).with("/index/auto/node/properties", hash_match(:body, "foo"))
57
- subject.add_property("foo")
55
+ subject.connection.should_receive(:post).with("/index/auto/node/properties", hash_match(:body, "foo"))
56
+ subject.add_node_auto_index_property("foo")
58
57
  end
59
58
 
60
59
  it "removes a property from an auto index" do
61
- connection.should_receive(:delete).with("/index/auto/node/properties/foo")
62
- subject.remove_property("foo")
60
+ subject.connection.should_receive(:delete).with("/index/auto/node/properties/foo")
61
+ subject.remove_node_auto_index_property("foo")
63
62
  end
64
63
 
65
64
  end