active_interaction 1.1.7 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +9 -1
  3. data/README.md +3 -2
  4. data/lib/active_interaction.rb +7 -1
  5. data/lib/active_interaction/base.rb +61 -13
  6. data/lib/active_interaction/concerns/runnable.rb +2 -18
  7. data/lib/active_interaction/concerns/transactable.rb +72 -0
  8. data/lib/active_interaction/errors.rb +7 -0
  9. data/lib/active_interaction/filter.rb +23 -2
  10. data/lib/active_interaction/filter_column.rb +59 -0
  11. data/lib/active_interaction/filters/abstract_date_time_filter.rb +14 -0
  12. data/lib/active_interaction/filters/abstract_filter.rb +4 -7
  13. data/lib/active_interaction/filters/abstract_numeric_filter.rb +4 -0
  14. data/lib/active_interaction/filters/boolean_filter.rb +4 -0
  15. data/lib/active_interaction/filters/date_time_filter.rb +3 -0
  16. data/lib/active_interaction/filters/decimal_filter.rb +54 -0
  17. data/lib/active_interaction/filters/file_filter.rb +4 -0
  18. data/lib/active_interaction/filters/time_filter.rb +4 -0
  19. data/lib/active_interaction/grouped_input.rb +24 -0
  20. data/lib/active_interaction/locale/en.yml +1 -0
  21. data/lib/active_interaction/modules/input_processor.rb +40 -0
  22. data/lib/active_interaction/version.rb +1 -1
  23. data/spec/active_interaction/base_spec.rb +90 -29
  24. data/spec/active_interaction/concerns/runnable_spec.rb +0 -26
  25. data/spec/active_interaction/concerns/transactable_spec.rb +114 -0
  26. data/spec/active_interaction/filter_column_spec.rb +96 -0
  27. data/spec/active_interaction/filter_spec.rb +15 -11
  28. data/spec/active_interaction/filters/array_filter_spec.rb +13 -5
  29. data/spec/active_interaction/filters/boolean_filter_spec.rb +6 -0
  30. data/spec/active_interaction/filters/date_filter_spec.rb +76 -5
  31. data/spec/active_interaction/filters/date_time_filter_spec.rb +87 -5
  32. data/spec/active_interaction/filters/decimal_filter_spec.rb +70 -0
  33. data/spec/active_interaction/filters/file_filter_spec.rb +11 -3
  34. data/spec/active_interaction/filters/float_filter_spec.rb +12 -4
  35. data/spec/active_interaction/filters/hash_filter_spec.rb +16 -8
  36. data/spec/active_interaction/filters/integer_filter_spec.rb +12 -4
  37. data/spec/active_interaction/filters/model_filter_spec.rb +12 -5
  38. data/spec/active_interaction/filters/string_filter_spec.rb +11 -3
  39. data/spec/active_interaction/filters/symbol_filter_spec.rb +10 -2
  40. data/spec/active_interaction/filters/time_filter_spec.rb +87 -5
  41. data/spec/active_interaction/grouped_input_spec.rb +19 -0
  42. data/spec/active_interaction/modules/input_processor_spec.rb +75 -0
  43. data/spec/support/filters.rb +6 -0
  44. metadata +16 -1
