neography 1.1.1 → 1.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -13,7 +13,7 @@ Neography is a thin Ruby wrapper to the Neo4j Rest API, for more information:
13
13
  * [Getting Started with Neo4j Server](http://neo4j.org/community/)
14
14
  * [Neo4j Rest API Reference](http://docs.neo4j.org/chunked/milestone/rest-api.html)
15
15
 
16
- If you want to the full power of Neo4j, you will want to use JRuby and the excellent Neo4j.rb gem at https://github.com/andreasronge/neo4j by Andreas Ronge
16
+ If you want to utilize the full power of Neo4j, you will want to use JRuby and the excellent Neo4j.rb gem at https://github.com/andreasronge/neo4j by Andreas Ronge
17
17
 
18
18
 
19
19
  ## Installation
@@ -110,7 +110,7 @@ module Neography
110
110
  code, body, parsed = handle_batch(response)
111
111
  else
112
112
  code = response.code
113
- body = response.body
113
+ body = response.body.force_encoding("UTF-8")
114
114
  parsed = false
115
115
  end
116
116
  return_result(code, body, parsed)
@@ -118,7 +118,7 @@ module Neography
118
118
 
119
119
  def handle_batch(response)
120
120
  code = 200
121
- body = @parser.json(response.body)
121
+ body = @parser.json(response.body.force_encoding("UTF-8"))
122
122
  body.each do |result|
123
123
  if result["status"] >= 400
124
124
  code = result["status"]
@@ -7,7 +7,7 @@ module Neography
7
7
  # See: http://api.rubyonrails.org/classes/Rails/Railtie.html
8
8
  initializer 'neography.configure' do
9
9
  # Provides a hook so people implementing the gem can do this in a railtie of their own:
10
- # initializer "my_thing.neography_initialization", before: 'neography_railtie.configure_rails_initialization' do
10
+ # initializer "my_thing.neography_initialization", before: 'neography.configure' do
11
11
  # require 'my_thing/neography'
12
12
  # end
13
13
  end
@@ -13,7 +13,7 @@ module Neography
13
13
  :query => query,
14
14
  :params => parameters
15
15
  }.to_json,
16
- :headers => json_content_type.merge({'Accept' => 'application/json;stream=true'})
16
+ :headers => json_content_type.merge({'Accept' => 'application/json;stream=true;charset=UTF-8'})
17
17
  }
18
18
 
19
19
  @connection.post(optioned_path(cypher_options), options)
@@ -17,11 +17,11 @@ module Neography
17
17
  def list
18
18
  @connection.get(base_path)
19
19
  end
20
-
20
+
21
21
  def get(id)
22
- @connection.get(node_path(:id => id))
22
+ @connection.get(node_path(:id => get_id(id)))
23
23
  end
24
-
24
+
25
25
  def get_nodes(label)
26
26
  @connection.get(nodes_path(:label => label))
27
27
  end
@@ -37,9 +37,9 @@ module Neography
37
37
  ).to_json,
38
38
  :headers => json_content_type
39
39
  }
40
- @connection.post(node_path(:id => id), options)
40
+ @connection.post(node_path(:id => get_id(id)), options)
41
41
  end
42
-
42
+
43
43
  def set(id, label)
44
44
  options = {
45
45
  :body => (
@@ -47,11 +47,11 @@ module Neography
47
47
  ).to_json,
48
48
  :headers => json_content_type
49
49
  }
50
- @connection.put(node_path(:id => id), options)
51
- end
50
+ @connection.put(node_path(:id => get_id(id)), options)
51
+ end
52
52
 
53
53
  def delete(id, label)
54
- @connection.delete(delete_path(:id => id, :label => label))
54
+ @connection.delete(delete_path(:id => get_id(id), :label => label))
55
55
  end
56
56
 
57
57
 
@@ -1,3 +1,3 @@
1
1
  module Neography
2
- VERSION = "1.1.1"
2
+ VERSION = "1.1.2"
3
3
  end
