active_interaction 2.1.3 → 2.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +26 -0
- data/README.md +16 -7
- data/lib/active_interaction.rb +1 -1
- data/lib/active_interaction/backports.rb +2 -0
- data/lib/active_interaction/base.rb +7 -3
- data/lib/active_interaction/filter.rb +2 -0
- data/lib/active_interaction/filters/array_filter.rb +0 -5
- data/lib/active_interaction/version.rb +1 -1
- data/spec/active_interaction/base_spec.rb +6 -0
- data/spec/active_interaction/errors_spec.rb +19 -0
- data/spec/active_interaction/filters/hash_filter_spec.rb +10 -0
- data/spec/active_interaction/integration/hash_interaction_spec.rb +11 -1
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9a82290d24f562e44617bf6deba80d915d78113f
|
4
|
+
data.tar.gz: c6e08917700fe184b5bfe9acd9443fce727f5138
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 804a4044b041fa61133131811df899bc7c934fb153662f4438cb21e18f780624e76e30ecb6fa0b4894ad24dbfd89050a437a9e712972460e490939b859ad1d99
|
7
|
+
data.tar.gz: a896550485474632bf0111ba1665eac326091b025e79c9ea1f0826bc079d8a0cde2000e5692884058a85ed37a15d001452e5b09a9f4bed9d24036255ccfc30d5
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,18 @@
|
|
1
|
+
# [2.1.4][] (2015-11-03)
|
2
|
+
|
3
|
+
## Fixed
|
4
|
+
|
5
|
+
- [#320][]: Stopped requiring ActiveRecord.
|
6
|
+
|
7
|
+
## Added
|
8
|
+
|
9
|
+
- [#310][]: Added a warning when a filter is redefined.
|
10
|
+
|
11
|
+
## Changed
|
12
|
+
|
13
|
+
- [#311][]: Changed the error message when defining the default value for a
|
14
|
+
hash.
|
15
|
+
|
1
16
|
# [2.1.3][] (2015-10-02)
|
2
17
|
|
3
18
|
## Fixed
|
@@ -57,6 +72,12 @@ For help upgrading to version 2, please read [the announcement post][].
|
|
57
72
|
- [#215][]: Rather than symbolizing keys all hashes now use indifferent access.
|
58
73
|
This takes care of potential but unlikely DoS attacks noted in [#163][].
|
59
74
|
|
75
|
+
# [1.6.1][] (2015-10-02)
|
76
|
+
|
77
|
+
## Fixed
|
78
|
+
|
79
|
+
- [#303][]: Allowed ActiveRecord associations as inputs to array filters.
|
80
|
+
|
60
81
|
# [1.6.0][] (2015-05-06)
|
61
82
|
|
62
83
|
## Added
|
@@ -455,12 +476,14 @@ For help upgrading to version 2, please read [the announcement post][].
|
|
455
476
|
|
456
477
|
- Initial release.
|
457
478
|
|
479
|
+
[2.1.4]: https://github.com/orgsync/active_interaction/compare/v2.1.3...v2.1.4
|
458
480
|
[2.1.3]: https://github.com/orgsync/active_interaction/compare/v2.1.2...v2.1.3
|
459
481
|
[2.1.2]: https://github.com/orgsync/active_interaction/compare/v2.1.1...v2.1.2
|
460
482
|
[2.1.1]: https://github.com/orgsync/active_interaction/compare/v2.1.0...v2.1.1
|
461
483
|
[2.1.0]: https://github.com/orgsync/active_interaction/compare/v2.0.1...v2.1.0
|
462
484
|
[2.0.1]: https://github.com/orgsync/active_interaction/compare/v2.0.0...v2.0.1
|
463
485
|
[2.0.0]: https://github.com/orgsync/active_interaction/compare/v1.6.0...v2.0.0
|
486
|
+
[1.6.1]: https://github.com/orgsync/active_interaction/compare/v1.6.0...v1.6.1
|
464
487
|
[1.6.0]: https://github.com/orgsync/active_interaction/compare/v1.5.1...v1.6.0
|
465
488
|
[1.5.1]: https://github.com/orgsync/active_interaction/compare/v1.5.0...v1.5.1
|
466
489
|
[1.5.0]: https://github.com/orgsync/active_interaction/compare/v1.4.1...v1.5.0
|
@@ -597,5 +620,8 @@ For help upgrading to version 2, please read [the announcement post][].
|
|
597
620
|
[#298]: https://github.com/orgsync/active_interaction/issues/298
|
598
621
|
[#303]: https://github.com/orgsync/active_interaction/issues/303
|
599
622
|
[#304]: https://github.com/orgsync/active_interaction/issues/304
|
623
|
+
[#310]: https://github.com/orgsync/active_interaction/issues/310
|
624
|
+
[#311]: https://github.com/orgsync/active_interaction/issues/311
|
625
|
+
[#320]: https://github.com/orgsync/active_interaction/issues/320
|
600
626
|
|
601
627
|
[the announcement post]: http://devblog.orgsync.com/2015/05/06/announcing-active-interaction-2/
|
data/README.md
CHANGED
@@ -285,7 +285,7 @@ BooleanInteraction.run!(kool_aid: true)
|
|
285
285
|
|
286
286
|
### File
|
287
287
|
|
288
|
-
File filters also accept `TempFile`s and anything that responds to `#
|
288
|
+
File filters also accept `TempFile`s and anything that responds to `#rewind`.
|
289
289
|
That means that you can pass the `params` from uploading files via forms in
|
290
290
|
Rails.
|
291
291
|
|
@@ -614,7 +614,8 @@ IntegerInteraction.run!(limit: 10)
|
|
614
614
|
ActiveInteraction plays nicely with Rails. You can use interactions to handle
|
615
615
|
your business logic instead of models or controllers. To see how it all works,
|
616
616
|
let's take a look at a complete example of a controller with the typical
|
617
|
-
resourceful actions.
|
617
|
+
resourceful actions. For a complete working example, check out [Aire][], our
|
618
|
+
example Rails application.
|
618
619
|
|
619
620
|
### Controller
|
620
621
|
|
@@ -1167,7 +1168,7 @@ input type.
|
|
1167
1168
|
### Optional inputs
|
1168
1169
|
|
1169
1170
|
Optional inputs can be defined by using the `:default` option as described in
|
1170
|
-
[the
|
1171
|
+
[the filters section][]. Within the interaction, provided and default values
|
1171
1172
|
are merged to create `inputs`. There are times where it is useful to know
|
1172
1173
|
whether a value was passed to `run` or the result of a filter default. In
|
1173
1174
|
particular, it is useful when `nil` is an acceptable value. For example, you
|
@@ -1194,17 +1195,23 @@ And if you want to update it, pass in the new value as usual.
|
|
1194
1195
|
|
1195
1196
|
``` rb
|
1196
1197
|
user = User.find(...)
|
1198
|
+
|
1197
1199
|
# Don't update their birthday.
|
1198
1200
|
UpdateUser.run!(user: user)
|
1201
|
+
|
1199
1202
|
# Remove their birthday.
|
1200
1203
|
UpdateUser.run!(user: user, birthday: nil)
|
1204
|
+
|
1201
1205
|
# Update their birthday.
|
1202
1206
|
UpdateUser.run!(user: user, birthday: Date.new(2000, 1, 2))
|
1203
1207
|
```
|
1204
1208
|
|
1205
1209
|
### Predicates
|
1206
1210
|
|
1207
|
-
ActiveInteraction creates a predicate method for every input defined by a
|
1211
|
+
ActiveInteraction creates a predicate method for every input defined by a
|
1212
|
+
filter. So if you have an input called `foo`, there will be a predicate method
|
1213
|
+
called `#foo?`. That method will tell you if the input was given (that is, if
|
1214
|
+
it was not `nil`).
|
1208
1215
|
|
1209
1216
|
``` rb
|
1210
1217
|
class SayHello < ActiveInteraction::Base
|
@@ -1226,6 +1233,9 @@ SayHello.run!(name: 'Taylor')
|
|
1226
1233
|
# => "Hello, Taylor!"
|
1227
1234
|
```
|
1228
1235
|
|
1236
|
+
See [the optional inputs section][] for help on determining if an input was
|
1237
|
+
present in the input hash instead of just `nil`.
|
1238
|
+
|
1229
1239
|
### Translations
|
1230
1240
|
|
1231
1241
|
ActiveInteraction is i18n aware out of the box! All you have to do is add
|
@@ -1288,8 +1298,6 @@ available on GitHub.
|
|
1288
1298
|
|
1289
1299
|
ActiveInteraction is licensed under [the MIT License][].
|
1290
1300
|
|
1291
|
-
Logo design by [Tyler Lee][].
|
1292
|
-
|
1293
1301
|
[the project page]: http://orgsync.github.io/active_interaction/
|
1294
1302
|
[the full documentation]: http://rubydoc.info/github/orgsync/active_interaction
|
1295
1303
|
[semantic versioning]: http://semver.org/spec/v2.0.0.html
|
@@ -1307,4 +1315,5 @@ Logo design by [Tyler Lee][].
|
|
1307
1315
|
[formtastic]: https://rubygems.org/gems/formtastic
|
1308
1316
|
[simple_form]: https://rubygems.org/gems/simple_form
|
1309
1317
|
[the filters section]: #filters
|
1310
|
-
[
|
1318
|
+
[the optional inputs section]: #optional-inputs
|
1319
|
+
[aire]: example
|
data/lib/active_interaction.rb
CHANGED
@@ -143,10 +143,14 @@ module ActiveInteraction
|
|
143
143
|
|
144
144
|
# @param filter [Filter]
|
145
145
|
def initialize_filter(filter)
|
146
|
-
|
146
|
+
attribute = filter.name
|
147
|
+
if filters.key?(attribute)
|
148
|
+
warn "WARNING: Redefining #{name}##{attribute} filter"
|
149
|
+
end
|
150
|
+
filters[attribute] = filter
|
147
151
|
|
148
|
-
attr_accessor
|
149
|
-
define_method("#{
|
152
|
+
attr_accessor attribute
|
153
|
+
define_method("#{attribute}?") { !public_send(attribute).nil? }
|
150
154
|
|
151
155
|
eagerly_evaluate_default(filter)
|
152
156
|
end
|
@@ -127,6 +127,8 @@ module ActiveInteraction
|
|
127
127
|
fail InvalidValueError if value.is_a?(GroupedInput)
|
128
128
|
|
129
129
|
cast(value)
|
130
|
+
rescue InvalidNestedValueError => error
|
131
|
+
raise InvalidDefaultError, "#{name}: #{value.inspect} (#{error})"
|
130
132
|
rescue InvalidValueError, MissingValueError
|
131
133
|
raise InvalidDefaultError, "#{name}: #{value.inspect}"
|
132
134
|
end
|
@@ -226,6 +226,12 @@ describe ActiveInteraction::Base do
|
|
226
226
|
let(:described_class) { InteractionWithFilter }
|
227
227
|
let(:thing) { rand }
|
228
228
|
|
229
|
+
it 'warns when redefining a filter' do
|
230
|
+
klass = Class.new(described_class)
|
231
|
+
expect(klass).to receive(:warn).with(/\AWARNING:/)
|
232
|
+
klass.boolean :thing
|
233
|
+
end
|
234
|
+
|
229
235
|
describe '.run(inputs = {})' do
|
230
236
|
it "returns an instance of #{described_class}" do
|
231
237
|
expect(outcome).to be_a described_class
|
@@ -17,6 +17,25 @@ describe ActiveInteraction::Errors do
|
|
17
17
|
|
18
18
|
subject(:errors) { described_class.new(klass.new) }
|
19
19
|
|
20
|
+
context 'backports' do
|
21
|
+
describe '#delete' do
|
22
|
+
it 'deletes the detailed error' do
|
23
|
+
errors.add(:attribute)
|
24
|
+
errors.delete(:attribute)
|
25
|
+
expect(errors.details).to_not have_key :attribute
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe '#initialize_dup' do
|
30
|
+
it 'duplicates the detailed errors' do
|
31
|
+
errors.add(:attribute)
|
32
|
+
other = errors.dup
|
33
|
+
expect(other.details).to eql errors.details
|
34
|
+
expect(other.details).to_not be errors.details
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
20
39
|
describe '#merge!' do
|
21
40
|
let(:other) { described_class.new(klass.new) }
|
22
41
|
|
@@ -6,6 +6,16 @@ describe ActiveInteraction::HashFilter, :filter do
|
|
6
6
|
include_context 'filters'
|
7
7
|
it_behaves_like 'a filter'
|
8
8
|
|
9
|
+
context 'backports' do
|
10
|
+
describe '.transform_keys' do
|
11
|
+
it 'transforms keys' do
|
12
|
+
original = { 'key' => 'value' }
|
13
|
+
transformed = described_class.transform_keys(original, &:to_sym)
|
14
|
+
expect(transformed).to eql(key: 'value')
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
9
19
|
context 'with a nested nameless filter' do
|
10
20
|
let(:block) { proc { hash } }
|
11
21
|
|
@@ -55,7 +55,7 @@ describe HashInteraction do
|
|
55
55
|
end
|
56
56
|
|
57
57
|
context 'with an invalid nested default' do
|
58
|
-
it 'raises an error' do
|
58
|
+
it 'raises an error with a non-empty hash' do
|
59
59
|
expect do
|
60
60
|
Class.new(ActiveInteraction::Base) do
|
61
61
|
hash :a, default: { x: Object.new } do
|
@@ -64,5 +64,15 @@ describe HashInteraction do
|
|
64
64
|
end
|
65
65
|
end.to raise_error ActiveInteraction::InvalidDefaultError
|
66
66
|
end
|
67
|
+
|
68
|
+
it 'raises an error' do
|
69
|
+
expect do
|
70
|
+
Class.new(ActiveInteraction::Base) do
|
71
|
+
hash :a, default: {} do
|
72
|
+
hash :x
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end.to raise_error ActiveInteraction::InvalidDefaultError
|
76
|
+
end
|
67
77
|
end
|
68
78
|
end
|
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: 2.1.
|
4
|
+
version: 2.1.4
|
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: 2015-
|
12
|
+
date: 2015-11-03 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activemodel
|
@@ -113,14 +113,14 @@ dependencies:
|
|
113
113
|
requirements:
|
114
114
|
- - "~>"
|
115
115
|
- !ruby/object:Gem::Version
|
116
|
-
version: '1.
|
116
|
+
version: '1.9'
|
117
117
|
type: :development
|
118
118
|
prerelease: false
|
119
119
|
version_requirements: !ruby/object:Gem::Requirement
|
120
120
|
requirements:
|
121
121
|
- - "~>"
|
122
122
|
- !ruby/object:Gem::Version
|
123
|
-
version: '1.
|
123
|
+
version: '1.9'
|
124
124
|
- !ruby/object:Gem::Dependency
|
125
125
|
name: rake
|
126
126
|
requirement: !ruby/object:Gem::Requirement
|
@@ -155,14 +155,14 @@ dependencies:
|
|
155
155
|
requirements:
|
156
156
|
- - "~>"
|
157
157
|
- !ruby/object:Gem::Version
|
158
|
-
version: '0.
|
158
|
+
version: '0.34'
|
159
159
|
type: :development
|
160
160
|
prerelease: false
|
161
161
|
version_requirements: !ruby/object:Gem::Requirement
|
162
162
|
requirements:
|
163
163
|
- - "~>"
|
164
164
|
- !ruby/object:Gem::Version
|
165
|
-
version: '0.
|
165
|
+
version: '0.34'
|
166
166
|
- !ruby/object:Gem::Dependency
|
167
167
|
name: yard
|
168
168
|
requirement: !ruby/object:Gem::Requirement
|