@@ -0,0 +1,19 @@
1
+ # coding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe ActiveInteraction::GroupedInput do
6
+ subject(:grouped_input) { described_class.new }
7
+
8
+ it 'subclasses OpenStruct' do
9
+ expect(grouped_input).to be_an OpenStruct
10
+ end
11
+
12
+ it 'responds to #[]' do
13
+ expect { grouped_input[:key] }.to_not raise_error
14
+ end
15
+
16
+ it 'responds to #[]=' do
17
+ expect { grouped_input[:key] = :value }.to_not raise_error
18
+ end
19
+ end
@@ -0,0 +1,75 @@
1
+ # coding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe ActiveInteraction::InputProcessor do
6
+ describe '.reserved?(name)' do
7
+ it 'returns true for anything starting with "_interaction_"' do
8
+ expect(described_class.reserved?('_interaction_')).to be_true
9
+ end
10
+
11
+ it 'returns false for anything else' do
12
+ expect(described_class.reserved?(SecureRandom.hex)).to be_false
13
+ end
14
+ end
15
+
16
+ describe '.process(inputs)' do
17
+ let(:inputs) { {} }
18
+ let(:result) { described_class.process(inputs) }
19
+
20
+ context 'with simple inputs' do
21
+ before { inputs[:key] = :value }
22
+
23
+ it 'sends them straight through' do
24
+ expect(result).to eql inputs
25
+ end
26
+ end
27
+
28
+ context 'with groupable inputs' do
29
+ context 'without a matching simple input' do
30
+ before do
31
+ inputs.merge!(
32
+ 'key(1i)' => :value1,
33
+ 'key(2i)' => :value2
34
+ )
35
+ end
36
+
37
+ it 'groups the inputs into a GroupedInput' do
38
+ expect(result).to eq(
39
+ key: ActiveInteraction::GroupedInput.new(
40
+ '1' => :value1,
41
+ '2' => :value2
42
+ )
43
+ )
44
+ end
45
+ end
46
+
47
+ context 'with a matching simple input' do
48
+ before do
49
+ inputs.merge!(
50
+ 'key(1i)' => :value1,
51
+ key: :value2
52
+ )
53
+ end
54
+
55
+ it 'groups the inputs into a GroupedInput' do
56
+ expect(result).to eq(
57
+ key: ActiveInteraction::GroupedInput.new(
58
+ '1' => :value1
59
+ )
60
+ )
61
+ end
62
+ end
63
+ end
64
+
65
+ context 'with a reserved name' do
66
+ before { inputs[:_interaction_key] = :value }
67
+
68
+ it 'raises an error' do
69
+ expect do
70
+ result
71
+ end.to raise_error ActiveInteraction::ReservedNameError
72
+ end
73
+ end
74
+ end
75
+ end
@@ -221,4 +221,10 @@ shared_examples_for 'a filter' do
221
221
  expect(filter.options).to eql options
222
222
  end
223
223
  end
224
+
225
+ describe '#database_column_type' do
226
+ it 'returns a symbol' do
227
+ expect(filter.database_column_type).to be_a Symbol
228
+ end
229
+ end
224
230
  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: 1.1.7
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aaron Lasseigne
@@ -160,8 +160,10 @@ files:
160
160
  - lib/active_interaction/concerns/hashable.rb
161
161
  - lib/active_interaction/concerns/missable.rb
162
162
  - lib/active_interaction/concerns/runnable.rb
163
+ - lib/active_interaction/concerns/transactable.rb
163
164
  - lib/active_interaction/errors.rb
164
165
  - lib/active_interaction/filter.rb
166
+ - lib/active_interaction/filter_column.rb
165
167
  - lib/active_interaction/filters/abstract_date_time_filter.rb
166
168
  - lib/active_interaction/filters/abstract_filter.rb
167
169
  - lib/active_interaction/filters/abstract_numeric_filter.rb
@@ -169,6 +171,7 @@ files:
169
171
  - lib/active_interaction/filters/boolean_filter.rb
170
172
  - lib/active_interaction/filters/date_filter.rb
171
173
  - lib/active_interaction/filters/date_time_filter.rb
174
+ - lib/active_interaction/filters/decimal_filter.rb
172
175
  - lib/active_interaction/filters/file_filter.rb
173
176
  - lib/active_interaction/filters/float_filter.rb
174
177
  - lib/active_interaction/filters/hash_filter.rb
@@ -177,7 +180,9 @@ files:
177
180
  - lib/active_interaction/filters/string_filter.rb
178
181
  - lib/active_interaction/filters/symbol_filter.rb
179
182
  - lib/active_interaction/filters/time_filter.rb
183
+ - lib/active_interaction/grouped_input.rb
180
184
  - lib/active_interaction/locale/en.yml
185
+ - lib/active_interaction/modules/input_processor.rb
181
186
  - lib/active_interaction/modules/validation.rb
182
187
  - lib/active_interaction/version.rb
183
188
  - spec/active_interaction/base_spec.rb
@@ -185,7 +190,9 @@ files:
185
190
  - spec/active_interaction/concerns/hashable_spec.rb
186
191
  - spec/active_interaction/concerns/missable_spec.rb
187
192
  - spec/active_interaction/concerns/runnable_spec.rb
193
+ - spec/active_interaction/concerns/transactable_spec.rb
188
194
  - spec/active_interaction/errors_spec.rb