@@ -0,0 +1,71 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ describe Neography::Node do
5
+
6
+ describe "create and new" do
7
+
8
+ it "can create a node with UTF-8 encoded properties" do
9
+ new_node = Neography::Node.create("name" => "美都池水")
10
+ new_node.name.should == "美都池水"
11
+ end
12
+
13
+ it "can create a node with more than one UTF-8 encoded properties" do
14
+ new_node = Neography::Node.create("first_name" => "美都", "last_name" => "池水")
15
+ new_node.first_name.should == "美都"
16
+ new_node.last_name.should == "池水"
17
+ end
18
+
19
+ end
20
+
21
+ describe "load" do
22
+ it "can get a node with UTF-8 encoded properties that exists" do
23
+ new_node = Neography::Node.create("first_name" => "美都", "last_name" => "池水")
24
+ existing_node = Neography::Node.load(new_node)
25
+ existing_node.should_not be_nil
26
+ existing_node.neo_id.should_not be_nil
27
+ existing_node.neo_id.should == new_node.neo_id
28
+ existing_node.first_name.should == "美都"
29
+ existing_node.last_name.should == "池水"
30
+ end
31
+
32
+ it "can get a node with UTF-8 encoded properties from an index" do
33
+ @neo = Neography::Rest.new
34
+ new_node = Neography::Node.create("first_name" => "美都", "last_name" => "池水")
35
+ key = generate_text(6)
36
+ value = generate_text
37
+ @neo.add_node_to_index("test_node_index", key, value, new_node)
38
+ node_from_index = @neo.get_node_index("test_node_index", key, value)
39
+ existing_node = Neography::Node.load(node_from_index)
40
+ existing_node.should_not be_nil
41
+ existing_node.neo_id.should_not be_nil
42
+ existing_node.neo_id.should == new_node.neo_id
43
+ existing_node.first_name.should == "美都"
44
+ existing_node.last_name.should == "池水"
45
+ end
46
+
47
+ it "can get a node with UTF-8 encoded properties that exists via cypher" do
48
+ new_node = Neography::Node.create("first_name" => "美都", "last_name" => "池水")
49
+ cypher = "START n = node({id}) return n"
50
+ @neo = Neography::Rest.new
51
+ results = @neo.execute_query(cypher, {:id => new_node.neo_id.to_i})
52
+ existing_node = Neography::Node.load(results)
53
+ existing_node.should_not be_nil
54
+ existing_node.neo_id.should_not be_nil
55
+ existing_node.neo_id.should == new_node.neo_id
56
+ existing_node.first_name.should == "美都"
57
+ existing_node.last_name.should == "池水"
58
+ end
59
+
60
+ it "can get columns of data from a node with UTF-8 encoded properties that exists via cypher" do
61
+ new_node = Neography::Node.create("first_name" => "美都", "last_name" => "池水")
62
+ cypher = "START me = node({id})
63
+ RETURN me.first_name, me.last_name"
64
+ @neo = Neography::Rest.new
65
+ results = @neo.execute_query(cypher, {:id => new_node.neo_id.to_i})
66
+ results['data'][0].should == ["美都","池水"]
67
+ end
68
+
69
+ end
70
+
71
+ end
@@ -16,9 +16,8 @@ describe Neography::Rest do
16
16
  describe "add_label" do
17
17
  it "can add a label to a node" do
18
18
  new_node = @neo.create_node
19
- new_node_id = new_node["self"].split('/').last
20
- @neo.add_label(new_node_id, "Person")
21
- labels = @neo.get_node_labels(new_node_id)
19
+ @neo.add_label(new_node, "Person")
20
+ labels = @neo.get_node_labels(new_node)
22
21
  labels.should == ["Person"]
23
22
  end
24
23
 
@@ -39,7 +38,7 @@ describe Neography::Rest do
39
38
  labels.should == ["Actor", "Director"]
40
39
  end
41
40
  end
42
-
41
+
43
42
  describe "set_label" do
44
43
  it "can set a label to a node" do
45
44
  new_node = @neo.create_node
@@ -47,17 +46,16 @@ describe Neography::Rest do
47
46
  @neo.set_label(new_node_id, "Person")
48
47
  labels = @neo.get_node_labels(new_node_id)
49
48
  labels.should == ["Person"]
50
- end
49
+ end
51
50
 
52
51
  it "can set a label to a node that already had a label" do
53
52
  new_node = @neo.create_node
54
- new_node_id = new_node["self"].split('/').last
55
- @neo.add_label(new_node_id, "Actor")
56
- @neo.set_label(new_node_id, "Director")
57
- labels = @neo.get_node_labels(new_node_id)
53
+ @neo.add_label(new_node, "Actor")
54
+ @neo.set_label(new_node, "Director")
55
+ labels = @neo.get_node_labels(new_node)
58
56
  labels.should == ["Director"]
59
- end
60
-
57
+ end
58
+
61
59
  it "can set multiple labels to a node" do
