neography 1.5.1 → 1.5.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a16e39f25ab231bc89fdd3264b2733afe76ba05c
4
- data.tar.gz: c8f8bda96a4a56e46883c98724e6595b34ffbf93
3
+ metadata.gz: 89f4b73b7076509662fa63dcd258140246c1eba9
4
+ data.tar.gz: c7d4f53d9ab25de8d6c1e392387581b667cb4688
5
5
  SHA512:
6
- metadata.gz: fa8b0790fc17409f22d894f10256a83773992047d7e63dd9864cc6e3d8b40b55f24caa4d907a83b5f3902892fe5d21e68a015ce190898b46391a14ed5d2146ad
7
- data.tar.gz: d2bc2fbec2ded020a7f3df4d010f06380c6c936c6849f2088d15e4c931323cd14938a2571982a1e4aeac620748c1590ebe0865234207560c81e0001a0a81650b
6
+ metadata.gz: ee4def6fd87563f802e9019f43b808525c6d9a13d2d137613b587c37cbd714cb832d0fb243702c0b3a9f53009b71f8c743820a88ef27b58f16a21e330360f631
7
+ data.tar.gz: 0c63606246d769a7af6e45eb3fe44903994e6a201514e27d56807da6953dc7a3267c3b5f96a9bdce2a6f2f51ff5f0a6aeaf6ada15fe961edc03584a2d032d2cc
data/Guardfile CHANGED
@@ -1,14 +1,6 @@
1
- # A sample Guardfile
2
- # More info at https://github.com/guard/guard#readme
3
-
4
1
  guard :rspec do
5
- # Just rerun the whole suite until the file names are matching
6
- # in lib/ and spec/
7
- #
8
- # watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
9
- # watch(%r{^lib/(.+)\.rb$}) { |m| "spec/unit/lib/#{m[1]}_spec.rb" }
10
- watch(%r{^lib/(.+)\.rb$}) { "spec" }
11
-
2
+ watch(%r{^lib/neography/(.+)\.rb$}) { |m| "spec/unit/#{m[1]}_spec.rb" }
3
+ watch(%r{^lib/neography/(.+)\.rb$}) { |m| "spec/integration/#{m[1]}_spec.rb" }
12
4
  watch(%r{^spec/.+_spec\.rb$})
13
5
  watch('spec/spec_helper.rb') { "spec" }
14
6
  end
@@ -213,7 +213,7 @@ module Neography
213
213
  message = parsed_body["message"]
214
214
  stacktrace = parsed_body["stacktrace"]
215
215
 
216
- @logger.error "#{response.dump} error: #{body}" if @log_enabled
216
+ @logger.error "#{response.data} error: #{body}" if @log_enabled
217
217
  raise_errors(code, parsed_body["exception"], message, stacktrace, request, index)
218
218
  end
219
219
 
@@ -53,11 +53,34 @@ module Neography
53
53
  end
54
54
  end
55
55
 
56
- ##
57
- # List of labels of current node.
58
- # Returns array of strings
59
56
  def labels
60
- self.neo_server.get_node_labels(self.neo_id)
57
+ @cached_labels ||= [self.neo_server.get_node_labels(self.neo_id)].compact.flatten
58
+ end
59
+
60
+ def set_labels(labels)
61
+ # I just invalidate the cache instead of updating it to make sure
62
+ # it doesn't contain something else than what ends up in neo4j
63
+ # (consider duplicate/invalid labels, etc).
64
+ @cached_labels = nil
65
+ self.neo_server.set_label(self, [labels].flatten)
66
+ end
67
+ alias_method :set_label, :set_labels
68
+
69
+ def add_labels(labels)
70
+ # Just invalidating the cache on purpose, see set_labels
71
+ @cached_labels = nil
72
+ self.neo_server.add_label(self, [labels].flatten)
73
+ end
74
+ alias_method :add_label, :add_labels
75
+
76
+
77
+ def delete_label(label)
78
+ @cached_labels = nil
79
+ self.neo_server.delete_label(self, label)
80
+ end
81
+
82
+ def cached_labels=(labels)
83
+ @cached_labels = [labels].flatten
61
84
  end
62
85
  end
63
86
  end
@@ -1,3 +1,3 @@
1
1
  module Neography
2
- VERSION = "1.5.1"
2
+ VERSION = "1.5.2"
3
3
  end
data/neography.gemspec CHANGED
@@ -20,7 +20,7 @@ Gem::Specification.new do |s|
20
20
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
21
21
  s.require_paths = ["lib"]
22
22
 
23
- s.add_development_dependency "rspec", ">= 2.11"
23
+ s.add_development_dependency "rspec", "3.0"
24
24
  s.add_development_dependency "net-http-spy", "0.2.1"
25
25
  s.add_development_dependency "coveralls"
26
26
  s.add_development_dependency "debugger"
@@ -247,14 +247,41 @@ describe Neography::Node do
247
247
  end
248
248
  end
249
249
 
250
- describe 'gets labels' do
251
- let(:subject) {
250
+ describe 'labels' do
251
+
252
+ it "loading from neo4j" do
252
253
  node = Neography::Node.create
253
254
  node.neo_server.add_label(node, 'Label')
254
255
  node.neo_server.add_label(node, 'Label2')
255
- node
256
- }
256
+ expect(node.labels).to eq(%w(Label Label2))
257
+ end
258
+
259
+ it "adding via the node" do
260
+ node = Neography::Node.create
261
+ node.neo_server.add_label(node, 'Label')
262
+ node.add_labels('Label2')
263
+ expect(node.labels).to eq(%w(Label Label2))
264
+ end
265
+
266
+ it "resetting via the node" do
267
+ node = Neography::Node.create
268
+ node.neo_server.add_label(node, 'Label')
269
+ expect do
270
+ node.set_labels("Reset")
271
+ end.to change{ node.labels }.from(['Label']).to(["Reset"])
272
+ end
273
+
274
+ it "deleting via the node" do
275
+ node = Neography::Node.create
276
+ node.neo_server.add_label(node, 'Label')
277
+ expect do
278
+ node.delete_label("Label")
279
+ end.to change{ node.labels }.from(['Label']).to([])
280
+ end
281
+
282
+
283
+
257
284
 
