active_interaction 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +7 -0
- data/LICENSE.txt +22 -0
- data/README.md +202 -0
- data/lib/active_interaction.rb +23 -0
- data/lib/active_interaction/base.rb +162 -0
- data/lib/active_interaction/errors.rb +6 -0
- data/lib/active_interaction/filter.rb +41 -0
- data/lib/active_interaction/filter_method.rb +17 -0
- data/lib/active_interaction/filter_methods.rb +26 -0
- data/lib/active_interaction/filters/array_filter.rb +56 -0
- data/lib/active_interaction/filters/boolean_filter.rb +30 -0
- data/lib/active_interaction/filters/date_filter.rb +31 -0
- data/lib/active_interaction/filters/date_time_filter.rb +31 -0
- data/lib/active_interaction/filters/file_filter.rb +38 -0
- data/lib/active_interaction/filters/float_filter.rb +32 -0
- data/lib/active_interaction/filters/hash_filter.rb +47 -0
- data/lib/active_interaction/filters/integer_filter.rb +31 -0
- data/lib/active_interaction/filters/model_filter.rb +40 -0
- data/lib/active_interaction/filters/string_filter.rb +25 -0
- data/lib/active_interaction/filters/time_filter.rb +44 -0
- data/lib/active_interaction/overload_hash.rb +11 -0
- data/lib/active_interaction/version.rb +3 -0
- data/spec/active_interaction/base_spec.rb +175 -0
- data/spec/active_interaction/filter_method_spec.rb +48 -0
- data/spec/active_interaction/filter_methods_spec.rb +30 -0
- data/spec/active_interaction/filter_spec.rb +29 -0
- data/spec/active_interaction/filters/array_filter_spec.rb +54 -0
- data/spec/active_interaction/filters/boolean_filter_spec.rb +40 -0
- data/spec/active_interaction/filters/date_filter_spec.rb +32 -0
- data/spec/active_interaction/filters/date_time_filter_spec.rb +32 -0
- data/spec/active_interaction/filters/file_filter_spec.rb +32 -0
- data/spec/active_interaction/filters/float_filter_spec.rb +40 -0
- data/spec/active_interaction/filters/hash_filter_spec.rb +57 -0
- data/spec/active_interaction/filters/integer_filter_spec.rb +32 -0
- data/spec/active_interaction/filters/model_filter_spec.rb +40 -0
- data/spec/active_interaction/filters/string_filter_spec.rb +16 -0
- data/spec/active_interaction/filters/time_filter_spec.rb +66 -0
- data/spec/active_interaction/integration/array_interaction_spec.rb +69 -0
- data/spec/active_interaction/integration/boolean_interaction_spec.rb +5 -0
- data/spec/active_interaction/integration/date_interaction_spec.rb +5 -0
- data/spec/active_interaction/integration/date_time_interaction_spec.rb +5 -0
- data/spec/active_interaction/integration/file_interaction_spec.rb +5 -0
- data/spec/active_interaction/integration/float_interaction_spec.rb +5 -0
- data/spec/active_interaction/integration/hash_interaction_spec.rb +69 -0
- data/spec/active_interaction/integration/integer_interaction_spec.rb +5 -0
- data/spec/active_interaction/integration/model_interaction_spec.rb +5 -0
- data/spec/active_interaction/integration/string_interaction_spec.rb +5 -0
- data/spec/active_interaction/integration/time_interaction_spec.rb +5 -0
- data/spec/active_interaction/overload_hash_spec.rb +41 -0
- data/spec/spec_helper.rb +6 -0
- data/spec/support/filters.rb +37 -0
- data/spec/support/interactions.rb +79 -0
- metadata +278 -0
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe ActiveInteraction::OverloadHash do
|
4
|
+
subject { double.extend(described_class) }
|
5
|
+
|
6
|
+
describe '#hash(*args, &block)' do
|
7
|
+
context 'with no arguments' do
|
8
|
+
let(:hash) { subject.hash }
|
9
|
+
|
10
|
+
it 'returns a Fixnum' do
|
11
|
+
expect(hash).to be_a Fixnum
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
context 'with arguments' do
|
16
|
+
let(:arguments) { [:attribute, {}] }
|
17
|
+
let(:hash) { subject.hash(*arguments) }
|
18
|
+
|
19
|
+
before { allow(subject).to receive(:method_missing) }
|
20
|
+
|
21
|
+
it 'calls method_missing' do
|
22
|
+
hash
|
23
|
+
expect(subject).to have_received(:method_missing).once.
|
24
|
+
with(:hash, *arguments)
|
25
|
+
end
|
26
|
+
|
27
|
+
context 'with a block' do
|
28
|
+
let(:block) { Proc.new {} }
|
29
|
+
let(:hash) { subject.hash(*arguments, &block) }
|
30
|
+
|
31
|
+
it 'calls method_missing' do
|
32
|
+
hash
|
33
|
+
expect(subject).to have_received(:method_missing).once.
|
34
|
+
with(:hash, *arguments)
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'passes the block to method_missing'
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
shared_context 'filters' do
|
2
|
+
let(:key) { SecureRandom.hex }
|
3
|
+
let(:value) { nil }
|
4
|
+
let(:options) { {} }
|
5
|
+
let(:block) { Proc.new {} }
|
6
|
+
subject(:result) { described_class.prepare(key, value, options, &block) }
|
7
|
+
end
|
8
|
+
|
9
|
+
shared_examples_for 'a filter' do
|
10
|
+
include_context 'filters'
|
11
|
+
|
12
|
+
context '.prepare(key, value, options = {}, &block)' do
|
13
|
+
context 'with nil' do
|
14
|
+
it 'raises an error' do
|
15
|
+
expect { result }.to raise_error ActiveInteraction::MissingValue
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
context 'with anything else' do
|
20
|
+
let(:value) { Object.new }
|
21
|
+
|
22
|
+
it 'raises an error' do
|
23
|
+
expect { result }.to raise_error ActiveInteraction::InvalidValue
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
context 'optional' do
|
28
|
+
before { options.merge!(allow_nil: true) }
|
29
|
+
|
30
|
+
context 'with nil' do
|
31
|
+
it 'returns nil' do
|
32
|
+
expect(result).to be_nil
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
shared_context 'interactions' do
|
2
|
+
let(:options) { {} }
|
3
|
+
let(:outcome) { described_class.run(options) }
|
4
|
+
let(:result) { outcome.result }
|
5
|
+
end
|
6
|
+
|
7
|
+
shared_examples_for 'an interaction' do |type, value_lambda, filter_options = {}|
|
8
|
+
include_context 'interactions'
|
9
|
+
|
10
|
+
let(:described_class) do
|
11
|
+
Class.new(ActiveInteraction::Base) do
|
12
|
+
send(type, :required, filter_options)
|
13
|
+
send(type, :optional, filter_options.merge(allow_nil: true))
|
14
|
+
send(type, :default, filter_options.merge(default: value_lambda.call))
|
15
|
+
send(type, :nil_default, filter_options.merge(allow_nil: true, default: nil))
|
16
|
+
|
17
|
+
def execute
|
18
|
+
{
|
19
|
+
required: required,
|
20
|
+
optional: optional,
|
21
|
+
default: default,
|
22
|
+
nil_default: nil_default
|
23
|
+
}
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
context 'without required options' do
|
29
|
+
it 'is invalid' do
|
30
|
+
expect(outcome).to be_invalid
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
context 'with options[:required]' do
|
35
|
+
let(:required) { value_lambda.call }
|
36
|
+
|
37
|
+
before { options.merge!(required: required) }
|
38
|
+
|
39
|
+
it 'is valid' do
|
40
|
+
expect(outcome).to be_valid
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'returns the correct value for :required' do
|
44
|
+
expect(result[:required]).to eq required
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'returns nil for :optional' do
|
48
|
+
expect(result[:optional]).to be_nil
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'does not return nil for :default' do
|
52
|
+
expect(result[:default]).to_not be_nil
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'returns nil for :nil_default' do
|
56
|
+
expect(result[:nil_default]).to be_nil
|
57
|
+
end
|
58
|
+
|
59
|
+
context 'with options[:optional]' do
|
60
|
+
let(:optional) { value_lambda.call }
|
61
|
+
|
62
|
+
before { options.merge!(optional: optional) }
|
63
|
+
|
64
|
+
it 'returns the correct value for :optional' do
|
65
|
+
expect(result[:optional]).to eq optional
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
context 'with options[:default]' do
|
70
|
+
let(:default) { value_lambda.call }
|
71
|
+
|
72
|
+
before { options.merge!(default: default) }
|
73
|
+
|
74
|
+
it 'returns the correct value for :default' do
|
75
|
+
expect(result[:default]).to eq default
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
metadata
ADDED
@@ -0,0 +1,278 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: active_interaction
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.1.1
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Aaron Lasseigne
|
9
|
+
- Taylor Fausak
|
10
|
+
autorequire:
|
11
|
+
bindir: bin
|
12
|
+
cert_chain: []
|
13
|
+
date: 2013-07-13 00:00:00.000000000 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: activemodel
|
17
|
+
type: :runtime
|
18
|
+
requirement: !ruby/object:Gem::Requirement
|
19
|
+
requirements:
|
20
|
+
- - ! '>='
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 3.0.0
|
23
|
+
none: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
requirements:
|
26
|
+
- - ! '>='
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
version: 3.0.0
|
29
|
+
none: false
|
30
|
+
prerelease: false
|
31
|
+
- !ruby/object:Gem::Dependency
|
32
|
+
name: bundler
|
33
|
+
type: :development
|
34
|
+
requirement: !ruby/object:Gem::Requirement
|
35
|
+
requirements:
|
36
|
+
- - ~>
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: '1.3'
|
39
|
+
none: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
requirements:
|
42
|
+
- - ~>
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: '1.3'
|
45
|
+
none: false
|
46
|
+
prerelease: false
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: coveralls
|
49
|
+
type: :development
|
50
|
+
requirement: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0.6'
|
55
|
+
none: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ~>
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '0.6'
|
61
|
+
none: false
|
62
|
+
prerelease: false
|
63
|
+
- !ruby/object:Gem::Dependency
|
64
|
+
name: guard-rspec
|
65
|
+
type: :development
|
66
|
+
requirement: !ruby/object:Gem::Requirement
|
67
|
+
requirements:
|
68
|
+
- - ~>
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '3.0'
|
71
|
+
none: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - ~>
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '3.0'
|
77
|
+
none: false
|
78
|
+
prerelease: false
|
79
|
+
- !ruby/object:Gem::Dependency
|
80
|
+
name: kramdown
|
81
|
+
type: :development
|
82
|
+
requirement: !ruby/object:Gem::Requirement
|
83
|
+
requirements:
|
84
|
+
- - ~>
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: '1.1'
|
87
|
+
none: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
requirements:
|
90
|
+
- - ~>
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: '1.1'
|
93
|
+
none: false
|
94
|
+
prerelease: false
|
95
|
+
- !ruby/object:Gem::Dependency
|
96
|
+
name: rake
|
97
|
+
type: :development
|
98
|
+
requirement: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - ~>
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '10.1'
|
103
|
+
none: false
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
requirements:
|
106
|
+
- - ~>
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: '10.1'
|
109
|
+
none: false
|
110
|
+
prerelease: false
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: rb-fsevent
|
113
|
+
type: :development
|
114
|
+
requirement: !ruby/object:Gem::Requirement
|
115
|
+
requirements:
|
116
|
+
- - ~>
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: '0.9'
|
119
|
+
none: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ~>
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0.9'
|
125
|
+
none: false
|
126
|
+
prerelease: false
|
127
|
+
- !ruby/object:Gem::Dependency
|
128
|
+
name: rspec
|
129
|
+
type: :development
|
130
|
+
requirement: !ruby/object:Gem::Requirement
|
131
|
+
requirements:
|
132
|
+
- - ~>
|
133
|
+
- !ruby/object:Gem::Version
|
134
|
+
version: '2.14'
|
135
|
+
none: false
|
136
|
+
version_requirements: !ruby/object:Gem::Requirement
|
137
|
+
requirements:
|
138
|
+
- - ~>
|
139
|
+
- !ruby/object:Gem::Version
|
140
|
+
version: '2.14'
|
141
|
+
none: false
|
142
|
+
prerelease: false
|
143
|
+
- !ruby/object:Gem::Dependency
|
144
|
+
name: yard
|
145
|
+
type: :development
|
146
|
+
requirement: !ruby/object:Gem::Requirement
|
147
|
+
requirements:
|
148
|
+
- - ~>
|
149
|
+
- !ruby/object:Gem::Version
|
150
|
+
version: '0.8'
|
151
|
+
none: false
|
152
|
+
version_requirements: !ruby/object:Gem::Requirement
|
153
|
+
requirements:
|
154
|
+
- - ~>
|
155
|
+
- !ruby/object:Gem::Version
|
156
|
+
version: '0.8'
|
157
|
+
none: false
|
158
|
+
prerelease: false
|
159
|
+
description: Manage application specific business logic.
|
160
|
+
email:
|
161
|
+
- aaron.lasseigne@gmail.com
|
162
|
+
- taylor@fausak.me
|
163
|
+
executables: []
|
164
|
+
extensions: []
|
165
|
+
extra_rdoc_files: []
|
166
|
+
files:
|
167
|
+
- spec/active_interaction/base_spec.rb
|
168
|
+
- spec/active_interaction/filter_method_spec.rb
|
169
|
+
- spec/active_interaction/filter_methods_spec.rb
|
170
|
+
- spec/active_interaction/filter_spec.rb
|
171
|
+
- spec/active_interaction/filters/array_filter_spec.rb
|
172
|
+
- spec/active_interaction/filters/boolean_filter_spec.rb
|
173
|
+
- spec/active_interaction/filters/date_filter_spec.rb
|
174
|
+
- spec/active_interaction/filters/date_time_filter_spec.rb
|
175
|
+
- spec/active_interaction/filters/file_filter_spec.rb
|
176
|
+
- spec/active_interaction/filters/float_filter_spec.rb
|
177
|
+
- spec/active_interaction/filters/hash_filter_spec.rb
|
178
|
+
- spec/active_interaction/filters/integer_filter_spec.rb
|
179
|
+
- spec/active_interaction/filters/model_filter_spec.rb
|
180
|
+
- spec/active_interaction/filters/string_filter_spec.rb
|
181
|
+
- spec/active_interaction/filters/time_filter_spec.rb
|
182
|
+
- spec/active_interaction/integration/array_interaction_spec.rb
|
183
|
+
- spec/active_interaction/integration/boolean_interaction_spec.rb
|
184
|
+
- spec/active_interaction/integration/date_interaction_spec.rb
|
185
|
+
- spec/active_interaction/integration/date_time_interaction_spec.rb
|
186
|
+
- spec/active_interaction/integration/file_interaction_spec.rb
|
187
|
+
- spec/active_interaction/integration/float_interaction_spec.rb
|
188
|
+
- spec/active_interaction/integration/hash_interaction_spec.rb
|
189
|
+
- spec/active_interaction/integration/integer_interaction_spec.rb
|
190
|
+
- spec/active_interaction/integration/model_interaction_spec.rb
|
191
|
+
- spec/active_interaction/integration/string_interaction_spec.rb
|
192
|
+
- spec/active_interaction/integration/time_interaction_spec.rb
|
193
|
+
- spec/active_interaction/overload_hash_spec.rb
|
194
|
+
- spec/spec_helper.rb
|
195
|
+
- spec/support/filters.rb
|
196
|
+
- spec/support/interactions.rb
|
197
|
+
- lib/active_interaction/base.rb
|
198
|
+
- lib/active_interaction/errors.rb
|
199
|
+
- lib/active_interaction/filter.rb
|
200
|
+
- lib/active_interaction/filter_method.rb
|
201
|
+
- lib/active_interaction/filter_methods.rb
|
202
|
+
- lib/active_interaction/filters/array_filter.rb
|
203
|
+
- lib/active_interaction/filters/boolean_filter.rb
|
204
|
+
- lib/active_interaction/filters/date_filter.rb
|
205
|
+
- lib/active_interaction/filters/date_time_filter.rb
|
206
|
+
- lib/active_interaction/filters/file_filter.rb
|
207
|
+
- lib/active_interaction/filters/float_filter.rb
|
208
|
+
- lib/active_interaction/filters/hash_filter.rb
|
209
|
+
- lib/active_interaction/filters/integer_filter.rb
|
210
|
+
- lib/active_interaction/filters/model_filter.rb
|
211
|
+
- lib/active_interaction/filters/string_filter.rb
|
212
|
+
- lib/active_interaction/filters/time_filter.rb
|
213
|
+
- lib/active_interaction/overload_hash.rb
|
214
|
+
- lib/active_interaction/version.rb
|
215
|
+
- lib/active_interaction.rb
|
216
|
+
- CHANGELOG.md
|
217
|
+
- LICENSE.txt
|
218
|
+
- README.md
|
219
|
+
homepage: https://github.com/orgsync/active_interaction
|
220
|
+
licenses:
|
221
|
+
- MIT
|
222
|
+
post_install_message:
|
223
|
+
rdoc_options: []
|
224
|
+
require_paths:
|
225
|
+
- lib
|
226
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
227
|
+
requirements:
|
228
|
+
- - ! '>='
|
229
|
+
- !ruby/object:Gem::Version
|
230
|
+
version: 1.9.3
|
231
|
+
none: false
|
232
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
233
|
+
requirements:
|
234
|
+
- - ! '>='
|
235
|
+
- !ruby/object:Gem::Version
|
236
|
+
segments:
|
237
|
+
- 0
|
238
|
+
hash: -3542562646665336521
|
239
|
+
version: '0'
|
240
|
+
none: false
|
241
|
+
requirements: []
|
242
|
+
rubyforge_project:
|
243
|
+
rubygems_version: 1.8.23
|
244
|
+
signing_key:
|
245
|
+
specification_version: 3
|
246
|
+
summary: Manage application specific business logic.
|
247
|
+
test_files:
|
248
|
+
- spec/active_interaction/base_spec.rb
|
249
|
+
- spec/active_interaction/filter_method_spec.rb
|
250
|
+
- spec/active_interaction/filter_methods_spec.rb
|
251
|
+
- spec/active_interaction/filter_spec.rb
|
252
|
+
- spec/active_interaction/filters/array_filter_spec.rb
|
253
|
+
- spec/active_interaction/filters/boolean_filter_spec.rb
|
254
|
+
- spec/active_interaction/filters/date_filter_spec.rb
|
255
|
+
- spec/active_interaction/filters/date_time_filter_spec.rb
|
256
|
+
- spec/active_interaction/filters/file_filter_spec.rb
|
257
|
+
- spec/active_interaction/filters/float_filter_spec.rb
|
258
|
+
- spec/active_interaction/filters/hash_filter_spec.rb
|
259
|
+
- spec/active_interaction/filters/integer_filter_spec.rb
|
260
|
+
- spec/active_interaction/filters/model_filter_spec.rb
|
261
|
+
- spec/active_interaction/filters/string_filter_spec.rb
|
262
|
+
- spec/active_interaction/filters/time_filter_spec.rb
|
263
|
+
- spec/active_interaction/integration/array_interaction_spec.rb
|
264
|
+
- spec/active_interaction/integration/boolean_interaction_spec.rb
|
265
|
+
- spec/active_interaction/integration/date_interaction_spec.rb
|
266
|
+
- spec/active_interaction/integration/date_time_interaction_spec.rb
|
267
|
+
- spec/active_interaction/integration/file_interaction_spec.rb
|
268
|
+
- spec/active_interaction/integration/float_interaction_spec.rb
|
269
|
+
- spec/active_interaction/integration/hash_interaction_spec.rb
|
270
|
+
- spec/active_interaction/integration/integer_interaction_spec.rb
|
271
|
+
- spec/active_interaction/integration/model_interaction_spec.rb
|
272
|
+
- spec/active_interaction/integration/string_interaction_spec.rb
|
273
|
+
- spec/active_interaction/integration/time_interaction_spec.rb
|
274
|
+
- spec/active_interaction/overload_hash_spec.rb
|
275
|
+
- spec/spec_helper.rb
|
276
|
+
- spec/support/filters.rb
|
277
|
+
- spec/support/interactions.rb
|
278
|
+
has_rdoc:
|