linkage 0.0.8 → 0.1.0.pre

Sign up to get free protection for your applications and to get access to all the features.
Files changed (105) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +1 -0
  3. data/.yardopts +1 -0
  4. data/Gemfile +1 -19
  5. data/Gemfile-java +3 -0
  6. data/README.markdown +88 -34
  7. data/Rakefile +16 -15
  8. data/TODO +4 -0
  9. data/lib/linkage/comparator.rb +139 -144
  10. data/lib/linkage/comparators/compare.rb +236 -29
  11. data/lib/linkage/comparators/strcompare.rb +85 -0
  12. data/lib/linkage/comparators/within.rb +24 -20
  13. data/lib/linkage/configuration.rb +44 -466
  14. data/lib/linkage/dataset.rb +28 -127
  15. data/lib/linkage/exceptions.rb +5 -0
  16. data/lib/linkage/field.rb +6 -37
  17. data/lib/linkage/field_set.rb +3 -3
  18. data/lib/linkage/match_recorder.rb +22 -0
  19. data/lib/linkage/match_set.rb +34 -0
  20. data/lib/linkage/match_sets/csv.rb +39 -0
  21. data/lib/linkage/match_sets/database.rb +45 -0
  22. data/lib/linkage/matcher.rb +30 -0
  23. data/lib/linkage/result_set.rb +25 -110
  24. data/lib/linkage/result_sets/csv.rb +54 -0
  25. data/lib/linkage/result_sets/database.rb +42 -0
  26. data/lib/linkage/runner.rb +57 -16
  27. data/lib/linkage/score_recorder.rb +30 -0
  28. data/lib/linkage/score_set.rb +49 -0
  29. data/lib/linkage/score_sets/csv.rb +64 -0
  30. data/lib/linkage/score_sets/database.rb +77 -0
  31. data/lib/linkage/version.rb +1 -1
  32. data/lib/linkage.rb +14 -17
  33. data/linkage.gemspec +13 -1
  34. data/linkage.gemspec-java +32 -0
  35. data/test/helper.rb +30 -23
  36. data/test/integration/test_cross_linkage.rb +46 -25
  37. data/test/integration/test_database_result_set.rb +55 -0
  38. data/test/integration/test_dual_linkage.rb +19 -94
  39. data/test/integration/test_self_linkage.rb +100 -203
  40. data/test/integration/test_within_comparator.rb +24 -77
  41. data/test/unit/comparators/test_compare.rb +254 -50
  42. data/test/unit/comparators/test_strcompare.rb +45 -0
  43. data/test/unit/comparators/test_within.rb +14 -26
  44. data/test/unit/match_sets/test_csv.rb +78 -0
  45. data/test/unit/match_sets/test_database.rb +63 -0
  46. data/test/unit/result_sets/test_csv.rb +111 -0
  47. data/test/unit/result_sets/test_database.rb +68 -0
  48. data/test/unit/score_sets/test_csv.rb +151 -0
  49. data/test/unit/score_sets/test_database.rb +149 -0
  50. data/test/unit/test_comparator.rb +46 -83
  51. data/test/unit/test_comparators.rb +4 -0
  52. data/test/unit/test_configuration.rb +99 -145
  53. data/test/unit/test_dataset.rb +52 -73
  54. data/test/unit/test_field.rb +4 -55
  55. data/test/unit/test_field_set.rb +6 -6
  56. data/test/unit/test_match_recorder.rb +23 -0
  57. data/test/unit/test_match_set.rb +23 -0
  58. data/test/unit/test_match_sets.rb +4 -0
  59. data/test/unit/test_matcher.rb +44 -0
  60. data/test/unit/test_result_set.rb +24 -223
  61. data/test/unit/test_result_sets.rb +4 -0
  62. data/test/unit/test_runner.rb +122 -17
  63. data/test/unit/test_runners.rb +4 -0
  64. data/test/unit/test_score_recorder.rb +25 -0
  65. data/test/unit/test_score_set.rb +37 -0
  66. data/test/unit/test_score_sets.rb +4 -0
  67. metadata +183 -90
  68. data/Gemfile.lock +0 -92
  69. data/lib/linkage/comparators/binary.rb +0 -12
  70. data/lib/linkage/data.rb +0 -175
  71. data/lib/linkage/decollation.rb +0 -93
  72. data/lib/linkage/expectation.rb +0 -21
  73. data/lib/linkage/expectations/exhaustive.rb +0 -63
  74. data/lib/linkage/expectations/simple.rb +0 -168
  75. data/lib/linkage/function.rb +0 -148
  76. data/lib/linkage/functions/binary.rb +0 -30
  77. data/lib/linkage/functions/cast.rb +0 -54
  78. data/lib/linkage/functions/length.rb +0 -29
  79. data/lib/linkage/functions/strftime.rb +0 -33
  80. data/lib/linkage/functions/trim.rb +0 -30
  81. data/lib/linkage/group.rb +0 -55
  82. data/lib/linkage/meta_object.rb +0 -139
  83. data/lib/linkage/runner/single_threaded.rb +0 -187
  84. data/lib/linkage/utils.rb +0 -164
  85. data/lib/linkage/warnings.rb +0 -5
  86. data/test/integration/test_collation.rb +0 -45
  87. data/test/integration/test_configuration.rb +0 -268
  88. data/test/integration/test_dataset.rb +0 -116
  89. data/test/integration/test_functions.rb +0 -88
  90. data/test/integration/test_result_set.rb +0 -85
  91. data/test/integration/test_scoring.rb +0 -84
  92. data/test/unit/expectations/test_exhaustive.rb +0 -111
  93. data/test/unit/expectations/test_simple.rb +0 -303
  94. data/test/unit/functions/test_binary.rb +0 -54
  95. data/test/unit/functions/test_cast.rb +0 -98
  96. data/test/unit/functions/test_length.rb +0 -52
  97. data/test/unit/functions/test_strftime.rb +0 -60
  98. data/test/unit/functions/test_trim.rb +0 -43
  99. data/test/unit/runner/test_single_threaded.rb +0 -12
  100. data/test/unit/test_data.rb +0 -445
  101. data/test/unit/test_decollation.rb +0 -201
  102. data/test/unit/test_function.rb +0 -233
  103. data/test/unit/test_group.rb +0 -38
  104. data/test/unit/test_meta_object.rb +0 -208
  105. data/test/unit/test_utils.rb +0 -341
