light-service 0.15.0 → 0.18.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/project-build.yml +28 -0
  3. data/.rubocop.yml +117 -3
  4. data/.travis.yml +3 -8
  5. data/README.md +89 -37
  6. data/RELEASES.md +18 -1
  7. data/lib/generators/light_service/generator_utils.rb +0 -2
  8. data/lib/light-service/action.rb +61 -4
  9. data/lib/light-service/context/key_verifier.rb +22 -3
  10. data/lib/light-service/context.rb +10 -12
  11. data/lib/light-service/errors.rb +5 -0
  12. data/lib/light-service/orchestrator.rb +1 -1
  13. data/lib/light-service/organizer/reduce_case.rb +48 -0
  14. data/lib/light-service/organizer/reduce_if_else.rb +21 -0
  15. data/lib/light-service/organizer/with_reducer.rb +11 -14
  16. data/lib/light-service/organizer/with_reducer_log_decorator.rb +2 -2
  17. data/lib/light-service/organizer.rb +20 -3
  18. data/lib/light-service/testing/context_factory.rb +2 -0
  19. data/lib/light-service/version.rb +1 -1
  20. data/lib/light-service.rb +2 -0
  21. data/light-service.gemspec +3 -2
  22. data/spec/acceptance/after_actions_spec.rb +17 -6
  23. data/spec/acceptance/around_each_spec.rb +15 -0
  24. data/spec/acceptance/before_actions_spec.rb +3 -9
  25. data/spec/acceptance/log_from_organizer_spec.rb +1 -1
  26. data/spec/acceptance/organizer/add_to_context_spec.rb +27 -0
  27. data/spec/acceptance/organizer/execute_with_add_to_context_spec.rb +28 -0
  28. data/spec/acceptance/organizer/reduce_case_spec.rb +53 -0
  29. data/spec/acceptance/organizer/reduce_if_else_spec.rb +60 -0
  30. data/spec/acceptance/organizer/reduce_if_spec.rb +2 -0
  31. data/spec/action_optional_expected_keys_spec.rb +82 -0
  32. data/spec/context/inspect_spec.rb +5 -21
  33. data/spec/context_spec.rb +1 -1
  34. data/spec/lib/generators/action_generator_advanced_spec.rb +1 -1
  35. data/spec/lib/generators/action_generator_simple_spec.rb +1 -1
  36. data/spec/lib/generators/organizer_generator_advanced_spec.rb +1 -1
  37. data/spec/lib/generators/organizer_generator_simple_spec.rb +1 -1
  38. data/spec/sample/calculates_tax_spec.rb +0 -1
  39. data/spec/sample/looks_up_tax_percentage_action_spec.rb +3 -1
  40. data/spec/test_doubles.rb +48 -5
  41. metadata +22 -13
  42. data/gemfiles/activesupport_4.gemfile +0 -7
  43. data/resources/orchestrators_deprecated.svg +0 -10
