orientdb 0.0.8-jruby → 0.0.9-jruby

Sign up to get free protection for your applications and to get access to all the features.
data/orientdb.gemspec CHANGED
@@ -5,12 +5,12 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{orientdb}
8
- s.version = "0.0.8"
8
+ s.version = "0.0.9"
9
9
  s.platform = %q{jruby}
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 1.3.6") if s.respond_to? :required_rubygems_version=
12
12
  s.authors = ["Adrian Madrid"]
13
- s.date = %q{2011-01-14}
13
+ s.date = %q{2011-01-17}
14
14
  s.default_executable = %q{orientdb_console}
15
15
  s.description = %q{Simple JRuby wrapper for the OrientDB.}
16
16
  s.email = ["aemadrid@gmail.com"]
@@ -45,6 +45,8 @@ Gem::Specification.new do |s|
45
45
  "lib/orientdb/property.rb",
46
46
  "lib/orientdb/record.rb",
47
47
  "lib/orientdb/schema.rb",
48
+ "lib/orientdb/sql.rb",
49
+ "lib/orientdb/sql_ext.rb",
48
50
  "lib/orientdb/sql_query.rb",
49
51
  "lib/orientdb/storage.rb",
50
52
  "lib/orientdb/user.rb",
@@ -54,7 +56,9 @@ Gem::Specification.new do |s|
54
56
  "spec/document_spec.rb",
55
57
  "spec/orientdb_spec.rb",
56
58
  "spec/spec.opts",
57
- "spec/spec_helper.rb"
59
+ "spec/spec_basic_helper.rb",
60
+ "spec/spec_helper.rb",
61
+ "spec/sql_spec.rb"
58
62
  ]