@@ -1,43 +0,0 @@
1
- require 'helper'
2
-
3
- class UnitTests::TestTrim < Test::Unit::TestCase
4
- test "subclass of Function" do
5
- assert_equal Linkage::Function, Linkage::Functions::Trim.superclass
6
- end
7
-
8
- test "ruby_type for string literal" do
9
- trim = Linkage::Functions::Trim.new("foo", :dataset => stub('dataset'))
10
- assert_equal({:type => String}, trim.ruby_type)
11
- end
12
-
13
- test "ruby_type for string field" do
14
- field_1 = stub_field('field 1', :name => :bar, :ruby_type => {:type => String}, :dataset => stub('dataset'))
15
- assert_equal({:type => String}, Linkage::Functions::Trim.new(field_1).ruby_type)
16
-
17
- field_2 = stub_field('field 2', :name => :bar, :ruby_type => {:type => String, :opts => {:size => 123}}, :dataset => stub('dataset'))
18
- assert_equal({:type => String, :opts => {:size => 123}}, Linkage::Functions::Trim.new(field_2).ruby_type)
19
- end
20
-
21
- test "ruby_type for string function" do
22
- func = new_function('foo', {:type => String, :opts => {:junk => '123'}})
23
- assert_equal({:type => String, :opts => {:junk => '123'}}, Linkage::Functions::Trim.new(func.new(:dataset => stub('dataset'))).ruby_type)
24
- end
25
-
26
- test "parameters" do
27
- assert_equal [[String]], Linkage::Functions::Trim.parameters
28
- end
29
-
30
- test "name" do
31
- assert_equal "trim", Linkage::Functions::Trim.function_name
32
- end
33
-
34
- test "registers itself" do
35
- assert_equal Linkage::Function["trim"], Linkage::Functions::Trim
36
- end
37
-
38
- test "collation returns argument collation if it exists" do
39
- field_1 = stub_field('field 1', :name => :bar, :ruby_type => {:type => String}, :collation => 'foo', :dataset => stub('dataset'))
40
- trim = Linkage::Functions::Trim.new(field_1)
41
- assert_equal 'foo', trim.collation
42
- end
43
- end
@@ -1,12 +0,0 @@
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
@@ -1,445 +0,0 @@
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 "to_expr raises NotImplementedError" do
23
- d = Linkage::Data.new(:foo)
24
- assert_raises(NotImplementedError) { d.to_expr }
25
- end
26
-
27
- test "database_type" do
28
- dataset = mock('dataset')
29
- data_1 = new_data(:foo, {}, dataset)
30
- dataset.expects(:database_type).returns(:mysql)
31
- assert_equal :mysql, data_1.database_type
32
- end
33
-
34
- test "merge two identical fields" do
35
- data_1 = new_data(:id, {:type =>Integer})
36
- data_2 = new_data(:id, {:type =>Integer})
37
- expected_type = {:type => Integer}
38
-
39
- result_data = data_1.merge(data_2)
40
- assert_equal(:id, result_data.name)
41
- assert_equal(expected_type, result_data.ruby_type)
42
-
43
- result_data = data_2.merge(data_1)
44
- assert_equal(:id, result_data.name)
45
- assert_equal(expected_type, result_data.ruby_type)
46
- end
47
-
48
- test "merge fields with different names" do
49
- data_1 = new_data(:foo, {:type => Integer})
50
- data_2 = new_data(:bar, {:type => Integer})
51
-
52
- result_data = data_1.merge(data_2)
53
- assert_equal(:foo_bar, result_data.name)
54
- result_data = data_2.merge(data_1)
55
- assert_equal(:bar_foo, result_data.name)
56
- end
57
-
58
- test "merge two boolean fields" do
59
- data_1 = new_data(:foo, {:type => TrueClass})
60
- data_2 = new_data(:foo, {:type => TrueClass})
61
- expected_type = {:type => TrueClass}
62
-
63
- result_data = data_1.merge(data_2)
64
- assert_equal(:foo, result_data.name)
65
- assert_equal(expected_type, result_data.ruby_type)
66
-
67
- result_data = data_2.merge(data_1)
68
- assert_equal(:foo, result_data.name)
69
- assert_equal(expected_type, result_data.ruby_type)
70
- end
71
-
72
- test "merge a boolean field and an integer field" do
73
- data_1 = new_data(:foo, {:type => Integer})
74
- data_2 = new_data(:foo, {:type => TrueClass})
75
- expected_type = {:type => Integer}
76
- assert_equal(expected_type, data_1.merge(data_2).ruby_type)
77
- assert_equal(expected_type, data_2.merge(data_1).ruby_type)
78
- end
79
-
80
- test "merge a boolean field and a bignum field" do
81
- data_1 = new_data(:foo, {:type => Bignum})
82
- data_2 = new_data(:foo, {:type => TrueClass})
83
- expected_type = {:type => Bignum}
84
- assert_equal(expected_type, data_1.merge(data_2).ruby_type)
85
- assert_equal(expected_type, data_2.merge(data_1).ruby_type)
86
- end
87
-
88
- test "merge a boolean field and a float field" do
89
- data_1 = new_data(:foo, {:type => Float})
90
- data_2 = new_data(:foo, {:type => TrueClass})
91
- expected_type = {:type => Float}
92
- assert_equal(expected_type, data_1.merge(data_2).ruby_type)
93
- assert_equal(expected_type, data_2.merge(data_1).ruby_type)
94
- end
95
-
96
- test "merge a boolean field and a decimal field" do
97
- data_1 = new_data(:foo, {:type => BigDecimal})
98
- data_2 = new_data(:foo, {:type => TrueClass})
99
- expected_type = {:type => BigDecimal}
100
- assert_equal(expected_type, data_1.merge(data_2).ruby_type)
101
- assert_equal(expected_type, data_2.merge(data_1).ruby_type)
102
- end
103
-
104
- test "merge a boolean field and a decimal field with size" do
105
- data_1 = new_data(:foo, {:type => BigDecimal, :opts => {:size => [10, 2]}})
106
- data_2 = new_data(:foo, {:type => TrueClass})
107
- expected_type = {:type => BigDecimal, :opts => {:size => [10, 2]}}
108
- assert_equal(expected_type, data_1.merge(data_2).ruby_type)
109
- assert_equal(expected_type, data_2.merge(data_1).ruby_type)
110
- end
111
-
112
- test "merge a boolean field and a string field" do
113
- data_1 = new_data(:foo, {:type => String, :opts => {:size => 10}})
114
- data_2 = new_data(:foo, {:type => TrueClass})
115
- expected_type = {:type => String, :opts => {:size => 10}}
116
- assert_equal(expected_type, data_1.merge(data_2).ruby_type)
117
- assert_equal(expected_type, data_2.merge(data_1).ruby_type)
118
- end
119
-
120
- test "merge a boolean field and a text field" do
121
- data_1 = new_data(:foo, {:type => String, :opts => {:text => true}})
122
- data_2 = new_data(:foo, {:type => TrueClass})
123
- expected_type = {:type => String, :opts => {:text => true}}
124
- assert_equal(expected_type, data_1.merge(data_2).ruby_type)
125
- assert_equal(expected_type, data_2.merge(data_1).ruby_type)
126
- end
127
-
128
- test "merge a boolean field and a fixed string field" do
129
- data_1 = new_data(:foo, {:type => String, :opts => {:size => 10, :fixed => true}})
130
- data_2 = new_data(:foo, {:type => TrueClass})
131
- expected_type = {:type => String, :opts => {:size => 10, :fixed => true}}
132
- assert_equal(expected_type, data_1.merge(data_2).ruby_type)
133
- assert_equal(expected_type, data_2.merge(data_1).ruby_type)
134
- end
135
-
136
- test "merge two integer fields" do
137
- data_1 = new_data(:foo, {:type => Integer})
138
- data_2 = new_data(:foo, {:type => Integer})
139
- expected_type = {:type => Integer}
140
- assert_equal(expected_type, data_1.merge(data_2).ruby_type)
141
- assert_equal(expected_type, data_2.merge(data_1).ruby_type)
142
- end
143
-
144
- test "merge an integer field and a bignum field" do
145
- data_1 = new_data(:foo, {:type => Bignum})
146
- data_2 = new_data(:foo, {:type => Integer})
147
- expected_type = {:type => Bignum}
148
- assert_equal(expected_type, data_1.merge(data_2).ruby_type)
149
- assert_equal(expected_type, data_2.merge(data_1).ruby_type)
150
- end
151
-
152
- test "merge an integer field and a float field" do
153
- data_1 = new_data(:foo, {:type => Float})
154
- data_2 = new_data(:foo, {:type => Integer})
155
- expected_type = {:type => Float}
156
- assert_equal(expected_type, data_1.merge(data_2).ruby_type)
157
- assert_equal(expected_type, data_2.merge(data_1).ruby_type)
158
- end
159
-
160
- test "merge an integer field and a decimal field" do
161
- data_1 = new_data(:foo, {:type => BigDecimal})
162
- data_2 = new_data(:foo, {:type => Integer})
163
- expected_type = {:type => BigDecimal}
164
- assert_equal(expected_type, data_1.merge(data_2).ruby_type)
165
- assert_equal(expected_type, data_2.merge(data_1).ruby_type)
166
- end
167
-
168
- test "merge an integer field and a decimal field with size" do
169
- data_1 = new_data(:foo, {:type => BigDecimal, :opts => {:size => [10, 2]}})
170
- data_2 = new_data(:foo, {:type => Integer})
171
- expected_type = {:type => BigDecimal, :opts => {:size => [10, 2]}}
172
- assert_equal(expected_type, data_1.merge(data_2).ruby_type)
173
- assert_equal(expected_type, data_2.merge(data_1).ruby_type)
174
- end
175
-
176
- test "merge an integer field and a string field" do
177
- data_1 = new_data(:foo, {:type => String, :opts => {:size => 10}})
178
- data_2 = new_data(:foo, {:type => Integer})
179
- expected_type = {:type => String, :opts => {:size => 10}}
180
- assert_equal(expected_type, data_1.merge(data_2).ruby_type)
181
- assert_equal(expected_type, data_2.merge(data_1).ruby_type)
182
- end
183
-
184
- test "merge an integer field and a text field" do
185
- data_1 = new_data(:foo, {:type => String, :opts => {:text => true}})
186
- data_2 = new_data(:foo, {:type => Integer})
187
- expected_type = {:type => String, :opts => {:text => true}}
188
- assert_equal(expected_type, data_1.merge(data_2).ruby_type)
189
- assert_equal(expected_type, data_2.merge(data_1).ruby_type)
190
- end
191
-
192
- test "merge an integer field and a fixed string field" do
193
- data_1 = new_data(:foo, {:type => String, :opts => {:size => 10, :fixed => true}})
194
- data_2 = new_data(:foo, {:type => Integer})
195
- expected_type = {:type => String, :opts => {:size => 10, :fixed => true}}
196
- assert_equal(expected_type, data_1.merge(data_2).ruby_type)
197
- assert_equal(expected_type, data_2.merge(data_1).ruby_type)
198
- end
199
-
200
- test "merge two bignum fields" do
201
- data_1 = new_data(:foo, {:type => Bignum})
202
- data_2 = new_data(:foo, {:type => Bignum})
203
- expected_type = {:type => Bignum}
204
- assert_equal(expected_type, data_1.merge(data_2).ruby_type)
205
- assert_equal(expected_type, data_2.merge(data_1).ruby_type)
206
- end
207
-
208
- test "merge an bignum field and a decimal field" do
209
- data_1 = new_data(:foo, {:type => BigDecimal})
210
- data_2 = new_data(:foo, {:type => Bignum})
211
- expected_type = {:type => BigDecimal}
212
- assert_equal(expected_type, data_1.merge(data_2).ruby_type)
213
- assert_equal(expected_type, data_2.merge(data_1).ruby_type)
214
- end
215
-
216
- test "merge an bignum field and a decimal field with size" do
217
- data_1 = new_data(:foo, {:type => BigDecimal, :opts => {:size => [10, 2]}})
218
- data_2 = new_data(:foo, {:type => Bignum})
219
- expected_type = {:type => BigDecimal, :opts => {:size => [10, 2]}}
220
- assert_equal(expected_type, data_1.merge(data_2).ruby_type)
221
- assert_equal(expected_type, data_2.merge(data_1).ruby_type)
222
- end
223
-
224
- test "merge an bignum field and a string field" do
225
- data_1 = new_data(:foo, {:type => String, :opts => {:size => 10}})
226
- data_2 = new_data(:foo, {:type => Bignum})
227
- expected_type = {:type => String, :opts => {:size => 10}}
228
- assert_equal(expected_type, data_1.merge(data_2).ruby_type)
229
- assert_equal(expected_type, data_2.merge(data_1).ruby_type)
230
- end
231
-
232
- test "merge an bignum field and a text field" do
233
- data_1 = new_data(:foo, {:type => String, :opts => {:text => true}})
234
- data_2 = new_data(:foo, {:type => Bignum})
235
- expected_type = {:type => String, :opts => {:text => true}}
236
- assert_equal(expected_type, data_1.merge(data_2).ruby_type)
237
- assert_equal(expected_type, data_2.merge(data_1).ruby_type)
238
- end
239
-
240
- test "merge an bignum field and a fixed string field" do
241
- data_1 = new_data(:foo, {:type => String, :opts => {:size => 10, :fixed => true}})
242
- data_2 = new_data(:foo, {:type => Bignum})
243
- expected_type = {:type => String, :opts => {:size => 10, :fixed => true}}
244
- assert_equal(expected_type, data_1.merge(data_2).ruby_type)
245
- assert_equal(expected_type, data_2.merge(data_1).ruby_type)
246
- end
247
-
248
- test "merge two float fields" do
249
- data_1 = new_data(:foo, {:type => Float})
250
- data_2 = new_data(:foo, {:type => Float})
251
- expected_type = {:type => Float}
252
- assert_equal(expected_type, data_1.merge(data_2).ruby_type)
253
- assert_equal(expected_type, data_2.merge(data_1).ruby_type)
254
- end
255
-
256
- test "merge a float field and a bignum field" do
257
- data_1 = new_data(:foo, {:type => Bignum})
258
- data_2 = new_data(:foo, {:type => Float})
259
- expected_type = {:type => BigDecimal}
260
- assert_equal(expected_type, data_1.merge(data_2).ruby_type)
261
- assert_equal(expected_type, data_2.merge(data_1).ruby_type)
262
- end
263
-
264
- test "merge a float field and a decimal field" do
265
- data_1 = new_data(:foo, {:type => BigDecimal})
266
- data_2 = new_data(:foo, {:type => Float})
267
- expected_type = {:type => BigDecimal}
268
- assert_equal(expected_type, data_1.merge(data_2).ruby_type)
269
- assert_equal(expected_type, data_2.merge(data_1).ruby_type)
270
- end
271
-
272
- test "merge a float field and a decimal field with size" do
273
- data_1 = new_data(:foo, {:type => BigDecimal, :opts => {:size => [10, 2]}})
274
- data_2 = new_data(:foo, {:type => Float})
275
- expected_type = {:type => BigDecimal, :opts => {:size => [10, 2]}}
276
- assert_equal(expected_type, data_1.merge(data_2).ruby_type)
277
- assert_equal(expected_type, data_2.merge(data_1).ruby_type)
278
- end
279
-
280
- test "merge a float field and a string field" do
281
- data_1 = new_data(:foo, {:type => String, :opts => {:size => 10}})
282
- data_2 = new_data(:foo, {:type => Float})
283
- expected_type = {:type => String, :opts => {:size => 10}}
284
- assert_equal(expected_type, data_1.merge(data_2).ruby_type)
285
- assert_equal(expected_type, data_2.merge(data_1).ruby_type)
286
- end
287
-
288
- test "merge a float field and a text field" do
289
- data_1 = new_data(:foo, {:type => String, :opts => {:text => true}})
290
- data_2 = new_data(:foo, {:type => Float})
291
- expected_type = {:type => String, :opts => {:text => true}}
292
- assert_equal(expected_type, data_1.merge(data_2).ruby_type)
293
- assert_equal(expected_type, data_2.merge(data_1).ruby_type)
294
- end
295
-
296
- test "merge a float field and a fixed string field" do
297
- data_1 = new_data(:foo, {:type => String, :opts => {:size => 10, :fixed => true}})
298
- data_2 = new_data(:foo, {:type => Float})
299
- expected_type = {:type => String, :opts => {:size => 10, :fixed => true}}
300
- assert_equal(expected_type, data_1.merge(data_2).ruby_type)
301
- assert_equal(expected_type, data_2.merge(data_1).ruby_type)
302
- end
303
-
304
- test "merge two decimal fields" do
305
- data_1 = new_data(:foo, {:type => BigDecimal})
306
- data_2 = new_data(:foo, {:type => BigDecimal})
307
- expected_type = {:type => BigDecimal}
308
- assert_equal(expected_type, data_1.merge(data_2).ruby_type)
309
- assert_equal(expected_type, data_2.merge(data_1).ruby_type)
310
- end
311
-
312
- test "merge two decimal fields, one with size" do
313
- data_1 = new_data(:foo, {:type => BigDecimal, :opts => {:size => [10, 2]}})
314
- data_2 = new_data(:foo, {:type => BigDecimal})
315
- expected_type = {:type => BigDecimal, :opts => {:size => [10, 2]}}
316
- assert_equal(expected_type, data_1.merge(data_2).ruby_type)
317
- assert_equal(expected_type, data_2.merge(data_1).ruby_type)
318
- end
319
-
320
- test "merge two decimal fields, both with size" do
321
- data_1 = new_data(:foo, {:type => BigDecimal, :opts => {:size => [10, 2]}})
322
- data_2 = new_data(:foo, {:type => BigDecimal, :opts => {:size => [12, 1]}})
323
- expected_type = {:type => BigDecimal, :opts => {:size => [12, 2]}}
324
- assert_equal(expected_type, data_1.merge(data_2).ruby_type)
325
- assert_equal(expected_type, data_2.merge(data_1).ruby_type)
326
- end
327
-
328
- test "merge two decimal fields, both with size, one without scale" do
329
- data_1 = new_data(:foo, {:type => BigDecimal, :opts => {:size => [10]}})
330
- data_2 = new_data(:foo, {:type => BigDecimal, :opts => {:size => [12, 1]}})
331
- expected_type = {:type => BigDecimal, :opts => {:size => [12, 1]}}
332
- assert_equal(expected_type, data_1.merge(data_2).ruby_type)
333
- assert_equal(expected_type, data_2.merge(data_1).ruby_type)
334
- end
335
-
336
- test "merge a decimal field and a string field" do
337
- data_1 = new_data(:foo, {:type => String, :opts => {:size => 10}})
338
- data_2 = new_data(:foo, {:type => BigDecimal})
339
- expected_type = {:type => String, :opts => {:size => 10}}
340
- assert_equal(expected_type, data_1.merge(data_2).ruby_type)
341
- assert_equal(expected_type, data_2.merge(data_1).ruby_type)
342
- end
343
-
344
- test "merge a decimal field with size and a string field" do
345
- data_1 = new_data(:foo, {:type => String, :opts => {:size => 10}})
346
- data_2 = new_data(:foo, {:type => BigDecimal, :opts => {:size => [12, 2]}})
347
- expected_type = {:type => String, :opts => {:size => 13}}
348
- assert_equal(expected_type, data_1.merge(data_2).ruby_type)
349
- assert_equal(expected_type, data_2.merge(data_1).ruby_type)
350
- end
351
-
352
- test "merge a decimal field and a text field" do
353
- data_1 = new_data(:foo, {:type => String, :opts => {:text => true}})
354
- data_2 = new_data(:foo, {:type => BigDecimal})
355
- expected_type = {:type => String, :opts => {:text => true}}
356
- assert_equal(expected_type, data_1.merge(data_2).ruby_type)
357
- assert_equal(expected_type, data_2.merge(data_1).ruby_type)
358
- end
359
-
360
- test "merge a decimal field with size and a text field" do
361
- data_1 = new_data(:foo, {:type => String, :opts => {:text => true}})
362
- data_2 = new_data(:foo, {:type => BigDecimal, :opts => {:size => [12, 2]}})
363
- expected_type = {:type => String, :opts => {:text => true}}
364
- assert_equal(expected_type, data_1.merge(data_2).ruby_type)
365
- assert_equal(expected_type, data_2.merge(data_1).ruby_type)
366
- end
367
-
368
- test "merge a decimal field and a fixed string field" do
369
- data_1 = new_data(:foo, {:type => String, :opts => {:size => 10, :fixed => true}})
370
- data_2 = new_data(:foo, {:type => BigDecimal})
371
- expected_type = {:type => String, :opts => {:size => 10, :fixed => true}}
372
- assert_equal(expected_type, data_1.merge(data_2).ruby_type)
373
- assert_equal(expected_type, data_2.merge(data_1).ruby_type)
374
- end
375
-
376
- test "merge two string fields" do
377
- data_1 = new_data(:foo, {:type => String, :opts => {:size => 20}})
378
- data_2 = new_data(:foo, {:type => String, :opts => {:size => 20}})
379
- expected_type = {:type => String, :opts => {:size => 20}}
380
- assert_equal(expected_type, data_1.merge(data_2).ruby_type)
381
- assert_equal(expected_type, data_2.merge(data_1).ruby_type)
382
- end
383
-
384
- test "merge two string fields with different sizes" do
385
- data_1 = new_data(:foo, {:type => String, :opts => {:size => 15}})
386
- data_2 = new_data(:foo, {:type => String, :opts => {:size => 20}})
387
- expected_type = {:type => String, :opts => {:size => 20}}
388
- assert_equal(expected_type, data_1.merge(data_2).ruby_type)
389
- assert_equal(expected_type, data_2.merge(data_1).ruby_type)
390
- end
391
-
392
- test "merge two fields and specify name" do
393
- data_1 = new_data(:id, {:type => Integer})
394
- data_2 = new_data(:id, {:type => Integer})
395
-
396
- result_data = data_1.merge(data_2, 'foo')
397
- assert_equal :foo, result_data.name
398
-
399
- result_data = data_2.merge(data_1, 'foo')
400
- assert_equal :foo, result_data.name
401
- end
402
-
403
- test "merge a string field and a date field" do
404
- data_1 = new_data(:foo, {:type => String})
405
- data_2 = new_data(:foo, {:type => Date})
406
- assert_raises { data_1.merge(data_2).ruby_type }
407
- end
408
-
409
- test "merging two string fields with different collations strips the collation" do
410
- dataset_1 = stub('dataset 1', :database_type => :mysql)
411
- data_1 = new_data(:foo, {:type => String, :opts => {:collate => :foo}}, dataset_1)
412
- dataset_2 = stub('dataset 2', :database_type => :mysql)
413
- data_2 = new_data(:foo, {:type => String, :opts => {:collate => :bar}}, dataset_2)
414
-
415
- result_data = data_1.merge(data_2)
416
- result_opts = result_data.ruby_type[:opts] || {}
417
- assert_nil result_opts[:collate]
418
- end
419
-
420
- test "merging two string fields with different database types strips the collation" do
421
- dataset_1 = stub('dataset 1', :database_type => :mysql)
422
- data_1 = new_data(:foo, {:type => String, :opts => {:collate => :foo}}, dataset_1)
423
- dataset_2 = stub('dataset 2', :database_type => :sqlite)
424
- data_2 = new_data(:foo, {:type => String, :opts => {:collate => :foo}}, dataset_2)
425
-
426
- result_data = data_1.merge(data_2)
427
- result_opts = result_data.ruby_type[:opts] || {}
428
- assert_nil result_opts[:collate]
429
- end
430
-
431
- test "merged field has database type if they're the same" do
432
- dataset_1 = stub('dataset 1', :database_type => :mysql)
433
- data_1 = new_data(:foo, {:type => String}, dataset_1)
434
- dataset_2 = stub('dataset 2', :database_type => :mysql)
435
- data_2 = new_data(:foo, {:type => String}, dataset_2)
436
- result_data = data_1.merge(data_2)
437
- assert_equal :mysql, result_data.database_type
438
- end
439
-
440
- test "collation returns nil by default" do
441
- dataset = stub('dataset')
442
- data = new_data(:foo, {:type => String}, dataset)
443
- assert_nil data.collation
444
- end
445
- end