neography 0.0.31 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (85) hide show
  1. data/.gitignore +3 -0
  2. data/.travis.yml +1 -1
  3. data/CONTRIBUTORS +2 -1
  4. data/README.md +247 -0
  5. data/Rakefile +1 -2
  6. data/lib/neography/config.rb +48 -16
  7. data/lib/neography/connection.rb +151 -0
  8. data/lib/neography/errors.rb +42 -0
  9. data/lib/neography/node.rb +17 -14
  10. data/lib/neography/node_relationship.rb +3 -1
  11. data/lib/neography/node_traverser.rb +24 -20
  12. data/lib/neography/property.rb +31 -28
  13. data/lib/neography/property_container.rb +1 -1
  14. data/lib/neography/relationship.rb +16 -19
  15. data/lib/neography/rest/auto_indexes.rb +64 -0
  16. data/lib/neography/rest/batch.rb +262 -0
  17. data/lib/neography/rest/clean.rb +19 -0
  18. data/lib/neography/rest/cypher.rb +24 -0
  19. data/lib/neography/rest/gremlin.rb +24 -0
  20. data/lib/neography/rest/helpers.rb +26 -0
  21. data/lib/neography/rest/indexes.rb +97 -0
  22. data/lib/neography/rest/node_auto_indexes.rb +14 -0
  23. data/lib/neography/rest/node_indexes.rb +35 -0
  24. data/lib/neography/rest/node_paths.rb +57 -0
  25. data/lib/neography/rest/node_properties.rb +11 -0
  26. data/lib/neography/rest/node_relationships.rb +53 -0
  27. data/lib/neography/rest/node_traversal.rb +81 -0
  28. data/lib/neography/rest/nodes.rb +102 -0
  29. data/lib/neography/rest/paths.rb +36 -0
  30. data/lib/neography/rest/properties.rb +56 -0
  31. data/lib/neography/rest/relationship_auto_indexes.rb +14 -0
  32. data/lib/neography/rest/relationship_indexes.rb +35 -0
  33. data/lib/neography/rest/relationship_properties.rb +11 -0
  34. data/lib/neography/rest/relationships.rb +23 -0
  35. data/lib/neography/rest.rb +285 -615
  36. data/lib/neography/tasks.rb +1 -1
  37. data/lib/neography/version.rb +1 -1
  38. data/lib/neography.rb +13 -2
  39. data/neography.gemspec +8 -8
  40. data/spec/integration/authorization_spec.rb +2 -2
  41. data/spec/integration/index_spec.rb +4 -4
  42. data/spec/integration/neography_spec.rb +2 -2
  43. data/spec/integration/node_path_spec.rb +2 -2
  44. data/spec/integration/node_relationship_spec.rb +5 -3
  45. data/spec/integration/node_spec.rb +20 -19
  46. data/spec/integration/parsing_spec.rb +2 -2
  47. data/spec/integration/relationship_spec.rb +2 -2
  48. data/spec/integration/rest_batch_spec.rb +28 -28
  49. data/spec/integration/rest_bulk_spec.rb +2 -2
  50. data/spec/integration/rest_experimental_spec.rb +2 -2
  51. data/spec/integration/rest_gremlin_fail_spec.rb +2 -2
  52. data/spec/integration/rest_header_spec.rb +4 -9
  53. data/spec/integration/rest_index_spec.rb +21 -1
  54. data/spec/integration/rest_node_spec.rb +58 -44
  55. data/spec/integration/rest_path_spec.rb +5 -5
  56. data/spec/integration/rest_plugin_spec.rb +8 -2
  57. data/spec/integration/rest_relationship_spec.rb +35 -30
  58. data/spec/integration/rest_traverse_spec.rb +2 -2
  59. data/spec/matchers.rb +33 -0
  60. data/spec/neography_spec.rb +23 -0
  61. data/spec/spec_helper.rb +19 -1
  62. data/spec/unit/config_spec.rb +46 -0
  63. data/spec/unit/connection_spec.rb +205 -0
  64. data/spec/unit/node_spec.rb +100 -0
  65. data/spec/unit/properties_spec.rb +136 -0
  66. data/spec/unit/relationship_spec.rb +118 -0
  67. data/spec/unit/rest/batch_spec.rb +243 -0
  68. data/spec/unit/rest/clean_spec.rb +17 -0
  69. data/spec/unit/rest/cypher_spec.rb +21 -0
  70. data/spec/unit/rest/gremlin_spec.rb +26 -0
  71. data/spec/unit/rest/node_auto_indexes_spec.rb +67 -0
  72. data/spec/unit/rest/node_indexes_spec.rb +126 -0
  73. data/spec/unit/rest/node_paths_spec.rb +80 -0
  74. data/spec/unit/rest/node_properties_spec.rb +80 -0
  75. data/spec/unit/rest/node_relationships_spec.rb +78 -0
  76. data/spec/unit/rest/node_traversal_spec.rb +128 -0
  77. data/spec/unit/rest/nodes_spec.rb +188 -0
  78. data/spec/unit/rest/paths_spec.rb +69 -0
  79. data/spec/unit/rest/relationship_auto_indexes_spec.rb +67 -0
  80. data/spec/unit/rest/relationship_indexes_spec.rb +128 -0
  81. data/spec/unit/rest/relationship_properties_spec.rb +80 -0
  82. data/spec/unit/rest/relationships_spec.rb +22 -0
  83. metadata +86 -19
  84. data/Gemfile.lock +0 -44
  85. data/README.rdoc +0 -420
