linkage 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,190 @@
1
+ require 'helper'
2
+
3
+ class UnitTests::TestFunction < Test::Unit::TestCase
4
+
5
+ def setup
6
+ super
7
+ @_functions = Linkage::Function.instance_variable_get("@functions")
8
+ end
9
+
10
+ def teardown
11
+ Linkage::Function.instance_variable_set("@functions", @_functions)
12
+ super
13
+ end
14
+
15
+ test "subclass of data" do
16
+ assert_equal Linkage::Data, Linkage::Function.superclass
17
+ end
18
+
19
+ test "function_name returns nil in base class" do
20
+ assert_raises(NotImplementedError) { Linkage::Function.function_name }
21
+ end
22
+
23
+ test "ruby_type raises not implemented error in base class" do
24
+ klass = Class.new(Linkage::Function)
25
+ klass.send(:define_singleton_method, :function_name) { "foo" }
26
+ f = klass.new
27
+ assert_raises(NotImplementedError) { f.ruby_type }
28
+ end
29
+
30
+ test "registering subclass requires non-nil function_name" do
31
+ klass = Class.new(Linkage::Function)
32
+ assert_raises(ArgumentError) { Linkage::Function.register(klass) }
33
+ end
34
+
35
+ test "registering subclass requires ruby_type" do
36
+ klass = new_function('foo')
37
+ assert_raises(ArgumentError) { Linkage::Function.register(klass) }
38
+ end
39
+
40
+ test "function with no arguments" do
41
+ klass = new_function('foo', {:type => String})
42
+ f = klass.new
43
+ assert_equal :foo, f.name
44
+ assert_equal :foo.sql_function, f.to_expr
45
+ assert f.static?
46
+ end
47
+
48
+ test "function with static value" do
49
+ klass = new_function('foo', {:type => String})
50
+ f = klass.new(123)
51
+ assert_equal :foo.sql_function(123), f.to_expr
52
+ assert_equal :foo_123, f.name
53
+ assert f.static?
54
+ end
55
+
56
+ test "function with field" do
57
+ klass = new_function('foo', {:type => String})
58
+ dataset = stub('dataset')
59
+ field = stub_field('field', :name => :bar, :ruby_type => {:type => String}, :dataset => dataset)
60
+ f = klass.new(field)
61
+ assert_equal :foo_bar, f.name
62
+ assert_equal :foo.sql_function(:bar), f.to_expr
63
+ assert !f.static?
64
+ assert_equal dataset, f.dataset
65
+ end
66
+
67
+ test "function with dynamic function" do
68
+ klass_1 = new_function('foo', {:type => String})
69
+ klass_2 = new_function('bar', {:type => String})
70
+
71
+ dataset = stub('dataset')
72
+ field = stub_field('field', :name => :baz, :ruby_type => {:type => String}, :dataset => dataset)
73
+ func_1 = klass_1.new(field)
74
+ assert_equal :foo_baz, func_1.name
75
+ assert !func_1.static?
76
+ assert_equal dataset, func_1.dataset
77
+
78
+ func_2 = klass_2.new(func_1)
79
+ assert_equal :bar_foo_baz, func_2.name
80
+ assert !func_2.static?
81
+ assert_equal :bar.sql_function(:foo.sql_function(:baz)), func_2.to_expr
82
+ assert_equal dataset, func_2.dataset
83
+ end
84
+
85
+ test "function with static function" do
86
+ klass_1 = new_function('foo', {:type => String})
87
+ klass_2 = new_function('bar', {:type => String})
88
+
89
+ dataset = stub('dataset')
90
+ func_1 = klass_1.new(123)
91
+ assert_equal :foo_123, func_1.name
92
+ assert func_1.static?
93
+
94
+ func_2 = klass_2.new(func_1)
95
+ assert_equal :bar_foo_123, func_2.name
96
+ assert_equal :bar.sql_function(:foo.sql_function(123)), func_2.to_expr
97
+ assert func_2.static?
98
+ end
99
+
100
+ test "function with mixed function arguments" do
101
+ klass_1 = new_function('foo', {:type => String})
102
+ klass_2 = new_function('bar', {:type => String})
103
+ klass_3 = new_function('baz', {:type => String})
104
+
105
+ func_1 = klass_1.new(123)
106
+ assert_equal :foo_123, func_1.name
107
+ assert func_1.static?
108
+
109
+ dataset = stub('dataset')
110
+ field = stub_field('field', :name => :quux, :ruby_type => {:type => String}, :dataset => dataset)
111
+ func_2 = klass_2.new(field)
112
+ assert_equal :bar_quux, func_2.name
113
+ assert !func_2.static?
114
+ assert_equal dataset, func_2.dataset
115
+
116
+ func_3 = klass_3.new(func_2, func_1)
117
+ assert_equal :baz_bar_quux_foo_123, func_3.name
118
+ assert !func_3.static?
119
+ assert_equal dataset, func_3.dataset
120
+ assert_equal :baz.sql_function(:bar.sql_function(:quux), :foo.sql_function(123)), func_3.to_expr
121
+ end
122
+
123
+ test "function with multiple fields" do
124
+ klass = new_function('foo', {:type => String})
125
+ dataset = stub('dataset')
126
+ field_1 = stub_field('field', :name => :bar, :ruby_type => {:type => String}, :dataset => dataset)
127
+ field_2 = stub_field('field', :name => :baz, :ruby_type => {:type => String}, :dataset => dataset)
128
+ func = klass.new(field_1, field_2)
129
+ assert_equal :foo_bar_baz, func.name
130
+ assert_equal :foo.sql_function(:bar, :baz), func.to_expr
131
+ assert !func.static?
132
+ end
133
+
134
+ test "function with multiple mixed arguments" do
135
+ klass = new_function('foo', {:type => String})
136
+ dataset = stub('dataset')
137
+ field = stub_field('field', :name => :bar, :ruby_type => {:type => String}, :dataset => dataset)
138
+ f = klass.new(field, 123, 'abc')
139
+ assert_equal :foo_bar_123_abc, f.name
140
+ assert_equal :foo.sql_function(:bar, 123, 'abc'), f.to_expr
141
+ assert_equal dataset, f.dataset
142
+ end
143
+
144
+ test "illegal function with fields from more than one dataset" do
145
+ klass = new_function('foo', {:type => String})
146
+ dataset_1 = stub('dataset 1')
147
+ dataset_2 = stub('dataset 2')
148
+ field_1 = stub_field('field', :name => :bar, :ruby_type => {:type => String}, :dataset => dataset_1)
149
+ field_2 = stub_field('field', :name => :baz, :ruby_type => {:type => String}, :dataset => dataset_2)
150
+
151
+ assert_raises(ArgumentError) do
152
+ func = klass.new(field_1, field_2)
153
+ end
154
+ end
155
+
156
+ test "fetching registered function" do
157
+ klass = new_function('foo', {:type => String})
158
+ Linkage::Function.register(klass)
159
+ assert_equal klass, Linkage::Function['foo']
160
+ end
161
+
162
+ test "valid parameters" do
163
+ func = new_function('foo', {:type => String}, [[String]])
164
+ assert_equal :foo.sql_function("foo"), func.new("foo").to_expr
165
+ field = stub_field('field', :name => :bar, :ruby_type => {:type => String})
166
+ assert_equal :foo.sql_function(:bar), func.new(field).to_expr
167
+ assert_equal :foo.sql_function(:foo.sql_function("hey")), func.new(func.new("hey")).to_expr
168
+ end
169
+
170
+ test "invalid parameters" do
171
+ func = new_function('foo', {:type => String}, [[String]])
172
+ assert_raises(TypeError) do
173
+ func.new(123)
174
+ end
175
+ field = stub_field('field', :name => :bar, :ruby_type => {:type => Integer})
176
+ assert_raises(TypeError) do
177
+ func.new(field)
178
+ end
179
+ func2 = new_function('bar', {:type => Integer})
180
+ assert_raises(TypeError) do
181
+ func.new(func2.new)
182
+ end
183
+ assert_raises(ArgumentError) do
184
+ func.new("123", "456")
185
+ end
186
+ assert_raises(ArgumentError) do
187
+ func.new
188
+ end
189
+ end
190
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: linkage
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-10-25 00:00:00.000000000Z
12
+ date: 2011-12-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: sequel
16
- requirement: &14148960 !ruby/object:Gem::Requirement
16
+ requirement: &7134200 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *14148960
24
+ version_requirements: *7134200
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: bundler
27
- requirement: &14147000 !ruby/object:Gem::Requirement
27
+ requirement: &7128660 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 1.0.0
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *14147000
35
+ version_requirements: *7128660
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: jeweler
38
- requirement: &14143380 !ruby/object:Gem::Requirement
38
+ requirement: &7140220 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: 1.6.4
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *14143380
46
+ version_requirements: *7140220
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rcov
49
- requirement: &14142120 !ruby/object:Gem::Requirement
49
+ requirement: &7137480 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,21 +54,10 @@ dependencies:
54
54
  version: '0'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *14142120
