active_interaction 3.0.0 → 3.0.1

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: 66bb9089f91627be5b2370b6e68eb216ff3da581
4
- data.tar.gz: 0f107c34005d354adb1fc2bad3b72776b588b455
3
+ metadata.gz: 570d5eae8a7122f5acf5ea497d191574073c80d1
4
+ data.tar.gz: f5a66f3defbfd2cee1dabf0a60f7d4799544b043
5
5
  SHA512:
6
- metadata.gz: d17dab874880c2d8b363e749ef785800bece6d567196937968bd20637a8f7c1df5e653583d0397f11b2934d2c00aba16ada93af8e7b0abda6aa53df07de91463
7
- data.tar.gz: 09dbd1ee68e85d8a0b49e492eb2043e75350fb6194385f654cb95fed861bfb63046e53ce7f909f83e0b90ea4097b71e2616d2ba11f6968b864b8004f07906d01
6
+ metadata.gz: 4af716412dbce18461deb2ff8a15878511c683ef9fc3bc499b027788ecba3d98ada05ed09ab615a0ec8adcfbcd61a39c57cd119a3095c26c3a0760891d9d74bd
7
+ data.tar.gz: 2911bf4456d0724b48804e4176ed96fcf40361b7dba671dfa7450f3a24180e3188a1509d4ffdeb8e41ed40e8895e80a4d2c5f96ce37651a14d208345c457ad82
@@ -1,3 +1,9 @@
1
+ # [3.0.1][] (2016-01-15)
2
+
3
+ ## Fixed
4
+
5
+ - [#349][]: Merging errors on `:base` with a message that was a `String` attempted to translate it.
6
+
1
7
  # [3.0.0][] (2016-01-13)
2
8
 
3
9
  ## Changed
@@ -504,6 +510,7 @@ For help upgrading to version 2, please read [the announcement post][].
504
510
 
505
511
  - Initial release.
506
512
 
513
+ [3.0.1]: https://github.com/orgsync/active_interaction/compare/v3.0.0...v3.0.1
507
514
  [3.0.0]: https://github.com/orgsync/active_interaction/compare/v2.2.0...v3.0.0
508
515
  [2.2.0]: https://github.com/orgsync/active_interaction/compare/v2.1.5...v2.2.0
509
516
  [2.1.5]: https://github.com/orgsync/active_interaction/compare/v2.1.4...v2.1.5
@@ -660,5 +667,6 @@ For help upgrading to version 2, please read [the announcement post][].
660
667
  [#336]: https://github.com/orgsync/active_interaction/pull/336
661
668
  [#344]: https://github.com/orgsync/active_interaction/pull/344
662
669
  [#346]: https://github.com/orgsync/active_interaction/pull/346
670
+ [#349]: https://github.com/orgsync/active_interaction/pull/349
663
671
 
664
672
  [the announcement post]: http://devblog.orgsync.com/2015/05/06/announcing-active-interaction-2/
@@ -254,7 +254,7 @@ module ActiveInteraction
254
254
  begin
255
255
  public_send("#{name}=", filter.clean(inputs[name], self))
256
256
  rescue InvalidValueError, MissingValueError, NoDefaultError
257
- # #type_check will add errors if appropriate.
257
+ nil # #type_check will add errors if appropriate.
258
258
  end
259
259
  end
260
260
  end
@@ -121,8 +121,8 @@ module ActiveInteraction
121
121
  if attribute?(attribute)
122
122
  add(attribute, error, detail) unless added?(attribute, error, detail)
123
123
  else
124
- message = full_message(
125
- attribute, other.generate_message(attribute, error))
124
+ translated_error = translate(other, attribute, error)
125
+ message = full_message(attribute, translated_error)
126
126
  attribute = :base
127
127
  add(attribute, message) unless added?(attribute, message)
128
128
  end
@@ -131,5 +131,13 @@ module ActiveInteraction
131
131
  def attribute?(attribute)
132
132
  @base.respond_to?(attribute)
133
133
  end
134
+
135
+ def translate(other, attribute, error)
136
+ if error.is_a?(Symbol)
137
+ other.generate_message(attribute, error)
138
+ else
139
+ error
140
+ end
141
+ end
134
142
  end
135
143
  end
@@ -14,7 +14,7 @@ module ActiveInteraction
14
14
  # Describes an input filter for an interaction.
15
15
  class Filter
16
16
  # @return [Hash{Symbol => Class}]
17
- CLASSES = {}
17
+ CLASSES = {} # rubocop:disable Style/MutableConstant
18
18
  private_constant :CLASSES
19
19
 
20
20
  # @return [Hash{Symbol => Filter}]
@@ -9,7 +9,7 @@ module ActiveInteraction
9
9
  #
10
10
  # @private
11
11
  class AbstractDateTimeFilter < AbstractFilter
12
- alias_method :_cast, :cast
12
+ alias _cast cast
13
13
  private :_cast
14
14
 
15
15
  def cast(value, context)
@@ -8,7 +8,7 @@ module ActiveInteraction
8
8
  #
9
9
  # @private
10
10
  class AbstractNumericFilter < AbstractFilter
11
- alias_method :_cast, :cast
11
+ alias _cast cast
12
12
  private :_cast
13
13
 
14
14
  def cast(value, context)
@@ -24,7 +24,7 @@ module ActiveInteraction
24
24
  class TimeFilter < AbstractDateTimeFilter
25
25
  register :time
26
26
 
27
- alias_method :_klass, :klass
27
+ alias _klass klass
28
28
  private :_klass
29
29
 
30
30
  def initialize(name, options = {}, &block)
@@ -6,5 +6,5 @@ module ActiveInteraction
6
6
  # The version number.
7
7
  #
8
8
  # @return [Gem::Version]
9
- VERSION = Gem::Version.new('3.0.0')
9
+ VERSION = Gem::Version.new('3.0.1')
10
10
  end
@@ -36,7 +36,7 @@ describe ActiveInteraction::Base do
36
36
  describe '.new(inputs = {})' do
37
37
  it 'does not allow :_interaction_* as an option' do
38
38
  key = :"_interaction_#{SecureRandom.hex}"
39
- inputs.merge!(key => nil)
39
+ inputs[key] = nil
40
40
  expect do
41
41
  interaction
42
42
  end.to raise_error ActiveInteraction::InvalidValueError
@@ -44,7 +44,7 @@ describe ActiveInteraction::Base do
44
44
 
45
45
  it 'does not allow "_interaction_*" as an option' do
46
46
  key = "_interaction_#{SecureRandom.hex}"
47
- inputs.merge!(key => nil)
47
+ inputs[key] = nil
48
48
  expect do
49
49
  interaction
50
50
  end.to raise_error ActiveInteraction::InvalidValueError
@@ -75,7 +75,7 @@ describe ActiveInteraction::Base do
75
75
  end
76
76
 
77
77
  context 'passing' do
78
- before { inputs.merge!(thing: SecureRandom.hex) }
78
+ before { inputs[:thing] = SecureRandom.hex }
79
79
 
80
80
  it 'returns a valid outcome' do
81
81
  expect(interaction).to be_valid
@@ -85,7 +85,7 @@ describe ActiveInteraction::Base do
85
85
 
86
86
  context 'with a single input' do
87
87
  let(:thing) { SecureRandom.hex }
88
- before { inputs.merge!(thing: thing) }
88
+ before { inputs[:thing] = thing }
89
89
 
90
90
  it 'sets the attribute' do
91
91
  expect(interaction.thing).to eql thing
@@ -98,7 +98,7 @@ describe ActiveInteraction::Base do
98
98
 
99
99
  context 'validation' do
100
100
  context 'failing' do
101
- before { inputs.merge!(thing: thing) }
101
+ before { inputs[:thing] = thing }
102
102
 
103
103
  context 'with an invalid value' do
104
104
  let(:thing) { 'a' }
@@ -118,7 +118,7 @@ describe ActiveInteraction::Base do
118
118
  end
119
119
 
120
120
  context 'passing' do
121
- before { inputs.merge!(thing: 1) }
121
+ before { inputs[:thing] = 1 }
122
122
 
123
123
  it 'returns a valid outcome' do
124
124
  expect(interaction).to be_valid
@@ -127,7 +127,7 @@ describe ActiveInteraction::Base do
127
127
  end
128
128
 
129
129
  context 'with a single input' do
130
- before { inputs.merge!(thing: 1) }
130
+ before { inputs[:thing] = 1 }
131
131
 
132
132
  it 'sets the attribute to the filtered value' do
133
133
  expect(interaction.thing).to eql 1.0
@@ -248,7 +248,7 @@ describe ActiveInteraction::Base do
248
248
  end
249
249
 
250
250
  context 'passing validations' do
251
- before { inputs.merge!(thing: thing) }
251
+ before { inputs[:thing] = thing }
252
252
 
253
253
  context 'failing runtime validations' do
254
254
  before do
@@ -311,7 +311,7 @@ describe ActiveInteraction::Base do
311
311
  end
312
312
 
313
313
  context 'passing validations' do
314
- before { inputs.merge!(thing: thing) }
314
+ before { inputs[:thing] = thing }
315
315
 
316
316
  it 'returns the result' do
317
317
  expect(result[:thing]).to eql thing
@@ -341,7 +341,8 @@ describe ActiveInteraction::Base do
341
341
 
342
342
  context 'with valid composition' do
343
343
  before do
344
- inputs.merge!(x: x, z: z)
344
+ inputs[:x] = x
345
+ inputs[:z] = z
345
346
  end
346
347
 
347
348
  it 'is valid' do
@@ -485,7 +486,7 @@ describe ActiveInteraction::Base do
485
486
  let(:thing) { rand }
486
487
 
487
488
  before do
488
- inputs.merge!(thing: thing)
489
+ inputs[:thing] = thing
489
490
  end
490
491
 
491
492
  it 'returns true' do
@@ -90,7 +90,7 @@ describe ActiveInteraction::Runnable do
90
90
  let(:result) { double }
91
91
 
92
92
  it 'returns the result' do
93
- expect(instance.result = result).to eql result
93
+ expect((instance.result = result)).to eql result
94
94
  end
95
95
 
96
96
  it 'sets the result' do
@@ -57,13 +57,28 @@ describe ActiveInteraction::Errors do
57
57
  end
58
58
 
59
59
  context 'with a detailed error' do
60
- before do
61
- other.add(:attribute)
60
+ context 'that is a symbol' do
61
+ before do
62
+ other.add(:attribute)
63
+ end
64
+
65
+ it 'adds the error' do
66
+ errors.merge!(other)
67
+ expect(errors.details[:attribute]).to eql [{ error: :invalid }]
68
+ end
62
69
  end
63
70
 
64
- it 'adds the error' do
65
- errors.merge!(other)
66
- expect(errors.details[:attribute]).to eql [{ error: :invalid }]
71
+ context 'that is a string' do
72
+ let(:message) { SecureRandom.hex }
73
+
74
+ before do
75
+ other.add(:base, message)
76
+ end
77
+
78
+ it 'adds the error' do
79
+ errors.merge!(other)
80
+ expect(errors.details[:base]).to eql [{ error: message }]
81
+ end
67
82
  end
68
83
  end
69
84
 
@@ -10,7 +10,7 @@ describe ActiveInteraction::DateFilter, :filter do
10
10
  let(:format) { '%d/%m/%Y' }
11
11
 
12
12
  before do
13
- options.merge!(format: format)
13
+ options[:format] = format
14
14
  end
15
15
  end
16
16
 
@@ -116,12 +116,10 @@ describe ActiveInteraction::DateFilter, :filter do
116
116
  describe '#default' do
117
117
  context 'with a GroupedInput' do
118
118
  before do
119
- options.merge!(
120
- default: ActiveInteraction::GroupedInput.new(
121
- '1' => '2012',
122
- '2' => '1',
123
- '3' => '2'
124
- )
119
+ options[:default] = ActiveInteraction::GroupedInput.new(
120
+ '1' => '2012',
121
+ '2' => '1',
122
+ '3' => '2'
125
123
  )
126
124
  end
127
125
 
@@ -10,7 +10,7 @@ describe ActiveInteraction::DateTimeFilter, :filter do
10
10
  let(:format) { '%d/%m/%Y %H:%M:%S %:z' }
11
11
 
12
12
  before do
13
- options.merge!(format: format)
13
+ options[:format] = format
14
14
  end
15
15
  end
16
16
 
@@ -124,15 +124,13 @@ describe ActiveInteraction::DateTimeFilter, :filter do
124
124
  describe '#default' do
125
125
  context 'with a GroupedInput' do
126
126
  before do
127
- options.merge!(
128
- default: ActiveInteraction::GroupedInput.new(
129
- '1' => '2012',
130
- '2' => '1',
131
- '3' => '2',
132
- '4' => '3',
133
- '5' => '4',
134
- '6' => '5'
135
- )
127
+ options[:default] = ActiveInteraction::GroupedInput.new(
128
+ '1' => '2012',
129
+ '2' => '1',
130
+ '3' => '2',
131
+ '4' => '3',
132
+ '5' => '4',
133
+ '6' => '5'
136
134
  )
137
135
  end
138
136
 
@@ -10,7 +10,7 @@ describe ActiveInteraction::DecimalFilter, :filter do
10
10
  let(:digits) { 4 }
11
11
 
12
12
  before do
13
- options.merge!(digits: digits)
13
+ options[:digits] = digits
14
14
  end
15
15
  end
16
16
 
@@ -80,7 +80,7 @@ describe ActiveInteraction::HashFilter, :filter do
80
80
  describe '#default' do
81
81
  context 'with a Hash' do
82
82
  before do
83
- options.merge!(default: {})
83
+ options[:default] = {}
84
84
  end
85
85
 
86
86
  it 'returns the Hash' do
@@ -90,7 +90,7 @@ describe ActiveInteraction::HashFilter, :filter do
90
90
 
91
91
  context 'with a non-empty Hash' do
92
92
  before do
93
- options.merge!(default: { a: {} })
93
+ options[:default] = { a: {} }
94
94
  end
95
95
 
96
96
  it 'raises an error' do
@@ -10,7 +10,7 @@ describe ActiveInteraction::ObjectFilter, :filter do
10
10
  it_behaves_like 'a filter'
11
11
 
12
12
  before do
13
- options.merge!(class: Thing)
13
+ options[:class] = Thing
14
14
  end
15
15
 
16
16
  describe '#cast' do
@@ -101,7 +101,7 @@ describe ActiveInteraction::ObjectFilter, :filter do
101
101
 
102
102
  context 'with class as a superclass' do
103
103
  before do
104
- options.merge!(class: Thing.superclass)
104
+ options[:class] = Thing.superclass
105
105
  end
106
106
 
107
107
  it 'returns the instance' do
@@ -111,7 +111,7 @@ describe ActiveInteraction::ObjectFilter, :filter do
111
111
 
112
112
  context 'with class as a String' do
113
113
  before do
114
- options.merge!(class: Thing.name)
114
+ options[:class] = Thing.name
115
115
  end
116
116
 
117
117
  it 'returns the instance' do
@@ -131,7 +131,7 @@ describe ActiveInteraction::ObjectFilter, :filter do
131
131
 
132
132
  context 'with class as an invalid String' do
133
133
  before do
134
- options.merge!(class: 'invalid')
134
+ options[:class] = 'invalid'
135
135
  end
136
136
 
137
137
  it 'raises an error' do
@@ -8,7 +8,7 @@ describe ActiveInteraction::StringFilter, :filter do
8
8
 
9
9
  shared_context 'without strip' do
10
10
  before do
11
- options.merge!(strip: false)
11
+ options[:strip] = false
12
12
  end
13
13
  end
14
14
 
@@ -10,7 +10,7 @@ describe ActiveInteraction::TimeFilter, :filter do
10
10
  let(:format) { '%d/%m/%Y %H:%M:%S %z' }
11
11
 
12
12
  before do
13
- options.merge!(format: format)
13
+ options[:format] = format
14
14
  end
15
15
  end
16
16
 
@@ -146,15 +146,13 @@ describe ActiveInteraction::TimeFilter, :filter do
146
146
  describe '#default' do
147
147
  context 'with a GroupedInput' do
148
148
  before do
149
- options.merge!(
150
- default: ActiveInteraction::GroupedInput.new(
151
- '1' => '2012',
152
- '2' => '1',
153
- '3' => '2',
154
- '4' => '3',
155
- '5' => '4',
156
- '6' => '5'
157
- )
149
+ options[:default] = ActiveInteraction::GroupedInput.new(
150
+ '1' => '2012',
151
+ '2' => '1',
152
+ '3' => '2',
153
+ '4' => '3',
154
+ '5' => '4',
155
+ '6' => '5'
158
156
  )
159
157
  end
160
158
 
@@ -31,7 +31,7 @@ describe ArrayInteraction do
31
31
  context 'with inputs[:a]' do
32
32
  let(:a) { [[]] }
33
33
 
34
- before { inputs.merge!(a: a) }
34
+ before { inputs[:a] = a }
35
35
 
36
36
  it 'returns the correct value for :a' do
37
37
  expect(result[:a]).to eql a
@@ -18,7 +18,7 @@ describe HashInteraction do
18
18
  context 'with inputs[:a]' do
19
19
  let(:a) { { x: {} } }
20
20
 
21
- before { inputs.merge!(a: a) }
21
+ before { inputs[:a] = a }
22
22
 
23
23
  it 'returns the correct value for :a' do
24
24
  expect(result[:a]).to eql a.with_indifferent_access
@@ -10,6 +10,7 @@ TimeZone = Class.new do
10
10
  def self.parse(*args)
11
11
  TimeWithZone.new(Time.parse(*args))
12
12
  rescue ArgumentError
13
+ nil
13
14
  end
14
15
  end
15
16
 
@@ -37,7 +38,7 @@ describe TimeInteraction do
37
38
  let(:a) { nil }
38
39
 
39
40
  before do
40
- inputs.merge!(a: a)
41
+ inputs[:a] = a
41
42
 
42
43
  allow(Time).to receive(:zone).and_return(TimeZone)
43
44
  end
@@ -9,7 +9,7 @@ shared_context 'filters' do
9
9
 
10
10
  shared_context 'optional' do
11
11
  before do
12
- options.merge!(default: nil)
12
+ options[:default] = nil
13
13
  end
14
14
  end
15
15
 
@@ -112,7 +112,7 @@ shared_examples_for 'a filter' do
112
112
 
113
113
  context 'with an invalid default' do
114
114
  before do
115
- options.merge!(default: Object.new)
115
+ options[:default] = Object.new
116
116
  end
117
117
 
118
118
  it 'raises an error' do
@@ -144,7 +144,7 @@ shared_examples_for 'a filter' do
144
144
 
145
145
  context 'with an invalid default' do
146
146
  before do
147
- options.merge!(default: Object.new)
147
+ options[:default] = Object.new
148
148
  end
149
149
 
150
150
  it 'raises an error' do
@@ -177,7 +177,7 @@ shared_examples_for 'a filter' do
177
177
  let(:desc) { SecureRandom.hex }
178
178
 
179
179
  before do
180
- options.merge!(desc: desc)
180
+ options[:desc] = desc
181
181
  end
182
182
 
183
183
  it 'returns the description' do
@@ -54,7 +54,7 @@ shared_examples_for 'an interaction' do |type, generator, filter_options = {}|
54
54
  context 'with inputs[:required]' do
55
55
  let(:required) { generator.call }
56
56
 
57
- before { inputs.merge!(required: required) }
57
+ before { inputs[:required] = required }
58
58
 
59
59
  it 'is valid' do
60
60
  expect(outcome).to be_valid
@@ -73,7 +73,7 @@ shared_examples_for 'an interaction' do |type, generator, filter_options = {}|
73
73
  end
74
74
 
75
75
  it 'does not return nil for :default when given nil' do
76
- inputs.merge!(default: nil)
76
+ inputs[:default] = nil
77
77
  expect(result[:default]).to_not be_nil
78
78
  end
79
79
 
@@ -92,7 +92,7 @@ shared_examples_for 'an interaction' do |type, generator, filter_options = {}|
92
92
  context 'with inputs[:optional]' do
93
93
  let(:optional) { generator.call }
94
94
 
95
- before { inputs.merge!(optional: optional) }
95
+ before { inputs[:optional] = optional }
96
96
 
97
97
  it 'returns the correct value for :optional' do
98
98
  expect(result[:optional]).to eql optional
@@ -102,7 +102,7 @@ shared_examples_for 'an interaction' do |type, generator, filter_options = {}|
102
102
  context 'with inputs[:default]' do
103
103
  let(:default) { generator.call }
104
104
 
105
- before { inputs.merge!(default: default) }
105
+ before { inputs[:default] = default }
106
106
 
107
107
  it 'returns the correct value for :default' do
108
108
  expect(result[:default]).to eql 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: 3.0.0
4
+ version: 3.0.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: 2016-01-13 00:00:00.000000000 Z
12
+ date: 2016-01-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activemodel
@@ -163,14 +163,14 @@ dependencies:
163
163
  requirements:
164
164
  - - "~>"
165
165
  - !ruby/object:Gem::Version
166
- version: '0.35'
166
+ version: 0.36.0
167
167
  type: :development
168
168
  prerelease: false
169
169
  version_requirements: !ruby/object:Gem::Requirement
170
170
  requirements:
171
171
  - - "~>"
172
172
  - !ruby/object:Gem::Version
173
- version: '0.35'
173
+ version: 0.36.0
174
174
  - !ruby/object:Gem::Dependency
175
175
  name: yard
176
176
  requirement: !ruby/object:Gem::Requirement
@@ -300,7 +300,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
300
300
  version: '0'
301
301
  requirements: []
302
302
  rubyforge_project:
303
- rubygems_version: 2.4.5
303
+ rubygems_version: 2.5.1
304
304
  signing_key:
305
305
  specification_version: 4
306
306
  summary: Manage application specific business logic.