use_cases 0.2.5 → 0.3.2

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
  SHA256:
3
- metadata.gz: cf8f3d237d63199c6af9da931fa275833b6cadf3378548d95208f7aa11bc7a49
4
- data.tar.gz: bc428dd162cfa152966ffb1eae6273796649baa4f8a702fe43887ce05fab26c6
3
+ metadata.gz: 86bb76e93659c9a0512a573bb45ea5c1a4c905bcbbf8df35c6144f687c4f75d0
4
+ data.tar.gz: b52e54fd5535dc623f1627f38afd6904448bbe01cd6a5c77570c456e15aa105e
5
5
  SHA512:
6
- metadata.gz: 3fef9fde7da990fd80b02754bc2f63d5550fdbb856044dd9ee8a4bdb392be814807d3ff345b5c5cae609572b10b00c57512b3b37bc3cc8812fb989726a706570
7
- data.tar.gz: 1c5acb9f5f82918d6f79eed927d346f0bd165bb66dd3e0b6f673d8419bc34faa6b991d8066df7080ebdaf75170801c0363cacb4d6463305131e1d520bb4afbc5
6
+ metadata.gz: f359f8ceddc2bc4de7379565e3e69ac0444f85d343e17d9b80d8fb7665db575f963a7dcd57df0e6be37e0b718e61c142e1661f07b917b580a6c9b192f16d58b6
7
+ data.tar.gz: d2085d518a685ea7d3edb1491cb629f691f33d8e9e637ddc3adf463b6f997263cf08b5bc8b307e960a2dc59abf2b8b3cb2a96c0c12d0cfe131fe9d89549d484e
@@ -2,30 +2,62 @@
2
2
 
3
3
  require "rspec"
4
4
 
5
- RSpec::Matchers.define(:fail_with_code) do |expected_code|
5
+ RSpec::Matchers.define(:be_failure_with_code) do |expected_code|
6
6
  match do |test_subject|
7
7
  expect(test_subject.failure?).to be true
8
- expect(test_subject.failure.first).to eq expected_code
8
+ expect(test_subject.failure.first).to eql expected_code
9
+ end
10
+
11
+ failure_message do |test_subject|
12
+ if text_subject.failure?
13
+ "the use case was expected to fail with code #{expected_code} but it returned #{test_subject.failure.first}"
14
+ else
15
+ "the use case was expected to fail with code #{expected_code} but it did not fail"
16
+ end
9
17
  end
10
18
  end
11
19
 
12
- RSpec::Matchers.define(:fail_with_payload) do |expected_result|
20
+ RSpec::Matchers.define(:be_failure_with_payload) do |expected_result|
13
21
  match do |test_subject|
14
22
  expect(test_subject.failure?).to be true
15
- expect(test_subject.failure.last).to eq expected_result
23
+ expect(test_subject.failure.last).to eql expected_result
16
24
  end
25
+
26
+ failure_message do |test_subject|
27
+ if test_subject.failure?
28
+ "the use case was expected to fail with #{expected_result.inspect} but it returned #{test_subject.failure.last.inspect}"
29
+ else
30
+ "the use case was expected to fail but it succeeded with #{test_subject.success.inspect}"
31
+ end
32
+ end
17
33
  end
18
34
 
19
- RSpec::Matchers.define(:fail_with) do |*expected_failure|
35
+ RSpec::Matchers.define(:be_failure_with) do |*expected_failure|
20
36
  match do |test_subject|
21
37
  expect(test_subject.failure?).to be true
22
- expect(test_subject.failure).to eq expected_failure
38
+ expect(test_subject.failure).to eql expected_failure
23
39
  end
40
+
41
+ failure_message do |test_subject|
42
+ if test_subject.failure?
43
+ "the use case was expected to fail with #{expected_result.inspect} but it returned #{test_subject.failure.inspect}"
44
+ else
45
+ "the use case was expected to fail but it succeeded with #{test_subject.success.inspect}"
46
+ end
47
+ end
24
48
  end
25
49
 