58
- - !ruby/object:Gem::Dependency
59
- name: guard-test
60
- requirement: &14139060 !ruby/object:Gem::Requirement
61
- none: false
62
- requirements:
63
- - - ! '>='
64
- - !ruby/object:Gem::Version
65
- version: '0'
66
- type: :development
67
- prerelease: false
68
- version_requirements: *14139060
57
+ version_requirements: *7137480
69
58
  - !ruby/object:Gem::Dependency
70
59
  name: test-unit
71
- requirement: &14137580 !ruby/object:Gem::Requirement
60
+ requirement: &7145460 !ruby/object:Gem::Requirement
72
61
  none: false
73
62
  requirements:
74
63
  - - =
@@ -76,10 +65,10 @@ dependencies:
76
65
  version: 2.3.2
77
66
  type: :development
78
67
  prerelease: false
79
- version_requirements: *14137580
68
+ version_requirements: *7145460
80
69
  - !ruby/object:Gem::Dependency
81
70
  name: mocha
82
- requirement: &14135540 !ruby/object:Gem::Requirement
71
+ requirement: &7153760 !ruby/object:Gem::Requirement
83
72
  none: false
84
73
  requirements:
85
74
  - - ! '>='
@@ -87,10 +76,10 @@ dependencies:
87
76
  version: '0'
