orientdb4r 0.3.3 → 0.4.0
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 +7 -0
- data/README.rdoc +28 -14
- data/Rakefile +34 -0
- data/changelog.txt +12 -1
- data/lib/orientdb4r.rb +15 -14
- data/lib/orientdb4r/client.rb +26 -22
- data/lib/orientdb4r/rest/client.rb +76 -44
- data/lib/orientdb4r/utils.rb +7 -2
- data/lib/orientdb4r/version.rb +1 -0
- data/test/test_client.rb +17 -13
- data/test/test_database.rb +71 -36
- data/test/test_ddo.rb +3 -2
- data/test/test_dmo.rb +7 -2
- data/test/test_document_crud.rb +25 -35
- data/test/test_utils.rb +9 -0
- metadata +7 -11
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d475ea55280ea01281cefdee2731f1441d141095
|
4
|
+
data.tar.gz: 59f012f6c7a58d90af9650a9c27a85a691a65c74
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 2f0fb1f707050138c665237b963d64001b60ffcc460f6c6ded6009d2e2675977d504e225472399ad8ab66863adf54b68fce83df7f3687e2b2cfe3a0a6d98fd31
|
7
|
+
data.tar.gz: b6b538be7c8c18eb4352bec64be2b33979522f432e0a2e007d6abbb88c8eb3bf1ad654c5c7255c4d9f18f4069422c3967ff2d626b516128fa15ead84d324ae94
|
data/README.rdoc
CHANGED
@@ -1,4 +1,11 @@
|
|
1
|
-
|
1
|
+
|
2
|
+
_ _ _ _ _ _
|
3
|
+
___ _ __(_) ___ _ __ | |_ __| | |__ | || | _ __
|
4
|
+
/ _ \| '__| |/ _ \ '_ \| __/ _` | '_ \| || |_| '__|
|
5
|
+
| (_) | | | | __/ | | | || (_| | |_) |__ _| |
|
6
|
+
\___/|_| |_|\___|_| |_|\__\__,_|_.__/ |_| |_|
|
7
|
+
|
8
|
+
= Ruby binding for Orient DB
|
2
9
|
|
3
10
|
A Ruby client for the NoSQL Graph/Document database Orient DB (http://orientdb.org).
|
4
11
|
|
@@ -9,14 +16,19 @@ see Wiki page for more sample at https://github.com/veny/orientdb4r/wiki
|
|
9
16
|
|
10
17
|
require 'orientdb4r'
|
11
18
|
|
19
|
+
DB = 'foo'
|
12
20
|
CLASS = 'myclass'
|
13
21
|
|
14
22
|
client = Orientdb4r.client # equivalent for :host => 'localhost', :port => 2480, :ssl => false
|
15
23
|
|
16
|
-
client.database_exists? :database =>
|
17
|
-
=>
|
24
|
+
client.database_exists? :database => DB, :user => 'admin', :password => 'admin'
|
25
|
+
=> false
|
26
|
+
|
27
|
+
client.create_database :database => DB, :type => :memory, :user => 'root', :password => 'root'
|
28
|
+
=> false
|
18
29
|
|
19
|
-
client.connect :database =>
|
30
|
+
client.connect :database => DB, :user => 'admin', :password => 'admin'
|
31
|
+
=> true
|
20
32
|
|
21
33
|
unless client.class_exists? CLASS
|
22
34
|
client.create_class(CLASS) do |c|
|
@@ -53,7 +65,7 @@ see Wiki page for more sample at https://github.com/veny/orientdb4r/wiki
|
|
53
65
|
|
54
66
|
client.drop_class CLASS
|
55
67
|
client.disconnect
|
56
|
-
|
68
|
+
=> ["401 Unauthorized: Logged out", 401]
|
57
69
|
|
58
70
|
== INSTALL
|
59
71
|
|
@@ -72,19 +84,21 @@ see Wiki page for more sample at https://github.com/veny/orientdb4r/wiki
|
|
72
84
|
|
73
85
|
== REQUIREMENTS
|
74
86
|
|
75
|
-
|
76
|
-
*
|
77
|
-
* OrientDB 1.0.
|
78
|
-
* OrientDB 1.0.1
|
79
|
-
* OrientDB 1.1.0-SNAPSHOT r5913+
|
87
|
+
* Ruby 1.9.x+
|
88
|
+
* OrientDB 1.0.x-1.3.x for *v0.3.x*
|
89
|
+
* OrientDB 1.4.0+ for *v0.4.x*
|
80
90
|
|
81
91
|
== TESTS
|
82
|
-
In order to run the tests you only need to:
|
83
92
|
|
84
|
-
cd /path/to/repository
|
85
|
-
rake test
|
86
93
|
|
87
|
-
|
94
|
+
> cd /path/to/repository
|
95
|
+
> rake db:setup4test # to create the temp DB which doesn't seem to be a default since v1.5
|
96
|
+
> rake test
|
97
|
+
|
98
|
+
Make sure before starting the tests:
|
99
|
+
* database server is running on localhost:2480
|
100
|
+
* there is a root account with username=root and password=root
|
101
|
+
|
88
102
|
|
89
103
|
== AUTHOR
|
90
104
|
|
data/Rakefile
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'rake/testtask'
|
2
|
+
require 'rest_client'
|
2
3
|
|
3
4
|
Rake::TestTask.new do |t|
|
4
5
|
t.libs << 'test'
|
@@ -6,3 +7,36 @@ end
|
|
6
7
|
|
7
8
|
desc "Run tests"
|
8
9
|
task :default => :test
|
10
|
+
|
11
|
+
namespace :db do
|
12
|
+
|
13
|
+
DB_HOST = 'localhost'
|
14
|
+
DB_PORT = 2480
|
15
|
+
DB_NAME = 'temp'
|
16
|
+
DB_ROOT_USER = 'root'
|
17
|
+
DB_ROOT_PASS = 'root'
|
18
|
+
|
19
|
+
desc 'Check whether a test DB exists and create if not'
|
20
|
+
task :setup4test do
|
21
|
+
found = true
|
22
|
+
begin
|
23
|
+
::RestClient::Request.new({:url=>"http://#{DB_HOST}:#{DB_PORT}/database/#{DB_NAME}", :method=>:get, :user=>DB_ROOT_USER, :password=>DB_ROOT_PASS}).execute
|
24
|
+
rescue Errno::ECONNREFUSED
|
25
|
+
fail "server seems to be closed, not running on #{DB_HOST}:#{DB_PORT}?"
|
26
|
+
rescue ::RestClient::Unauthorized
|
27
|
+
# this is expected reaction if DB does not exist
|
28
|
+
puts 'DB does NOT exist -> create'
|
29
|
+
found = false
|
30
|
+
rescue ::RestClient::Exception => e
|
31
|
+
fail "unexpected failure: #{e}"
|
32
|
+
end
|
33
|
+
|
34
|
+
if found
|
35
|
+
puts 'DB already exists'
|
36
|
+
else
|
37
|
+
::RestClient::Request.new({:url=>"http://#{DB_HOST}:#{DB_PORT}/database/#{DB_NAME}/memory", :method=>:post, :user=>DB_ROOT_USER, :password=>DB_ROOT_PASS}).execute
|
38
|
+
puts 'DB created'
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
data/changelog.txt
CHANGED
@@ -1,6 +1,15 @@
|
|
1
|
+
0.4.0 2013-08-14
|
2
|
+
- Closes gap between this driver and OrientDb v1.4.0+ which introduced some changes on REST API (connect & create_document).
|
3
|
+
- No more backward compatible with OrientDb v1.3.x and lesser.
|
4
|
+
- Enhancement #20 : Method 'compare_versions' accepts a block now
|
5
|
+
- Bug Fix #25
|
6
|
+
|
7
|
+
|
8
|
+
|
1
9
|
0.3.3 2012-12-16
|
2
10
|
- Enhancement #18 : Added 'abstract' option into creating a new class
|
3
11
|
- Enhancement #19 : Added GET - List Databases
|
12
|
+
- Bug Fix #22
|
4
13
|
|
5
14
|
0.3.2 2012-11-02
|
6
15
|
- Enhancement #13 : configurable User-Agent request header
|
@@ -11,10 +20,12 @@
|
|
11
20
|
- Bug Fix #14, #15
|
12
21
|
|
13
22
|
0.3.0 2012-08-01
|
14
|
-
-
|
23
|
+
- Introduces support for cluster of distributed servers.
|
15
24
|
- initial strategies for load balancing: sequence, round robin
|
16
25
|
- Keep-Alive feature: Excon HTTP library is fully working
|
17
26
|
|
27
|
+
|
28
|
+
|
18
29
|
0.2.10 2012-07-21
|
19
30
|
- experimental support for Excon HTTP library with Keep-Alive connection
|
20
31
|
|
data/lib/orientdb4r.rb
CHANGED
@@ -8,20 +8,21 @@ require 'orientdb4r/version'
|
|
8
8
|
# This module represents the entry point for using the Ruby OrientDB client.
|
9
9
|
module Orientdb4r
|
10
10
|
|
11
|
-
autoload :Utils,
|
12
|
-
autoload :Client,
|
13
|
-
autoload :RestClient,
|
14
|
-
autoload :BinClient,
|
15
|
-
autoload :Rid,
|
16
|
-
autoload :HashExtension,
|
17
|
-
autoload :OClass,
|
18
|
-
autoload :ChainedError,
|
19
|
-
autoload :Node,
|
20
|
-
autoload :RestNode,
|
21
|
-
autoload :RestClientNode,
|
22
|
-
autoload :ExconNode,
|
23
|
-
autoload :Sequence,
|
24
|
-
autoload :RoundRobin,
|
11
|
+
autoload :Utils, 'orientdb4r/utils'
|
12
|
+
autoload :Client, 'orientdb4r/client'
|
13
|
+
autoload :RestClient, 'orientdb4r/rest/client'
|
14
|
+
autoload :BinClient, 'orientdb4r/bin/client'
|
15
|
+
autoload :Rid, 'orientdb4r/rid'
|
16
|
+
autoload :HashExtension, 'orientdb4r/rest/model'
|
17
|
+
autoload :OClass, 'orientdb4r/rest/model'
|
18
|
+
autoload :ChainedError, 'orientdb4r/chained_error'
|
19
|
+
autoload :Node, 'orientdb4r/node'
|
20
|
+
autoload :RestNode, 'orientdb4r/rest/node'
|
21
|
+
autoload :RestClientNode, 'orientdb4r/rest/restclient_node'
|
22
|
+
autoload :ExconNode, 'orientdb4r/rest/excon_node'
|
23
|
+
autoload :Sequence, 'orientdb4r/load_balancing'
|
24
|
+
autoload :RoundRobin, 'orientdb4r/load_balancing'
|
25
|
+
autoload :DocumentMetadata, 'orientdb4r/rest/model'
|
25
26
|
|
26
27
|
|
27
28
|
class << self
|
data/lib/orientdb4r/client.rb
CHANGED
@@ -3,16 +3,11 @@ module Orientdb4r
|
|
3
3
|
class Client
|
4
4
|
include Utils
|
5
5
|
|
6
|
-
#
|
7
|
-
DEFAULT_SERVER_VERSION = '1.0.0--'
|
8
|
-
|
9
|
-
# # Regexp to validate format of providet version.
|
6
|
+
# # Regexp to validate format of provided version.
|
10
7
|
SERVER_VERSION_PATTERN = /^\d+\.\d+\.\d+[-SNAPHOT]*$/
|
11
8
|
|
12
9
|
# connection parameters
|
13
10
|
attr_reader :user, :password, :database
|
14
|
-
# version loaded from server
|
15
|
-
attr_reader :server_version
|
16
11
|
# type of connection library [:restclient, :excon]
|
17
12
|
attr_reader :connection_library
|
18
13
|
# type of load balancing [:sequence, :round_robin]
|
@@ -112,7 +107,22 @@ module Orientdb4r
|
|
112
107
|
# Retrieves the available databases.
|
113
108
|
# That is protected by the resource "server.listDatabases"
|
114
109
|
# that by default is assigned to the guest (anonymous) user in orientdb-server-config.xml.
|
115
|
-
def list_databases()
|
110
|
+
def list_databases(options)
|
111
|
+
raise NotImplementedError, 'this should be overridden by concrete client'
|
112
|
+
end
|
113
|
+
|
114
|
+
|
115
|
+
###
|
116
|
+
# Exports a gzip file that contains the database JSON export.
|
117
|
+
# Returns name of stored file.
|
118
|
+
def export(options)
|
119
|
+
raise NotImplementedError, 'this should be overridden by concrete client'
|
120
|
+
end
|
121
|
+
|
122
|
+
|
123
|
+
###
|
124
|
+
# Imports a database from an uploaded JSON text file.
|
125
|
+
def import(options)
|
116
126
|
raise NotImplementedError, 'this should be overridden by concrete client'
|
117
127
|
end
|
118
128
|
|
@@ -147,15 +157,7 @@ module Orientdb4r
|
|
147
157
|
sql = "CREATE CLASS #{name}"
|
148
158
|
sql << " EXTENDS #{options[:extends]}" if options.include? :extends
|
149
159
|
sql << " CLUSTER #{options[:cluster]}" if options.include? :cluster
|
150
|
-
|
151
|
-
bigger_1_2 = (compare_versions(server_version, '1.2.0') > 0)
|
152
|
-
if options.include?(:abstract)
|
153
|
-
if bigger_1_2
|
154
|
-
sql << ' ABSTRACT'
|
155
|
-
else
|
156
|
-
Orientdb4r::logger.warn("abstract class not supported in OrientDB version #{compare_versions}")
|
157
|
-
end
|
158
|
-
end
|
160
|
+
sql << ' ABSTRACT' if options.include?(:abstract)
|
159
161
|
|
160
162
|
drop_class name if options[:force]
|
161
163
|
|
@@ -202,7 +204,8 @@ module Orientdb4r
|
|
202
204
|
rslt = true
|
203
205
|
begin
|
204
206
|
get_class name
|
205
|
-
rescue OrientdbError
|
207
|
+
rescue OrientdbError => e
|
208
|
+
raise e if e.is_a? ConnectionError and e.message == 'not connected' # workaround for AOP2 (unable to decorate already existing methods)
|
206
209
|
rslt = false
|
207
210
|
end
|
208
211
|
rslt
|
@@ -212,15 +215,14 @@ module Orientdb4r
|
|
212
215
|
###
|
213
216
|
# Removes a class from the schema.
|
214
217
|
def drop_class(name, options={})
|
215
|
-
raise ArgumentError,
|
218
|
+
raise ArgumentError, 'class name is blank' if blank?(name)
|
216
219
|
|
217
220
|
# :mode=>:strict forbids to drop a class that is a super class for other one
|
218
221
|
opt_pattern = { :mode => :nil }
|
219
222
|
verify_options(options, opt_pattern)
|
220
223
|
if :strict == options[:mode]
|
221
|
-
response =
|
222
|
-
|
223
|
-
children = connect_info['classes'].select { |i| i['superClass'] == name }
|
224
|
+
response = get_database
|
225
|
+
children = response['classes'].select { |i| i['superClass'] == name }
|
224
226
|
unless children.empty?
|
225
227
|
raise OrientdbError, "class is super-class, cannot be deleted, name=#{name}"
|
226
228
|
end
|
@@ -264,7 +266,9 @@ module Orientdb4r
|
|
264
266
|
|
265
267
|
###
|
266
268
|
# Create a new document.
|
267
|
-
# Returns the Record-id assigned.
|
269
|
+
# Returns the Record-id assigned for OrientDB version <= 1.3.x
|
270
|
+
# and the whole new document for version >= 1.4.x
|
271
|
+
# (see https://groups.google.com/forum/?fromgroups=#!topic/orient-database/UJGAXYpHDmo for more info).
|
268
272
|
def create_document(doc)
|
269
273
|
raise NotImplementedError, 'this should be overridden by concrete client'
|
270
274
|
end
|
@@ -5,7 +5,7 @@ module Orientdb4r
|
|
5
5
|
|
6
6
|
|
7
7
|
before [:query, :command], :assert_connected
|
8
|
-
before [:create_class, :get_class, :drop_class, :create_property], :assert_connected
|
8
|
+
before [:create_class, :get_class, :class_exists?, :drop_class, :create_property], :assert_connected
|
9
9
|
before [:create_document, :get_document, :update_document, :delete_document], :assert_connected
|
10
10
|
around [:query, :command], :time_around
|
11
11
|
|
@@ -88,33 +88,24 @@ module Orientdb4r
|
|
88
88
|
|
89
89
|
@nodes.each { |node| node.cleanup } # destroy all used session <= problem in 1.3.0-SNAPSHOT
|
90
90
|
begin
|
91
|
-
|
91
|
+
http_response = call_server(:method => :get, :uri => "connect/#{@database}")
|
92
92
|
rescue
|
93
93
|
@connected = false
|
94
|
-
@server_version = nil
|
95
94
|
@user = nil
|
96
95
|
@password = nil
|
97
96
|
@database = nil
|
98
97
|
@nodes.each { |node| node.cleanup }
|
99
98
|
raise ConnectionError
|
100
99
|
end
|
101
|
-
rslt = process_response response
|
102
|
-
decorate_classes_with_model(rslt['classes'])
|
103
100
|
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
@server_version = DEFAULT_SERVER_VERSION
|
109
|
-
end
|
110
|
-
unless server_version =~ SERVER_VERSION_PATTERN
|
111
|
-
Orientdb4r::logger.warn "bad version format, version=#{server_version}"
|
112
|
-
@server_version = DEFAULT_SERVER_VERSION
|
113
|
-
end
|
101
|
+
rslt = process_response http_response
|
102
|
+
# no metadata in connect v1.4.0+
|
103
|
+
# https://groups.google.com/forum/?fromgroups=#!topic/orient-database/R0VoOfIyDng
|
104
|
+
#decorate_classes_with_model(rslt['classes']) unless rslt['classes'].nil?
|
114
105
|
|
115
|
-
Orientdb4r::logger.info "successfully connected to server,
|
106
|
+
Orientdb4r::logger.info "successfully connected to server, code=#{rslt.code}"
|
116
107
|
@connected = true
|
117
|
-
|
108
|
+
@connected
|
118
109
|
end
|
119
110
|
|
120
111
|
|
@@ -128,7 +119,6 @@ module Orientdb4r
|
|
128
119
|
# It always returns 401 because some browsers intercept this and avoid to reuse the same session again.
|
129
120
|
ensure
|
130
121
|
@connected = false
|
131
|
-
@server_version = nil
|
132
122
|
@user = nil
|
133
123
|
@password = nil
|
134
124
|
@database = nil
|
@@ -158,12 +148,12 @@ module Orientdb4r
|
|
158
148
|
|
159
149
|
def create_database(options) #:nodoc:
|
160
150
|
options_pattern = {
|
161
|
-
:database => :mandatory, :type =>
|
151
|
+
:database => :mandatory, :type => :memory,
|
162
152
|
:user => :optional, :password => :optional
|
163
153
|
}
|
164
154
|
verify_and_sanitize_options(options, options_pattern)
|
165
155
|
|
166
|
-
params = { :method => :post, :uri => "database/#{options[:database]}/#{options[:type]}" }
|
156
|
+
params = { :method => :post, :uri => "database/#{options[:database]}/#{options[:type].to_s}" }
|
167
157
|
params[:no_session] = true # out of existing session which represents an already done authentication
|
168
158
|
|
169
159
|
# additional authentication allowed, overriden in 'call_server' if not defined
|
@@ -198,7 +188,9 @@ module Orientdb4r
|
|
198
188
|
response = call_server params
|
199
189
|
|
200
190
|
# NotFoundError cannot be raised - no way how to recognize from 401 bad auth
|
201
|
-
process_response
|
191
|
+
rslt = process_response response
|
192
|
+
decorate_classes_with_model(rslt['classes']) unless rslt['classes'].nil?
|
193
|
+
rslt
|
202
194
|
end
|
203
195
|
|
204
196
|
|
@@ -220,12 +212,61 @@ module Orientdb4r
|
|
220
212
|
end
|
221
213
|
|
222
214
|
|
223
|
-
|
224
|
-
|
215
|
+
#> curl --user root:root http://localhost:2480/listDatabases
|
216
|
+
def list_databases(options=nil) #:nodoc:
|
217
|
+
verify_and_sanitize_options(options, { :user => :optional, :password => :optional })
|
218
|
+
|
219
|
+
params = { :method => :get, :uri => 'listDatabases', :no_session => true }
|
220
|
+
# additional authentication allowed, overriden in 'call_server' if not defined
|
221
|
+
params[:user] = options[:user] if options.include? :user
|
222
|
+
params[:password] = options[:password] if options.include? :password
|
223
|
+
|
224
|
+
response = call_server params
|
225
225
|
rslt = process_response(response)
|
226
226
|
rslt['databases']
|
227
227
|
end
|
228
228
|
|
229
|
+
|
230
|
+
def export(options=nil) #:nodoc:
|
231
|
+
raise ArgumentError, 'options have to be a Hash' if !options.nil? and !options.kind_of? Hash
|
232
|
+
|
233
|
+
if options.nil? or (!options.nil? and options[:database].nil?)
|
234
|
+
# use database from connect
|
235
|
+
raise ConnectionError, 'client has to be connected if no database given' unless connected?
|
236
|
+
options = {} if options.nil?
|
237
|
+
options[:database] = database
|
238
|
+
end
|
239
|
+
|
240
|
+
options_pattern = { :database => :mandatory, :user => :optional, :password => :optional, :file => :optional }
|
241
|
+
verify_options(options, options_pattern)
|
242
|
+
|
243
|
+
params = {:method => :get, :uri => "export/#{options[:database]}"}
|
244
|
+
params[:no_session] = true # out of existing session which represents an already done authentication
|
245
|
+
|
246
|
+
# additional authentication allowed, overriden in 'call_server' if not defined
|
247
|
+
params[:user] = options[:user] if options.include? :user
|
248
|
+
params[:password] = options[:password] if options.include? :password
|
249
|
+
|
250
|
+
response = call_server params
|
251
|
+
rslt = process_response(response)
|
252
|
+
|
253
|
+
filename = options[:file]
|
254
|
+
filename = response.headers[:content_disposition].split('filename=')[-1] if filename.nil?
|
255
|
+
File.open(filename, 'w') do |f|
|
256
|
+
f.write rslt
|
257
|
+
end
|
258
|
+
|
259
|
+
filename
|
260
|
+
end
|
261
|
+
|
262
|
+
|
263
|
+
def import(options=nil) #:nodoc:
|
264
|
+
raise NotImplementedError, 'not working via REST API, see here for more info: https://github.com/nuvolabase/orientdb/issues/1345'
|
265
|
+
# params = {:method => :post, :uri => 'import/'}
|
266
|
+
# response = call_server params
|
267
|
+
end
|
268
|
+
|
269
|
+
|
229
270
|
# ---------------------------------------------------------------------- SQL
|
230
271
|
|
231
272
|
def query(sql, options=nil) #:nodoc:
|
@@ -261,25 +302,12 @@ module Orientdb4r
|
|
261
302
|
def get_class(name) #:nodoc:
|
262
303
|
raise ArgumentError, "class name is blank" if blank?(name)
|
263
304
|
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
raise NotFoundError, 'class not found' if response.body =~ /Invalid class/
|
268
|
-
end
|
269
|
-
|
270
|
-
classes = [rslt]
|
271
|
-
else
|
272
|
-
# there is bug in REST API [v1.0.0, fixed in r5902], only data are returned
|
273
|
-
# workaround - use metadate delivered by 'connect'
|
274
|
-
response = call_server(:method => :get, :uri => "connect/#{@database}")
|
275
|
-
connect_info = process_response(response) do
|
276
|
-
raise NotFoundError, 'class not found' if response.body =~ /Invalid class/
|
277
|
-
end
|
278
|
-
|
279
|
-
classes = connect_info['classes'].select { |i| i['name'] == name }
|
280
|
-
raise NotFoundError, "class not found, name=#{name}" unless 1 == classes.size
|
305
|
+
response = call_server(:method => :get, :uri => "class/#{@database}/#{name}")
|
306
|
+
rslt = process_response(response) do
|
307
|
+
raise NotFoundError, 'class not found' if response.body =~ /Invalid class/
|
281
308
|
end
|
282
309
|
|
310
|
+
classes = [rslt]
|
283
311
|
decorate_classes_with_model(classes)
|
284
312
|
clazz = classes[0]
|
285
313
|
clazz.extend Orientdb4r::HashExtension
|
@@ -298,13 +326,15 @@ module Orientdb4r
|
|
298
326
|
# ----------------------------------------------------------------- DOCUMENT
|
299
327
|
|
300
328
|
def create_document(doc) #:nodoc:
|
301
|
-
|
329
|
+
http_response = call_server(:method => :post, :uri => "document/#{@database}", \
|
302
330
|
:content_type => 'application/json', :data => doc.to_json)
|
303
|
-
|
304
|
-
raise DataError, 'validation problem' if
|
331
|
+
resp = process_response(http_response) do
|
332
|
+
raise DataError, 'validation problem' if http_response.body =~ /OValidationException/
|
305
333
|
end
|
306
334
|
|
307
|
-
|
335
|
+
resp = ::JSON.parse(http_response.body) # workaround: https://groups.google.com/forum/?fromgroups=#!topic/orient-database/UJGAXYpHDmo
|
336
|
+
resp.extend Orientdb4r::DocumentMetadata
|
337
|
+
resp
|
308
338
|
end
|
309
339
|
|
310
340
|
|
@@ -380,6 +410,8 @@ module Orientdb4r
|
|
380
410
|
rslt = case
|
381
411
|
when content_type.start_with?('text/plain')
|
382
412
|
response.body
|
413
|
+
when content_type.start_with?('application/x-gzip')
|
414
|
+
response.body
|
383
415
|
when content_type.start_with?('application/json')
|
384
416
|
::JSON.parse(response.body)
|
385
417
|
else
|
data/lib/orientdb4r/utils.rb
CHANGED
@@ -59,8 +59,13 @@ module Orientdb4r
|
|
59
59
|
firstv = /^(?:(\d+)\.)?(?:(\d+)\.)?(\*|\d+)/.match(first)[0]
|
60
60
|
secondv = /^(?:(\d+)\.)?(?:(\d+)\.)?(\*|\d+)/.match(second)[0]
|
61
61
|
|
62
|
-
|
63
|
-
|
62
|
+
rslt = 0
|
63
|
+
rslt = 1 if firstv > secondv
|
64
|
+
rslt = -1 if firstv < secondv
|
65
|
+
|
66
|
+
yield rslt if block_given?
|
67
|
+
|
68
|
+
rslt
|
64
69
|
end
|
65
70
|
|
66
71
|
class Proxy
|
data/lib/orientdb4r/version.rb
CHANGED
@@ -2,6 +2,7 @@ module Orientdb4r
|
|
2
2
|
|
3
3
|
# Version history.
|
4
4
|
VERSION_HISTORY = [
|
5
|
+
['0.4.0', '2013-08-14', "Closed gap between this driver and OrientDB v1.4.0+; Enh #20, BF #25"],
|
5
6
|
['0.3.3', '2012-12-16', "Enh #18 ('abstract' option into creating a new class), Enh #19 (GET - List Databases)"],
|
6
7
|
['0.3.2', '2012-11-02', "Enh #13 (User-Agent), Enh #16 (configurable Recover Time in Load Balancing)"],
|
7
8
|
['0.3.1', '2012-08-27', "Timeout for reuse of dirty nodes in load balancing; BF #14, BF #15"],
|
data/test/test_client.rb
CHANGED
@@ -46,9 +46,11 @@ class TestClient < Test::Unit::TestCase
|
|
46
46
|
assert_instance_of Orientdb4r::RestClientNode, client.nodes[0]
|
47
47
|
|
48
48
|
# excon
|
49
|
-
|
50
|
-
|
51
|
-
|
49
|
+
if Gem::Specification::find_all_by_name('excon').any?
|
50
|
+
client = Orientdb4r.client :connection_library => :excon, :instance => :new
|
51
|
+
assert_equal :excon, client.connection_library
|
52
|
+
assert_instance_of Orientdb4r::ExconNode, client.nodes[0]
|
53
|
+
end
|
52
54
|
end
|
53
55
|
|
54
56
|
###
|
@@ -68,17 +70,19 @@ class TestClient < Test::Unit::TestCase
|
|
68
70
|
end
|
69
71
|
RestClient.proxy = nil # restore no setting
|
70
72
|
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
73
|
+
if Gem::Specification::find_all_by_name('excon').any?
|
74
|
+
# no proxy - excon
|
75
|
+
client = Orientdb4r.client :connection_library => :excon, :instance => :new
|
76
|
+
assert_nil client.proxy
|
77
|
+
assert_nil client.nodes[0].proxy
|
75
78
|
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
79
|
+
# proxy - excon
|
80
|
+
client = Orientdb4r.client :connection_library => :excon, :proxy => PROXY_URL, :instance => :new
|
81
|
+
assert_equal PROXY_URL, client.proxy
|
82
|
+
assert_equal PROXY_URL, client.nodes[0].proxy
|
83
|
+
assert_raise Orientdb4r::ConnectionError do
|
84
|
+
client.connect :database => 'temp', :user => 'admin', :password => 'admin'
|
85
|
+
end
|
82
86
|
end
|
83
87
|
end
|
84
88
|
|
data/test/test_database.rb
CHANGED
@@ -2,15 +2,10 @@ require 'test/unit'
|
|
2
2
|
require 'orientdb4r'
|
3
3
|
|
4
4
|
###
|
5
|
-
# This class tests
|
6
|
-
# * CONNECT
|
7
|
-
# * DISCONNECT
|
8
|
-
# * CREATE DATABASE
|
9
|
-
# * GET DATABASE
|
10
|
-
# * DELETE DATABASE
|
11
|
-
# * SERVER info
|
5
|
+
# This class tests DB management.
|
12
6
|
class TestDatabase < Test::Unit::TestCase
|
13
7
|
|
8
|
+
DB = 'temp'
|
14
9
|
Orientdb4r::logger.level = Logger::DEBUG
|
15
10
|
|
16
11
|
def setup
|
@@ -20,34 +15,32 @@ class TestDatabase < Test::Unit::TestCase
|
|
20
15
|
###
|
21
16
|
# CONNECT
|
22
17
|
def test_connect
|
23
|
-
assert_nothing_thrown do @client.connect :database =>
|
24
|
-
rslt = @client.connect :database =>
|
25
|
-
assert_instance_of
|
26
|
-
assert rslt.size > 0
|
27
|
-
assert rslt.include? 'classes'
|
18
|
+
assert_nothing_thrown do @client.connect :database => DB, :user => 'admin', :password => 'admin'; end
|
19
|
+
rslt = @client.connect :database => DB, :user => 'admin', :password => 'admin'
|
20
|
+
assert_instance_of TrueClass, rslt
|
28
21
|
|
29
22
|
assert_equal 'admin', @client.user
|
30
23
|
assert_equal 'admin', @client.password
|
31
|
-
assert_equal
|
32
|
-
assert_not_nil @client.server_version
|
24
|
+
assert_equal DB, @client.database
|
33
25
|
|
34
26
|
# connection refused
|
35
27
|
client = Orientdb4r.client :port => 2840, :instance => :new
|
36
28
|
assert_raise Orientdb4r::ConnectionError do
|
37
|
-
client.connect :database =>
|
29
|
+
client.connect :database => DB, :user => 'admin', :password => 'admin'
|
38
30
|
end
|
39
31
|
|
40
32
|
# bad DB name
|
41
33
|
assert_raise Orientdb4r::UnauthorizedError do
|
42
34
|
@client.connect :database => 'unknown_db', :user => 'admin', :password => 'admin'
|
43
35
|
end
|
44
|
-
#
|
45
|
-
|
46
|
-
|
47
|
-
|
36
|
+
# !!! curl -v --user admin:adminX http://localhost:2480/connect/foo/bar
|
37
|
+
# # bad DB name with '/' => wrong REST resource
|
38
|
+
# assert_raise Orientdb4r::ServerError do
|
39
|
+
# @client.connect :database => 'temp/temp', :user => 'admin', :password => 'admin'
|
40
|
+
# end
|
48
41
|
# bad credentials
|
49
42
|
assert_raise Orientdb4r::UnauthorizedError do
|
50
|
-
@client.connect :database =>
|
43
|
+
@client.connect :database => DB, :user => 'admin1', :password => 'admin'
|
51
44
|
end
|
52
45
|
|
53
46
|
# clean up
|
@@ -58,7 +51,7 @@ class TestDatabase < Test::Unit::TestCase
|
|
58
51
|
###
|
59
52
|
# DISCONNECT
|
60
53
|
def test_disconnect
|
61
|
-
@client.connect :database =>
|
54
|
+
@client.connect :database => DB, :user => 'admin', :password => 'admin'
|
62
55
|
assert @client.connected?
|
63
56
|
assert_nothing_thrown do @client.disconnect; end
|
64
57
|
assert !@client.connected?
|
@@ -68,14 +61,12 @@ class TestDatabase < Test::Unit::TestCase
|
|
68
61
|
assert_nil @client.user
|
69
62
|
assert_nil @client.password
|
70
63
|
assert_nil @client.database
|
71
|
-
assert_nil @client.server_version
|
72
64
|
end
|
73
65
|
|
74
66
|
|
75
67
|
###
|
76
68
|
# CREATE DATABASE
|
77
|
-
|
78
|
-
def xtest_create_database
|
69
|
+
def test_create_database
|
79
70
|
assert_nothing_thrown do
|
80
71
|
@client.create_database :database => 'UniT', :user => 'root', :password => 'root'
|
81
72
|
end
|
@@ -87,7 +78,7 @@ class TestDatabase < Test::Unit::TestCase
|
|
87
78
|
@client.create_database :database => 'UniT', :user => 'root', :password => 'root'
|
88
79
|
end
|
89
80
|
# insufficient rights
|
90
|
-
assert_raise Orientdb4r::
|
81
|
+
assert_raise Orientdb4r::UnauthorizedError do
|
91
82
|
@client.create_database :database => 'UniT1', :user => 'admin', :password => 'admin'
|
92
83
|
end
|
93
84
|
|
@@ -104,16 +95,25 @@ class TestDatabase < Test::Unit::TestCase
|
|
104
95
|
# GET DATABASE
|
105
96
|
def test_get_database
|
106
97
|
# not connected - allowed with additional authentication
|
107
|
-
assert_nothing_thrown do @client.get_database :database =>
|
98
|
+
assert_nothing_thrown do @client.get_database :database => DB, :user => 'admin', :password => 'admin' ; end
|
108
99
|
assert_raise Orientdb4r::ConnectionError do @client.get_database; end
|
109
100
|
# connected
|
110
|
-
@client.connect :database =>
|
101
|
+
@client.connect :database => DB, :user => 'admin', :password => 'admin'
|
111
102
|
assert_nothing_thrown do @client.get_database; end # gets info about connected DB
|
112
103
|
|
113
104
|
rslt = @client.get_database
|
114
105
|
assert_not_nil rslt
|
115
106
|
assert_instance_of Hash, rslt
|
107
|
+
assert !rslt.empty?
|
108
|
+
# server
|
109
|
+
assert rslt.include? 'server'
|
110
|
+
assert_instance_of Hash, rslt['server']
|
111
|
+
assert !rslt['server'].empty?
|
112
|
+
assert rslt['server'].include? 'version'
|
113
|
+
# classes
|
116
114
|
assert rslt.include? 'classes'
|
115
|
+
assert_instance_of Array, rslt['classes']
|
116
|
+
assert !rslt['classes'].empty?
|
117
117
|
|
118
118
|
# bad databases
|
119
119
|
assert_raise Orientdb4r::UnauthorizedError do @client.get_database :database => 'UnknownDB'; end
|
@@ -121,8 +121,8 @@ class TestDatabase < Test::Unit::TestCase
|
|
121
121
|
|
122
122
|
|
123
123
|
# database_exists?
|
124
|
-
assert @client.database_exists?(:database =>
|
125
|
-
assert @client.database_exists?(:database =>
|
124
|
+
assert @client.database_exists?(:database => DB, :user => 'admin', :password => 'admin')
|
125
|
+
assert @client.database_exists?(:database => DB) # use credentials of logged in user
|
126
126
|
assert !@client.database_exists?(:database => 'UnknownDB')
|
127
127
|
assert !@client.database_exists?(:database => 'temp/admin')
|
128
128
|
end
|
@@ -130,8 +130,7 @@ class TestDatabase < Test::Unit::TestCase
|
|
130
130
|
|
131
131
|
###
|
132
132
|
# DELETE DATABASE
|
133
|
-
|
134
|
-
def xtest_delete_database
|
133
|
+
def test_delete_database
|
135
134
|
@client.create_database :database => 'UniT', :user => 'root', :password => 'root'
|
136
135
|
|
137
136
|
# deleting non-existing DB
|
@@ -139,7 +138,7 @@ class TestDatabase < Test::Unit::TestCase
|
|
139
138
|
@client.delete_database :database => 'UniT1', :user => 'root', :password => 'root'
|
140
139
|
end
|
141
140
|
# insufficient rights
|
142
|
-
assert_raise Orientdb4r::
|
141
|
+
assert_raise Orientdb4r::UnauthorizedError do
|
143
142
|
@client.delete_database :database => 'UniT', :user => 'admin', :password => 'admin'
|
144
143
|
end
|
145
144
|
|
@@ -151,7 +150,6 @@ class TestDatabase < Test::Unit::TestCase
|
|
151
150
|
|
152
151
|
###
|
153
152
|
# SERVER info
|
154
|
-
# Temporary disabled because of dependency to password of 'root' account
|
155
153
|
def xtest_server
|
156
154
|
# admin/admin has not 'server.info' resource access in standard installation
|
157
155
|
assert_raise Orientdb4r::OrientdbError do @client.server :user => 'admin', :password => 'admin'; end
|
@@ -168,11 +166,11 @@ class TestDatabase < Test::Unit::TestCase
|
|
168
166
|
# GET List Databases
|
169
167
|
# Retrieves the available databases.
|
170
168
|
def test_list_databases
|
171
|
-
dbs = @client.list_databases
|
169
|
+
dbs = @client.list_databases :user => 'root', :password => 'root'
|
172
170
|
assert_not_nil dbs
|
173
171
|
assert_instance_of Array, dbs
|
174
172
|
assert !dbs.empty?
|
175
|
-
assert dbs.include?
|
173
|
+
assert dbs.include? DB
|
176
174
|
end
|
177
175
|
|
178
176
|
|
@@ -183,6 +181,7 @@ class TestDatabase < Test::Unit::TestCase
|
|
183
181
|
assert_raise Orientdb4r::ConnectionError do @client.query "INSERT INTO OUser(name) VALUES('x')"; end
|
184
182
|
#BF #21 assert_raise Orientdb4r::ConnectionError do @client.create_class 'x'; end
|
185
183
|
assert_raise Orientdb4r::ConnectionError do @client.create_property 'x', 'prop', :boolean; end
|
184
|
+
assert_raise Orientdb4r::ConnectionError do @client.class_exists? 'x'; end
|
186
185
|
assert_raise Orientdb4r::ConnectionError do @client.get_class 'x'; end
|
187
186
|
assert_raise Orientdb4r::ConnectionError do @client.drop_class 'x'; end
|
188
187
|
assert_raise Orientdb4r::ConnectionError do @client.create_document({ '@class' => 'x', :prop => 1 }); end
|
@@ -197,7 +196,7 @@ class TestDatabase < Test::Unit::TestCase
|
|
197
196
|
def test_session_id
|
198
197
|
client = Orientdb4r.client :instance => :new
|
199
198
|
assert_nil client.nodes[0].session_id
|
200
|
-
client.connect :database =>
|
199
|
+
client.connect :database => DB, :user => 'admin', :password => 'admin'
|
201
200
|
session_id = client.nodes[0].session_id
|
202
201
|
assert_not_nil session_id
|
203
202
|
client.query 'SELECT count(*) FROM OUser'
|
@@ -208,4 +207,40 @@ class TestDatabase < Test::Unit::TestCase
|
|
208
207
|
assert_nil client.nodes[0].session_id
|
209
208
|
end
|
210
209
|
|
210
|
+
|
211
|
+
###
|
212
|
+
# EXPORT
|
213
|
+
def test_export
|
214
|
+
client = Orientdb4r.client :instance => :new
|
215
|
+
|
216
|
+
# export of connected database
|
217
|
+
client.connect :database => DB, :user => 'admin', :password => 'admin'
|
218
|
+
rslt = client.export
|
219
|
+
assert File.exist? './temp.gz'
|
220
|
+
assert File.file? './temp.gz'
|
221
|
+
assert 'temp.gz', rslt
|
222
|
+
File.delete './temp.gz'
|
223
|
+
|
224
|
+
# export with given file
|
225
|
+
given_filename = "#{Dir.tmpdir}/TEMP.gz"
|
226
|
+
client.export :file => given_filename
|
227
|
+
assert File.exist? given_filename
|
228
|
+
assert File.file? given_filename
|
229
|
+
assert given_filename, rslt
|
230
|
+
|
231
|
+
# explicit given DB
|
232
|
+
client.disconnect
|
233
|
+
assert_nothing_thrown do
|
234
|
+
client.export :database => DB, :user => 'admin', :password => 'admin', :file => given_filename
|
235
|
+
end
|
236
|
+
# unknow DB
|
237
|
+
assert_raise Orientdb4r::UnauthorizedError do
|
238
|
+
client.export :database => 'unknown', :user => 'admin', :password => 'admin'
|
239
|
+
end
|
240
|
+
# bad password
|
241
|
+
assert_raise Orientdb4r::UnauthorizedError do
|
242
|
+
client.export :database => DB, :user => 'admin', :password => 'unknown'
|
243
|
+
end
|
244
|
+
end
|
245
|
+
|
211
246
|
end
|
data/test/test_ddo.rb
CHANGED
@@ -109,8 +109,9 @@ class TestDdo < Test::Unit::TestCase
|
|
109
109
|
assert_nothing_thrown do @client.drop_class(CLASS); end
|
110
110
|
assert_raise Orientdb4r::NotFoundError do @client.get_class(CLASS); end # no info more
|
111
111
|
# the class is not visible in class list delivered by connect
|
112
|
-
|
113
|
-
|
112
|
+
db_info = @client.get_database
|
113
|
+
puts db_info['classes'].class
|
114
|
+
assert db_info['classes'].select { |i| i.name == CLASS }.empty?
|
114
115
|
|
115
116
|
# CLASS extends super_class
|
116
117
|
@client.create_class(CLASS, :extends => super_clazz);
|
data/test/test_dmo.rb
CHANGED
@@ -102,8 +102,13 @@ class TestDmo < Test::Unit::TestCase
|
|
102
102
|
assert_raise Orientdb4r::ServerError do
|
103
103
|
@client.query 'xxx'
|
104
104
|
end
|
105
|
-
# record not found
|
106
|
-
|
105
|
+
# record not found in existing cluster
|
106
|
+
entries = @client.query 'SELECT FROM #0:1111'
|
107
|
+
assert_not_nil entries
|
108
|
+
assert_instance_of Array, entries
|
109
|
+
assert entries.empty?
|
110
|
+
# try to find entry in a non-existing cluster
|
111
|
+
assert_raise Orientdb4r::ServerError do @client.query 'SELECT FROM #111:1111'; end
|
107
112
|
# used for INSERT
|
108
113
|
assert_raise Orientdb4r::ServerError do
|
109
114
|
@client.query "INSERT INTO #{CLASS} (prop1, prop2, friends) VALUES (0, 'string0', [])"
|
data/test/test_document_crud.rb
CHANGED
@@ -31,26 +31,20 @@ class TestDocumentCrud < Test::Unit::TestCase
|
|
31
31
|
# CREATE
|
32
32
|
def test_create_document
|
33
33
|
assert_nothing_thrown do @client.create_document( { '@class' => CLASS, 'prop1' => 99, 'prop2' => 'ipsum lorem' }); end
|
34
|
-
|
35
|
-
assert_instance_of
|
34
|
+
doc = @client.create_document({ '@class' => CLASS, 'prop1' => 1, 'prop2' => 'text' })
|
35
|
+
assert_instance_of Hash, doc
|
36
|
+
assert_not_nil doc.doc_rid
|
37
|
+
assert_instance_of Orientdb4r::Rid, doc.doc_rid
|
38
|
+
assert_equal CLASS, doc.doc_class
|
39
|
+
assert_equal 0, doc.doc_version
|
36
40
|
|
37
41
|
# no effect if a define the version
|
38
|
-
|
39
|
-
@client.create_document({ '@class' => CLASS, '@version' => 2, 'prop1' => 1, 'prop2' => 'text' })
|
40
|
-
end
|
41
|
-
rid = @client.create_document({ '@class' => CLASS, 'prop1' => 1, 'prop2' => 'text' })
|
42
|
-
doc = @client.get_document rid
|
43
|
-
assert_equal CLASS, doc.doc_class
|
44
|
-
assert_equal rid, doc.doc_rid
|
42
|
+
doc = @client.create_document({ '@class' => CLASS, '@version' => 2, 'prop1' => 1, 'prop2' => 'text' })
|
45
43
|
assert_equal 0, doc.doc_version
|
46
44
|
|
47
45
|
# no effect if an unknown class
|
48
|
-
|
49
|
-
|
50
|
-
end
|
51
|
-
rid = @client.create_document({ '@class' => 'unknown_class', 'a' => 11, 'b' => 'text1' })
|
52
|
-
doc = @client.get_document rid
|
53
|
-
assert_nil doc.doc_class
|
46
|
+
doc = @client.create_document({ '@class' => 'unknown_class', 'a' => 11, 'b' => 'text1' })
|
47
|
+
assert_equal 'unknown_class', doc.doc_class
|
54
48
|
assert_equal 11, doc['a']
|
55
49
|
assert_equal 'text1', doc['b']
|
56
50
|
# or missing class
|
@@ -73,11 +67,11 @@ class TestDocumentCrud < Test::Unit::TestCase
|
|
73
67
|
###
|
74
68
|
# GET
|
75
69
|
def test_get_document
|
76
|
-
|
70
|
+
created = @client.create_document( { '@class' => CLASS, 'prop1' => 1, 'prop2' => 'text' })
|
77
71
|
|
78
|
-
doc = @client.get_document
|
72
|
+
doc = @client.get_document created.doc_rid
|
79
73
|
assert_equal CLASS, doc.doc_class
|
80
|
-
assert_equal
|
74
|
+
assert_equal created.doc_rid, doc.doc_rid
|
81
75
|
assert_equal 0, doc.doc_version
|
82
76
|
assert_equal 'd', doc.doc_type
|
83
77
|
assert_equal 1, doc['prop1']
|
@@ -86,7 +80,7 @@ class TestDocumentCrud < Test::Unit::TestCase
|
|
86
80
|
assert doc.kind_of? Orientdb4r::DocumentMetadata
|
87
81
|
|
88
82
|
# not existing RID
|
89
|
-
rid1 = Orientdb4r::Rid.new("#{
|
83
|
+
rid1 = Orientdb4r::Rid.new("#{created.doc_rid.cluster_id}:#{created.doc_rid.document_id + 1}") # '#6:0' > '#6:1' or '#6:11' > '#6:12'
|
90
84
|
assert_raise Orientdb4r::NotFoundError do @client.get_document rid1; end
|
91
85
|
# bad RID format
|
92
86
|
assert_raise ArgumentError do @client.get_document('xx'); end
|
@@ -95,34 +89,34 @@ class TestDocumentCrud < Test::Unit::TestCase
|
|
95
89
|
###
|
96
90
|
# UPDATE
|
97
91
|
def test_update_document
|
98
|
-
|
99
|
-
doc = @client.get_document
|
92
|
+
created = @client.create_document( { '@class' => CLASS, 'prop1' => 1, 'prop2' => 'text' })
|
93
|
+
doc = @client.get_document created.doc_rid
|
100
94
|
|
101
95
|
doc['prop1'] = 2
|
102
96
|
doc['prop2'] = 'unit'
|
103
97
|
assert_nothing_thrown do @client.update_document doc; end
|
104
|
-
doc = @client.get_document
|
98
|
+
doc = @client.get_document created.doc_rid
|
105
99
|
assert_equal 2, doc['prop1']
|
106
100
|
assert_equal 'unit', doc['prop2']
|
107
101
|
|
108
102
|
# bad version
|
109
|
-
doc = @client.get_document
|
103
|
+
doc = @client.get_document created.doc_rid
|
110
104
|
doc['prop1'] = 222 # a property has to be changed to server engine sees a difference
|
111
105
|
doc['@version'] = 2
|
112
106
|
assert_raise Orientdb4r::DataError do @client.update_document doc; end
|
113
107
|
|
114
108
|
# class cannot be changed
|
115
|
-
doc = @client.get_document
|
109
|
+
doc = @client.get_document created.doc_rid
|
116
110
|
doc['@class'] = 'OUser'
|
117
111
|
assert_nothing_thrown do @client.update_document doc; end
|
118
|
-
assert_equal CLASS, @client.get_document(
|
112
|
+
assert_equal CLASS, @client.get_document(created.doc_rid).doc_class
|
119
113
|
|
120
114
|
# no mandatory property
|
121
|
-
doc = @client.get_document
|
115
|
+
doc = @client.get_document created.doc_rid
|
122
116
|
doc.delete 'prop2'
|
123
117
|
assert_raise Orientdb4r::DataError do @client.update_document doc; end
|
124
118
|
# notNull is null, or lesser/bigger
|
125
|
-
doc = @client.get_document
|
119
|
+
doc = @client.get_document created.doc_rid
|
126
120
|
doc['prop1'] = nil
|
127
121
|
assert_raise Orientdb4r::DataError do @client.update_document doc; end
|
128
122
|
end
|
@@ -131,18 +125,14 @@ class TestDocumentCrud < Test::Unit::TestCase
|
|
131
125
|
###
|
132
126
|
# DELETE
|
133
127
|
def test_delete_document
|
134
|
-
|
135
|
-
doc = @client.get_document rid
|
128
|
+
doc = @client.create_document( { '@class' => CLASS, 'prop1' => 1, 'prop2' => 'text' })
|
136
129
|
assert_not_nil doc
|
137
130
|
|
138
|
-
assert_nothing_thrown do @client.delete_document
|
139
|
-
assert_raise Orientdb4r::NotFoundError do @client.get_document
|
131
|
+
assert_nothing_thrown do @client.delete_document doc.doc_rid; end
|
132
|
+
assert_raise Orientdb4r::NotFoundError do @client.get_document doc.doc_rid; end
|
140
133
|
|
141
134
|
# already deleted
|
142
|
-
|
143
|
-
if @client.compare_versions(@client.server_version, '1.1.0') < 0
|
144
|
-
assert_raise Orientdb4r::NotFoundError do @client.delete_document rid; end
|
145
|
-
end
|
135
|
+
assert_raise Orientdb4r::NotFoundError do @client.delete_document doc.doc_rid; end
|
146
136
|
|
147
137
|
# not existing RID
|
148
138
|
assert_raise Orientdb4r::NotFoundError do @client.delete_document '#4:1111'; end
|
data/test/test_utils.rb
CHANGED
@@ -54,6 +54,15 @@ class TestUtils < Test::Unit::TestCase
|
|
54
54
|
assert_equal -1, compare_versions('1.0.0', '1.0.1')
|
55
55
|
assert_equal -1, compare_versions('1.0.0', '1.1.0')
|
56
56
|
assert_equal -1, compare_versions('1.0.0', '2.0.0')
|
57
|
+
|
58
|
+
# test block
|
59
|
+
tmp = -100;
|
60
|
+
compare_versions('1.0.0', '1.0.0') { |comp| tmp = comp }
|
61
|
+
assert_equal 0, tmp
|
62
|
+
compare_versions('1.0.0', '2.0.0') { |comp| tmp = comp }
|
63
|
+
assert_equal -1, tmp
|
64
|
+
compare_versions('3.0.0', '2.0.0') { |comp| tmp = comp }
|
65
|
+
assert_equal 1, tmp
|
57
66
|
end
|
58
67
|
|
59
68
|
end
|
metadata
CHANGED
@@ -1,20 +1,18 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: orientdb4r
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.4.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Vaclav Sykora
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2013-08-14 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: rest-client
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
17
|
- - ~>
|
20
18
|
- !ruby/object:Gem::Version
|
@@ -22,7 +20,6 @@ dependencies:
|
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
24
|
- - ~>
|
28
25
|
- !ruby/object:Gem::Version
|
@@ -75,28 +72,27 @@ files:
|
|
75
72
|
- test/test_utils.rb
|
76
73
|
homepage: http://github.com/veny/orientdb4r
|
77
74
|
licenses: []
|
75
|
+
metadata: {}
|
78
76
|
post_install_message:
|
79
77
|
rdoc_options:
|
80
78
|
- --charset=UTF-8
|
81
79
|
require_paths:
|
82
80
|
- lib
|
83
81
|
required_ruby_version: !ruby/object:Gem::Requirement
|
84
|
-
none: false
|
85
82
|
requirements:
|
86
|
-
- -
|
83
|
+
- - '>='
|
87
84
|
- !ruby/object:Gem::Version
|
88
85
|
version: '0'
|
89
86
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
90
|
-
none: false
|
91
87
|
requirements:
|
92
|
-
- -
|
88
|
+
- - '>'
|
93
89
|
- !ruby/object:Gem::Version
|
94
90
|
version: 1.3.1
|
95
91
|
requirements: []
|
96
92
|
rubyforge_project:
|
97
|
-
rubygems_version:
|
93
|
+
rubygems_version: 2.0.3
|
98
94
|
signing_key:
|
99
|
-
specification_version:
|
95
|
+
specification_version: 4
|
100
96
|
summary: Ruby binding for Orient DB.
|
101
97
|
test_files:
|
102
98
|
- test/readme_sample.rb
|