62
60
  new_node = @neo.create_node
63
61
  new_node_id = new_node["self"].split('/').last
@@ -70,12 +68,11 @@ describe Neography::Rest do
70
68
  describe "delete_label" do
71
69
  it "can delete a label from a node" do
72
70
  new_node = @neo.create_node
73
- new_node_id = new_node["self"].split('/').last
74
- @neo.set_label(new_node_id, ["Actor", "Director"])
75
- @neo.delete_label(new_node_id, "Actor")
76
- labels = @neo.get_node_labels(new_node_id)
71
+ @neo.set_label(new_node, ["Actor", "Director"])
72
+ @neo.delete_label(new_node, "Actor")
73
+ labels = @neo.get_node_labels(new_node)
77
74
  labels.should == ["Director"]
78
- end
75
+ end
79
76
 
80
77
  it "can delete a label from a node that doesn't have one" do
81
78
  new_node = @neo.create_node
@@ -83,15 +80,15 @@ describe Neography::Rest do
83
80
  @neo.delete_label(new_node_id, "Actor")
84
81
  labels = @neo.get_node_labels(new_node_id)
85
82
  labels.should == []
86
- end
83
+ end
87
84
 
88
85
  it "cannot delete a label from a node that doesn't exist" do
89
86
  new_node = @neo.create_node
90
87
  new_node_id = new_node["self"].split('/').last
91
- expect {
88
+ expect {
92
89
  @neo.delete_label(new_node_id.to_i + 1, "Actor")
93
90
  }.to raise_error Neography::NodeNotFoundException
94
- end
91
+ end
95
92
  end
96
93
 
97
94
  describe "get_nodes_labeled" do
@@ -101,14 +98,14 @@ describe Neography::Rest do
101
98
  @neo.set_label(new_node_id, ["Actor", "Director"])
102
99
  nodes = @neo.get_nodes_labeled("Actor")
103
100
  nodes.last["self"].split('/').last.should == new_node_id
104
- end
101
+ end
105
102
 
106
103
  it "returns an empty array on non-existing label" do
107
104
  nodes = @neo.get_nodes_labeled("do_not_exist")
108
105
  nodes.should == []
109
- end
106
+ end
110
107
  end
111
-
108
+
112
109
  describe "find_nodes_labeled" do
113
110
  it "can find a node with a label and a property" do
114
111
  new_node = @neo.create_node(:name => "max")
@@ -116,7 +113,7 @@ describe Neography::Rest do
116
113
  @neo.set_label(new_node_id, "clown")
117
114
  nodes = @neo.find_nodes_labeled("clown", { :name => "max" })
118
115
  nodes.last["self"].split('/').last.should == new_node_id
119
- end
116
+ end
120
117
 
121
118
  it "returns an empty array on non-existing label property" do
122
119
  new_node = @neo.create_node(:name => "max")
@@ -124,8 +121,8 @@ describe Neography::Rest do
124
121
  @neo.set_label(new_node_id, "clown")
125
122
  nodes = @neo.find_nodes_labeled("clown", { :name => "does_not_exist" })
126
123
  nodes.should == []
127
- end
124
+ end
125
+
126
+ end
128
127
 
129
- end
130
-
131
- end
128
+ end
@@ -1,3 +1,5 @@
1
+ # Encoding: utf-8
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe Neography::Rest do
@@ -71,6 +73,16 @@ describe Neography::Rest do
71
73
  @neo.get_node(fake_node)
72
74
  }.to raise_error Neography::NodeNotFoundException
73
75
  end
76
+
77
+ it "can get a node with a tilde" do
78
+ new_node = @neo.create_node("name" => "Ateísmo Sureño")
79
+ new_node[:id] = new_node["self"].split('/').last
80
+ existing_node = @neo.get_node(new_node)
81
+ existing_node.should_not be_nil
82
+ existing_node.should have_key("self")
83
+ existing_node["self"].split('/').last.should == new_node[:id]
84
+ existing_node["data"]["name"].should == "Ateísmo Sureño"
85
+ end
74
86
  end
75
87
 
76
88
  describe "set_node_properties" do
@@ -1,3 +1,5 @@
1
+ # Encoding: utf-8
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe Neography::Rest do
@@ -51,6 +53,54 @@ describe Neography::Rest do
51
53
  existing_node["data"][0][0]["self"].split('/').last.should == id
52
54
  end
53
55
 