88
77
  type: :development
89
78
  prerelease: false
90
- version_requirements: *14135540
79
+ version_requirements: *7153760
91
80
  - !ruby/object:Gem::Dependency
92
81
  name: sqlite3
93
- requirement: &14133820 !ruby/object:Gem::Requirement
82
+ requirement: &7165200 !ruby/object:Gem::Requirement
94
83
  none: false
95
84
  requirements:
96
85
  - - ! '>='
@@ -98,10 +87,10 @@ dependencies:
98
87
  version: '0'
99
88
  type: :development
100
89
  prerelease: false
101
- version_requirements: *14133820
90
+ version_requirements: *7165200
102
91
  - !ruby/object:Gem::Dependency
103
92
  name: yard
104
- requirement: &14132420 !ruby/object:Gem::Requirement
93
+ requirement: &7162960 !ruby/object:Gem::Requirement
105
94
  none: false
106
95
  requirements:
107
96
  - - ! '>='
@@ -109,10 +98,10 @@ dependencies:
109
98
  version: '0'
110
99
  type: :development
111
100
  prerelease: false
112
- version_requirements: *14132420
101
+ version_requirements: *7162960
113
102
  - !ruby/object:Gem::Dependency
114
103
  name: rake
115
- requirement: &14130000 !ruby/object:Gem::Requirement
104
+ requirement: &7161840 !ruby/object:Gem::Requirement
116
105
  none: false
117
106
  requirements:
118
107
  - - ! '>='
@@ -120,10 +109,32 @@ dependencies:
120
109
  version: '0'
121
110
  type: :development
122
111
  prerelease: false
123
- version_requirements: *14130000
112
+ version_requirements: *7161840
124
113
  - !ruby/object:Gem::Dependency
125
114
  name: versionomy
