linkage 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +3 -2
- data/Gemfile.lock +25 -17
- data/Guardfile +2 -3
- data/Rakefile +1 -1
- data/VERSION +1 -1
- data/lib/linkage/configuration.rb +55 -15
- data/lib/linkage/data.rb +171 -0
- data/lib/linkage/dataset.rb +16 -16
- data/lib/linkage/expectation.rb +6 -6
- data/lib/linkage/field.rb +5 -144
- data/lib/linkage/function.rb +108 -0
- data/lib/linkage/functions/trim.rb +22 -0
- data/lib/linkage/warnings.rb +5 -0
- data/lib/linkage.rb +3 -0
- data/linkage.gemspec +24 -4
- data/test/config.yml +5 -0
- data/test/helper.rb +27 -2
- data/test/integration/test_dual_linkage.rb +33 -0
- data/test/integration/test_self_linkage.rb +21 -0
- data/test/unit/functions/test_trim.rb +36 -0
- data/test/unit/test_configuration.rb +42 -6
- data/test/unit/test_data.rb +456 -0
- data/test/unit/test_dataset.rb +85 -22
- data/test/unit/test_expectation.rb +97 -1
- data/test/unit/test_field.rb +15 -411
- data/test/unit/test_function.rb +190 -0
- metadata +58 -39
- /data/test/unit/{test_single_threaded_runner.rb → runner/test_single_threaded.rb} +0 -0
@@ -0,0 +1,456 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class UnitTests::TestData < Test::Unit::TestCase
|
4
|
+
class DataSubclass < Linkage::Data
|
5
|
+
attr_reader :ruby_type, :dataset
|
6
|
+
def initialize(name, ruby_type, dataset = nil)
|
7
|
+
super(name)
|
8
|
+
@ruby_type = ruby_type
|
9
|
+
@dataset = dataset
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def new_data(name, ruby_type, dataset = nil, klass = DataSubclass)
|
14
|
+
klass.new(name, ruby_type, dataset)
|
15
|
+
end
|
16
|
+
|
17
|
+
test "ruby_type raises NotImplementedError" do
|
18
|
+
d = Linkage::Data.new(:foo)
|
19
|
+
assert_raises(NotImplementedError) { d.ruby_type }
|
20
|
+
end
|
21
|
+
|
22
|
+
test "dataset raises NotImplementedError" do
|
23
|
+
d = Linkage::Data.new(:foo)
|
24
|
+
assert_raises(NotImplementedError) { d.dataset }
|
25
|
+
end
|
26
|
+
|
27
|
+
test "to_expr raises NotImplementedError" do
|
28
|
+
d = Linkage::Data.new(:foo)
|
29
|
+
assert_raises(NotImplementedError) { d.to_expr }
|
30
|
+
end
|
31
|
+
|
32
|
+
test "merge two identical fields" do
|
33
|
+
data_1 = new_data(:id, {:type =>Integer})
|
34
|
+
data_2 = new_data(:id, {:type =>Integer})
|
35
|
+
expected_type = {:type => Integer}
|
36
|
+
|
37
|
+
result_data = data_1.merge(data_2)
|
38
|
+
assert_equal(:id, result_data.name)
|
39
|
+
assert_equal(expected_type, result_data.ruby_type)
|
40
|
+
|
41
|
+
result_data = data_2.merge(data_1)
|
42
|
+
assert_equal(:id, result_data.name)
|
43
|
+
assert_equal(expected_type, result_data.ruby_type)
|
44
|
+
end
|
45
|
+
|
46
|
+
test "merge fields with different names" do
|
47
|
+
data_1 = new_data(:foo, {:type => Integer})
|
48
|
+
data_2 = new_data(:bar, {:type => Integer})
|
49
|
+
|
50
|
+
result_data = data_1.merge(data_2)
|
51
|
+
assert_equal(:foo_bar, result_data.name)
|
52
|
+
result_data = data_2.merge(data_1)
|
53
|
+
assert_equal(:bar_foo, result_data.name)
|
54
|
+
end
|
55
|
+
|
56
|
+
test "merge two boolean fields" do
|
57
|
+
data_1 = new_data(:foo, {:type => TrueClass})
|
58
|
+
data_2 = new_data(:foo, {:type => TrueClass})
|
59
|
+
expected_type = {:type => TrueClass}
|
60
|
+
|
61
|
+
result_data = data_1.merge(data_2)
|
62
|
+
assert_equal(:foo, result_data.name)
|
63
|
+
assert_equal(expected_type, result_data.ruby_type)
|
64
|
+
|
65
|
+
result_data = data_2.merge(data_1)
|
66
|
+
assert_equal(:foo, result_data.name)
|
67
|
+
assert_equal(expected_type, result_data.ruby_type)
|
68
|
+
end
|
69
|
+
|
70
|
+
test "merge a boolean field and an integer field" do
|
71
|
+
data_1 = new_data(:foo, {:type => Integer})
|
72
|
+
data_2 = new_data(:foo, {:type => TrueClass})
|
73
|
+
expected_type = {:type => Integer}
|
74
|
+
assert_equal(expected_type, data_1.merge(data_2).ruby_type)
|
75
|
+
assert_equal(expected_type, data_2.merge(data_1).ruby_type)
|
76
|
+
end
|
77
|
+
|
78
|
+
test "merge a boolean field and a bignum field" do
|
79
|
+
data_1 = new_data(:foo, {:type => Bignum})
|
80
|
+
data_2 = new_data(:foo, {:type => TrueClass})
|
81
|
+
expected_type = {:type => Bignum}
|
82
|
+
assert_equal(expected_type, data_1.merge(data_2).ruby_type)
|
83
|
+
assert_equal(expected_type, data_2.merge(data_1).ruby_type)
|
84
|
+
end
|
85
|
+
|
86
|
+
test "merge a boolean field and a float field" do
|
87
|
+
data_1 = new_data(:foo, {:type => Float})
|
88
|
+
data_2 = new_data(:foo, {:type => TrueClass})
|
89
|
+
expected_type = {:type => Float}
|
90
|
+
assert_equal(expected_type, data_1.merge(data_2).ruby_type)
|
91
|
+
assert_equal(expected_type, data_2.merge(data_1).ruby_type)
|
92
|
+
end
|
93
|
+
|
94
|
+
test "merge a boolean field and a decimal field" do
|
95
|
+
data_1 = new_data(:foo, {:type => BigDecimal})
|
96
|
+
data_2 = new_data(:foo, {:type => TrueClass})
|
97
|
+
expected_type = {:type => BigDecimal}
|
98
|
+
assert_equal(expected_type, data_1.merge(data_2).ruby_type)
|
99
|
+
assert_equal(expected_type, data_2.merge(data_1).ruby_type)
|
100
|
+
end
|
101
|
+
|
102
|
+
test "merge a boolean field and a decimal field with size" do
|
103
|
+
data_1 = new_data(:foo, {:type => BigDecimal, :opts => {:size => [10, 2]}})
|
104
|
+
data_2 = new_data(:foo, {:type => TrueClass})
|
105
|
+
expected_type = {:type => BigDecimal, :opts => {:size => [10, 2]}}
|
106
|
+
assert_equal(expected_type, data_1.merge(data_2).ruby_type)
|
107
|
+
assert_equal(expected_type, data_2.merge(data_1).ruby_type)
|
108
|
+
end
|
109
|
+
|
110
|
+
test "merge a boolean field and a string field" do
|
111
|
+
data_1 = new_data(:foo, {:type => String, :opts => {:size => 10}})
|
112
|
+
data_2 = new_data(:foo, {:type => TrueClass})
|
113
|
+
expected_type = {:type => String, :opts => {:size => 10}}
|
114
|
+
assert_equal(expected_type, data_1.merge(data_2).ruby_type)
|
115
|
+
assert_equal(expected_type, data_2.merge(data_1).ruby_type)
|
116
|
+
end
|
117
|
+
|
118
|
+
test "merge a boolean field and a text field" do
|
119
|
+
data_1 = new_data(:foo, {:type => String, :opts => {:text => true}})
|
120
|
+
data_2 = new_data(:foo, {:type => TrueClass})
|
121
|
+
expected_type = {:type => String, :opts => {:text => true}}
|
122
|
+
assert_equal(expected_type, data_1.merge(data_2).ruby_type)
|
123
|
+
assert_equal(expected_type, data_2.merge(data_1).ruby_type)
|
124
|
+
end
|
125
|
+
|
126
|
+
test "merge a boolean field and a fixed string field" do
|
127
|
+
data_1 = new_data(:foo, {:type => String, :opts => {:size => 10, :fixed => true}})
|
128
|
+
data_2 = new_data(:foo, {:type => TrueClass})
|
129
|
+
expected_type = {:type => String, :opts => {:size => 10, :fixed => true}}
|
130
|
+
assert_equal(expected_type, data_1.merge(data_2).ruby_type)
|
131
|
+
assert_equal(expected_type, data_2.merge(data_1).ruby_type)
|
132
|
+
end
|
133
|
+
|
134
|
+
test "merge two integer fields" do
|
135
|
+
data_1 = new_data(:foo, {:type => Integer})
|
136
|
+
data_2 = new_data(:foo, {:type => Integer})
|
137
|
+
expected_type = {:type => Integer}
|
138
|
+
assert_equal(expected_type, data_1.merge(data_2).ruby_type)
|
139
|
+
assert_equal(expected_type, data_2.merge(data_1).ruby_type)
|
140
|
+
end
|
141
|
+
|
142
|
+
test "merge an integer field and a bignum field" do
|
143
|
+
data_1 = new_data(:foo, {:type => Bignum})
|
144
|
+
data_2 = new_data(:foo, {:type => Integer})
|
145
|
+
expected_type = {:type => Bignum}
|
146
|
+
assert_equal(expected_type, data_1.merge(data_2).ruby_type)
|
147
|
+
assert_equal(expected_type, data_2.merge(data_1).ruby_type)
|
148
|
+
end
|
149
|
+
|
150
|
+
test "merge an integer field and a float field" do
|
151
|
+
data_1 = new_data(:foo, {:type => Float})
|
152
|
+
data_2 = new_data(:foo, {:type => Integer})
|
153
|
+
expected_type = {:type => Float}
|
154
|
+
assert_equal(expected_type, data_1.merge(data_2).ruby_type)
|
155
|
+
assert_equal(expected_type, data_2.merge(data_1).ruby_type)
|
156
|
+
end
|
157
|
+
|
158
|
+
test "merge an integer field and a decimal field" do
|
159
|
+
data_1 = new_data(:foo, {:type => BigDecimal})
|
160
|
+
data_2 = new_data(:foo, {:type => Integer})
|
161
|
+
expected_type = {:type => BigDecimal}
|
162
|
+
assert_equal(expected_type, data_1.merge(data_2).ruby_type)
|
163
|
+
assert_equal(expected_type, data_2.merge(data_1).ruby_type)
|
164
|
+
end
|
165
|
+
|
166
|
+
test "merge an integer field and a decimal field with size" do
|
167
|
+
data_1 = new_data(:foo, {:type => BigDecimal, :opts => {:size => [10, 2]}})
|
168
|
+
data_2 = new_data(:foo, {:type => Integer})
|
169
|
+
expected_type = {:type => BigDecimal, :opts => {:size => [10, 2]}}
|
170
|
+
assert_equal(expected_type, data_1.merge(data_2).ruby_type)
|
171
|
+
assert_equal(expected_type, data_2.merge(data_1).ruby_type)
|
172
|
+
end
|
173
|
+
|
174
|
+
test "merge an integer field and a string field" do
|
175
|
+
data_1 = new_data(:foo, {:type => String, :opts => {:size => 10}})
|
176
|
+
data_2 = new_data(:foo, {:type => Integer})
|
177
|
+
expected_type = {:type => String, :opts => {:size => 10}}
|
178
|
+
assert_equal(expected_type, data_1.merge(data_2).ruby_type)
|
179
|
+
assert_equal(expected_type, data_2.merge(data_1).ruby_type)
|
180
|
+
end
|
181
|
+
|
182
|
+
test "merge an integer field and a text field" do
|
183
|
+
data_1 = new_data(:foo, {:type => String, :opts => {:text => true}})
|
184
|
+
data_2 = new_data(:foo, {:type => Integer})
|
185
|
+
expected_type = {:type => String, :opts => {:text => true}}
|
186
|
+
assert_equal(expected_type, data_1.merge(data_2).ruby_type)
|
187
|
+
assert_equal(expected_type, data_2.merge(data_1).ruby_type)
|
188
|
+
end
|
189
|
+
|
190
|
+
test "merge an integer field and a fixed string field" do
|
191
|
+
data_1 = new_data(:foo, {:type => String, :opts => {:size => 10, :fixed => true}})
|
192
|
+
data_2 = new_data(:foo, {:type => Integer})
|
193
|
+
expected_type = {:type => String, :opts => {:size => 10, :fixed => true}}
|
194
|
+
assert_equal(expected_type, data_1.merge(data_2).ruby_type)
|
195
|
+
assert_equal(expected_type, data_2.merge(data_1).ruby_type)
|
196
|
+
end
|
197
|
+
|
198
|
+
test "merge two bignum fields" do
|
199
|
+
data_1 = new_data(:foo, {:type => Bignum})
|
200
|
+
data_2 = new_data(:foo, {:type => Bignum})
|
201
|
+
expected_type = {:type => Bignum}
|
202
|
+
assert_equal(expected_type, data_1.merge(data_2).ruby_type)
|
203
|
+
assert_equal(expected_type, data_2.merge(data_1).ruby_type)
|
204
|
+
end
|
205
|
+
|
206
|
+
test "merge an bignum field and a decimal field" do
|
207
|
+
data_1 = new_data(:foo, {:type => BigDecimal})
|
208
|
+
data_2 = new_data(:foo, {:type => Bignum})
|
209
|
+
expected_type = {:type => BigDecimal}
|
210
|
+
assert_equal(expected_type, data_1.merge(data_2).ruby_type)
|
211
|
+
assert_equal(expected_type, data_2.merge(data_1).ruby_type)
|
212
|
+
end
|
213
|
+
|
214
|
+
test "merge an bignum field and a decimal field with size" do
|
215
|
+
data_1 = new_data(:foo, {:type => BigDecimal, :opts => {:size => [10, 2]}})
|
216
|
+
data_2 = new_data(:foo, {:type => Bignum})
|
217
|
+
expected_type = {:type => BigDecimal, :opts => {:size => [10, 2]}}
|
218
|
+
assert_equal(expected_type, data_1.merge(data_2).ruby_type)
|
219
|
+
assert_equal(expected_type, data_2.merge(data_1).ruby_type)
|
220
|
+
end
|
221
|
+
|
222
|
+
test "merge an bignum field and a string field" do
|
223
|
+
data_1 = new_data(:foo, {:type => String, :opts => {:size => 10}})
|
224
|
+
data_2 = new_data(:foo, {:type => Bignum})
|
225
|
+
expected_type = {:type => String, :opts => {:size => 10}}
|
226
|
+
assert_equal(expected_type, data_1.merge(data_2).ruby_type)
|
227
|
+
assert_equal(expected_type, data_2.merge(data_1).ruby_type)
|
228
|
+
end
|
229
|
+
|
230
|
+
test "merge an bignum field and a text field" do
|
231
|
+
data_1 = new_data(:foo, {:type => String, :opts => {:text => true}})
|
232
|
+
data_2 = new_data(:foo, {:type => Bignum})
|
233
|
+
expected_type = {:type => String, :opts => {:text => true}}
|
234
|
+
assert_equal(expected_type, data_1.merge(data_2).ruby_type)
|
235
|
+
assert_equal(expected_type, data_2.merge(data_1).ruby_type)
|
236
|
+
end
|
237
|
+
|
238
|
+
test "merge an bignum field and a fixed string field" do
|
239
|
+
data_1 = new_data(:foo, {:type => String, :opts => {:size => 10, :fixed => true}})
|
240
|
+
data_2 = new_data(:foo, {:type => Bignum})
|
241
|
+
expected_type = {:type => String, :opts => {:size => 10, :fixed => true}}
|
242
|
+
assert_equal(expected_type, data_1.merge(data_2).ruby_type)
|
243
|
+
assert_equal(expected_type, data_2.merge(data_1).ruby_type)
|
244
|
+
end
|
245
|
+
|
246
|
+
test "merge two float fields" do
|
247
|
+
data_1 = new_data(:foo, {:type => Float})
|
248
|
+
data_2 = new_data(:foo, {:type => Float})
|
249
|
+
expected_type = {:type => Float}
|
250
|
+
assert_equal(expected_type, data_1.merge(data_2).ruby_type)
|
251
|
+
assert_equal(expected_type, data_2.merge(data_1).ruby_type)
|
252
|
+
end
|
253
|
+
|
254
|
+
test "merge a float field and a bignum field" do
|
255
|
+
data_1 = new_data(:foo, {:type => Bignum})
|
256
|
+
data_2 = new_data(:foo, {:type => Float})
|
257
|
+
expected_type = {:type => BigDecimal}
|
258
|
+
assert_equal(expected_type, data_1.merge(data_2).ruby_type)
|
259
|
+
assert_equal(expected_type, data_2.merge(data_1).ruby_type)
|
260
|
+
end
|
261
|
+
|
262
|
+
test "merge a float field and a decimal field" do
|
263
|
+
data_1 = new_data(:foo, {:type => BigDecimal})
|
264
|
+
data_2 = new_data(:foo, {:type => Float})
|
265
|
+
expected_type = {:type => BigDecimal}
|
266
|
+
assert_equal(expected_type, data_1.merge(data_2).ruby_type)
|
267
|
+
assert_equal(expected_type, data_2.merge(data_1).ruby_type)
|
268
|
+
end
|
269
|
+
|
270
|
+
test "merge a float field and a decimal field with size" do
|
271
|
+
data_1 = new_data(:foo, {:type => BigDecimal, :opts => {:size => [10, 2]}})
|
272
|
+
data_2 = new_data(:foo, {:type => Float})
|
273
|
+
expected_type = {:type => BigDecimal, :opts => {:size => [10, 2]}}
|
274
|
+
assert_equal(expected_type, data_1.merge(data_2).ruby_type)
|
275
|
+
assert_equal(expected_type, data_2.merge(data_1).ruby_type)
|
276
|
+
end
|
277
|
+
|
278
|
+
test "merge a float field and a string field" do
|
279
|
+
data_1 = new_data(:foo, {:type => String, :opts => {:size => 10}})
|
280
|
+
data_2 = new_data(:foo, {:type => Float})
|
281
|
+
expected_type = {:type => String, :opts => {:size => 10}}
|
282
|
+
assert_equal(expected_type, data_1.merge(data_2).ruby_type)
|
283
|
+
assert_equal(expected_type, data_2.merge(data_1).ruby_type)
|
284
|
+
end
|
285
|
+
|
286
|
+
test "merge a float field and a text field" do
|
287
|
+
data_1 = new_data(:foo, {:type => String, :opts => {:text => true}})
|
288
|
+
data_2 = new_data(:foo, {:type => Float})
|
289
|
+
expected_type = {:type => String, :opts => {:text => true}}
|
290
|
+
assert_equal(expected_type, data_1.merge(data_2).ruby_type)
|
291
|
+
assert_equal(expected_type, data_2.merge(data_1).ruby_type)
|
292
|
+
end
|
293
|
+
|
294
|
+
test "merge a float field and a fixed string field" do
|
295
|
+
data_1 = new_data(:foo, {:type => String, :opts => {:size => 10, :fixed => true}})
|
296
|
+
data_2 = new_data(:foo, {:type => Float})
|
297
|
+
expected_type = {:type => String, :opts => {:size => 10, :fixed => true}}
|
298
|
+
assert_equal(expected_type, data_1.merge(data_2).ruby_type)
|
299
|
+
assert_equal(expected_type, data_2.merge(data_1).ruby_type)
|
300
|
+
end
|
301
|
+
|
302
|
+
test "merge two decimal fields" do
|
303
|
+
data_1 = new_data(:foo, {:type => BigDecimal})
|
304
|
+
data_2 = new_data(:foo, {:type => BigDecimal})
|
305
|
+
expected_type = {:type => BigDecimal}
|
306
|
+
assert_equal(expected_type, data_1.merge(data_2).ruby_type)
|
307
|
+
assert_equal(expected_type, data_2.merge(data_1).ruby_type)
|
308
|
+
end
|
309
|
+
|
310
|
+
test "merge two decimal fields, one with size" do
|
311
|
+
data_1 = new_data(:foo, {:type => BigDecimal, :opts => {:size => [10, 2]}})
|
312
|
+
data_2 = new_data(:foo, {:type => BigDecimal})
|
313
|
+
expected_type = {:type => BigDecimal, :opts => {:size => [10, 2]}}
|
314
|
+
assert_equal(expected_type, data_1.merge(data_2).ruby_type)
|
315
|
+
assert_equal(expected_type, data_2.merge(data_1).ruby_type)
|
316
|
+
end
|
317
|
+
|
318
|
+
test "merge two decimal fields, both with size" do
|
319
|
+
data_1 = new_data(:foo, {:type => BigDecimal, :opts => {:size => [10, 2]}})
|
320
|
+
data_2 = new_data(:foo, {:type => BigDecimal, :opts => {:size => [12, 1]}})
|
321
|
+
expected_type = {:type => BigDecimal, :opts => {:size => [12, 2]}}
|
322
|
+
assert_equal(expected_type, data_1.merge(data_2).ruby_type)
|
323
|
+
assert_equal(expected_type, data_2.merge(data_1).ruby_type)
|
324
|
+
end
|
325
|
+
|
326
|
+
test "merge two decimal fields, both with size, one without scale" do
|
327
|
+
data_1 = new_data(:foo, {:type => BigDecimal, :opts => {:size => [10]}})
|
328
|
+
data_2 = new_data(:foo, {:type => BigDecimal, :opts => {:size => [12, 1]}})
|
329
|
+
expected_type = {:type => BigDecimal, :opts => {:size => [12, 1]}}
|
330
|
+
assert_equal(expected_type, data_1.merge(data_2).ruby_type)
|
331
|
+
assert_equal(expected_type, data_2.merge(data_1).ruby_type)
|
332
|
+
end
|
333
|
+
|
334
|
+
test "merge a decimal field and a string field" do
|
335
|
+
data_1 = new_data(:foo, {:type => String, :opts => {:size => 10}})
|
336
|
+
data_2 = new_data(:foo, {:type => BigDecimal})
|
337
|
+
expected_type = {:type => String, :opts => {:size => 10}}
|
338
|
+
assert_equal(expected_type, data_1.merge(data_2).ruby_type)
|
339
|
+
assert_equal(expected_type, data_2.merge(data_1).ruby_type)
|
340
|
+
end
|
341
|
+
|
342
|
+
test "merge a decimal field with size and a string field" do
|
343
|
+
data_1 = new_data(:foo, {:type => String, :opts => {:size => 10}})
|
344
|
+
data_2 = new_data(:foo, {:type => BigDecimal, :opts => {:size => [12, 2]}})
|
345
|
+
expected_type = {:type => String, :opts => {:size => 13}}
|
346
|
+
assert_equal(expected_type, data_1.merge(data_2).ruby_type)
|
347
|
+
assert_equal(expected_type, data_2.merge(data_1).ruby_type)
|
348
|
+
end
|
349
|
+
|
350
|
+
test "merge a decimal field and a text field" do
|
351
|
+
data_1 = new_data(:foo, {:type => String, :opts => {:text => true}})
|
352
|
+
data_2 = new_data(:foo, {:type => BigDecimal})
|
353
|
+
expected_type = {:type => String, :opts => {:text => true}}
|
354
|
+
assert_equal(expected_type, data_1.merge(data_2).ruby_type)
|
355
|
+
assert_equal(expected_type, data_2.merge(data_1).ruby_type)
|
356
|
+
end
|
357
|
+
|
358
|
+
test "merge a decimal field with size and a text field" do
|
359
|
+
data_1 = new_data(:foo, {:type => String, :opts => {:text => true}})
|
360
|
+
data_2 = new_data(:foo, {:type => BigDecimal, :opts => {:size => [12, 2]}})
|
361
|
+
expected_type = {:type => String, :opts => {:text => true}}
|
362
|
+
assert_equal(expected_type, data_1.merge(data_2).ruby_type)
|
363
|
+
assert_equal(expected_type, data_2.merge(data_1).ruby_type)
|
364
|
+
end
|
365
|
+
|
366
|
+
test "merge a decimal field and a fixed string field" do
|
367
|
+
data_1 = new_data(:foo, {:type => String, :opts => {:size => 10, :fixed => true}})
|
368
|
+
data_2 = new_data(:foo, {:type => BigDecimal})
|
369
|
+
expected_type = {:type => String, :opts => {:size => 10, :fixed => true}}
|
370
|
+
assert_equal(expected_type, data_1.merge(data_2).ruby_type)
|
371
|
+
assert_equal(expected_type, data_2.merge(data_1).ruby_type)
|
372
|
+
end
|
373
|
+
|
374
|
+
test "merge two string fields" do
|
375
|
+
data_1 = new_data(:foo, {:type => String, :opts => {:size => 20}})
|
376
|
+
data_2 = new_data(:foo, {:type => String, :opts => {:size => 20}})
|
377
|
+
expected_type = {:type => String, :opts => {:size => 20}}
|
378
|
+
assert_equal(expected_type, data_1.merge(data_2).ruby_type)
|
379
|
+
assert_equal(expected_type, data_2.merge(data_1).ruby_type)
|
380
|
+
end
|
381
|
+
|
382
|
+
test "merge two string fields with different sizes" do
|
383
|
+
data_1 = new_data(:foo, {:type => String, :opts => {:size => 15}})
|
384
|
+
data_2 = new_data(:foo, {:type => String, :opts => {:size => 20}})
|
385
|
+
expected_type = {:type => String, :opts => {:size => 20}}
|
386
|
+
assert_equal(expected_type, data_1.merge(data_2).ruby_type)
|
387
|
+
assert_equal(expected_type, data_2.merge(data_1).ruby_type)
|
388
|
+
end
|
389
|
+
|
390
|
+
test "merge two fields and specify name" do
|
391
|
+
data_1 = new_data(:id, {:type => Integer})
|
392
|
+
data_2 = new_data(:id, {:type => Integer})
|
393
|
+
|
394
|
+
result_data = data_1.merge(data_2, 'foo')
|
395
|
+
assert_equal :foo, result_data.name
|
396
|
+
|
397
|
+
result_data = data_2.merge(data_1, 'foo')
|
398
|
+
assert_equal :foo, result_data.name
|
399
|
+
end
|
400
|
+
|
401
|
+
test "== returns true when data have the same name and are from the same dataset" do
|
402
|
+
dataset_1 = stub('dataset')
|
403
|
+
data_1 = new_data(:foo, {:type => Integer}, dataset_1)
|
404
|
+
dataset_2 = stub('dataset clone')
|
405
|
+
data_2 = new_data(:foo, {:type => Integer}, dataset_2)
|
406
|
+
|
407
|
+
dataset_1.expects(:==).with(dataset_2).returns(true)
|
408
|
+
assert_equal data_1, data_2
|
409
|
+
end
|
410
|
+
|
411
|
+
test "== returns false when data have different classes" do
|
412
|
+
dataset_1 = stub('dataset')
|
413
|
+
data_1 = new_data(:foo, {:type => Integer}, dataset_1, DataSubclass)
|
414
|
+
dataset_2 = stub('dataset clone')
|
415
|
+
data_2 = new_data(:foo, {:type => Integer}, dataset_2, DataSubclass.clone)
|
416
|
+
assert_not_equal data_1, data_2
|
417
|
+
end
|
418
|
+
|
419
|
+
test "== returns false when data have the same name but are from different datasets" do
|
420
|
+
dataset_1 = stub('dataset')
|
421
|
+
data_1 = new_data(:foo, {:type => Integer}, dataset_1)
|
422
|
+
dataset_2 = stub('dataset clone')
|
423
|
+
data_2 = new_data(:foo, {:type => Integer}, dataset_2)
|
424
|
+
|
425
|
+
dataset_1.expects(:==).with(dataset_2).returns(false)
|
426
|
+
assert_not_equal data_1, data_2
|
427
|
+
end
|
428
|
+
|
429
|
+
test "== returns true for identical static functions" do
|
430
|
+
klass = new_function('foo', {:type => String})
|
431
|
+
func_1 = klass.new(123)
|
432
|
+
func_2 = klass.new(123)
|
433
|
+
|
434
|
+
assert_equal func_1, func_2
|
435
|
+
end
|
436
|
+
|
437
|
+
test "belongs_to? dataset" do
|
438
|
+
dataset = stub('dataset 1', :id => 1)
|
439
|
+
data = new_data(:foo, {:type => Integer}, dataset)
|
440
|
+
assert data.belongs_to?(dataset)
|
441
|
+
end
|
442
|
+
|
443
|
+
test "belongs_to? dataset with same id" do
|
444
|
+
dataset_1 = stub('dataset 1', :id => 1)
|
445
|
+
dataset_2 = stub('dataset 2', :id => 1)
|
446
|
+
data = new_data(:foo, {:type => Integer}, dataset_1)
|
447
|
+
assert data.belongs_to?(dataset_2)
|
448
|
+
end
|
449
|
+
|
450
|
+
test "belongs_to? dataset with different id" do
|
451
|
+
dataset_1 = stub('dataset 1', :id => 1)
|
452
|
+
dataset_2 = stub('dataset 2', :id => 2)
|
453
|
+
data = new_data(:foo, {:type => Integer}, dataset_1)
|
454
|
+
assert !data.belongs_to?(dataset_2)
|
455
|
+
end
|
456
|
+
end
|
data/test/unit/test_dataset.rb
CHANGED
@@ -15,9 +15,9 @@ class UnitTests::TestDataset < Test::Unit::TestCase
|
|
15
15
|
|
16
16
|
@id_field = stub("id field", :dataset= => nil, :name => :id)
|
17
17
|
Linkage::Field.stubs(:new).with(:id, kind_of(Hash)).returns(@id_field)
|
18
|
-
@first_name_field = stub("first_name field", :dataset= => nil, :name => :first_name)
|
18
|
+
@first_name_field = stub("first_name field", :dataset= => nil, :name => :first_name, :to_expr => :first_name)
|
19
19
|
Linkage::Field.stubs(:new).with(:first_name, kind_of(Hash)).returns(@first_name_field)
|
20
|
-
@last_name_field = stub("last_name field", :dataset= => nil, :name => :last_name)
|
20
|
+
@last_name_field = stub("last_name field", :dataset= => nil, :name => :last_name, :to_expr => :last_name)
|
21
21
|
Linkage::Field.stubs(:new).with(:last_name, kind_of(Hash)).returns(@last_name_field)
|
22
22
|
end
|
23
23
|
|
@@ -107,8 +107,8 @@ class UnitTests::TestDataset < Test::Unit::TestCase
|
|
107
107
|
assert_empty dataset_2.instance_variable_get(:@filter)
|
108
108
|
end
|
109
109
|
|
110
|
-
test "add_order, then each" do
|
111
|
-
field =
|
110
|
+
test "add_order with field, then each" do
|
111
|
+
field = stub_field('field', :name => :last_name, :to_expr => :last_name)
|
112
112
|
ds = Linkage::Dataset.new("foo:/bar", "baz")
|
113
113
|
ds.add_order(field)
|
114
114
|
@dataset.expects(:order).with(:last_name).returns(@dataset)
|
@@ -123,8 +123,25 @@ class UnitTests::TestDataset < Test::Unit::TestCase
|
|
123
123
|
assert ran
|
124
124
|
end
|
125
125
|
|
126
|
+
test "add_order with function, then each" do
|
127
|
+
expr = stub('expression')
|
128
|
+
func = stub_function('func', :name => :trim_stuff, :to_expr => expr)
|
129
|
+
ds = Linkage::Dataset.new("foo:/bar", "baz")
|
130
|
+
ds.add_order(func)
|
131
|
+
@dataset.expects(:order).with(expr).returns(@dataset)
|
132
|
+
row = {:id => 123, :trim_stuff => 'foo'}
|
133
|
+
@dataset.expects(:each).yields(row)
|
134
|
+
|
135
|
+
ran = false
|
136
|
+
ds.each do |yielded_row|
|
137
|
+
ran = true
|
138
|
+
assert_equal({:pk => 123, :values => {:trim_stuff => 'foo'}}, yielded_row)
|
139
|
+
end
|
140
|
+
assert ran
|
141
|
+
end
|
142
|
+
|
126
143
|
test "add_order descending, then each" do
|
127
|
-
field =
|
144
|
+
field = stub_field('field', :name => :last_name, :to_expr => :last_name)
|
128
145
|
ds = Linkage::Dataset.new("foo:/bar", "baz")
|
129
146
|
ds.add_order(field, :desc)
|
130
147
|
@dataset.expects(:order).with(:last_name.desc).returns(@dataset)
|
@@ -139,8 +156,8 @@ class UnitTests::TestDataset < Test::Unit::TestCase
|
|
139
156
|
assert ran
|
140
157
|
end
|
141
158
|
|
142
|
-
test "add_order weeds out duplicates" do
|
143
|
-
field =
|
159
|
+
test "add_order weeds out field duplicates" do
|
160
|
+
field = stub_field('field', :name => :last_name, :to_expr => :last_name)
|
144
161
|
ds = Linkage::Dataset.new("foo:/bar", "baz")
|
145
162
|
ds.add_order(field)
|
146
163
|
ds.add_order(field)
|
@@ -149,8 +166,19 @@ class UnitTests::TestDataset < Test::Unit::TestCase
|
|
149
166
|
ds.each { }
|
150
167
|
end
|
151
168
|
|
152
|
-
test "
|
153
|
-
|
169
|
+
test "add_order weeds out function duplicates" do
|
170
|
+
expr = stub('expression')
|
171
|
+
func = stub_function('func', :name => :trim_stuff, :to_expr => expr)
|
172
|
+
ds = Linkage::Dataset.new("foo:/bar", "baz")
|
173
|
+
ds.add_order(func)
|
174
|
+
ds.add_order(func)
|
175
|
+
@dataset.expects(:order).with(expr).returns(@dataset)
|
176
|
+
@dataset.expects(:each)
|
177
|
+
ds.each { }
|
178
|
+
end
|
179
|
+
|
180
|
+
test "add_select with field, then each" do
|
181
|
+
field = stub_field('field', :name => :last_name, :to_expr => :last_name)
|
154
182
|
ds = Linkage::Dataset.new("foo:/bar", "baz")
|
155
183
|
ds.add_select(field)
|
156
184
|
@dataset.expects(:select).with(:id, :last_name).returns(@dataset)
|
@@ -166,7 +194,7 @@ class UnitTests::TestDataset < Test::Unit::TestCase
|
|
166
194
|
end
|
167
195
|
|
168
196
|
test "add_select with an alias, then each" do
|
169
|
-
field =
|
197
|
+
field = stub_field('field', :name => :last_name, :to_expr => :last_name)
|
170
198
|
ds = Linkage::Dataset.new("foo:/bar", "baz")
|
171
199
|
ds.add_select(field, :junk)
|
172
200
|
@dataset.expects(:select).with(:id, :last_name.as(:junk)).returns(@dataset)
|
@@ -181,8 +209,25 @@ class UnitTests::TestDataset < Test::Unit::TestCase
|
|
181
209
|
assert ran
|
182
210
|
end
|
183
211
|
|
212
|
+
test "add_select with function, then each" do
|
213
|
+
expr = stub('expression')
|
214
|
+
func = stub_function('func', :name => :trim_stuff, :to_expr => expr)
|
215
|
+
ds = Linkage::Dataset.new("foo:/bar", "baz")
|
216
|
+
ds.add_select(func)
|
217
|
+
@dataset.expects(:select).with(:id, expr).returns(@dataset)
|
218
|
+
row = {:id => 123, :trim_stuff => 'foo'}
|
219
|
+
@dataset.expects(:each).yields(row)
|
220
|
+
|
221
|
+
ran = false
|
222
|
+
ds.each do |yielded_row|
|
223
|
+
ran = true
|
224
|
+
assert_equal({:pk => 123, :values => {:trim_stuff => 'foo'}}, yielded_row)
|
225
|
+
end
|
226
|
+
assert ran
|
227
|
+
end
|
228
|
+
|
184
229
|
test "add_select weeds out duplicates" do
|
185
|
-
field =
|
230
|
+
field = stub_field('field', :name => :last_name, :to_expr => :last_name)
|
186
231
|
ds = Linkage::Dataset.new("foo:/bar", "baz")
|
187
232
|
ds.add_select(field)
|
188
233
|
ds.add_select(field)
|
@@ -191,8 +236,8 @@ class UnitTests::TestDataset < Test::Unit::TestCase
|
|
191
236
|
ds.each { }
|
192
237
|
end
|
193
238
|
|
194
|
-
test "add_filter with
|
195
|
-
field = stub('field', :name => :age)
|
239
|
+
test "add_filter with :== between field and static value, then each" do
|
240
|
+
field = stub('field', :name => :age, :to_expr => :age)
|
196
241
|
ds = Linkage::Dataset.new("foo:/bar", "baz")
|
197
242
|
ds.add_filter(field, :==, 30)
|
198
243
|
@dataset.expects(:filter).with(:age => 30).returns(@dataset)
|
@@ -207,9 +252,27 @@ class UnitTests::TestDataset < Test::Unit::TestCase
|
|
207
252
|
assert ran
|
208
253
|
end
|
209
254
|
|
255
|
+
test "add_filter with :== between field and static function, then each" do
|
256
|
+
field = stub_field('field', :name => :age, :to_expr => :age)
|
257
|
+
expr = stub('expression')
|
258
|
+
func = stub_function('func', :name => :func, :to_expr => expr)
|
259
|
+
ds = Linkage::Dataset.new("foo:/bar", "baz")
|
260
|
+
ds.add_filter(field, :==, func)
|
261
|
+
@dataset.expects(:filter).with(:age => expr).returns(@dataset)
|
262
|
+
row = {:id => 123, :junk => 'foo'}
|
263
|
+
@dataset.expects(:each).yields(row)
|
264
|
+
|
265
|
+
ran = false
|
266
|
+
ds.each do |yielded_row|
|
267
|
+
ran = true
|
268
|
+
assert_equal({:pk => 123, :values => {:junk => 'foo'}}, yielded_row)
|
269
|
+
end
|
270
|
+
assert ran
|
271
|
+
end
|
272
|
+
|
210
273
|
test "add_filter with :== between two fields, then each" do
|
211
|
-
field_1 = stub_field('field 1', :name => :foo)
|
212
|
-
field_2 = stub_field('field 2', :name => :bar)
|
274
|
+
field_1 = stub_field('field 1', :name => :foo, :to_expr => :foo)
|
275
|
+
field_2 = stub_field('field 2', :name => :bar, :to_expr => :bar)
|
213
276
|
ds = Linkage::Dataset.new("foo:/bar", "baz")
|
214
277
|
ds.add_filter(field_1, :==, field_2)
|
215
278
|
@dataset.expects(:filter).with(:foo => :bar).returns(@dataset)
|
@@ -218,7 +281,7 @@ class UnitTests::TestDataset < Test::Unit::TestCase
|
|
218
281
|
end
|
219
282
|
|
220
283
|
test "add_filter with :>, then each" do
|
221
|
-
field = stub('field', :name => :age)
|
284
|
+
field = stub('field', :name => :age, :to_expr => :age)
|
222
285
|
ds = Linkage::Dataset.new("foo:/bar", "baz")
|
223
286
|
ds.add_filter(field, :>, 30)
|
224
287
|
@dataset.expects(:filter).with(expr{age > 30}).returns(@dataset)
|
@@ -227,7 +290,7 @@ class UnitTests::TestDataset < Test::Unit::TestCase
|
|
227
290
|
end
|
228
291
|
|
229
292
|
test "add_filter with :<, then each" do
|
230
|
-
field =
|
293
|
+
field = stub_field('field', :name => :age, :to_expr => :age)
|
231
294
|
ds = Linkage::Dataset.new("foo:/bar", "baz")
|
232
295
|
ds.add_filter(field, :<, 30)
|
233
296
|
@dataset.expects(:filter).with(expr{age < 30}).returns(@dataset)
|
@@ -236,7 +299,7 @@ class UnitTests::TestDataset < Test::Unit::TestCase
|
|
236
299
|
end
|
237
300
|
|
238
301
|
test "add_filter with :>=, then each" do
|
239
|
-
field =
|
302
|
+
field = stub_field('field', :name => :age, :to_expr => :age)
|
240
303
|
ds = Linkage::Dataset.new("foo:/bar", "baz")
|
241
304
|
ds.add_filter(field, :>=, 30)
|
242
305
|
@dataset.expects(:filter).with(expr{age >= 30}).returns(@dataset)
|
@@ -245,7 +308,7 @@ class UnitTests::TestDataset < Test::Unit::TestCase
|
|
245
308
|
end
|
246
309
|
|
247
310
|
test "add_filter with :<=, then each" do
|
248
|
-
field = stub('field', :name => :age)
|
311
|
+
field = stub('field', :name => :age, :to_expr => :age)
|
249
312
|
ds = Linkage::Dataset.new("foo:/bar", "baz")
|
250
313
|
ds.add_filter(field, :<=, 30)
|
251
314
|
@dataset.expects(:filter).with(expr{age <= 30}).returns(@dataset)
|
@@ -254,7 +317,7 @@ class UnitTests::TestDataset < Test::Unit::TestCase
|
|
254
317
|
end
|
255
318
|
|
256
319
|
test "add_filter with :!=, then each" do
|
257
|
-
field =
|
320
|
+
field = stub_field('field', :name => :age, :to_expr => :age)
|
258
321
|
ds = Linkage::Dataset.new("foo:/bar", "baz")
|
259
322
|
ds.add_filter(field, :'!=', 30)
|
260
323
|
@dataset.expects(:filter).with(~{:age => 30}).returns(@dataset)
|
@@ -263,8 +326,8 @@ class UnitTests::TestDataset < Test::Unit::TestCase
|
|
263
326
|
end
|
264
327
|
|
265
328
|
test "add_filter with :> field, then each" do
|
266
|
-
field_1 = stub_field('field 1', :name => :age)
|
267
|
-
field_2 = stub_field('field 2', :name => :age_2)
|
329
|
+
field_1 = stub_field('field 1', :name => :age, :to_expr => :age)
|
330
|
+
field_2 = stub_field('field 2', :name => :age_2, :to_expr => :age_2)
|
268
331
|
ds = Linkage::Dataset.new("foo:/bar", "baz")
|
269
332
|
ds.add_filter(field_1, :>, field_2)
|
270
333
|
@dataset.expects(:filter).with(expr{age > age_2}).returns(@dataset)
|