granite 0.9.0 → 0.9.1

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
- SHA1:
3
- metadata.gz: 5d965fa31280c0c7068dec41cd034c2242444690
4
- data.tar.gz: 22680daf024cf9d8956715e40c75ce2d3ad4cf93
2
+ SHA256:
3
+ metadata.gz: bbe5e30c9b3c74f9a703caf9d9a30c6ea0791aaad7b159f8f5e12dd58d1b62d3
4
+ data.tar.gz: 5c6751169deb310e651cdeace4ac9612419892f13ec7188b06eee4385bc5f4ba
5
5
  SHA512:
6
- metadata.gz: 3c92b2d9fb29164aa10c6b390686cdfca6830861eccaa8c85b6986996ee768fe0e34a7b6219ff4d6ae9a384d4d2cfd514a2896b248c9f01eff2af9bf0eef361b
7
- data.tar.gz: 0f5fed5af5c2d707a41e3de1d4d18695e464605e0cd31fbbe0526e23c982fc5a02f1ea5961a82367baf06119994006af76f343ae271129575f9f0fced2666d1f
6
+ metadata.gz: c7cf2f66caafc82d058cc9e89404828733fbe5f7798de7016bff4a002454f2275f730e936cd48861e5080d582989be13a411484ee0d12dfd3ed65e5f993aabb0
7
+ data.tar.gz: 32530f64d500262d218909f28ce3d27d1845baba024e853b4041a9780b33b87d05824cd0ba32cbde5c12d1f44978e3dc615f448be3c1a6dc3e02c70df3045c9d
@@ -75,6 +75,7 @@ module Granite
75
75
  # @raise [NotImplementedError] execute_perform! method was not defined yet
76
76
  def try_perform!(context: nil, **options)
77
77
  return unless satisfy_preconditions?
78
+
78
79
  transaction do
79
80
  validate!(context)
80
81
  perform_action!(**options)
@@ -85,6 +85,7 @@ module Granite
85
85
  #
86
86
  def authorize!
87
87
  fail Granite::Action::NotAllowedError, self unless allowed?
88
+
88
89
  self
89
90
  end
90
91
  end
@@ -11,6 +11,7 @@ module Granite
11
11
  def execute!(context)
12
12
  return if @options[:if] && !context.instance_exec(&@options[:if])
13
13
  return if @options[:unless] && context.instance_exec(&@options[:unless])
14
+
14
15
  _execute(context)
15
16
  end
16
17
 
@@ -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
- trigger_after_commit_callbacks
55
- ensure
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
- transactions_stack.callbacks.reverse_each do |callback|
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([list, of, 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 |messages|
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
- result &&= if @exactly
55
- errors.to_a.sort == @expected_messages.sort
56
- else
57
- (@expected_messages - errors).empty?
58
- end
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?
@@ -1,3 +1,3 @@
1
1
  module Granite
2
- VERSION = '0.9.0'.freeze
2
+ VERSION = '0.9.1'.freeze
3
3
  end
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.0
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-09-18 00:00:00.000000000 Z
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.14
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