195
+ - spec/active_interaction/filter_column_spec.rb
189
196
  - spec/active_interaction/filter_spec.rb
190
197
  - spec/active_interaction/filters/abstract_date_time_filter_spec.rb
191
198
  - spec/active_interaction/filters/abstract_filter_spec.rb
@@ -194,6 +201,7 @@ files:
194
201
  - spec/active_interaction/filters/boolean_filter_spec.rb
195
202
  - spec/active_interaction/filters/date_filter_spec.rb
196
203
  - spec/active_interaction/filters/date_time_filter_spec.rb
204
+ - spec/active_interaction/filters/decimal_filter_spec.rb
197
205
  - spec/active_interaction/filters/file_filter_spec.rb
198
206
  - spec/active_interaction/filters/float_filter_spec.rb
199
207
  - spec/active_interaction/filters/hash_filter_spec.rb
@@ -202,6 +210,7 @@ files:
202
210
  - spec/active_interaction/filters/string_filter_spec.rb
203
211
  - spec/active_interaction/filters/symbol_filter_spec.rb
204
212
  - spec/active_interaction/filters/time_filter_spec.rb
213
+ - spec/active_interaction/grouped_input_spec.rb
205
214
  - spec/active_interaction/i18n_spec.rb
206
215
  - spec/active_interaction/integration/array_interaction_spec.rb
207
216
  - spec/active_interaction/integration/boolean_interaction_spec.rb
@@ -215,6 +224,7 @@ files:
215
224
  - spec/active_interaction/integration/string_interaction_spec.rb
216
225
  - spec/active_interaction/integration/symbol_interaction_spec.rb
217
226
  - spec/active_interaction/integration/time_interaction_spec.rb
227
+ - spec/active_interaction/modules/input_processor_spec.rb
218
228
  - spec/active_interaction/modules/validation_spec.rb
219
229
  - spec/spec_helper.rb
220
230
  - spec/support/concerns.rb
@@ -250,7 +260,9 @@ test_files:
250
260
  - spec/active_interaction/concerns/hashable_spec.rb
251
261
  - spec/active_interaction/concerns/missable_spec.rb
252
262
  - spec/active_interaction/concerns/runnable_spec.rb
263
+ - spec/active_interaction/concerns/transactable_spec.rb
253
264
  - spec/active_interaction/errors_spec.rb
265
+ - spec/active_interaction/filter_column_spec.rb
254
266
  - spec/active_interaction/filter_spec.rb
255
267
  - spec/active_interaction/filters/abstract_date_time_filter_spec.rb
256
268
  - spec/active_interaction/filters/abstract_filter_spec.rb
@@ -259,6 +271,7 @@ test_files:
259
271
  - spec/active_interaction/filters/boolean_filter_spec.rb
260
272
  - spec/active_interaction/filters/date_filter_spec.rb
261
273
  - spec/active_interaction/filters/date_time_filter_spec.rb
274
+ - spec/active_interaction/filters/decimal_filter_spec.rb
262
275
  - spec/active_interaction/filters/file_filter_spec.rb
263
276
  - spec/active_interaction/filters/float_filter_spec.rb
264
277
  - spec/active_interaction/filters/hash_filter_spec.rb
@@ -267,6 +280,7 @@ test_files:
267
280
  - spec/active_interaction/filters/string_filter_spec.rb
268
281
  - spec/active_interaction/filters/symbol_filter_spec.rb
269
282
  - spec/active_interaction/filters/time_filter_spec.rb
283
+ - spec/active_interaction/grouped_input_spec.rb
270
284
  - spec/active_interaction/i18n_spec.rb
271
285
  - spec/active_interaction/integration/array_interaction_spec.rb
272
286
  - spec/active_interaction/integration/boolean_interaction_spec.rb
@@ -280,6 +294,7 @@ test_files:
280
294
  - spec/active_interaction/integration/string_interaction_spec.rb
281
295
  - spec/active_interaction/integration/symbol_interaction_spec.rb
282
296
  - spec/active_interaction/integration/time_interaction_spec.rb
297
+ - spec/active_interaction/modules/input_processor_spec.rb
283
298
  - spec/active_interaction/modules/validation_spec.rb
284
299
  - spec/spec_helper.rb
285
300
  - spec/support/concerns.rb