@@ -0,0 +1,82 @@
1
+ require 'spec_helper'
2
+ require 'test_doubles'
3
+
4
+ describe ":expects macro using defaults" do
5
+ context "when all expected keys are supplied" do
6
+ it "is expected to ignore default values" do
7
+ outcome = TestDoubles::AddsNumbersWithOptionalDefaults.execute(
8
+ :first_number => 3,
9
+ :second_number => 5,
10
+ :third_number => 7
11
+ )
12
+
13
+ expect(outcome.total).to eq 15
14
+ end
15
+ end
16
+
17
+ context "when defaults are supplied" do
18
+ it "is expected to use static values" do
19
+ outcome = TestDoubles::AddsNumbersWithOptionalDefaults.execute(
20
+ :first_number => 3,
21
+ :second_number => 7
22
+ )
23
+
24
+ expect(outcome.total).to eq 20
25
+ end
26
+
27
+ it "is expected to use dynamic values" do
28
+ outcome = TestDoubles::AddsNumbersWithOptionalDefaults.execute(
29
+ :first_number => 3,
30
+ :third_number => 5
31
+ )
32
+
33
+ expect(outcome.total).to eq 18
34
+ end
35
+
36
+ it "is expected to process defaults in their defined order" do
37
+ outcome = TestDoubles::AddsNumbersWithOptionalDefaults.execute(
38
+ :third_number => 5,
39
+ :first_number => 3
40
+ )
41
+
42
+ expect(outcome.total).to eq 18
43
+ end
44
+
45
+ it "is expected to use all defaults if required" do
46
+ outcome = TestDoubles::AddsNumbersWithOptionalDefaults.execute(
47
+ :first_number => 3
48
+ )
49
+
50
+ expect(outcome.total).to eq 23
51
+ end
52
+ end
53
+
54
+ context "when used within an organizer" do
55
+ it "is expected to process required defaults" do
56
+ outcome = TestDoubles::OrganizerWithActionsUsingDefaults.call
57
+
58
+ expect(outcome.total).to eq 20
59
+ end
60
+ end
61
+
62
+ context "when defaults are misconfigured" do
63
+ it "is expected to raise an exception" do
64
+ expect do
65
+ # Needs to be specified in the block
66
+ # as error is raised at define time
67
+ class AddsNumbersWithIncorrectDefaults
68
+ extend LightService::Action
69
+
70
+ expects :first, :default => 10 # This one is fine. Other two arent
71
+ expects :second, :defalut => ->(ctx) { ctx[:first] + 7 }
72
+ expects :third, :deafult => 10
73
+ promises :total
74
+
75
+ executed do |ctx|
76
+ ctx.total = ctx.first + ctx.second + ctx.third
77
+ end
78
+ end
79
+ end.to raise_error(LightService::UnusableExpectKeyDefaultError)
80
+ end
81
+ end
82
+ end
@@ -13,13 +13,7 @@ RSpec.describe LightService::Context do
13
13
  describe '#inspect' do
14
14
  it 'inspects the hash with all the fields' do
15
15
  inspected_context =
16
- 'LightService::Context({}, ' \
17
- + 'success: true, ' \
18
- + 'message: \'\', ' \
19
- + 'error_code: nil, ' \
20
- + 'skip_remaining: false, ' \
21
- + 'aliases: {}' \
22
- + ')'
16
+ "LightService::Context({}, success: true, message: '', error_code: nil, skip_remaining: false, aliases: {})"
23
17
 
24
18
  expect(context.inspect).to eq(inspected_context)
25
19
  end
@@ -28,13 +22,8 @@ RSpec.describe LightService::Context do
28
22
  context.fail!('There was an error')
29
23
 
30
24
  inspected_context =
31
- 'LightService::Context({}, ' \
32
- + 'success: false, ' \
33
- + 'message: \'There was an error\', ' \
34
- + 'error_code: nil, ' \
35
- + 'skip_remaining: false, ' \
36
- + 'aliases: {}' \
37
- + ')'
25
+ "LightService::Context({}, success: false, message: 'There was an error', error_code: nil, " \
26
+ "skip_remaining: false, aliases: {})"
38
27
 
39
28
  expect(context.inspect).to eq(inspected_context)
40
29
  end
@@ -43,13 +32,8 @@ RSpec.describe LightService::Context do
43
32
  context.skip_remaining!('No need to process')
44
33
 
45
34
  inspected_context =
46
- 'LightService::Context({}, ' \
47
- + 'success: true, ' \
48
- + 'message: \'No need to process\', ' \
49
- + 'error_code: nil, ' \
50
- + 'skip_remaining: true, ' \
51
- + 'aliases: {}' \
52
- + ')'
35
+ "LightService::Context({}, success: true, message: 'No need to process', error_code: nil, " \
36
+ "skip_remaining: true, aliases: {})"
53
37
 
54
38
  expect(context.inspect).to eq(inspected_context)
55
39
  end
data/spec/context_spec.rb CHANGED
@@ -167,7 +167,7 @@ RSpec.describe LightService::Context do
167
167
  end
168
168
 
169
169
  it "allows a default block value for #fetch" do
