neography-down 1.6.4
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.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/.project +12 -0
- data/.rspec +1 -0
- data/.travis.yml +4 -0
- data/CHANGELOG.md +939 -0
- data/CONTRIBUTORS +18 -0
- data/Gemfile +4 -0
- data/Guardfile +14 -0
- data/LICENSE +19 -0
- data/README.md +281 -0
- data/Rakefile +14 -0
- data/examples/facebook.rb +40 -0
- data/examples/facebook_v2.rb +25 -0
- data/examples/greatest.rb +43 -0
- data/examples/linkedin.rb +39 -0
- data/examples/linkedin_v2.rb +22 -0
- data/examples/traversal_example1.rb +65 -0
- data/examples/traversal_example2.rb +54 -0
- data/lib/neography.rb +45 -0
- data/lib/neography/config.rb +64 -0
- data/lib/neography/connection.rb +263 -0
- data/lib/neography/equal.rb +21 -0
- data/lib/neography/errors.rb +60 -0
- data/lib/neography/index.rb +52 -0
- data/lib/neography/multi_json_parser.rb +28 -0
- data/lib/neography/neography.rb +10 -0
- data/lib/neography/node.rb +63 -0
- data/lib/neography/node_path.rb +29 -0
- data/lib/neography/node_relationship.rb +37 -0
- data/lib/neography/node_traverser.rb +146 -0
- data/lib/neography/path_traverser.rb +100 -0
- data/lib/neography/property.rb +110 -0
- data/lib/neography/property_container.rb +28 -0
- data/lib/neography/railtie.rb +19 -0
- data/lib/neography/relationship.rb +78 -0
- data/lib/neography/relationship_traverser.rb +80 -0
- data/lib/neography/rest.rb +99 -0
- data/lib/neography/rest/batch.rb +414 -0
- data/lib/neography/rest/clean.rb +17 -0
- data/lib/neography/rest/constraints.rb +38 -0
- data/lib/neography/rest/cypher.rb +29 -0
- data/lib/neography/rest/extensions.rb +21 -0
- data/lib/neography/rest/gremlin.rb +20 -0
- data/lib/neography/rest/helpers.rb +96 -0
- data/lib/neography/rest/node_auto_indexes.rb +60 -0
- data/lib/neography/rest/node_indexes.rb +139 -0
- data/lib/neography/rest/node_labels.rb +49 -0
- data/lib/neography/rest/node_paths.rb +49 -0
- data/lib/neography/rest/node_properties.rb +52 -0
- data/lib/neography/rest/node_relationships.rb +33 -0
- data/lib/neography/rest/node_traversal.rb +25 -0
- data/lib/neography/rest/nodes.rb +94 -0
- data/lib/neography/rest/other_node_relationships.rb +38 -0
- data/lib/neography/rest/relationship_auto_indexes.rb +60 -0
- data/lib/neography/rest/relationship_indexes.rb +142 -0
- data/lib/neography/rest/relationship_properties.rb +52 -0
- data/lib/neography/rest/relationship_types.rb +11 -0
- data/lib/neography/rest/relationships.rb +16 -0
- data/lib/neography/rest/schema_indexes.rb +26 -0
- data/lib/neography/rest/spatial.rb +137 -0
- data/lib/neography/rest/transactions.rb +101 -0
- data/lib/neography/tasks.rb +207 -0
- data/lib/neography/version.rb +3 -0
- data/neography.gemspec +39 -0
- data/spec/integration/authorization_spec.rb +40 -0
- data/spec/integration/broken_spatial_spec.rb +28 -0
- data/spec/integration/index_spec.rb +71 -0
- data/spec/integration/neography_spec.rb +10 -0
- data/spec/integration/node_encoding_spec.rb +71 -0
- data/spec/integration/node_path_spec.rb +222 -0
- data/spec/integration/node_relationship_spec.rb +381 -0
- data/spec/integration/node_spec.rb +260 -0
- data/spec/integration/parsing_spec.rb +13 -0
- data/spec/integration/performance_spec.rb +17 -0
- data/spec/integration/relationship_spec.rb +37 -0
- data/spec/integration/rest_batch_no_streaming_spec.rb +41 -0
- data/spec/integration/rest_batch_spec.rb +604 -0
- data/spec/integration/rest_batch_streaming_spec.rb +51 -0
- data/spec/integration/rest_bulk_spec.rb +106 -0
- data/spec/integration/rest_constraints_spec.rb +72 -0
- data/spec/integration/rest_experimental_spec.rb +22 -0
- data/spec/integration/rest_gremlin_fail_spec.rb +46 -0
- data/spec/integration/rest_header_spec.rb +15 -0
- data/spec/integration/rest_index_spec.rb +481 -0
- data/spec/integration/rest_labels_spec.rb +128 -0
- data/spec/integration/rest_node_spec.rb +274 -0
- data/spec/integration/rest_other_node_relationship_spec.rb +137 -0
- data/spec/integration/rest_path_spec.rb +231 -0
- data/spec/integration/rest_plugin_spec.rb +177 -0
- data/spec/integration/rest_relationship_spec.rb +354 -0
- data/spec/integration/rest_relationship_types_spec.rb +18 -0
- data/spec/integration/rest_schema_index_spec.rb +32 -0
- data/spec/integration/rest_spatial_spec.rb +166 -0
- data/spec/integration/rest_transaction_spec.rb +166 -0
- data/spec/integration/rest_traverse_spec.rb +149 -0
- data/spec/integration/unmanaged_spec.rb +27 -0
- data/spec/matchers.rb +33 -0
- data/spec/neography_spec.rb +23 -0
- data/spec/spec_helper.rb +44 -0
- data/spec/unit/config_spec.rb +135 -0
- data/spec/unit/connection_spec.rb +284 -0
- data/spec/unit/node_spec.rb +100 -0
- data/spec/unit/properties_spec.rb +285 -0
- data/spec/unit/relationship_spec.rb +118 -0
- data/spec/unit/rest/batch_spec.rb +262 -0
- data/spec/unit/rest/clean_spec.rb +16 -0
- data/spec/unit/rest/constraints_spec.rb +45 -0
- data/spec/unit/rest/cypher_spec.rb +20 -0
- data/spec/unit/rest/extensions_spec.rb +28 -0
- data/spec/unit/rest/gremlin_spec.rb +25 -0
- data/spec/unit/rest/helpers_spec.rb +124 -0
- data/spec/unit/rest/labels_spec.rb +77 -0
- data/spec/unit/rest/node_auto_indexes_spec.rb +70 -0
- data/spec/unit/rest/node_indexes_spec.rb +140 -0
- data/spec/unit/rest/node_paths_spec.rb +77 -0
- data/spec/unit/rest/node_properties_spec.rb +79 -0
- data/spec/unit/rest/node_relationships_spec.rb +57 -0
- data/spec/unit/rest/node_traversal_spec.rb +35 -0
- data/spec/unit/rest/nodes_spec.rb +187 -0
- data/spec/unit/rest/relationship_auto_indexes_spec.rb +66 -0
- data/spec/unit/rest/relationship_indexes_spec.rb +132 -0
- data/spec/unit/rest/relationship_properties_spec.rb +79 -0
- data/spec/unit/rest/relationship_types_spec.rb +15 -0
- data/spec/unit/rest/relationships_spec.rb +21 -0
- data/spec/unit/rest/schema_index_spec.rb +30 -0
- data/spec/unit/rest/transactions_spec.rb +43 -0
- metadata +372 -0
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
module Neography
|
|
4
|
+
describe Node do
|
|
5
|
+
|
|
6
|
+
describe "::create" do
|
|
7
|
+
context "no explicit server" do
|
|
8
|
+
|
|
9
|
+
before do
|
|
10
|
+
@db = double(Neography::Rest, :is_a? => true).as_null_object
|
|
11
|
+
allow(Rest).to receive(:new) { @db }
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
it "assigns a new Rest db by default" do
|
|
15
|
+
node = Node.create
|
|
16
|
+
expect(node.neo_server).to eq(@db)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
it "creates without arguments" do
|
|
20
|
+
expect(@db).to receive(:create_node).with(nil)
|
|
21
|
+
Node.create
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
it "creates with only a hash argument" do
|
|
25
|
+
properties = { :foo => "bar" }
|
|
26
|
+
expect(@db).to receive(:create_node).with(properties)
|
|
27
|
+
Node.create(properties)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
context "explicit server" do
|
|
33
|
+
|
|
34
|
+
it "cannot pass a server as the first argument, properties as the second (deprecated)" do
|
|
35
|
+
@other_server = Neography::Rest.new
|
|
36
|
+
properties = { :foo => "bar" }
|
|
37
|
+
expect(@other_server).not_to receive(:create_node).with(properties)
|
|
38
|
+
expect {
|
|
39
|
+
Node.create(@other_server, properties)
|
|
40
|
+
}.to raise_error(ArgumentError)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
it "can pass properties as the first argument, a server as the second" do
|
|
44
|
+
@other_server = Neography::Rest.new
|
|
45
|
+
properties = { :foo => "bar" }
|
|
46
|
+
expect(@other_server).to receive(:create_node).with(properties)
|
|
47
|
+
Node.create(properties, @other_server)
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
describe "::load" do
|
|
54
|
+
context "no explicit server" do
|
|
55
|
+
|
|
56
|
+
before do
|
|
57
|
+
# stub out actual connections
|
|
58
|
+
@db = double(Rest).as_null_object
|
|
59
|
+
allow(Rest).to receive(:new) { @db }
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
it "load by id" do
|
|
63
|
+
expect(@db).to receive(:get_node).with(5)
|
|
64
|
+
Node.load(5)
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
it "loads by node" do
|
|
68
|
+
node = Node.new
|
|
69
|
+
expect(@db).not_to receive(:get_node).with(node)
|
|
70
|
+
Node.load(node)
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
it "loads by full server string" do
|
|
74
|
+
expect(@db).to receive(:get_node).with("http://localhost:7474/db/data/node/2")
|
|
75
|
+
Node.load("http://localhost:7474/db/data/node/2")
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
context "explicit server" do
|
|
81
|
+
|
|
82
|
+
it "cannot pass a server as the first argument, node as the second (depracted)" do
|
|
83
|
+
@other_server = Neography::Rest.new
|
|
84
|
+
expect(@other_server).not_to receive(:get_node).with(42)
|
|
85
|
+
expect {
|
|
86
|
+
node = Node.load(@other_server, 42)
|
|
87
|
+
}.to raise_error(ArgumentError)
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
it "can pass a node as the first argument, server as the second" do
|
|
91
|
+
@other_server = Neography::Rest.new
|
|
92
|
+
expect(@other_server).to receive(:get_node).with(42)
|
|
93
|
+
node = Node.load(42, @other_server)
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
end
|
|
100
|
+
end
|
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
module Neography
|
|
4
|
+
describe "Properties" do
|
|
5
|
+
|
|
6
|
+
before do
|
|
7
|
+
@db = double(Neography::Rest, :is_a? => true).as_null_object
|
|
8
|
+
allow(Rest).to receive(:new) { @db }
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
context "Node" do
|
|
12
|
+
|
|
13
|
+
subject(:node) do
|
|
14
|
+
node = Node.create
|
|
15
|
+
allow(node).to receive(:neo_id).and_return(42)
|
|
16
|
+
node
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
it "sets properties as accessor" do
|
|
20
|
+
expect(@db).to receive(:"set_node_properties").with(42, { "key" => "value" })
|
|
21
|
+
node.key = "value"
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
it "sets properties as array entry" do
|
|
25
|
+
expect(@db).to receive(:"set_node_properties").with(42, { "key" => "value" })
|
|
26
|
+
node["key"] = "value"
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
it "gets properties as accessor" do
|
|
30
|
+
allow(@db).to receive(:"set_node_properties")
|
|
31
|
+
node.key = "value"
|
|
32
|
+
expect(node.key).to eq("value")
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
it "gets properties as array entry" do
|
|
36
|
+
allow(@db).to receive(:"set_node_properties")
|
|
37
|
+
node["key"] = "value"
|
|
38
|
+
expect(node["key"]).to eq("value")
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
it "resets properties as accessor" do
|
|
42
|
+
expect(@db).to receive(:"remove_node_properties").with(42, ["key"])
|
|
43
|
+
node.key = "value"
|
|
44
|
+
node.key = nil
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
it "resets properties as array entry" do
|
|
48
|
+
expect(@db).to receive(:"remove_node_properties").with(42, ["key"])
|
|
49
|
+
node["key"] = "value"
|
|
50
|
+
node["key"] = nil
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
it "gets unknown properties as nil" do
|
|
54
|
+
expect(node.unknown).to eq(nil)
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
it "overwrites existing properties" do
|
|
58
|
+
expect(@db).to receive(:"set_node_properties").with(42, { "key" => "value1" })
|
|
59
|
+
node.key = "value1"
|
|
60
|
+
|
|
61
|
+
expect(@db).to receive(:"set_node_properties").with(42, { "key" => "value2" })
|
|
62
|
+
node.key = "value2"
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
it "knows its attributes" do
|
|
66
|
+
allow(@db).to receive(:"set_node_properties")
|
|
67
|
+
node.key = "value"
|
|
68
|
+
node["key2"] = "value"
|
|
69
|
+
expect(node.attributes).to match_array([ :key, :key2 ])
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
describe "resets all node properties with one http request" do
|
|
73
|
+
before(:each) do
|
|
74
|
+
@change_node = Node.create
|
|
75
|
+
|
|
76
|
+
# A property that we will overwrite
|
|
77
|
+
@change_node[:old_key] = 'value'
|
|
78
|
+
|
|
79
|
+
# Stub neo id
|
|
80
|
+
allow(@change_node).to receive(:neo_id).and_return(22)
|
|
81
|
+
|
|
82
|
+
# What we call set_properties with
|
|
83
|
+
@new_data = { new_key: "new value"}
|
|
84
|
+
|
|
85
|
+
# Make sure the request is dispatched to the rest layer
|
|
86
|
+
expect(@db).to receive(:reset_node_properties).with(22, @new_data)
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
it "removes the old property getter" do
|
|
90
|
+
expect{
|
|
91
|
+
@change_node.reset_properties(@new_data)
|
|
92
|
+
}.to change{@change_node.respond_to?(:old_key)}.from(true).to(false)
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
it "removes the old property setter" do
|
|
96
|
+
expect{
|
|
97
|
+
@change_node.reset_properties(@new_data)
|
|
98
|
+
}.to change{@change_node.respond_to?('old_key=')}.from(true).to(false)
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
it "removes the property from the underlying openstruct" do
|
|
102
|
+
expect{
|
|
103
|
+
@change_node.reset_properties(@new_data)
|
|
104
|
+
}.to change{@change_node['old_key']}.from('value').to(nil)
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
it "adds the new property getter" do
|
|
108
|
+
expect{
|
|
109
|
+
@change_node.reset_properties(@new_data)
|
|
110
|
+
}.to change{@change_node.respond_to?(:new_key)}.from(false).to(true)
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
it "adds the new property setter" do
|
|
114
|
+
expect{
|
|
115
|
+
@change_node.reset_properties(@new_data)
|
|
116
|
+
}.to change{@change_node.respond_to?('new_key=')}.from(false).to(true)
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
it "adds the new property to the underlying openstruct" do
|
|
120
|
+
expect{
|
|
121
|
+
@change_node.reset_properties(@new_data)
|
|
122
|
+
}.to change{@change_node['new_key']}.from(nil).to('new value')
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
it "updates its attributes" do
|
|
126
|
+
expect{
|
|
127
|
+
@change_node.reset_properties(@new_data)
|
|
128
|
+
}.to change{@change_node.attributes}.from([:old_key]).to([:new_key])
|
|
129
|
+
end
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
describe "sets all node properties with one http request" do
|
|
134
|
+
before(:each) do
|
|
135
|
+
@change_node = Node.create
|
|
136
|
+
|
|
137
|
+
# A property that we will overwrite
|
|
138
|
+
@change_node[:old_key] = 'value'
|
|
139
|
+
|
|
140
|
+
# A property that we will not overwrite and that must stay
|
|
141
|
+
@change_node[:old_remaining_key] = 'remaining value'
|
|
142
|
+
|
|
143
|
+
# Stub neo id
|
|
144
|
+
allow(@change_node).to receive(:neo_id).and_return(22)
|
|
145
|
+
|
|
146
|
+
# What we call set_properties with
|
|
147
|
+
@new_data = { "new_key" => "new value", 'old_key' => nil }
|
|
148
|
+
|
|
149
|
+
# What we expect neography to send as the new properties
|
|
150
|
+
update_data = { new_key: 'new value', old_remaining_key: 'remaining value'}
|
|
151
|
+
|
|
152
|
+
# Make sure the request is dispatched to the rest layer
|
|
153
|
+
expect(@db).to receive(:reset_node_properties).with(22, update_data)
|
|
154
|
+
end
|
|
155
|
+
|
|
156
|
+
it "removes the old property getter" do
|
|
157
|
+
expect{
|
|
158
|
+
@change_node.set_properties(@new_data)
|
|
159
|
+
}.to change{@change_node.respond_to?(:old_key)}.from(true).to(false)
|
|
160
|
+
end
|
|
161
|
+
|
|
162
|
+
it "removes the old property setter" do
|
|
163
|
+
expect{
|
|
164
|
+
@change_node.set_properties(@new_data)
|
|
165
|
+
}.to change{@change_node.respond_to?('old_key=')}.from(true).to(false)
|
|
166
|
+
end
|
|
167
|
+
|
|
168
|
+
it "removes the property from the underlying openstruct" do
|
|
169
|
+
expect{
|
|
170
|
+
@change_node.set_properties(@new_data)
|
|
171
|
+
}.to change{@change_node['old_key']}.from('value').to(nil)
|
|
172
|
+
end
|
|
173
|
+
|
|
174
|
+
it "doesn't touch the remaining property in the openstruct" do
|
|
175
|
+
expect{
|
|
176
|
+
@change_node.set_properties(@new_data)
|
|
177
|
+
}.to_not change{@change_node['old_remaining_key']}
|
|
178
|
+
end
|
|
179
|
+
|
|
180
|
+
it "doesn't touch the remaining property getter" do
|
|
181
|
+
expect{
|
|
182
|
+
@change_node.set_properties(@new_data)
|
|
183
|
+
}.to_not change{@change_node.respond_to?(:old_remaining_key)}
|
|
184
|
+
end
|
|
185
|
+
|
|
186
|
+
it "doesn't touch the remaining property setter" do
|
|
187
|
+
expect{
|
|
188
|
+
@change_node.set_properties(@new_data)
|
|
189
|
+
}.to_not change{@change_node.respond_to?('old_remaining_key=')}
|
|
190
|
+
end
|
|
191
|
+
|
|
192
|
+
it "adds the new property getter" do
|
|
193
|
+
expect{
|
|
194
|
+
@change_node.set_properties(@new_data)
|
|
195
|
+
}.to change{@change_node.respond_to?(:new_key)}.from(false).to(true)
|
|
196
|
+
end
|
|
197
|
+
|
|
198
|
+
it "adds the new property setter" do
|
|
199
|
+
expect{
|
|
200
|
+
@change_node.set_properties(@new_data)
|
|
201
|
+
}.to change{@change_node.respond_to?('new_key=')}.from(false).to(true)
|
|
202
|
+
end
|
|
203
|
+
|
|
204
|
+
it "adds the new property to the underlying openstruct" do
|
|
205
|
+
expect{
|
|
206
|
+
@change_node.set_properties(@new_data)
|
|
207
|
+
}.to change{@change_node['new_key']}.from(nil).to('new value')
|
|
208
|
+
end
|
|
209
|
+
|
|
210
|
+
it "updates its attributes" do
|
|
211
|
+
expect{
|
|
212
|
+
@change_node.set_properties(@new_data)
|
|
213
|
+
}.to change{@change_node.attributes}.from([:old_key, :old_remaining_key]).to([:old_remaining_key, :new_key])
|
|
214
|
+
end
|
|
215
|
+
end
|
|
216
|
+
|
|
217
|
+
end
|
|
218
|
+
|
|
219
|
+
context "Relationship" do
|
|
220
|
+
|
|
221
|
+
subject(:relationship) do
|
|
222
|
+
from = Node.create
|
|
223
|
+
to = Node.create
|
|
224
|
+
|
|
225
|
+
rel = Relationship.create(:type, from, to)
|
|
226
|
+
allow(rel).to receive(:neo_id).and_return(42)
|
|
227
|
+
rel
|
|
228
|
+
end
|
|
229
|
+
|
|
230
|
+
it "sets properties as accessor" do
|
|
231
|
+
expect(@db).to receive(:"set_relationship_properties").with(42, { "key" => "value" })
|
|
232
|
+
relationship.key = "value"
|
|
233
|
+
end
|
|
234
|
+
|
|
235
|
+
it "sets properties as array entry" do
|
|
236
|
+
expect(@db).to receive(:"set_relationship_properties").with(42, { "key" => "value" })
|
|
237
|
+
relationship["key"] = "value"
|
|
238
|
+
end
|
|
239
|
+
|
|
240
|
+
it "gets properties as accessor" do
|
|
241
|
+
allow(@db).to receive(:"set_relationship_properties")
|
|
242
|
+
relationship.key = "value"
|
|
243
|
+
expect(relationship.key).to eq("value")
|
|
244
|
+
end
|
|
245
|
+
|
|
246
|
+
it "gets properties as array entry" do
|
|
247
|
+
allow(@db).to receive(:"set_relationship_properties")
|
|
248
|
+
relationship["key"] = "value"
|
|
249
|
+
expect(relationship["key"]).to eq("value")
|
|
250
|
+
end
|
|
251
|
+
|
|
252
|
+
it "resets properties as accessor" do
|
|
253
|
+
expect(@db).to receive(:"remove_relationship_properties").with(42, ["key"])
|
|
254
|
+
relationship.key = "value"
|
|
255
|
+
relationship.key = nil
|
|
256
|
+
end
|
|
257
|
+
|
|
258
|
+
it "resets properties as array entry" do
|
|
259
|
+
expect(@db).to receive(:"remove_relationship_properties").with(42, ["key"])
|
|
260
|
+
relationship["key"] = "value"
|
|
261
|
+
relationship["key"] = nil
|
|
262
|
+
end
|
|
263
|
+
|
|
264
|
+
it "gets unknown properties as nil" do
|
|
265
|
+
expect(relationship.unknown).to eq(nil)
|
|
266
|
+
end
|
|
267
|
+
|
|
268
|
+
it "overwrites existing properties" do
|
|
269
|
+
expect(@db).to receive(:"set_relationship_properties").with(42, { "key" => "value1" })
|
|
270
|
+
relationship.key = "value1"
|
|
271
|
+
|
|
272
|
+
expect(@db).to receive(:"set_relationship_properties").with(42, { "key" => "value2" })
|
|
273
|
+
relationship.key = "value2"
|
|
274
|
+
end
|
|
275
|
+
|
|
276
|
+
it "knows its attributes" do
|
|
277
|
+
allow(@db).to receive(:"set_relationship_properties")
|
|
278
|
+
relationship.key = "value"
|
|
279
|
+
relationship["key2"] = "value"
|
|
280
|
+
expect(relationship.attributes).to match_array([ :key, :key2 ])
|
|
281
|
+
end
|
|
282
|
+
|
|
283
|
+
end
|
|
284
|
+
end
|
|
285
|
+
end
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
module Neography
|
|
4
|
+
describe Relationship do
|
|
5
|
+
|
|
6
|
+
let(:db) { double(Rest).as_null_object }
|
|
7
|
+
let(:relationship_hash) do
|
|
8
|
+
{
|
|
9
|
+
"self" => "0",
|
|
10
|
+
"start" => "1",
|
|
11
|
+
"end" => "2",
|
|
12
|
+
"data" => {}
|
|
13
|
+
}
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
let(:from) { double(:neo_server => db) }
|
|
17
|
+
let(:to) { double(:neo_server => db) }
|
|
18
|
+
let(:props) { { :foo => "bar" } }
|
|
19
|
+
|
|
20
|
+
describe "::create" do
|
|
21
|
+
it "creates a new node through Rest" do
|
|
22
|
+
expect(db).to receive(:create_relationship).with("type", from, to, props)
|
|
23
|
+
|
|
24
|
+
Relationship.create("type", from, to, props)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
it "assigns fields" do
|
|
28
|
+
allow(db).to receive(:create_relationship).and_return(relationship_hash)
|
|
29
|
+
|
|
30
|
+
rel = Relationship.create("type", from, to, props)
|
|
31
|
+
|
|
32
|
+
expect(rel.start_node).to eq(from)
|
|
33
|
+
expect(rel.end_node).to eq(to)
|
|
34
|
+
expect(rel.rel_type).to eq("type")
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
describe "::load" do
|
|
39
|
+
context "no explicit server" do
|
|
40
|
+
|
|
41
|
+
before do
|
|
42
|
+
# stub out actual connections
|
|
43
|
+
@db = double(Rest).as_null_object
|
|
44
|
+
allow(Rest).to receive(:new) { @db }
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
it "load by id" do
|
|
48
|
+
expect(@db).to receive(:get_relationship).with(5)
|
|
49
|
+
Relationship.load(5)
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
it "loads by relationship" do
|
|
53
|
+
relationship = Relationship.new(relationship_hash)
|
|
54
|
+
expect(@db).to receive(:get_relationship).with(relationship)
|
|
55
|
+
Relationship.load(relationship)
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
it "loads by full server string" do
|
|
59
|
+
expect(@db).to receive(:get_relationship).with("http://localhost:7474/db/data/relationship/2")
|
|
60
|
+
Relationship.load("http://localhost:7474/db/data/relationship/2")
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
context "explicit server" do
|
|
66
|
+
|
|
67
|
+
it "cannot pass a server as the first argument, relationship as the second" do
|
|
68
|
+
@other_server = Neography::Rest.new
|
|
69
|
+
expect(@other_server).not_to receive(:get_relationship).with(42)
|
|
70
|
+
expect {
|
|
71
|
+
relationship = Relationship.load(@other_server, 42)
|
|
72
|
+
}.to raise_error(ArgumentError)
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
it "can pass a relationship as the first argument, server as the second" do
|
|
76
|
+
@other_server = Neography::Rest.new
|
|
77
|
+
expect(@other_server).to receive(:get_relationship).with(42)
|
|
78
|
+
relationship = Relationship.load(42, @other_server)
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
describe "#del" do
|
|
85
|
+
|
|
86
|
+
before do
|
|
87
|
+
allow(db).to receive(:create_relationship) { relationship_hash }
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
subject(:relationship) { Relationship.create("type", from, to, props) }
|
|
91
|
+
|
|
92
|
+
it "deletes a node" do
|
|
93
|
+
expect(db).to receive(:delete_relationship).with("0")
|
|
94
|
+
relationship.del
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
describe "#other_node" do
|
|
100
|
+
|
|
101
|
+
before do
|
|
102
|
+
allow(db).to receive(:create_relationship) { relationship_hash }
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
subject(:relationship) { Relationship.create("type", from, to, props) }
|
|
106
|
+
|
|
107
|
+
it "knows the other node based on from" do
|
|
108
|
+
expect(relationship.other_node(from)).to eq(to)
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
it "knows the other node based on to" do
|
|
112
|
+
expect(relationship.other_node(to)).to eq(from)
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
end
|
|
118
|
+
end
|