active_interaction 3.2.1 → 3.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/active_interaction/base.rb +16 -2
- data/lib/active_interaction/version.rb +1 -1
- data/spec/active_interaction/base_spec.rb +17 -0
- 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: bcb762bfdc148c4eeb1e277f07e13c60fb3944d8
|
4
|
+
data.tar.gz: 7676378a761abeadec3fecc6e350dd27a7fbdd37
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4abdb88c3887e65abed055d535a49ebf8ff9ccd42fba9798315c3f0cb7646461c60007381867c32a8a5f8b4c87082bd4a8bedd3905e3fec041cd0457daed94e9
|
7
|
+
data.tar.gz: b8c6e2b73a547575e9eaa92c3d412044174e3ea1196dd6a868ad17fb657cdbb495a5455f9411ba5bba9f1c76350bf7505ac78f576cae5b8a7080e0e5a751751b
|
@@ -169,8 +169,7 @@ module ActiveInteraction
|
|
169
169
|
#
|
170
170
|
# @private
|
171
171
|
def initialize(inputs = {})
|
172
|
-
|
173
|
-
|
172
|
+
inputs = normalize_inputs!(inputs)
|
174
173
|
process_inputs(inputs.symbolize_keys)
|
175
174
|
end
|
176
175
|
|
@@ -234,6 +233,21 @@ module ActiveInteraction
|
|
234
233
|
|
235
234
|
private
|
236
235
|
|
236
|
+
# We want to allow both `Hash` objects and `ActionController::Parameters`
|
237
|
+
# objects. In Rails < 5, parameters are a subclass of hash and calling
|
238
|
+
# `#symbolize_keys` returns the entire hash, not just permitted values. In
|
239
|
+
# Rails >= 5, parameters are not a subclass of hash but calling
|
240
|
+
# `#to_unsafe_h` returns the entire hash.
|
241
|
+
def normalize_inputs!(inputs)
|
242
|
+
return inputs if inputs.is_a?(Hash)
|
243
|
+
|
244
|
+
parameters = 'ActionController::Parameters'
|
245
|
+
klass = parameters.safe_constantize
|
246
|
+
return inputs.to_unsafe_h if klass && inputs.is_a?(klass)
|
247
|
+
|
248
|
+
raise ArgumentError, "inputs must be a hash or #{parameters}"
|
249
|
+
end
|
250
|
+
|
237
251
|
# @param inputs [Hash{Symbol => Object}]
|
238
252
|
def process_inputs(inputs)
|
239
253
|
@_interaction_keys = inputs.keys.to_set & self.class.filters.keys
|
@@ -1,6 +1,7 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
|
3
3
|
require 'spec_helper'
|
4
|
+
require 'action_controller'
|
4
5
|
|
5
6
|
InteractionWithFilter = Class.new(TestInteraction) do
|
6
7
|
float :thing
|
@@ -58,6 +59,22 @@ describe ActiveInteraction::Base do
|
|
58
59
|
end
|
59
60
|
end
|
60
61
|
|
62
|
+
context 'with non-hash inputs' do
|
63
|
+
let(:inputs) { [[:k, :v]] }
|
64
|
+
|
65
|
+
it 'raises an error' do
|
66
|
+
expect { interaction }.to raise_error ArgumentError
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
context 'with ActionController::Parameters inputs' do
|
71
|
+
let(:inputs) { ActionController::Parameters.new }
|
72
|
+
|
73
|
+
it 'does not raise an error' do
|
74
|
+
expect { interaction }.to_not raise_error
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
61
78
|
context 'with a reader' do
|
62
79
|
let(:described_class) do
|
63
80
|
Class.new(TestInteraction) do
|
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.
|
4
|
+
version: 3.3.0
|
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-
|
12
|
+
date: 2016-09-13 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activemodel
|