170
- expect(context.fetch(:madeup) { :default }).to eq(:default)
170
+ expect(context.fetch(:madeup, :default)).to eq(:default)
171
171
  end
172
172
 
173
173
  context "when aliases are included via .make" do
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- require_relative '../../../lib/generators/light_service/action_generator.rb'
3
+ require_relative '../../../lib/generators/light_service/action_generator'
4
4
  require_relative './full_generator_test_blobs'
5
5
 
6
6
  describe LightService::Generators::ActionGenerator, :type => :generator do
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- require_relative '../../../lib/generators/light_service/action_generator.rb'
3
+ require_relative '../../../lib/generators/light_service/action_generator'
4
4
  require_relative './full_generator_test_blobs'
5
5
 
6
6
  describe LightService::Generators::ActionGenerator, :type => :generator do
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- require_relative '../../../lib/generators/light_service/organizer_generator.rb'
3
+ require_relative '../../../lib/generators/light_service/organizer_generator'
4
4
  require_relative './full_generator_test_blobs'
5
5
 
6
6
  describe LightService::Generators::OrganizerGenerator, :type => :generator do
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- require_relative '../../../lib/generators/light_service/organizer_generator.rb'
3
+ require_relative '../../../lib/generators/light_service/organizer_generator'
4
4
  require_relative './full_generator_test_blobs'
5
5
 
6
6
  describe LightService::Generators::OrganizerGenerator, :type => :generator do
@@ -10,7 +10,6 @@ describe CalculatesTax do
10
10
 
11
11
  it "calls the actions in order" do
12
12
  allow(LightService::Context).to receive(:make)
13
- .with(:order => order)
14
13
  .and_return(ctx)
15
14
 
16
15
  allow(LooksUpTaxPercentageAction).to receive(:execute)
@@ -1,7 +1,9 @@
1
1
  require 'spec_helper'
2
2
  require_relative 'tax/looks_up_tax_percentage_action'
3
3
 
4
- class TaxRange; end
4
+ class TaxRange
5
+ extend LightService::Action
6
+ end
5
7
 
6
8
  describe LooksUpTaxPercentageAction do
7
9
  let(:region) { double('region') }
data/spec/test_doubles.rb CHANGED
@@ -45,6 +45,7 @@ module TestDoubles
45
45
 
46
46
  class TestLogger
47
47
  attr_accessor :logs
48
+
48
49
  def initialize
49
50
  @logs = []
50
51
  end
@@ -74,6 +75,16 @@ module TestDoubles
74
75
  end
75
76
  end
76
77
 
78
+ class AroundEachWithReduceIfOrganizer
79
+ extend LightService::Organizer
80
+
81
+ def self.call(action_arguments)
82
+ with(action_arguments)
83
+ .around_each(AroundEachLoggerHandler)
84
+ .reduce(ReduceIfOrganizer.actions)
85
+ end
86
+ end
87
+
77
88
  class AddsTwoActionWithFetch
78
89
  extend LightService::Action
79
90
 
@@ -83,8 +94,13 @@ module TestDoubles
83
94
  end
84
95
  end
85
96
 
86
- class AnAction; end
87
- class AnotherAction; end
97
+ class AnAction
98
+ extend LightService::Action
99
+ end
100
+
101
+ class AnotherAction
102
+ extend LightService::Action
103
+ end
88
104
 
89
105
  class AnOrganizer
90
106
  extend LightService::Organizer
@@ -166,9 +182,7 @@ module TestDoubles
166
182
  promises :latte
167
183
 
168
184
  executed do |context|
169
- if context.milk == :very_hot
170
- context.fail!("Can't make a latte from a milk that's very hot!")
171
- end
185
+ context.fail!("Can't make a latte from a milk that's very hot!") if context.milk == :very_hot
172
186
 
173
187
  if context.milk == :super_hot
174
188
  error_message = "Can't make a latte from a milk that's super hot!"
@@ -478,7 +492,9 @@ module TestDoubles
478
492
  class NullAction
479
493
  extend LightService::Action
480
494
 
495
+ # rubocop:disable Lint/EmptyBlock
481
496
  executed { |_ctx| }
497
+ # rubocop:enable Lint/EmptyBlock
482
498
  end
483
499
 
484
500
  class TestIterate
@@ -566,6 +582,33 @@ module TestDoubles
566
582
  end
567
583
  end
568
584
 
585
+ class AddsNumbersWithOptionalDefaults
586
+ extend LightService::Action
587
+
588
+ expects :first_number
589
+ expects :second_number, :default => ->(ctx) { ctx[:first_number] + 7 }
590
+ expects :third_number, :default => 10
591
+ promises :total
592
+
593
+ executed do |ctx|
594
+ ctx.total = ctx.first_number + ctx.second_number + ctx.third_number
595
+ end
596
+ end
597
+
598
+ class OrganizerWithActionsUsingDefaults
599
+ extend LightService::Organizer
600
+ def self.call
601
+ with(:first_number => 1, :number => 1).reduce(actions)
602
+ end
603
+
604
+ def self.actions
605
+ [
606
+ AddsNumbersWithOptionalDefaults,
607
+ AddToTotalAction
608
+ ]
609
+ end
610
+ end
611
+
569
612
  class AnOrganizerThatAddsToContext
570
613
  extend LightService::Organizer
571
614
  def self.call
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: light-service
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.15.0
4
+ version: 0.18.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Attila Domokos
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-07-28 00:00:00.000000000 Z
11
+ date: 2022-04-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 3.0.0
19
+ version: 4.0.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: 3.0.0
26
+ version: 4.0.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: generator_spec
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -114,14 +114,14 @@ dependencies:
114
114
  requirements:
115
115
  - - "~>"
116
116
  - !ruby/object:Gem::Version
117
- version: 0.68.0
117
+ version: 1.26.0
118
118
  type: :development
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
122
  - - "~>"
123
123
  - !ruby/object:Gem::Version
124
- version: 0.68.0
124
+ version: 1.26.0
125
125
  - !ruby/object:Gem::Dependency
126
126
  name: rubocop-performance
127
127
  requirement: !ruby/object:Gem::Requirement
@@ -157,6 +157,7 @@ executables: []
157
157
  extensions: []
158
158
  extra_rdoc_files: []
159
159
  files:
160
+ - ".github/workflows/project-build.yml"
160
161
  - ".gitignore"
161
162
  - ".rspec"
162
163
  - ".rubocop.yml"
@@ -168,7 +169,6 @@ files:
168
169
  - README.md
169
170
  - RELEASES.md
170
171
  - Rakefile
171
- - gemfiles/activesupport_4.gemfile
172
172
  - gemfiles/activesupport_5.gemfile
173
173
  - gemfiles/activesupport_6.gemfile
174
174
  - lib/generators/light_service/action_generator.rb
@@ -189,7 +189,9 @@ files:
189
189
  - lib/light-service/organizer.rb
190
190
  - lib/light-service/organizer/execute.rb
191
191
  - lib/light-service/organizer/iterate.rb
192
+ - lib/light-service/organizer/reduce_case.rb
192
193
  - lib/light-service/organizer/reduce_if.rb
194
+ - lib/light-service/organizer/reduce_if_else.rb
193
195
  - lib/light-service/organizer/reduce_until.rb
194
196
  - lib/light-service/organizer/scoped_reducable.rb
195
197
  - lib/light-service/organizer/verify_call_method_exists.rb
@@ -203,7 +205,6 @@ files:
203
205
  - light-service.gemspec
204
206
  - resources/fail_actions.png
205
207
  - resources/light-service.png
206
- - resources/orchestrators_deprecated.svg
207
208
  - resources/organizer_and_actions.png
208
209
  - resources/skip_actions.png
209
210
  - spec/acceptance/add_numbers_spec.rb
@@ -228,7 +229,10 @@ files:
228
229
  - spec/acceptance/organizer/around_each_with_reduce_if_spec.rb
