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,46 @@
1
+ require 'spec_helper'
2
+
3
+ module Neography
4
+ describe Config do
5
+
6
+ subject(:config) { Config.new }
7
+
8
+ context "defaults" do
9
+
10
+ its(:protocol) { should == 'http://' }
11
+ its(:server) { should == 'localhost' }
12
+ its(:port) { should == 7474 }
13
+ its(:directory) { should == '' }
14
+ its(:cypher_path) { should == '/cypher' }
15
+ its(:gremlin_path) { should == '/ext/GremlinPlugin/graphdb/execute_script' }
16
+ its(:log_file) { should == 'neography.log' }
17
+ its(:log_enabled) { should == false }
18
+ its(:max_threads) { should == 20 }
19
+ its(:authentication) { should == nil }
20
+ its(:username) { should == nil }
21
+ its(:password) { should == nil }
22
+ its(:parser) { should == MultiJsonParser}
23
+
24
+ it "has a hash representation" do
25
+ expected_hash = {
26
+ :protocol => 'http://',
27
+ :server => 'localhost',
28
+ :port => 7474,
29
+ :directory => '',
30
+ :cypher_path => '/cypher',
31
+ :gremlin_path => '/ext/GremlinPlugin/graphdb/execute_script',
32
+ :log_file => 'neography.log',
33
+ :log_enabled => false,
34
+ :max_threads => 20,
35
+ :authentication => nil,
36
+ :username => nil,
37
+ :password => nil,
38
+ :parser => MultiJsonParser
39
+ }
40
+ config.to_hash.should == expected_hash
41
+ end
42
+
43
+ end
44
+
45
+ end
46
+ end
@@ -0,0 +1,211 @@
1
+ require 'spec_helper'
2
+
3
+ module Neography
4
+ describe Connection do
5
+
6
+ subject(:connection) { Connection.new }
7
+
8
+ context "defaults" do
9
+
10
+ it "intializes with defaults" do
11
+ connection.configuration.should == "http://localhost:7474/db/data"
12
+ end
13
+
14
+ end
15
+
16
+ context "custom options" do
17
+
18
+ subject(:connection) { Connection.new(options) }
19
+
20
+ context "hash options" do
21
+ let(:options) do
22
+ {
23
+ :protocol => "https://",
24
+ :server => "foobar",
25
+ :port => 4242,
26
+ :directory => "/dir",
27
+ :cypher_path => "/cyph",
28
+ :gremlin_path => "/grem",
29
+ :log_file => "neo.log",
30
+ :log_enabled => false,
31
+ :max_threads => 10,
32
+ :parser => Foo,
33
+ :authentication => "foo",
34
+ :username => "bar",
35
+ :password => "baz"
36
+ }
37
+ end
38
+
39
+ it "accepts all options in a hash" do
40
+ connection.configuration.should == "https://foobar:4242/dir/db/data"
41
+
42
+ connection.protocol.should == "https://"
43
+ connection.server.should == "foobar"
44
+ connection.port.should == 4242
45
+ connection.directory.should == "/dir"
46
+ connection.cypher_path.should == "/cyph"
47
+ connection.gremlin_path.should == "/grem"
48
+ connection.log_file.should == "neo.log"
49
+ connection.log_enabled.should == false
50
+ connection.max_threads.should == 10
51
+ connection.parser.should == Foo
52
+
53
+ connection.authentication.should == {
54
+ :foo_auth => {
55
+ :username => "bar",
56
+ :password => "baz"
57
+ }
58
+ }
59
+ end
60
+ end
61
+
62
+ context "string option" do
63
+ let(:options) { "https://user:pass@somehost:8585/path" }
64
+
65
+ it "accepts a string as configuration" do
66
+ connection.configuration.should == "https://somehost:8585/path/db/data"
67
+ connection.authentication.should == {
68
+ :basic_auth => {
69
+ :username => "user",
70
+ :password => "pass"
71
+ }
72
+ }
73
+ end
74
+ end
75
+
76
+ end
77
+
78
+ context "requests" do
79
+
80
+ it "does a GET request" do
81
+ connection.client.should_receive(:get).with("http://localhost:7474/db/data/foo/bar", nil, nil) { double.as_null_object }
82
+ connection.get("/foo/bar")
83
+ end
84
+
85
+ it "does a POST request" do
86
+ connection.client.should_receive(:post).with("http://localhost:7474/db/data/foo/bar", nil, nil) { double.as_null_object }
87
+ connection.post("/foo/bar")
88
+ end
89
+
90
+ it "does a PUT request" do
91
+ connection.client.should_receive(:put).with("http://localhost:7474/db/data/foo/bar", nil, nil) { double.as_null_object }
92
+ connection.put("/foo/bar")
93
+ end
94
+
95
+ it "does a DELETE request" do
96
+ connection.client.should_receive(:delete).with("http://localhost:7474/db/data/foo/bar", nil, nil) { double.as_null_object }
97
+ connection.delete("/foo/bar")
98
+ end
99
+
100
+ context "authentication" do
101
+ subject(:connection) do
102
+ Connection.new({
103
+ :authentication => "basic",
104
+ :username => "foo",
105
+ :password => "bar"
106
+ })
107
+ end
108
+
109
+ it "does requests with authentication" do
110
+ connection.client.should_receive(:set_auth).with(
111
+ "http://localhost:7474/db/data/foo/bar",
112
+ "foo",
113
+ "bar") { double.as_null_object }
114
+
115
+ connection.client.should_receive(:get).with(
116
+ "http://localhost:7474/db/data/foo/bar", nil, nil
117
+ ) { double.as_null_object }
118
+
119
+ connection.get("/foo/bar")
120
+ end
121
+ end
122
+
123
+ it "adds the User-Agent to the headers" do
124
+ connection.client.should_receive(:get).with(
125
+ "http://localhost:7474/db/data/foo/bar",
126
+ nil, { "User-Agent" => "Neography/#{Neography::VERSION}", "X-Stream"=>true}
127
+ ) { double.as_null_object }
128
+
129
+ connection.get("/foo/bar", :headers => {})
130
+ end
131
+
132
+ context "errors" do
133
+
134
+ it "raises NodeNotFoundException" do
135
+ response = error_response(code: 404, message: "a message", exception: "NodeNotFoundException")
136
+ connection.client.stub(:get).and_return(response)
137
+ expect {
138
+ connection.get("/foo/bar")
139
+ }.to raise_error NodeNotFoundException
140
+ end
141
+
142
+ it "raises OperationFailureException" do
143
+ response = error_response(code: 409, message: "a message", exception: "OperationFailureException")
144
+ connection.client.stub(:get).and_return(response)
145
+ expect {
146
+ connection.get("/foo/bar")
147
+ }.to raise_error OperationFailureException
148
+ end
149
+
150
+ it "raises PropertyValueException" do
151
+ response = error_response(code: 400, message: "a message", exception: "PropertyValueException")
152
+ connection.client.stub(:get).and_return(response)
153
+ expect {
154
+ connection.get("/foo/bar")
155
+ }.to raise_error PropertyValueException
156
+ end
157
+
158
+ it "raises NoSuchPropertyException" do
159
+ response = error_response(code: 404, message: "a message", exception: "NoSuchPropertyException")
160
+ connection.client.stub(:get).and_return(response)
161
+ expect {
162
+ connection.get("/foo/bar")
163
+ }.to raise_error NoSuchPropertyException
164
+ end
165
+
166
+ it "raises RelationshipNotFoundException" do
167
+ response = error_response(code: 404, message: "a message", exception: "RelationshipNotFoundException")
168
+ connection.client.stub(:get).and_return(response)
169
+ expect {
170
+ connection.get("/foo/bar")
171
+ }.to raise_error RelationshipNotFoundException
172
+ end
173
+
174
+ it "raises BadInputException" do
175
+ response = error_response(code: 400, message: "a message", exception: "BadInputException")
176
+ connection.client.stub(:get).and_return(response)
177
+ expect {
178
+ connection.get("/foo/bar")
179
+ }.to raise_error BadInputException
180
+ end
181
+
182
+ it "raises UnauthorizedError" do
183
+ response = error_response(code: 401)
184
+ connection.client.stub(:get).and_return(response)
185
+ expect {
186
+ connection.get("/foo/bar")
187
+ }.to raise_error UnauthorizedError
188
+ end
189
+
190
+ it "raises NeographyError in all other cases" do
191
+ response = error_response(code: 418, message: "I'm a teapot.")
192
+ connection.client.stub(:get).and_return(response)
193
+ expect {
194
+ connection.get("/foo/bar")
195
+ }.to raise_error NeographyError
196
+ end
197
+
198
+ it "raises BadInputException" do
199
+ response = error_response(code: 500, message: "a message", exception: "JsonParseException")
200
+ connection.client.stub(:get).and_return(response)
201
+ expect {
202
+ connection.get("/foo/bar")
203
+ }.to raise_error NeographyError
204
+ end
205
+
206
+ end
207
+ end
208
+ end
209
+ end
210
+
211
+ class Foo; end
@@ -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
+ Rest.stub(:new) { @db }
12
+ end
13
+
14
+ it "assigns a new Rest db by default" do
15
+ node = Node.create
16
+ node.neo_server.should == @db
17
+ end
18
+
19
+ it "creates without arguments" do
20
+ @db.should_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
+ @db.should_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
+ @other_server.should_not_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
+ @other_server.should_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
+ Rest.stub(:new) { @db }
60
+ end
61
+
62
+ it "load by id" do
63
+ @db.should_receive(:get_node).with(5)
64
+ Node.load(5)
65
+ end
66
+
67
+ it "loads by node" do
68
+ node = Node.new
69
+ @db.should_not_receive(:get_node).with(node)
70
+ Node.load(node)
71
+ end
72
+
73
+ it "loads by full server string" do
74
+ @db.should_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
+ @other_server.should_not_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
+ @other_server.should_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,140 @@
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
+ Rest.stub(:new) { @db }
9
+ end
10
+
11
+ context "Node" do
12
+
13
+ subject(:node) do
14
+ node = Node.create
15
+ node.stub(:neo_id => 42)
16
+ node
17
+ end
18
+
19
+ it "sets properties as accessor" do
20
+ @db.should_receive(:"set_node_properties").with(42, { "key" => "value" })
21
+ node.key = "value"
22
+ end
23
+
24
+ it "sets properties as array entry" do
25
+ @db.should_receive(:"set_node_properties").with(42, { "key" => "value" })
26
+ node["key"] = "value"
27
+ end
28
+
29
+ it "gets properties as accessor" do
30
+ @db.stub(:"set_node_properties")
31
+ node.key = "value"
32
+ node.key.should == "value"
33
+ end
34
+
35
+ it "gets properties as array entry" do
36
+ @db.stub(:"set_node_properties")
37
+ node["key"] = "value"
38
+ node["key"].should == "value"
39
+ end
40
+
41
+ it "resets properties as accessor" do
42
+ @db.should_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
+ @db.should_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
+ node.unknown.should == nil
55
+ end
56
+
57
+ it "overwrites existing properties" do
58
+ @db.should_receive(:"set_node_properties").with(42, { "key" => "value1" })
59
+ node.key = "value1"
60
+
61
+ @db.should_receive(:"set_node_properties").with(42, { "key" => "value2" })
62
+ node.key = "value2"
63
+ end
64
+
65
+ it "knows its attributes" do
66
+ @db.stub(:"set_node_properties")
67
+ node.key = "value"
68
+ node["key2"] = "value"
69
+ node.attributes.should =~ [ :key, :key2 ]
70
+ end
71
+
72
+ end
73
+
74
+ context "Relationship" do
75
+
76
+ subject(:relationship) do
77
+ from = Node.create
78
+ to = Node.create
79
+
80
+ rel = Relationship.create(:type, from, to)
81
+ rel.stub(:neo_id => 42)
82
+ rel
83
+ end
84
+
85
+ it "sets properties as accessor" do
86
+ @db.should_receive(:"set_relationship_properties").with(42, { "key" => "value" })
87
+ relationship.key = "value"
88
+ end
89
+
90
+ it "sets properties as array entry" do
91
+ @db.should_receive(:"set_relationship_properties").with(42, { "key" => "value" })
92
+ relationship["key"] = "value"
93
+ end
94
+
95
+ it "gets properties as accessor" do
96
+ @db.stub(:"set_relationship_properties")
97
+ relationship.key = "value"
98
+ relationship.key.should == "value"
99
+ end
100
+
101
+ it "gets properties as array entry" do
102
+ @db.stub(:"set_relationship_properties")
103
+ relationship["key"] = "value"
104
+ relationship["key"].should == "value"
105
+ end
106
+
107
+ it "resets properties as accessor" do
108
+ @db.should_receive(:"remove_relationship_properties").with(42, ["key"])
109
+ relationship.key = "value"
110
+ relationship.key = nil
111
+ end
112
+
113
+ it "resets properties as array entry" do
114
+ @db.should_receive(:"remove_relationship_properties").with(42, ["key"])
115
+ relationship["key"] = "value"
116
+ relationship["key"] = nil
117
+ end
118
+
119
+ it "gets unknown properties as nil" do
120
+ relationship.unknown.should == nil
121
+ end
122
+
123
+ it "overwrites existing properties" do
124
+ @db.should_receive(:"set_relationship_properties").with(42, { "key" => "value1" })
125
+ relationship.key = "value1"
126
+
127
+ @db.should_receive(:"set_relationship_properties").with(42, { "key" => "value2" })
128
+ relationship.key = "value2"
129
+ end
130
+
131
+ it "knows its attributes" do
132
+ @db.stub(:"set_relationship_properties")
133
+ relationship.key = "value"
134
+ relationship["key2"] = "value"
135
+ relationship.attributes.should =~ [ :key, :key2 ]
136
+ end
137
+
138
+ end
139
+ end
140
+ end