use_cases 0.2.5 → 0.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/use_cases/rspec/matchers.rb +40 -8
- data/lib/use_cases/step_active_job_adapter.rb +12 -7
- data/lib/use_cases/step_adapters/check.rb +2 -2
- data/lib/use_cases/step_adapters/enqueue.rb +1 -1
- data/lib/use_cases/step_adapters/tee.rb +1 -3
- data/lib/use_cases/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 86bb76e93659c9a0512a573bb45ea5c1a4c905bcbbf8df35c6144f687c4f75d0
|
4
|
+
data.tar.gz: b52e54fd5535dc623f1627f38afd6904448bbe01cd6a5c77570c456e15aa105e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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(:
|
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
|
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(:
|
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
|
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(:
|
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
|
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(:
|
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
|
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
|
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.
|
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
|
-
|
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
|
-
|
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(
|
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
|
-
|
16
|
-
Success(prev_result)
|
14
|
+
Success(args.first)
|
17
15
|
end
|
18
16
|
end
|
19
17
|
end
|
data/lib/use_cases/version.rb
CHANGED
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
|
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-
|
11
|
+
date: 2021-10-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|