229
230
  - spec/acceptance/organizer/context_failure_and_skipping_spec.rb
230
231
  - spec/acceptance/organizer/execute_spec.rb
232
+ - spec/acceptance/organizer/execute_with_add_to_context_spec.rb
231
233
  - spec/acceptance/organizer/iterate_spec.rb
234
+ - spec/acceptance/organizer/reduce_case_spec.rb
235
+ - spec/acceptance/organizer/reduce_if_else_spec.rb
232
236
  - spec/acceptance/organizer/reduce_if_spec.rb
233
237
  - spec/acceptance/organizer/reduce_until_spec.rb
234
238
  - spec/acceptance/organizer/with_callback_spec.rb
@@ -237,6 +241,7 @@ files:
237
241
  - spec/acceptance/testing/context_factory_spec.rb
238
242
  - spec/action_expected_keys_spec.rb
239
243
  - spec/action_expects_and_promises_spec.rb
244
+ - spec/action_optional_expected_keys_spec.rb
240
245
  - spec/action_promised_keys_spec.rb
241
246
  - spec/action_spec.rb
242
247
  - spec/context/inspect_spec.rb
@@ -270,7 +275,7 @@ homepage: https://github.com/adomokos/light-service
270
275
  licenses:
271
276
  - MIT
272
277
  metadata: {}
273
- post_install_message:
278
+ post_install_message:
274
279
  rdoc_options: []
275
280
  require_paths:
276
281
  - lib
@@ -278,15 +283,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
278
283
  requirements:
279
284
  - - ">="
280
285
  - !ruby/object:Gem::Version
281
- version: '0'
286
+ version: 2.6.0
282
287
  required_rubygems_version: !ruby/object:Gem::Requirement
283
288
  requirements:
284
289
  - - ">="
285
290
  - !ruby/object:Gem::Version
286
291
  version: '0'
287
292
  requirements: []
288
- rubygems_version: 3.1.2
289
- signing_key:
293
+ rubygems_version: 3.3.12
294
+ signing_key:
290
295
  specification_version: 4
291
296
  summary: A service skeleton with an emphasis on simplicity
292
297
  test_files:
@@ -312,7 +317,10 @@ test_files:
312
317
  - spec/acceptance/organizer/around_each_with_reduce_if_spec.rb
313
318
  - spec/acceptance/organizer/context_failure_and_skipping_spec.rb
314
319
  - spec/acceptance/organizer/execute_spec.rb
320
+ - spec/acceptance/organizer/execute_with_add_to_context_spec.rb
315
321
  - spec/acceptance/organizer/iterate_spec.rb
322
+ - spec/acceptance/organizer/reduce_case_spec.rb
323
+ - spec/acceptance/organizer/reduce_if_else_spec.rb
316
324
  - spec/acceptance/organizer/reduce_if_spec.rb
317
325
  - spec/acceptance/organizer/reduce_until_spec.rb
318
326
  - spec/acceptance/organizer/with_callback_spec.rb
@@ -321,6 +329,7 @@ test_files:
321
329
  - spec/acceptance/testing/context_factory_spec.rb
322
330
  - spec/action_expected_keys_spec.rb
323
331
  - spec/action_expects_and_promises_spec.rb
332
+ - spec/action_optional_expected_keys_spec.rb
324
333
  - spec/action_promised_keys_spec.rb
325
334
  - spec/action_spec.rb
326
335
  - spec/context/inspect_spec.rb
@@ -1,7 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "activesupport", "~> 4.0"
6
-
7
- gemspec :path => "../"
@@ -1,10 +0,0 @@
1
- <?xml version="1.0" encoding="utf-8"?>
2
- <svg version="1.1"
3
- xmlns="http://www.w3.org/2000/svg"
4
- xmlns:xlink="http://www.w3.org/1999/xlink"
5
- width="350" height="20"
6
- >
7
- <text font-size="20" x="0" y="20" font-family="Verdana">
8
- <tspan fill="red">Orchestrators are DEPRECATED!</tspan>
9
- </text>
10
- </svg>