59
63
  s.homepage = %q{http://rubygems.org/gems/orientdb}
60
64
  s.require_paths = ["lib"]
@@ -43,45 +43,51 @@ describe "OrientDB" do
43
43
  before :all do
44
44
  create_classes
45
45
 
46
- @oclass = @employee_class.name
47
- @e1 = OrientDB::Document.create DB, @oclass, :name => "Mark", :age => 36, :groups => %w{admin sales}
48
- @e2 = OrientDB::Document.create DB, @oclass, :name => "John", :age => 37, :groups => %w{admin tech}
49
- @e3 = OrientDB::Document.create DB, @oclass, :name => "Luke", :age => 38, :groups => %w{tech support}
50
- @e4 = OrientDB::Document.create DB, @oclass, :name => "Matt", :age => 39, :groups => %w{admin office}
51
- @e5 = OrientDB::Document.create DB, @oclass, :name => "Pete", :age => 40, :groups => %w{vp office}
52
- @employees = [@e1,@e2,@e3,@e4,@e5]
46
+ @oclass = @employee_class.name
47
+ @e1 = OrientDB::Document.create DB, @oclass, :name => "Mark", :age => 36, :groups => %w{admin sales}
48
+ @e2 = OrientDB::Document.create DB, @oclass, :name => "John", :age => 37, :groups => %w{admin tech}
49
+ @e3 = OrientDB::Document.create DB, @oclass, :name => "Luke", :age => 38, :groups => %w{tech support}
50
+ @e4 = OrientDB::Document.create DB, @oclass, :name => "Matt", :age => 39, :groups => %w{admin office}
51
+ @e5 = OrientDB::Document.create DB, @oclass, :name => "Pete", :age => 40, :groups => %w{vp office}
52
+ @employees = [@e1, @e2, @e3, @e4, @e5]
53
53
  end
54
54
 
55
55
  it "should prepare valid queries" do
56
- qry1 = DB.prepare_sql_query :oclass => "person"
57
- qry1.should be_a_kind_of OrientDB::SQLQuery
58
- qry1.text.should == "SELECT * FROM person"
56
+ exp = "SELECT * FROM #{@oclass}"
57
+ qry1 = DB.prepare_sql_query exp
58
+ qry1.should be_a_kind_of OrientDB::SQLSynchQuery
59
+ qry1.text.should == exp
59
60
 
60
- qry2 = DB.prepare_sql_query :oclass => "person", :name => "John"
61
- qry2.should be_a_kind_of OrientDB::SQLQuery
62
- qry2.text.should == "SELECT * FROM person WHERE name = 'John'"
61
+ qry2 = DB.prepare_sql_query OrientDB::SQL::Query.new.from(@oclass).where(:name => "John")
62
+ qry2.should be_a_kind_of OrientDB::SQLSynchQuery
63
+ qry2.text.should == "SELECT FROM #{@oclass} WHERE name = 'John'"
63
64
 
64
65
  qry3 = DB.prepare_sql_query qry2.text
65
- qry3.should be_a_kind_of OrientDB::SQLQuery
66
+ qry3.should be_a_kind_of OrientDB::SQLSynchQuery
66
67
  qry3.text.should == qry2.text
67
68
 
68
69
  qry4 = DB.prepare_sql_query qry3
69
- qry4.should be_a_kind_of OrientDB::SQLQuery
70
+ qry4.should be_a_kind_of OrientDB::SQLSynchQuery
70
71
  qry4.text.should == qry2.text
71
72
  end
72
73
 
73
74
  it "should get all rows for a class" do
74
- DB.all(:oclass => @oclass).map.should == @employees
75
+ DB.query('SELECT FROM employee').map.should == @employees
76
+ end
77
+
78
+ it "should create a valid query and return the right results" do
79
+ qry = OrientDB::SQL::Query.new.from(@oclass).where("'admin' IN groups", 'age > 37')
80
+ DB.first(qry).should == @e4
75
81
  end
76
82
 
77
83
  it "should find rows by simple field values" do
78
- DB.first(:oclass => @oclass, :name => "Mark").should == @e1
79
- DB.first(:oclass => @oclass, :age => 37).should == @e2
84
+ DB.first("SELECT * FROM employee WHERE name = 'Mark'").should == @e1
85
+ DB.first('SELECT * FROM employee WHERE age = 37').should == @e2
80
86
  end
81
87
 
82
88
  it "should find rows by values in arrays" do
83
89
  qry = DB.prepare_sql_query "SELECT * FROM #{@oclass} WHERE 'admin' IN groups"
84
- DB.query(qry).map.should == [@e1,@e2,@e4]
90
+ DB.query(qry).map.should == [@e1, @e2, @e4]
85
91
  end
86
92
 
87
93
  end
@@ -0,0 +1,25 @@
1
+ unless defined?(SPEC_BASIC_HELPER_LOADED)
2
+
3
+ GEM_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
4
+ LIB_ROOT = GEM_ROOT + '/lib'
5
+ SPEC_ROOT = GEM_ROOT + '/spec'
6
+ TEMP_DIR = SPEC_ROOT + '/tmp'
7
+ puts ">> GEM_ROOT : #{GEM_ROOT}"
8
+
9
+ $LOAD_PATH.unshift(LIB_ROOT) unless $LOAD_PATH.include?(LIB_ROOT)
10
+
11
+ require 'orientdb'
12
+ require 'rspec'
13
+ #require 'rspec/autorun'
14
+ require 'fileutils'
15
+
16
+ RSpec.configure do |config|
17
+ config.color_enabled = true
18
+ end
19
+
20
+ class Developer
21
+
22
+ end
23
+
24
+ SPEC_BASIC_HELPER_LOADED = true
25
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,25 +1,12 @@
1
1
  $LOAD_PATH.unshift(File.dirname(__FILE__))
2
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
- require 'orientdb'
4
- require 'rspec'
5
- #require 'rspec/autorun'
6
- require 'fileutils'
7
2
 
8
3
  unless defined?(SPEC_HELPER_LOADED)
9
4
 
10
- GEM_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
11
- LIB_ROOT = GEM_ROOT + '/lib'
12
- SPEC_ROOT = GEM_ROOT + '/spec'
13
- TEMP_DIR = SPEC_ROOT + '/tmp'
5
+ require 'spec_basic_helper'
14
6
 
15
7
  TEST_DB_PATH = "#{TEMP_DIR}/databases/db_#{rand(999) + 1}"
16
-
17
- puts ">> GEM_ROOT : #{GEM_ROOT}"
18
- puts ">> TEST_DB PATH : #{TEST_DB_PATH}"
19
-
20
- $LOAD_PATH.unshift(LIB_ROOT) unless $LOAD_PATH.include?(LIB_ROOT)
21
-
22
8
  FileUtils.mkdir_p TEST_DB_PATH
9
+ puts ">> TEST_DB PATH : #{TEST_DB_PATH}"
23
10
 
24
11
  DB = OrientDB::Database.new("local:#{TEST_DB_PATH}/test").create
25
12
 
data/spec/sql_spec.rb ADDED
@@ -0,0 +1,666 @@
1
+ require File.expand_path("../spec_basic_helper", __FILE__)
2
+
3
+ describe "OrientDB" do
4
+
5
+ describe "SQL" do
6
+
7
+ describe "Query" do
8
+
9
+ it "should do a blank query" do
10
+ @q = OrientDB::SQL::Query.new
11
+ @q.should be_a_kind_of OrientDB::SQL::Query
12
+ @q.to_s.should == 'SELECT FROM'
13
+ end
14
+
15
+ describe "quote" do
16
+ it "should quote numeric values correctly" do
17
+ OrientDB::SQL::Query.quote(1).should == "1"
18
+ OrientDB::SQL::Query.quote(1.1).should == "1.1"
19
+ OrientDB::SQL::Query.quote(10_000_000).should == "10000000"
20
+ end
21
+
22
+ it "should quote symbols correctly" do
23
+ OrientDB::SQL::Query.quote(:name).should == "name"
24
+ end
25
+
26
+ it "should quote strings correctly" do
27
+ OrientDB::SQL::Query.quote("name").should == "'name'"
28
+ OrientDB::SQL::Query.quote("'name'").should == "'name'"
29
+ OrientDB::SQL::Query.quote("O'Brien").should == "'O\\'Brien'"
30
+ OrientDB::SQL::Query.quote("'O\\'Brien'").should == "'O\\'Brien'"
31
+ OrientDB::SQL::Query.quote("O'Brien & O'Malley").should == "'O\\'Brien & O\\'Malley'"
32
+ end
33
+
34
+ it "should quote arrays correctly" do
35
+ OrientDB::SQL::Query.quote([:a, 'b', 1]).should == "[a, 'b', 1]"
36
+ end
37
+
38
+ it "should quote regular expressions correctly" do
39
+ OrientDB::SQL::Query.quote(/\d{1,3}\.\d{1,3}/).should == "'\\d{1,3}\\.\\d{1,3}'"
40
+ end
41
+
42
+ it "should quote record attributes properly" do
43
+ OrientDB::SQL::Query.quote(:@this).should == "@this"
44
+ OrientDB::SQL::Query.quote(:@rid).should == "@rid"
45
+ OrientDB::SQL::Query.quote(:@class).should == "@class"
46
+ OrientDB::SQL::Query.quote(:@version).should == "@version"
47
+ OrientDB::SQL::Query.quote(:@size).should == "@size"
48
+ OrientDB::SQL::Query.quote(:@type).should == "@type"
49
+ end
50
+ end
51
+
52
+ describe "SELECT" do
53
+
54
+ before :each do
55
+ @q = OrientDB::SQL::Query.new
56
+ end
57
+
58
+ it "should select simple string columns" do
59
+ @q.select('name').to_s.should == 'SELECT name FROM'
60
+ end
61
+
62
+ it "should select with extended dots on __ separated strings" do
63
+ @q.select('name__a').to_s.should == 'SELECT name.a FROM'
64
+ end
65
+
66
+ it "should select as alias on ___ separated strings" do
67
+ @q.select('name___a').to_s.should == 'SELECT name AS a FROM'
68
+ end
69
+
70
+ it "should select as mixed alias/dots strings" do
71
+ @q.select('name__a___b').to_s.should == 'SELECT name.a AS b FROM'
72
+ end
73
+
74
+ it "should select simple symbol columns" do
75
+ @q.select(:name).to_s.should == 'SELECT name FROM'
76
+ end
77
+
78
+ it "should select simple integer columns" do
79
+ @q.select(1).to_s.should == 'SELECT 1 FROM'
80
+ end
81
+
82
+ it "should select simple hashes" do
83
+ @q.select(:name => :a).to_s.should == 'SELECT name AS a FROM'
84
+ end
85
+
86
+ it "should select simple two column arrays as aliases" do
87
+ @q.select(['name', 'a']).to_s.should == 'SELECT name AS a FROM'
88
+ end
89
+
90
+ it "should select simple n-column arrays as entries" do
91
+ @q.select(['name', 'age', 'code']).to_s.should == 'SELECT name, age, code FROM'
92
+ end
93
+
94
+ it "should select simple multiple parameters as entries" do
95
+ @q.select('name', :age, 1, [:a, :b], :x => :y).to_s.should == 'SELECT name, age, 1, a AS b, x AS y FROM'
96
+ end
97
+
98
+ it "should select simple multiple parameters as entries using columns" do
99
+ @q.columns('name', :age, 1, [:a, :b], :x => :y).to_s.should == 'SELECT name, age, 1, a AS b, x AS y FROM'
100
+ end
101
+
102
+ it "should handle concatenation" do
103
+ @q.select('name').select(:age).to_s.should == 'SELECT name, age FROM'
104
+ end
105
+
106
+ it "should handle overriding" do
107
+ @q.select('name').select!(:age).to_s.should == 'SELECT age FROM'
108
+ end
109
+ end
110
+
111
+ describe "FROM" do
112
+
113
+ before :each do
114
+ @q = OrientDB::SQL::Query.new
115
+ end
116
+
117
+ it "should use a simple string target" do
118
+ @q.from('Developer').to_s.should == 'SELECT FROM Developer'
119
+ end
120
+
121
+ it "should use a simple symbol target" do
122
+ @q.from(:Developer).to_s.should == 'SELECT FROM Developer'
123
+ end
124
+
125
+ it "should use a simple object target" do
126
+ @q.from(Developer).to_s.should == 'SELECT FROM Developer'
127
+ end
128
+
129
+ it "should use multiple simple string targets" do
130
+ @q.from('5:1', '5:3', '5:5').to_s.should == 'SELECT FROM [5:1, 5:3, 5:5]'
131
+ end
132
+
133
+ it "should handle concatenation" do
134
+ @q.from('5:1').from('5:3').from('5:5').to_s.should == 'SELECT FROM [5:1, 5:3, 5:5]'
135
+ end
136
+
137
+ it "should handle overriding" do
138
+ @q.from('5:1').from!('5:5').to_s.should == 'SELECT FROM 5:5'
139
+ end
140
+ end
141
+
142
+ describe "WHERE" do
143
+
144
+ before :each do
145
+ @q = OrientDB::SQL::Query.new
146
+ end
147
+
148
+ it "should handle simple hashes" do
149
+ @q.where(:a => 1).to_s.should == 'SELECT FROM WHERE a = 1'
150
+ end
151
+
152
+ it "should handle simple arrays" do
153
+ @q.where(['a > 1', 'b < 3', 'c = 5']).to_s.should == 'SELECT FROM WHERE a > 1 AND b < 3 AND c = 5'
154
+ end
155
+
156
+ it "should handle concatenation" do
157
+ @q.where(:a => 1).where(:b => 2).to_s.should == 'SELECT FROM WHERE a = 1 AND b = 2'
158
+ end
159
+
160
+ it "should handle overriding" do
161
+ @q.where(:a => 1).where!(:b => 2).to_s.should == 'SELECT FROM WHERE b = 2'
162
+ end
163
+
164
+ it "should handle simple joined AND conditions" do
165
+ @q.where(:a => 1).and(:b => 2).to_s.should == 'SELECT FROM WHERE a = 1 AND b = 2'
166
+ end
167
+
168
+ it "should handle simple joined OR conditions" do
169
+ @q.where(:a => 1).or(:b => 2).to_s.should == 'SELECT FROM WHERE a = 1 OR b = 2'
170
+ end
171
+
172
+ it "should handle simple joined AND NOT conditions" do
173
+ @q.where(:a => 1).and_not(:b => 2).to_s.should == 'SELECT FROM WHERE a = 1 AND NOT b = 2'
174
+ end
175
+
176
+ it "should handle simple joined OR NOT conditions" do
177
+ @q.where(:a => 1).or_not(:b => 2).to_s.should == 'SELECT FROM WHERE a = 1 OR NOT b = 2'
178
+ end
179
+
180
+ it "should handle complex joined AND conditions (1)" do
181
+ @q.where(:a => 1, :b => 2).and(:c => 3).to_s.should == 'SELECT FROM WHERE (a = 1 AND b = 2) AND c = 3'
182
+ end
183
+
184
+ it "should handle complex joined AND conditions (2)" do
185
+ @q.where(:a => 1, :b => 2).and(:c => 3, :d => 4).to_s.should == 'SELECT FROM WHERE (a = 1 AND b = 2) AND (c = 3 AND d = 4)'
186
+ end
187
+
188
+ it "should handle complex joined OR conditions (1)" do
189
+ @q.where(:a => 1, :b => 2).or(:c => 3).to_s.should == 'SELECT FROM WHERE (a = 1 AND b = 2) OR c = 3'
190
+ end
191
+
192
+ it "should handle complex joined OR conditions (2)" do
193
+ @q.where(:a => 1, :b => 2).or(:c => 3, :d => 4).to_s.should == 'SELECT FROM WHERE (a = 1 AND b = 2) OR (c = 3 AND d = 4)'
194
+ end
195
+
196
+ it "should handle complex joined AND NOT conditions (1)" do
197
+ @q.where(:a => 1, :b => 2).and_not(:c => 3).to_s.should == 'SELECT FROM WHERE (a = 1 AND b = 2) AND NOT c = 3'
198
+ end
199
+
200
+ it "should handle complex joined AND NOT conditions (2)" do
201
+ @q.where(:a => 1, :b => 2).and_not(:c => 3, :d => 4).to_s.should == 'SELECT FROM WHERE (a = 1 AND b = 2) AND NOT (c = 3 AND d = 4)'
202
+ end
203
+
204
+ it "should handle complex joined OR NOT conditions (1)" do
205
+ @q.where(:a => 1, :b => 2).or_not(:c => 3).to_s.should == 'SELECT FROM WHERE (a = 1 AND b = 2) OR NOT c = 3'
206
+ end
207
+
208
+ it "should handle complex joined OR NOT conditions (2)" do
209
+ @q.where(:a => 1, :b => 2).or_not(:c => 3, :d => 4).to_s.should == 'SELECT FROM WHERE (a = 1 AND b = 2) OR NOT (c = 3 AND d = 4)'
210
+ end
211
+ end
212
+
213
+ describe "ORDER BY" do
214
+
215
+ before :each do
216
+ @q = OrientDB::SQL::Query.new
217
+ end
218
+
219
+ it "should handle simple hashes" do
220
+ @q.order(:a => :desc).to_s.should == 'SELECT FROM ORDER BY a DESC'
221
+ end
222
+
223
+ it "should handle two column arrays" do
224
+ @q.order([:a, :desc]).to_s.should == 'SELECT FROM ORDER BY a DESC'
225
+ end
226
+
227
+ it "should handle n column arrays" do
228
+ @q.order([:a, :b, :c]).to_s.should == 'SELECT FROM ORDER BY a, b, c'
229
+ end
230
+
231
+ it "should handle simple entries" do
232
+ @q.order(:a, 'b').to_s.should == 'SELECT FROM ORDER BY a, b'
233
+ end
234
+
235
+ it "should default to ASC on unrecognized directions" do
236
+ @q.order(:a => :unknown).to_s.should == 'SELECT FROM ORDER BY a ASC'
237
+ end
238
+
239
+ it "should handle concatenation" do
240
+ @q.order(:a).order(:b).to_s.should == 'SELECT FROM ORDER BY a, b'
241
+ end
242
+
243
+ it "should handle overriding" do
244
+ @q.order(:a).order!(:b).to_s.should == 'SELECT FROM ORDER BY b'
245
+ end
246
+ end
247
+
248
+ describe "LIMIT" do
249
+
250
+ before :each do
251
+ @q = OrientDB::SQL::Query.new
252
+ end
253
+
254
+ it "should handle integers" do
255
+ @q.limit(1).to_s.should == 'SELECT FROM LIMIT 1'
256
+ end
257
+
258
+ it "should handle strings" do
259
+ @q.limit('1').to_s.should == 'SELECT FROM LIMIT 1'
260
+ end
261
+
262
+ it "should handle other types" do
263
+ @q.limit(:'1').to_s.should == 'SELECT FROM LIMIT 1'
264
+ end
265
+
266
+ it "should override on concatenation" do
267
+ @q.limit(2).limit(1).to_s.should == 'SELECT FROM LIMIT 1'
268
+ end
269
+
270
+ it "should override on bang (alias)" do
271
+ @q.limit!(2).limit!(1).to_s.should == 'SELECT FROM LIMIT 1'
272
+ end
273
+ end
274
+
275
+ describe "RANGE" do
276
+
277
+ before :each do
278
+ @q = OrientDB::SQL::Query.new
279
+ end
280
+
281
+ it "should handle lower only" do
282
+ @q.range('1:1').to_s.should == 'SELECT FROM RANGE 1:1'
283
+ end
284
+
285
+ it "should handle lower and higher" do
286
+ @q.range('1:1', '1:5').to_s.should == 'SELECT FROM RANGE 1:1, 1:5'
287
+ end
288
+
289
+ it "should override on concatenation" do
290
+ @q.range('2:1', '2:5').range('1:1').to_s.should == 'SELECT FROM RANGE 1:1'
291
+ end
292
+
293
+ it "should override on bang (alias)" do
294
+ @q.range!('2:1', '2:5').range!('1:1').to_s.should == 'SELECT FROM RANGE 1:1'
295
+ end
296
+ end
297
+
298
+ describe "Monkey Patching" do
299
+ describe Symbol do
300
+ OrientDB::SQL.monkey_patch! Symbol
301
+
302
+ describe "Order" do
303
+ it "#asc should work" do
304
+ :name.asc.should == 'name ASC'
305
+ end
306
+
307
+ it "#desc should work" do
308
+ :name.desc.should == 'name DESC'
309
+ end
310
+ end
311
+
312
+ describe "Conditional" do
313
+ it "#like should work" do
314
+ :name.like("test%").should == "name LIKE 'test%'"
315
+ end
316
+
317
+ it "#eq should work" do
318
+ :age.eq(35).should == "age = 35"
319
+ end
320
+
321
+ it "#ne should work" do
322
+ :age.ne(35).should == "age <> 35"
323
+ end
324
+
325
+ it "#lt should work" do
326
+ :age.lt(35).should == "age < 35"
327
+ end
328
+
329
+ it "#lte should work" do
330
+ :age.lte(35).should == "age <= 35"
331
+ end
332
+
333
+ it "#gt should work" do
334
+ :age.gt(35).should == "age > 35"
335
+ end
336
+
337
+ it "#gte should work" do
338
+ :age.gte(35).should == "age >= 35"
339
+ end
340
+
341
+ it "#is_null should work" do
342
+ :name.is_null.should == "name IS null"
343
+ end
344
+
345
+ it "#is_not_null should work" do
346
+ :name.is_not_null.should == "name IS NOT null"
347
+ end
348
+
349
+ it "#in should work" do
350
+ :age.in(34, 36, 38).should == "age IN [34, 36, 38]"
351
+ end
352
+
353
+ it "#contains should work" do
354
+ :name.contains(:name, "tester").should == "name contains (name = 'tester')"
355
+ end
356
+
357
+ it "#contains_all should work" do
358
+ :name.contains_all(:name, "tester").should == "name containsAll (name = 'tester')"
359
+ end
360
+
361
+ it "#contains_key should work" do
362
+ :name.contains_key("tester").should == "name containsKey 'tester'"
363
+ end
364
+
365
+ it "#contains_value should work" do
366
+ :name.contains_value("tester").should == "name containsValue 'tester'"
367
+ end
368
+
369
+ it "#contains_text should work" do
370
+ :name.contains_text("tester").should == "name containsText 'tester'"
371
+ end
372
+
373
+ it "#matches should work" do
374
+ :name.matches(/(john|mark)/).should == "name matches '(john|mark)'"
375
+ end
376
+ end
377
+
378
+ describe "Field Operators" do
379
+ it "#odb_length should work" do
380
+ :name.odb_length.should == "name.length()"
381
+ end
382
+
383
+ it "#odb_trim should work" do
384
+ :name.odb_trim.should == "name.trim()"
385
+ end
386
+
387
+ it "#to_upper_case should work" do
388
+ :name.to_upper_case.should == "name.toUpperCase()"
389
+ end
390
+
391
+ it "#to_lower_case should work" do
392
+ :name.to_lower_case.should == "name.toLowerCase()"
393
+ end
394
+
395
+ it "#odb_left should work" do
396
+ :name.odb_left(5).should == "name.left(5)"
397
+ end
398
+
399
+ it "#odb_right should work" do
400
+ :name.odb_right(5).should == "name.right(5)"
401
+ end
402
+
403
+ it "#sub_string should work" do
404
+ :name.sub_string(3).should == "name.subString(3)"
405
+ :name.sub_string(3, 5).should == "name.subString(3, 5)"
406
+ end
407
+
408
+ it "#char_at should work" do
409
+ :name.char_at(3).should == "name.charAt(3)"
410
+ end
411
+
412
+ it "#index_of should work" do
413
+ :name.index_of("test").should == "name.indexOf('test')"
414
+ :name.index_of("test", 3).should == "name.indexOf('test', 3)"
415
+ end
416
+
417
+ it "#odb_format should work" do
418
+ :name.odb_format('%-20.20s').should == "name.format('%-20.20s')"
419
+ end
420
+
421
+ it "#odb_size should work" do
422
+ :name.odb_size.should == "name.size()"
423
+ end
424
+
425
+ it "#as_string should work" do
426
+ :name.as_string.should == "name.asString()"
427
+ end
428
+
429
+ it "#as_integer should work" do
430
+ :name.as_integer.should == "name.asInteger()"
431
+ end
432
+
433
+ it "#as_float should work" do
434
+ :name.as_float.should == "name.asFloat()"
435
+ end
436
+
437
+ it "#as_date should work" do
438
+ :name.as_date.should == "name.asDate()"
439
+ end
440
+
441
+ it "#as_date_time should work" do
442
+ :name.as_date_time.should == "name.asDateTime()"
443
+ end
444
+
445
+ it "#as_boolean should work" do
446
+ :name.as_boolean.should == "name.asBoolean()"
447
+ end
448
+ end
449
+
450
+ describe "Bundled Functions" do
451
+ it "#odb_count should work" do
452
+ :name.odb_count.should == "count(name)"
453
+ end
454
+
455
+ it "#odb_min should work" do
456
+ :name.odb_min.should == "min(name)"
457
+ end
458
+
459
+ it "#odb_max should work" do
460
+ :name.odb_max.should == "max(name)"
461
+ end
462
+
463
+ it "#odb_avg should work" do
464
+ :name.odb_avg.should == "avg(name)"
465
+ end
466
+
467
+ it "#odb_sum should work" do
468
+ :name.odb_sum.should == "sum(name)"
469
+ end
470
+
471
+ it "#sysdate should work" do
472
+ :'yyyy.MM.dd'.sysdate.should == "sysdate('yyyy.MM.dd')"
473
+ end
474
+
475
+ it "#odb_format_str should work" do
476
+ :'%d - Mr. %s %s (%s)'.odb_format_str(:id, :name, :surname, :address).should == "format('%d - Mr. %s %s (%s)', id, name, surname, address)"
477
+ end
478
+ end
479
+ end
480
+
481
+ describe String do
482
+ OrientDB::SQL.monkey_patch! String
483
+
484
+ describe "Order" do
485
+ it "#asc should work" do
486
+ 'name'.asc.should == 'name ASC'
487
+ end
488
+
489
+ it "#desc should work" do
490
+ 'name'.desc.should == 'name DESC'
491
+ end
492
+ end
493
+
494
+ describe "Conditional" do
495
+ it "#like should work" do
496
+ 'name'.like("test%").should == "name LIKE 'test%'"
497
+ end
498
+
499
+ it "#eq should work" do
500
+ 'age'.eq(35).should == "age = 35"
501
+ end
502
+
503
+ it "#ne should work" do
504
+ 'age'.ne(35).should == "age <> 35"
505
+ end
506
+
507
+ it "#lt should work" do
508
+ 'age'.lt(35).should == "age < 35"
509
+ end
510
+
511
+ it "#lte should work" do
512
+ 'age'.lte(35).should == "age <= 35"
513
+ end
514
+
515
+ it "#gt should work" do
516
+ 'age'.gt(35).should == "age > 35"
517
+ end
518
+
519
+ it "#gte should work" do
520
+ 'age'.gte(35).should == "age >= 35"
521
+ end
522
+
523
+ it "#is_null should work" do
524
+ 'name'.is_null.should == "name IS null"
525
+ end
526
+
527
+ it "#is_not_null should work" do
528
+ 'name'.is_not_null.should == "name IS NOT null"
529
+ end
530
+
531
+ it "#in should work" do
532
+ 'age'.in(34, 36, 38).should == "age IN [34, 36, 38]"
533
+ end
534
+
535
+ it "#contains should work" do
536
+ 'name'.contains('name', "tester").should == "name contains (name = 'tester')"
537
+ end
538
+
539
+ it "#contains_all should work" do
540
+ 'name'.contains_all('name', "tester").should == "name containsAll (name = 'tester')"
541
+ end
542
+
543
+ it "#contains_key should work" do
544
+ 'name'.contains_key("tester").should == "name containsKey 'tester'"
545
+ end
546
+
547
+ it "#contains_value should work" do
548
+ 'name'.contains_value("tester").should == "name containsValue 'tester'"
549
+ end
550
+
551
+ it "#contains_text should work" do
552
+ 'name'.contains_text("tester").should == "name containsText 'tester'"
553
+ end
554
+
555
+ it "#matches should work" do
556
+ 'name'.matches(/(john|mark)/).should == "name matches '(john|mark)'"
557
+ end
558
+ end
559
+
560
+ describe "Field Operators" do
561
+ it "#odb_length should work" do
562
+ 'name'.odb_length.should == "name.length()"
563
+ end
564
+
565
+ it "#odb_trim should work" do
566
+ 'name'.odb_trim.should == "name.trim()"
567
+ end
568
+
569
+ it "#to_upper_case should work" do
570
+ 'name'.to_upper_case.should == "name.toUpperCase()"
571
+ end
572
+
573
+ it "#to_lower_case should work" do
574
+ 'name'.to_lower_case.should == "name.toLowerCase()"
575
+ end
576
+
577
+ it "#odb_left should work" do
578
+ 'name'.odb_left(5).should == "name.left(5)"
579
+ end
580
+
581
+ it "#odb_right should work" do
582
+ 'name'.odb_right(5).should == "name.right(5)"
583
+ end
584
+
585
+ it "#sub_string should work" do
586
+ 'name'.sub_string(3).should == "name.subString(3)"
587
+ 'name'.sub_string(3, 5).should == "name.subString(3, 5)"
588
+ end
589
+
590
+ it "#char_at should work" do
591
+ 'name'.char_at(3).should == "name.charAt(3)"
592
+ end
593
+
594
+ it "#index_of should work" do
595
+ 'name'.index_of("test").should == "name.indexOf('test')"
596
+ 'name'.index_of("test", 3).should == "name.indexOf('test', 3)"
597
+ end
598
+
599
+ it "#odb_format should work" do
600
+ 'name'.odb_format('%-20.20s').should == "name.format('%-20.20s')"
601
+ end
602
+
603
+ it "#odb_size should work" do
604
+ 'name'.odb_size.should == "name.size()"
605
+ end
606
+
607
+ it "#as_string should work" do
608
+ 'name'.as_string.should == "name.asString()"
609
+ end
610
+
611
+ it "#as_integer should work" do
612
+ 'name'.as_integer.should == "name.asInteger()"
613
+ end
614
+
615
+ it "#as_float should work" do
616
+ 'name'.as_float.should == "name.asFloat()"
617
+ end
618
+
619
+ it "#as_date should work" do
620
+ 'name'.as_date.should == "name.asDate()"
621
+ end
622
+
623
+ it "#as_date_time should work" do
624
+ 'name'.as_date_time.should == "name.asDateTime()"
625
+ end
626
+
627
+ it "#as_boolean should work" do
628
+ 'name'.as_boolean.should == "name.asBoolean()"
629
+ end
630
+ end
631
+
632
+ describe "Bundled Functions" do
633
+ it "#odb_count should work" do
634
+ 'name'.odb_count.should == "count(name)"
635
+ end
636
+
637
+ it "#odb_min should work" do
638
+ 'name'.odb_min.should == "min(name)"
639
+ end
640
+
641
+ it "#odb_max should work" do
642
+ 'name'.odb_max.should == "max(name)"
643
+ end
644
+
645
+ it "#odb_avg should work" do
646
+ 'name'.odb_avg.should == "avg(name)"
647
+ end
648
+
649
+ it "#odb_sum should work" do
650
+ 'name'.odb_sum.should == "sum(name)"
651
+ end
652
+
653
+ it "#sysdate should work" do
654
+ 'yyyy.MM.dd'.sysdate.should == "sysdate('yyyy.MM.dd')"
655
+ end
656
+
657
+ it "#odb_format_str should work" do
658
+ '%d - Mr. %s %s (%s)'.odb_format_str(:id, :name, :surname, :address).should == "format('%d - Mr. %s %s (%s)', id, name, surname, address)"
659
+ end
660
+ end
661
+ end
662
+ end
663
+ end
664
+
665
+ end
666
+ end