mutations 0.9.0 → 0.9.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +35 -0
- data/CHANGELOG.md +10 -0
- data/Gemfile +0 -6
- data/README.md +1 -1
- data/Rakefile +0 -1
- data/lib/mutations/array_filter.rb +1 -2
- data/lib/mutations/command.rb +1 -1
- data/lib/mutations/date_filter.rb +7 -5
- data/lib/mutations/hash_filter.rb +1 -4
- data/lib/mutations/integer_filter.rb +7 -6
- data/lib/mutations/string_filter.rb +9 -8
- data/lib/mutations/version.rb +1 -1
- data/mutations.gemspec +1 -1
- data/spec/additional_filter_spec.rb +3 -3
- data/spec/array_filter_spec.rb +19 -19
- data/spec/boolean_filter_spec.rb +6 -6
- data/spec/command_spec.rb +17 -16
- data/spec/date_filter_spec.rb +19 -23
- data/spec/default_spec.rb +2 -2
- data/spec/duck_filter_spec.rb +6 -6
- data/spec/errors_spec.rb +14 -14
- data/spec/file_filter_spec.rb +14 -18
- data/spec/float_filter_spec.rb +11 -11
- data/spec/hash_filter_spec.rb +36 -36
- data/spec/integer_filter_spec.rb +10 -10
- data/spec/model_filter_spec.rb +7 -7
- data/spec/mutations_spec.rb +1 -1
- data/spec/spec_helper.rb +0 -1
- data/spec/string_filter_spec.rb +52 -29
- data/spec/symbol_filter_spec.rb +6 -6
- data/spec/time_filter_spec.rb +16 -16
- metadata +11 -11
- data/.travis.yml +0 -15
data/spec/date_filter_spec.rb
CHANGED
|
@@ -6,7 +6,7 @@ describe "Mutations::DateFilter" do
|
|
|
6
6
|
f = Mutations::DateFilter.new
|
|
7
7
|
filtered, errors = f.filter(date)
|
|
8
8
|
assert_equal date, filtered
|
|
9
|
-
|
|
9
|
+
assert_nil errors
|
|
10
10
|
end
|
|
11
11
|
|
|
12
12
|
it "takes a DateTime object" do
|
|
@@ -14,19 +14,15 @@ describe "Mutations::DateFilter" do
|
|
|
14
14
|
f = Mutations::DateFilter.new
|
|
15
15
|
filtered, errors = f.filter(date)
|
|
16
16
|
assert_equal date, filtered
|
|
17
|
-
|
|
17
|
+
assert_nil errors
|
|
18
18
|
end
|
|
19
19
|
|
|
20
20
|
it "takes a Time object and converts it to a date" do
|
|
21
21
|
time = Time.now
|
|
22
22
|
f = Mutations::DateFilter.new
|
|
23
23
|
filtered, errors = f.filter(time)
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
assert_equal nil, errors
|
|
27
|
-
else
|
|
28
|
-
assert_equal :date, errors
|
|
29
|
-
end
|
|
24
|
+
assert_equal time.to_date, filtered
|
|
25
|
+
assert_nil errors
|
|
30
26
|
end
|
|
31
27
|
|
|
32
28
|
it "checks if the given date is after a certain date" do
|
|
@@ -36,7 +32,7 @@ describe "Mutations::DateFilter" do
|
|
|
36
32
|
filtered, errors = f.filter(date)
|
|
37
33
|
|
|
38
34
|
assert_equal date, filtered
|
|
39
|
-
|
|
35
|
+
assert_nil errors
|
|
40
36
|
end
|
|
41
37
|
|
|
42
38
|
it "gives errors when the given date is before the after date" do
|
|
@@ -45,7 +41,7 @@ describe "Mutations::DateFilter" do
|
|
|
45
41
|
f = Mutations::DateFilter.new(:after => after_date)
|
|
46
42
|
filtered, errors = f.filter(date)
|
|
47
43
|
|
|
48
|
-
|
|
44
|
+
assert_nil filtered
|
|
49
45
|
assert_equal :after, errors
|
|
50
46
|
end
|
|
51
47
|
|
|
@@ -56,7 +52,7 @@ describe "Mutations::DateFilter" do
|
|
|
56
52
|
filtered, errors = f.filter(date)
|
|
57
53
|
|
|
58
54
|
assert_equal date, filtered
|
|
59
|
-
|
|
55
|
+
assert_nil errors
|
|
60
56
|
end
|
|
61
57
|
|
|
62
58
|
it "gives errors when the given date is after the before date" do
|
|
@@ -65,7 +61,7 @@ describe "Mutations::DateFilter" do
|
|
|
65
61
|
f = Mutations::DateFilter.new(:before => before_date)
|
|
66
62
|
filtered, errors = f.filter(date)
|
|
67
63
|
|
|
68
|
-
|
|
64
|
+
assert_nil filtered
|
|
69
65
|
assert_equal :before, errors
|
|
70
66
|
end
|
|
71
67
|
|
|
@@ -77,7 +73,7 @@ describe "Mutations::DateFilter" do
|
|
|
77
73
|
filtered, errors = f.filter(date)
|
|
78
74
|
|
|
79
75
|
assert_equal date, filtered
|
|
80
|
-
|
|
76
|
+
assert_nil errors
|
|
81
77
|
end
|
|
82
78
|
|
|
83
79
|
it "should be able to parse a D-M-Y string to a date" do
|
|
@@ -87,7 +83,7 @@ describe "Mutations::DateFilter" do
|
|
|
87
83
|
filtered, errors = f.filter(date_string)
|
|
88
84
|
|
|
89
85
|
assert_equal date, filtered
|
|
90
|
-
|
|
86
|
+
assert_nil errors
|
|
91
87
|
end
|
|
92
88
|
|
|
93
89
|
it "should be able to parse a Y-M-D string to a date" do
|
|
@@ -97,7 +93,7 @@ describe "Mutations::DateFilter" do
|
|
|
97
93
|
filtered, errors = f.filter(date_string)
|
|
98
94
|
|
|
99
95
|
assert_equal date, filtered
|
|
100
|
-
|
|
96
|
+
assert_nil errors
|
|
101
97
|
end
|
|
102
98
|
|
|
103
99
|
it "should be able to handle date formatting" do
|
|
@@ -107,21 +103,21 @@ describe "Mutations::DateFilter" do
|
|
|
107
103
|
filtered, errors = f.filter(date_string)
|
|
108
104
|
|
|
109
105
|
assert_equal date, filtered
|
|
110
|
-
|
|
106
|
+
assert_nil errors
|
|
111
107
|
|
|
112
108
|
date_string = "1, 2, 2000"
|
|
113
109
|
f = Mutations::DateFilter.new(:format => '%m, %d, %Y')
|
|
114
110
|
filtered, errors = f.filter(date_string)
|
|
115
111
|
|
|
116
112
|
assert_equal date, filtered
|
|
117
|
-
|
|
113
|
+
assert_nil errors
|
|
118
114
|
end
|
|
119
115
|
|
|
120
116
|
it "considers nil to be invalid" do
|
|
121
117
|
f = Mutations::DateFilter.new
|
|
122
118
|
filtered, errors = f.filter(nil)
|
|
123
119
|
|
|
124
|
-
|
|
120
|
+
assert_nil filtered
|
|
125
121
|
assert_equal :nils, errors
|
|
126
122
|
end
|
|
127
123
|
|
|
@@ -136,8 +132,8 @@ describe "Mutations::DateFilter" do
|
|
|
136
132
|
f = Mutations::DateFilter.new(:nils => true)
|
|
137
133
|
filtered, errors = f.filter(nil)
|
|
138
134
|
|
|
139
|
-
|
|
140
|
-
|
|
135
|
+
assert_nil filtered
|
|
136
|
+
assert_nil errors
|
|
141
137
|
end
|
|
142
138
|
|
|
143
139
|
it "considers empty strings to be nil if empty_is_nil option is used" do
|
|
@@ -149,8 +145,8 @@ describe "Mutations::DateFilter" do
|
|
|
149
145
|
it "returns empty strings as nil if empty_is_nil option is used" do
|
|
150
146
|
f = Mutations::DateFilter.new(:empty_is_nil => true, :nils => true)
|
|
151
147
|
filtered, errors = f.filter("")
|
|
152
|
-
|
|
153
|
-
|
|
148
|
+
assert_nil filtered
|
|
149
|
+
assert_nil errors
|
|
154
150
|
end
|
|
155
151
|
|
|
156
152
|
it "doesn't allow non-existing dates" do
|
|
@@ -158,7 +154,7 @@ describe "Mutations::DateFilter" do
|
|
|
158
154
|
f = Mutations::DateFilter.new
|
|
159
155
|
filtered, errors = f.filter(date_string)
|
|
160
156
|
|
|
161
|
-
|
|
157
|
+
assert_nil filtered
|
|
162
158
|
assert_equal :date, errors
|
|
163
159
|
end
|
|
164
160
|
end
|
data/spec/default_spec.rb
CHANGED
|
@@ -16,13 +16,13 @@ describe 'Mutations - defaults' do
|
|
|
16
16
|
it "should have a default if no value is passed" do
|
|
17
17
|
outcome = DefaultCommand.run
|
|
18
18
|
assert_equal true, outcome.success?
|
|
19
|
-
assert_equal
|
|
19
|
+
assert_equal({"name" => "Bob Jones"}, outcome.result)
|
|
20
20
|
end
|
|
21
21
|
|
|
22
22
|
it "should have the passed value if a value is passed" do
|
|
23
23
|
outcome = DefaultCommand.run(:name => "Fred")
|
|
24
24
|
assert_equal true, outcome.success?
|
|
25
|
-
assert_equal
|
|
25
|
+
assert_equal({"name" => "Fred"}, outcome.result)
|
|
26
26
|
end
|
|
27
27
|
|
|
28
28
|
it "should be an error if nil is passed on a required field with a default" do
|
data/spec/duck_filter_spec.rb
CHANGED
|
@@ -6,11 +6,11 @@ describe "Mutations::DuckFilter" do
|
|
|
6
6
|
f = Mutations::DuckFilter.new(:methods => [:length])
|
|
7
7
|
filtered, errors = f.filter("test")
|
|
8
8
|
assert_equal "test", filtered
|
|
9
|
-
|
|
9
|
+
assert_nil errors
|
|
10
10
|
|
|
11
11
|
filtered, errors = f.filter([1, 2])
|
|
12
12
|
assert_equal [1, 2], filtered
|
|
13
|
-
|
|
13
|
+
assert_nil errors
|
|
14
14
|
end
|
|
15
15
|
|
|
16
16
|
it "doesn't allow objects that respond to a single specified method" do
|
|
@@ -27,15 +27,15 @@ describe "Mutations::DuckFilter" do
|
|
|
27
27
|
it "considers nil to be invalid" do
|
|
28
28
|
f = Mutations::DuckFilter.new(:nils => false)
|
|
29
29
|
filtered, errors = f.filter(nil)
|
|
30
|
-
|
|
30
|
+
assert_nil filtered
|
|
31
31
|
assert_equal :nils, errors
|
|
32
32
|
end
|
|
33
33
|
|
|
34
34
|
it "considers nil to be valid" do
|
|
35
35
|
f = Mutations::DuckFilter.new(:nils => true)
|
|
36
36
|
filtered, errors = f.filter(nil)
|
|
37
|
-
|
|
38
|
-
|
|
37
|
+
assert_nil filtered
|
|
38
|
+
assert_nil errors
|
|
39
39
|
end
|
|
40
40
|
|
|
41
41
|
it "Allows anything if no methods are specified" do
|
|
@@ -43,7 +43,7 @@ describe "Mutations::DuckFilter" do
|
|
|
43
43
|
[true, "hi", 1, [1, 2, 3]].each do |v|
|
|
44
44
|
filtered, errors = f.filter(v)
|
|
45
45
|
assert_equal v, filtered
|
|
46
|
-
|
|
46
|
+
assert_nil errors
|
|
47
47
|
end
|
|
48
48
|
end
|
|
49
49
|
end
|
data/spec/errors_spec.rb
CHANGED
|
@@ -26,33 +26,33 @@ describe "Mutations - errors" do
|
|
|
26
26
|
o = GivesErrors.run(:hash1 => 1, :arr1 => "bob")
|
|
27
27
|
|
|
28
28
|
assert !o.success?
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
29
|
+
assert_kind_of Mutations::ErrorHash, o.errors
|
|
30
|
+
assert_kind_of Mutations::ErrorAtom, o.errors[:str1]
|
|
31
|
+
assert_kind_of Mutations::ErrorAtom, o.errors[:str2]
|
|
32
32
|
assert_nil o.errors[:int1]
|
|
33
|
-
|
|
34
|
-
|
|
33
|
+
assert_kind_of Mutations::ErrorAtom, o.errors[:hash1]
|
|
34
|
+
assert_kind_of Mutations::ErrorAtom, o.errors[:arr1]
|
|
35
35
|
end
|
|
36
36
|
|
|
37
37
|
it "returns an ErrorHash for nested hashes" do
|
|
38
38
|
o = GivesErrors.run(:hash1 => {:bool1 => "poop"})
|
|
39
39
|
|
|
40
40
|
assert !o.success?
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
41
|
+
assert_kind_of Mutations::ErrorHash, o.errors
|
|
42
|
+
assert_kind_of Mutations::ErrorHash, o.errors[:hash1]
|
|
43
|
+
assert_kind_of Mutations::ErrorAtom, o.errors[:hash1][:bool1]
|
|
44
|
+
assert_kind_of Mutations::ErrorAtom, o.errors[:hash1][:bool2]
|
|
45
45
|
end
|
|
46
46
|
|
|
47
47
|
it "returns an ErrorArray for errors in arrays" do
|
|
48
48
|
o = GivesErrors.run(:str1 => "a", :str2 => "opt1", :arr1 => ["bob", 1, "sally"])
|
|
49
49
|
|
|
50
50
|
assert !o.success?
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
51
|
+
assert_kind_of Mutations::ErrorHash, o.errors
|
|
52
|
+
assert_kind_of Mutations::ErrorArray, o.errors[:arr1]
|
|
53
|
+
assert_kind_of Mutations::ErrorAtom, o.errors[:arr1][0]
|
|
54
54
|
assert_nil o.errors[:arr1][1]
|
|
55
|
-
|
|
55
|
+
assert_kind_of Mutations::ErrorAtom, o.errors[:arr1][2]
|
|
56
56
|
end
|
|
57
57
|
|
|
58
58
|
describe "error messages" do
|
|
@@ -97,7 +97,7 @@ describe "Mutations - errors" do
|
|
|
97
97
|
expected = ["Str1 can't be blank", "Str2 isn't an option", "Int1 isn't an integer", "Bool1 isn't a boolean", "Bool2 is required", "Arr1[0] isn't an integer", "Arr1[2] isn't an integer"]
|
|
98
98
|
|
|
99
99
|
assert_equal expected.size, @outcome.errors.message_list.size
|
|
100
|
-
expected.each { |e|
|
|
100
|
+
expected.each { |e| assert_includes @outcome.errors.message_list, e }
|
|
101
101
|
end
|
|
102
102
|
end
|
|
103
103
|
|
data/spec/file_filter_spec.rb
CHANGED
|
@@ -8,16 +8,12 @@ describe "Mutations::FileFilter" do
|
|
|
8
8
|
attr_accessor :content_type, :original_filename
|
|
9
9
|
end
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
filtered, errors = f.filter(file)
|
|
18
|
-
assert_equal file, filtered
|
|
19
|
-
assert_equal nil, errors
|
|
20
|
-
end
|
|
11
|
+
it "allows files - file class" do
|
|
12
|
+
file = File.new("README.md")
|
|
13
|
+
f = Mutations::FileFilter.new
|
|
14
|
+
filtered, errors = f.filter(file)
|
|
15
|
+
assert_equal file, filtered
|
|
16
|
+
assert_nil errors
|
|
21
17
|
end
|
|
22
18
|
|
|
23
19
|
it "allows files - stringio class" do
|
|
@@ -25,15 +21,15 @@ describe "Mutations::FileFilter" do
|
|
|
25
21
|
f = Mutations::FileFilter.new
|
|
26
22
|
filtered, errors = f.filter(file)
|
|
27
23
|
assert_equal file, filtered
|
|
28
|
-
|
|
24
|
+
assert_nil errors
|
|
29
25
|
end
|
|
30
26
|
|
|
31
27
|
it "allows files - tempfile" do
|
|
32
28
|
file = Tempfile.new("bob")
|
|
33
29
|
f = Mutations::FileFilter.new
|
|
34
30
|
filtered, errors = f.filter(file)
|
|
35
|
-
|
|
36
|
-
|
|
31
|
+
assert_equal file, filtered
|
|
32
|
+
assert_nil errors
|
|
37
33
|
end
|
|
38
34
|
|
|
39
35
|
it "doesn't allow non-files" do
|
|
@@ -50,15 +46,15 @@ describe "Mutations::FileFilter" do
|
|
|
50
46
|
it "considers nil to be invalid" do
|
|
51
47
|
f = Mutations::FileFilter.new(:nils => false)
|
|
52
48
|
filtered, errors = f.filter(nil)
|
|
53
|
-
|
|
49
|
+
assert_nil filtered
|
|
54
50
|
assert_equal :nils, errors
|
|
55
51
|
end
|
|
56
52
|
|
|
57
53
|
it "considers nil to be valid" do
|
|
58
54
|
f = Mutations::FileFilter.new(:nils => true)
|
|
59
55
|
filtered, errors = f.filter(nil)
|
|
60
|
-
|
|
61
|
-
|
|
56
|
+
assert_nil filtered
|
|
57
|
+
assert_nil errors
|
|
62
58
|
end
|
|
63
59
|
|
|
64
60
|
it "considers empty strings to be empty" do
|
|
@@ -72,7 +68,7 @@ describe "Mutations::FileFilter" do
|
|
|
72
68
|
f = Mutations::FileFilter.new(:size => 4)
|
|
73
69
|
filtered, errors = f.filter(file)
|
|
74
70
|
assert_equal file, filtered
|
|
75
|
-
|
|
71
|
+
assert_nil errors
|
|
76
72
|
end
|
|
77
73
|
|
|
78
74
|
it "shouldn't allow big files" do
|
|
@@ -88,7 +84,7 @@ describe "Mutations::FileFilter" do
|
|
|
88
84
|
f = Mutations::FileFilter.new(:upload => true)
|
|
89
85
|
filtered, errors = f.filter(file)
|
|
90
86
|
assert_equal file, filtered
|
|
91
|
-
|
|
87
|
+
assert_nil errors
|
|
92
88
|
end
|
|
93
89
|
|
|
94
90
|
it "should require extra methods if uploaded file: deny" do
|
data/spec/float_filter_spec.rb
CHANGED
|
@@ -6,42 +6,42 @@ describe "Mutations::FloatFilter" do
|
|
|
6
6
|
f = Mutations::FloatFilter.new
|
|
7
7
|
filtered, errors = f.filter(3.1415926)
|
|
8
8
|
assert_equal 3.1415926, filtered
|
|
9
|
-
|
|
9
|
+
assert_nil errors
|
|
10
10
|
end
|
|
11
11
|
|
|
12
12
|
it "allows strings that start with a digit" do
|
|
13
13
|
f = Mutations::FloatFilter.new
|
|
14
14
|
filtered, errors = f.filter("3")
|
|
15
15
|
assert_equal 3.0, filtered
|
|
16
|
-
|
|
16
|
+
assert_nil errors
|
|
17
17
|
end
|
|
18
18
|
|
|
19
19
|
it "allows string representation of float" do
|
|
20
20
|
f = Mutations::FloatFilter.new
|
|
21
21
|
filtered, errors = f.filter("3.14")
|
|
22
22
|
assert_equal 3.14, filtered
|
|
23
|
-
|
|
23
|
+
assert_nil errors
|
|
24
24
|
end
|
|
25
25
|
|
|
26
26
|
it "allows string representation of float without a number before dot" do
|
|
27
27
|
f = Mutations::FloatFilter.new
|
|
28
28
|
filtered, errors = f.filter(".14")
|
|
29
29
|
assert_equal 0.14, filtered
|
|
30
|
-
|
|
30
|
+
assert_nil errors
|
|
31
31
|
end
|
|
32
32
|
|
|
33
33
|
it "allows negative strings" do
|
|
34
34
|
f = Mutations::FloatFilter.new
|
|
35
35
|
filtered, errors = f.filter("-.14")
|
|
36
36
|
assert_equal(-0.14, filtered)
|
|
37
|
-
|
|
37
|
+
assert_nil errors
|
|
38
38
|
end
|
|
39
39
|
|
|
40
40
|
it "allows strings with a positive sign" do
|
|
41
41
|
f = Mutations::FloatFilter.new
|
|
42
42
|
filtered, errors = f.filter("+.14")
|
|
43
43
|
assert_equal 0.14, filtered
|
|
44
|
-
|
|
44
|
+
assert_nil errors
|
|
45
45
|
end
|
|
46
46
|
|
|
47
47
|
it "doesnt't allow other strings, nor does it allow random objects or symbols" do
|
|
@@ -55,15 +55,15 @@ describe "Mutations::FloatFilter" do
|
|
|
55
55
|
it "considers nil to be invalid" do
|
|
56
56
|
f = Mutations::FloatFilter.new(:nils => false)
|
|
57
57
|
filtered, errors = f.filter(nil)
|
|
58
|
-
|
|
58
|
+
assert_nil filtered
|
|
59
59
|
assert_equal :nils, errors
|
|
60
60
|
end
|
|
61
61
|
|
|
62
62
|
it "considers nil to be valid" do
|
|
63
63
|
f = Mutations::FloatFilter.new(:nils => true)
|
|
64
64
|
filtered, errors = f.filter(nil)
|
|
65
|
-
|
|
66
|
-
|
|
65
|
+
assert_nil filtered
|
|
66
|
+
assert_nil errors
|
|
67
67
|
end
|
|
68
68
|
|
|
69
69
|
it "considers empty strings to be empty" do
|
|
@@ -83,7 +83,7 @@ describe "Mutations::FloatFilter" do
|
|
|
83
83
|
f = Mutations::FloatFilter.new(:min => 10)
|
|
84
84
|
filtered, errors = f.filter(31)
|
|
85
85
|
assert_equal 31, filtered
|
|
86
|
-
|
|
86
|
+
assert_nil errors
|
|
87
87
|
end
|
|
88
88
|
|
|
89
89
|
it "considers high numbers invalid" do
|
|
@@ -97,7 +97,7 @@ describe "Mutations::FloatFilter" do
|
|
|
97
97
|
f = Mutations::FloatFilter.new(:max => 10)
|
|
98
98
|
filtered, errors = f.filter(3)
|
|
99
99
|
assert_equal 3, filtered
|
|
100
|
-
|
|
100
|
+
assert_nil errors
|
|
101
101
|
end
|
|
102
102
|
|
|
103
103
|
end
|
data/spec/hash_filter_spec.rb
CHANGED
|
@@ -8,8 +8,8 @@ describe "Mutations::HashFilter" do
|
|
|
8
8
|
string :foo
|
|
9
9
|
end
|
|
10
10
|
filtered, errors = hf.filter(:foo => "bar")
|
|
11
|
-
assert_equal
|
|
12
|
-
|
|
11
|
+
assert_equal({"foo" => "bar"}, filtered)
|
|
12
|
+
assert_nil errors
|
|
13
13
|
end
|
|
14
14
|
|
|
15
15
|
it 'disallows non-hashes' do
|
|
@@ -29,7 +29,7 @@ describe "Mutations::HashFilter" do
|
|
|
29
29
|
string :foo
|
|
30
30
|
end
|
|
31
31
|
_filtered, errors = hf.filter(input)
|
|
32
|
-
|
|
32
|
+
assert_nil errors
|
|
33
33
|
end
|
|
34
34
|
|
|
35
35
|
it "allows wildcards in hashes" do
|
|
@@ -37,8 +37,8 @@ describe "Mutations::HashFilter" do
|
|
|
37
37
|
string :*
|
|
38
38
|
end
|
|
39
39
|
filtered, errors = hf.filter(:foo => "bar", :baz => "ban")
|
|
40
|
-
assert_equal
|
|
41
|
-
|
|
40
|
+
assert_equal({"foo" => "bar", "baz" => "ban"}, filtered)
|
|
41
|
+
assert_nil errors
|
|
42
42
|
end
|
|
43
43
|
|
|
44
44
|
it "allows floats in hashes" do
|
|
@@ -46,8 +46,8 @@ describe "Mutations::HashFilter" do
|
|
|
46
46
|
float :foo
|
|
47
47
|
end
|
|
48
48
|
filtered, errors = hf.filter(:foo => 3.14)
|
|
49
|
-
assert_equal
|
|
50
|
-
|
|
49
|
+
assert_equal({"foo" => 3.14}, filtered)
|
|
50
|
+
assert_nil errors
|
|
51
51
|
end
|
|
52
52
|
|
|
53
53
|
it "allows ducks in hashes" do
|
|
@@ -55,8 +55,8 @@ describe "Mutations::HashFilter" do
|
|
|
55
55
|
duck :foo, :methods => [:length]
|
|
56
56
|
end
|
|
57
57
|
filtered, errors = hf.filter(:foo => "123")
|
|
58
|
-
assert_equal
|
|
59
|
-
|
|
58
|
+
assert_equal({"foo" => "123"}, filtered)
|
|
59
|
+
assert_nil errors
|
|
60
60
|
end
|
|
61
61
|
|
|
62
62
|
it "allows dates in hashes" do
|
|
@@ -65,7 +65,7 @@ describe "Mutations::HashFilter" do
|
|
|
65
65
|
end
|
|
66
66
|
filtered, errors = hf.filter(:foo => "1-1-2000")
|
|
67
67
|
assert_equal Date.new(2000, 1, 1), filtered[:foo]
|
|
68
|
-
|
|
68
|
+
assert_nil errors
|
|
69
69
|
end
|
|
70
70
|
|
|
71
71
|
it "allows files in hashes" do
|
|
@@ -74,8 +74,8 @@ describe "Mutations::HashFilter" do
|
|
|
74
74
|
file :foo
|
|
75
75
|
end
|
|
76
76
|
filtered, errors = hf.filter(:foo => sio)
|
|
77
|
-
assert_equal
|
|
78
|
-
|
|
77
|
+
assert_equal({"foo" => sio}, filtered)
|
|
78
|
+
assert_nil errors
|
|
79
79
|
end
|
|
80
80
|
|
|
81
81
|
it "doesn't allow wildcards in hashes" do
|
|
@@ -83,7 +83,7 @@ describe "Mutations::HashFilter" do
|
|
|
83
83
|
string :*
|
|
84
84
|
end
|
|
85
85
|
_filtered, errors = hf.filter(:foo => [])
|
|
86
|
-
assert_equal
|
|
86
|
+
assert_equal({"foo" => :string}, errors.symbolic)
|
|
87
87
|
end
|
|
88
88
|
|
|
89
89
|
it "allows a mix of specific keys and then wildcards" do
|
|
@@ -92,8 +92,8 @@ describe "Mutations::HashFilter" do
|
|
|
92
92
|
integer :*
|
|
93
93
|
end
|
|
94
94
|
filtered, errors = hf.filter(:foo => "bar", :baz => "4")
|
|
95
|
-
assert_equal
|
|
96
|
-
|
|
95
|
+
assert_equal({"foo" => "bar", "baz" => 4}, filtered)
|
|
96
|
+
assert_nil errors
|
|
97
97
|
end
|
|
98
98
|
|
|
99
99
|
it "doesn't allow a mix of specific keys and then wildcards -- should raise errors appropriately" do
|
|
@@ -102,7 +102,7 @@ describe "Mutations::HashFilter" do
|
|
|
102
102
|
integer :*
|
|
103
103
|
end
|
|
104
104
|
_filtered, errors = hf.filter(:foo => "bar", :baz => "poopin")
|
|
105
|
-
assert_equal
|
|
105
|
+
assert_equal({"baz" => :integer}, errors.symbolic)
|
|
106
106
|
end
|
|
107
107
|
|
|
108
108
|
describe "optional params and nils" do
|
|
@@ -117,8 +117,8 @@ describe "Mutations::HashFilter" do
|
|
|
117
117
|
end
|
|
118
118
|
|
|
119
119
|
filtered, errors = hf.filter(:foo => "bar")
|
|
120
|
-
assert_equal
|
|
121
|
-
|
|
120
|
+
assert_equal({"foo" => "bar"}, filtered)
|
|
121
|
+
assert_nil errors
|
|
122
122
|
end
|
|
123
123
|
|
|
124
124
|
it "bar is optional -- it works if nil is passed" do
|
|
@@ -132,8 +132,8 @@ describe "Mutations::HashFilter" do
|
|
|
132
132
|
end
|
|
133
133
|
|
|
134
134
|
filtered, errors = hf.filter(:foo => "bar", :bar => nil)
|
|
135
|
-
assert_equal
|
|
136
|
-
|
|
135
|
+
assert_equal({"foo" => "bar"}, filtered)
|
|
136
|
+
assert_nil errors
|
|
137
137
|
end
|
|
138
138
|
|
|
139
139
|
it "bar is optional -- it works if nil is passed and nils are allowed" do
|
|
@@ -147,8 +147,8 @@ describe "Mutations::HashFilter" do
|
|
|
147
147
|
end
|
|
148
148
|
|
|
149
149
|
filtered, errors = hf.filter(:foo => "bar", :bar => nil)
|
|
150
|
-
assert_equal
|
|
151
|
-
|
|
150
|
+
assert_equal({"foo" => "bar", "bar" => nil}, filtered)
|
|
151
|
+
assert_nil errors
|
|
152
152
|
end
|
|
153
153
|
end
|
|
154
154
|
|
|
@@ -164,8 +164,8 @@ describe "Mutations::HashFilter" do
|
|
|
164
164
|
end
|
|
165
165
|
|
|
166
166
|
filtered, errors = hf.filter(:foo => "bar", :bar => "")
|
|
167
|
-
assert_equal
|
|
168
|
-
|
|
167
|
+
assert_equal({"foo" => "bar"}, filtered)
|
|
168
|
+
assert_nil errors
|
|
169
169
|
end
|
|
170
170
|
|
|
171
171
|
it "bar is optional -- discards empty if it needs to be stripped" do
|
|
@@ -179,8 +179,8 @@ describe "Mutations::HashFilter" do
|
|
|
179
179
|
end
|
|
180
180
|
|
|
181
181
|
filtered, errors = hf.filter(:foo => "bar", :bar => " ")
|
|
182
|
-
assert_equal
|
|
183
|
-
|
|
182
|
+
assert_equal({"foo" => "bar"}, filtered)
|
|
183
|
+
assert_nil errors
|
|
184
184
|
end
|
|
185
185
|
|
|
186
186
|
it "bar is optional -- don't discard empty if it's spaces but stripping is off" do
|
|
@@ -194,8 +194,8 @@ describe "Mutations::HashFilter" do
|
|
|
194
194
|
end
|
|
195
195
|
|
|
196
196
|
filtered, errors = hf.filter(:foo => "bar", :bar => " ")
|
|
197
|
-
assert_equal
|
|
198
|
-
|
|
197
|
+
assert_equal({"foo" => "bar", "bar" => " "}, filtered)
|
|
198
|
+
assert_nil errors
|
|
199
199
|
end
|
|
200
200
|
|
|
201
201
|
it "bar is optional -- errors if discard_empty is false and value is blank" do
|
|
@@ -209,7 +209,7 @@ describe "Mutations::HashFilter" do
|
|
|
209
209
|
end
|
|
210
210
|
|
|
211
211
|
_filtered, errors = hf.filter(:foo => "bar", :bar => "")
|
|
212
|
-
assert_equal
|
|
212
|
+
assert_equal({"bar" => :empty}, errors.symbolic)
|
|
213
213
|
end
|
|
214
214
|
|
|
215
215
|
it "bar is optional -- discards empty -- now with wildcards" do
|
|
@@ -223,8 +223,8 @@ describe "Mutations::HashFilter" do
|
|
|
223
223
|
end
|
|
224
224
|
|
|
225
225
|
filtered, errors = hf.filter(:foo => "bar", :bar => "", :baz => "\t")
|
|
226
|
-
assert_equal
|
|
227
|
-
|
|
226
|
+
assert_equal({"foo" => "bar"}, filtered)
|
|
227
|
+
assert_nil errors
|
|
228
228
|
end
|
|
229
229
|
end
|
|
230
230
|
|
|
@@ -240,8 +240,8 @@ describe "Mutations::HashFilter" do
|
|
|
240
240
|
end
|
|
241
241
|
|
|
242
242
|
filtered, errors = hf.filter(:foo => "bar", :bar => "baz")
|
|
243
|
-
assert_equal
|
|
244
|
-
|
|
243
|
+
assert_equal({"foo" => "bar"}, filtered)
|
|
244
|
+
assert_nil errors
|
|
245
245
|
end
|
|
246
246
|
|
|
247
247
|
it "should discard invalid optional values for wildcards" do
|
|
@@ -255,8 +255,8 @@ describe "Mutations::HashFilter" do
|
|
|
255
255
|
end
|
|
256
256
|
|
|
257
257
|
filtered, errors = hf.filter(:foo => "bar", :bar => "baz", :wat => 1)
|
|
258
|
-
assert_equal
|
|
259
|
-
|
|
258
|
+
assert_equal({"foo" => "bar", "wat" => 1}, filtered)
|
|
259
|
+
assert_nil errors
|
|
260
260
|
end
|
|
261
261
|
|
|
262
262
|
|
|
@@ -268,7 +268,7 @@ describe "Mutations::HashFilter" do
|
|
|
268
268
|
end
|
|
269
269
|
|
|
270
270
|
_filtered, errors = hf.filter(:foo => "bar")
|
|
271
|
-
assert_equal
|
|
271
|
+
assert_equal({"foo" => :integer}, errors.symbolic)
|
|
272
272
|
end
|
|
273
273
|
end
|
|
274
274
|
|