activetokyocabinet 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/active_record/connection_adapters/tokyocabinet_adapter.rb +32 -0
- data/lib/active_record/connection_adapters/tokyotyrant_adapter.rb +37 -1
- data/lib/active_tokyocabinet/sqlparser.tab.rb +232 -216
- data/lib/active_tokyocabinet/sqlparser.y +16 -9
- data/lib/active_tokyocabinet/tdb.rb +4 -0
- data/spec/spec_helper.rb +53 -20
- data/spec/tcspec2ttspec.sh +2 -0
- data/spec/tokyocabinet_spec.rb +481 -0
- data/spec/tokyotyrant_spec.rb +481 -0
- metadata +4 -2
- data/spec/activetokyocabinet_spec.rb +0 -260
@@ -89,6 +89,13 @@ rule
|
|
89
89
|
{
|
90
90
|
{:name => val[0], :op => tccond(val[1], val[3]), :expr => val[3]}
|
91
91
|
}
|
92
|
+
| between_predicate
|
93
|
+
|
94
|
+
between_predicate : id BETWEEN value AND value
|
95
|
+
{
|
96
|
+
{:name => val[0], :op => tccond(val[1], nil), :expr => [val[2], val[4]]}
|
97
|
+
}
|
98
|
+
|
92
99
|
order_by_clause :
|
93
100
|
{
|
94
101
|
nil
|
@@ -173,12 +180,12 @@ rule
|
|
173
180
|
| INCANY
|
174
181
|
| INC
|
175
182
|
| IN
|
176
|
-
|
|
183
|
+
| ANYONE
|
177
184
|
| REGEXP
|
178
|
-
|
|
185
|
+
| BT
|
179
186
|
| FTS
|
180
|
-
|
|
181
|
-
|
|
187
|
+
| FTSAND
|
188
|
+
| FTSOR
|
182
189
|
| FTSEX
|
183
190
|
| '>='
|
184
191
|
| '<='
|
@@ -207,7 +214,7 @@ def scan
|
|
207
214
|
until @ss.eos?
|
208
215
|
if (tok = @ss.scan /\s+/)
|
209
216
|
# nothing to do
|
210
|
-
elsif (tok = @ss.scan /(?:BW|EW|INCALL|INCANY|INC|IN|
|
217
|
+
elsif (tok = @ss.scan /(?:BW|EW|INCALL|INCANY|INC|IN|ANYONE|REGEXP|BT|BETWEEN|FTS|FTSAND|FTSOR|FTSEX)\b/i)
|
211
218
|
yield tok.upcase.to_sym, tok
|
212
219
|
elsif (tok = @ss.scan /(?:>=|<=|>|<|=)/)
|
213
220
|
yield tok, tok
|
@@ -256,7 +263,7 @@ def tccond(op, expr)
|
|
256
263
|
:QCSTRAND
|
257
264
|
when 'INCANY'
|
258
265
|
:QCSTROR
|
259
|
-
when 'IN', '
|
266
|
+
when 'IN', 'ANYONE'
|
260
267
|
expr.all? {|i| i.kind_of?(Numeric) } ? :QCNUMOREQ : :QCSTROREQ
|
261
268
|
when 'REGEXP'
|
262
269
|
:QCSTRRX
|
@@ -268,13 +275,13 @@ def tccond(op, expr)
|
|
268
275
|
:QCNUMLT
|
269
276
|
when '<='
|
270
277
|
:QCNUMLE
|
271
|
-
when 'BETWEEN'
|
278
|
+
when 'BT', 'BETWEEN'
|
272
279
|
:QCNUMBT
|
273
280
|
when 'FTS'
|
274
281
|
:QCFTSPH
|
275
|
-
when '
|
282
|
+
when 'FTSAND'
|
276
283
|
:QCFTSAND
|
277
|
-
when '
|
284
|
+
when 'FTSOR'
|
278
285
|
:QCFTSOR
|
279
286
|
when 'FTSEX'
|
280
287
|
:QCFTSEX
|
@@ -13,6 +13,10 @@ module ActiveTokyoCabinet
|
|
13
13
|
@columns << ActiveRecord::ConnectionAdapters::Column.new(name.to_s, nil)
|
14
14
|
class_eval "def \#{name}; v = self[:\#{name}]; (v.nil? || v.empty?) ? nil : v.#{conv}; end"
|
15
15
|
end
|
16
|
+
|
17
|
+
def setindex(name, type)
|
18
|
+
self.connection.setindex(self.table_name, name, type)
|
19
|
+
end
|
16
20
|
}
|
17
21
|
end
|
18
22
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -86,20 +86,22 @@ EOS
|
|
86
86
|
|
87
87
|
def employee_data
|
88
88
|
data = [
|
89
|
-
[7369, 'SMITH'
|
90
|
-
[7499, 'ALLEN'
|
91
|
-
[7521, 'WARD'
|
92
|
-
[7566, 'JONES'
|
93
|
-
[7654, 'MARTIN', 'SALESMAN'
|
94
|
-
[7698, 'BLAKE'
|
95
|
-
[7782, 'CLARK'
|
96
|
-
[7788, 'SCOTT'
|
97
|
-
[7839, 'KING'
|
98
|
-
[7844, 'TURNER', 'SALESMAN'
|
99
|
-
[7876, 'ADAMS'
|
100
|
-
[7900, 'JAMES'
|
101
|
-
[7902, 'FORD'
|
102
|
-
[7934, 'MILLER', 'CLERK'
|
89
|
+
[7369, 'SMITH' , 'CLERK' , 7902, '17-DEC-1980', 800.0, nil, 20],
|
90
|
+
[7499, 'ALLEN' , 'SALESMAN' , 7698, '20-FEB-1981', 1600.0, 300.0, 30],
|
91
|
+
[7521, 'WARD' , 'SALESMAN' , 7698, '22-FEB-1981', 1250.0, 500.0, 30],
|
92
|
+
[7566, 'JONES' , 'MANAGER' , 7839, '2-APR-1981' , 2975.0, nil, 20],
|
93
|
+
[7654, 'MARTIN' , 'SALESMAN' , 7698, '28-SEP-1981', 1250.0, 1400.0, 30],
|
94
|
+
[7698, 'BLAKE' , 'MANAGER' , 7839, '1-MAY-1981' , 2850.0, nil, 30],
|
95
|
+
[7782, 'CLARK' , 'MANAGER' , 7839, '9-JUN-1981' , 2450.0, nil, 10],
|
96
|
+
[7788, 'SCOTT' , 'ANALYST' , 7566, '09-DEC-1982', 3000.0, nil, 20],
|
97
|
+
[7839, 'KING' , 'PRESIDENT' , nil, '17-NOV-1981', 5000.0, nil, 10],
|
98
|
+
[7844, 'TURNER' , 'SALESMAN' , 7698, '8-SEP-1981' , 1500.0, 0.0, 30],
|
99
|
+
[7876, 'ADAMS' , 'CLERK' , 7788, '12-JAN-1983', 1100.0, nil, 20],
|
100
|
+
[7900, 'JAMES' , 'CLERK' , 7698, '3-DEC-1981' , 950.0, nil, 30],
|
101
|
+
[7902, 'FORD' , 'ANALYST' , 7566, '3-DEC-1981' , 3000.0, nil, 20],
|
102
|
+
[7934, 'MILLER' , 'CLERK' , 7782, '23-JAN-1982', 1300.0, nil, 10],
|
103
|
+
[7935, 'HATSUNE MIKU', 'ANALYST,MANAGER', 7784, '23-JAN-1982', 1350.0, nil, 30],
|
104
|
+
[7936, 'KAGAMINE RIN', 'ANALYST,CLERK' , 7786, '23-JAN-1983', 1400.0, nil, 10],
|
103
105
|
[ nil, nil , nil , nil, nil , nil, nil, nil],
|
104
106
|
]
|
105
107
|
|
@@ -178,13 +180,9 @@ module ActiveTokyoCabinetSpec
|
|
178
180
|
)
|
179
181
|
end
|
180
182
|
|
181
|
-
def tctmgr_create(path)
|
182
|
-
`tctmgr create #{path}`
|
183
|
-
end
|
184
|
-
|
185
183
|
def create_tables
|
186
|
-
|
187
|
-
|
184
|
+
`tctmgr create #{$wd}/employees.tct`
|
185
|
+
`tctmgr create #{$wd}/departments.tct`
|
188
186
|
end
|
189
187
|
|
190
188
|
def clean
|
@@ -193,4 +191,39 @@ module ActiveTokyoCabinetSpec
|
|
193
191
|
end
|
194
192
|
end # class << self
|
195
193
|
end # module TokyoCabinetSpec
|
194
|
+
|
195
|
+
module TokyoTyrantSpec
|
196
|
+
extend ActiveTokyoCabinetSpec::Base
|
197
|
+
|
198
|
+
class << self
|
199
|
+
def establish_connection
|
200
|
+
ActiveRecord::Base.establish_connection(
|
201
|
+
:adapter => 'tokyotyrant',
|
202
|
+
:database => {
|
203
|
+
:employees => {:host => 'localhost', :port => 1978},
|
204
|
+
:departments => {:host => 'localhost', :port => 1979},
|
205
|
+
}
|
206
|
+
)
|
207
|
+
end
|
208
|
+
|
209
|
+
def create_tables
|
210
|
+
Dir.glob("#{$wd}/*.{tct,pid}*").each do |f|
|
211
|
+
FileUtils.rm_f f
|
212
|
+
end
|
213
|
+
|
214
|
+
`ttserver -port 1978 -dmn -pid "#{$wd}/employees.pid" "#{$wd}/employees.tct"`
|
215
|
+
`ttserver -port 1979 -dmn -pid "#{$wd}/departments.pid" "#{$wd}/departments.tct"`
|
216
|
+
sleep 3
|
217
|
+
end
|
218
|
+
|
219
|
+
def clean
|
220
|
+
`killall -9 ttserver`
|
221
|
+
sleep 3
|
222
|
+
|
223
|
+
Dir.glob("#{$wd}/*.{tct,pid}*").each do |f|
|
224
|
+
FileUtils.rm_f f
|
225
|
+
end
|
226
|
+
end
|
227
|
+
end # class << self
|
228
|
+
end # module TokyoCabinetSpec
|
196
229
|
end # module ActiveTokyoCabinetSpec
|
@@ -0,0 +1,481 @@
|
|
1
|
+
$wd = File.dirname(File.expand_path(__FILE__))
|
2
|
+
ENV['RUBYLIB'] = "#{$wd}/../lib"
|
3
|
+
|
4
|
+
require 'spec_helper'
|
5
|
+
include SpecHelper
|
6
|
+
include ActiveTokyoCabinetSpec
|
7
|
+
|
8
|
+
describe 'tokyocabinet:' do
|
9
|
+
before do
|
10
|
+
TokyoCabinetSpec.establish_connection
|
11
|
+
TokyoCabinetSpec.create_tables
|
12
|
+
TokyoCabinetSpec.setup_employee
|
13
|
+
TokyoCabinetSpec.setup_department
|
14
|
+
end
|
15
|
+
|
16
|
+
it "employees length > 0" do
|
17
|
+
employees = Employee.find(:all)
|
18
|
+
employees.length.should == employee_data.length
|
19
|
+
end
|
20
|
+
|
21
|
+
it "employees has a one data (ename = 'SMITH')" do
|
22
|
+
employees = Employee.find(:all, :conditions => ['ename = ?', 'SMITH'])
|
23
|
+
employees.length.should == 1
|
24
|
+
data = employee_data.find {|i| i[EMP_ENAME] == 'SMITH' }
|
25
|
+
validate_employee(data, employees[0])
|
26
|
+
end
|
27
|
+
|
28
|
+
it "employees has a one data (empno = 7521)" do
|
29
|
+
employees = Employee.find(:all, :conditions => ['empno = ?', 7521])
|
30
|
+
employees.length.should == 1
|
31
|
+
data = employee_data.find {|i| i[EMP_EMPNO] == 7521 }
|
32
|
+
validate_employee(data, employees[0])
|
33
|
+
end
|
34
|
+
|
35
|
+
it "employees has no data (ename = 'SMITH' and job = 'SALESMAN')" do
|
36
|
+
employees = Employee.find(:all, :conditions => ['ename = ? and job = ?', 'SMITH', 'SALESMAN'])
|
37
|
+
employees.should be_empty
|
38
|
+
end
|
39
|
+
|
40
|
+
it "employees a one data (ename = 'TURNER' and job = 'SALESMAN')" do
|
41
|
+
employees = Employee.find(:all, :conditions => ['ename = ? and job = ?', 'TURNER', 'SALESMAN'])
|
42
|
+
employees.length.should == 1
|
43
|
+
data = employee_data.find {|i| i[EMP_ENAME] == 'TURNER' and i[EMP_JOB] == 'SALESMAN' }
|
44
|
+
validate_employee(data, employees[0])
|
45
|
+
end
|
46
|
+
|
47
|
+
it "employees a one data ({:ename => 'TURNER', :job => 'SALESMAN'})" do
|
48
|
+
employees = Employee.find(:all, :conditions => {:ename => 'TURNER', :job => 'SALESMAN'})
|
49
|
+
employees.length.should == 1
|
50
|
+
data = employee_data.find {|i| i[EMP_ENAME] == 'TURNER' and i[EMP_JOB] == 'SALESMAN' }
|
51
|
+
validate_employee(data, employees[0])
|
52
|
+
end
|
53
|
+
|
54
|
+
it "employees has any data" do
|
55
|
+
employee_data.each do |data|
|
56
|
+
employee_id = data.id
|
57
|
+
employee = Employee.find(employee_id)
|
58
|
+
|
59
|
+
employee.should_not be_nil
|
60
|
+
employee.id.should == employee_id
|
61
|
+
validate_employee(data, employee)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
it "employees has any data (job = 'SALESMAN')" do
|
66
|
+
employees = Employee.find(:all, :conditions => ['job = ?', 'SALESMAN'])
|
67
|
+
employees.should_not be_empty
|
68
|
+
|
69
|
+
employees.each do |employee|
|
70
|
+
data = employee_data[employee.id - 1]
|
71
|
+
|
72
|
+
data.should_not be_nil
|
73
|
+
data[EMP_JOB].should == 'SALESMAN'
|
74
|
+
validate_employee(data, employee)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
it "employees has any data (id=1,2,3)" do
|
79
|
+
employees = Employee.find([1, 2, 3])
|
80
|
+
employees.should_not be_empty
|
81
|
+
data_list = employee_data[0..2]
|
82
|
+
employees.length.should == data_list.length
|
83
|
+
|
84
|
+
data_list.each do |data|
|
85
|
+
empno, ename, job, mgr, hiredate, sal, comm, deptno = data
|
86
|
+
employee_id = data.id
|
87
|
+
employee = employees.find {|i| i.id == employee_id }
|
88
|
+
|
89
|
+
employee.should_not be_nil
|
90
|
+
employee.id.should == employee_id
|
91
|
+
validate_employee(data, employee)
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
it "employees has any data (order by ename desc limit 3)" do
|
96
|
+
employees = Employee.find(:all, :order => 'ename desc', :limit => 3)
|
97
|
+
data_list = employee_data.sort_by {|i| i[EMP_ENAME] || '' }.reverse[0..2]
|
98
|
+
employees.length.should == data_list.length
|
99
|
+
|
100
|
+
data_list.each do |data|
|
101
|
+
employee = employees.find {|i| i.id == data.id }
|
102
|
+
employee.should_not be_nil
|
103
|
+
validate_employee(data, employee)
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
it "employees has any data (order by ename desc limit 4 offset 5)" do
|
108
|
+
employees = Employee.find(:all, :order => 'ename desc', :limit => 4, :offset => 5)
|
109
|
+
employees.should_not be_empty
|
110
|
+
data_list = employee_data.sort_by {|i| i[EMP_ENAME] || '' }.reverse[5..8]
|
111
|
+
employees.length.should == data_list.length
|
112
|
+
|
113
|
+
data_list.each do |data|
|
114
|
+
employee = employees.find {|i| i.id == data.id }
|
115
|
+
employee.should_not be_nil
|
116
|
+
validate_employee(data, employee)
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
it "employees has any data (ename bw 'J')" do
|
121
|
+
employees = Employee.find(:all, :conditions => ['ename bw ?', 'J'])
|
122
|
+
employees.should_not be_empty
|
123
|
+
data_list = employee_data.select {|i| i[EMP_ENAME] =~ /\AJ/ }
|
124
|
+
employees.length.should == data_list.length
|
125
|
+
|
126
|
+
data_list.each do |data|
|
127
|
+
employee = employees.find {|i| i.id == data.id }
|
128
|
+
employee.should_not be_nil
|
129
|
+
validate_employee(data, employee)
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
it "employees has any data (ename ew 'ES')" do
|
134
|
+
employees = Employee.find(:all, :conditions => ['ename ew ?', 'ES'])
|
135
|
+
employees.should_not be_empty
|
136
|
+
data_list = employee_data.select {|i| i[EMP_ENAME] =~ /ES\Z/ }
|
137
|
+
employees.length.should == data_list.length
|
138
|
+
|
139
|
+
data_list.each do |data|
|
140
|
+
employee = employees.find {|i| i.id == data.id }
|
141
|
+
employee.should_not be_nil
|
142
|
+
validate_employee(data, employee)
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
it "employees has any data (ename inc 'LA')" do
|
147
|
+
employees = Employee.find(:all, :conditions => ['ename inc ?', 'LA'])
|
148
|
+
employees.should_not be_empty
|
149
|
+
data_list = employee_data.select {|i| i[EMP_ENAME] =~ /LA/ }
|
150
|
+
employees.length.should == data_list.length
|
151
|
+
|
152
|
+
data_list.each do |data|
|
153
|
+
employee = employees.find {|i| i.id == data.id }
|
154
|
+
employee.should_not be_nil
|
155
|
+
validate_employee(data, employee)
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
it "employees has any data (job incall ('ANALYST', 'MANAGER'))" do
|
160
|
+
employees = Employee.find(:all, :conditions => ['job incall (?)', ['ANALYST', 'MANAGER']])
|
161
|
+
employees.should_not be_empty
|
162
|
+
data_list = employee_data.select {|i| i[EMP_JOB] =~ /ANALYST/ and i[EMP_JOB] =~ /MANAGER/ }
|
163
|
+
employees.length.should == data_list.length
|
164
|
+
|
165
|
+
data_list.each do |data|
|
166
|
+
employee = employees.find {|i| i.id == data.id }
|
167
|
+
employee.should_not be_nil
|
168
|
+
validate_employee(data, employee)
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
it "employees has any data (job incany ('ANALYST', 'MANAGER'))" do
|
173
|
+
employees = Employee.find(:all, :conditions => ['job incany (?)', ['ANALYST', 'MANAGER']])
|
174
|
+
employees.should_not be_empty
|
175
|
+
data_list = employee_data.select {|i| i[EMP_JOB] =~ /ANALYST/ or i[EMP_JOB] =~ /MANAGER/ }
|
176
|
+
employees.length.should == data_list.length
|
177
|
+
|
178
|
+
data_list.each do |data|
|
179
|
+
employee = employees.find {|i| i.id == data.id }
|
180
|
+
employee.should_not be_nil
|
181
|
+
validate_employee(data, employee)
|
182
|
+
end
|
183
|
+
end
|
184
|
+
|
185
|
+
it "employees has any data (job in ('ANALYST', 'MANAGER'))" do
|
186
|
+
employees = Employee.find(:all, :conditions => ['job in (?)', ['ANALYST', 'MANAGER']])
|
187
|
+
employees.should_not be_empty
|
188
|
+
data_list = employee_data.select {|i| i[EMP_JOB] == 'ANALYST' or i[EMP_JOB] == 'MANAGER' }
|
189
|
+
employees.length.should == data_list.length
|
190
|
+
|
191
|
+
data_list.each do |data|
|
192
|
+
employee = employees.find {|i| i.id == data.id }
|
193
|
+
employee.should_not be_nil
|
194
|
+
validate_employee(data, employee)
|
195
|
+
end
|
196
|
+
end
|
197
|
+
|
198
|
+
it "employees has any data (empno in (7934, 7935, 7936))" do
|
199
|
+
employees = Employee.find(:all, :conditions => ['empno in (?)', [7934, 7935, 7936]])
|
200
|
+
employees.should_not be_empty
|
201
|
+
data_list = employee_data.select {|i| [7934, 7935, 7936].include?(i[EMP_EMPNO]) }
|
202
|
+
employees.length.should == data_list.length
|
203
|
+
|
204
|
+
data_list.each do |data|
|
205
|
+
employee = employees.find {|i| i.id == data.id }
|
206
|
+
employee.should_not be_nil
|
207
|
+
validate_employee(data, employee)
|
208
|
+
end
|
209
|
+
end
|
210
|
+
|
211
|
+
it "employees has any data (job anyone ('ANALYST', 'MANAGER'))" do
|
212
|
+
employees = Employee.find(:all, :conditions => ['job anyone (?)', ['ANALYST', 'MANAGER']])
|
213
|
+
employees.should_not be_empty
|
214
|
+
data_list = employee_data.select {|i| i[EMP_JOB] == 'ANALYST' or i[EMP_JOB] == 'MANAGER' }
|
215
|
+
employees.length.should == data_list.length
|
216
|
+
|
217
|
+
data_list.each do |data|
|
218
|
+
employee = employees.find {|i| i.id == data.id }
|
219
|
+
employee.should_not be_nil
|
220
|
+
validate_employee(data, employee)
|
221
|
+
end
|
222
|
+
end
|
223
|
+
|
224
|
+
it "employees has any data (ename regexp '^J[AO].+$')" do
|
225
|
+
employees = Employee.find(:all, :conditions => ['ename regexp ?', '^J[AO].+$'])
|
226
|
+
employees.should_not be_empty
|
227
|
+
data_list = employee_data.select {|i| i[EMP_ENAME] =~ /\AJ[AO].+\Z/ }
|
228
|
+
employees.length.should == data_list.length
|
229
|
+
|
230
|
+
data_list.each do |data|
|
231
|
+
employee = employees.find {|i| i.id == data.id }
|
232
|
+
employee.should_not be_nil
|
233
|
+
validate_employee(data, employee)
|
234
|
+
end
|
235
|
+
end
|
236
|
+
|
237
|
+
it "employees has any data (ename fts 'MI')" do
|
238
|
+
employees = Employee.find(:all, :conditions => ['ename fts ?', 'MI'])
|
239
|
+
employees.should_not be_empty
|
240
|
+
data_list = employee_data.select {|i| i[EMP_ENAME] =~ /MI/ }
|
241
|
+
employees.length.should == data_list.length
|
242
|
+
|
243
|
+
data_list.each do |data|
|
244
|
+
employee = employees.find {|i| i.id == data.id }
|
245
|
+
employee.should_not be_nil
|
246
|
+
validate_employee(data, employee)
|
247
|
+
end
|
248
|
+
end
|
249
|
+
|
250
|
+
it "employees has any data (ename ftsand 'HATSUNE MIKU')" do
|
251
|
+
# XXX:
|
252
|
+
employees = Employee.find(:all, :conditions => ['ename ftsand ?', 'HATSUNE MIKU'])
|
253
|
+
employees = Employee.find(:all, :conditions => ['ename ftsand (?)', ['HATSUNE', 'MIKU']])
|
254
|
+
end
|
255
|
+
|
256
|
+
it "employees has any data (hiredate ftsor '1983 DEC')" do
|
257
|
+
# XXX:
|
258
|
+
employees = Employee.find(:all, :conditions => ['hiredate ftsor ?', '1983 DEC'])
|
259
|
+
employees = Employee.find(:all, :conditions => ['hiredate ftsor (?)', ['1983', 'DEC']])
|
260
|
+
end
|
261
|
+
|
262
|
+
it "employees has any data (ename ftsex 'MIKU || RIN')" do
|
263
|
+
employees = Employee.find(:all, :conditions => ['ename ftsex ?', 'MIKU || RIN'])
|
264
|
+
employees.should_not be_empty
|
265
|
+
data_list = employee_data.select {|i| i[EMP_ENAME] =~ /MIKU/ or i[EMP_ENAME] =~ /RIN/ }
|
266
|
+
employees.length.should == data_list.length
|
267
|
+
|
268
|
+
data_list.each do |data|
|
269
|
+
employee = employees.find {|i| i.id == data.id }
|
270
|
+
employee.should_not be_nil
|
271
|
+
validate_employee(data, employee)
|
272
|
+
end
|
273
|
+
end
|
274
|
+
|
275
|
+
it "employees has any data (ename ftsex 'HATSUNE && MIKU')" do
|
276
|
+
employees = Employee.find(:all, :conditions => ['ename ftsex ?', 'HATSUNE && MIKU'])
|
277
|
+
employees.should_not be_empty
|
278
|
+
data_list = employee_data.select {|i| i[EMP_ENAME] =~ /HATSUNE/ and i[EMP_ENAME] =~ /MIKU/ }
|
279
|
+
employees.length.should == data_list.length
|
280
|
+
|
281
|
+
data_list.each do |data|
|
282
|
+
employee = employees.find {|i| i.id == data.id }
|
283
|
+
employee.should_not be_nil
|
284
|
+
validate_employee(data, employee)
|
285
|
+
end
|
286
|
+
end
|
287
|
+
|
288
|
+
it "employees has any data ([])" do
|
289
|
+
employee_data.each do |data|
|
290
|
+
empno, ename, job, mgr, hiredate, sal, comm, deptno = data
|
291
|
+
employee_id = data.id
|
292
|
+
employee = Employee.find(employee_id)
|
293
|
+
|
294
|
+
employee.should_not be_nil
|
295
|
+
employee[:id].should == employee_id
|
296
|
+
employee[:empno].should == empno.to_s
|
297
|
+
employee[:ename].should == ename.to_s
|
298
|
+
employee[:job].should == job.to_s
|
299
|
+
employee[:mgr].should == mgr.to_s
|
300
|
+
employee[:hiredate].should == hiredate.to_s
|
301
|
+
employee[:sal].should == sal.to_s
|
302
|
+
employee[:comm].should == comm.to_s
|
303
|
+
employee[:deptno].should == deptno.to_s
|
304
|
+
end
|
305
|
+
end
|
306
|
+
|
307
|
+
# -------------------------------------------------------------------
|
308
|
+
|
309
|
+
it "departments length > 0" do
|
310
|
+
departments = Department.find(:all)
|
311
|
+
departments.length.should == department_data.length
|
312
|
+
end
|
313
|
+
|
314
|
+
it "departments has a one data (dname = 'SALES')" do
|
315
|
+
departments = Department.find(:all, :conditions => ['dname = ?', 'SALES'])
|
316
|
+
departments.length.should == 1
|
317
|
+
data = department_data.find {|i| i[DEPT_DNAME] == 'SALES' }
|
318
|
+
validate_department(data, departments[0])
|
319
|
+
end
|
320
|
+
|
321
|
+
it "departments has a one data (deptno = 20)" do
|
322
|
+
departments = Department.find(:all, :conditions => ['deptno = ?', 20])
|
323
|
+
departments.length.should == 1
|
324
|
+
data = department_data.find {|i| i[DEPT_DEPTNO] == 20 }
|
325
|
+
validate_department(data, departments[0])
|
326
|
+
end
|
327
|
+
|
328
|
+
it "departments has no data (deptno = 20 and loc = 'BOSTON')" do
|
329
|
+
departments = Department.find(:all, :conditions => ['deptno = ? and loc = ?', 20, 'BOSTON'])
|
330
|
+
departments.should be_empty
|
331
|
+
end
|
332
|
+
|
333
|
+
it "departments has a one data (deptno = 40 and loc = 'BOSTON')" do
|
334
|
+
departments = Department.find(:all, :conditions => ['deptno = ? and loc = ?', 40, 'BOSTON'])
|
335
|
+
departments.length.should == 1
|
336
|
+
data = department_data.find {|i| i[DEPT_DEPTNO] == 40 and i[DEPT_LOC] == 'BOSTON' }
|
337
|
+
validate_department(data, departments[0])
|
338
|
+
end
|
339
|
+
|
340
|
+
it "departments has a one data ({:deptno => 40. :loc => 'BOSTON'})" do
|
341
|
+
departments = Department.find(:all, :conditions => {:deptno => 40, :loc => 'BOSTON'})
|
342
|
+
departments.length.should == 1
|
343
|
+
data = department_data.find {|i| i[DEPT_DEPTNO] == 40 and i[DEPT_LOC] == 'BOSTON' }
|
344
|
+
validate_department(data, departments[0])
|
345
|
+
end
|
346
|
+
|
347
|
+
it "departments has any data" do
|
348
|
+
department_data.each do |data|
|
349
|
+
department_id = data.id
|
350
|
+
department = Department.find(department_id)
|
351
|
+
|
352
|
+
department.should_not be_nil
|
353
|
+
department.id.should == department_id
|
354
|
+
validate_department(data, department)
|
355
|
+
end
|
356
|
+
end
|
357
|
+
|
358
|
+
it "departments has any data ([])" do
|
359
|
+
department_data.each do |data|
|
360
|
+
deptno, dname, loc = data
|
361
|
+
department_id = data.id
|
362
|
+
department = Department.find(department_id)
|
363
|
+
|
364
|
+
department.should_not be_nil
|
365
|
+
department[:id].should == department_id
|
366
|
+
department[:deptno].should == deptno.to_s
|
367
|
+
department[:dname].should == dname.to_s
|
368
|
+
department[:loc].should == loc.to_s
|
369
|
+
end
|
370
|
+
end
|
371
|
+
|
372
|
+
it "department has any data (loc in ('NEW YORK', 'CHICAGO'))" do
|
373
|
+
departments = Department.find(:all, :conditions => ['loc in (?)', ['NEW YORK', 'CHICAGO']])
|
374
|
+
departments.should_not be_empty
|
375
|
+
|
376
|
+
departments.each do |department|
|
377
|
+
data = department_data[department.id - 1]
|
378
|
+
|
379
|
+
data.should_not be_nil
|
380
|
+
validate_department(data, department)
|
381
|
+
end
|
382
|
+
end
|
383
|
+
|
384
|
+
it "department has any data ({:loc => ['NEW YORK', 'CHICAGO']})" do
|
385
|
+
departments = Department.find(:all, :conditions => {:loc => ['NEW YORK', 'CHICAGO']})
|
386
|
+
departments.should_not be_empty
|
387
|
+
|
388
|
+
departments.each do |department|
|
389
|
+
data = department_data[department.id - 1]
|
390
|
+
|
391
|
+
data.should_not be_nil
|
392
|
+
['NEW YORK', 'CHICAGO'].should include(data[DEPT_LOC])
|
393
|
+
validate_department(data, department)
|
394
|
+
end
|
395
|
+
end
|
396
|
+
|
397
|
+
it "departments has any data (id=1,2,3)" do
|
398
|
+
departments = Department.find([1, 2, 3])
|
399
|
+
departments.should_not be_empty
|
400
|
+
data_list = department_data[0..2]
|
401
|
+
departments.length.should == data_list.length
|
402
|
+
|
403
|
+
data_list.each do |data|
|
404
|
+
deptno, dname, loc = data
|
405
|
+
department_id = data.id
|
406
|
+
department = departments.find {|i| i.id == department_id }
|
407
|
+
|
408
|
+
department.should_not be_nil
|
409
|
+
validate_department(data, department)
|
410
|
+
end
|
411
|
+
end
|
412
|
+
|
413
|
+
it "departments has any data (order by deptno numdesc limit 65535 offset 1)" do
|
414
|
+
departments = Department.find(:all, :order => 'deptno numdesc', :limit => 65535, :offset => 1)
|
415
|
+
departments.should_not be_empty
|
416
|
+
data_list = department_data.sort_by {|i| i[DEPT_DEPTNO] || 0 }.reverse[1..-1]
|
417
|
+
departments.length.should == data_list.length
|
418
|
+
|
419
|
+
data_list.each do |data|
|
420
|
+
department = departments.find {|i| i.id == data.id }
|
421
|
+
department.should_not be_nil
|
422
|
+
validate_department(data, department)
|
423
|
+
end
|
424
|
+
end
|
425
|
+
|
426
|
+
it "departments has any data (order by deptno numasc)" do
|
427
|
+
departments = Department.find(:all, :order => 'deptno numasc')
|
428
|
+
departments.should_not be_empty
|
429
|
+
data_list = department_data.sort_by {|i| i[DEPT_DEPTNO] || 0 }
|
430
|
+
departments.length.should == data_list.length
|
431
|
+
|
432
|
+
data_list.each do |data|
|
433
|
+
department = departments.find {|i| i.id == data.id }
|
434
|
+
department.should_not be_nil
|
435
|
+
validate_department(data, department)
|
436
|
+
end
|
437
|
+
end
|
438
|
+
|
439
|
+
it "departments has any data (deptno between 20 and 30)" do
|
440
|
+
departments = Department.find(:all, :conditions => ['deptno between ? and ?', 20, 30])
|
441
|
+
departments.should_not be_empty
|
442
|
+
data_list = department_data.select {|i| i[DEPT_DEPTNO] and 20 <= i[DEPT_DEPTNO] and i[DEPT_DEPTNO] <= 30 }
|
443
|
+
departments.length.should == data_list.length
|
444
|
+
|
445
|
+
data_list.each do |data|
|
446
|
+
department = departments.find {|i| i.id == data.id }
|
447
|
+
department.should_not be_nil
|
448
|
+
validate_department(data, department)
|
449
|
+
end
|
450
|
+
end
|
451
|
+
|
452
|
+
it "departments has any data (deptno bt (?) [20, 30])" do
|
453
|
+
departments = Department.find(:all, :conditions => ['deptno bt (?)', [20, 30]])
|
454
|
+
departments.should_not be_empty
|
455
|
+
data_list = department_data.select {|i| i[DEPT_DEPTNO] and 20 <= i[DEPT_DEPTNO] and i[DEPT_DEPTNO] <= 30 }
|
456
|
+
departments.length.should == data_list.length
|
457
|
+
|
458
|
+
data_list.each do |data|
|
459
|
+
department = departments.find {|i| i.id == data.id }
|
460
|
+
department.should_not be_nil
|
461
|
+
validate_department(data, department)
|
462
|
+
end
|
463
|
+
end
|
464
|
+
|
465
|
+
it "departments has any data (deptno bt (?, ?) [20, 30])" do
|
466
|
+
departments = Department.find(:all, :conditions => ['deptno bt (?, ?)', 20, 30])
|
467
|
+
departments.should_not be_empty
|
468
|
+
data_list = department_data.select {|i| i[DEPT_DEPTNO] and 20 <= i[DEPT_DEPTNO] and i[DEPT_DEPTNO] <= 30 }
|
469
|
+
departments.length.should == data_list.length
|
470
|
+
|
471
|
+
data_list.each do |data|
|
472
|
+
department = departments.find {|i| i.id == data.id }
|
473
|
+
department.should_not be_nil
|
474
|
+
validate_department(data, department)
|
475
|
+
end
|
476
|
+
end
|
477
|
+
|
478
|
+
after do
|
479
|
+
TokyoCabinetSpec.clean
|
480
|
+
end
|
481
|
+
end
|