mutations 0.5.12 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- data/{.travis → .travis.yml} +3 -0
- data/CHANGELOG.md +10 -2
- data/Gemfile +5 -2
- data/README.md +1 -0
- data/TODO +1 -3
- data/lib/mutations.rb +14 -1
- data/lib/mutations/additional_filter.rb +13 -0
- data/lib/mutations/array_filter.rb +12 -30
- data/lib/mutations/boolean_filter.rb +3 -3
- data/lib/mutations/command.rb +5 -4
- data/lib/mutations/date_filter.rb +52 -0
- data/lib/mutations/duck_filter.rb +4 -4
- data/lib/mutations/errors.rb +24 -20
- data/lib/mutations/exception.rb +1 -1
- data/lib/mutations/file_filter.rb +7 -7
- data/lib/mutations/float_filter.rb +5 -5
- data/lib/mutations/hash_filter.rb +12 -29
- data/lib/mutations/integer_filter.rb +5 -5
- data/lib/mutations/model_filter.rb +13 -8
- data/lib/mutations/outcome.rb +1 -1
- data/lib/mutations/string_filter.rb +10 -10
- data/lib/mutations/version.rb +2 -2
- data/mutations.gemspec +0 -2
- data/spec/additional_filter_spec.rb +76 -0
- data/spec/array_filter_spec.rb +25 -17
- data/spec/boolean_filter_spec.rb +5 -5
- data/spec/command_spec.rb +30 -30
- data/spec/date_filter_spec.rb +146 -0
- data/spec/default_spec.rb +10 -10
- data/spec/duck_filter_spec.rb +6 -6
- data/spec/errors_spec.rb +8 -9
- data/spec/file_filter_spec.rb +26 -22
- data/spec/float_filter_spec.rb +8 -8
- data/spec/hash_filter_spec.rb +31 -23
- data/spec/inheritance_spec.rb +9 -9
- data/spec/integer_filter_spec.rb +9 -9
- data/spec/model_filter_spec.rb +26 -6
- data/spec/mutations_spec.rb +1 -1
- data/spec/simple_command.rb +2 -2
- data/spec/spec_helper.rb +1 -1
- data/spec/string_filter_spec.rb +17 -17
- metadata +8 -4
data/spec/hash_filter_spec.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
require 'spec_helper'
|
2
2
|
require 'stringio'
|
3
3
|
|
4
4
|
describe "Mutations::HashFilter" do
|
@@ -7,7 +7,7 @@ describe "Mutations::HashFilter" do
|
|
7
7
|
hf = Mutations::HashFilter.new do
|
8
8
|
string :foo
|
9
9
|
end
|
10
|
-
filtered, errors = hf.filter(foo
|
10
|
+
filtered, errors = hf.filter(:foo => "bar")
|
11
11
|
assert_equal ({"foo" => "bar"}), filtered
|
12
12
|
assert_equal nil, errors
|
13
13
|
end
|
@@ -24,7 +24,7 @@ describe "Mutations::HashFilter" do
|
|
24
24
|
hf = Mutations::HashFilter.new do
|
25
25
|
string :*
|
26
26
|
end
|
27
|
-
filtered, errors = hf.filter(foo
|
27
|
+
filtered, errors = hf.filter(:foo => "bar", :baz => "ban")
|
28
28
|
assert_equal ({"foo" => "bar", "baz" => "ban"}), filtered
|
29
29
|
assert_equal nil, errors
|
30
30
|
end
|
@@ -33,26 +33,35 @@ describe "Mutations::HashFilter" do
|
|
33
33
|
hf = Mutations::HashFilter.new do
|
34
34
|
float :foo
|
35
35
|
end
|
36
|
-
filtered, errors = hf.filter(foo
|
36
|
+
filtered, errors = hf.filter(:foo => 3.14)
|
37
37
|
assert_equal ({"foo" => 3.14}), filtered
|
38
38
|
assert_equal nil, errors
|
39
39
|
end
|
40
|
-
|
40
|
+
|
41
41
|
it "allows ducks in hashes" do
|
42
42
|
hf = Mutations::HashFilter.new do
|
43
|
-
duck :foo, methods
|
43
|
+
duck :foo, :methods => [:length]
|
44
44
|
end
|
45
|
-
filtered, errors = hf.filter(foo
|
45
|
+
filtered, errors = hf.filter(:foo => "123")
|
46
46
|
assert_equal ({"foo" => "123"}), filtered
|
47
47
|
assert_equal nil, errors
|
48
48
|
end
|
49
|
-
|
49
|
+
|
50
|
+
it "allows dates in hashes" do
|
51
|
+
hf = Mutations::HashFilter.new do
|
52
|
+
date :foo, :format => "%d-%m-%Y"
|
53
|
+
end
|
54
|
+
filtered, errors = hf.filter(:foo => "1-1-2000")
|
55
|
+
assert_equal Date.new(2000, 1, 1), filtered[:foo]
|
56
|
+
assert_equal nil, errors
|
57
|
+
end
|
58
|
+
|
50
59
|
it "allows files in hashes" do
|
51
60
|
sio = StringIO.new("bob")
|
52
61
|
hf = Mutations::HashFilter.new do
|
53
62
|
file :foo
|
54
63
|
end
|
55
|
-
filtered, errors = hf.filter(foo
|
64
|
+
filtered, errors = hf.filter(:foo => sio)
|
56
65
|
assert_equal ({"foo" => sio}), filtered
|
57
66
|
assert_equal nil, errors
|
58
67
|
end
|
@@ -61,7 +70,7 @@ describe "Mutations::HashFilter" do
|
|
61
70
|
hf = Mutations::HashFilter.new do
|
62
71
|
string :*
|
63
72
|
end
|
64
|
-
filtered, errors = hf.filter(foo
|
73
|
+
filtered, errors = hf.filter(:foo => [])
|
65
74
|
assert_equal ({"foo" => :string}), errors.symbolic
|
66
75
|
end
|
67
76
|
|
@@ -70,7 +79,7 @@ describe "Mutations::HashFilter" do
|
|
70
79
|
string :foo
|
71
80
|
integer :*
|
72
81
|
end
|
73
|
-
filtered, errors = hf.filter(foo
|
82
|
+
filtered, errors = hf.filter(:foo => "bar", :baz => "4")
|
74
83
|
assert_equal ({"foo" => "bar", "baz" => 4}), filtered
|
75
84
|
assert_equal nil, errors
|
76
85
|
end
|
@@ -80,7 +89,7 @@ describe "Mutations::HashFilter" do
|
|
80
89
|
string :foo
|
81
90
|
integer :*
|
82
91
|
end
|
83
|
-
filtered, errors = hf.filter(foo
|
92
|
+
filtered, errors = hf.filter(:foo => "bar", :baz => "poopin")
|
84
93
|
assert_equal ({"baz" => :integer}), errors.symbolic
|
85
94
|
end
|
86
95
|
|
@@ -95,7 +104,7 @@ describe "Mutations::HashFilter" do
|
|
95
104
|
end
|
96
105
|
end
|
97
106
|
|
98
|
-
filtered, errors = hf.filter(foo
|
107
|
+
filtered, errors = hf.filter(:foo => "bar")
|
99
108
|
assert_equal ({"foo" => "bar"}), filtered
|
100
109
|
assert_equal nil, errors
|
101
110
|
end
|
@@ -110,7 +119,7 @@ describe "Mutations::HashFilter" do
|
|
110
119
|
end
|
111
120
|
end
|
112
121
|
|
113
|
-
filtered, errors = hf.filter(foo
|
122
|
+
filtered, errors = hf.filter(:foo => "bar", :bar => nil)
|
114
123
|
assert_equal ({"foo" => "bar"}), filtered
|
115
124
|
assert_equal nil, errors
|
116
125
|
end
|
@@ -121,11 +130,11 @@ describe "Mutations::HashFilter" do
|
|
121
130
|
string :foo
|
122
131
|
end
|
123
132
|
optional do
|
124
|
-
string :bar, nils
|
133
|
+
string :bar, :nils => true
|
125
134
|
end
|
126
135
|
end
|
127
136
|
|
128
|
-
filtered, errors = hf.filter(foo
|
137
|
+
filtered, errors = hf.filter(:foo => "bar", :bar => nil)
|
129
138
|
assert_equal ({"foo" => "bar", "bar" => nil}), filtered
|
130
139
|
assert_equal nil, errors
|
131
140
|
end
|
@@ -138,11 +147,11 @@ describe "Mutations::HashFilter" do
|
|
138
147
|
string :foo
|
139
148
|
end
|
140
149
|
optional do
|
141
|
-
string :bar, discard_empty
|
150
|
+
string :bar, :discard_empty => true
|
142
151
|
end
|
143
152
|
end
|
144
153
|
|
145
|
-
filtered, errors = hf.filter(foo
|
154
|
+
filtered, errors = hf.filter(:foo => "bar", :bar => "")
|
146
155
|
assert_equal ({"foo" => "bar"}), filtered
|
147
156
|
assert_equal nil, errors
|
148
157
|
end
|
@@ -153,11 +162,11 @@ describe "Mutations::HashFilter" do
|
|
153
162
|
string :foo
|
154
163
|
end
|
155
164
|
optional do
|
156
|
-
string :bar, discard_empty
|
165
|
+
string :bar, :discard_empty => false
|
157
166
|
end
|
158
167
|
end
|
159
168
|
|
160
|
-
filtered, errors = hf.filter(foo
|
169
|
+
filtered, errors = hf.filter(:foo => "bar", :bar => "")
|
161
170
|
assert_equal ({"bar" => :empty}), errors.symbolic
|
162
171
|
end
|
163
172
|
|
@@ -167,15 +176,14 @@ describe "Mutations::HashFilter" do
|
|
167
176
|
string :foo
|
168
177
|
end
|
169
178
|
optional do
|
170
|
-
string :*, discard_empty
|
179
|
+
string :*, :discard_empty => true
|
171
180
|
end
|
172
181
|
end
|
173
182
|
|
174
|
-
filtered, errors = hf.filter(foo
|
183
|
+
filtered, errors = hf.filter(:foo => "bar", :bar => "")
|
175
184
|
assert_equal ({"foo" => "bar"}), filtered
|
176
185
|
assert_equal nil, errors
|
177
186
|
end
|
178
187
|
end
|
179
188
|
|
180
|
-
|
181
189
|
end
|
data/spec/inheritance_spec.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
require 'spec_helper'
|
2
2
|
require 'simple_command'
|
3
3
|
|
4
4
|
describe 'Mutations - inheritance' do
|
@@ -15,25 +15,25 @@ describe 'Mutations - inheritance' do
|
|
15
15
|
end
|
16
16
|
|
17
17
|
it 'should filter with inherited command' do
|
18
|
-
mutation = SimpleInherited.run(name
|
18
|
+
mutation = SimpleInherited.run(:name => "bob", :email => "jon@jones.com", :age => 10, :amount => 22)
|
19
19
|
assert mutation.success?
|
20
|
-
assert_equal HashWithIndifferentAccess.new(name
|
20
|
+
assert_equal HashWithIndifferentAccess.new(:name => "bob", :email => "jon@jones.com", :age => 10, :amount => 22), mutation.result
|
21
21
|
end
|
22
22
|
|
23
23
|
it 'should filter with original command' do
|
24
|
-
mutation = SimpleCommand.run(name
|
24
|
+
mutation = SimpleCommand.run(:name => "bob", :email => "jon@jones.com", :age => 10, :amount => 22)
|
25
25
|
assert mutation.success?
|
26
|
-
assert_equal HashWithIndifferentAccess.new(name
|
26
|
+
assert_equal HashWithIndifferentAccess.new(:name => "bob", :email => "jon@jones.com", :amount => 22), mutation.result
|
27
27
|
end
|
28
28
|
|
29
29
|
it 'shouldnt collide' do
|
30
|
-
mutation = SimpleInherited.run(name
|
30
|
+
mutation = SimpleInherited.run(:name => "bob", :email => "jon@jones.com", :age => 10, :amount => 22)
|
31
31
|
assert mutation.success?
|
32
|
-
assert_equal HashWithIndifferentAccess.new(name
|
32
|
+
assert_equal HashWithIndifferentAccess.new(:name => "bob", :email => "jon@jones.com", :age => 10, :amount => 22), mutation.result
|
33
33
|
|
34
|
-
mutation = SimpleCommand.run(name
|
34
|
+
mutation = SimpleCommand.run(:name => "bob", :email => "jon@jones.com", :age => 10, :amount => 22)
|
35
35
|
assert mutation.success?
|
36
|
-
assert_equal HashWithIndifferentAccess.new(name
|
36
|
+
assert_equal HashWithIndifferentAccess.new(:name => "bob", :email => "jon@jones.com", :amount => 22), mutation.result
|
37
37
|
end
|
38
38
|
|
39
39
|
end
|
data/spec/integer_filter_spec.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
describe "Mutations::IntegerFilter" do
|
4
4
|
|
@@ -32,56 +32,56 @@ describe "Mutations::IntegerFilter" do
|
|
32
32
|
end
|
33
33
|
|
34
34
|
it "considers nil to be invalid" do
|
35
|
-
f = Mutations::IntegerFilter.new(nils
|
35
|
+
f = Mutations::IntegerFilter.new(:nils => false)
|
36
36
|
filtered, errors = f.filter(nil)
|
37
37
|
assert_equal nil, filtered
|
38
38
|
assert_equal :nils, errors
|
39
39
|
end
|
40
40
|
|
41
41
|
it "considers nil to be valid" do
|
42
|
-
f = Mutations::IntegerFilter.new(nils
|
42
|
+
f = Mutations::IntegerFilter.new(:nils => true)
|
43
43
|
filtered, errors = f.filter(nil)
|
44
44
|
assert_equal nil, filtered
|
45
45
|
assert_equal nil, errors
|
46
46
|
end
|
47
47
|
|
48
48
|
it "considers low numbers invalid" do
|
49
|
-
f = Mutations::IntegerFilter.new(min
|
49
|
+
f = Mutations::IntegerFilter.new(:min => 10)
|
50
50
|
filtered, errors = f.filter(3)
|
51
51
|
assert_equal 3, filtered
|
52
52
|
assert_equal :min, errors
|
53
53
|
end
|
54
54
|
|
55
55
|
it "considers low numbers valid" do
|
56
|
-
f = Mutations::IntegerFilter.new(min
|
56
|
+
f = Mutations::IntegerFilter.new(:min => 10)
|
57
57
|
filtered, errors = f.filter(31)
|
58
58
|
assert_equal 31, filtered
|
59
59
|
assert_equal nil, errors
|
60
60
|
end
|
61
61
|
|
62
62
|
it "considers high numbers invalid" do
|
63
|
-
f = Mutations::IntegerFilter.new(max
|
63
|
+
f = Mutations::IntegerFilter.new(:max => 10)
|
64
64
|
filtered, errors = f.filter(31)
|
65
65
|
assert_equal 31, filtered
|
66
66
|
assert_equal :max, errors
|
67
67
|
end
|
68
68
|
|
69
69
|
it "considers high numbers vaild" do
|
70
|
-
f = Mutations::IntegerFilter.new(max
|
70
|
+
f = Mutations::IntegerFilter.new(:max => 10)
|
71
71
|
filtered, errors = f.filter(3)
|
72
72
|
assert_equal 3, filtered
|
73
73
|
assert_equal nil, errors
|
74
74
|
end
|
75
75
|
|
76
76
|
it "considers not matching numbers to be invalid" do
|
77
|
-
f = Mutations::IntegerFilter.new(in
|
77
|
+
f = Mutations::IntegerFilter.new(:in => [3, 4, 5])
|
78
78
|
filtered, errors = f.filter(6)
|
79
79
|
assert_equal 6, filtered
|
80
80
|
assert_equal :in, errors
|
81
81
|
end
|
82
82
|
|
83
83
|
it "considers matching numbers to be valid" do
|
84
|
-
f = Mutations::IntegerFilter.new(in
|
84
|
+
f = Mutations::IntegerFilter.new(:in => [3, 4, 5])
|
85
85
|
filtered, errors = f.filter(3)
|
86
86
|
assert_equal 3, filtered
|
87
87
|
assert_nil errors
|
data/spec/model_filter_spec.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
describe "Mutations::ModelFilter" do
|
4
4
|
|
@@ -15,7 +15,6 @@ describe "Mutations::ModelFilter" do
|
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
|
-
|
19
18
|
it "allows models" do
|
20
19
|
f = Mutations::ModelFilter.new(:simple_model)
|
21
20
|
m = SimpleModel.new
|
@@ -35,32 +34,53 @@ describe "Mutations::ModelFilter" do
|
|
35
34
|
end
|
36
35
|
|
37
36
|
it "raises an exception during filtering if constantization of class fails" do
|
38
|
-
f = Mutations::ModelFilter.new(:simple_model, class
|
37
|
+
f = Mutations::ModelFilter.new(:simple_model, :class => "ComplexModel")
|
39
38
|
assert_raises NameError do
|
40
39
|
f.filter(nil)
|
41
40
|
end
|
42
41
|
end
|
43
42
|
|
44
43
|
it "raises an exception during filtering if constantization of builder fails" do
|
45
|
-
f = Mutations::ModelFilter.new(:simple_model, builder
|
44
|
+
f = Mutations::ModelFilter.new(:simple_model, :builder => "ComplexModel")
|
46
45
|
assert_raises NameError do
|
47
46
|
f.filter(nil)
|
48
47
|
end
|
49
48
|
end
|
50
49
|
|
51
50
|
it "considers nil to be invalid" do
|
52
|
-
f = Mutations::ModelFilter.new(:simple_model, nils
|
51
|
+
f = Mutations::ModelFilter.new(:simple_model, :nils => false)
|
53
52
|
filtered, errors = f.filter(nil)
|
54
53
|
assert_equal nil, filtered
|
55
54
|
assert_equal :nils, errors
|
56
55
|
end
|
57
56
|
|
58
57
|
it "considers nil to be valid" do
|
59
|
-
f = Mutations::ModelFilter.new(:simple_model, nils
|
58
|
+
f = Mutations::ModelFilter.new(:simple_model, :nils => true)
|
60
59
|
filtered, errors = f.filter(nil)
|
61
60
|
assert_equal nil, filtered
|
62
61
|
assert_equal nil, errors
|
63
62
|
end
|
63
|
+
|
64
|
+
it "will re-constantize if cache_constants is false" do
|
65
|
+
was = Mutations.cache_constants?
|
66
|
+
Mutations.cache_constants = false
|
67
|
+
f = Mutations::ModelFilter.new(:simple_model)
|
68
|
+
m = SimpleModel.new
|
69
|
+
filtered, errors = f.filter(m)
|
70
|
+
assert_equal m, filtered
|
71
|
+
assert_equal nil, errors
|
72
|
+
|
73
|
+
Object.send(:remove_const, 'SimpleModel')
|
74
|
+
|
75
|
+
class SimpleModel; end
|
76
|
+
|
77
|
+
m = SimpleModel.new
|
78
|
+
filtered, errors = f.filter(m)
|
79
|
+
assert_equal m, filtered
|
80
|
+
assert_equal nil, errors
|
81
|
+
|
82
|
+
Mutations.cache_constants = was
|
83
|
+
end
|
64
84
|
|
65
85
|
# it "allows you to override class with a constant and succeed" do
|
66
86
|
# end
|
data/spec/mutations_spec.rb
CHANGED
data/spec/simple_command.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
data/spec/string_filter_spec.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
describe "Mutations::StringFilter" do
|
4
4
|
|
@@ -25,112 +25,112 @@ describe "Mutations::StringFilter" do
|
|
25
25
|
|
26
26
|
it "disallows non-string" do
|
27
27
|
sf = Mutations::StringFilter.new
|
28
|
-
[["foo"], {a
|
28
|
+
[["foo"], {:a => "1"}, Object.new].each do |thing|
|
29
29
|
filtered, errors = sf.filter(thing)
|
30
30
|
assert_equal :string, errors
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
34
34
|
it "strips" do
|
35
|
-
sf = Mutations::StringFilter.new(strip
|
35
|
+
sf = Mutations::StringFilter.new(:strip => true)
|
36
36
|
filtered, errors = sf.filter(" hello ")
|
37
37
|
assert_equal "hello", filtered
|
38
38
|
assert_equal nil, errors
|
39
39
|
end
|
40
40
|
|
41
41
|
it "doesn't strip" do
|
42
|
-
sf = Mutations::StringFilter.new(strip
|
42
|
+
sf = Mutations::StringFilter.new(:strip => false)
|
43
43
|
filtered, errors = sf.filter(" hello ")
|
44
44
|
assert_equal " hello ", filtered
|
45
45
|
assert_equal nil, errors
|
46
46
|
end
|
47
47
|
|
48
48
|
it "considers nil to be invalid" do
|
49
|
-
sf = Mutations::StringFilter.new(nils
|
49
|
+
sf = Mutations::StringFilter.new(:nils => false)
|
50
50
|
filtered, errors = sf.filter(nil)
|
51
51
|
assert_equal nil, filtered
|
52
52
|
assert_equal :nils, errors
|
53
53
|
end
|
54
54
|
|
55
55
|
it "considers nil to be valid" do
|
56
|
-
sf = Mutations::StringFilter.new(nils
|
56
|
+
sf = Mutations::StringFilter.new(:nils => true)
|
57
57
|
filtered, errors = sf.filter(nil)
|
58
58
|
assert_equal nil, filtered
|
59
59
|
assert_equal nil, errors
|
60
60
|
end
|
61
61
|
|
62
62
|
it "considers empty strings to be invalid" do
|
63
|
-
sf = Mutations::StringFilter.new(empty
|
63
|
+
sf = Mutations::StringFilter.new(:empty => false)
|
64
64
|
filtered, errors = sf.filter("")
|
65
65
|
assert_equal "", filtered
|
66
66
|
assert_equal :empty, errors
|
67
67
|
end
|
68
68
|
|
69
69
|
it "considers empty strings to be valid" do
|
70
|
-
sf = Mutations::StringFilter.new(empty
|
70
|
+
sf = Mutations::StringFilter.new(:empty => true)
|
71
71
|
filtered, errors = sf.filter("")
|
72
72
|
assert_equal "", filtered
|
73
73
|
assert_equal nil, errors
|
74
74
|
end
|
75
75
|
|
76
76
|
it "considers stripped strings that are empty to be invalid" do
|
77
|
-
sf = Mutations::StringFilter.new(empty
|
77
|
+
sf = Mutations::StringFilter.new(:empty => false)
|
78
78
|
filtered, errors = sf.filter(" ")
|
79
79
|
assert_equal "", filtered
|
80
80
|
assert_equal :empty, errors
|
81
81
|
end
|
82
82
|
|
83
83
|
it "considers long strings to be invalid" do
|
84
|
-
sf = Mutations::StringFilter.new(max_length
|
84
|
+
sf = Mutations::StringFilter.new(:max_length => 5)
|
85
85
|
filtered, errors = sf.filter("123456")
|
86
86
|
assert_equal "123456", filtered
|
87
87
|
assert_equal :max_length, errors
|
88
88
|
end
|
89
89
|
|
90
90
|
it "considers long strings to be valid" do
|
91
|
-
sf = Mutations::StringFilter.new(max_length
|
91
|
+
sf = Mutations::StringFilter.new(:max_length => 5)
|
92
92
|
filtered, errors = sf.filter("12345")
|
93
93
|
assert_equal "12345", filtered
|
94
94
|
assert_equal nil, errors
|
95
95
|
end
|
96
96
|
|
97
97
|
it "considers short strings to be invalid" do
|
98
|
-
sf = Mutations::StringFilter.new(min_length
|
98
|
+
sf = Mutations::StringFilter.new(:min_length => 5)
|
99
99
|
filtered, errors = sf.filter("1234")
|
100
100
|
assert_equal "1234", filtered
|
101
101
|
assert_equal :min_length, errors
|
102
102
|
end
|
103
103
|
|
104
104
|
it "considers short strings to be valid" do
|
105
|
-
sf = Mutations::StringFilter.new(min_length
|
105
|
+
sf = Mutations::StringFilter.new(:min_length => 5)
|
106
106
|
filtered, errors = sf.filter("12345")
|
107
107
|
assert_equal "12345", filtered
|
108
108
|
assert_equal nil, errors
|
109
109
|
end
|
110
110
|
|
111
111
|
it "considers bad matches to be invalid" do
|
112
|
-
sf = Mutations::StringFilter.new(matches
|
112
|
+
sf = Mutations::StringFilter.new(:matches => /aaa/)
|
113
113
|
filtered, errors = sf.filter("aab")
|
114
114
|
assert_equal "aab", filtered
|
115
115
|
assert_equal :matches, errors
|
116
116
|
end
|
117
117
|
|
118
118
|
it "considers good matches to be valid" do
|
119
|
-
sf = Mutations::StringFilter.new(matches
|
119
|
+
sf = Mutations::StringFilter.new(:matches => /aaa/)
|
120
120
|
filtered, errors = sf.filter("baaab")
|
121
121
|
assert_equal "baaab", filtered
|
122
122
|
assert_equal nil, errors
|
123
123
|
end
|
124
124
|
|
125
125
|
it "considers non-inclusion to be invalid" do
|
126
|
-
sf = Mutations::StringFilter.new(in
|
126
|
+
sf = Mutations::StringFilter.new(:in => %w(red blue green))
|
127
127
|
filtered, errors = sf.filter("orange")
|
128
128
|
assert_equal "orange", filtered
|
129
129
|
assert_equal :in, errors
|
130
130
|
end
|
131
131
|
|
132
132
|
it "considers inclusion to be valid" do
|
133
|
-
sf = Mutations::StringFilter.new(in
|
133
|
+
sf = Mutations::StringFilter.new(:in => %w(red blue green))
|
134
134
|
filtered, errors = sf.filter("red")
|
135
135
|
assert_equal "red", filtered
|
136
136
|
assert_equal nil, errors
|