linkage 0.0.6 → 0.0.8
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.
- data/.gitignore +10 -0
- data/Gemfile +15 -13
- data/Gemfile.lock +67 -37
- data/Guardfile +0 -2
- data/Rakefile +122 -25
- data/lib/linkage/comparator.rb +172 -0
- data/lib/linkage/comparators/binary.rb +12 -0
- data/lib/linkage/comparators/compare.rb +46 -0
- data/lib/linkage/comparators/within.rb +32 -0
- data/lib/linkage/configuration.rb +285 -153
- data/lib/linkage/data.rb +32 -7
- data/lib/linkage/dataset.rb +107 -32
- data/lib/linkage/decollation.rb +93 -0
- data/lib/linkage/expectation.rb +21 -0
- data/lib/linkage/expectations/exhaustive.rb +63 -0
- data/lib/linkage/expectations/simple.rb +168 -0
- data/lib/linkage/field.rb +30 -4
- data/lib/linkage/field_set.rb +6 -3
- data/lib/linkage/function.rb +50 -3
- data/lib/linkage/functions/binary.rb +30 -0
- data/lib/linkage/functions/cast.rb +54 -0
- data/lib/linkage/functions/length.rb +29 -0
- data/lib/linkage/functions/strftime.rb +12 -11
- data/lib/linkage/functions/trim.rb +8 -0
- data/lib/linkage/group.rb +20 -0
- data/lib/linkage/import_buffer.rb +5 -16
- data/lib/linkage/meta_object.rb +139 -0
- data/lib/linkage/result_set.rb +74 -17
- data/lib/linkage/runner/single_threaded.rb +125 -10
- data/lib/linkage/version.rb +3 -0
- data/lib/linkage.rb +11 -0
- data/linkage.gemspec +16 -121
- data/test/config.yml +5 -0
- data/test/helper.rb +73 -8
- data/test/integration/test_collation.rb +45 -0
- data/test/integration/test_configuration.rb +268 -0
- data/test/integration/test_cross_linkage.rb +4 -17
- data/test/integration/test_dataset.rb +45 -2
- data/test/integration/test_dual_linkage.rb +40 -24
- data/test/integration/test_functions.rb +22 -0
- data/test/integration/test_result_set.rb +85 -0
- data/test/integration/test_scoring.rb +84 -0
- data/test/integration/test_self_linkage.rb +5 -0
- data/test/integration/test_within_comparator.rb +100 -0
- data/test/unit/comparators/test_compare.rb +105 -0
- data/test/unit/comparators/test_within.rb +57 -0
- data/test/unit/expectations/test_exhaustive.rb +111 -0
- data/test/unit/expectations/test_simple.rb +303 -0
- data/test/unit/functions/test_binary.rb +54 -0
- data/test/unit/functions/test_cast.rb +98 -0
- data/test/unit/functions/test_length.rb +52 -0
- data/test/unit/functions/test_strftime.rb +17 -13
- data/test/unit/functions/test_trim.rb +11 -4
- data/test/unit/test_comparator.rb +124 -0
- data/test/unit/test_configuration.rb +137 -175
- data/test/unit/test_data.rb +44 -0
- data/test/unit/test_dataset.rb +73 -21
- data/test/unit/test_decollation.rb +201 -0
- data/test/unit/test_field.rb +38 -14
- data/test/unit/test_field_set.rb +12 -8
- data/test/unit/test_function.rb +83 -16
- data/test/unit/test_group.rb +28 -0
- data/test/unit/test_import_buffer.rb +13 -27
- data/test/unit/test_meta_object.rb +208 -0
- data/test/unit/test_result_set.rb +221 -3
- metadata +82 -190
@@ -0,0 +1,201 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'helper'
|
3
|
+
|
4
|
+
class UnitTests::TestDecollation < Test::Unit::TestCase
|
5
|
+
include Linkage::Decollation
|
6
|
+
|
7
|
+
test "mysql's latin1_swedish_ci handles 'A' letters" do
|
8
|
+
# MySQL 6.0.4 collation (http://www.collation-charts.org/mysql60/mysql604.latin1_swedish_ci.html)
|
9
|
+
["A", "a", "À", "Á", "Â", "Ã", "à", "á", "â", "ã"].each do |chr|
|
10
|
+
assert_equal "A", decollate(chr, :mysql, "latin1_swedish_ci")
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
test "mysql's latin1_swedish_ci handles 'B' letters" do
|
15
|
+
["B", "b"].each do |chr|
|
16
|
+
assert_equal "B", decollate(chr, :mysql, "latin1_swedish_ci")
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
test "mysql's latin1_swedish_ci handles 'C' letters" do
|
21
|
+
["C", "c", "Ç", "ç"].each do |chr|
|
22
|
+
assert_equal "C", decollate(chr, :mysql, "latin1_swedish_ci")
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
test "mysql's latin1_swedish_ci handles 'D' letters" do
|
27
|
+
["D", "d", "Ð", "ð"].each do |chr|
|
28
|
+
assert_equal "D", decollate(chr, :mysql, "latin1_swedish_ci")
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
test "mysql's latin1_swedish_ci handles 'E' letters" do
|
33
|
+
["E", "e", "È", "É", "Ê", "Ë", "è", "é", "ê", "ë"].each do |chr|
|
34
|
+
assert_equal "E", decollate(chr, :mysql, "latin1_swedish_ci")
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
test "mysql's latin1_swedish_ci handles 'F' letters" do
|
39
|
+
["F", "f"].each do |chr|
|
40
|
+
assert_equal "F", decollate(chr, :mysql, "latin1_swedish_ci")
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
test "mysql's latin1_swedish_ci handles 'G' letters" do
|
45
|
+
["G", "g"].each do |chr|
|
46
|
+
assert_equal "G", decollate(chr, :mysql, "latin1_swedish_ci")
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
test "mysql's latin1_swedish_ci handles 'H' letters" do
|
51
|
+
["H", "h"].each do |chr|
|
52
|
+
assert_equal "H", decollate(chr, :mysql, "latin1_swedish_ci")
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
test "mysql's latin1_swedish_ci handles 'I' letters" do
|
57
|
+
["I", "i", "Ì", "Í", "Î", "Ï", "ì", "í", "î", "ï"].each do |chr|
|
58
|
+
assert_equal "I", decollate(chr, :mysql, "latin1_swedish_ci")
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
test "mysql's latin1_swedish_ci handles 'J' letters" do
|
63
|
+
["J", "j"].each do |chr|
|
64
|
+
assert_equal "J", decollate(chr, :mysql, "latin1_swedish_ci")
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
test "mysql's latin1_swedish_ci handles 'K' letters" do
|
69
|
+
["K", "k"].each do |chr|
|
70
|
+
assert_equal "K", decollate(chr, :mysql, "latin1_swedish_ci")
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
test "mysql's latin1_swedish_ci handles 'L' letters" do
|
75
|
+
["L", "l"].each do |chr|
|
76
|
+
assert_equal "L", decollate(chr, :mysql, "latin1_swedish_ci")
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
test "mysql's latin1_swedish_ci handles 'M' letters" do
|
81
|
+
["M", "m"].each do |chr|
|
82
|
+
assert_equal "M", decollate(chr, :mysql, "latin1_swedish_ci")
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
test "mysql's latin1_swedish_ci handles 'N' letters" do
|
87
|
+
["N", "n", "Ñ", "ñ"].each do |chr|
|
88
|
+
assert_equal "N", decollate(chr, :mysql, "latin1_swedish_ci")
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
test "mysql's latin1_swedish_ci handles 'O' letters" do
|
93
|
+
["O", "o", "Ò", "Ó", "Ô", "Õ", "ò", "ó", "ô", "õ"].each do |chr|
|
94
|
+
assert_equal "O", decollate(chr, :mysql, "latin1_swedish_ci")
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
test "mysql's latin1_swedish_ci handles 'P' letters" do
|
99
|
+
["P", "p"].each do |chr|
|
100
|
+
assert_equal "P", decollate(chr, :mysql, "latin1_swedish_ci")
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
test "mysql's latin1_swedish_ci handles 'Q' letters" do
|
105
|
+
["Q", "q"].each do |chr|
|
106
|
+
assert_equal "Q", decollate(chr, :mysql, "latin1_swedish_ci")
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
test "mysql's latin1_swedish_ci handles 'R' letters" do
|
111
|
+
["R", "r"].each do |chr|
|
112
|
+
assert_equal "R", decollate(chr, :mysql, "latin1_swedish_ci")
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
test "mysql's latin1_swedish_ci handles 'S' letters" do
|
117
|
+
["S", "s"].each do |chr|
|
118
|
+
assert_equal "S", decollate(chr, :mysql, "latin1_swedish_ci")
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
test "mysql's latin1_swedish_ci handles 'T' letters" do
|
123
|
+
["T", "t"].each do |chr|
|
124
|
+
assert_equal "T", decollate(chr, :mysql, "latin1_swedish_ci")
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
test "mysql's latin1_swedish_ci handles 'U' letters" do
|
129
|
+
["U", "u", "Ù", "Ú", "Û", "ù", "ú", "û"].each do |chr|
|
130
|
+
assert_equal "U", decollate(chr, :mysql, "latin1_swedish_ci")
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
test "mysql's latin1_swedish_ci handles 'V' letters" do
|
135
|
+
["V", "v"].each do |chr|
|
136
|
+
assert_equal "V", decollate(chr, :mysql, "latin1_swedish_ci")
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
test "mysql's latin1_swedish_ci handles 'W' letters" do
|
141
|
+
["W", "w"].each do |chr|
|
142
|
+
assert_equal "W", decollate(chr, :mysql, "latin1_swedish_ci")
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
test "mysql's latin1_swedish_ci handles 'X' letters" do
|
147
|
+
["X", "x"].each do |chr|
|
148
|
+
assert_equal "X", decollate(chr, :mysql, "latin1_swedish_ci")
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
test "mysql's latin1_swedish_ci handles 'Y' letters" do
|
153
|
+
["Y", "y", "Ü", "Ý", "ü", "ý"].each do |chr|
|
154
|
+
assert_equal "Y", decollate(chr, :mysql, "latin1_swedish_ci")
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
test "mysql's latin1_swedish_ci handles 'Z' letters" do
|
159
|
+
["Z", "z"].each do |chr|
|
160
|
+
assert_equal "Z", decollate(chr, :mysql, "latin1_swedish_ci")
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
test "mysql's latin1_swedish_ci handles '[' letters" do
|
165
|
+
["[", "Å", "å"].each do |chr|
|
166
|
+
assert_equal "[", decollate(chr, :mysql, "latin1_swedish_ci")
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
test "mysql's latin1_swedish_ci handles '\\' letters" do
|
171
|
+
["\\", "Ä", "Æ", "ä", "æ"].each do |chr|
|
172
|
+
assert_equal "\\", decollate(chr, :mysql, "latin1_swedish_ci")
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|
176
|
+
test "mysql's latin1_swedish_ci handles ']' letters" do
|
177
|
+
["]", "Ö", "ö"].each do |chr|
|
178
|
+
assert_equal "]", decollate(chr, :mysql, "latin1_swedish_ci")
|
179
|
+
end
|
180
|
+
end
|
181
|
+
|
182
|
+
test "mysql's latin1_swedish_ci handles 'Ø' letters" do
|
183
|
+
["Ø", "ø"].each do |chr|
|
184
|
+
assert_equal "Ø", decollate(chr, :mysql, "latin1_swedish_ci")
|
185
|
+
end
|
186
|
+
end
|
187
|
+
|
188
|
+
test "mysql's latin1_swedish_ci handles 'Þ' letters" do
|
189
|
+
["Þ", "þ"].each do |chr|
|
190
|
+
assert_equal "Þ", decollate(chr, :mysql, "latin1_swedish_ci")
|
191
|
+
end
|
192
|
+
end
|
193
|
+
|
194
|
+
test "mysql's latin1_swedish_ci ignores trailing spaces" do
|
195
|
+
assert_equal "FOO", decollate("foo ", :mysql, "latin1_swedish_ci")
|
196
|
+
end
|
197
|
+
|
198
|
+
test "unknown collation" do
|
199
|
+
assert_equal "fOo", decollate("fOo", :foo, :bar)
|
200
|
+
end
|
201
|
+
end
|
data/test/unit/test_field.rb
CHANGED
@@ -6,45 +6,69 @@ class UnitTests::TestField < Test::Unit::TestCase
|
|
6
6
|
end
|
7
7
|
|
8
8
|
test "initialize with schema info" do
|
9
|
+
dataset = stub('dataset')
|
9
10
|
schema = {:allow_null=>true, :default=>nil, :primary_key=>true, :db_type=>"integer", :type=>:integer, :ruby_default=>nil}
|
10
|
-
field = Linkage::Field.new(:id, schema)
|
11
|
+
field = Linkage::Field.new(dataset, :id, schema)
|
11
12
|
assert_equal :id, field.name
|
12
13
|
assert_equal schema, field.schema
|
13
|
-
|
14
|
-
|
15
|
-
test "initialize with ruby type" do
|
16
|
-
info = {:type => Integer}
|
17
|
-
field = Linkage::Field.new(:id, nil, info)
|
18
|
-
assert_equal :id, field.name
|
19
|
-
assert_equal info, field.ruby_type
|
14
|
+
assert_equal dataset, field.dataset
|
20
15
|
end
|
21
16
|
|
22
17
|
test "static? is always false" do
|
18
|
+
dataset = stub('dataset')
|
23
19
|
schema = {:allow_null=>true, :default=>nil, :primary_key=>true, :db_type=>"integer", :type=>:integer, :ruby_default=>nil}
|
24
|
-
field = Linkage::Field.new(:id, schema)
|
20
|
+
field = Linkage::Field.new(dataset, :id, schema)
|
25
21
|
assert !field.static?
|
26
22
|
end
|
27
23
|
|
28
24
|
test "ruby_type for integer" do
|
29
|
-
|
25
|
+
dataset = stub('dataset')
|
26
|
+
field = Linkage::Field.new(dataset, :id, {:allow_null=>true, :default=>nil, :primary_key=>true, :db_type=>"integer", :type=>:integer, :ruby_default=>nil})
|
30
27
|
assert_equal({:type => Integer}, field.ruby_type)
|
31
28
|
end
|
32
29
|
|
33
30
|
test "primary_key? returns true if primary key" do
|
34
|
-
|
31
|
+
dataset = stub('dataset')
|
32
|
+
field_1 = Linkage::Field.new(dataset, :id, {:allow_null=>true, :default=>nil, :primary_key=>true, :db_type=>"integer", :type=>:integer, :ruby_default=>nil})
|
35
33
|
assert field_1.primary_key?
|
36
34
|
|
37
|
-
field_2 = Linkage::Field.new(:foo, {:allow_null=>true, :default=>nil, :primary_key=>false, :db_type=>"integer", :type=>:integer, :ruby_default=>nil})
|
35
|
+
field_2 = Linkage::Field.new(dataset, :foo, {:allow_null=>true, :default=>nil, :primary_key=>false, :db_type=>"integer", :type=>:integer, :ruby_default=>nil})
|
38
36
|
assert !field_2.primary_key?
|
39
37
|
end
|
40
38
|
|
41
39
|
test "to_expr returns name" do
|
42
|
-
|
40
|
+
dataset = stub('dataset')
|
41
|
+
field = Linkage::Field.new(dataset, :id, {:allow_null=>true, :default=>nil, :primary_key=>true, :db_type=>"integer", :type=>:integer, :ruby_default=>nil})
|
43
42
|
assert_equal :id, field.to_expr
|
44
43
|
end
|
45
44
|
|
46
45
|
test "to_expr ignores adapter argument" do
|
47
|
-
|
46
|
+
dataset = stub('dataset')
|
47
|
+
field = Linkage::Field.new(dataset, :id, {:allow_null=>true, :default=>nil, :primary_key=>true, :db_type=>"integer", :type=>:integer, :ruby_default=>nil})
|
48
48
|
assert_equal :id, field.to_expr(:foo)
|
49
49
|
end
|
50
|
+
|
51
|
+
test "collation" do
|
52
|
+
dataset = stub('dataset')
|
53
|
+
field = Linkage::Field.new(dataset, :foo, {:allow_null=>true, :default=>nil, :primary_key=>false, :db_type=>"varchar(255)", :type=>:string, :collation=>"latin1_general_cs", :ruby_default=>nil})
|
54
|
+
assert_equal "latin1_general_cs", field.collation
|
55
|
+
assert_equal "latin1_general_cs", field.ruby_type[:opts][:collate]
|
56
|
+
end
|
57
|
+
|
58
|
+
test "initialize MergeField with ruby type" do
|
59
|
+
info = {:type => Integer}
|
60
|
+
field = Linkage::MergeField.new(:id, info)
|
61
|
+
assert_equal :id, field.name
|
62
|
+
assert_equal info, field.ruby_type
|
63
|
+
assert_nil field.schema
|
64
|
+
assert_nil field.dataset
|
65
|
+
end
|
66
|
+
|
67
|
+
test "MergeField#database_type accessor" do
|
68
|
+
field_1 = Linkage::MergeField.new(:id, {:type => Integer})
|
69
|
+
assert_nil field_1.database_type
|
70
|
+
|
71
|
+
field_2 = Linkage::MergeField.new(:id, {:type => Integer}, :mysql)
|
72
|
+
assert_equal :mysql, field_2.database_type
|
73
|
+
end
|
50
74
|
end
|
data/test/unit/test_field_set.rb
CHANGED
@@ -15,14 +15,16 @@ class UnitTests::TestFieldSet < Test::Unit::TestCase
|
|
15
15
|
end
|
16
16
|
|
17
17
|
test "creates fields on initialization" do
|
18
|
+
dataset = mock('dataset', :schema => @schema)
|
19
|
+
|
18
20
|
field_1 = stub('id field')
|
19
21
|
field_2 = stub('first_name field')
|
20
22
|
field_3 = stub('last_name field')
|
21
|
-
Linkage::Field.expects(:new).with(:id, @schema[:id]).returns(field_1)
|
22
|
-
Linkage::Field.expects(:new).with(:first_name, @schema[:first_name]).returns(field_2)
|
23
|
-
Linkage::Field.expects(:new).with(:last_name, @schema[:last_name]).returns(field_3)
|
23
|
+
Linkage::Field.expects(:new).with(dataset, :id, @schema[:id]).returns(field_1)
|
24
|
+
Linkage::Field.expects(:new).with(dataset, :first_name, @schema[:first_name]).returns(field_2)
|
25
|
+
Linkage::Field.expects(:new).with(dataset, :last_name, @schema[:last_name]).returns(field_3)
|
24
26
|
|
25
|
-
fs = Linkage::FieldSet.new(
|
27
|
+
fs = Linkage::FieldSet.new(dataset)
|
26
28
|
assert_equal field_1, fs.primary_key
|
27
29
|
assert_equal field_1, fs[:id]
|
28
30
|
assert_equal field_2, fs[:first_name]
|
@@ -30,14 +32,16 @@ class UnitTests::TestFieldSet < Test::Unit::TestCase
|
|
30
32
|
end
|
31
33
|
|
32
34
|
test "case-insensitive names" do
|
35
|
+
dataset = stub('dataset', :schema => @schema)
|
36
|
+
|
33
37
|
field_1 = stub('id field')
|
34
38
|
field_2 = stub('first_name field')
|
35
39
|
field_3 = stub('last_name field')
|
36
|
-
Linkage::Field.stubs(:new).with(:id, @schema[:id]).returns(field_1)
|
37
|
-
Linkage::Field.stubs(:new).with(:first_name, @schema[:first_name]).returns(field_2)
|
38
|
-
Linkage::Field.stubs(:new).with(:last_name, @schema[:last_name]).returns(field_3)
|
40
|
+
Linkage::Field.stubs(:new).with(dataset, :id, @schema[:id]).returns(field_1)
|
41
|
+
Linkage::Field.stubs(:new).with(dataset, :first_name, @schema[:first_name]).returns(field_2)
|
42
|
+
Linkage::Field.stubs(:new).with(dataset, :last_name, @schema[:last_name]).returns(field_3)
|
39
43
|
|
40
|
-
fs = Linkage::FieldSet.new(
|
44
|
+
fs = Linkage::FieldSet.new(dataset)
|
41
45
|
assert_equal field_1, fs.primary_key
|
42
46
|
assert_equal field_1, fs[:Id]
|
43
47
|
assert_equal field_2, fs[:fIrst_name]
|
data/test/unit/test_function.rb
CHANGED
@@ -23,7 +23,8 @@ class UnitTests::TestFunction < Test::Unit::TestCase
|
|
23
23
|
test "ruby_type raises not implemented error in base class" do
|
24
24
|
klass = Class.new(Linkage::Function)
|
25
25
|
klass.send(:define_singleton_method, :function_name) { "foo" }
|
26
|
-
|
26
|
+
dataset = stub('dataset')
|
27
|
+
f = klass.new(:dataset => dataset)
|
27
28
|
assert_raises(NotImplementedError) { f.ruby_type }
|
28
29
|
end
|
29
30
|
|
@@ -39,7 +40,7 @@ class UnitTests::TestFunction < Test::Unit::TestCase
|
|
39
40
|
|
40
41
|
test "function with no arguments" do
|
41
42
|
klass = new_function('foo', {:type => String})
|
42
|
-
f = klass.new
|
43
|
+
f = klass.new(:dataset => stub('dataset'))
|
43
44
|
assert_equal :foo, f.name
|
44
45
|
assert_equal :foo.sql_function, f.to_expr
|
45
46
|
assert f.static?
|
@@ -47,7 +48,7 @@ class UnitTests::TestFunction < Test::Unit::TestCase
|
|
47
48
|
|
48
49
|
test "function with static value" do
|
49
50
|
klass = new_function('foo', {:type => String})
|
50
|
-
f = klass.new(123)
|
51
|
+
f = klass.new(123, :dataset => stub('dataset'))
|
51
52
|
assert_equal :foo.sql_function(123), f.to_expr
|
52
53
|
assert_equal :foo_123, f.name
|
53
54
|
assert f.static?
|
@@ -55,18 +56,47 @@ class UnitTests::TestFunction < Test::Unit::TestCase
|
|
55
56
|
|
56
57
|
test "function with field" do
|
57
58
|
klass = new_function('foo', {:type => String})
|
58
|
-
|
59
|
+
|
60
|
+
dataset = stub('dataset')
|
61
|
+
field = stub_field('field', {
|
62
|
+
:name => :bar, :to_expr => :bar,
|
63
|
+
:ruby_type => {:type => String}, :dataset => dataset
|
64
|
+
})
|
59
65
|
f = klass.new(field)
|
60
66
|
assert_equal :foo_bar, f.name
|
61
67
|
assert_equal :foo.sql_function(:bar), f.to_expr
|
68
|
+
assert_equal dataset, f.dataset
|
62
69
|
assert !f.static?
|
63
70
|
end
|
64
71
|
|
72
|
+
test "creating function with conflicting datasets raises exception" do
|
73
|
+
klass = new_function('foo', {:type => String}, [[String], [String]])
|
74
|
+
|
75
|
+
dataset_1 = stub('dataset')
|
76
|
+
field_1 = stub_field('field 1', {
|
77
|
+
:name => :foo, :to_expr => :foo,
|
78
|
+
:ruby_type => {:type => String}, :dataset => dataset_1
|
79
|
+
})
|
80
|
+
dataset_2 = stub('dataset')
|
81
|
+
field_2 = stub_field('field 2', {
|
82
|
+
:name => :bar, :to_expr => :bar,
|
83
|
+
:ruby_type => {:type => String}, :dataset => dataset_2
|
84
|
+
})
|
85
|
+
|
86
|
+
assert_raises(ArgumentError) { klass.new(field_1, field_2) }
|
87
|
+
end
|
88
|
+
|
89
|
+
test "getting dataset for a static function without dataset raises exception" do
|
90
|
+
klass = new_function('foo', {:type => String})
|
91
|
+
func = klass.new
|
92
|
+
assert_raises(RuntimeError) { func.dataset }
|
93
|
+
end
|
94
|
+
|
65
95
|
test "function with dynamic function" do
|
66
96
|
klass_1 = new_function('foo', {:type => String})
|
67
97
|
klass_2 = new_function('bar', {:type => String})
|
68
98
|
|
69
|
-
field = stub_field('field', :name => :baz, :to_expr => :baz, :ruby_type => {:type => String})
|
99
|
+
field = stub_field('field', :name => :baz, :to_expr => :baz, :ruby_type => {:type => String}, :dataset => stub('dataset'))
|
70
100
|
func_1 = klass_1.new(field)
|
71
101
|
assert_equal :foo_baz, func_1.name
|
72
102
|
assert !func_1.static?
|
@@ -81,7 +111,7 @@ class UnitTests::TestFunction < Test::Unit::TestCase
|
|
81
111
|
klass_1 = new_function('foo', {:type => String})
|
82
112
|
klass_2 = new_function('bar', {:type => String})
|
83
113
|
|
84
|
-
func_1 = klass_1.new(123)
|
114
|
+
func_1 = klass_1.new(123, :dataset => stub('dataset'))
|
85
115
|
assert_equal :foo_123, func_1.name
|
86
116
|
assert func_1.static?
|
87
117
|
|
@@ -96,11 +126,12 @@ class UnitTests::TestFunction < Test::Unit::TestCase
|
|
96
126
|
klass_2 = new_function('bar', {:type => String})
|
97
127
|
klass_3 = new_function('baz', {:type => String})
|
98
128
|
|
99
|
-
|
129
|
+
dataset = stub('dataset')
|
130
|
+
func_1 = klass_1.new(123, :dataset => dataset)
|
100
131
|
assert_equal :foo_123, func_1.name
|
101
132
|
assert func_1.static?
|
102
133
|
|
103
|
-
field = stub_field('field', :name => :quux, :to_expr => :quux, :ruby_type => {:type => String})
|
134
|
+
field = stub_field('field', :name => :quux, :to_expr => :quux, :ruby_type => {:type => String}, :dataset => dataset)
|
104
135
|
func_2 = klass_2.new(field)
|
105
136
|
assert_equal :bar_quux, func_2.name
|
106
137
|
assert !func_2.static?
|
@@ -113,8 +144,9 @@ class UnitTests::TestFunction < Test::Unit::TestCase
|
|
113
144
|
|
114
145
|
test "function with multiple fields" do
|
115
146
|
klass = new_function('foo', {:type => String})
|
116
|
-
|
117
|
-
|
147
|
+
dataset = stub('dataset')
|
148
|
+
field_1 = stub_field('field', :name => :bar, :to_expr => :bar, :ruby_type => {:type => String}, :dataset => dataset)
|
149
|
+
field_2 = stub_field('field', :name => :baz, :to_expr => :baz, :ruby_type => {:type => String}, :dataset => dataset)
|
118
150
|
func = klass.new(field_1, field_2)
|
119
151
|
assert_equal :foo_bar_baz, func.name
|
120
152
|
assert_equal :foo.sql_function(:bar, :baz), func.to_expr
|
@@ -123,7 +155,7 @@ class UnitTests::TestFunction < Test::Unit::TestCase
|
|
123
155
|
|
124
156
|
test "function with multiple mixed arguments" do
|
125
157
|
klass = new_function('foo', {:type => String})
|
126
|
-
field = stub_field('field', :name => :bar, :to_expr => :bar, :ruby_type => {:type => String})
|
158
|
+
field = stub_field('field', :name => :bar, :to_expr => :bar, :ruby_type => {:type => String}, :dataset => stub('dataset'))
|
127
159
|
f = klass.new(field, 123, 'abc')
|
128
160
|
assert_equal :foo_bar_123_abc, f.name
|
129
161
|
assert_equal :foo.sql_function(:bar, 123, 'abc'), f.to_expr
|
@@ -136,11 +168,12 @@ class UnitTests::TestFunction < Test::Unit::TestCase
|
|
136
168
|
end
|
137
169
|
|
138
170
|
test "valid parameters" do
|
139
|
-
|
140
|
-
|
171
|
+
klass = new_function('foo', {:type => String}, [[String]])
|
172
|
+
dataset = stub('dataset')
|
173
|
+
assert_equal :foo.sql_function("foo"), klass.new("foo", :dataset => dataset).to_expr
|
141
174
|
field = stub_field('field', :name => :bar, :to_expr => :bar, :ruby_type => {:type => String})
|
142
|
-
assert_equal :foo.sql_function(:bar),
|
143
|
-
assert_equal :foo.sql_function(:foo.sql_function("hey")),
|
175
|
+
assert_equal :foo.sql_function(:bar), klass.new(field, :dataset => dataset).to_expr
|
176
|
+
assert_equal :foo.sql_function(:foo.sql_function("hey")), klass.new(klass.new("hey", :dataset => dataset)).to_expr
|
144
177
|
end
|
145
178
|
|
146
179
|
test "invalid parameters" do
|
@@ -153,8 +186,9 @@ class UnitTests::TestFunction < Test::Unit::TestCase
|
|
153
186
|
func.new(field)
|
154
187
|
end
|
155
188
|
func2 = new_function('bar', {:type => Integer})
|
189
|
+
dataset = stub('dataset')
|
156
190
|
assert_raises(TypeError) do
|
157
|
-
func.new(func2.new)
|
191
|
+
func.new(func2.new(:dataset => dataset))
|
158
192
|
end
|
159
193
|
assert_raises(ArgumentError) do
|
160
194
|
func.new("123", "456")
|
@@ -163,4 +197,37 @@ class UnitTests::TestFunction < Test::Unit::TestCase
|
|
163
197
|
func.new
|
164
198
|
end
|
165
199
|
end
|
200
|
+
|
201
|
+
test "two functions with the same name and arguments and datasets are equal" do
|
202
|
+
klass = new_function('foo', {:type => String}, [[String]])
|
203
|
+
dataset = stub('dataset')
|
204
|
+
field = stub_field('field', :dataset => dataset, :ruby_type => {:type => String})
|
205
|
+
|
206
|
+
func_1 = klass.new(field)
|
207
|
+
func_2 = klass.new(field)
|
208
|
+
assert func_1 == func_2
|
209
|
+
end
|
210
|
+
|
211
|
+
test "#== with two static functions" do
|
212
|
+
klass = new_function('foo', {:type => String}, [[String]])
|
213
|
+
dataset = stub('dataset')
|
214
|
+
func_1 = klass.new('foo', :dataset => dataset)
|
215
|
+
func_2 = klass.new('foo', :dataset => dataset)
|
216
|
+
assert func_1 == func_2
|
217
|
+
end
|
218
|
+
|
219
|
+
test "collation returns nil by default" do
|
220
|
+
klass = new_function('foo', {:type => String}, [[String]])
|
221
|
+
dataset = stub('dataset')
|
222
|
+
func = klass.new('foo', :dataset => dataset)
|
223
|
+
assert_nil func.collation
|
224
|
+
end
|
225
|
+
|
226
|
+
test "special :any parameter" do
|
227
|
+
klass = new_function('foo', {:type => String}, [[:any]])
|
228
|
+
dataset = stub('dataset')
|
229
|
+
assert_nothing_raised do
|
230
|
+
klass.new('foo', :dataset => dataset)
|
231
|
+
end
|
232
|
+
end
|
166
233
|
end
|
data/test/unit/test_group.rb
CHANGED
@@ -7,4 +7,32 @@ class UnitTests::TestGroup < Test::Unit::TestCase
|
|
7
7
|
assert_equal 1, g.count
|
8
8
|
assert_equal 456, g.id
|
9
9
|
end
|
10
|
+
|
11
|
+
test "decollate strings" do
|
12
|
+
test_ruby_type = { :type => String, :opts => { :collate => "latin1_swedish_ci" } }
|
13
|
+
group = Linkage::Group.new({:test => 'TeSt '}, {
|
14
|
+
:count => 1, :id => 456, :ruby_types => { :test => test_ruby_type },
|
15
|
+
:database_type => :mysql
|
16
|
+
})
|
17
|
+
assert_equal({:test => "TEST"}, group.decollated_values)
|
18
|
+
end
|
19
|
+
|
20
|
+
test "don't decollate non-strings or strings without collation information" do
|
21
|
+
ruby_types = {
|
22
|
+
:foo => {
|
23
|
+
:type => String, :opts => { :collate => "latin1_swedish_ci" }
|
24
|
+
},
|
25
|
+
:bar => {
|
26
|
+
:type => Fixnum
|
27
|
+
},
|
28
|
+
:baz => {
|
29
|
+
:type => String
|
30
|
+
}
|
31
|
+
}
|
32
|
+
group = Linkage::Group.new({:foo => 'foO', :bar => 123, :baz => "foO"}, {
|
33
|
+
:count => 1, :id => 456, :ruby_types => ruby_types,
|
34
|
+
:database_type => :mysql
|
35
|
+
})
|
36
|
+
assert_equal({:foo => "FOO", :bar => 123, :baz => "foO"}, group.decollated_values)
|
37
|
+
end
|
10
38
|
end
|
@@ -2,50 +2,36 @@ require 'helper'
|
|
2
2
|
|
3
3
|
class UnitTests::TestImportBuffer < Test::Unit::TestCase
|
4
4
|
test "basic usage" do
|
5
|
-
|
5
|
+
database = stub('database')
|
6
|
+
dataset = stub('dataset', :db => database)
|
7
|
+
|
8
|
+
buf = Linkage::ImportBuffer.new(dataset, [:qux, :thud])
|
6
9
|
buf.add([123, 456])
|
7
10
|
buf.add(['test', 'junk'])
|
8
11
|
|
9
|
-
database
|
10
|
-
Sequel.expects(:connect).with('foo:/bar/db', {}).yields(database)
|
11
|
-
dataset = mock('dataset')
|
12
|
-
database.expects(:[]).with(:baz_table).returns(dataset)
|
12
|
+
database.expects(:synchronize).yields
|
13
13
|
dataset.expects(:import).with([:qux, :thud], [[123, 456], ['test', 'junk']])
|
14
14
|
buf.flush
|
15
15
|
end
|
16
16
|
|
17
17
|
test "flush performs a no-op when buffer is empty" do
|
18
|
-
|
19
|
-
|
18
|
+
database = stub('database')
|
19
|
+
dataset = stub('dataset', :db => database)
|
20
|
+
dataset.expects(:import).never
|
21
|
+
buf = Linkage::ImportBuffer.new(dataset, [:qux, :thud])
|
20
22
|
buf.flush
|
21
23
|
end
|
22
24
|
|
23
25
|
test "auto-flush" do
|
24
|
-
|
25
|
-
|
26
|
+
database = stub('database')
|
27
|
+
dataset = stub('dataset', :db => database)
|
26
28
|
headers = [:qux, :thud]
|
27
29
|
limit = 3
|
28
|
-
buf = Linkage::ImportBuffer.new(
|
30
|
+
buf = Linkage::ImportBuffer.new(dataset, headers, limit)
|
29
31
|
2.times { |i| buf.add([123, 456]) }
|
30
32
|
|
31
|
-
database
|
32
|
-
Sequel.expects(:connect).with('foo:/bar/db', {}).yields(database)
|
33
|
-
dataset = mock('dataset')
|
34
|
-
database.expects(:[]).with(:baz_table).returns(dataset)
|
33
|
+
database.expects(:synchronize).yields
|
35
34
|
dataset.expects(:import).with([:qux, :thud], [[123, 456], [123, 456], ['test', 'junk']])
|
36
35
|
buf.add(['test', 'junk'])
|
37
36
|
end
|
38
|
-
|
39
|
-
test "accepts Sequel.connect options" do
|
40
|
-
buf = Linkage::ImportBuffer.new('foo:/bar/db', 'baz_table', [:qux, :thud], :foo => 123)
|
41
|
-
buf.add([123, 456])
|
42
|
-
buf.add(['test', 'junk'])
|
43
|
-
|
44
|
-
database = mock('database')
|
45
|
-
Sequel.expects(:connect).with('foo:/bar/db', :foo => 123).yields(database)
|
46
|
-
dataset = mock('dataset')
|
47
|
-
database.expects(:[]).with(:baz_table).returns(dataset)
|
48
|
-
dataset.expects(:import).with([:qux, :thud], [[123, 456], ['test', 'junk']])
|
49
|
-
buf.flush
|
50
|
-
end
|
51
37
|
end
|