action_logic 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,286 @@
1
+ require 'action_logic'
2
+ require 'fixtures/custom_types'
3
+ require 'fixtures/constants'
4
+
5
+ class SimpleTestTask
6
+ include ActionLogic::ActionTask
7
+
8
+ def call
9
+ context.new_attribute = true
10
+ end
11
+ end
12
+
13
+ class ValidateAroundTestTask
14
+ include ActionLogic::ActionTask
15
+
16
+ validates_around Constants::ALL_VALIDATIONS
17
+
18
+ def call
19
+ end
20
+ end
21
+
22
+ class ValidateAroundCustomTypeTestTask
23
+ include ActionLogic::ActionTask
24
+
25
+ validates_around :custom_type => { :type => :customtype1, :presence => true }
26
+
27
+ def call
28
+ end
29
+ end
30
+
31
+ class ValidateAroundUnrecognizablePresenceTestTask
32
+ include ActionLogic::ActionTask
33
+
34
+ validates_around :integer_test => { :presence => :true }
35
+
36
+ def call
37
+ end
38
+ end
39
+
40
+ class ValidateAroundPresenceTestTask
41
+ include ActionLogic::ActionTask
42
+
43
+ validates_around :integer_test => { :presence => true }
44
+
45
+ def call
46
+ end
47
+ end
48
+
49
+ class ValidateAroundCustomPresenceTestTask
50
+ include ActionLogic::ActionTask
51
+
52
+ validates_around :array_test => { :presence => ->(array_test) { array_test.any? } }
53
+
54
+ def call
55
+ end
56
+
57
+ def tasks
58
+ []
59
+ end
60
+ end
61
+
62
+ class ValidateBeforeTestTask
63
+ include ActionLogic::ActionTask
64
+
65
+ validates_before Constants::ALL_VALIDATIONS
66
+
67
+ def call
68
+ end
69
+ end
70
+
71
+ class ValidateBeforeCustomTypeTestTask
72
+ include ActionLogic::ActionTask
73
+
74
+ validates_before :custom_type => { :type => :customtype1, :presence => true }
75
+
76
+ def call
77
+ end
78
+ end
79
+
80
+ class ValidateBeforeUnrecognizablePresenceTestTask
81
+ include ActionLogic::ActionTask
82
+
83
+ validates_before :integer_test => { :presence => :true }
84
+
85
+ def call
86
+ end
87
+ end
88
+
89
+ class ValidateBeforePresenceTestTask
90
+ include ActionLogic::ActionTask
91
+
92
+ validates_before :integer_test => { :presence => true }
93
+
94
+ def call
95
+ end
96
+ end
97
+
98
+ class ValidateBeforeCustomPresenceTestTask
99
+ include ActionLogic::ActionTask
100
+
101
+ validates_before :array_test => { :presence => ->(array_test) { array_test.any? } }
102
+
103
+ def call
104
+ end
105
+
106
+ def tasks
107
+ []
108
+ end
109
+ end
110
+
111
+ class ValidateAfterTestTask
112
+ include ActionLogic::ActionTask
113
+
114
+ validates_after Constants::ALL_VALIDATIONS
115
+
116
+ def call
117
+ context.integer_test = 1
118
+ context.float_test = 1.0
119
+ context.string_test = "string"
120
+ context.bool_test = false
121
+ context.hash_test = {}
122
+ context.array_test = []
123
+ context.symbol_test = :symbol
124
+ context.nil_test = nil
125
+ end
126
+ end
127
+
128
+ class ValidateAfterMissingAttributesTestTask
129
+ include ActionLogic::ActionTask
130
+
131
+ validates_after Constants::ALL_VALIDATIONS
132
+
133
+ def call
134
+ end
135
+ end
136
+
137
+ class ValidateAfterInvalidTypeTestTask
138
+ include ActionLogic::ActionTask
139
+
140
+ validates_after Constants::ALL_VALIDATIONS
141
+
142
+ def call
143
+ context.integer_test = nil
144
+ context.float_test = nil
145
+ context.string_test = nil
146
+ context.bool_test = nil
147
+ context.hash_test = nil
148
+ context.array_test = nil
149
+ context.symbol_test = nil
150
+ context.nil_test = 1
151
+ end
152
+ end
153
+
154
+ class ValidateAfterCustomTypeTestTask
155
+ include ActionLogic::ActionTask
156
+
157
+ validates_after :custom_type => { :type => :customtype1, :presence => true }
158
+
159
+ def call
160
+ context.custom_type = CustomType1.new
161
+ end
162
+ end
163
+
164
+ class ValidateAfterInvalidCustomTypeTestTask
165
+ include ActionLogic::ActionTask
166
+
167
+ validates_after :custom_type => { :type => :customtype2, :presence => true }
168
+
169
+ def call
170
+ context.custom_type = CustomType1.new
171
+ end
172
+ end
173
+
174
+ class ValidateAfterPresenceTestTask
175
+ include ActionLogic::ActionTask
176
+
177
+ validates_after :integer_test => { :presence => true }
178
+
179
+ def call
180
+ context.integer_test = 1
181
+ end
182
+ end
183
+
184
+ class ValidateAfterInvalidPresenceTestTask
185
+ include ActionLogic::ActionTask
186
+
187
+ validates_after :integer_test => { :presence => true }
188
+
189
+ def call
190
+ context.integer_test = nil
191
+ end
192
+ end
193
+
194
+ class ValidateAfterCustomPresenceTestTask
195
+ include ActionLogic::ActionTask
196
+
197
+ validates_after :array_test => { :presence => ->(array_test) { array_test.any? } }
198
+
199
+ def call
200
+ context.array_test = [1]
201
+ end
202
+ end
203
+
204
+ class ValidateAfterInvalidCustomPresenceTestTask
205
+ include ActionLogic::ActionTask
206
+
207
+ validates_after :array_test => { :presence => ->(array_test) { array_test.any? } }
208
+
209
+ def call
210
+ context.array_test = []
211
+ end
212
+ end
213
+
214
+ class ValidateAfterUnrecognizablePresenceTestTask
215
+ include ActionLogic::ActionTask
216
+
217
+ validates_after :integer_test => { :presence => :true }
218
+
219
+ def call
220
+ context.integer_test = 1
221
+ end
222
+ end
223
+
224
+ class ErrorHandlerTestTask
225
+ include ActionLogic::ActionTask
226
+
227
+ def call
228
+ raise
229
+ end
230
+
231
+ def error(e)
232
+ context.e = e
233
+ end
234
+ end
235
+
236
+ class ErrorHandlerInvalidAttributesBeforeTestTask
237
+ include ActionLogic::ActionTask
238
+
239
+ validates_before Constants::ALL_VALIDATIONS
240
+
241
+ def call
242
+ raise
243
+ end
244
+
245
+ def error(e)
246
+ context.error = "error"
247
+ end
248
+ end
249
+
250
+ class ErrorHandlerInvalidAttributesAfterTestTask
251
+ include ActionLogic::ActionTask
252
+
253
+ validates_after Constants::ALL_VALIDATIONS
254
+
255
+ def call
256
+ raise
257
+ end
258
+
259
+ def error(e)
260
+ context.error = "error"
261
+ end
262
+ end
263
+
264
+ class MissingErrorHandlerTestTask
265
+ include ActionLogic::ActionTask
266
+
267
+ def call
268
+ raise
269
+ end
270
+ end
271
+
272
+ class FailureTestTask
273
+ include ActionLogic::ActionTask
274
+
275
+ def call
276
+ context.fail!(Constants::FAILURE_MESSAGE)
277
+ end
278
+ end
279
+
280
+ class HaltTestTask
281
+ include ActionLogic::ActionTask
282
+
283
+ def call
284
+ context.halt!(Constants::HALT_MESSAGE)
285
+ end
286
+ end
@@ -0,0 +1,324 @@
1
+ require 'action_logic'
2
+ require 'fixtures/tasks'
3
+ require 'fixtures/constants'
4
+
5
+ class SimpleTestUseCase
6
+ include ActionLogic::ActionUseCase
7
+
8
+ def call
9
+ end
10
+
11
+ def tasks
12
+ [SimpleTestTask]
13
+ end
14
+ end
15
+
16
+ class SimpleTestUseCase2
17
+ include ActionLogic::ActionUseCase
18
+
19
+ def call
20
+ end
21
+
22
+ def tasks
23
+ [UseCaseTestTask1,
24
+ UseCaseTestTask2]
25
+ end
26
+ end
27
+
28
+ class SimpleTestUseCase3
29
+ include ActionLogic::ActionUseCase
30
+
31
+ def call
32
+ context.second = "defined in use case"
33
+ end
34
+
35
+ def tasks
36
+ [UseCaseTestTask1]
37
+ end
38
+ end
39
+
40
+ class ValidateBeforeTestUseCase
41
+ include ActionLogic::ActionUseCase
42
+
43
+ validates_before Constants::ALL_VALIDATIONS
44
+
45
+ def call
46
+ end
47
+
48
+ def tasks
49
+ []
50
+ end
51
+ end
52
+
53
+ class ValidateBeforePresenceTestUseCase
54
+ include ActionLogic::ActionUseCase
55
+
56
+ validates_before Constants::PRESENCE_VALIDATION
57
+
58
+ def call
59
+ end
60
+
61
+ def tasks
62
+ []
63
+ end
64
+ end
65
+
66
+ class ValidateBeforeCustomPresenceTestUseCase
67
+ include ActionLogic::ActionUseCase
68
+
69
+ validates_before Constants::CUSTOM_PRESENCE_VALIDATION
70
+
71
+ def call
72
+ end
73
+
74
+ def tasks
75
+ []
76
+ end
77
+ end
78
+
79
+ class ValidateBeforeCustomTypeTestUseCase
80
+ include ActionLogic::ActionUseCase
81
+
82
+ validates_before Constants::CUSTOM_TYPE_VALIDATION1
83
+
84
+ def call
85
+ end
86
+
87
+ def tasks
88
+ []
89
+ end
90
+ end
91
+
92
+ class ValidateBeforeUnrecognizablePresenceTestUseCase
93
+ include ActionLogic::ActionUseCase
94
+
95
+ validates_before :integer_test => { :presence => :true }
96
+
97
+ def call
98
+ end
99
+
100
+ def tasks
101
+ []
102
+ end
103
+ end
104
+
105
+ class ValidateAfterTestUseCase
106
+ include ActionLogic::ActionUseCase
107
+
108
+ validates_after Constants::ALL_VALIDATIONS
109
+
110
+ def call
111
+ context.integer_test = 1
112
+ context.float_test = 1.0
113
+ context.string_test = "string"
114
+ context.bool_test = false
115
+ context.hash_test = {}
116
+ context.array_test = []
117
+ context.symbol_test = :symbol
118
+ context.nil_test = nil
119
+ end
120
+
121
+ def tasks
122
+ []
123
+ end
124
+ end
125
+
126
+ class ValidateAfterMissingAttributesTestUseCase
127
+ include ActionLogic::ActionUseCase
128
+
129
+ validates_after Constants::ALL_VALIDATIONS
130
+
131
+ def call
132
+ end
133
+
134
+ def tasks
135
+ []
136
+ end
137
+ end
138
+
139
+ class ValidateAfterInvalidTypeTestUseCase
140
+ include ActionLogic::ActionUseCase
141
+
142
+ validates_after Constants::ALL_VALIDATIONS
143
+
144
+ def call
145
+ context.integer_test = nil
146
+ context.float_test = nil
147
+ context.string_test = nil
148
+ context.bool_test = nil
149
+ context.hash_test = nil
150
+ context.array_test = nil
151
+ context.symbol_test = nil
152
+ context.nil_test = 1
153
+ end
154
+
155
+ def tasks
156
+ []
157
+ end
158
+ end
159
+
160
+ class ValidateAfterCustomTypeTestUseCase
161
+ include ActionLogic::ActionUseCase
162
+
163
+ validates_after Constants::CUSTOM_TYPE_VALIDATION1
164
+
165
+ def call
166
+ context.custom_type = CustomType1.new
167
+ end
168
+
169
+ def tasks
170
+ []
171
+ end
172
+ end
173
+
174
+ class ValidateAfterInvalidCustomTypeTestUseCase
175
+ include ActionLogic::ActionUseCase
176
+
177
+ validates_after Constants::CUSTOM_TYPE_VALIDATION2
178
+
179
+ def call
180
+ context.custom_type = CustomType1.new
181
+ end
182
+
183
+ def tasks
184
+ []
185
+ end
186
+ end
187
+
188
+ class ValidateAfterPresenceTestUseCase
189
+ include ActionLogic::ActionUseCase
190
+
191
+ validates_after Constants::PRESENCE_VALIDATION
192
+
193
+ def call
194
+ context.integer_test = 1
195
+ end
196
+
197
+ def tasks
198
+ []
199
+ end
200
+ end
201
+
202
+ class ValidateAfterInvalidPresenceTestUseCase
203
+ include ActionLogic::ActionUseCase
204
+
205
+ validates_after Constants::PRESENCE_VALIDATION
206
+
207
+ def call
208
+ context.integer_test = nil
209
+ end
210
+
211
+ def tasks
212
+ []
213
+ end
214
+ end
215
+
216
+ class ValidateAfterCustomPresenceTestUseCase
217
+ include ActionLogic::ActionUseCase
218
+
219
+ validates_after Constants::CUSTOM_PRESENCE_VALIDATION
220
+
221
+ def call
222
+ context.array_test = [1]
223
+ end
224
+
225
+ def tasks
226
+ []
227
+ end
228
+ end
229
+
230
+ class ValidateAfterInvalidCustomPresenceTestUseCase
231
+ include ActionLogic::ActionUseCase
232
+
233
+ validates_after Constants::CUSTOM_PRESENCE_VALIDATION
234
+
235
+ def call
236
+ context.array_test = []
237
+ end
238
+
239
+ def tasks
240
+ []
241
+ end
242
+ end
243
+
244
+ class ValidateAfterUnrecognizablePresenceTestUseCase
245
+ include ActionLogic::ActionUseCase
246
+
247
+ validates_after :integer_test => { :presence => :true }
248
+
249
+ def call
250
+ context.integer_test = 1
251
+ end
252
+
253
+ def tasks
254
+ []
255
+ end
256
+ end
257
+
258
+ class FailureTestUseCase
259
+ include ActionLogic::ActionUseCase
260
+
261
+ def call
262
+ end
263
+
264
+ def tasks
265
+ [UseCaseTestTask1,
266
+ UseCaseTestTask2,
267
+ UseCaseFailureTestTask,
268
+ UseCaseTestTask3]
269
+ end
270
+ end
271
+
272
+ class HaltTestUseCase
273
+ include ActionLogic::ActionUseCase
274
+
275
+ def call
276
+ end
277
+
278
+ def tasks
279
+ [UseCaseTestTask1,
280
+ UseCaseTestTask2,
281
+ UseCaseHaltTestTask,
282
+ UseCaseTestTask3]
283
+ end
284
+ end
285
+
286
+ class UseCaseTestTask1
287
+ include ActionLogic::ActionTask
288
+
289
+ def call
290
+ context.first = "first"
291
+ end
292
+ end
293
+
294
+ class UseCaseTestTask2
295
+ include ActionLogic::ActionTask
296
+
297
+ def call
298
+ context.second = "second"
299
+ end
300
+ end
301
+
302
+ class UseCaseTestTask3
303
+ include ActionLogic::ActionTask
304
+
305
+ def call
306
+ context.third = "third"
307
+ end
308
+ end
309
+
310
+ class UseCaseFailureTestTask
311
+ include ActionLogic::ActionTask
312
+
313
+ def call
314
+ context.fail!(Constants::FAILURE_MESSAGE)
315
+ end
316
+ end
317
+
318
+ class UseCaseHaltTestTask
319
+ include ActionLogic::ActionTask
320
+
321
+ def call
322
+ context.halt!(Constants::HALT_MESSAGE)
323
+ end
324
+ end
@@ -0,0 +1,17 @@
1
+ require 'simplecov'
2
+ SimpleCov.start
3
+
4
+ require 'coveralls'
5
+ Coveralls.wear!
6
+
7
+ $LOAD_PATH << File.join(File.dirname(__FILE__), '..', 'lib')
8
+ $LOAD_PATH << File.join(File.dirname(__FILE__))
9
+
10
+ require 'action_logic'
11
+
12
+ RSpec.configure do |c|
13
+ #c.fail_fast = true
14
+ c.color = true
15
+ c.formatter = 'documentation'
16
+ c.order = 'rand'
17
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: action_logic
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rick Winfrey
@@ -72,7 +72,30 @@ executables: []
72
72
  extensions: []