258
- it { expect(subject.labels).to eq(%w(Label Label2)) }
259
285
  end
286
+
260
287
  end
data/spec/spec_helper.rb CHANGED
@@ -39,6 +39,7 @@ def error_response(attributes)
39
39
  message: attributes[:message],
40
40
  exception: attributes[:exception],
41
41
  stacktrace: attributes[:stacktrace]
42
- }.reject { |k,v| v.nil? }.to_json
42
+ }.reject { |k,v| v.nil? }.to_json,
43
+ data: http_header
43
44
  )
44
45
  end
@@ -156,6 +156,13 @@ module Neography
156
156
 
157
157
  context "errors" do
158
158
 
159
+ subject(:connection) do
160
+ Connection.new({
161
+ :logger => Logger.new(nil),
162
+ :log_enabled => true
163
+ })
164
+ end
165
+
159
166
  it "raises NodeNotFoundException" do
160
167
  response = error_response(code: 404, message: "a message", exception: "NodeNotFoundException")
161
168
  allow(connection.client).to receive(:request).and_return(response)
@@ -27,6 +27,76 @@ module Neography
27
27
  Node.create(properties)
28
28
  end
29
29
 
30
+ describe "labels" do
31
+ let(:node){ Node.create }
32
+
33
+ it "are only fetched once" do
34
+ expect(@db).to receive(:get_node_labels).exactly(1).and_return []
35
+ node.labels
36
+ node.labels
37
+ end
38
+
39
+ it "cache can be set from the outside" do
40
+ expect(@db).to_not receive(:get_node_labels)
41
+ node.cached_labels = ["Bar"]
42
+
43
+ expect(node.labels).to eq ["Bar"]
44
+ end
45
+
46
+ it "cache is invalidated when labels are set" do
47
+ expect(@db).to receive(:get_node_labels).exactly(2).and_return []
48
+ expect(@db).to receive(:set_label).exactly(1)
49
+ node.labels
50
+ node.set_labels("Something")
51
+ node.labels
52
+ end
53
+
54
+ it "cache is invalidated when labels are set" do
55
+ expect(@db).to receive(:get_node_labels).exactly(2).and_return []
56
+ expect(@db).to receive(:add_label).exactly(1)
57
+ node.labels
58
+ node.add_labels("Something")
59
+ node.labels
60
+ end
61
+
62
+ it "cache is invalidated when labels are deleted" do
63
+ expect(@db).to receive(:get_node_labels).exactly(2).and_return []
64
+ expect(@db).to receive(:delete_label).exactly(1)
65
+ node.labels
66
+ node.delete_label("Something")
67
+ node.labels
68
+ end
69
+
70
+ describe "set" do
71
+ it "as a single label" do
72
+ expect(@db).to receive(:set_label).with(node, ["Foo"])
73
+ node.set_label("Foo")
74
+ end
75
+
76
+ it "as an array" do
77
+ expect(@db).to receive(:set_label).with(node, ["Foo"])
78
+ node.set_labels(["Foo"])
79
+ end
80
+ end
81
+
82
+ describe "add" do
83
+ it "as a single label" do
84
+ expect(@db).to receive(:add_label).with(node, ["Foo"])
85
+ node.add_label("Foo")
86
+ end
87
+
88
+ it "as an array" do
89
+ expect(@db).to receive(:add_label).with(node, ["Foo"])
90
+ node.add_labels(["Foo"])
91
+ end
92
+ end
93
+
94
+ it "can be deleted" do
95
+ expect(@db).to receive(:delete_label).with(node, "Foo")
96
+ node.delete_label("Foo")
97
+ end
98
+ end
99
+
30
100
  end
31
101
 
32
102
  context "explicit server" do
@@ -79,18 +149,18 @@ module Neography
79
149
 
80
150
  context "explicit server" do
81
151
 
82
- it "cannot pass a server as the first argument, node as the second (depracted)" do
152
+ it "cannot pass a server as the first argument, node as the second (deprecated)" do
83
153
  @other_server = Neography::Rest.new
84
154
  expect(@other_server).not_to receive(:get_node).with(42)
85
155
  expect {
86
- node = Node.load(@other_server, 42)
156
+ Node.load(@other_server, 42)
87
157
  }.to raise_error(ArgumentError)
88
158
  end
89
159
 
90
160
  it "can pass a node as the first argument, server as the second" do
91
161
  @other_server = Neography::Rest.new
92
162
  expect(@other_server).to receive(:get_node).with(42)
93
- node = Node.load(42, @other_server)
163
+ Node.load(42, @other_server)
94
164
  end
95
165
 
96
166
  end
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: neography
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.1
4
+ version: 1.5.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Max De Marzi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-09 00:00:00.000000000 Z
11
+ date: 2014-06-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - '='
18
18
  - !ruby/object:Gem::Version
19
- version: '2.11'
19
+ version: '3.0'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ">="
24
+ - - '='
25
25
  - !ruby/object:Gem::Version
26
- version: '2.11'
26
+ version: '3.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: net-http-spy
29
29
  requirement: !ruby/object:Gem::Requirement