65
65
end
66
66
67
67
it "updates attributes on an existing relationship" do
68
+ create_node ( from )
69
+ create_node ( to )
70
+
71
+ relationship = Neo4j ::Http ::Relationship . new ( label : "KNOWS" , uuid : "RelationshipUuid" , age : 21 )
72
+ create_relationship ( from , relationship , to )
73
+
74
+ updated_relationship = Neo4j ::Http ::Relationship . new ( label : "KNOWS" , uuid : "RelationshipUuid" , age : 33 )
75
+ result = create_relationship ( from , updated_relationship , to )
76
+
77
+ expect ( result [ "relationship" ] . keys ) . to eq ( %w[ uuid age _neo4j_meta_data ] )
78
+ expect ( result [ "relationship" ] [ "uuid" ] ) . to eq ( "RelationshipUuid" )
79
+ expect ( result [ "relationship" ] [ "age" ] ) . to eq ( 33 )
80
+
81
+ rel = Neo4j ::Http ::Relationship . new ( label : "KNOWS" )
82
+ relationships = client . find_relationships ( relationship : rel , from : from , to : to )
83
+ expect ( relationships . count ) . to eq ( 1 )
84
+ end
85
+
86
+ it "allows relationships with same labels between same nodes if primary key is set and different" do
87
+ create_node ( from )
88
+ create_node ( to )
89
+
90
+ relationship_friend = Neo4j ::Http ::Relationship . new ( label : "KNOWS" , primary_key_name : "uuid" , uuid : "FriendUuid" , how : "friend" )
91
+ edge_a = create_relationship ( from , relationship_friend , to )
92
+
93
+ relationship_colleague = Neo4j ::Http ::Relationship . new ( label : "KNOWS" , primary_key_name : "uuid" , uuid : "ColleagueUuid" , how : "colleague" )
94
+ edge_b = create_relationship ( from , relationship_colleague , to )
95
+
96
+ expect ( edge_a [ "relationship" ] [ "uuid" ] ) . to eq ( "FriendUuid" )
97
+ expect ( edge_a [ "relationship" ] [ "how" ] ) . to eq ( "friend" )
98
+
99
+ expect ( edge_b [ "relationship" ] [ "uuid" ] ) . to eq ( "ColleagueUuid" )
100
+ expect ( edge_b [ "relationship" ] [ "how" ] ) . to eq ( "colleague" )
101
+
102
+ result = client . find_relationships ( relationship : relationship , from : from , to : to )
103
+
104
+ expect ( result . count ) . to eq ( 2 )
105
+ expect ( result [ 0 ] [ "from" ] [ "uuid" ] ) . to eq ( result [ 1 ] [ "from" ] [ "uuid" ] )
106
+ expect ( result [ 0 ] [ "to" ] [ "uuid" ] ) . to eq ( result [ 1 ] [ "to" ] [ "uuid" ] )
107
+ expect ( result [ 0 ] [ "relationship" ] [ "how" ] ) . not_to eq ( result [ 1 ] [ "relationship" ] [ "how" ] )
68
108
end
69
109
end
70
110
99
139
end
100
140
end
101
141
142
+ describe "delete_relationship_on_primary_key" do
143
+ it "removes the correct relationship" do
144
+ relationship1 = Neo4j ::Http ::Relationship . new ( label : "KNOWS" , primary_key_name : "how" , how : "friend" )
145
+ relationship2 = Neo4j ::Http ::Relationship . new ( label : "KNOWS" , primary_key_name : "how" , how : "colleague" )
146
+ client . upsert_relationship ( relationship : relationship1 , from : from , to : to , create_nodes : true )
147
+ client . upsert_relationship ( relationship : relationship2 , from : from , to : to , create_nodes : true )
148
+
149
+ expect ( client . find_relationships ( relationship : relationship , from : from , to : to ) . count ) . to eq ( 2 )
150
+
151
+ result = client . delete_relationship_on_primary_key ( relationship : relationship2 )
152
+ expect ( result . keys ) . to eq ( [ "relationship" ] )
153
+
154
+ rels = client . find_relationships ( relationship : relationship , from : from , to : to )
155
+ expect ( rels . count ) . to eq ( 1 )
156
+ expect ( rels . first [ "relationship" ] [ "how" ] ) . to eq ( "friend" )
157
+ end
158
+
159
+ it "doesn't delete if primary key is missing" do
160
+ relationship1 = Neo4j ::Http ::Relationship . new ( label : "KNOWS" , primary_key_name : "how" , how : "friend" )
161
+ relationship2 = Neo4j ::Http ::Relationship . new ( label : "KNOWS" , primary_key_name : "how" , how : "colleague" )
162
+ client . upsert_relationship ( relationship : relationship1 , from : from , to : to , create_nodes : true )
163
+ client . upsert_relationship ( relationship : relationship2 , from : from , to : to , create_nodes : true )
164
+
165
+ expect ( client . find_relationships ( relationship : relationship , from : from , to : to ) . count ) . to eq ( 2 )
166
+
167
+ result = client . delete_relationship_on_primary_key ( relationship : relationship )
168
+ expect ( result ) . to be_nil
169
+
170
+ expect ( client . find_relationships ( relationship : relationship , from : from , to : to ) . count ) . to eq ( 2 )
171
+ end
172
+ end
173
+
102
174
def verify_relationship ( from , relationship , to )
103
175
results = Neo4j ::Http ::CypherClient . default . execute_cypher (
104
176
"MATCH (from:Bot {uuid: $from})-[relationship:#{ relationship } ]-(to:Bot {uuid: $to})
@@ -116,4 +188,8 @@ def verify_relationship(from, relationship, to)
116
188
def create_node ( node )
117
189
Neo4j ::Http ::NodeClient . default . upsert_node ( node )
118
190
end
191
+
192
+ def create_relationship ( from , relationship , to )
193
+ Neo4j ::Http ::RelationshipClient . default . upsert_relationship ( from : from , relationship : relationship , to : to )
194
+ end
119
195
end
0 commit comments