56
+ it "can perform a range query" do
57
+ name = generate_text(6)
58
+ new_node = @neo.create_node({:number => 3})
59
+ id = new_node["self"].split('/').last
60
+ @neo.create_node_index(name, "fulltext","lucene")
61
+ @neo.add_node_to_index(name, "number", 3, new_node)
62
+ existing_node = @neo.find_node_index(name, "number:[1 TO 5]")
63
+ existing_node.first["self"].should == new_node["self"]
64
+ existing_node.first.should_not be_nil
65
+ existing_node.first["data"]["number"].should == 3
66
+ existing_node = @neo.execute_query("start n=node:#{name}(\"number:[1 TO 5]\") return n")
67
+ existing_node.should have_key("data")
68
+ existing_node.should have_key("columns")
69
+ existing_node["data"][0][0].should have_key("self")
70
+ existing_node["data"][0][0]["self"].split('/').last.should == id
71
+ end
72
+
73
+ it "can perform a range query with a term" do
74
+ name = generate_text(6)
75
+ new_node = @neo.create_node({:number => 3, :name => "Max"})
76
+ id = new_node["self"].split('/').last
77
+ @neo.create_node_index(name, "fulltext","lucene")
78
+ @neo.add_node_to_index(name, "number", 3, new_node)
79
+ @neo.add_node_to_index(name, "name", "max", new_node)
80
+ existing_node = @neo.find_node_index(name, "name:max AND number:[1 TO 5]")
81
+ existing_node.first["self"].should == new_node["self"]
82
+ existing_node.first.should_not be_nil
83
+ existing_node.first["data"]["number"].should == 3
84
+ existing_node.first["data"]["name"].should == "Max"
85
+ existing_node = @neo.execute_query("start n=node:#{name}(\"name:max AND number:[1 TO 5]\") return n")
86
+ existing_node.should have_key("data")
87
+ existing_node.should have_key("columns")
88
+ existing_node["data"][0][0].should have_key("self")
89
+ existing_node["data"][0][0]["self"].split('/').last.should == id
90
+ end
91
+
92
+
93
+ it "can get a node with a tilde" do
94
+ new_node = @neo.create_node("name" => "Ateísmo Sureño")
95
+ id = new_node["self"].split('/').last
96
+ existing_node = @neo.execute_query("start n=node(#{id}) return n")
97
+ existing_node.should_not be_nil
98
+ existing_node.should have_key("data")
99
+ existing_node.should have_key("columns")
100
+ existing_node["data"][0][0]["self"].split('/').last.should == id
101
+ existing_node["data"][0][0]["data"]["name"].should == "Ateísmo Sureño"
102
+ end
103
+
54
104
  it "can get the a node with a variable" do
55
105
  new_node = @neo.create_node
56
106
  id = new_node["self"].split('/').last
@@ -10,7 +10,7 @@ module Neography
10
10
  it "executes a cypher query" do
11
11
  options = {
12
12
  :body=>"{\"query\":\"SOME QUERY\",\"params\":{\"foo\":\"bar\",\"baz\":\"qux\"}}",
13
- :headers=>{"Content-Type"=>"application/json", "Accept"=>"application/json;stream=true"}
13
+ :headers=>{"Content-Type"=>"application/json", "Accept"=>"application/json;stream=true;charset=UTF-8"}
14
14
  }
15
15
  connection.should_receive(:post).with("/cypher", options)
16
16
  subject.query("SOME QUERY", { :foo => "bar", :baz => "qux" })
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: neography
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.1.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-07-18 00:00:00.000000000 Z
12
+ date: 2013-08-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
@@ -244,6 +244,7 @@ files:
244
244
  - spec/integration/authorization_spec.rb
245
245
  - spec/integration/index_spec.rb
246
246
  - spec/integration/neography_spec.rb
247
+ - spec/integration/node_encoding_spec.rb
247
248
  - spec/integration/node_path_spec.rb
248
249
  - spec/integration/node_relationship_spec.rb
249
250
  - spec/integration/node_spec.rb
@@ -324,6 +325,7 @@ test_files:
324
325
  - spec/integration/authorization_spec.rb
325
326
  - spec/integration/index_spec.rb
326
327
  - spec/integration/neography_spec.rb
328
+ - spec/integration/node_encoding_spec.rb
327
329
  - spec/integration/node_path_spec.rb
328
330
  - spec/integration/node_relationship_spec.rb
329
331
  - spec/integration/node_spec.rb