active_interaction 1.1.6 → 1.1.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 57e566015dd952d744123dd2471da57d7b9ba9ea
4
- data.tar.gz: 17d15bb89957162cbc25479595d1bb43cec54ef5
3
+ metadata.gz: 9ebbd60d2d495d3011785f7fb78478f6b6b4a2d9
4
+ data.tar.gz: e52b7f93aff786d4a8be65e36121ecc5b30eaf3b
5
5
  SHA512:
6
- metadata.gz: 1a93ea6f2cd2a63854ee2a4418994c9a41dc46c63d83208f4281da9e3d8f786cf23b0891d28b2a0909ffabdeaf47e0caec5957d7762127447ec97caa59867679
7
- data.tar.gz: e6386cde98bec96a9da6564b74809a824539b400535dd7608fb446741d353d1181a6d2b3b9c39deb706e19f8cef8747a10c8e7479df5f9e32d1942591e7b8418
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
- [Master]: https://github.com/orgsync/active_interaction/compare/v1.1.6...master
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
@@ -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(active_interaction locale en.yml)), File.dirname(__FILE__))
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.6
44
+ # @version 1.1.7
45
45
  module ActiveInteraction end
@@ -135,6 +135,8 @@ module ActiveInteraction
135
135
  # @param klass [Class]
136
136
  def inherited(klass)
137
137
  klass.instance_variable_set(:@_interaction_filters, filters.dup)
138
+
139
+ super
138
140
  end
139
141
 
140
142
  # @param filter [Filter]
@@ -5,37 +5,39 @@ module ActiveInteraction
5
5
  #
6
6
  # @private
7
7
  module Validation
8
- # @param filters [Hash{Symbol => Filter}]
9
- # @param inputs [Hash{Symbol => Object}]
10
- def self.validate(filters, inputs)
11
- filters.each_with_object([]) do |(name, filter), errors|
12
- begin
13
- filter.cast(inputs[name])
14
- rescue InvalidNestedValueError,
15
- InvalidValueError,
16
- MissingValueError => e
17
- errors << error_args(filter, e)
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
- private
23
+ private
23
24
 
24
- def self.error_args(filter, error)
25
- case error
26
- when InvalidNestedValueError
27
- [filter.name, :invalid_nested, nil,
28
- name: e.filter_name.inspect, value: e.input_value.inspect]
29
- when InvalidValueError
30
- [filter.name, :invalid_type, nil, type: type(filter)]
31
- when MissingValueError
32
- [filter.name, :missing]
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
- # @param filter [Filter]
37
- def self.type(filter)
38
- I18n.translate("#{Base.i18n_scope}.types.#{filter.class.slug}")
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
@@ -5,5 +5,5 @@ module ActiveInteraction
5
5
  # The version number.
6
6
  #
7
7
  # @return [Gem::Version]
8
- VERSION = Gem::Version.new('1.1.6')
8
+ VERSION = Gem::Version.new('1.1.7')
9
9
  end
@@ -171,7 +171,7 @@ describe ActiveInteraction::Base do
171
171
  end
172
172
  end
173
173
 
174
- %w(thing1 thing2).each do |thing|
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(error error)
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
- let(:described_class) { InteractionWithFilter }
330
+ context 'filters' do
331
+ let(:described_class) { InteractionWithFilter }
331
332
 
332
- def filters(klass)
333
- klass.filters.keys
334
- end
333
+ def filters(klass)
334
+ klass.filters.keys
335
+ end
335
336
 
336
- it 'includes the filters from the superclass' do
337
- expect(filters(Class.new(described_class))).to include :thing
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
- it 'does not mutate the filters on the superclass' do
341
- Class.new(described_class) { float :other_thing }
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
- expect(filters(described_class)).to_not include :other_thing
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
- filter_options.merge(default: generator.call))
27
+ filter_options.merge(default: generator.call))
28
28
  public_send(type, :defaults_1, :defaults_2,
29
- filter_options.merge(default: generator.call))
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.6
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-29 00:00:00.000000000 Z
12
+ date: 2014-04-30 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activemodel