active_interaction 3.2.1 → 3.3.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a6c697a5664d9fb8f7dc5e12088c25261aa878d5
4
- data.tar.gz: d79c93af7a60358da30c2f91b381191fb4961847
3
+ metadata.gz: bcb762bfdc148c4eeb1e277f07e13c60fb3944d8
4
+ data.tar.gz: 7676378a761abeadec3fecc6e350dd27a7fbdd37
5
5
  SHA512:
6
- metadata.gz: ffff1d6c71ca6be49b219b300bde3363bd282b3c6ea49805acd9a9a8ea452f8fd51caadda41a21bc75652c2b03562a61c207c90662d498e3c5c78b3c61daa52d
7
- data.tar.gz: c8f8fba72f89b45bc1678c0bcc283286c67c077e2a481f5f5f339de8b3eb4576b2b4f1ccbec1a76c6ac027ead45bc24cdc0a33f1f183ebd041e15b44122da9b5
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
- raise ArgumentError, 'inputs must be a hash' unless inputs.is_a?(Hash)
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
@@ -6,5 +6,5 @@ module ActiveInteraction
6
6
  # The version number.
7
7
  #
8
8
  # @return [Gem::Version]
9
- VERSION = Gem::Version.new('3.2.1')
9
+ VERSION = Gem::Version.new('3.3.0')
10
10
  end
@@ -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.2.1
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-08-26 00:00:00.000000000 Z
12
+ date: 2016-09-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activemodel