granite 0.9.0 → 0.9.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 +5 -5
- data/lib/granite/action/performing.rb +1 -0
- data/lib/granite/action/policies.rb +1 -0
- data/lib/granite/action/preconditions/base_precondition.rb +1 -0
- data/lib/granite/action/preconditions/embedded_precondition.rb +1 -0
- data/lib/granite/action/transaction_manager.rb +6 -4
- data/lib/granite/represents/attribute.rb +2 -0
- data/lib/granite/rspec/satisfy_preconditions.rb +11 -8
- data/lib/granite/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: bbe5e30c9b3c74f9a703caf9d9a30c6ea0791aaad7b159f8f5e12dd58d1b62d3
|
4
|
+
data.tar.gz: 5c6751169deb310e651cdeace4ac9612419892f13ec7188b06eee4385bc5f4ba
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c7cf2f66caafc82d058cc9e89404828733fbe5f7798de7016bff4a002454f2275f730e936cd48861e5080d582989be13a411484ee0d12dfd3ed65e5f993aabb0
|
7
|
+
data.tar.gz: 32530f64d500262d218909f28ce3d27d1845baba024e853b4041a9780b33b87d05824cd0ba32cbde5c12d1f44978e3dc615f448be3c1a6dc3e02c70df3045c9d
|
@@ -33,6 +33,7 @@ module Granite
|
|
33
33
|
|
34
34
|
def decline_action(context, action)
|
35
35
|
return if action.satisfy_preconditions?
|
36
|
+
|
36
37
|
action.errors[:base].each { |error| context.errors.add(:base, error) }
|
37
38
|
action.failed_preconditions.each { |error| context.failed_preconditions << error }
|
38
39
|
end
|
@@ -51,15 +51,17 @@ module Granite
|
|
51
51
|
end
|
52
52
|
|
53
53
|
def finish_root_transaction
|
54
|
-
|
55
|
-
|
54
|
+
callbacks = transactions_stack.callbacks
|
55
|
+
|
56
56
|
self.transactions_stack = nil
|
57
|
+
|
58
|
+
trigger_after_commit_callbacks(callbacks)
|
57
59
|
end
|
58
60
|
|
59
|
-
def trigger_after_commit_callbacks
|
61
|
+
def trigger_after_commit_callbacks(callbacks)
|
60
62
|
collected_errors = []
|
61
63
|
|
62
|
-
|
64
|
+
callbacks.reverse_each do |callback|
|
63
65
|
begin
|
64
66
|
callback.respond_to?(:run_callbacks) ? callback.run_callbacks(:commit) : callback.call
|
65
67
|
rescue StandardError => e
|
@@ -12,6 +12,7 @@ module Granite
|
|
12
12
|
|
13
13
|
def sync
|
14
14
|
return if reference.nil?
|
15
|
+
|
15
16
|
reference.public_send(writer, read)
|
16
17
|
end
|
17
18
|
|
@@ -23,6 +24,7 @@ module Granite
|
|
23
24
|
|
24
25
|
def type
|
25
26
|
return reflection.options[:type] if reflection.options[:type].present?
|
27
|
+
|
26
28
|
active_data_type || type_from_type_for_attribute || super
|
27
29
|
end
|
28
30
|
|
@@ -3,7 +3,7 @@
|
|
3
3
|
# Checks if business action satisfies preconditions in current state.
|
4
4
|
#
|
5
5
|
# Modifiers:
|
6
|
-
# * `with_message(message)` (and `with_messages(
|
6
|
+
# * `with_message(message)` (and `with_messages(list, of, messages)`) --
|
7
7
|
# only for negated matchers, checks messages of preconditions not satisfied;
|
8
8
|
# * `with_message_of_kind(:message_kind)` (and `with_messages_of_kinds(:list, :of, :messages)`) --
|
9
9
|
# only for negated matchers, checks messages of preconditions not satisfied;
|
@@ -17,6 +17,7 @@
|
|
17
17
|
# # assuming subject is business action
|
18
18
|
# it { is_expected.to satisfy_preconditions }
|
19
19
|
# it { is_expected.not_to satisfy_preconditions.with_message('Tax form has not been signed') }
|
20
|
+
# it { is_expected.not_to satisfy_preconditions.with_messages(/^Tax form has not been signed by/', 'Signature required') }
|
20
21
|
# it { is_expected.not_to satisfy_preconditions.with_message_of_kind(:relevant_portfolio_items_needed) }
|
21
22
|
# it { is_expected.not_to satisfy_preconditions.with_messages_of_kinds(:relevant_portfolio_items_needed, :relevant_education_needed) }
|
22
23
|
# ```
|
@@ -26,8 +27,8 @@ RSpec::Matchers.define :satisfy_preconditions do
|
|
26
27
|
@expected_messages = [message]
|
27
28
|
end
|
28
29
|
|
29
|
-
chain(:with_messages) do
|
30
|
-
@expected_messages = messages
|
30
|
+
chain(:with_messages) do |*messages|
|
31
|
+
@expected_messages = messages.flatten
|
31
32
|
end
|
32
33
|
|
33
34
|
chain(:with_message_of_kind) do |kind|
|
@@ -44,6 +45,7 @@ RSpec::Matchers.define :satisfy_preconditions do
|
|
44
45
|
|
45
46
|
match do |object|
|
46
47
|
fail '"with_messages" method chain is not supported for positive matcher' if @expected_messages
|
48
|
+
|
47
49
|
object.satisfy_preconditions?
|
48
50
|
end
|
49
51
|
|
@@ -51,11 +53,12 @@ RSpec::Matchers.define :satisfy_preconditions do
|
|
51
53
|
result = !object.satisfy_preconditions?
|
52
54
|
if @expected_messages
|
53
55
|
errors = object.errors[:base]
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
56
|
+
|
57
|
+
result &&= @expected_messages.all? { |expected| errors.any? { |error| error.match? expected } }
|
58
|
+
|
59
|
+
if @exactly
|
60
|
+
result &&= errors.none? { |error| @expected_messages.none? { |expected| error.match? expected } }
|
61
|
+
end
|
59
62
|
elsif @expected_kind_of_messages
|
60
63
|
error_kinds = object.errors.details[:base].map(&:values).flatten
|
61
64
|
result &&= (@expected_kind_of_messages - error_kinds).empty?
|
data/lib/granite/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: granite
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Arkadiy Zabazhanov & friends
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-11-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: actionpack
|
@@ -351,7 +351,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
351
351
|
version: '0'
|
352
352
|
requirements: []
|
353
353
|
rubyforge_project:
|
354
|
-
rubygems_version: 2.6
|
354
|
+
rubygems_version: 2.7.6
|
355
355
|
signing_key:
|
356
356
|
specification_version: 4
|
357
357
|
summary: Another business actions architecture for Rails apps
|