active_interaction 1.1.6 → 1.1.7
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/CHANGELOG.md +6 -1
- data/lib/active_interaction.rb +2 -2
- data/lib/active_interaction/base.rb +2 -0
- data/lib/active_interaction/modules/validation.rb +27 -25
- data/lib/active_interaction/version.rb +1 -1
- data/spec/active_interaction/base_spec.rb +41 -11
- data/spec/active_interaction/i18n_spec.rb +2 -2
- data/spec/support/interactions.rb +2 -2
- 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: 9ebbd60d2d495d3011785f7fb78478f6b6b4a2d9
|
4
|
+
data.tar.gz: e52b7f93aff786d4a8be65e36121ecc5b30eaf3b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b9b58d141cca46ad7b9b0dba1373c9e0cb159cc04d9831b0660df7d1941347d94b1e63b8f9f063d0425240173757f4fff00453650299d46f52059b5d49ccb1f9
|
7
|
+
data.tar.gz: 14bee4cebb9847f4eb759016e9846e7171d6a7647b78516c4389686dbb1e6ed7f8e94438a63d1a83c028f446c86d4289f57ededca0af5afaabc0887ff742d60f
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,9 @@
|
|
1
1
|
# [Master][]
|
2
2
|
|
3
|
+
# [1.1.7][] (2014-04-30)
|
4
|
+
|
5
|
+
- Fix a bug that leaked validators among all child classes.
|
6
|
+
|
3
7
|
# [1.1.6][] (2014-04-29)
|
4
8
|
|
5
9
|
- Fix a bug that caused nested hash error messages to be misleading.
|
@@ -182,7 +186,8 @@
|
|
182
186
|
|
183
187
|
- Initial release.
|
184
188
|
|
185
|
-
[
|
189
|
+
[master]: https://github.com/orgsync/active_interaction/compare/v1.1.7...master
|
190
|
+
[1.1.7]: https://github.com/orgsync/active_interaction/compare/v1.1.6...v1.1.7
|
186
191
|
[1.1.6]: https://github.com/orgsync/active_interaction/compare/v1.1.5...v1.1.6
|
187
192
|
[1.1.5]: https://github.com/orgsync/active_interaction/compare/v1.1.4...v1.1.5
|
188
193
|
[1.1.4]: https://github.com/orgsync/active_interaction/compare/v1.1.3...v1.1.4
|
data/lib/active_interaction.rb
CHANGED
@@ -32,7 +32,7 @@ require 'active_interaction/filters/time_filter'
|
|
32
32
|
require 'active_interaction/base'
|
33
33
|
|
34
34
|
I18n.load_path << File.expand_path(
|
35
|
-
File.join(%w
|
35
|
+
File.join(%w[active_interaction locale en.yml]), File.dirname(__FILE__))
|
36
36
|
|
37
37
|
# Manage application specific business logic.
|
38
38
|
#
|
@@ -41,5 +41,5 @@ I18n.load_path << File.expand_path(
|
|
41
41
|
#
|
42
42
|
# @since 1.0.0
|
43
43
|
#
|
44
|
-
# @version 1.1.
|
44
|
+
# @version 1.1.7
|
45
45
|
module ActiveInteraction end
|
@@ -5,37 +5,39 @@ module ActiveInteraction
|
|
5
5
|
#
|
6
6
|
# @private
|
7
7
|
module Validation
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
8
|
+
class << self
|
9
|
+
# @param filters [Hash{Symbol => Filter}]
|
10
|
+
# @param inputs [Hash{Symbol => Object}]
|
11
|
+
def validate(filters, inputs)
|
12
|
+
filters.each_with_object([]) do |(name, filter), errors|
|
13
|
+
begin
|
14
|
+
filter.cast(inputs[name])
|
15
|
+
rescue InvalidNestedValueError,
|
16
|
+
InvalidValueError,
|
17
|
+
MissingValueError => e
|
18
|
+
errors << error_args(filter, e)
|
19
|
+
end
|
18
20
|
end
|
19
21
|
end
|
20
|
-
end
|
21
22
|
|
22
|
-
|
23
|
+
private
|
23
24
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
25
|
+
def error_args(filter, error)
|
26
|
+
case error
|
27
|
+
when InvalidNestedValueError
|
28
|
+
[filter.name, :invalid_nested, nil,
|
29
|
+
name: e.filter_name.inspect, value: e.input_value.inspect]
|
30
|
+
when InvalidValueError
|
31
|
+
[filter.name, :invalid_type, nil, type: type(filter)]
|
32
|
+
when MissingValueError
|
33
|
+
[filter.name, :missing]
|
34
|
+
end
|
33
35
|
end
|
34
|
-
end
|
35
36
|
|
36
|
-
|
37
|
-
|
38
|
-
|
37
|
+
# @param filter [Filter]
|
38
|
+
def type(filter)
|
39
|
+
I18n.translate("#{Base.i18n_scope}.types.#{filter.class.slug}")
|
40
|
+
end
|
39
41
|
end
|
40
42
|
end
|
41
43
|
end
|
@@ -171,7 +171,7 @@ describe ActiveInteraction::Base do
|
|
171
171
|
end
|
172
172
|
end
|
173
173
|
|
174
|
-
%w
|
174
|
+
%w[thing1 thing2].each do |thing|
|
175
175
|
it "adds an attr_reader for #{thing}" do
|
176
176
|
expect(interaction).to respond_to thing
|
177
177
|
end
|
@@ -229,7 +229,7 @@ describe ActiveInteraction::Base do
|
|
229
229
|
end
|
230
230
|
|
231
231
|
it 'has errors' do
|
232
|
-
expect(outcome.errors.messages[:thing]).to eql %w
|
232
|
+
expect(outcome.errors.messages[:thing]).to eql %w[error error]
|
233
233
|
end
|
234
234
|
|
235
235
|
it 'has symbolic errors' do
|
@@ -327,20 +327,50 @@ describe ActiveInteraction::Base do
|
|
327
327
|
end
|
328
328
|
|
329
329
|
context 'inheritance' do
|
330
|
-
|
330
|
+
context 'filters' do
|
331
|
+
let(:described_class) { InteractionWithFilter }
|
331
332
|
|
332
|
-
|
333
|
-
|
334
|
-
|
333
|
+
def filters(klass)
|
334
|
+
klass.filters.keys
|
335
|
+
end
|
335
336
|
|
336
|
-
|
337
|
-
|
337
|
+
it 'includes the filters from the superclass' do
|
338
|
+
expect(filters(Class.new(described_class))).to include :thing
|
339
|
+
end
|
340
|
+
|
341
|
+
it 'does not mutate the filters on the superclass' do
|
342
|
+
Class.new(described_class) { float :other_thing }
|
343
|
+
|
344
|
+
expect(filters(described_class)).to_not include :other_thing
|
345
|
+
end
|
338
346
|
end
|
339
347
|
|
340
|
-
|
341
|
-
|
348
|
+
context 'validators' do
|
349
|
+
it 'does not pollute validators' do
|
350
|
+
a = Class.new(ActiveInteraction::Base) do
|
351
|
+
string :a
|
352
|
+
validates_presence_of :a
|
353
|
+
end
|
342
354
|
|
343
|
-
|
355
|
+
b = Class.new(ActiveInteraction::Base) do
|
356
|
+
string :b
|
357
|
+
validates_presence_of :b
|
358
|
+
end
|
359
|
+
|
360
|
+
expect(a.validators).to_not eql b.validators
|
361
|
+
end
|
362
|
+
|
363
|
+
it 'gives duped validators to subclasses' do
|
364
|
+
a = Class.new(ActiveInteraction::Base) do
|
365
|
+
string :a
|
366
|
+
validates_presence_of :a
|
367
|
+
end
|
368
|
+
|
369
|
+
b = Class.new(a)
|
370
|
+
|
371
|
+
expect(a.validators).to eql b.validators
|
372
|
+
expect(a.validators).to_not equal b.validators
|
373
|
+
end
|
344
374
|
end
|
345
375
|
end
|
346
376
|
|
@@ -11,7 +11,7 @@ end
|
|
11
11
|
describe I18nInteraction do
|
12
12
|
include_context 'interactions'
|
13
13
|
|
14
|
-
TYPES = %w
|
14
|
+
TYPES = %w[
|
15
15
|
array
|
16
16
|
boolean
|
17
17
|
date
|
@@ -23,7 +23,7 @@ describe I18nInteraction do
|
|
23
23
|
model
|
24
24
|
string
|
25
25
|
time
|
26
|
-
|
26
|
+
]
|
27
27
|
|
28
28
|
shared_examples 'translation' do
|
29
29
|
context 'types' do
|
@@ -24,9 +24,9 @@ shared_examples_for 'an interaction' do |type, generator, filter_options = {}|
|
|
24
24
|
public_send(type, :required, filter_options)
|
25
25
|
public_send(type, :optional, filter_options.merge(default: nil))
|
26
26
|
public_send(type, :default,
|
27
|
-
|
27
|
+
filter_options.merge(default: generator.call))
|
28
28
|
public_send(type, :defaults_1, :defaults_2,
|
29
|
-
|
29
|
+
filter_options.merge(default: generator.call))
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
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.1.
|
4
|
+
version: 1.1.7
|
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-04-
|
12
|
+
date: 2014-04-30 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activemodel
|