neography-calamitates 1.2.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (120) hide show
  1. data/.gitignore +15 -0
  2. data/.project +12 -0
  3. data/.travis.yml +4 -0
  4. data/CONTRIBUTORS +18 -0
  5. data/Gemfile +4 -0
  6. data/LICENSE +19 -0
  7. data/README.md +261 -0
  8. data/Rakefile +14 -0
  9. data/examples/facebook.rb +40 -0
  10. data/examples/facebook_v2.rb +25 -0
  11. data/examples/greatest.rb +43 -0
  12. data/examples/linkedin.rb +39 -0
  13. data/examples/linkedin_v2.rb +22 -0
  14. data/examples/traversal_example1.rb +65 -0
  15. data/examples/traversal_example2.rb +54 -0
  16. data/lib/neography.rb +45 -0
  17. data/lib/neography/config.rb +52 -0
  18. data/lib/neography/connection.rb +203 -0
  19. data/lib/neography/equal.rb +21 -0
  20. data/lib/neography/errors.rb +45 -0
  21. data/lib/neography/index.rb +52 -0
  22. data/lib/neography/multi_json_parser.rb +28 -0
  23. data/lib/neography/neography.rb +10 -0
  24. data/lib/neography/node.rb +53 -0
  25. data/lib/neography/node_path.rb +29 -0
  26. data/lib/neography/node_relationship.rb +37 -0
  27. data/lib/neography/node_traverser.rb +146 -0
  28. data/lib/neography/path_traverser.rb +100 -0
  29. data/lib/neography/property.rb +61 -0
  30. data/lib/neography/property_container.rb +29 -0
  31. data/lib/neography/railtie.rb +19 -0
  32. data/lib/neography/relationship.rb +70 -0
  33. data/lib/neography/relationship_traverser.rb +80 -0
  34. data/lib/neography/rest.rb +470 -0
  35. data/lib/neography/rest/auto_indexes.rb +64 -0
  36. data/lib/neography/rest/batch.rb +277 -0
  37. data/lib/neography/rest/clean.rb +19 -0
  38. data/lib/neography/rest/cypher.rb +33 -0
  39. data/lib/neography/rest/extensions.rb +25 -0
  40. data/lib/neography/rest/gremlin.rb +24 -0
  41. data/lib/neography/rest/helpers.rb +38 -0
  42. data/lib/neography/rest/indexes.rb +100 -0
  43. data/lib/neography/rest/node_auto_indexes.rb +14 -0
  44. data/lib/neography/rest/node_indexes.rb +50 -0
  45. data/lib/neography/rest/node_labels.rb +60 -0
  46. data/lib/neography/rest/node_paths.rb +57 -0
  47. data/lib/neography/rest/node_properties.rb +11 -0
  48. data/lib/neography/rest/node_relationships.rb +42 -0
  49. data/lib/neography/rest/node_traversal.rb +81 -0
  50. data/lib/neography/rest/nodes.rb +102 -0
  51. data/lib/neography/rest/other_node_relationships.rb +48 -0
  52. data/lib/neography/rest/paths.rb +36 -0
  53. data/lib/neography/rest/properties.rb +56 -0
  54. data/lib/neography/rest/relationship_auto_indexes.rb +14 -0
  55. data/lib/neography/rest/relationship_indexes.rb +35 -0
  56. data/lib/neography/rest/relationship_properties.rb +11 -0
  57. data/lib/neography/rest/relationship_types.rb +18 -0
  58. data/lib/neography/rest/relationships.rb +23 -0
  59. data/lib/neography/rest/schema_indexes.rb +34 -0
  60. data/lib/neography/rest/transactions.rb +102 -0
  61. data/lib/neography/tasks.rb +158 -0
  62. data/lib/neography/version.rb +3 -0
  63. data/neography.gemspec +32 -0
  64. data/spec/integration/authorization_spec.rb +48 -0
  65. data/spec/integration/index_spec.rb +70 -0
  66. data/spec/integration/neography_spec.rb +10 -0
  67. data/spec/integration/node_encoding_spec.rb +71 -0
  68. data/spec/integration/node_path_spec.rb +222 -0
  69. data/spec/integration/node_relationship_spec.rb +381 -0
  70. data/spec/integration/node_spec.rb +251 -0
  71. data/spec/integration/parsing_spec.rb +13 -0
  72. data/spec/integration/performance_spec.rb +17 -0
  73. data/spec/integration/relationship_spec.rb +37 -0
  74. data/spec/integration/rest_batch_spec.rb +512 -0
  75. data/spec/integration/rest_batch_streaming_spec.rb +32 -0
  76. data/spec/integration/rest_bulk_spec.rb +106 -0
  77. data/spec/integration/rest_experimental_spec.rb +22 -0
  78. data/spec/integration/rest_gremlin_fail_spec.rb +46 -0
  79. data/spec/integration/rest_header_spec.rb +14 -0
  80. data/spec/integration/rest_index_spec.rb +468 -0
  81. data/spec/integration/rest_labels_spec.rb +128 -0
  82. data/spec/integration/rest_node_spec.rb +274 -0
  83. data/spec/integration/rest_other_node_relationship_spec.rb +137 -0
  84. data/spec/integration/rest_path_spec.rb +231 -0
  85. data/spec/integration/rest_plugin_spec.rb +177 -0
  86. data/spec/integration/rest_relationship_spec.rb +354 -0
  87. data/spec/integration/rest_relationship_types_spec.rb +18 -0
  88. data/spec/integration/rest_schema_index_spec.rb +32 -0
  89. data/spec/integration/rest_transaction_spec.rb +166 -0
  90. data/spec/integration/rest_traverse_spec.rb +149 -0
  91. data/spec/matchers.rb +33 -0
  92. data/spec/neography_spec.rb +23 -0
  93. data/spec/spec_helper.rb +45 -0
  94. data/spec/unit/config_spec.rb +46 -0
  95. data/spec/unit/connection_spec.rb +211 -0
  96. data/spec/unit/node_spec.rb +100 -0
  97. data/spec/unit/properties_spec.rb +140 -0
  98. data/spec/unit/relationship_spec.rb +118 -0
  99. data/spec/unit/rest/batch_spec.rb +243 -0
  100. data/spec/unit/rest/clean_spec.rb +17 -0
  101. data/spec/unit/rest/cypher_spec.rb +21 -0
  102. data/spec/unit/rest/extensions_spec.rb +29 -0
  103. data/spec/unit/rest/gremlin_spec.rb +26 -0
  104. data/spec/unit/rest/labels_spec.rb +73 -0
  105. data/spec/unit/rest/node_auto_indexes_spec.rb +67 -0
  106. data/spec/unit/rest/node_indexes_spec.rb +141 -0
  107. data/spec/unit/rest/node_paths_spec.rb +80 -0
  108. data/spec/unit/rest/node_properties_spec.rb +80 -0
  109. data/spec/unit/rest/node_relationships_spec.rb +78 -0
  110. data/spec/unit/rest/node_traversal_spec.rb +128 -0
  111. data/spec/unit/rest/nodes_spec.rb +188 -0
  112. data/spec/unit/rest/paths_spec.rb +69 -0
  113. data/spec/unit/rest/relationship_auto_indexes_spec.rb +67 -0
  114. data/spec/unit/rest/relationship_indexes_spec.rb +132 -0
  115. data/spec/unit/rest/relationship_properties_spec.rb +80 -0
  116. data/spec/unit/rest/relationship_types_spec.rb +16 -0
  117. data/spec/unit/rest/relationships_spec.rb +22 -0
  118. data/spec/unit/rest/schema_index_spec.rb +31 -0
  119. data/spec/unit/rest/transactions_spec.rb +44 -0
  120. metadata +372 -0
@@ -0,0 +1,128 @@
1
+ require 'spec_helper'
2
+
3
+ module Neography
4
+ class Rest
5
+ describe NodeTraversal do
6
+
7
+ let(:connection) { double }
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) { double }
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) { double(: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) { double }
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