light-service 0.3.4 → 0.3.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 713a827193e2ac90169a99251cbb9d9745ed4394
4
- data.tar.gz: 91400a943609efb9e0a811437b73d30faf1090cb
3
+ metadata.gz: c74e129f4aa196c42077e14704239de1e3cdafec
4
+ data.tar.gz: 47f5b3dd133c2ceec5b66ecf513a9dbd78559708
5
5
  SHA512:
6
- metadata.gz: 4ceecbf3154d271ead7dfb8105dc38100589b0e0158943c3994a1f1649b30b9e5d65725b7d3416311b1975b5a8a5a0a181a2c26e4843689637b88a873d2792a3
7
- data.tar.gz: 6f44c67e69cd032a46320d75ab6a7188f3d177e090207abdcbed34a1db984b914367d2ba6a9eeb3aaa881d3f4e9f91a59207323993db8984d7024b754ab387bc
6
+ metadata.gz: 496f22c177d5b14d0ba7d33fb6b54700e1a150e6a8683d29be30b7ec0304b24fb9daa8adac00f934c6b1f956e94d0330d020014a18450cbf89b98751b184f7f6
7
+ data.tar.gz: 24f9965dcf22ec98ed9ebb9a3083111cce43f30e438d607ccecf2d7290ee1a61c0a6e400f935ea318708b883c0eefc56bd87c86dcf94bfb6830af7021f6e91bd
data/.rspec CHANGED
@@ -1,2 +1,3 @@
1
1
  --color
2
2
  --format progress