126
- requirement: &14129120 !ruby/object:Gem::Requirement
115
+ requirement: &7176680 !ruby/object:Gem::Requirement
116
+ none: false
117
+ requirements:
118
+ - - ! '>='
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
121
+ type: :development
122
+ prerelease: false
123
+ version_requirements: *7176680
124
+ - !ruby/object:Gem::Dependency
125
+ name: mysql2
126
+ requirement: &7175420 !ruby/object:Gem::Requirement
127
+ none: false
128
+ requirements:
129
+ - - ! '>='
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: *7175420
135
+ - !ruby/object:Gem::Dependency
136
+ name: pry
137
+ requirement: &7171460 !ruby/object:Gem::Requirement
127
138
  none: false
128
139
  requirements:
129
140
  - - ! '>='
@@ -131,10 +142,10 @@ dependencies:
131
142
  version: '0'
132
143
  type: :development
133
144
  prerelease: false
134
- version_requirements: *14129120
145
+ version_requirements: *7171460
135
146
  - !ruby/object:Gem::Dependency
136
- name: guard-yard
137
- requirement: &14127660 !ruby/object:Gem::Requirement
147
+ name: rdiscount
148
+ requirement: &7170260 !ruby/object:Gem::Requirement
138
149
  none: false
139
150
  requirements:
140
151
  - - ! '>='
@@ -142,7 +153,7 @@ dependencies:
142
153
  version: '0'
143
154
  type: :development
144
155
  prerelease: false
145
- version_requirements: *14127660
156
+ version_requirements: *7170260
146
157
  description: Wraps Sequel to perform record linkage between one or two datasets
147
158
  email: jeremy.f.stephens@vanderbilt.edu
148
159
  executables: []
@@ -162,28 +173,36 @@ files:
162
173
  - VERSION
163
174
  - lib/linkage.rb
164
175
  - lib/linkage/configuration.rb
176
+ - lib/linkage/data.rb
165
177
  - lib/linkage/dataset.rb
166
178
  - lib/linkage/expectation.rb
167
179
  - lib/linkage/field.rb
180
+ - lib/linkage/function.rb
181
+ - lib/linkage/functions/trim.rb
168
182
  - lib/linkage/group.rb
169
183
  - lib/linkage/import_buffer.rb
170
184
  - lib/linkage/runner.rb
171
185
  - lib/linkage/runner/single_threaded.rb
172
186
  - lib/linkage/utils.rb
187
+ - lib/linkage/warnings.rb
173
188
  - linkage.gemspec
189
+ - test/config.yml
174
190
  - test/helper.rb
175
191
  - test/integration/test_cross_linkage.rb
176
192
  - test/integration/test_dual_linkage.rb
177
193
  - test/integration/test_self_linkage.rb
194
+ - test/unit/functions/test_trim.rb
195
+ - test/unit/runner/test_single_threaded.rb
178
196
  - test/unit/test_configuration.rb
197
+ - test/unit/test_data.rb
179
198
  - test/unit/test_dataset.rb
180
199
  - test/unit/test_expectation.rb
181
200
  - test/unit/test_field.rb
201
+ - test/unit/test_function.rb
182
202
  - test/unit/test_group.rb
183
203
  - test/unit/test_import_buffer.rb
184
204
  - test/unit/test_linkage.rb
185
205
  - test/unit/test_runner.rb
186
- - test/unit/test_single_threaded_runner.rb
187
206
  - test/unit/test_utils.rb
188
207
  homepage: http://github.com/coupler/linkage
189
208
  licenses:
@@ -200,7 +219,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
200
219
  version: '0'
201
220
  segments:
202
221
  - 0
203
- hash: 2889761151257020688
222
+ hash: 3999364823081997349
204
223
  required_rubygems_version: !ruby/object:Gem::Requirement
205
224
  none: false
206
225
  requirements:
@@ -209,7 +228,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
209
228
  version: '0'
210
229
  requirements: []
211
230
  rubyforge_project:
212
- rubygems_version: 1.8.10
231
+ rubygems_version: 1.8.11
213
232
  signing_key:
214
233
  specification_version: 3
215
234
  summary: Sequel-based record linkage