73
73
  extra_rdoc_files: []
74
74
  files:
75
+ - ".gitignore"
76
+ - Gemfile
77
+ - Gemfile.lock
78
+ - README.md
79
+ - action_logic.gemspec
75
80
  - lib/action_logic.rb
81
+ - lib/action_logic/action_context.rb
82
+ - lib/action_logic/action_coordinator.rb
83
+ - lib/action_logic/action_core.rb
84
+ - lib/action_logic/action_task.rb
85
+ - lib/action_logic/action_use_case.rb
86
+ - lib/action_logic/action_validation.rb
87
+ - lib/action_logic/errors.rb
88
+ - lib/action_logic/version.rb
89
+ - spec/action_logic/action_context_spec.rb
90
+ - spec/action_logic/action_coordinator_spec.rb
91
+ - spec/action_logic/action_task_spec.rb
92
+ - spec/action_logic/active_use_case_spec.rb
93
+ - spec/fixtures/constants.rb
94
+ - spec/fixtures/coordinators.rb
95
+ - spec/fixtures/custom_types.rb
96
+ - spec/fixtures/tasks.rb
97
+ - spec/fixtures/use_cases.rb
98
+ - spec/spec_helper.rb
76
99
  homepage: https://github.com/rewinfrey/action_logic
77
100
  licenses:
78
101
  - MIT
@@ -97,4 +120,14 @@ rubygems_version: 2.4.5.1
97
120
  signing_key:
98
121
  specification_version: 4
99
122
  summary: Business logic abstraction
100
- test_files: []
123
+ test_files:
124
+ - spec/action_logic/action_context_spec.rb
125
+ - spec/action_logic/action_coordinator_spec.rb
126
+ - spec/action_logic/action_task_spec.rb
127
+ - spec/action_logic/active_use_case_spec.rb
128
+ - spec/fixtures/constants.rb
129
+ - spec/fixtures/coordinators.rb
130
+ - spec/fixtures/custom_types.rb
131
+ - spec/fixtures/tasks.rb
132
+ - spec/fixtures/use_cases.rb
133
+ - spec/spec_helper.rb