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,26 +1,28 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
|
-
|
5
|
+
TimeZone = Class.new do
|
4
6
|
def self.at(*args)
|
5
7
|
TimeWithZone.at(*args)
|
6
8
|
end
|
7
9
|
end
|
8
10
|
|
9
|
-
|
11
|
+
TimeWithZone = Class.new do
|
10
12
|
def self.at(*args)
|
11
|
-
|
13
|
+
new(Time.at(*args))
|
12
14
|
end
|
13
15
|
|
14
16
|
def initialize(time)
|
15
17
|
@time = time
|
16
18
|
end
|
17
19
|
|
18
|
-
def ==(
|
19
|
-
@time ==
|
20
|
+
def ==(other)
|
21
|
+
@time == other
|
20
22
|
end
|
21
23
|
end
|
22
24
|
|
23
|
-
|
25
|
+
TimeInteraction = Class.new(TestInteraction) do
|
24
26
|
time :a
|
25
27
|
|
26
28
|
def execute
|
@@ -37,7 +39,7 @@ describe TimeInteraction do
|
|
37
39
|
|
38
40
|
before do
|
39
41
|
allow(Time).to receive(:zone).and_return(TimeZone)
|
40
|
-
|
42
|
+
inputs.merge!(a: a)
|
41
43
|
end
|
42
44
|
|
43
45
|
it 'returns the correct value' do
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
describe ActiveInteraction::Core do
|
@@ -31,11 +33,14 @@ describe ActiveInteraction::Core do
|
|
31
33
|
end
|
32
34
|
|
33
35
|
shared_examples '#run!' do
|
34
|
-
let(:
|
36
|
+
let(:inputs) { double }
|
35
37
|
|
36
38
|
it 'calls #run' do
|
37
|
-
|
38
|
-
|
39
|
+
begin
|
40
|
+
instance.run!(inputs)
|
41
|
+
rescue ActiveInteraction::InvalidInteractionError
|
42
|
+
expect(instance).to have_received(:run).once.with(inputs)
|
43
|
+
end
|
39
44
|
end
|
40
45
|
end
|
41
46
|
|
@@ -47,9 +52,9 @@ describe ActiveInteraction::Core do
|
|
47
52
|
end
|
48
53
|
|
49
54
|
it 'raises an error' do
|
50
|
-
expect
|
55
|
+
expect do
|
51
56
|
instance.run!
|
52
|
-
|
57
|
+
end.to raise_error ActiveInteraction::InvalidInteractionError
|
53
58
|
end
|
54
59
|
end
|
55
60
|
|
@@ -93,14 +98,14 @@ describe ActiveInteraction::Core do
|
|
93
98
|
end
|
94
99
|
|
95
100
|
it 'calls ActiveRecord::Base#transaction' do
|
96
|
-
block =
|
101
|
+
block = proc {}
|
97
102
|
expect(ActiveRecord::Base).to receive(:transaction).once.with(no_args)
|
98
103
|
instance.send(:transaction, &block)
|
99
104
|
end
|
100
105
|
|
101
106
|
it 'calls ActiveRecord::Base#transaction' do
|
102
107
|
args = [:a, :b, :c]
|
103
|
-
block =
|
108
|
+
block = proc {}
|
104
109
|
expect(ActiveRecord::Base).to receive(:transaction).once.with(*args)
|
105
110
|
instance.send(:transaction, *args, &block)
|
106
111
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
describe ActiveInteraction::MethodMissing do
|
@@ -9,9 +11,9 @@ describe ActiveInteraction::MethodMissing do
|
|
9
11
|
let(:slug) { :slug }
|
10
12
|
|
11
13
|
it 'calls super' do
|
12
|
-
expect
|
14
|
+
expect do
|
13
15
|
instance.method_missing(slug)
|
14
|
-
|
16
|
+
end.to raise_error NameError
|
15
17
|
end
|
16
18
|
end
|
17
19
|
|
@@ -24,18 +26,18 @@ describe ActiveInteraction::MethodMissing do
|
|
24
26
|
end
|
25
27
|
|
26
28
|
it 'yields' do
|
27
|
-
expect
|
29
|
+
expect do |b|
|
28
30
|
instance.method_missing(slug, &b)
|
29
|
-
|
31
|
+
end.to yield_with_args(filter, [], {})
|
30
32
|
end
|
31
33
|
|
32
34
|
context 'with names' do
|
33
35
|
let(:names) { [:a, :b, :c] }
|
34
36
|
|
35
37
|
it 'yields' do
|
36
|
-
expect
|
38
|
+
expect do |b|
|
37
39
|
instance.method_missing(:boolean, *names, &b)
|
38
|
-
|
40
|
+
end.to yield_with_args(filter, names, {})
|
39
41
|
end
|
40
42
|
end
|
41
43
|
|
@@ -43,9 +45,9 @@ describe ActiveInteraction::MethodMissing do
|
|
43
45
|
let(:options) { { a: nil, b: false, c: true } }
|
44
46
|
|
45
47
|
it 'yields' do
|
46
|
-
expect
|
48
|
+
expect do |b|
|
47
49
|
instance.method_missing(:boolean, options, &b)
|
48
|
-
|
50
|
+
end.to yield_with_args(filter, [], options)
|
49
51
|
end
|
50
52
|
end
|
51
53
|
|
@@ -54,9 +56,9 @@ describe ActiveInteraction::MethodMissing do
|
|
54
56
|
let(:options) { { a: nil, b: false, c: true } }
|
55
57
|
|
56
58
|
it 'yields' do
|
57
|
-
expect
|
59
|
+
expect do |b|
|
58
60
|
instance.method_missing(:boolean, *names, options, &b)
|
59
|
-
|
61
|
+
end.to yield_with_args(filter, names, options)
|
60
62
|
end
|
61
63
|
end
|
62
64
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
describe ActiveInteraction::OverloadHash do
|
@@ -21,18 +23,18 @@ describe ActiveInteraction::OverloadHash do
|
|
21
23
|
|
22
24
|
it 'calls method_missing' do
|
23
25
|
hash
|
24
|
-
expect(subject).to have_received(:method_missing).once
|
25
|
-
with(:hash, *arguments)
|
26
|
+
expect(subject).to have_received(:method_missing).once
|
27
|
+
.with(:hash, *arguments)
|
26
28
|
end
|
27
29
|
|
28
30
|
context 'with a block' do
|
29
|
-
let(:block) {
|
31
|
+
let(:block) { proc {} }
|
30
32
|
let(:hash) { subject.hash(*arguments, &block) }
|
31
33
|
|
32
34
|
it 'calls method_missing' do
|
33
35
|
hash
|
34
|
-
expect(subject).to have_received(:method_missing).once
|
35
|
-
with(:hash, *arguments)
|
36
|
+
expect(subject).to have_received(:method_missing).once
|
37
|
+
.with(:hash, *arguments)
|
36
38
|
end
|
37
39
|
|
38
40
|
it 'passes the block to method_missing' do
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
describe ActiveInteraction::Validation do
|
@@ -16,7 +18,7 @@ describe ActiveInteraction::Validation do
|
|
16
18
|
end
|
17
19
|
|
18
20
|
context 'filter.cast returns a value' do
|
19
|
-
let(:inputs) { {name: 1} }
|
21
|
+
let(:inputs) { { name: 1 } }
|
20
22
|
|
21
23
|
before do
|
22
24
|
filter.stub(:cast).and_return(1)
|
@@ -37,7 +39,8 @@ describe ActiveInteraction::Validation do
|
|
37
39
|
let(:filter) { ActiveInteraction::FloatFilter.new(:name, {}) }
|
38
40
|
|
39
41
|
it 'returns an :invalid_nested error' do
|
40
|
-
type = I18n.translate(
|
42
|
+
type = I18n.translate(
|
43
|
+
"#{ActiveInteraction::Base.i18n_scope}.types.#{filter.class.slug}")
|
41
44
|
|
42
45
|
expect(result).to eq [[filter.name, :invalid, nil, type: type]]
|
43
46
|
end
|
data/spec/spec_helper.rb
CHANGED
data/spec/support/filters.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
1
3
|
shared_context 'filters' do
|
2
4
|
let(:block) { nil }
|
3
5
|
let(:name) { SecureRandom.hex.to_sym }
|
@@ -24,9 +26,9 @@ shared_examples_for 'a filter' do
|
|
24
26
|
describe '.factory' do
|
25
27
|
context 'with an invalid slug' do
|
26
28
|
it 'raises an error' do
|
27
|
-
expect
|
29
|
+
expect do
|
28
30
|
described_class.factory(:invalid)
|
29
|
-
|
31
|
+
end.to raise_error ActiveInteraction::MissingFilterError
|
30
32
|
end
|
31
33
|
end
|
32
34
|
|
@@ -60,18 +62,18 @@ shared_examples_for 'a filter' do
|
|
60
62
|
include_context 'required'
|
61
63
|
|
62
64
|
it 'raises an error' do
|
63
|
-
expect
|
65
|
+
expect do
|
64
66
|
filter.cast(value)
|
65
|
-
|
67
|
+
end.to raise_error ActiveInteraction::MissingValueError
|
66
68
|
end
|
67
69
|
|
68
70
|
context 'with an invalid default' do
|
69
71
|
let(:value) { Object.new }
|
70
72
|
|
71
73
|
it 'raises an error' do
|
72
|
-
expect
|
74
|
+
expect do
|
73
75
|
filter.cast(value)
|
74
|
-
|
76
|
+
end.to raise_error ActiveInteraction::InvalidValueError
|
75
77
|
end
|
76
78
|
end
|
77
79
|
end
|
@@ -92,18 +94,18 @@ shared_examples_for 'a filter' do
|
|
92
94
|
include_context 'required'
|
93
95
|
|
94
96
|
it 'raises an error' do
|
95
|
-
expect
|
97
|
+
expect do
|
96
98
|
filter.clean(value)
|
97
|
-
|
99
|
+
end.to raise_error ActiveInteraction::MissingValueError
|
98
100
|
end
|
99
101
|
|
100
102
|
context 'with an invalid value' do
|
101
103
|
let(:value) { Object.new }
|
102
104
|
|
103
105
|
it 'raises an error' do
|
104
|
-
expect
|
106
|
+
expect do
|
105
107
|
filter.clean(value)
|
106
|
-
|
108
|
+
end.to raise_error ActiveInteraction::InvalidValueError
|
107
109
|
end
|
108
110
|
end
|
109
111
|
end
|
@@ -114,9 +116,9 @@ shared_examples_for 'a filter' do
|
|
114
116
|
end
|
115
117
|
|
116
118
|
it 'raises an error' do
|
117
|
-
expect
|
119
|
+
expect do
|
118
120
|
filter.clean(value)
|
119
|
-
|
121
|
+
end.to raise_error ActiveInteraction::InvalidDefaultError
|
120
122
|
end
|
121
123
|
end
|
122
124
|
end
|
@@ -134,9 +136,9 @@ shared_examples_for 'a filter' do
|
|
134
136
|
include_context 'required'
|
135
137
|
|
136
138
|
it 'raises an error' do
|
137
|
-
expect
|
139
|
+
expect do
|
138
140
|
filter.default
|
139
|
-
|
141
|
+
end.to raise_error ActiveInteraction::NoDefaultError
|
140
142
|
end
|
141
143
|
end
|
142
144
|
|
@@ -146,9 +148,9 @@ shared_examples_for 'a filter' do
|
|
146
148
|
end
|
147
149
|
|
148
150
|
it 'raises an error' do
|
149
|
-
expect
|
151
|
+
expect do
|
150
152
|
filter.default
|
151
|
-
|
153
|
+
end.to raise_error ActiveInteraction::InvalidDefaultError
|
152
154
|
end
|
153
155
|
end
|
154
156
|
end
|
@@ -1,4 +1,6 @@
|
|
1
|
-
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
TestInteraction = Class.new(ActiveInteraction::Base) do
|
2
4
|
def self.name
|
3
5
|
SecureRandom.hex
|
4
6
|
end
|
@@ -8,8 +10,8 @@ class TestInteraction < ActiveInteraction::Base
|
|
8
10
|
end
|
9
11
|
|
10
12
|
shared_context 'interactions' do
|
11
|
-
let(:
|
12
|
-
let(:outcome) { described_class.run(
|
13
|
+
let(:inputs) { {} }
|
14
|
+
let(:outcome) { described_class.run(inputs) }
|
13
15
|
let(:result) { outcome.result }
|
14
16
|
end
|
15
17
|
|
@@ -36,16 +38,16 @@ shared_examples_for 'an interaction' do |type, generator, filter_options = {}|
|
|
36
38
|
end
|
37
39
|
end
|
38
40
|
|
39
|
-
context 'without required
|
41
|
+
context 'without required inputs' do
|
40
42
|
it 'is invalid' do
|
41
43
|
expect(outcome).to be_invalid
|
42
44
|
end
|
43
45
|
end
|
44
46
|
|
45
|
-
context 'with
|
47
|
+
context 'with inputs[:required]' do
|
46
48
|
let(:required) { generator.call }
|
47
49
|
|
48
|
-
before {
|
50
|
+
before { inputs.merge!(required: required) }
|
49
51
|
|
50
52
|
it 'is valid' do
|
51
53
|
expect(outcome).to be_valid
|
@@ -64,7 +66,7 @@ shared_examples_for 'an interaction' do |type, generator, filter_options = {}|
|
|
64
66
|
end
|
65
67
|
|
66
68
|
it 'does not return nil for :default when given nil' do
|
67
|
-
|
69
|
+
inputs.merge!(default: nil)
|
68
70
|
expect(result[:default]).to_not be_nil
|
69
71
|
end
|
70
72
|
|
@@ -76,20 +78,20 @@ shared_examples_for 'an interaction' do |type, generator, filter_options = {}|
|
|
76
78
|
expect(result[:defaults_2]).to_not be_nil
|
77
79
|
end
|
78
80
|
|
79
|
-
context 'with
|
81
|
+
context 'with inputs[:optional]' do
|
80
82
|
let(:optional) { generator.call }
|
81
83
|
|
82
|
-
before {
|
84
|
+
before { inputs.merge!(optional: optional) }
|
83
85
|
|
84
86
|
it 'returns the correct value for :optional' do
|
85
87
|
expect(result[:optional]).to eq optional
|
86
88
|
end
|
87
89
|
end
|
88
90
|
|
89
|
-
context 'with
|
91
|
+
context 'with inputs[:default]' do
|
90
92
|
let(:default) { generator.call }
|
91
93
|
|
92
|
-
before {
|
94
|
+
before { inputs.merge!(default: default) }
|
93
95
|
|
94
96
|
it 'returns the correct value for :default' do
|
95
97
|
expect(result[:default]).to eq default
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_interaction
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Aaron Lasseigne
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-12-
|
12
|
+
date: 2013-12-17 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activemodel
|
@@ -51,28 +51,28 @@ dependencies:
|
|
51
51
|
requirements:
|
52
52
|
- - ~>
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '0.
|
54
|
+
version: '0.7'
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
57
|
version_requirements: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - ~>
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '0.
|
61
|
+
version: '0.7'
|
62
62
|
- !ruby/object:Gem::Dependency
|
63
63
|
name: guard-rspec
|
64
64
|
requirement: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - ~>
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: '
|
68
|
+
version: '4.2'
|
69
69
|
type: :development
|
70
70
|
prerelease: false
|
71
71
|
version_requirements: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
73
|
- - ~>
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: '
|
75
|
+
version: '4.2'
|
76
76
|
- !ruby/object:Gem::Dependency
|
77
77
|
name: rake
|
78
78
|
requirement: !ruby/object:Gem::Requirement
|
@@ -129,6 +129,20 @@ dependencies:
|
|
129
129
|
- - ~>
|
130
130
|
- !ruby/object:Gem::Version
|
131
131
|
version: '2.14'
|
132
|
+
- !ruby/object:Gem::Dependency
|
133
|
+
name: rubocop
|
134
|
+
requirement: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ~>
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0.15'
|
139
|
+
type: :development
|
140
|
+
prerelease: false
|
141
|
+
version_requirements: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - ~>
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0.15'
|
132
146
|
- !ruby/object:Gem::Dependency
|
133
147
|
name: yard
|
134
148
|
requirement: !ruby/object:Gem::Requirement
|