@@ -0,0 +1,78 @@
1
+ require 'spec_helper'
2
+
3
+ module Neography
4
+ class Rest
5
+ describe NodeRelationships do
6
+
7
+ let(:connection) { stub(:configuration => "http://configuration") }
8
+ subject { NodeRelationships.new(connection) }
9
+
10
+ it "creates a relationship" do
11
+ body_hash = { "type" => "some_type",
12
+ "to" => "http://configuration/node/43",
13
+ "data" => {"foo"=>"bar","baz"=>"qux"}
14
+ }
15
+ connection.should_receive(:post).with("/node/42/relationships", json_match(:body, body_hash))
16
+
17
+ subject.create("some_type", "42", "43", {:foo => "bar", :baz => "qux"})
18
+ end
19
+
20
+ it "returns the post results" do
21
+ connection.stub(:post).and_return("foo")
22
+
23
+ subject.create("some_type", "42", "43", {}).should == "foo"
24
+ end
25
+
26
+ it "gets relationships" do
27
+ connection.should_receive(:get).with("/node/42/relationships/all")
28
+ subject.get("42")
29
+ end
30
+
31
+ it "gets relationships with direction" do
32
+ connection.should_receive(:get).with("/node/42/relationships/in")
33
+ subject.get("42", :in)
34
+ end
35
+
36
+ it "gets relationships with direction and type" do
37
+ connection.should_receive(:get).with("/node/42/relationships/in/foo")
38
+ subject.get("42", :in, "foo")
39
+ end
40
+
41
+ it "gets relationships with direction and types" do
42
+ connection.should_receive(:get).with("/node/42/relationships/in/foo&bar")
43
+ subject.get("42", :in, ["foo", "bar"])
44
+ end
45
+
46
+ it "returns nil if no relationships were found" do
47
+ connection.stub(:get).and_return(nil)
48
+ subject.get("42", :in).should be_nil
49
+ end
50
+
51
+ it "returns nil if no relationships were found by type" do
52
+ connection.stub(:get).and_return(nil)
53
+ subject.get("42", :in, "foo")
54
+ end
55
+
56
+ context "directions" do
57
+
58
+ [ :incoming, "incoming", :in, "in" ].each do |direction|
59
+ it "parses 'in' direction" do
60
+ NodeRelationships.new(nil).parse_direction(direction).should == "in"
61
+ end
62
+ end
63
+
64
+ [ :outgoing, "outgoing", :out, "out" ].each do |direction|
65
+ it "parses 'out' direction" do
66
+ NodeRelationships.new(nil).parse_direction(direction).should == "out"
67
+ end
68
+ end
69
+
70
+ it "parses 'all' direction by default" do
71
+ NodeRelationships.new(nil).parse_direction("foo").should == "all"
72
+ end
73
+
74
+ end
75
+
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,128 @@
1
+ require 'spec_helper'
2
+
3
+ module Neography
4
+ class Rest
5
+ describe NodeTraversal do
6
+
7
+ let(:connection) { stub }
8
+ subject { NodeTraversal.new(connection) }
9
+
10
+ it "traverses" do
11
+ description = {
12
+ "order" => :breadth,
13
+ "uniqueness" => :nodeglobal,
14
+ "relationships" => "relationships",
15
+ "prune evaluator" => "prune_evaluator",
16
+ "return filter" => "return_filter",
17
+ "depth" => 4
18
+ }
19
+
20
+ expected_body = {
21
+ "order" => "breadth first",
22
+ "uniqueness" => "node global",
23
+ "relationships" => "relationships",
24
+ "prune_evaluator" => "prune_evaluator",
25
+ "return_filter" => "return_filter",
26
+ "max_depth" => 4
27
+ }
28
+
29
+ connection.should_receive(:post).with("/node/42/traverse/relationship", json_match(:body, expected_body))
30
+
31
+ subject.traverse("42", :relationship, description)
32
+ end
33
+
34
+ context "options" do
35
+ let(:traversal) { NodeTraversal.new(nil) }
36
+
37
+ context "order" do
38
+ [ :breadth, "breadth", "breadth first", "breadthFirst", :wide, "wide" ].each do |order|
39
+ it "parses breadth first" do
40
+ subject.send(:get_order, order).should == "breadth first"
41
+ end
42
+ end
43
+
44
+ it "parses depth first by default" do
45
+ subject.send(:get_order, "foo").should == "depth first"
46
+ end
47
+ end
48
+
49
+ context "uniqueness" do
50
+ [ :nodeglobal, "node global", "nodeglobal", "node_global" ].each do |order|
51
+ it "parses node global" do
52
+ subject.send(:get_uniqueness, order).should == "node global"
53
+ end
54
+ end
55
+
56
+ [ :nodepath, "node path", "nodepath", "node_path" ].each do |order|
57
+ it "parses node path" do
58
+ subject.send(:get_uniqueness, order).should == "node path"
59
+ end
60
+ end
61
+
62
+ [ :noderecent, "node recent", "noderecent", "node_recent" ].each do |order|
63
+ it "parses node recent" do
64
+ subject.send(:get_uniqueness, order).should == "node recent"
65
+ end
66
+ end
67
+
68
+ [ :relationshipglobal, "relationship global", "relationshipglobal", "relationship_global" ].each do |order|
69
+ it "parses relationship global" do
70
+ subject.send(:get_uniqueness, order).should == "relationship global"
71
+ end
72
+ end
73
+
74
+ [ :relationshippath, "relationship path", "relationshippath", "relationship_path" ].each do |order|
75
+ it "parses relationship path" do
76
+ subject.send(:get_uniqueness, order).should == "relationship path"
77
+ end
78
+ end
79
+
80
+ [ :relationshiprecent, "relationship recent", "relationshiprecent", "relationship_recent" ].each do |order|
81
+ it "parses relationship recent" do
82
+ subject.send(:get_uniqueness, order).should == "relationship recent"
83
+ end
84
+ end
85
+
86
+ it "parses none by default" do
87
+ subject.send(:get_uniqueness, "foo").should == "none"
88
+ end
89
+ end
90
+
91
+ context "depth" do
92
+ it "parses nil as nil" do
93
+ subject.send(:get_depth, nil).should be_nil
94
+ end
95
+ it "parses 0 as 1" do
96
+ subject.send(:get_depth, "0").should == 1
97
+ end
98
+ it "parses integers" do
99
+ subject.send(:get_depth, "42").should == 42
100
+ end
101
+ end
102
+
103
+ context "type" do
104
+ [ :relationship, "relationship", :relationships, "relationships" ].each do |type|
105
+ it "parses relationship" do
106
+ subject.send(:get_type, type).should == "relationship"
107
+ end
108
+ end
109
+ [ :path, "path", :paths, "paths" ].each do |type|
110
+ it "parses path" do
111
+ subject.send(:get_type, type).should == "path"
112
+ end
113
+ end
114
+ [ :fullpath, "fullpath", :fullpaths, "fullpaths" ].each do |type|
115
+ it "parses fullpath" do
116
+ subject.send(:get_type, type).should == "fullpath"
117
+ end
118
+ end
119
+
120
+ it "parses node by default" do
121
+ subject.send(:get_type, "foo").should == "node"
122
+ end
123
+ end
124
+ end
125
+
126
+ end
127
+ end
128
+ end
@@ -0,0 +1,188 @@
1
+ require 'spec_helper'
2
+
3
+ module Neography
4
+ class Rest
5
+ describe Nodes do
6
+
7
+ let(:connection) { stub }
8
+ subject { Nodes.new(connection) }
9
+
10
+ context "get nodes" do
11
+ it "gets single nodes" do
12
+ connection.should_receive(:get).with("/node/42")
13
+ subject.get("42")
14
+ end
15
+
16
+ it "gets multiple nodes" do
17
+ connection.should_receive(:get).with("/node/42")
18
+ connection.should_receive(:get).with("/node/43")
19
+ subject.get_each("42", "43")
20
+ end
21
+
22
+ it "returns multiple nodes in an array" do
23
+ connection.stub(:get).and_return("foo", "bar")
24
+ subject.get_each("42", "43").should == [ "foo", "bar" ]
25
+ end
26
+
27
+ it "gets the root node" do
28
+ connection.stub(:get).with("/").and_return({ "reference_node" => "42" })
29
+ connection.should_receive(:get).with("/node/42")
30
+ subject.root
31
+ end
32
+
33
+ it "returns the root node" do
34
+ connection.stub(:get).and_return({ "reference_node" => "42" }, "foo")
35
+ subject.root.should == "foo"
36
+ end
37
+ end
38
+
39
+ context "create nodes" do
40
+
41
+ it "creates with attributes" do
42
+ options = {
43
+ :body => '{"foo":"bar","baz":"qux"}',
44
+ :headers => json_content_type
45
+ }
46
+ connection.should_receive(:post).with("/node", options)
47
+ subject.create_with_attributes({:foo => "bar", :baz => "qux"})
48
+ end
49
+
50
+ it "returns the created node" do
51
+ connection.stub(:post).and_return("foo")
52
+ subject.create_with_attributes({}).should == "foo"
53
+ end
54
+
55
+ it "creates with attributes using #create method" do
56
+ options = {
57
+ :body => '{"foo":"bar","baz":"qux"}',
58
+ :headers => json_content_type
59
+ }
60
+ connection.should_receive(:post).with("/node", options)
61
+ subject.create({:foo => "bar", :baz => "qux"})
62
+ end
63
+
64
+ it "creates empty nodes" do
65
+ connection.should_receive(:post).with("/node")
66
+ subject.create_empty
67
+ end
68
+
69
+ it "returns an empty node" do
70
+ connection.stub(:post).and_return("foo")
71
+ subject.create_empty.should == "foo"
72
+ end
73
+
74
+ it "creates empty nodes using #create method" do
75
+ connection.should_receive(:post).with("/node")
76
+ subject.create
77
+ end
78
+
79
+ end
80
+
81
+ context "delete nodes" do
82
+
83
+ it "deletes a node" do
84
+ connection.should_receive(:delete).with("/node/42")
85
+ subject.delete("42")
86
+ end
87
+
88
+ end
89
+
90
+ context "#create_multiple" do
91
+
92
+ it "creates multiple with attributes" do
93
+ options1 = {
94
+ :body => '{"foo1":"bar1","baz1":"qux1"}',
95
+ :headers => json_content_type
96
+ }
97
+ options2 = {
98
+ :body => '{"foo2":"bar2","baz2":"qux2"}',
99
+ :headers => json_content_type
100
+ }
101
+ connection.should_receive(:post).with("/node", options1)
102
+ connection.should_receive(:post).with("/node", options2)
103
+
104
+ subject.create_multiple([
105
+ {:foo1 => "bar1", :baz1 => "qux1"},
106
+ {:foo2 => "bar2", :baz2 => "qux2"}
107
+ ])
108
+ end
109
+
110
+ it "returns multiple nodes with attributes in an array" do
111
+ connection.stub(:post).and_return("foo", "bar")
112
+ subject.create_multiple([{},{}]).should == ["foo", "bar"]
113
+ end
114
+
115
+ # exotic?
116
+ it "creates multiple with and without attributes" do
117
+ options1 = {
118
+ :body => '{"foo1":"bar1","baz1":"qux1"}',
119
+ :headers => json_content_type
120
+ }
121
+ connection.should_receive(:post).with("/node", options1)
122
+ connection.should_receive(:post).with("/node")
123
+
124
+ subject.create_multiple([
125
+ {:foo1 => "bar1", :baz1 => "qux1"},
126
+ "not a hash" # ?
127
+ ])
128
+ end
129
+
130
+ it "creates multiple empty nodes" do
131
+ connection.should_receive(:post).with("/node").twice
132
+ subject.create_multiple(2)
133
+ end
134
+
135
+ it "returns multiple empty nodes in an array" do
136
+ connection.stub(:post).and_return("foo", "bar")
137
+ subject.create_multiple(2).should == ["foo", "bar"]
138
+ end
139
+
140
+ end
141
+
142
+ context "#create_multiple_threaded" do
143
+
144
+ let(:connection) { stub(:max_threads => 2) }
145
+
146
+ it "creates multiple with attributes" do
147
+ options1 = {
148
+ :body => '{"foo1":"bar1","baz1":"qux1"}',
149
+ :headers => json_content_type
150
+ }
151
+ options2 = {
152
+ :body => '{"foo2":"bar2","baz2":"qux2"}',
153
+ :headers => json_content_type
154
+ }
155
+ connection.should_receive(:post).with("/node", options1)
156
+ connection.should_receive(:post).with("/node", options2)
157
+
158
+ subject.create_multiple_threaded([
159
+ {:foo1 => "bar1", :baz1 => "qux1"},
160
+ {:foo2 => "bar2", :baz2 => "qux2"}
161
+ ])
162
+ end
163
+
164
+ # exotic?
165
+ it "creates multiple with and without attributes" do
166
+ options1 = {
167
+ :body => '{"foo1":"bar1","baz1":"qux1"}',
168
+ :headers => json_content_type
169
+ }
170
+ connection.should_receive(:post).with("/node", options1)
171
+ connection.should_receive(:post).with("/node")
172
+
173
+ subject.create_multiple_threaded([
174
+ {:foo1 => "bar1", :baz1 => "qux1"},
175
+ "not a hash" # ?
176
+ ])
177
+ end
178
+
179
+ it "creates multiple empty nodes" do
180
+ connection.should_receive(:post).with("/node").twice
181
+ subject.create_multiple_threaded(2)
182
+ end
183
+
184
+ end
185
+
186
+ end
187
+ end
188
+ end
@@ -0,0 +1,69 @@
1
+ require 'spec_helper'
2
+
3
+ module Neography
4
+ class Rest
5
+
6
+ class Dummy
7
+ extend Paths
8
+
9
+ add_path :one, "/node/:id"
10
+ add_path :two, "/node/:id/properties/:property"
11
+ end
12
+
13
+ describe Dummy do
14
+
15
+ context "instance methods" do
16
+
17
+ it { should respond_to(:one_path) }
18
+ it { should respond_to(:two_path) }
19
+
20
+ it "replaces a key" do
21
+ subject.one_path(:id => 42).should == "/node/42"
22
+ end
23
+
24
+ it "replaces multiple keys" do
25
+ subject.two_path(:id => 42, :property => "foo").should == "/node/42/properties/foo"
26
+ end
27
+
28
+ it "url encodes spaces" do
29
+ subject.one_path(:id => "with space").should == "/node/with%20space"
30
+ end
31
+
32
+ # URI.encode does not escape slashes (and rightly so), but should escape these keys
33
+ it "url encodes slashes" do
34
+ subject.one_path(:id => "with/slash").should == "/node/with%2Fslash"
35
+ end
36
+
37
+ end
38
+
39
+ context "class methods" do
40
+
41
+ subject { Dummy }
42
+
43
+ it { should respond_to(:one_path) }
44
+ it { should respond_to(:two_path) }
45
+
46
+ it "replaces a key" do
47
+ subject.one_path(:id => 42).should == "/node/42"
48
+ end
49
+
50
+ it "replaces multiple keys" do
51
+ subject.two_path(:id => 42, :property => "foo").should == "/node/42/properties/foo"
52
+ end
53
+
54
+ it "url encodes spaces" do
55
+ subject.one_path(:id => "with space").should == "/node/with%20space"
56
+ end
57
+
58
+ # URI.encode does not escape slashes (and rightly so), but should escape these keys
59
+ it "url encodes slashes" do
60
+ subject.one_path(:id => "with/slash").should == "/node/with%2Fslash"
61
+ end
62
+
63
+ end
64
+
65
+ end
66
+
67
+ end
68
+ end
69
+
@@ -0,0 +1,67 @@
1
+ require 'spec_helper'
2
+
3
+ module Neography
4
+ class Rest
5
+ describe RelationshipAutoIndexes do
6
+
7
+ let(:connection) { stub }
8
+ subject { RelationshipAutoIndexes.new(connection) }
9
+
10
+ it "gets a relationship from an auto index" do
11
+ connection.should_receive(:get).with("/index/auto/relationship/some_key/some_value")
12
+ subject.get("some_key", "some_value")
13
+ end
14
+
15
+ 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
18
+ end
19
+
20
+ it "finds by key and value if value passed to #find_or_query" do
21
+ connection.should_receive(:get).with("/index/auto/relationship/some_key/some_value")
22
+ subject.find_or_query("some_key", "some_value")
23
+ end
24
+
25
+ it "finds by query if no value passed to #find_or_query" do
26
+ connection.should_receive(:get).with("/index/auto/relationship/?query=some_query")
27
+ subject.find_or_query("some_query")
28
+ end
29
+
30
+ it "finds by key and value" do
31
+ connection.should_receive(:get).with("/index/auto/relationship/some_key/some_value")
32
+ subject.find("some_key", "some_value")
33
+ end
34
+
35
+ it "finds by query" do
36
+ connection.should_receive(:get).with("/index/auto/relationship/?query=some_query")
37
+ subject.query("some_query")
38
+ end
39
+
40
+ it "gets the status" do
41
+ connection.should_receive(:get).with("/index/auto/relationship/status")
42
+ subject.status
43
+ end
44
+
45
+ it "sets the status" do
46
+ connection.should_receive(:put).with("/index/auto/relationship/status", hash_match(:body, '"foo"'))
47
+ subject.status = "foo"
48
+ end
49
+
50
+ it "gets auto index properties" do
51
+ connection.should_receive(:get).with("/index/auto/relationship/properties")
52
+ subject.properties
53
+ end
54
+
55
+ it "adds a property to an auto index" do
56
+ connection.should_receive(:post).with("/index/auto/relationship/properties", hash_match(:body, "foo"))
57
+ subject.add_property("foo")
58
+ end
59
+
60
+ it "removes a property from an auto index" do
61
+ connection.should_receive(:delete).with("/index/auto/relationship/properties/foo")
62
+ subject.remove_property("foo")
63
+ end
64
+
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,128 @@
1
+ require 'spec_helper'
2
+
3
+ module Neography
4
+ class Rest
5
+ describe RelationshipIndexes do
6
+
7
+ let(:connection) { stub(:configuration => "http://configuration") }
8
+ subject { RelationshipIndexes.new(connection) }
9
+
10
+ it "lists all indexes" do
11
+ connection.should_receive(:get).with("/index/relationship")
12
+ subject.list
13
+ end
14
+
15
+ it "creates a relationship index" do
16
+ expected_body = {
17
+ "config" => {
18
+ "type" => "some_type",
19
+ "provider" => "some_provider"
20
+ },
21
+ "name" => "some_index"
22
+ }
23
+ connection.should_receive(:post).with("/index/relationship", json_match(:body, expected_body))
24
+ subject.create("some_index", "some_type", "some_provider")
25
+ end
26
+
27
+ it "returns the post result after creation" do
28
+ connection.stub(:post).and_return("foo")
29
+ subject.create("some_index", "some_type", "some_provider").should == "foo"
30
+ end
31
+
32
+ it "creates an auto-index" do
33
+ expected_body = {
34
+ "config" => {
35
+ "type" => "some_type",
36
+ "provider" => "some_provider"
37
+ },
38
+ "name" => "relationship_auto_index"
39
+ }
40
+ connection.should_receive(:post).with("/index/relationship", json_match(:body, expected_body))
41
+ subject.create_auto("some_type", "some_provider")
42
+ end
43
+
44
+ it "creates a unique relationship in an index" do
45
+ expected_body = {
46
+ "key" => "key",
47
+ "value" => "value",
48
+ "type" => "type",
49
+ "start" => "http://configuration/node/42",
50
+ "end" => "http://configuration/node/43"
51
+ }
52
+ connection.should_receive(:post).with("/index/relationship/some_index?unique", json_match(:body, expected_body))
53
+ subject.create_unique("some_index", "key", "value", "type", "42", "43")
54
+ end
55
+
56
+ it "adds a relationship to an index" do
57
+ expected_body = {
58
+ "uri" => "http://configuration/relationship/42",
59
+ "key" => "key",
60
+ "value" => "value"
61
+ }
62
+ connection.should_receive(:post).with("/index/relationship/some_index", json_match(:body, expected_body))
63
+ subject.add("some_index", "key", "value", "42")
64
+ end
65
+
66
+ it "gets a relationship from an index" do
67
+ connection.should_receive(:get).with("/index/relationship/some_index/some_key/some_value")
68
+ subject.get("some_index", "some_key", "some_value")
69
+ end
70
+
71
+ it "returns nil if nothing was found in the index" do
72
+ connection.stub(:get).and_return(nil)
73
+ subject.get("some_index", "some_key", "some_value").should be_nil
74
+ end
75
+
76
+ it "finds by key and value if both passed to #find" do
77
+ connection.should_receive(:get).with("/index/relationship/some_index/some_key/some_value")
78
+ subject.find("some_index", "some_key", "some_value")
79
+ end
80
+
81
+ it "finds by query if no value passed to #find" do
82
+ connection.should_receive(:get).with("/index/relationship/some_index?query=some_query")
83
+ subject.find("some_index", "some_query")
84
+ end
85
+
86
+ it "finds by key query" do
87
+ connection.should_receive(:get).with("/index/relationship/some_index/some_key/some_value")
88
+ subject.find_by_key_value("some_index", "some_key", "some_value")
89
+ end
90
+
91
+ it "finds by query" do
92
+ connection.should_receive(:get).with("/index/relationship/some_index?query=some_query")
93
+ subject.find_by_query("some_index", "some_query")
94
+ end
95
+
96
+ it "removes a relationship from an index for #remove with two arguments" do
97
+ connection.should_receive(:delete).with("/index/relationship/some_index/42")
98
+ subject.remove("some_index", "42")
99
+ end
100
+
101
+ it "removes a relationship from an index by key for #remove with three arguments" do
102
+ connection.should_receive(:delete).with("/index/relationship/some_index/some_key/42")
103
+ subject.remove("some_index", "some_key", "42")
104
+ end
105
+
106
+ it "removes a relationship from an index by key and value for #remove with four arguments" do
107
+ connection.should_receive(:delete).with("/index/relationship/some_index/some_key/some_value/42")
108
+ subject.remove("some_index", "some_key", "some_value", "42")
109
+ end
110
+
111
+ it "removes a relationship from an index" do
112
+ connection.should_receive(:delete).with("/index/relationship/some_index/42")
113
+ subject.remove_by_id("some_index", "42")
114
+ end
115
+
116
+ it "removes a relationship from an index by key" do
117
+ connection.should_receive(:delete).with("/index/relationship/some_index/some_key/42")
118
+ subject.remove_by_key("some_index", "42", "some_key")
119
+ end
120
+
121
+ it "removes a relationship from an index by key and value" do
122
+ connection.should_receive(:delete).with("/index/relationship/some_index/some_key/some_value/42")
123
+ subject.remove_by_value("some_index", "42", "some_key", "some_value")
124
+ end
125
+
126
+ end
127
+ end
128
+ end