26
- RSpec::Matchers.define(:succeed_with) do |expected_result|
50
+ RSpec::Matchers.define(:be_successful_with) do |expected_result|
27
51
  match do |test_subject|
28
52
  expect(test_subject.success?).to be true
29
- expect(test_subject.success).to eq expected_result
53
+ expect(test_subject.success).to eql expected_result
30
54
  end
55
+
56
+ failure_message do |test_subject|
57
+ if test_subject.success?
58
+ "the use case was expected to succeed with #{expected_result.inspect} but it returned #{test_subject.success.inspect}"
59
+ else
60
+ "the use case was expected to succeed but it failed with #{test_subject.failure.inspect}"
61
+ end
62
+ end
31
63
  end
@@ -14,20 +14,25 @@ module UseCases
14
14
  end
15
15
 
16
16
  def deserialize_step_arguments(args)
17
- args.map { |arg| arg.is_a?(Hash) && arg.delete("_serialized_by_use_case") ? arg.deserialize : arg }
17
+ args.map do |arg|
18
+ if arg.is_a?(Hash) && arg.delete("_serialized_by_use_case")
19
+ arg.delete('_class').constantize.new(arg)
20
+ else
21
+ arg
22
+ end
23
+ end
18
24
  end
19
25
 
20
26
  def self.serialize_step_arguments(args)
21
- args.select.with_index do |arg, index|
27
+ args.select.map.with_index do |arg, index|
22
28
  ActiveJob::Arguments.send(:serialize_argument, arg)
23
-
24
29
  rescue ActiveJob::SerializationError => _e
25
- arg.serialize.merge("_serialized_by_use_case" => true)
26
-
30
+ arg.serialize.merge("_serialized_by_use_case" => true, "_class" => arg.class.name)
27
31
  rescue NoMethodError => _e
28
- puts "[WARNING] #{arg.class} (index = #{index})" \
32
+ puts "[WARNING] #{arg} of class (#{arg.clas}) (index = #{index})" \
29
33
  "is not serializable and does not repond to #serialize and will be ignored."
30
- false
34
+ else
35
+ arg
31
36
  end
32
37
  end
33
38
  end
@@ -9,13 +9,13 @@ module UseCases
9
9
 
10
10
  def do_call(*args)
11
11
  result = super(*args)
12
- prev_result = previous_step_result.value
12
+
13
13
  raise InvalidReturnValue, "The return value should not be a Monad." if result.is_a?(Dry::Monads::Result)
14
14
 
15
15
  failure_code = options[:failure] || :check_failure
16
16
  failure_message = options[:failure_message] || "Failed"
17
17
 
18
- result ? Success(prev_result) : Failure([failure_code, failure_message])
18
+ result ? Success(args.first) : Failure([failure_code, failure_message])
19
19
  end
20
20
  end
21
21
  end
@@ -6,7 +6,7 @@ module UseCases
6
6
  def do_call(*base_args)
7
7
  args = [object.class.name, name.to_s, *base_args]
8
8
  args = ::UseCases::StepActiveJobAdapter.serialize_step_arguments(args)
9
-
9
+ byebug
10
10
  job_options = options.slice(:queue, :wait, :wait_until, :priority)
11
11
 
12
12
  ::UseCases::StepActiveJobAdapter.set(job_options).perform_later(*args)
@@ -9,11 +9,9 @@ module UseCases
9
9
 
10
10
  def do_call(*args)
11
11
  result = super(*args)
12
- rescue StandardError => _e
13
12
  raise InvalidReturnValue, "For a tee step, a Monad will have no effect." if result.is_a?(Dry::Monads::Result)
14
13
 
15
- prev_result = previous_step_result.value
16
- Success(prev_result)
14
+ Success(args.first)
17
15
  end
18
16
  end
19
17
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module UseCases
4
- VERSION = "0.2.5"
4
+ VERSION = "0.3.2"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: use_cases
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.5
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ring Twice
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-10-20 00:00:00.000000000 Z
11
+ date: 2021-10-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport