-
Notifications
You must be signed in to change notification settings - Fork 80
/
cypher_node_unit_spec.rb
108 lines (93 loc) · 4.31 KB
/
cypher_node_unit_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
require 'spec_helper'
module Neo4j::Server
describe CypherNode do
let(:session) do
allow_any_instance_of(CypherSession).to receive(:initialize_resource)
CypherSession.new('http://an.url', connection)
end
let(:connection) do
double('connection')
end
let(:match_string) { "MATCH (n) WHERE ID(n) = {neo_id}" }
describe 'instance methods' do
describe 'props' do
let(:cypher_body) do
JSON.parse <<-HERE
{
"columns" : [ "a" ],
"data" : [ [ {
"outgoing_relationships" : "http://localhost:7474/db/data/node/43/relationships/out",
"labels" : "http://localhost:7474/db/data/node/43/labels",
"data" : {
"name" : "andreas"
},
"all_typed_relationships" : "http://localhost:7474/db/data/node/43/relationships/all/{-list|&|types}",
"traverse" : "http://localhost:7474/db/data/node/43/traverse/{returnType}",
"self" : "http://localhost:7474/db/data/node/43",
"property" : "http://localhost:7474/db/data/node/43/properties/{key}",
"outgoing_typed_relationships" : "http://localhost:7474/db/data/node/43/relationships/out/{-list|&|types}",
"properties" : "http://localhost:7474/db/data/node/43/properties",
"incoming_relationships" : "http://localhost:7474/db/data/node/43/relationships/in",
"extensions" : {
},
"create_relationship" : "http://localhost:7474/db/data/node/43/relationships",
"paged_traverse" : "http://localhost:7474/db/data/node/43/paged/traverse/{returnType}{?pageSize,leaseTime}",
"all_relationships" : "http://localhost:7474/db/data/node/43/relationships/all",
"incoming_typed_relationships" : "http://localhost:7474/db/data/node/43/relationships/in/{-list|&|types}"
} ] ]
}
HERE
end
let(:cypher_response) do
double('cypher response', error?: false, first_data: cypher_body['data'][0][0])
end
it "returns all properties" do
node = CypherNode.new(session, 42)
expect(session).to receive(:_query_entity_data).with("#{match_string} RETURN n", nil, neo_id: 42).and_return({'data'=> {'name'=>'andreas'}})
expect(node.props).to eq({name: 'andreas'})
end
end
describe 'exist?' do
it "generates correct cypher" do
cypher_response = double("cypher response", error?: false)
expect(session).to receive(:_query).with("#{match_string} RETURN ID(n)", neo_id: 42).and_return(cypher_response)
node = CypherNode.new(session, 42)
node.init_resource_data('data', 'http://bla/42')
expect(cypher_response).to receive(:data).and_return([])
# when
node.exist?
end
it "returns true if response contains node data" do
node = CypherNode.new(session, 42)
node.init_resource_data('data', 'http://bla/42')
response = double('response', error?: false)
expect(session).to receive(:_query).and_return(response)
expect(response).to receive(:data).and_return([:foo])
expect(node.exist?).to be true
end
end
describe '[]=' do
it 'generates correct cypher' do
node = CypherNode.new(session, 42)
response = double("cypher response", error?: false)
expect(session).to receive(:_query).with("#{match_string} SET n.`name` = { value }", { value: 'andreas', neo_id: node.neo_id }).and_return(response)
node['name'] = 'andreas'
end
it 'removed property if setting it to a nil value' do
node = CypherNode.new(session, 42)
response = double("cypher response", error?: false)
expect(session).to receive(:_query).with("#{match_string} REMOVE n.`name`", neo_id: 42).and_return(response)
node['name'] = nil
end
end
describe '[]' do
it 'generates correct cypher' do
node = CypherNode.new(session, 42)
response = double('cypher response',first_data: 'andreas', error?: false)
expect(session).to receive(:_query).with("#{match_string} RETURN n.`name`", neo_id: 42).and_return(response)
expect(node['name']).to eq('andreas')
end
end
end
end
end