much-result 0.1.0 → 0.1.1
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/README.md +12 -0
- data/lib/much-result.rb +22 -2
- data/lib/much-result/transaction.rb +2 -0
- data/lib/much-result/version.rb +1 -1
- data/test/unit/much-result_tests.rb +30 -0
- data/test/unit/transaction_tests.rb +6 -0
- 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: 50f359b93392a57fb5a5706b9b127b6683b4d9bbff35414d6dd2f88e13c3fe92
|
4
|
+
data.tar.gz: 85bd060061eb19a84d5fbb44e64ff4512f1d0cafece8049880ffa76933314fd8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 704dc5d29a3d8000ec35fe54b92055e2e2e491b0c30169bc1218476fac0a8c7e5ba5e9d308f9afa06b3be72b636333250726c379340db241d59fe5e795c25987
|
7
|
+
data.tar.gz: afd00a2cd6dd19af02af0c05d280434057440b6a5c4f5de713936fcc3d185abb11d22407d3ee68afcd4a97a43ab381a97e0eafc77730ec005a6479a50dab45c4
|
data/README.md
CHANGED
@@ -210,6 +210,18 @@ result.get_for_all_failure_results(:description)
|
|
210
210
|
|
211
211
|
Note: MuchResult::Transactions are designed to delegate to their MuchResult. You can interact with a MuchResult::Transaction as if it were a MuchResult.
|
212
212
|
|
213
|
+
You can configure a default transaction receiver (e.g. `ActiveRecord::Base`) in an initializer. Doing so means if no receiver is passed to `MuchResult.transaction`, the default receiver will be used:
|
214
|
+
|
215
|
+
```ruby
|
216
|
+
# In an initializer or configuration script:
|
217
|
+
MuchResult.default_transaction_receiver = ActiveRecord::Base
|
218
|
+
|
219
|
+
# Since no receiver is passed, ActiveRecord::Base will be used:
|
220
|
+
MuchResult.transaction do |transaction|
|
221
|
+
# ...
|
222
|
+
end
|
223
|
+
```
|
224
|
+
|
213
225
|
## Installation
|
214
226
|
|
215
227
|
Add this line to your application's Gemfile:
|
data/lib/much-result.rb
CHANGED
@@ -35,8 +35,28 @@ class MuchResult
|
|
35
35
|
}
|
36
36
|
end
|
37
37
|
|
38
|
-
def self.transaction(receiver, backtrace: caller, **kargs, &block)
|
39
|
-
|
38
|
+
def self.transaction(receiver = nil, backtrace: caller, **kargs, &block)
|
39
|
+
if (transaction_receiver = receiver || default_transaction_receiver).nil?
|
40
|
+
raise(
|
41
|
+
ArgumentError,
|
42
|
+
"no receiver given and no default_transaction_receiver configured."
|
43
|
+
)
|
44
|
+
end
|
45
|
+
|
46
|
+
MuchResult::Transaction.(
|
47
|
+
receiver || default_transaction_receiver,
|
48
|
+
backtrace: backtrace,
|
49
|
+
**kargs,
|
50
|
+
&block
|
51
|
+
)
|
52
|
+
end
|
53
|
+
|
54
|
+
def self.default_transaction_receiver
|
55
|
+
@default_transaction_receiver
|
56
|
+
end
|
57
|
+
|
58
|
+
def self.default_transaction_receiver=(receiver)
|
59
|
+
@default_transaction_receiver = receiver
|
40
60
|
end
|
41
61
|
|
42
62
|
attr_reader :sub_results, :description, :backtrace
|
data/lib/much-result/version.rb
CHANGED
@@ -14,6 +14,7 @@ class MuchResult
|
|
14
14
|
let(:value1) { Factory.value }
|
15
15
|
|
16
16
|
should have_imeths :success, :failure, :for, :tap, :transaction
|
17
|
+
should have_accessors :default_transaction_receiver
|
17
18
|
|
18
19
|
should "build success instances" do
|
19
20
|
result = subject.success
|
@@ -113,6 +114,35 @@ class MuchResult
|
|
113
114
|
|
114
115
|
assert_that(result.sub_results.size).equals(1)
|
115
116
|
end
|
117
|
+
|
118
|
+
should "configure default transaction receivers" do
|
119
|
+
MuchStub.on_call(MuchResult::Transaction, :call) { |call|
|
120
|
+
@transaction_call = call
|
121
|
+
}
|
122
|
+
|
123
|
+
receiver1 = Factory.transaction_receiver
|
124
|
+
kargs1 = {
|
125
|
+
backtrace: Factory.backtrace,
|
126
|
+
value: value1
|
127
|
+
}
|
128
|
+
block1 = -> {}
|
129
|
+
|
130
|
+
assert_that(subject.default_transaction_receiver).is_nil
|
131
|
+
assert_that(-> {
|
132
|
+
subject.transaction(**kargs1, &block1)
|
133
|
+
}).raises(ArgumentError)
|
134
|
+
|
135
|
+
subject.default_transaction_receiver = receiver1
|
136
|
+
subject.transaction(**kargs1, &block1)
|
137
|
+
|
138
|
+
assert_that(subject.default_transaction_receiver).equals(receiver1)
|
139
|
+
assert_that(@transaction_call.pargs).equals([receiver1])
|
140
|
+
assert_that(@transaction_call.kargs).equals(kargs1)
|
141
|
+
assert_that(@transaction_call.block).equals(block1)
|
142
|
+
|
143
|
+
subject.default_transaction_receiver = nil
|
144
|
+
assert_that(subject.default_transaction_receiver).is_nil
|
145
|
+
end
|
116
146
|
end
|
117
147
|
|
118
148
|
class InitTests < UnitTests
|
@@ -45,6 +45,12 @@ class MuchResult::Transaction
|
|
45
45
|
|
46
46
|
should have_imeths :result, :call, :rollback, :halt
|
47
47
|
|
48
|
+
should "complain if given a nil receiver" do
|
49
|
+
assert_that(-> {
|
50
|
+
unit_class.new(nil, **kargs1)
|
51
|
+
}).raises(ArgumentError)
|
52
|
+
end
|
53
|
+
|
48
54
|
should "know its result" do
|
49
55
|
assert_that(subject.result).is_instance_of(MuchResult)
|
50
56
|
assert_that(subject.result.value).equals(value1)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: much-result
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kelly Redding
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2020-09-
|
12
|
+
date: 2020-09-10 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: assert
|