linkage 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,51 @@
1
+ require 'helper'
2
+
3
+ class UnitTests::TestImportBuffer < Test::Unit::TestCase
4
+ test "basic usage" do
5
+ buf = Linkage::ImportBuffer.new('foo:/bar/db', 'baz_table', [:qux, :thud])
6
+ buf.add([123, 456])
7
+ buf.add(['test', 'junk'])
8
+
9
+ database = mock('database')
10
+ Sequel.expects(:connect).with('foo:/bar/db', {}).yields(database)
11
+ dataset = mock('dataset')
12
+ database.expects(:[]).with(:baz_table).returns(dataset)
13
+ dataset.expects(:import).with([:qux, :thud], [[123, 456], ['test', 'junk']])
14
+ buf.flush
15
+ end
16
+
17
+ test "flush performs a no-op when buffer is empty" do
18
+ Sequel.expects(:connect).never
19
+ buf = Linkage::ImportBuffer.new('foo:/bar/db', 'baz_table', [:qux, :thud])
20
+ buf.flush
21
+ end
22
+
23
+ test "auto-flush" do
24
+ uri = 'foo:/bar/db'
25
+ table = 'baz_table'
26
+ headers = [:qux, :thud]
27
+ limit = 3
28
+ buf = Linkage::ImportBuffer.new(uri, table, headers, {}, limit)
29
+ 2.times { |i| buf.add([123, 456]) }
30
+
31
+ database = mock('database')
32
+ Sequel.expects(:connect).with('foo:/bar/db', {}).yields(database)
33
+ dataset = mock('dataset')
34
+ database.expects(:[]).with(:baz_table).returns(dataset)
35
+ dataset.expects(:import).with([:qux, :thud], [[123, 456], [123, 456], ['test', 'junk']])
36
+ buf.add(['test', 'junk'])
37
+ 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
+ end
@@ -0,0 +1,6 @@
1
+ require 'helper'
2
+
3
+ module UnitTests
4
+ class TestLinkage < Test::Unit::TestCase
5
+ end
6
+ end
@@ -0,0 +1,14 @@
1
+ require 'helper'
2
+
3
+ class UnitTests::TestRunner < Test::Unit::TestCase
4
+ test "initialization" do
5
+ conf = stub("configuration")
6
+ runner = Linkage::Runner.new(conf, "foo:/results")
7
+ end
8
+
9
+ test "execute raises error" do
10
+ conf = stub("configuration")
11
+ runner = Linkage::Runner.new(conf, "foo:/results")
12
+ assert_raise_kind_of(NotImplementedError) { runner.execute }
13
+ end
14
+ end
@@ -0,0 +1,12 @@
1
+ require 'helper'
2
+
3
+ class UnitTests::TestSingleThreadedRunner < Test::Unit::TestCase
4
+ test "subclass of Runner" do
5
+ assert_equal Linkage::Runner, Linkage::SingleThreadedRunner.superclass
6
+ end
7
+
8
+ test "defines execute" do
9
+ methods = Linkage::SingleThreadedRunner.public_instance_methods(false)
10
+ assert methods.include?(:execute) || methods.include?("execute")
11
+ end
12
+ end
@@ -0,0 +1,341 @@
1
+ require 'helper'
2
+
3
+ class UnitTests::TestUtils < Test::Unit::TestCase
4
+ include Linkage::Utils
5
+
6
+ test "merge two identical primary keys" do
7
+ field_1 = {:allow_null=>true, :default=>nil, :primary_key=>true, :db_type=>"integer", :type=>:integer, :ruby_default=>nil}
8
+ field_2 = {:allow_null=>true, :default=>nil, :primary_key=>true, :db_type=>"integer", :type=>:integer, :ruby_default=>nil}
9
+ expected = {:type => Integer, :opts => {}}
10
+ assert_equal(expected, merge_fields(field_1, field_2))
11
+ assert_equal(expected, merge_fields(field_2, field_1))
12
+ end
13
+
14
+ test "merge two boolean fields" do
15
+ field_1 = {:allow_null=>true, :default=>nil, :primary_key=>false, :db_type=>"boolean", :type=>:boolean, :ruby_default=>nil}
16
+ field_2 = {:allow_null=>true, :default=>nil, :primary_key=>false, :db_type=>"boolean", :type=>:boolean, :ruby_default=>nil}
17
+ expected = {:type => TrueClass, :opts => {}}
18
+ assert_equal(expected, merge_fields(field_1, field_2))
19
+ assert_equal(expected, merge_fields(field_2, field_1))
20
+ end
21
+
22
+ test "merge a boolean field and an integer field" do
23
+ field_1 = {:allow_null=>true, :default=>nil, :primary_key=>false, :db_type=>"integer", :type=>:integer, :ruby_default=>nil}
24
+ field_2 = {:allow_null=>true, :default=>nil, :primary_key=>false, :db_type=>"boolean", :type=>:boolean, :ruby_default=>nil}
25
+ expected = {:type => Integer, :opts => {}}
26
+ assert_equal(expected, merge_fields(field_1, field_2))
27
+ assert_equal(expected, merge_fields(field_2, field_1))
28
+ end
29
+
30
+ test "merge a boolean field and a bignum field" do
31
+ field_1 = {:allow_null=>true, :default=>nil, :primary_key=>false, :db_type=>"bigint", :type=>:bigint, :ruby_default=>nil}
32
+ field_2 = {:allow_null=>true, :default=>nil, :primary_key=>false, :db_type=>"boolean", :type=>:boolean, :ruby_default=>nil}
33
+ expected = {:type => Bignum, :opts => {}}
34
+ assert_equal(expected, merge_fields(field_1, field_2))
35
+ assert_equal(expected, merge_fields(field_2, field_1))
36
+ end
37
+
38
+ test "merge a boolean field and a float field" do
39
+ field_1 = {:allow_null=>true, :default=>nil, :primary_key=>false, :db_type=>"float", :type=>:float, :ruby_default=>nil}
40
+ field_2 = {:allow_null=>true, :default=>nil, :primary_key=>false, :db_type=>"boolean", :type=>:boolean, :ruby_default=>nil}
41
+ expected = {:type => Float, :opts => {}}
42
+ assert_equal(expected, merge_fields(field_1, field_2))
43
+ assert_equal(expected, merge_fields(field_2, field_1))
44
+ end
45
+
46
+ test "merge a boolean field and a decimal field" do
47
+ field_1 = {:allow_null=>true, :default=>nil, :primary_key=>false, :db_type=>"decimal", :type=>:decimal, :ruby_default=>nil}
48
+ field_2 = {:allow_null=>true, :default=>nil, :primary_key=>false, :db_type=>"boolean", :type=>:boolean, :ruby_default=>nil}
49
+ expected = {:type => BigDecimal, :opts => {}}
50
+ assert_equal(expected, merge_fields(field_1, field_2))
51
+ assert_equal(expected, merge_fields(field_2, field_1))
52
+ end
53
+
54
+ test "merge a boolean field and a decimal field with size" do
55
+ field_1 = {:allow_null=>true, :default=>nil, :primary_key=>false, :db_type=>"decimal(10,2)", :type=>:decimal, :ruby_default=>nil}
56
+ field_2 = {:allow_null=>true, :default=>nil, :primary_key=>false, :db_type=>"boolean", :type=>:boolean, :ruby_default=>nil}
57
+ expected = {:type => BigDecimal, :opts => {:size => [10, 2]}}
58
+ assert_equal(expected, merge_fields(field_1, field_2))
59
+ assert_equal(expected, merge_fields(field_2, field_1))
60
+ end
61
+
62
+ test "merge a boolean field and a string field" do
63
+ field_1 = {:allow_null=>true, :default=>nil, :primary_key=>false, :db_type=>"varchar(10)", :type=>:string, :ruby_default=>nil}
64
+ field_2 = {:allow_null=>true, :default=>nil, :primary_key=>false, :db_type=>"boolean", :type=>:boolean, :ruby_default=>nil}
65
+ expected = {:type => String, :opts => {:size => 10}}
66
+ assert_equal(expected, merge_fields(field_1, field_2))
67
+ assert_equal(expected, merge_fields(field_2, field_1))
68
+ end
69
+
70
+ test "merge a boolean field and a text field" do
71
+ field_1 = {:allow_null=>true, :default=>nil, :primary_key=>false, :db_type=>"text", :type=>:text, :ruby_default=>nil}
72
+ field_2 = {:allow_null=>true, :default=>nil, :primary_key=>false, :db_type=>"boolean", :type=>:boolean, :ruby_default=>nil}
73
+ expected = {:type => String, :opts => {:text => true}}
74
+ assert_equal(expected, merge_fields(field_1, field_2))
75
+ assert_equal(expected, merge_fields(field_2, field_1))
76
+ end
77
+
78
+ test "merge a boolean field and a fixed string field" do
79
+ field_1 = {:allow_null=>true, :default=>nil, :primary_key=>false, :db_type=>"char(10)", :type=>:string, :ruby_default=>nil}
80
+ field_2 = {:allow_null=>true, :default=>nil, :primary_key=>false, :db_type=>"boolean", :type=>:boolean, :ruby_default=>nil}
81
+ expected = {:type => String, :opts => {:size => 10, :fixed => true}}
82
+ assert_equal(expected, merge_fields(field_1, field_2))
83
+ assert_equal(expected, merge_fields(field_2, field_1))
84
+ end
85
+
86
+ test "merge two integer fields" do
87
+ field_1 = {:allow_null=>true, :default=>nil, :primary_key=>false, :db_type=>"integer", :type=>:integer, :ruby_default=>nil}
88
+ field_2 = {:allow_null=>true, :default=>nil, :primary_key=>false, :db_type=>"integer", :type=>:integer, :ruby_default=>nil}
89
+ expected = {:type => Integer, :opts => {}}
90
+ assert_equal(expected, merge_fields(field_1, field_2))
91
+ assert_equal(expected, merge_fields(field_2, field_1))
92
+ end
93
+
94
+ test "merge an integer field and a bignum field" do
95
+ field_1 = {:allow_null=>true, :default=>nil, :primary_key=>false, :db_type=>"bigint", :type=>:bigint, :ruby_default=>nil}
96
+ field_2 = {:allow_null=>true, :default=>nil, :primary_key=>false, :db_type=>"integer", :type=>:integer, :ruby_default=>nil}
97
+ expected = {:type => Bignum, :opts => {}}
98
+ assert_equal(expected, merge_fields(field_1, field_2))
99
+ assert_equal(expected, merge_fields(field_2, field_1))
100
+ end
101
+
102
+ test "merge an integer field and a float field" do
103
+ field_1 = {:allow_null=>true, :default=>nil, :primary_key=>false, :db_type=>"float", :type=>:float, :ruby_default=>nil}
104
+ field_2 = {:allow_null=>true, :default=>nil, :primary_key=>false, :db_type=>"integer", :type=>:integer, :ruby_default=>nil}
105
+ expected = {:type => Float, :opts => {}}
106
+ assert_equal(expected, merge_fields(field_1, field_2))
107
+ assert_equal(expected, merge_fields(field_2, field_1))
108
+ end
109
+
110
+ test "merge an integer field and a decimal field" do
111
+ field_1 = {:allow_null=>true, :default=>nil, :primary_key=>false, :db_type=>"decimal", :type=>:decimal, :ruby_default=>nil}
112
+ field_2 = {:allow_null=>true, :default=>nil, :primary_key=>false, :db_type=>"integer", :type=>:integer, :ruby_default=>nil}
113
+ expected = {:type => BigDecimal, :opts => {}}
114
+ assert_equal(expected, merge_fields(field_1, field_2))
115
+ assert_equal(expected, merge_fields(field_2, field_1))
116
+ end
117
+
118
+ test "merge an integer field and a decimal field with size" do
119
+ field_1 = {:allow_null=>true, :default=>nil, :primary_key=>false, :db_type=>"decimal(10,2)", :type=>:decimal, :ruby_default=>nil}
120
+ field_2 = {:allow_null=>true, :default=>nil, :primary_key=>false, :db_type=>"integer", :type=>:integer, :ruby_default=>nil}
121
+ expected = {:type => BigDecimal, :opts => {:size => [10, 2]}}
122
+ assert_equal(expected, merge_fields(field_1, field_2))
123
+ assert_equal(expected, merge_fields(field_2, field_1))
124
+ end
125
+
126
+ test "merge an integer field and a string field" do
127
+ field_1 = {:allow_null=>true, :default=>nil, :primary_key=>false, :db_type=>"varchar(10)", :type=>:string, :ruby_default=>nil}
128
+ field_2 = {:allow_null=>true, :default=>nil, :primary_key=>false, :db_type=>"integer", :type=>:integer, :ruby_default=>nil}
129
+ expected = {:type => String, :opts => {:size => 10}}
130
+ assert_equal(expected, merge_fields(field_1, field_2))
131
+ assert_equal(expected, merge_fields(field_2, field_1))
132
+ end
133
+
134
+ test "merge an integer field and a text field" do
135
+ field_1 = {:allow_null=>true, :default=>nil, :primary_key=>false, :db_type=>"text", :type=>:text, :ruby_default=>nil}
136
+ field_2 = {:allow_null=>true, :default=>nil, :primary_key=>false, :db_type=>"integer", :type=>:integer, :ruby_default=>nil}
137
+ expected = {:type => String, :opts => {:text => true}}
138
+ assert_equal(expected, merge_fields(field_1, field_2))
139
+ assert_equal(expected, merge_fields(field_2, field_1))
140
+ end
141
+
142
+ test "merge an integer field and a fixed string field" do
143
+ field_1 = {:allow_null=>true, :default=>nil, :primary_key=>false, :db_type=>"char(10)", :type=>:string, :ruby_default=>nil}
144
+ field_2 = {:allow_null=>true, :default=>nil, :primary_key=>false, :db_type=>"integer", :type=>:integer, :ruby_default=>nil}
145
+ expected = {:type => String, :opts => {:size => 10, :fixed => true}}
146
+ assert_equal(expected, merge_fields(field_1, field_2))
147
+ assert_equal(expected, merge_fields(field_2, field_1))
148
+ end
149
+
150
+ test "merge two bignum fields" do
151
+ field_1 = {:allow_null=>true, :default=>nil, :primary_key=>false, :db_type=>"bigint", :type=>:bigint, :ruby_default=>nil}
152
+ field_2 = {:allow_null=>true, :default=>nil, :primary_key=>false, :db_type=>"bigint", :type=>:bigint, :ruby_default=>nil}
153
+ expected = {:type => Bignum, :opts => {}}
154
+ assert_equal(expected, merge_fields(field_1, field_2))
155
+ assert_equal(expected, merge_fields(field_2, field_1))
156
+ end
157
+
158
+ test "merge an bignum field and a decimal field" do
159
+ field_1 = {:allow_null=>true, :default=>nil, :primary_key=>false, :db_type=>"decimal", :type=>:decimal, :ruby_default=>nil}
160
+ field_2 = {:allow_null=>true, :default=>nil, :primary_key=>false, :db_type=>"bigint", :type=>:bigint, :ruby_default=>nil}
161
+ expected = {:type => BigDecimal, :opts => {}}
162
+ assert_equal(expected, merge_fields(field_1, field_2))
163
+ assert_equal(expected, merge_fields(field_2, field_1))
164
+ end
165
+
166
+ test "merge an bignum field and a decimal field with size" do
167
+ field_1 = {:allow_null=>true, :default=>nil, :primary_key=>false, :db_type=>"decimal(10,2)", :type=>:decimal, :ruby_default=>nil}
168
+ field_2 = {:allow_null=>true, :default=>nil, :primary_key=>false, :db_type=>"bigint", :type=>:bigint, :ruby_default=>nil}
169
+ expected = {:type => BigDecimal, :opts => {:size => [10, 2]}}
170
+ assert_equal(expected, merge_fields(field_1, field_2))
171
+ assert_equal(expected, merge_fields(field_2, field_1))
172
+ end
173
+
174
+ test "merge an bignum field and a string field" do
175
+ field_1 = {:allow_null=>true, :default=>nil, :primary_key=>false, :db_type=>"varchar(10)", :type=>:string, :ruby_default=>nil}
176
+ field_2 = {:allow_null=>true, :default=>nil, :primary_key=>false, :db_type=>"bigint", :type=>:bigint, :ruby_default=>nil}
177
+ expected = {:type => String, :opts => {:size => 10}}
178
+ assert_equal(expected, merge_fields(field_1, field_2))
179
+ assert_equal(expected, merge_fields(field_2, field_1))
180
+ end
181
+
182
+ test "merge an bignum field and a text field" do
183
+ field_1 = {:allow_null=>true, :default=>nil, :primary_key=>false, :db_type=>"text", :type=>:text, :ruby_default=>nil}
184
+ field_2 = {:allow_null=>true, :default=>nil, :primary_key=>false, :db_type=>"bigint", :type=>:bigint, :ruby_default=>nil}
185
+ expected = {:type => String, :opts => {:text => true}}
186
+ assert_equal(expected, merge_fields(field_1, field_2))
187
+ assert_equal(expected, merge_fields(field_2, field_1))
188
+ end
189
+
190
+ test "merge an bignum field and a fixed string field" do
191
+ field_1 = {:allow_null=>true, :default=>nil, :primary_key=>false, :db_type=>"char(10)", :type=>:string, :ruby_default=>nil}
192
+ field_2 = {:allow_null=>true, :default=>nil, :primary_key=>false, :db_type=>"bigint", :type=>:bigint, :ruby_default=>nil}
193
+ expected = {:type => String, :opts => {:size => 10, :fixed => true}}
194
+ assert_equal(expected, merge_fields(field_1, field_2))
195
+ assert_equal(expected, merge_fields(field_2, field_1))
196
+ end
197
+
198
+ test "merge two float fields" do
199
+ field_1 = {:allow_null=>true, :default=>nil, :primary_key=>false, :db_type=>"float", :type=>:float, :ruby_default=>nil}
200
+ field_2 = {:allow_null=>true, :default=>nil, :primary_key=>false, :db_type=>"float", :type=>:float, :ruby_default=>nil}
201
+ expected = {:type => Float, :opts => {}}
202
+ assert_equal(expected, merge_fields(field_1, field_2))
203
+ assert_equal(expected, merge_fields(field_2, field_1))
204
+ end
205
+
206
+ test "merge a float field and a bignum field" do
207
+ field_1 = {:allow_null=>true, :default=>nil, :primary_key=>false, :db_type=>"bigint", :type=>:bigint, :ruby_default=>nil}
208
+ field_2 = {:allow_null=>true, :default=>nil, :primary_key=>false, :db_type=>"float", :type=>:float, :ruby_default=>nil}
209
+ expected = {:type => BigDecimal, :opts => {}}
210
+ assert_equal(expected, merge_fields(field_1, field_2))
211
+ assert_equal(expected, merge_fields(field_2, field_1))
212
+ end
213
+
214
+ test "merge a float field and a decimal field" do
215
+ field_1 = {:allow_null=>true, :default=>nil, :primary_key=>false, :db_type=>"decimal", :type=>:decimal, :ruby_default=>nil}
216
+ field_2 = {:allow_null=>true, :default=>nil, :primary_key=>false, :db_type=>"float", :type=>:float, :ruby_default=>nil}
217
+ expected = {:type => BigDecimal, :opts => {}}
218
+ assert_equal(expected, merge_fields(field_1, field_2))
219
+ assert_equal(expected, merge_fields(field_2, field_1))
220
+ end
221
+
222
+ test "merge a float field and a decimal field with size" do
223
+ field_1 = {:allow_null=>true, :default=>nil, :primary_key=>false, :db_type=>"decimal(10,2)", :type=>:decimal, :ruby_default=>nil}
224
+ field_2 = {:allow_null=>true, :default=>nil, :primary_key=>false, :db_type=>"float", :type=>:float, :ruby_default=>nil}
225
+ expected = {:type => BigDecimal, :opts => {:size => [10, 2]}}
226
+ assert_equal(expected, merge_fields(field_1, field_2))
227
+ assert_equal(expected, merge_fields(field_2, field_1))
228
+ end
229
+
230
+ test "merge a float field and a string field" do
231
+ field_1 = {:allow_null=>true, :default=>nil, :primary_key=>false, :db_type=>"varchar(10)", :type=>:string, :ruby_default=>nil}
232
+ field_2 = {:allow_null=>true, :default=>nil, :primary_key=>false, :db_type=>"float", :type=>:float, :ruby_default=>nil}
233
+ expected = {:type => String, :opts => {:size => 10}}
234
+ assert_equal(expected, merge_fields(field_1, field_2))
235
+ assert_equal(expected, merge_fields(field_2, field_1))
236
+ end
237
+
238
+ test "merge a float field and a text field" do
239
+ field_1 = {:allow_null=>true, :default=>nil, :primary_key=>false, :db_type=>"text", :type=>:text, :ruby_default=>nil}
240
+ field_2 = {:allow_null=>true, :default=>nil, :primary_key=>false, :db_type=>"float", :type=>:float, :ruby_default=>nil}
241
+ expected = {:type => String, :opts => {:text => true}}
242
+ assert_equal(expected, merge_fields(field_1, field_2))
243
+ assert_equal(expected, merge_fields(field_2, field_1))
244
+ end
245
+
246
+ test "merge a float field and a fixed string field" do
247
+ field_1 = {:allow_null=>true, :default=>nil, :primary_key=>false, :db_type=>"char(10)", :type=>:string, :ruby_default=>nil}
248
+ field_2 = {:allow_null=>true, :default=>nil, :primary_key=>false, :db_type=>"float", :type=>:float, :ruby_default=>nil}
249
+ expected = {:type => String, :opts => {:size => 10, :fixed => true}}
250
+ assert_equal(expected, merge_fields(field_1, field_2))
251
+ assert_equal(expected, merge_fields(field_2, field_1))
252
+ end
253
+
254
+ test "merge two decimal fields" do
255
+ field_1 = {:allow_null=>true, :default=>nil, :primary_key=>false, :db_type=>"decimal", :type=>:decimal, :ruby_default=>nil}
256
+ field_2 = {:allow_null=>true, :default=>nil, :primary_key=>false, :db_type=>"decimal", :type=>:decimal, :ruby_default=>nil}
257
+ expected = {:type => BigDecimal, :opts => {}}
258
+ assert_equal(expected, merge_fields(field_1, field_2))
259
+ assert_equal(expected, merge_fields(field_2, field_1))
260
+ end
261
+
262
+ test "merge two decimal fields, one with size" do
263
+ field_1 = {:allow_null=>true, :default=>nil, :primary_key=>false, :db_type=>"decimal(10,2)", :type=>:decimal, :ruby_default=>nil}
264
+ field_2 = {:allow_null=>true, :default=>nil, :primary_key=>false, :db_type=>"decimal", :type=>:decimal, :ruby_default=>nil}
265
+ expected = {:type => BigDecimal, :opts => {:size => [10, 2]}}
266
+ assert_equal(expected, merge_fields(field_1, field_2))
267
+ assert_equal(expected, merge_fields(field_2, field_1))
268
+ end
269
+
270
+ test "merge two decimal fields, both with size" do
271
+ field_1 = {:allow_null=>true, :default=>nil, :primary_key=>false, :db_type=>"decimal(10,2)", :type=>:decimal, :ruby_default=>nil}
272
+ field_2 = {:allow_null=>true, :default=>nil, :primary_key=>false, :db_type=>"decimal(12,1)", :type=>:decimal, :ruby_default=>nil}
273
+ expected = {:type => BigDecimal, :opts => {:size => [12, 2]}}
274
+ assert_equal(expected, merge_fields(field_1, field_2))
275
+ assert_equal(expected, merge_fields(field_2, field_1))
276
+ end
277
+
278
+ test "merge two decimal fields, both with size, one without scale" do
279
+ field_1 = {:allow_null=>true, :default=>nil, :primary_key=>false, :db_type=>"decimal(10)", :type=>:decimal, :ruby_default=>nil}
280
+ field_2 = {:allow_null=>true, :default=>nil, :primary_key=>false, :db_type=>"decimal(12,1)", :type=>:decimal, :ruby_default=>nil}
281
+ expected = {:type => BigDecimal, :opts => {:size => [12, 1]}}
282
+ assert_equal(expected, merge_fields(field_1, field_2))
283
+ assert_equal(expected, merge_fields(field_2, field_1))
284
+ end
285
+
286
+ test "merge a decimal field and a string field" do
287
+ field_1 = {:allow_null=>true, :default=>nil, :primary_key=>false, :db_type=>"varchar(10)", :type=>:string, :ruby_default=>nil}
288
+ field_2 = {:allow_null=>true, :default=>nil, :primary_key=>false, :db_type=>"decimal", :type=>:decimal, :ruby_default=>nil}
289
+ expected = {:type => String, :opts => {:size => 10}}
290
+ assert_equal(expected, merge_fields(field_1, field_2))
291
+ assert_equal(expected, merge_fields(field_2, field_1))
292
+ end
293
+
294
+ test "merge a decimal field with size and a string field" do
295
+ field_1 = {:allow_null=>true, :default=>nil, :primary_key=>false, :db_type=>"varchar(10)", :type=>:string, :ruby_default=>nil}
296
+ field_2 = {:allow_null=>true, :default=>nil, :primary_key=>false, :db_type=>"decimal(12,2)", :type=>:decimal, :ruby_default=>nil}
297
+ expected = {:type => String, :opts => {:size => 13}}
298
+ assert_equal(expected, merge_fields(field_1, field_2))
299
+ assert_equal(expected, merge_fields(field_2, field_1))
300
+ end
301
+
302
+ test "merge a decimal field and a text field" do
303
+ field_1 = {:allow_null=>true, :default=>nil, :primary_key=>false, :db_type=>"text", :type=>:text, :ruby_default=>nil}
304
+ field_2 = {:allow_null=>true, :default=>nil, :primary_key=>false, :db_type=>"decimal", :type=>:decimal, :ruby_default=>nil}
305
+ expected = {:type => String, :opts => {:text => true}}
306
+ assert_equal(expected, merge_fields(field_1, field_2))
307
+ assert_equal(expected, merge_fields(field_2, field_1))
308
+ end
309
+
310
+ test "merge a decimal field with size and a text field" do
311
+ field_1 = {:allow_null=>true, :default=>nil, :primary_key=>false, :db_type=>"text", :type=>:text, :ruby_default=>nil}
312
+ field_2 = {:allow_null=>true, :default=>nil, :primary_key=>false, :db_type=>"decimal(12,2)", :type=>:decimal, :ruby_default=>nil}
313
+ expected = {:type => String, :opts => {:text => true}}
314
+ assert_equal(expected, merge_fields(field_1, field_2))
315
+ assert_equal(expected, merge_fields(field_2, field_1))
316
+ end
317
+
318
+ test "merge a decimal field and a fixed string field" do
319
+ field_1 = {:allow_null=>true, :default=>nil, :primary_key=>false, :db_type=>"char(10)", :type=>:string, :ruby_default=>nil}
320
+ field_2 = {:allow_null=>true, :default=>nil, :primary_key=>false, :db_type=>"decimal", :type=>:decimal, :ruby_default=>nil}
321
+ expected = {:type => String, :opts => {:size => 10, :fixed => true}}
322
+ assert_equal(expected, merge_fields(field_1, field_2))
323
+ assert_equal(expected, merge_fields(field_2, field_1))
324
+ end
325
+
326
+ test "merge two string fields" do
327
+ field_1 = {:allow_null=>true, :default=>nil, :primary_key=>false, :db_type=>"varchar(20)", :type=>:string, :ruby_default=>nil}
328
+ field_2 = {:allow_null=>true, :default=>nil, :primary_key=>false, :db_type=>"varchar(20)", :type=>:string, :ruby_default=>nil}
329
+ expected = {:type => String, :opts => {:size => 20}}
330
+ assert_equal(expected, merge_fields(field_1, field_2))
331
+ assert_equal(expected, merge_fields(field_2, field_1))
332
+ end
333
+
334
+ test "merge two string fields with different sizes" do
335
+ field_1 = {:allow_null=>true, :default=>nil, :primary_key=>false, :db_type=>"varchar(15)", :type=>:string, :ruby_default=>nil}
336
+ field_2 = {:allow_null=>true, :default=>nil, :primary_key=>false, :db_type=>"varchar(20)", :type=>:string, :ruby_default=>nil}
337
+ expected = {:type => String, :opts => {:size => 20}}
338
+ assert_equal(expected, merge_fields(field_1, field_2))
339
+ assert_equal(expected, merge_fields(field_2, field_1))
340
+ end
341
+ end
metadata ADDED
@@ -0,0 +1,272 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: linkage
3
+ version: !ruby/object:Gem::Version
4
+ hash: 31
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 0
10
+ version: 0.0.0
11
+ platform: ruby
12
+ authors:
13
+ - Jeremy Stephens
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-09-30 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ requirement: &id001 !ruby/object:Gem::Requirement
22
+ none: false
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ hash: 3
27
+ segments:
28
+ - 0
29
+ version: "0"
30
+ version_requirements: *id001
31
+ name: sequel
32
+ prerelease: false
33
+ type: :runtime
34
+ - !ruby/object:Gem::Dependency
35
+ requirement: &id002 !ruby/object:Gem::Requirement
36
+ none: false
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ hash: 23
41
+ segments:
42
+ - 1
43
+ - 0
44
+ - 0
45
+ version: 1.0.0
46
+ version_requirements: *id002
47
+ name: bundler
48
+ prerelease: false
49
+ type: :development
50
+ - !ruby/object:Gem::Dependency
51
+ requirement: &id003 !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ~>
55
+ - !ruby/object:Gem::Version
56
+ hash: 7
57
+ segments:
58
+ - 1
59
+ - 6
60
+ - 4
61
+ version: 1.6.4
62
+ version_requirements: *id003
63
+ name: jeweler
64
+ prerelease: false
65
+ type: :development
66
+ - !ruby/object:Gem::Dependency
67
+ requirement: &id004 !ruby/object:Gem::Requirement
68
+ none: false
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ hash: 3
73
+ segments:
74
+ - 0
75
+ version: "0"
76
+ version_requirements: *id004
77
+ name: rcov
78
+ prerelease: false
79
+ type: :development
80
+ - !ruby/object:Gem::Dependency
81
+ requirement: &id005 !ruby/object:Gem::Requirement
82
+ none: false
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ hash: 3
87
+ segments:
88
+ - 0
89
+ version: "0"
90
+ version_requirements: *id005
91
+ name: guard-test
92
+ prerelease: false
93
+ type: :development
94
+ - !ruby/object:Gem::Dependency
95
+ requirement: &id006 !ruby/object:Gem::Requirement
96
+ none: false
97
+ requirements:
98
+ - - "="
99
+ - !ruby/object:Gem::Version
100
+ hash: 7
101
+ segments:
102
+ - 2
103
+ - 3
104
+ - 2
105
+ version: 2.3.2
106
+ version_requirements: *id006
107
+ name: test-unit
108
+ prerelease: false
109
+ type: :development
110
+ - !ruby/object:Gem::Dependency
111
+ requirement: &id007 !ruby/object:Gem::Requirement
112
+ none: false
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ hash: 3
117
+ segments:
118
+ - 0
119
+ version: "0"
120
+ version_requirements: *id007
121
+ name: mocha
122
+ prerelease: false
123
+ type: :development
124
+ - !ruby/object:Gem::Dependency
125
+ requirement: &id008 !ruby/object:Gem::Requirement
126
+ none: false
127
+ requirements:
128
+ - - ">="
129
+ - !ruby/object:Gem::Version
130
+ hash: 3
131
+ segments:
132
+ - 0
133
+ version: "0"
134
+ version_requirements: *id008
135
+ name: sqlite3
136
+ prerelease: false
137
+ type: :development
138
+ - !ruby/object:Gem::Dependency
139
+ requirement: &id009 !ruby/object:Gem::Requirement
140
+ none: false
141
+ requirements:
142
+ - - ">="
143
+ - !ruby/object:Gem::Version
144
+ hash: 3
145
+ segments:
146
+ - 0
147
+ version: "0"
148
+ version_requirements: *id009
149
+ name: yard
150
+ prerelease: false
151
+ type: :development
152
+ - !ruby/object:Gem::Dependency
153
+ requirement: &id010 !ruby/object:Gem::Requirement
154
+ none: false
155
+ requirements:
156
+ - - ">="
157
+ - !ruby/object:Gem::Version
158
+ hash: 3
159
+ segments:
160
+ - 0
161
+ version: "0"
162
+ version_requirements: *id010
163
+ name: rake
164
+ prerelease: false
165
+ type: :development
166
+ - !ruby/object:Gem::Dependency
167
+ requirement: &id011 !ruby/object:Gem::Requirement
168
+ none: false
169
+ requirements:
170
+ - - ">="
171
+ - !ruby/object:Gem::Version
172
+ hash: 3
173
+ segments:
174
+ - 0
175
+ version: "0"
176
+ version_requirements: *id011
177
+ name: versionomy
178
+ prerelease: false
179
+ type: :development
180
+ - !ruby/object:Gem::Dependency
181
+ requirement: &id012 !ruby/object:Gem::Requirement
182
+ none: false
183
+ requirements:
184
+ - - ">="
185
+ - !ruby/object:Gem::Version
186
+ hash: 3
187
+ segments:
188
+ - 0
189
+ version: "0"
190
+ version_requirements: *id012
191
+ name: guard-yard
192
+ prerelease: false
193
+ type: :development
194
+ description: Wraps Sequel to perform record linkage between one or two datasets
195
+ email: jeremy.f.stephens@vanderbilt.edu
196
+ executables: []
197
+
198
+ extensions: []
199
+
200
+ extra_rdoc_files:
201
+ - LICENSE.txt
202
+ - README.markdown
203
+ files:
204
+ - .document
205
+ - .vimrc
206
+ - Gemfile
207
+ - Gemfile.lock
208
+ - Guardfile
209
+ - LICENSE.txt
210
+ - README.markdown
211
+ - Rakefile
212
+ - VERSION
213
+ - lib/linkage.rb
214
+ - lib/linkage/configuration.rb
215
+ - lib/linkage/dataset.rb
216
+ - lib/linkage/expectation.rb
217
+ - lib/linkage/field.rb
218
+ - lib/linkage/group.rb
219
+ - lib/linkage/import_buffer.rb
220
+ - lib/linkage/runner.rb
221
+ - lib/linkage/runner/single_threaded.rb
222
+ - lib/linkage/utils.rb
223
+ - linkage.gemspec
224
+ - test/helper.rb
225
+ - test/integration/test_cross_linkage.rb
226
+ - test/integration/test_dual_linkage.rb
227
+ - test/integration/test_self_linkage.rb
228
+ - test/unit/test_configuration.rb
229
+ - test/unit/test_dataset.rb
230
+ - test/unit/test_expectation.rb
231
+ - test/unit/test_field.rb
232
+ - test/unit/test_group.rb
233
+ - test/unit/test_import_buffer.rb
234
+ - test/unit/test_linkage.rb
235
+ - test/unit/test_runner.rb
236
+ - test/unit/test_single_threaded_runner.rb
237
+ - test/unit/test_utils.rb
238
+ homepage: http://github.com/coupler/linkage
239
+ licenses:
240
+ - MIT
241
+ post_install_message:
242
+ rdoc_options: []
243
+
244
+ require_paths:
245
+ - lib
246
+ required_ruby_version: !ruby/object:Gem::Requirement
247
+ none: false
248
+ requirements:
249
+ - - ">="
250
+ - !ruby/object:Gem::Version
251
+ hash: 3
252
+ segments:
253
+ - 0
254
+ version: "0"
255
+ required_rubygems_version: !ruby/object:Gem::Requirement
256
+ none: false
257
+ requirements:
258
+ - - ">="
259
+ - !ruby/object:Gem::Version
260
+ hash: 3
261
+ segments:
262
+ - 0
263
+ version: "0"
264
+ requirements: []
265
+
266
+ rubyforge_project:
267
+ rubygems_version: 1.8.10
268
+ signing_key:
269
+ specification_version: 3
270
+ summary: Sequel-based record linkage
271
+ test_files: []
272
+