3
+ --order rand
data/README.md CHANGED
@@ -273,12 +273,16 @@ For further examples, please visit the project's [Wiki](https://github.com/adomo
273
273
  Huge thanks to the [contributors](https://github.com/adomokos/light-service/graphs/contributors)!
274
274
 
275
275
  ## Release Notes
276
+ ### 0.3.5
277
+ * remove previously deprecated method Context#context_hash
278
+ * [Skipping](https://github.com/adomokos/light-service/commit/d2bd05455a7e4f78aa448db1ea1d692f7b8b67d3) the promised keys check in the context when the context is in failure state
279
+
276
280
  ### 0.3.4
277
281
  * The method call `with` is [now optional](https://github.com/adomokos/light-service/blob/master/spec/organizer_spec.rb#L18) in case you have nothing to put into the context.
278
282
  * Action name is being displayed in the error message when the expected or promised key is not in the context.
279
283
 
280
284
  ### 0.3.3
281
- * Switching the promises and expects keys accessors from Action to Context
285
+ * Switching the promises and expects key accessors from Action to Context
282
286
 
283
287
  ### 0.3.2
284
288
  * Fixing documentation and using separate arguments instead of a hash when setting the context to failure with error code
@@ -28,14 +28,14 @@ module LightService
28
28
  return action_context if action_context.stop_processing?
29
29
  action = self
30
30
 
31
- ContextKeyVerifier.verify_expected_keys_are_in_context(action_context, action)
31
+ Context::KeyVerifier.verify_expected_keys_are_in_context(action_context, action)
32
32
 
33
33
  action_context.define_accessor_methods_for_keys(expected_keys)
34
34
  action_context.define_accessor_methods_for_keys(promised_keys)
35
35
 
36
36
  yield(action_context)
37
37
 
38
- ContextKeyVerifier.verify_promised_keys_are_in_context(action_context, action)
38
+ Context::KeyVerifier.verify_promised_keys_are_in_context(action_context, action)
39
39
  end
40
40
  end
41
41
 
@@ -26,13 +26,6 @@ module LightService
26
26
  self.merge! values
27
27
  end
28
28
 
29
- # It's really there for testing and debugging
30
- # Deprecated: Please use `to_hash` instead
31
- def context_hash
32
- warn 'DEPRECATED: Please use `to_hash` instead'
33
- self.dup
34
- end
35
-
36
29
  def success?
37
30
  @outcome == ::LightService::Outcomes::SUCCESS
38
31
  end
@@ -2,35 +2,39 @@ module LightService
2
2
  class ExpectedKeysNotInContextError < StandardError; end
3
3
  class PromisedKeysNotInContextError < StandardError; end
4
4
 
5
- class ContextKeyVerifier
6
- class << self
7
- def verify_expected_keys_are_in_context(context, action)
8
- verify_keys_are_in_context(context, action.expected_keys) do |not_found_keys|
9
- fail ExpectedKeysNotInContextError, "expected #{format_keys(not_found_keys)} to be in the context during #{action.to_s}"
5
+ class Context
6
+ class KeyVerifier
7
+ class << self
8
+ def verify_expected_keys_are_in_context(context, action)
9
+ verify_keys_are_in_context(context, action.expected_keys) do |not_found_keys|
10
+ fail ExpectedKeysNotInContextError, "expected #{format_keys(not_found_keys)} to be in the context during #{action}"
11
+ end
10
12
  end
11
- end
12
13
 
13
- def verify_promised_keys_are_in_context(context, action)
14
- verify_keys_are_in_context(context, action.promised_keys) do |not_found_keys|
15
- fail PromisedKeysNotInContextError, "promised #{format_keys(not_found_keys)} to be in the context during #{action.to_s}"
14
+ def verify_promised_keys_are_in_context(context, action)
15
+ return context if context.failure?
16
+
17
+ verify_keys_are_in_context(context, action.promised_keys) do |not_found_keys|
18
+ fail PromisedKeysNotInContextError, "promised #{format_keys(not_found_keys)} to be in the context during #{action}"
19
+ end
16
20
  end
17
- end
18
21
 
19
- private
22
+ private
20
23
 
21
- def verify_keys_are_in_context(context, keys)
22
- keys ||= context.keys
24
+ def verify_keys_are_in_context(context, keys)
25
+ keys ||= context.keys
23
26
 
24
- not_found_keys = keys - context.keys
25
- unless not_found_keys.empty?
26
- yield not_found_keys
27
- end
27
+ not_found_keys = keys - context.keys
28
+ unless not_found_keys.empty?
29
+ yield not_found_keys
30
+ end
28
31
 
29
- context
30
- end
32
+ context
33
+ end
31
34
 
32
- def format_keys(keys)
33
- keys.map { |k| ":#{k}"}.join(', ')
35
+ def format_keys(keys)
36
+ keys.map { |k| ":#{k}"}.join(', ')
37
+ end
34
38
  end
35
39
  end
36
40
  end
@@ -1,3 +1,3 @@
1
1
  module LightService
2
- VERSION = "0.3.4"
2
+ VERSION = "0.3.5"
3
3
  end
@@ -5,52 +5,62 @@ module LightService
5
5
  class DummyActionForKeysToPromise
6
6
  include LightService::Action
7
7
  expects :tea, :milk
8
- promises :milk_tea, :something_else
8
+ promises :milk_tea
9
9
 
10
- executed do |context|
11
- context[:some_tea] = "#{context.tea} - #{context.milk}"
12
- end
13
10
  end
14
11
 
15
12
  context "when the promised key is not in the context" do
16
13
  it "raises an ArgumentError" do
17
- exception_error_text = "promised :milk_tea, :something_else to be in the context during LightService::DummyActionForKeysToPromise"
14
+ class DummyActionForKeysToPromise
15
+ executed do |context|
16
+ context[:some_tea] = "#{context.tea} - #{context.milk}"
17
+ end
18
+ end
19
+
20
+ exception_error_text = "promised :milk_tea to be in the context during LightService::DummyActionForKeysToPromise"
18
21
  expect {
19
22
  DummyActionForKeysToPromise.execute(:tea => "black", :milk => "full cream")
20
23
  }.to raise_error(PromisedKeysNotInContextError, exception_error_text)
21
24
  end
22
- end
23
25
 
24
- context "when the promised key is in the context" do
25
- class DummyActionSetsItemInContext
26
- include LightService::Action
27
- expects :tea, :milk
28
- promises :milk_tea
29
-
30
- executed do |context|
31
- context.milk_tea = "#{context.tea} - #{context.milk}"
32
- context.milk_tea += " hello"
26
+ it "fails the context without fulfilling its promise" do
27
+ class DummyActionForKeysToPromise
28
+ executed do |context|
29
+ context.fail!("Sorry, something bad has happened.")
30
+ end
33
31
  end
32
+
33
+ result_context = DummyActionForKeysToPromise.execute(:tea => "black",
34
+ :milk => "full cream")
35
+
36
+ expect(result_context).to be_failure
37
+ expect(result_context.keys).not_to include(:milk_tea)
34
38
  end
39
+ end
40
+
41
+ context "when the promised key is in the context" do
35
42
  it "sets in the context if it was set with not nil" do
36
- result_context = DummyActionSetsItemInContext.execute(:tea => "black",
43
+ class DummyActionForKeysToPromise
44
+ executed do |context|
45
+ context.milk_tea = "#{context.tea} - #{context.milk}"
46
+ context.milk_tea += " hello"
47
+ end
48
+ end
49
+
50
+ result_context = DummyActionForKeysToPromise.execute(:tea => "black",
37
51
  :milk => "full cream")
38
52
  expect(result_context).to be_success
39
53
  expect(result_context[:milk_tea]).to eq("black - full cream hello")
40
54
  end
41
55
 
42
- class DummyActionNilNotSetInContext
43
- include LightService::Action
44
- expects :tea, :milk
45
- promises :milk_tea
46
-
47
- executed do |context|
48
- context.milk_tea = nil
49
- end
50
- end
51
56
  it "sets in the context if it was set with nil" do
52
- result_context = DummyActionNilNotSetInContext.execute(:tea => "black",
53
- :milk => "full cream")
57
+ class DummyActionForKeysToPromise
58
+ executed do |context|
59
+ context.milk_tea = nil
60
+ end
61
+ end
62
+ result_context = DummyActionForKeysToPromise.execute(:tea => "black",
63
+ :milk => "full cream")
54
64
  expect(result_context).to be_success
55
65
  expect(result_context[:milk_tea]).to be_nil
56
66
  end
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.3.4
4
+ version: 0.3.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Attila Domokos
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-10 00:00:00.000000000 Z
11
+ date: 2014-06-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec