active_interaction 0.9.0 → 0.9.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +10 -1
- data/README.md +4 -4
- data/lib/active_interaction.rb +2 -0
- data/lib/active_interaction/base.rb +26 -14
- data/lib/active_interaction/errors.rb +7 -10
- data/lib/active_interaction/filter.rb +10 -10
- data/lib/active_interaction/filters.rb +2 -0
- data/lib/active_interaction/filters/abstract_date_time_filter.rb +4 -2
- data/lib/active_interaction/filters/abstract_numeric_filter.rb +3 -1
- data/lib/active_interaction/filters/array_filter.rb +5 -3
- data/lib/active_interaction/filters/boolean_filter.rb +2 -0
- data/lib/active_interaction/filters/date_filter.rb +2 -0
- data/lib/active_interaction/filters/date_time_filter.rb +2 -0
- data/lib/active_interaction/filters/file_filter.rb +2 -0
- data/lib/active_interaction/filters/float_filter.rb +2 -0
- data/lib/active_interaction/filters/hash_filter.rb +7 -6
- data/lib/active_interaction/filters/integer_filter.rb +2 -0
- data/lib/active_interaction/filters/model_filter.rb +2 -0
- data/lib/active_interaction/filters/string_filter.rb +2 -0
- data/lib/active_interaction/filters/symbol_filter.rb +2 -0
- data/lib/active_interaction/filters/time_filter.rb +2 -0
- data/lib/active_interaction/modules/active_model.rb +2 -0
- data/lib/active_interaction/modules/core.rb +4 -1
- data/lib/active_interaction/modules/method_missing.rb +2 -0
- data/lib/active_interaction/modules/overload_hash.rb +2 -0
- data/lib/active_interaction/modules/validation.rb +10 -5
- data/lib/active_interaction/version.rb +4 -1
- data/spec/active_interaction/base_spec.rb +60 -35
- data/spec/active_interaction/errors_spec.rb +48 -14
- data/spec/active_interaction/filter_spec.rb +4 -2
- data/spec/active_interaction/filters/array_filter_spec.rb +13 -6
- data/spec/active_interaction/filters/boolean_filter_spec.rb +2 -0
- data/spec/active_interaction/filters/date_filter_spec.rb +6 -4
- data/spec/active_interaction/filters/date_time_filter_spec.rb +6 -4
- data/spec/active_interaction/filters/file_filter_spec.rb +2 -0
- data/spec/active_interaction/filters/float_filter_spec.rb +4 -2
- data/spec/active_interaction/filters/hash_filter_spec.rb +16 -4
- data/spec/active_interaction/filters/integer_filter_spec.rb +4 -2
- data/spec/active_interaction/filters/model_filter_spec.rb +4 -2
- data/spec/active_interaction/filters/string_filter_spec.rb +2 -0
- data/spec/active_interaction/filters/symbol_filter_spec.rb +2 -0
- data/spec/active_interaction/filters/time_filter_spec.rb +6 -4
- data/spec/active_interaction/filters_spec.rb +2 -0
- data/spec/active_interaction/i18n_spec.rb +9 -9
- data/spec/active_interaction/integration/array_interaction_spec.rb +10 -8
- data/spec/active_interaction/integration/boolean_interaction_spec.rb +2 -0
- data/spec/active_interaction/integration/date_interaction_spec.rb +2 -0
- data/spec/active_interaction/integration/date_time_interaction_spec.rb +2 -0
- data/spec/active_interaction/integration/file_interaction_spec.rb +2 -0
- data/spec/active_interaction/integration/float_interaction_spec.rb +2 -0
- data/spec/active_interaction/integration/hash_interaction_spec.rb +10 -8
- data/spec/active_interaction/integration/integer_interaction_spec.rb +2 -0
- data/spec/active_interaction/integration/model_interaction_spec.rb +3 -1
- data/spec/active_interaction/integration/string_interaction_spec.rb +2 -0
- data/spec/active_interaction/integration/symbol_interaction_spec.rb +2 -0
- data/spec/active_interaction/integration/time_interaction_spec.rb +9 -7
- data/spec/active_interaction/modules/active_model_spec.rb +2 -0
- data/spec/active_interaction/modules/core_spec.rb +12 -7
- data/spec/active_interaction/modules/method_missing_spec.rb +12 -10
- data/spec/active_interaction/modules/overload_hash_spec.rb +7 -5
- data/spec/active_interaction/modules/validation_spec.rb +5 -2
- data/spec/spec_helper.rb +4 -0
- data/spec/support/filters.rb +18 -16
- data/spec/support/interactions.rb +13 -11
- metadata +20 -6
@@ -1,3 +1,5 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
describe ActiveInteraction::DateFilter, :filter do
|
@@ -43,18 +45,18 @@ describe ActiveInteraction::DateFilter, :filter do
|
|
43
45
|
let(:value) { 'invalid' }
|
44
46
|
|
45
47
|
it 'raises an error' do
|
46
|
-
expect
|
48
|
+
expect do
|
47
49
|
filter.cast(value)
|
48
|
-
|
50
|
+
end.to raise_error ActiveInteraction::InvalidValueError
|
49
51
|
end
|
50
52
|
|
51
53
|
context 'with format' do
|
52
54
|
include_context 'with format'
|
53
55
|
|
54
56
|
it 'raises an error' do
|
55
|
-
expect
|
57
|
+
expect do
|
56
58
|
filter.cast(value)
|
57
|
-
|
59
|
+
end.to raise_error ActiveInteraction::InvalidValueError
|
58
60
|
end
|
59
61
|
end
|
60
62
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
describe ActiveInteraction::DateTimeFilter, :filter do
|
@@ -43,18 +45,18 @@ describe ActiveInteraction::DateTimeFilter, :filter do
|
|
43
45
|
let(:value) { 'invalid' }
|
44
46
|
|
45
47
|
it 'raises an error' do
|
46
|
-
expect
|
48
|
+
expect do
|
47
49
|
filter.cast(value)
|
48
|
-
|
50
|
+
end.to raise_error ActiveInteraction::InvalidValueError
|
49
51
|
end
|
50
52
|
|
51
53
|
context 'with format' do
|
52
54
|
include_context 'with format'
|
53
55
|
|
54
56
|
it 'raises an error' do
|
55
|
-
expect
|
57
|
+
expect do
|
56
58
|
filter.cast(value)
|
57
|
-
|
59
|
+
end.to raise_error ActiveInteraction::InvalidValueError
|
58
60
|
end
|
59
61
|
end
|
60
62
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
describe ActiveInteraction::FloatFilter, :filter do
|
@@ -33,9 +35,9 @@ describe ActiveInteraction::FloatFilter, :filter do
|
|
33
35
|
let(:value) { 'invalid' }
|
34
36
|
|
35
37
|
it 'raises an error' do
|
36
|
-
expect
|
38
|
+
expect do
|
37
39
|
filter.cast(value)
|
38
|
-
|
40
|
+
end.to raise_error ActiveInteraction::InvalidValueError
|
39
41
|
end
|
40
42
|
end
|
41
43
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
describe ActiveInteraction::HashFilter, :filter do
|
@@ -5,7 +7,7 @@ describe ActiveInteraction::HashFilter, :filter do
|
|
5
7
|
it_behaves_like 'a filter'
|
6
8
|
|
7
9
|
context 'with a nested nameless filter' do
|
8
|
-
let(:block) {
|
10
|
+
let(:block) { proc { hash } }
|
9
11
|
|
10
12
|
it 'raises an error' do
|
11
13
|
expect { filter }.to raise_error ActiveInteraction::InvalidFilterError
|
@@ -30,7 +32,7 @@ describe ActiveInteraction::HashFilter, :filter do
|
|
30
32
|
end
|
31
33
|
|
32
34
|
context 'with a nested filter' do
|
33
|
-
let(:block) {
|
35
|
+
let(:block) { proc { hash :a } }
|
34
36
|
|
35
37
|
context 'with a Hash' do
|
36
38
|
let(:value) { { a: {} } }
|
@@ -38,6 +40,16 @@ describe ActiveInteraction::HashFilter, :filter do
|
|
38
40
|
it 'returns the Hash' do
|
39
41
|
expect(filter.cast(value)).to eq value
|
40
42
|
end
|
43
|
+
|
44
|
+
context 'with String keys' do
|
45
|
+
before do
|
46
|
+
value.stringify_keys!
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'does not raise an error' do
|
50
|
+
expect { filter.cast(value) }.to_not raise_error
|
51
|
+
end
|
52
|
+
end
|
41
53
|
end
|
42
54
|
end
|
43
55
|
end
|
@@ -59,9 +71,9 @@ describe ActiveInteraction::HashFilter, :filter do
|
|
59
71
|
end
|
60
72
|
|
61
73
|
it 'raises an error' do
|
62
|
-
expect
|
74
|
+
expect do
|
63
75
|
filter.default
|
64
|
-
|
76
|
+
end.to raise_error ActiveInteraction::InvalidDefaultError
|
65
77
|
end
|
66
78
|
end
|
67
79
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
describe ActiveInteraction::IntegerFilter, :filter do
|
@@ -33,9 +35,9 @@ describe ActiveInteraction::IntegerFilter, :filter do
|
|
33
35
|
let(:value) { 'invalid' }
|
34
36
|
|
35
37
|
it 'raises an error' do
|
36
|
-
expect
|
38
|
+
expect do
|
37
39
|
filter.cast(value)
|
38
|
-
|
40
|
+
end.to raise_error ActiveInteraction::InvalidValueError
|
39
41
|
end
|
40
42
|
end
|
41
43
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
class Model; end
|
@@ -35,9 +37,9 @@ describe ActiveInteraction::ModelFilter, :filter do
|
|
35
37
|
end
|
36
38
|
|
37
39
|
it 'raises an error' do
|
38
|
-
expect
|
40
|
+
expect do
|
39
41
|
filter.cast(value)
|
40
|
-
|
42
|
+
end.to raise_error ActiveInteraction::InvalidClassError
|
41
43
|
end
|
42
44
|
end
|
43
45
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
describe ActiveInteraction::TimeFilter, :filter do
|
@@ -43,18 +45,18 @@ describe ActiveInteraction::TimeFilter, :filter do
|
|
43
45
|
let(:value) { 'invalid' }
|
44
46
|
|
45
47
|
it 'raises an error' do
|
46
|
-
expect
|
48
|
+
expect do
|
47
49
|
filter.cast(value)
|
48
|
-
|
50
|
+
end.to raise_error ActiveInteraction::InvalidValueError
|
49
51
|
end
|
50
52
|
|
51
53
|
context 'with format' do
|
52
54
|
include_context 'with format'
|
53
55
|
|
54
56
|
it do
|
55
|
-
expect
|
57
|
+
expect do
|
56
58
|
filter.cast(value)
|
57
|
-
|
59
|
+
end.to raise_error ActiveInteraction::InvalidValueError
|
58
60
|
end
|
59
61
|
end
|
60
62
|
end
|
@@ -1,11 +1,11 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
|
-
|
5
|
+
I18nInteraction = Class.new(TestInteraction) do
|
4
6
|
hash :a do
|
5
7
|
hash :x
|
6
8
|
end
|
7
|
-
|
8
|
-
def execute; end
|
9
9
|
end
|
10
10
|
|
11
11
|
describe I18nInteraction do
|
@@ -47,7 +47,7 @@ describe I18nInteraction do
|
|
47
47
|
end
|
48
48
|
|
49
49
|
it 'returns the translation' do
|
50
|
-
|
50
|
+
inputs.merge!(a: Object.new)
|
51
51
|
expect(outcome.errors[:a]).to eq [translation]
|
52
52
|
end
|
53
53
|
end
|
@@ -74,20 +74,20 @@ describe I18nInteraction do
|
|
74
74
|
end
|
75
75
|
end
|
76
76
|
|
77
|
-
context '
|
77
|
+
context 'hsilgne' do
|
78
78
|
include_examples 'translation'
|
79
79
|
|
80
80
|
before do
|
81
|
-
I18n.
|
82
|
-
|
83
|
-
I18n.backend.store_translations(I18n.locale, active_interaction: {
|
81
|
+
I18n.backend.store_translations('hsilgne', active_interaction: {
|
84
82
|
errors: { messages: {
|
85
83
|
invalid: "%{type} #{'invalid'.reverse}",
|
86
84
|
invalid_nested: 'invalid_nested'.reverse,
|
87
85
|
missing: 'missing'.reverse
|
88
86
|
} },
|
89
|
-
types: TYPES.
|
87
|
+
types: TYPES.each_with_object({}) { |e, a| a[e] = e.reverse }
|
90
88
|
})
|
89
|
+
|
90
|
+
I18n.locale = 'hsilgne'
|
91
91
|
end
|
92
92
|
end
|
93
93
|
end
|
@@ -1,6 +1,8 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
|
-
|
5
|
+
ArrayInteraction = Class.new(TestInteraction) do
|
4
6
|
array :a do
|
5
7
|
array
|
6
8
|
end
|
@@ -9,7 +11,7 @@ class ArrayInteraction < ActiveInteraction::Base
|
|
9
11
|
end
|
10
12
|
|
11
13
|
def execute
|
12
|
-
|
14
|
+
inputs
|
13
15
|
end
|
14
16
|
end
|
15
17
|
|
@@ -17,10 +19,10 @@ describe ArrayInteraction do
|
|
17
19
|
include_context 'interactions'
|
18
20
|
it_behaves_like 'an interaction', :array, -> { [] }
|
19
21
|
|
20
|
-
context 'with
|
22
|
+
context 'with inputs[:a]' do
|
21
23
|
let(:a) { [[]] }
|
22
24
|
|
23
|
-
before {
|
25
|
+
before { inputs.merge!(a: a) }
|
24
26
|
|
25
27
|
it 'returns the correct value for :a' do
|
26
28
|
expect(result[:a]).to eq a
|
@@ -33,23 +35,23 @@ describe ArrayInteraction do
|
|
33
35
|
|
34
36
|
context 'with an invalid default' do
|
35
37
|
it 'raises an error' do
|
36
|
-
expect
|
38
|
+
expect do
|
37
39
|
Class.new(ActiveInteraction::Base) do
|
38
40
|
array :a, default: Object.new
|
39
41
|
end
|
40
|
-
|
42
|
+
end.to raise_error ActiveInteraction::InvalidDefaultError
|
41
43
|
end
|
42
44
|
end
|
43
45
|
|
44
46
|
context 'with an invalid nested default' do
|
45
47
|
it 'raises an error' do
|
46
|
-
expect
|
48
|
+
expect do
|
47
49
|
Class.new(ActiveInteraction::Base) do
|
48
50
|
array :a, default: [Object.new] do
|
49
51
|
array
|
50
52
|
end
|
51
53
|
end
|
52
|
-
|
54
|
+
end.to raise_error ActiveInteraction::InvalidDefaultError
|
53
55
|
end
|
54
56
|
end
|
55
57
|
end
|
@@ -1,6 +1,8 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
|
-
|
5
|
+
HashInteraction = Class.new(TestInteraction) do
|
4
6
|
hash :a do
|
5
7
|
hash :x
|
6
8
|
end
|
@@ -9,7 +11,7 @@ class HashInteraction < ActiveInteraction::Base
|
|
9
11
|
end
|
10
12
|
|
11
13
|
def execute
|
12
|
-
|
14
|
+
inputs
|
13
15
|
end
|
14
16
|
end
|
15
17
|
|
@@ -17,10 +19,10 @@ describe HashInteraction do
|
|
17
19
|
include_context 'interactions'
|
18
20
|
it_behaves_like 'an interaction', :hash, -> { {} }
|
19
21
|
|
20
|
-
context 'with
|
22
|
+
context 'with inputs[:a]' do
|
21
23
|
let(:a) { { x: {} } }
|
22
24
|
|
23
|
-
before {
|
25
|
+
before { inputs.merge!(a: a) }
|
24
26
|
|
25
27
|
it 'returns the correct value for :a' do
|
26
28
|
expect(result[:a]).to eq a.symbolize_keys
|
@@ -33,23 +35,23 @@ describe HashInteraction do
|
|
33
35
|
|
34
36
|
context 'with an invalid default' do
|
35
37
|
it 'raises an error' do
|
36
|
-
expect
|
38
|
+
expect do
|
37
39
|
Class.new(ActiveInteraction::Base) do
|
38
40
|
hash :a, default: Object.new
|
39
41
|
end
|
40
|
-
|
42
|
+
end.to raise_error ActiveInteraction::InvalidDefaultError
|
41
43
|
end
|
42
44
|
end
|
43
45
|
|
44
46
|
context 'with an invalid nested default' do
|
45
47
|
it 'raises an error' do
|
46
|
-
expect
|
48
|
+
expect do
|
47
49
|
Class.new(ActiveInteraction::Base) do
|
48
50
|
hash :a, default: { x: Object.new } do
|
49
51
|
hash :x
|
50
52
|
end
|
51
53
|
end
|
52
|
-
|
54
|
+
end.to raise_error ActiveInteraction::InvalidDefaultError
|
53
55
|
end
|
54
56
|
end
|
55
57
|
end
|