foraneus 0.0.12 → 0.0.13
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/README.md +48 -16
- data/lib/foraneus.rb +39 -19
- data/lib/foraneus/converters/date.rb +4 -1
- data/lib/foraneus/converters/float.rb +2 -0
- data/lib/foraneus/converters/integer.rb +2 -0
- data/spec/lib/foraneus/converters/boolean_converter_spec.rb +10 -8
- data/spec/lib/foraneus/converters/date_converter_spec.rb +14 -18
- data/spec/lib/foraneus/converters/decimal_converter_spec.rb +16 -16
- data/spec/lib/foraneus/converters/float_converter_spec.rb +24 -22
- data/spec/lib/foraneus/converters/integer_converter_spec.rb +32 -29
- data/spec/lib/foraneus/converters/noop_converter_spec.rb +4 -2
- data/spec/lib/foraneus/converters/string_converter_spec.rb +6 -4
- data/spec/lib/foraneus_spec.rb +232 -141
- data/spec/runner.rb +16 -0
- data/spec/spec_helper.rb +4 -1
- data/spec/spec_helper_its.rb +42 -0
- metadata +38 -49
|
@@ -2,43 +2,45 @@ require 'spec_helper'
|
|
|
2
2
|
|
|
3
3
|
describe Foraneus::Converters::Float do
|
|
4
4
|
|
|
5
|
+
subject { Foraneus::Converters::Float.new }
|
|
6
|
+
|
|
5
7
|
describe '#parse' do
|
|
6
|
-
|
|
8
|
+
describe 'with valid values' do
|
|
7
9
|
let(:number) { 1234.5678 }
|
|
8
10
|
let(:raw_number) { number.to_s }
|
|
9
11
|
|
|
10
12
|
it 'returns a float number' do
|
|
11
13
|
parsed = subject.parse(raw_number)
|
|
12
14
|
|
|
13
|
-
|
|
15
|
+
assert_kind_of Float, parsed
|
|
14
16
|
end
|
|
15
17
|
|
|
16
18
|
it 'parses the number' do
|
|
17
19
|
parsed = subject.parse(raw_number)
|
|
18
20
|
|
|
19
|
-
|
|
21
|
+
assert_equal number, parsed
|
|
20
22
|
end
|
|
21
23
|
|
|
22
|
-
|
|
24
|
+
describe 'with big ones' do
|
|
23
25
|
let(:big_number) { (11 ** 20) + 0.33 }
|
|
24
26
|
let(:raw_big_number) { big_number.to_s }
|
|
25
27
|
|
|
26
28
|
it 'also returns a float number' do
|
|
27
29
|
parsed = subject.parse(raw_big_number)
|
|
28
30
|
|
|
29
|
-
|
|
31
|
+
assert_kind_of Float, parsed
|
|
30
32
|
end
|
|
31
33
|
|
|
32
34
|
it 'also parses the number' do
|
|
33
35
|
parsed = subject.parse(raw_big_number)
|
|
34
36
|
|
|
35
|
-
|
|
37
|
+
assert_equal big_number, parsed
|
|
36
38
|
end
|
|
37
39
|
end
|
|
38
40
|
end
|
|
39
41
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
+
describe 'when separator and delimiter are given' do
|
|
43
|
+
let(:converter) {
|
|
42
44
|
Foraneus::Converters::Float.new(:delimiter => '.', :separator => ',')
|
|
43
45
|
}
|
|
44
46
|
|
|
@@ -46,35 +48,35 @@ describe Foraneus::Converters::Float do
|
|
|
46
48
|
s = '1.234.567,89'
|
|
47
49
|
n = 1_234_567.89
|
|
48
50
|
|
|
49
|
-
converter.parse(s)
|
|
51
|
+
assert_equal n, converter.parse(s)
|
|
50
52
|
end
|
|
51
53
|
|
|
52
54
|
it 'parses a float representation when no integer part' do
|
|
53
55
|
s = ',56'
|
|
54
56
|
n = 0.56
|
|
55
57
|
|
|
56
|
-
converter.parse(s)
|
|
58
|
+
assert_equal n, converter.parse(s)
|
|
57
59
|
end
|
|
58
60
|
end
|
|
59
61
|
|
|
60
|
-
|
|
62
|
+
describe 'with invalid values' do
|
|
61
63
|
let(:raw_invalid) { 'INVALID' }
|
|
62
64
|
|
|
63
65
|
it 'raises an error' do
|
|
64
|
-
|
|
66
|
+
assert_raises(ArgumentError) {
|
|
65
67
|
subject.parse(raw_invalid)
|
|
66
|
-
}
|
|
68
|
+
}
|
|
67
69
|
end
|
|
68
70
|
end
|
|
69
71
|
end
|
|
70
72
|
|
|
71
73
|
describe '#raw' do
|
|
72
74
|
it 'returns a string representation' do
|
|
73
|
-
|
|
75
|
+
assert_equal '2.34', subject.raw(2.34)
|
|
74
76
|
end
|
|
75
77
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
+
describe 'when separator and delimiter are given' do
|
|
79
|
+
let(:converter) {
|
|
78
80
|
Foraneus::Converters::Float.new(:delimiter => '.', :separator => ',')
|
|
79
81
|
}
|
|
80
82
|
|
|
@@ -82,28 +84,28 @@ describe Foraneus::Converters::Float do
|
|
|
82
84
|
n = 1_234_567.89
|
|
83
85
|
s = '1.234.567,89'
|
|
84
86
|
|
|
85
|
-
converter.raw(n)
|
|
87
|
+
assert_equal s, converter.raw(n)
|
|
86
88
|
end
|
|
87
89
|
end
|
|
88
90
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
+
describe 'when precision is given' do
|
|
92
|
+
let(:converter) {
|
|
91
93
|
Foraneus::Converters::Float.new(:precision => 2)
|
|
92
94
|
}
|
|
93
95
|
|
|
94
96
|
it 'fills with zeros when value precision is smaller than converter precision' do
|
|
95
97
|
n = 3.1
|
|
96
|
-
|
|
98
|
+
assert_equal '3.10', converter.raw(n)
|
|
97
99
|
end
|
|
98
100
|
|
|
99
101
|
it 'does not affect the representation when precision and converter precision are both equal' do
|
|
100
102
|
n = 3.14
|
|
101
|
-
|
|
103
|
+
assert_equal '3.14', converter.raw(n)
|
|
102
104
|
end
|
|
103
105
|
|
|
104
106
|
it 'does not truncate the representation when precision is larger than converter precision' do
|
|
105
107
|
n = 3.145
|
|
106
|
-
|
|
108
|
+
assert_equal '3.145', converter.raw(n)
|
|
107
109
|
end
|
|
108
110
|
end
|
|
109
111
|
|
|
@@ -2,43 +2,46 @@ require 'spec_helper'
|
|
|
2
2
|
|
|
3
3
|
describe Foraneus::Converters::Integer do
|
|
4
4
|
|
|
5
|
+
let(:converter) { Foraneus::Converters::Integer.new }
|
|
6
|
+
|
|
5
7
|
describe '#parse' do
|
|
6
|
-
|
|
8
|
+
|
|
9
|
+
describe 'with valid values' do
|
|
7
10
|
let(:number) { 1234 }
|
|
8
11
|
let(:raw_number) { number.to_s }
|
|
9
12
|
|
|
10
13
|
it 'returns an integer number' do
|
|
11
|
-
parsed =
|
|
14
|
+
parsed = converter.parse(raw_number)
|
|
12
15
|
|
|
13
|
-
|
|
16
|
+
assert_kind_of Integer, parsed
|
|
14
17
|
end
|
|
15
18
|
|
|
16
19
|
it 'parses the number' do
|
|
17
|
-
parsed =
|
|
20
|
+
parsed = converter.parse(raw_number)
|
|
18
21
|
|
|
19
|
-
|
|
22
|
+
assert_equal number, parsed
|
|
20
23
|
end
|
|
21
24
|
|
|
22
|
-
|
|
25
|
+
describe 'with big ones' do
|
|
23
26
|
let(:big_number) { (11 ** 20) }
|
|
24
27
|
let(:raw_big_number) { big_number.to_s }
|
|
25
28
|
|
|
26
29
|
it 'also returns an integer' do
|
|
27
|
-
parsed =
|
|
30
|
+
parsed = converter.parse(raw_big_number)
|
|
28
31
|
|
|
29
|
-
|
|
32
|
+
assert_kind_of Integer, parsed
|
|
30
33
|
end
|
|
31
34
|
|
|
32
35
|
it 'also parses the number' do
|
|
33
|
-
parsed =
|
|
36
|
+
parsed = converter.parse(raw_big_number)
|
|
34
37
|
|
|
35
|
-
|
|
38
|
+
assert_equal big_number, parsed
|
|
36
39
|
end
|
|
37
40
|
end
|
|
38
41
|
end
|
|
39
42
|
|
|
40
|
-
|
|
41
|
-
|
|
43
|
+
describe 'when delimiter is given' do
|
|
44
|
+
let(:converter) {
|
|
42
45
|
Foraneus::Converters::Integer.new(:delimiter => '.')
|
|
43
46
|
}
|
|
44
47
|
|
|
@@ -46,44 +49,44 @@ describe Foraneus::Converters::Integer do
|
|
|
46
49
|
s = '1.234.567'
|
|
47
50
|
n = 1_234_567
|
|
48
51
|
|
|
49
|
-
converter.parse(s)
|
|
52
|
+
assert_equal n, converter.parse(s)
|
|
50
53
|
end
|
|
51
54
|
end
|
|
52
55
|
|
|
53
|
-
|
|
56
|
+
describe 'with invalid values' do
|
|
54
57
|
let(:raw_invalid) { 'INVALID' }
|
|
55
58
|
|
|
56
59
|
it 'raises an error' do
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
}
|
|
60
|
+
assert_raises(ArgumentError) {
|
|
61
|
+
converter.parse(raw_invalid)
|
|
62
|
+
}
|
|
60
63
|
end
|
|
61
64
|
end
|
|
62
65
|
|
|
63
|
-
|
|
66
|
+
describe 'with empty values' do
|
|
64
67
|
it 'raises an error' do
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
}
|
|
68
|
+
assert_raises(ArgumentError) {
|
|
69
|
+
converter.parse('')
|
|
70
|
+
}
|
|
68
71
|
end
|
|
69
72
|
end
|
|
70
73
|
|
|
71
|
-
|
|
74
|
+
describe 'with nil values' do
|
|
72
75
|
it 'raises an error' do
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
}
|
|
76
|
+
assert_raises(TypeError) {
|
|
77
|
+
converter.parse(nil)
|
|
78
|
+
}
|
|
76
79
|
end
|
|
77
80
|
end
|
|
78
81
|
end
|
|
79
82
|
|
|
80
83
|
describe '#raw' do
|
|
81
84
|
it 'returns a string representation' do
|
|
82
|
-
|
|
85
|
+
assert_equal('2', converter.raw(2))
|
|
83
86
|
end
|
|
84
87
|
|
|
85
|
-
|
|
86
|
-
|
|
88
|
+
describe 'when delimiter is given' do
|
|
89
|
+
let(:converter) {
|
|
87
90
|
Foraneus::Converters::Integer.new(:delimiter => '.')
|
|
88
91
|
}
|
|
89
92
|
|
|
@@ -91,7 +94,7 @@ describe Foraneus::Converters::Integer do
|
|
|
91
94
|
n = 1_234_567
|
|
92
95
|
s = '1.234.567'
|
|
93
96
|
|
|
94
|
-
converter.raw(n)
|
|
97
|
+
assert_equal(s, converter.raw(n))
|
|
95
98
|
end
|
|
96
99
|
end
|
|
97
100
|
|
|
@@ -2,11 +2,13 @@ require 'spec_helper'
|
|
|
2
2
|
|
|
3
3
|
describe Foraneus::Converters::Noop do
|
|
4
4
|
|
|
5
|
+
let(:converter) { Foraneus::Converters::Noop.new }
|
|
6
|
+
|
|
5
7
|
describe '#parse' do
|
|
6
8
|
it 'returns the given object' do
|
|
7
9
|
o = Object.new
|
|
8
10
|
|
|
9
|
-
|
|
11
|
+
assert_equal(o, converter.parse(o))
|
|
10
12
|
end
|
|
11
13
|
end
|
|
12
14
|
|
|
@@ -14,7 +16,7 @@ describe Foraneus::Converters::Noop do
|
|
|
14
16
|
it 'returns the given object' do
|
|
15
17
|
o = Object.new
|
|
16
18
|
|
|
17
|
-
|
|
19
|
+
assert_equal(o, converter.raw(o))
|
|
18
20
|
end
|
|
19
21
|
end
|
|
20
22
|
end
|
|
@@ -2,27 +2,29 @@ require 'spec_helper'
|
|
|
2
2
|
|
|
3
3
|
describe Foraneus::Converters::String do
|
|
4
4
|
|
|
5
|
+
subject { Foraneus::Converters::String.new }
|
|
6
|
+
|
|
5
7
|
describe '#parse' do
|
|
6
8
|
it 'returns the string' do
|
|
7
9
|
parsed = subject.parse('string')
|
|
8
10
|
|
|
9
|
-
|
|
11
|
+
assert_equal 'string', parsed
|
|
10
12
|
end
|
|
11
13
|
|
|
12
14
|
it 'returns a string representation' do
|
|
13
15
|
parsed = subject.parse(1)
|
|
14
16
|
|
|
15
|
-
|
|
17
|
+
assert_equal '1', parsed
|
|
16
18
|
end
|
|
17
19
|
end
|
|
18
20
|
|
|
19
21
|
describe '#raw' do
|
|
20
22
|
it 'returns the string' do
|
|
21
|
-
|
|
23
|
+
assert_equal 'string', subject.raw('string')
|
|
22
24
|
end
|
|
23
25
|
|
|
24
26
|
it 'returns a string representation' do
|
|
25
|
-
subject.raw(1)
|
|
27
|
+
assert_equal '1', subject.raw(1)
|
|
26
28
|
end
|
|
27
29
|
end
|
|
28
30
|
end
|
data/spec/lib/foraneus_spec.rb
CHANGED
|
@@ -10,259 +10,350 @@ describe Foraneus do
|
|
|
10
10
|
end
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
describe '
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
its(:delay) { should eq(5) }
|
|
13
|
+
describe 'when errors accessor is renamed' do
|
|
14
|
+
let(:form_spec) {
|
|
15
|
+
Class.new(Foraneus) do
|
|
18
16
|
|
|
19
|
-
|
|
17
|
+
field :errors
|
|
20
18
|
|
|
21
|
-
|
|
19
|
+
accessors[:errors] = :non_clashing_errors
|
|
20
|
+
end
|
|
21
|
+
}
|
|
22
22
|
|
|
23
|
-
|
|
23
|
+
describe 'a parsed form' do
|
|
24
|
+
let(:form) { form_spec.parse(:errors => 'errors') }
|
|
24
25
|
|
|
25
|
-
|
|
26
|
+
it 'can return the errors field value' do
|
|
27
|
+
assert_equal 'errors', form.errors
|
|
28
|
+
end
|
|
26
29
|
|
|
27
|
-
it
|
|
30
|
+
it 'can return the raw errors value' do
|
|
31
|
+
assert_equal 'errors', form[:errors]
|
|
32
|
+
end
|
|
28
33
|
|
|
29
|
-
|
|
34
|
+
it 'responds to the new accessor' do
|
|
35
|
+
assert_equal({}, form.non_clashing_errors)
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
30
39
|
|
|
31
|
-
|
|
32
|
-
|
|
40
|
+
describe 'when data accessor is renamed' do
|
|
41
|
+
let(:form_spec) {
|
|
42
|
+
Class.new(Foraneus) do
|
|
33
43
|
|
|
34
|
-
|
|
44
|
+
field :delay
|
|
45
|
+
field :data
|
|
35
46
|
|
|
36
|
-
|
|
47
|
+
accessors[:data] = :non_clashing_data
|
|
48
|
+
end
|
|
49
|
+
}
|
|
37
50
|
|
|
38
|
-
|
|
51
|
+
describe 'a parsed form' do
|
|
52
|
+
let(:form) { form_spec.parse(:delay => 5, :data => 'value') }
|
|
39
53
|
|
|
40
|
-
|
|
54
|
+
it 'can return the data field value' do
|
|
55
|
+
assert_equal 'value', form.data
|
|
41
56
|
end
|
|
42
57
|
|
|
43
|
-
|
|
44
|
-
|
|
58
|
+
it 'responds to the new accessor' do
|
|
59
|
+
assert_equal({:delay => 5, :data => 'value'}, form.non_clashing_data)
|
|
60
|
+
end
|
|
45
61
|
|
|
46
|
-
|
|
62
|
+
end
|
|
47
63
|
|
|
48
|
-
|
|
64
|
+
describe 'when obtaining a raw representation' do
|
|
65
|
+
let(:form) { form_spec.raw(:delay => 5, :data => 'value') }
|
|
49
66
|
|
|
50
|
-
|
|
67
|
+
it 'allows access to the data field value' do
|
|
68
|
+
assert_equal 'value', form[:data]
|
|
69
|
+
end
|
|
51
70
|
|
|
52
|
-
|
|
71
|
+
it 'allows access to whole data set' do
|
|
72
|
+
assert_equal({:delay => 5, :data => 'value'}, form[])
|
|
53
73
|
end
|
|
54
74
|
end
|
|
75
|
+
end
|
|
55
76
|
|
|
56
|
-
|
|
57
|
-
|
|
77
|
+
describe '.parse' do
|
|
78
|
+
describe 'with parseable data' do
|
|
79
|
+
subject { form_spec.parse(:delay => '5') }
|
|
58
80
|
|
|
59
|
-
|
|
81
|
+
it 'parses' do
|
|
60
82
|
|
|
61
|
-
|
|
83
|
+
assert_equal 5, subject.delay
|
|
84
|
+
assert_equal 5, subject.data[:delay]
|
|
62
85
|
|
|
63
|
-
|
|
86
|
+
assert_equal '5', subject[:delay]
|
|
87
|
+
assert_nil subject['delay']
|
|
88
|
+
assert_equal({ :delay => '5' }, subject[])
|
|
64
89
|
|
|
65
|
-
|
|
90
|
+
assert subject.valid?
|
|
66
91
|
|
|
67
|
-
|
|
68
|
-
|
|
92
|
+
assert_empty subject.errors
|
|
93
|
+
end
|
|
69
94
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
converter.parse('FIVE')
|
|
73
|
-
rescue
|
|
74
|
-
e = $!
|
|
75
|
-
end
|
|
95
|
+
describe 'when strings as keys' do
|
|
96
|
+
subject { form_spec.parse('delay' => '5') }
|
|
76
97
|
|
|
77
|
-
|
|
98
|
+
it 'parses given data' do
|
|
99
|
+
assert_equal '5', subject['delay']
|
|
100
|
+
assert_equal '5', subject[:delay]
|
|
101
|
+
assert_equal 5, subject.data['delay']
|
|
102
|
+
|
|
103
|
+
assert_equal({ 'delay' => '5' }, subject[])
|
|
78
104
|
end
|
|
105
|
+
end
|
|
79
106
|
|
|
80
|
-
|
|
107
|
+
describe 'when empty strings' do
|
|
108
|
+
subject { form_spec.parse(:delay => '') }
|
|
81
109
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
end
|
|
110
|
+
it 'parses' do
|
|
111
|
+
assert_nil subject.delay
|
|
85
112
|
|
|
86
|
-
|
|
87
|
-
subject(:form) { form_spec.parse(:position => 'north') }
|
|
113
|
+
assert_nil subject.data[:delay]
|
|
88
114
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
form.position
|
|
92
|
-
}.to raise_error(NoMethodError)
|
|
115
|
+
assert subject.valid?
|
|
116
|
+
end
|
|
93
117
|
end
|
|
94
118
|
|
|
95
|
-
|
|
119
|
+
describe 'with non parseable data' do
|
|
120
|
+
subject { form_spec.parse(:delay => 'FIVE') }
|
|
96
121
|
|
|
97
|
-
|
|
122
|
+
it 'sets corresponding data as nil' do
|
|
123
|
+
assert_nil subject.delay
|
|
98
124
|
|
|
99
|
-
|
|
125
|
+
assert_equal 'FIVE', subject[:delay]
|
|
100
126
|
|
|
101
|
-
|
|
102
|
-
end
|
|
127
|
+
refute subject.valid?
|
|
103
128
|
|
|
104
|
-
|
|
105
|
-
|
|
129
|
+
assert_includes subject.errors, :delay
|
|
130
|
+
end
|
|
106
131
|
|
|
107
|
-
|
|
132
|
+
describe 'an error' do
|
|
133
|
+
let(:error) { subject.errors.values.first }
|
|
108
134
|
|
|
109
|
-
|
|
135
|
+
let(:converter_exception) do
|
|
136
|
+
begin
|
|
137
|
+
converter.parse('FIVE')
|
|
138
|
+
rescue
|
|
139
|
+
e = $!
|
|
140
|
+
end
|
|
110
141
|
|
|
111
|
-
|
|
142
|
+
e
|
|
143
|
+
end
|
|
112
144
|
|
|
113
|
-
|
|
145
|
+
it 'provides a key' do
|
|
146
|
+
assert_equal error.key, converter_exception.class.name
|
|
147
|
+
end
|
|
114
148
|
|
|
115
|
-
|
|
116
|
-
|
|
149
|
+
it 'provides a message' do
|
|
150
|
+
assert_equal error.message, converter_exception.message
|
|
151
|
+
end
|
|
152
|
+
end
|
|
153
|
+
end
|
|
117
154
|
|
|
118
|
-
|
|
119
|
-
|
|
155
|
+
describe 'with unexpected data' do
|
|
156
|
+
subject { form_spec.parse(:position => 'north') }
|
|
120
157
|
|
|
121
|
-
|
|
158
|
+
it 'does not have a getter for the received param' do
|
|
159
|
+
assert_raises(NoMethodError) {
|
|
160
|
+
subject.position
|
|
161
|
+
}
|
|
162
|
+
end
|
|
122
163
|
|
|
123
|
-
|
|
164
|
+
it 'parses' do
|
|
165
|
+
refute_includes subject.data, :position
|
|
124
166
|
|
|
125
|
-
|
|
126
|
-
end
|
|
167
|
+
assert_equal 'north', subject[:position]
|
|
127
168
|
|
|
128
|
-
|
|
129
|
-
subject(:form) { form_spec.parse(:delay => missing_value) }
|
|
169
|
+
assert_equal 'north', subject[][:position]
|
|
130
170
|
|
|
131
|
-
|
|
171
|
+
assert subject.valid?
|
|
172
|
+
end
|
|
173
|
+
end
|
|
132
174
|
|
|
133
|
-
|
|
175
|
+
describe 'when a field is declared as blanks_as_nil = true' do
|
|
176
|
+
let(:converter) { Foraneus::Converters::String.new(:blanks_as_nil => true) }
|
|
134
177
|
|
|
135
|
-
|
|
178
|
+
subject { form_spec.parse(:delay => '') }
|
|
136
179
|
|
|
137
|
-
|
|
180
|
+
it 'parses' do
|
|
181
|
+
assert_nil subject.delay
|
|
138
182
|
|
|
139
|
-
|
|
183
|
+
assert_equal({ :delay => nil }, subject.data)
|
|
184
|
+
assert_equal '', subject[:delay]
|
|
185
|
+
assert_equal({ :delay => '' }, subject[])
|
|
186
|
+
end
|
|
187
|
+
end
|
|
140
188
|
|
|
141
|
-
|
|
142
|
-
let(:converter) { Foraneus::Converters::
|
|
189
|
+
describe 'when a field is declared as blanks_as_nil = false' do
|
|
190
|
+
let(:converter) { Foraneus::Converters::String.new(:blanks_as_nil => false) }
|
|
143
191
|
|
|
144
|
-
|
|
192
|
+
subject { form_spec.parse(:delay => '') }
|
|
145
193
|
|
|
146
|
-
|
|
194
|
+
it 'parses' do
|
|
195
|
+
assert_equal '', subject.delay
|
|
196
|
+
assert_equal '', subject.data[:delay]
|
|
197
|
+
end
|
|
198
|
+
end
|
|
147
199
|
|
|
148
|
-
|
|
200
|
+
an_absent_parameters_value_handler = ->(missing_value) do
|
|
201
|
+
subject { form_spec.parse(:delay => missing_value) }
|
|
149
202
|
|
|
150
|
-
|
|
203
|
+
it 'parses' do
|
|
204
|
+
assert subject.valid?
|
|
151
205
|
|
|
152
|
-
|
|
206
|
+
assert_nil subject.delay
|
|
153
207
|
|
|
154
|
-
|
|
208
|
+
assert_equal missing_value, subject[:delay]
|
|
209
|
+
assert_equal missing_value, subject[][:delay]
|
|
210
|
+
end
|
|
155
211
|
|
|
156
|
-
describe '
|
|
157
|
-
|
|
212
|
+
describe 'when required field' do
|
|
213
|
+
let(:converter) { Foraneus::Converters::Integer.new(:required => true) }
|
|
214
|
+
|
|
215
|
+
it 'parses' do
|
|
216
|
+
refute subject.valid?
|
|
217
|
+
|
|
218
|
+
assert_nil subject.delay
|
|
219
|
+
|
|
220
|
+
refute_includes subject.data, :delay
|
|
221
|
+
|
|
222
|
+
assert_equal missing_value, subject[][:delay]
|
|
158
223
|
|
|
159
|
-
|
|
224
|
+
assert_includes subject.errors, :delay
|
|
225
|
+
end
|
|
226
|
+
|
|
227
|
+
describe 'an error' do
|
|
228
|
+
let(:error) { subject.errors.values.first }
|
|
229
|
+
|
|
230
|
+
it 'has key = KeyError' do
|
|
231
|
+
assert_equal 'KeyError', error.key
|
|
232
|
+
end
|
|
233
|
+
end
|
|
160
234
|
end
|
|
161
235
|
end
|
|
162
|
-
end
|
|
163
236
|
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
context 'with empty values' do
|
|
169
|
-
it_behaves_like 'an absent parameters value handler', ''
|
|
170
|
-
end
|
|
237
|
+
describe 'with nil values' do
|
|
238
|
+
instance_exec(nil, &an_absent_parameters_value_handler)
|
|
239
|
+
end
|
|
171
240
|
|
|
172
|
-
|
|
173
|
-
|
|
241
|
+
describe 'with empty values' do
|
|
242
|
+
instance_exec('', &an_absent_parameters_value_handler)
|
|
243
|
+
end
|
|
174
244
|
|
|
175
|
-
|
|
176
|
-
|
|
245
|
+
describe 'when required field' do
|
|
246
|
+
let(:converter) { Foraneus::Converters::Integer.new(:required => true) }
|
|
177
247
|
|
|
178
|
-
|
|
248
|
+
describe 'when missing input parameter' do
|
|
249
|
+
subject { form_spec.parse }
|
|
179
250
|
|
|
180
|
-
|
|
251
|
+
it 'parses' do
|
|
252
|
+
refute subject.valid?
|
|
181
253
|
|
|
182
|
-
|
|
254
|
+
assert_nil subject.delay
|
|
255
|
+
assert_nil subject[:delay]
|
|
256
|
+
end
|
|
257
|
+
end
|
|
183
258
|
end
|
|
184
|
-
end
|
|
185
259
|
|
|
186
|
-
|
|
187
|
-
|
|
260
|
+
describe 'when default value' do
|
|
261
|
+
let(:converter) { Foraneus::Converters::Integer.new(:default => 1) }
|
|
188
262
|
|
|
189
|
-
|
|
263
|
+
subject { form_spec.parse }
|
|
190
264
|
|
|
191
|
-
|
|
265
|
+
it 'parses' do
|
|
266
|
+
assert subject.valid?
|
|
192
267
|
|
|
193
|
-
|
|
268
|
+
assert_equal 1, subject.delay
|
|
194
269
|
|
|
195
|
-
|
|
270
|
+
assert_equal 1, subject.data[:delay]
|
|
196
271
|
|
|
197
|
-
|
|
272
|
+
assert_nil subject[:delay]
|
|
198
273
|
|
|
199
|
-
|
|
274
|
+
assert_nil subject[][:delay]
|
|
200
275
|
|
|
201
|
-
|
|
276
|
+
refute subject.errors.include?(:delay)
|
|
277
|
+
end
|
|
202
278
|
|
|
203
|
-
|
|
204
|
-
|
|
279
|
+
describe 'when missing required field' do
|
|
280
|
+
let(:converter) { Foraneus::Converters::Integer.new(:default => 1, :required => true) }
|
|
205
281
|
|
|
206
|
-
|
|
282
|
+
subject { form_spec.parse }
|
|
207
283
|
|
|
208
|
-
|
|
284
|
+
it 'parses' do
|
|
285
|
+
refute subject.valid?
|
|
209
286
|
|
|
210
|
-
|
|
287
|
+
assert_nil subject.delay
|
|
211
288
|
|
|
212
|
-
|
|
289
|
+
assert_nil subject[:delay]
|
|
290
|
+
end
|
|
291
|
+
end
|
|
213
292
|
end
|
|
214
293
|
end
|
|
215
294
|
end
|
|
216
295
|
|
|
217
296
|
describe '.raw' do
|
|
218
|
-
subject
|
|
297
|
+
subject { form_spec.raw(:delay => 5) }
|
|
219
298
|
|
|
220
|
-
|
|
299
|
+
it 'parses' do
|
|
300
|
+
assert_equal 5, subject.data[:delay]
|
|
221
301
|
|
|
222
|
-
|
|
302
|
+
assert_equal 5, subject.delay
|
|
223
303
|
|
|
224
|
-
|
|
304
|
+
assert_equal '5', subject[:delay]
|
|
225
305
|
|
|
226
|
-
|
|
306
|
+
assert_equal '5', subject[][:delay]
|
|
227
307
|
|
|
228
|
-
|
|
308
|
+
assert subject.valid?
|
|
229
309
|
|
|
230
|
-
|
|
310
|
+
assert_empty subject.errors
|
|
311
|
+
end
|
|
312
|
+
|
|
313
|
+
describe 'when strings as keys' do
|
|
314
|
+
subject { form_spec.raw('delay' => 5) }
|
|
231
315
|
|
|
232
|
-
|
|
233
|
-
|
|
316
|
+
it 'parses' do
|
|
317
|
+
assert_equal 5, subject.data['delay']
|
|
234
318
|
|
|
235
|
-
|
|
319
|
+
assert_equal '5', subject['delay']
|
|
236
320
|
|
|
237
|
-
|
|
321
|
+
assert_equal '5', subject[:delay]
|
|
238
322
|
|
|
239
|
-
|
|
323
|
+
assert_equal '5', subject[]['delay']
|
|
240
324
|
|
|
241
|
-
|
|
325
|
+
assert subject.valid?
|
|
326
|
+
|
|
327
|
+
assert_empty subject.errors
|
|
328
|
+
end
|
|
242
329
|
end
|
|
243
330
|
|
|
244
|
-
|
|
245
|
-
subject
|
|
331
|
+
describe 'with nil values' do
|
|
332
|
+
subject { form_spec.raw('delay' => nil) }
|
|
246
333
|
|
|
247
|
-
|
|
334
|
+
it 'parses' do
|
|
335
|
+
assert_nil subject.data['delay']
|
|
248
336
|
|
|
249
|
-
|
|
337
|
+
assert_nil subject['delay']
|
|
250
338
|
|
|
251
|
-
|
|
339
|
+
assert_nil subject[:delay]
|
|
252
340
|
|
|
253
|
-
|
|
341
|
+
assert_nil subject[]['delay']
|
|
342
|
+
end
|
|
254
343
|
end
|
|
255
344
|
|
|
256
|
-
|
|
345
|
+
describe 'when default value' do
|
|
257
346
|
let(:converter) { Foraneus::Converters::Integer.new(:default => 1) }
|
|
258
347
|
|
|
259
|
-
subject
|
|
260
|
-
|
|
261
|
-
its(:delay) { should be_nil }
|
|
348
|
+
subject { form_spec.raw }
|
|
262
349
|
|
|
263
|
-
|
|
350
|
+
it 'parses' do
|
|
351
|
+
assert_nil subject.delay
|
|
264
352
|
|
|
265
|
-
|
|
353
|
+
assert_equal '1', subject[:delay]
|
|
354
|
+
assert_equal '1', subject[][:delay]
|
|
355
|
+
end
|
|
266
356
|
end
|
|
267
357
|
end
|
|
358
|
+
|
|
268
359
|
end
|