active_interaction 1.2.1 → 1.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -1
- data/lib/active_interaction.rb +4 -3
- data/lib/active_interaction/filter.rb +8 -30
- data/lib/active_interaction/filters/array_filter.rb +2 -0
- data/lib/active_interaction/filters/boolean_filter.rb +2 -0
- data/lib/active_interaction/filters/date_filter.rb +1 -0
- data/lib/active_interaction/filters/date_time_filter.rb +2 -0
- data/lib/active_interaction/filters/decimal_filter.rb +2 -0
- data/lib/active_interaction/filters/file_filter.rb +2 -0
- data/lib/active_interaction/filters/float_filter.rb +1 -0
- data/lib/active_interaction/filters/hash_filter.rb +2 -0
- data/lib/active_interaction/filters/integer_filter.rb +1 -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/locale/en.yml +1 -0
- data/lib/active_interaction/modules/validation.rb +1 -1
- data/lib/active_interaction/version.rb +1 -1
- data/spec/active_interaction/filter_spec.rb +13 -21
- data/spec/active_interaction/i18n_spec.rb +3 -13
- data/spec/active_interaction/modules/validation_spec.rb +18 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8da6c6009b0e73aeec0afbc524e94c27dde01260
|
4
|
+
data.tar.gz: c34f2110a50219b87ba1e22cda387f0f429db7d2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 274c345305f246fc6ae9078846d317cbb7e19b4781d18e73f20ade3336ca77f34008e7e8ca65985a5b3573a0742d8c79a25e9c1ffcc707d947ee5316e965fcec
|
7
|
+
data.tar.gz: ff0bf22dfb87c3774a3a9397943dfa02959355b7773dd87d1d188ac7ac1df47a6014888fcba67ef1286200f6df93f98e96c008c3acf0234d0c87f83780e0464e
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,11 @@
|
|
1
1
|
# [Master][]
|
2
2
|
|
3
|
+
# [1.2.2][] (2014-05-07)
|
4
|
+
|
5
|
+
- Fix a bug that raised `NameError`s when there were invalid nested hash
|
6
|
+
errors.
|
7
|
+
- Add missing translation for symbol filters.
|
8
|
+
|
3
9
|
# [1.2.1][] (2014-05-02)
|
4
10
|
|
5
11
|
- Fix a bug that marked model inputs as invalid even if they returned true for
|
@@ -199,7 +205,8 @@
|
|
199
205
|
|
200
206
|
- Initial release.
|
201
207
|
|
202
|
-
[master]: https://github.com/orgsync/active_interaction/compare/v1.2.
|
208
|
+
[master]: https://github.com/orgsync/active_interaction/compare/v1.2.2...master
|
209
|
+
[1.2.2]: https://github.com/orgsync/active_interaction/compare/v1.2.1...v1.2.2
|
203
210
|
[1.2.1]: https://github.com/orgsync/active_interaction/compare/v1.2.0...v1.2.1
|
204
211
|
[1.2.0]: https://github.com/orgsync/active_interaction/compare/v1.1.7...v1.2.0
|
205
212
|
[1.1.7]: https://github.com/orgsync/active_interaction/compare/v1.1.6...v1.1.7
|
data/lib/active_interaction.rb
CHANGED
@@ -39,8 +39,9 @@ require 'active_interaction/base'
|
|
39
39
|
|
40
40
|
require 'active_interaction/backports'
|
41
41
|
|
42
|
-
I18n.load_path
|
43
|
-
File.join(%w[active_interaction locale
|
42
|
+
I18n.load_path += Dir[File.expand_path(
|
43
|
+
File.join(%w[active_interaction locale *.yml]), File.dirname(__FILE__))]
|
44
|
+
I18n.default_locale = :en
|
44
45
|
|
45
46
|
# Manage application specific business logic.
|
46
47
|
#
|
@@ -49,5 +50,5 @@ I18n.load_path << File.expand_path(
|
|
49
50
|
#
|
50
51
|
# @since 1.0.0
|
51
52
|
#
|
52
|
-
# @version 1.2.
|
53
|
+
# @version 1.2.2
|
53
54
|
module ActiveInteraction end
|
@@ -12,10 +12,6 @@ module ActiveInteraction
|
|
12
12
|
|
13
13
|
# Describes an input filter for an interaction.
|
14
14
|
class Filter
|
15
|
-
# @return [Regexp]
|
16
|
-
CLASS_REGEXP = /\AActiveInteraction::([A-Z]\w*)Filter\z/
|
17
|
-
private_constant :CLASS_REGEXP
|
18
|
-
|
19
15
|
# @return [Hash{Symbol => Class}]
|
20
16
|
CLASSES = {}
|
21
17
|
private_constant :CLASSES
|
@@ -32,6 +28,9 @@ module ActiveInteraction
|
|
32
28
|
undef_method :hash
|
33
29
|
|
34
30
|
class << self
|
31
|
+
# @return [Symbol]
|
32
|
+
attr_reader :slug
|
33
|
+
|
35
34
|
# Get the filter associated with a symbol.
|
36
35
|
#
|
37
36
|
# @example
|
@@ -52,35 +51,14 @@ module ActiveInteraction
|
|
52
51
|
CLASSES.fetch(slug) { fail MissingFilterError, slug.inspect }
|
53
52
|
end
|
54
53
|
|
55
|
-
|
56
|
-
#
|
57
|
-
# @example
|
58
|
-
# ActiveInteraction::BooleanFilter.slug
|
59
|
-
# # => :boolean
|
60
|
-
# @example
|
61
|
-
# ActiveInteraction::Filter.slug
|
62
|
-
# # => ActiveInteraction::InvalidClassError: ActiveInteraction::Filter
|
63
|
-
#
|
64
|
-
# @return [Symbol]
|
65
|
-
#
|
66
|
-
# @raise [InvalidClassError] If the filter doesn't have a valid slug.
|
67
|
-
#
|
68
|
-
# @see .factory
|
69
|
-
def slug
|
70
|
-
return @slug if defined?(@slug)
|
71
|
-
|
72
|
-
match = name[CLASS_REGEXP, 1]
|
73
|
-
fail InvalidClassError, name unless match
|
74
|
-
@slug = match.underscore.to_sym
|
75
|
-
end
|
54
|
+
private
|
76
55
|
|
56
|
+
# @param slug [Symbol]
|
77
57
|
# @param klass [Class]
|
78
58
|
#
|
79
|
-
# @
|
80
|
-
def
|
81
|
-
CLASSES[
|
82
|
-
rescue InvalidClassError
|
83
|
-
CLASSES[klass.name.to_sym] = klass
|
59
|
+
# @return [Class]
|
60
|
+
def register(slug)
|
61
|
+
CLASSES[@slug = slug] = self
|
84
62
|
end
|
85
63
|
end
|
86
64
|
|
@@ -26,7 +26,7 @@ module ActiveInteraction
|
|
26
26
|
case error
|
27
27
|
when InvalidNestedValueError
|
28
28
|
[filter.name, :invalid_nested, nil,
|
29
|
-
name:
|
29
|
+
name: error.filter_name.inspect, value: error.input_value.inspect]
|
30
30
|
when InvalidValueError
|
31
31
|
[filter.name, :invalid_type, nil, type: type(filter)]
|
32
32
|
when MissingValueError
|
@@ -2,11 +2,6 @@
|
|
2
2
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
5
|
-
module ActiveInteraction
|
6
|
-
class ATestFilter < ActiveInteraction::Filter; end
|
7
|
-
end
|
8
|
-
class ATestFilter < ActiveInteraction::Filter; end
|
9
|
-
|
10
5
|
describe ActiveInteraction::Filter, :filter do
|
11
6
|
include_context 'filters'
|
12
7
|
|
@@ -16,33 +11,30 @@ describe ActiveInteraction::Filter, :filter do
|
|
16
11
|
end
|
17
12
|
end
|
18
13
|
|
19
|
-
context
|
20
|
-
|
21
|
-
|
22
|
-
let(:described_class) { ActiveInteraction::ATestFilter }
|
14
|
+
context 'with an unregistered subclass' do
|
15
|
+
let(:described_class) { Class.new(ActiveInteraction::Filter) }
|
23
16
|
|
24
17
|
describe '.slug' do
|
25
|
-
it '
|
26
|
-
expect(described_class.slug).to
|
18
|
+
it 'is nil' do
|
19
|
+
expect(described_class.slug).to be_nil
|
27
20
|
end
|
28
21
|
end
|
29
22
|
end
|
30
23
|
|
31
|
-
context
|
32
|
-
|
24
|
+
context 'with a registered subclass' do
|
25
|
+
it_behaves_like 'a filter'
|
33
26
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
27
|
+
let(:described_class) do
|
28
|
+
s = slug
|
29
|
+
Class.new(ActiveInteraction::Filter) do
|
30
|
+
register s
|
38
31
|
end
|
39
32
|
end
|
33
|
+
let(:slug) { SecureRandom.hex.to_sym }
|
40
34
|
|
41
35
|
describe '.slug' do
|
42
|
-
it '
|
43
|
-
expect
|
44
|
-
described_class.slug
|
45
|
-
end.to raise_error ActiveInteraction::InvalidClassError
|
36
|
+
it 'returns the registered slug' do
|
37
|
+
expect(described_class.slug).to eql slug
|
46
38
|
end
|
47
39
|
end
|
48
40
|
end
|
@@ -11,19 +11,9 @@ end
|
|
11
11
|
describe I18nInteraction do
|
12
12
|
include_context 'interactions'
|
13
13
|
|
14
|
-
TYPES =
|
15
|
-
|
16
|
-
|
17
|
-
date
|
18
|
-
date_time
|
19
|
-
file
|
20
|
-
float
|
21
|
-
hash
|
22
|
-
integer
|
23
|
-
model
|
24
|
-
string
|
25
|
-
time
|
26
|
-
]
|
14
|
+
TYPES = ActiveInteraction::Filter
|
15
|
+
.const_get(:CLASSES)
|
16
|
+
.map { |slug, _| slug.to_s }
|
27
17
|
|
28
18
|
shared_examples 'translation' do
|
29
19
|
context 'types' do
|
@@ -49,10 +49,27 @@ describe ActiveInteraction::Validation do
|
|
49
49
|
context 'MissingValueError' do
|
50
50
|
let(:exception) { ActiveInteraction::MissingValueError }
|
51
51
|
|
52
|
-
it 'returns
|
52
|
+
it 'returns a :missing error' do
|
53
53
|
expect(result).to eql [[filter.name, :missing]]
|
54
54
|
end
|
55
55
|
end
|
56
|
+
|
57
|
+
context 'InvalidNestedValueError' do
|
58
|
+
let(:exception) do
|
59
|
+
ActiveInteraction::InvalidNestedValueError.new(name, value)
|
60
|
+
end
|
61
|
+
let(:name) { SecureRandom.hex.to_sym }
|
62
|
+
let(:value) { double }
|
63
|
+
|
64
|
+
it 'returns an :invalid_nested error' do
|
65
|
+
expect(result).to eql [[
|
66
|
+
filter.name,
|
67
|
+
:invalid_nested,
|
68
|
+
nil,
|
69
|
+
{ name: name.inspect, value: value.inspect }
|
70
|
+
]]
|
71
|
+
end
|
72
|
+
end
|
56
73
|
end
|
57
74
|
end
|
58
75
|
end
|
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: 1.2.
|
4
|
+
version: 1.2.2
|
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: 2014-05-
|
12
|
+
date: 2014-05-07 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activemodel
|