aasm 5.0.5 → 5.0.6

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
  SHA1:
3
- metadata.gz: 6e702f783991a9de8f199c63ef2872f9929cde73
4
- data.tar.gz: 9a1339c1f9e22d9bd7f00f6aabb493e303b1549e
3
+ metadata.gz: 51dfd1ad2a78034c409ddc556625e765260dd067
4
+ data.tar.gz: f934e43d4a35fc75a06d161190a8794e36066c02
5
5
  SHA512:
6
- metadata.gz: 7b34c93b3e939d6803fb3f7987ba2510fb33be577ac786140474d36305441829ea4b8318ee034dea4a005ed365d4d4930d6d9f3d4847902fdb77a1e85d5210e7
7
- data.tar.gz: 801b5dee037527de96cbf156eeebe6e92e216ce9bea97c9edf2bdd6e52790c66ff0e7186839afcb6d6a91ee3992028206f0b94089753380ba3d5701f68cb7312
6
+ metadata.gz: 983b08a4a0977c37dd73b77c5d80d014a05025d7f2841c26788518c82a8e738825ab9fa5fc8a36577e9c6a23fd33cf341c6fefc954630836e213ab40ee12c909
7
+ data.tar.gz: b091bca286362fb33a31f1b9705840f664ebd0a948c6b2dffbaa2436144c5931a04950080b18e16c1a7d9e4e1b8f517b7ea6c2c133259a3860905928fda32b90
@@ -0,0 +1,27 @@
1
+ ---
2
+ name: Bug report
3
+ about: Create a report to help us improve
4
+ title: ''
5
+ labels: ''
6
+ assignees: ''
7
+
8
+ ---
9
+
10
+ **Describe the bug**
11
+ A clear and concise description of what the bug is.
12
+
13
+ **To Reproduce**
14
+ Steps to reproduce the behavior:
15
+ 1. Go to '...'
16
+ 2. Click on '....'
17
+ 3. Scroll down to '....'
18
+ 4. See error
19
+
20
+ **Expected behavior**
21
+ A clear and concise description of what you expected to happen.
22
+
23
+ **Screenshots**
24
+ If applicable, add screenshots to help explain your problem.
25
+
26
+ **Additional context**
27
+ Add any other context about the problem here.
@@ -0,0 +1,20 @@
1
+ ---
2
+ name: Feature request
3
+ about: Suggest an idea for this project
4
+ title: ''
5
+ labels: ''
6
+ assignees: ''
7
+
8
+ ---
9
+
10
+ **Is your feature request related to a problem? Please describe.**
11
+ A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
12
+
13
+ **Describe the solution you'd like**
14
+ A clear and concise description of what you want to happen.
15
+
16
+ **Describe alternatives you've considered**
17
+ A clear and concise description of any alternative solutions or features you've considered.
18
+
19
+ **Additional context**
20
+ Add any other context or screenshots about the feature request here.
@@ -2,6 +2,9 @@ sudo: false
2
2
  language: ruby
3
3
  cache: bundler
4
4
 
5
+ jdk:
6
+ - openjdk8
7
+
5
8
  before_install:
6
9
  - rvm list
7
10
  - gem uninstall -v '>= 2' -i $(rvm gemdir)@global -ax bundler || true
@@ -17,17 +20,17 @@ services:
17
20
  - mongodb
18
21
  - redis-server
19
22
 
20
- addons:
21
- rethinkdb: '2.3.6'
23
+ #addons:
24
+ # rethinkdb: '2.3.4'
22
25
 
23
26
  gemfile:
24
27
  - gemfiles/norails.gemfile
25
28
  - gemfiles/rails_3.2.gemfile
26
29
  - gemfiles/rails_4.2.gemfile
27
30
  - gemfiles/rails_4.2_mongoid_5.gemfile
28
- - gemfiles/rails_4.2_nobrainer.gemfile
31
+ # - gemfiles/rails_4.2_nobrainer.gemfile
29
32
  - gemfiles/rails_5.0.gemfile
30
- - gemfiles/rails_5.0_nobrainer.gemfile
33
+ # - gemfiles/rails_5.0_nobrainer.gemfile
31
34
  - gemfiles/rails_5.1.gemfile
32
35
  - gemfiles/rails_5.2.gemfile
33
36
 
@@ -47,8 +50,8 @@ matrix:
47
50
  gemfile: gemfiles/norails.gemfile
48
51
  - rvm: 2.3.0
49
52
  gemfile: gemfiles/rails_5.0.gemfile
50
- - rvm: 2.3.0
51
- gemfile: gemfiles/rails_5.0_nobrainer.gemfile
53
+ # - rvm: 2.3.0
54
+ # gemfile: gemfiles/rails_5.0_nobrainer.gemfile
52
55
  - rvm: 2.3.0
53
56
  gemfile: gemfiles/rails_5.1.gemfile
54
57
  - rvm: 2.3.0
@@ -59,8 +62,8 @@ matrix:
59
62
  gemfile: gemfiles/rails_4.2.gemfile
60
63
  - rvm: 2.5.0
61
64
  gemfile: gemfiles/rails_4.2_mongoid_5.gemfile
62
- - rvm: 2.5.0
63
- gemfile: gemfiles/rails_4.2_nobrainer.gemfile
65
+ # - rvm: 2.5.0
66
+ # gemfile: gemfiles/rails_4.2_nobrainer.gemfile
64
67
  - rvm: jruby-9.1.12.0
65
68
  gemfile: gemfiles/norails.gemfile
66
69
  - rvm: jruby-9.1.12.0
@@ -69,10 +72,10 @@ matrix:
69
72
  gemfile: gemfiles/rails_5.1.gemfile
70
73
  - rvm: jruby-9.1.12.0
71
74
  gemfile: gemfiles/rails_5.2.gemfile
72
- - rvm: jruby-9.1.12.0
73
- gemfile: gemfiles/rails_4.2_nobrainer.gemfile
74
- - rvm: jruby-9.1.12.0
75
- gemfile: gemfiles/rails_5.0_nobrainer.gemfile
75
+ # - rvm: jruby-9.1.12.0
76
+ # gemfile: gemfiles/rails_4.2_nobrainer.gemfile
77
+ # - rvm: jruby-9.1.12.0
78
+ # gemfile: gemfiles/rails_5.0_nobrainer.gemfile
76
79
 
77
80
  notifications:
78
81
  slack:
@@ -2,6 +2,14 @@
2
2
 
3
3
  ## unreleased
4
4
 
5
+ ## 5.0.6
6
+
7
+ * Fix no_direct_assignment, couldn't be turned off pragmatically [#636](https://github.com/aasm/aasm/issues/636)
8
+ * Add instance level validation skip option [#644](https://github.com/aasm/aasm/pull/644), thanks to [Nitin-Salunke](https://github.com/Nitin-Salunke)
9
+ * Fixed aasm.current_event incorrectly yields nil when calling aasm.fire!(:event) [#551](https://github.com/aasm/aasm/issues/551) in [#638](https://github.com/aasm/aasm/pull/638), thanks to [DoubleJarvis](https://github.com/DoubleJarvis)
10
+ * Code Refactor [#634](https://github.com/aasm/aasm/pull/634) , thanks to [rahulknojha](https://github.com/rahulknojha)
11
+ * Fixed callback argument for :before_success & :success callback, [#630](https://github.com/aasm/aasm/pull/630)
12
+
5
13
  ## 5.0.5
6
14
 
7
15
  * Independent of ActiveSupport methods, [#627](https://github.com/aasm/aasm/pull/627),
data/Dockerfile CHANGED
@@ -1,9 +1,4 @@
1
- ARG RVM_RUBY_VERSIONS="2.4.0 2.5.0"
2
- ARG RVM_RUBY_DEFAULT="2.4.0"
3
- FROM msati/docker-rvm
4
-
5
- # After Ruby versions are installed we continue as non-root rvm user
6
- USER ${RVM_USER}
1
+ FROM ruby:2.3.4-slim
7
2
 
8
3
  LABEL maintainer="AASM"
9
4
 
data/README.md CHANGED
@@ -3,6 +3,7 @@
3
3
  [![Gem Version](https://badge.fury.io/rb/aasm.svg)](http://badge.fury.io/rb/aasm)
4
4
  [![Build Status](https://travis-ci.org/aasm/aasm.svg?branch=master)](https://travis-ci.org/aasm/aasm)
5
5
  [![Code Climate](https://codeclimate.com/github/aasm/aasm/badges/gpa.svg)](https://codeclimate.com/github/aasm/aasm)
6
+ [![codecov](https://codecov.io/gh/aasm/aasm/branch/master/graph/badge.svg)](https://codecov.io/gh/aasm/aasm)
6
7
 
7
8
  ## Index
8
9
  - [Upgrade from version 3 to 4](#upgrade-from-version-3-to-4)
@@ -29,6 +30,7 @@
29
30
  - [Transaction support](#transaction-support)
30
31
  - [Pessimistic Locking](#pessimistic-locking)
31
32
  - [Column name & migration](#column-name--migration)
33
+ - [Log State Changes](#log-state-changes)
32
34
  - [Inspection](#inspection)
33
35
  - [Warning output](#warning-output)
34
36
  - [RubyMotion support](#rubymotion-support)
@@ -214,13 +216,11 @@ Also, you can pass parameters to events:
214
216
 
215
217
  ```ruby
216
218
  job = Job.new
217
- job.run(:running, :defragmentation)
219
+ job.run(:defragmentation)
218
220
  ```
219
221
 
220
222
  In this case the `set_process` would be called with `:defragmentation` argument.
221
223
 
222
- Note that when passing arguments to a state transition, the first argument should be the desired end state. In the above example, we wish to transition to `:running` state and run the callback with `:defragmentation` argument. You can also omit or pass in `nil` as the desired end state, and AASM will try to transition to the first end state defined for that event.
223
-
224
224
  In case of an error during the event processing the error is rescued and passed to `:error`
225
225
  callback, which can handle it or re-raise it for further propagation.
226
226
 
@@ -741,6 +741,14 @@ class Job < ActiveRecord::Base
741
741
  end
742
742
  ```
743
743
 
744
+ Also You can skip the validation at instance level with `some_event_name_without_validation!` method.
745
+ With this you have the flexibility of having validation for all your transitions by default and then skip it wherever required.
746
+ Please note that only state column will be updated as mentioned in the above example.
747
+
748
+ ```ruby
749
+ job.run_without_validation!
750
+ ```
751
+
744
752
  If you want to make sure that the _AASM_ column for storing the state is not directly assigned,
745
753
  configure _AASM_ to not allow direct assignment, like this:
746
754
 
@@ -1082,6 +1090,13 @@ class AddJobState < ActiveRecord::Migration
1082
1090
  end
1083
1091
  ```
1084
1092
 
1093
+ ### Log State Changes
1094
+
1095
+ Logging state change can be done using [paper_trail](https://github.com/paper-trail-gem/paper_trail) gem
1096
+
1097
+ Example of implementation can be found here [https://github.com/nitsujri/aasm-papertrail-example](https://github.com/nitsujri/aasm-papertrail-example)
1098
+
1099
+
1085
1100
  ### Inspection
1086
1101
 
1087
1102
  AASM supports query methods for states and events
@@ -1193,7 +1208,7 @@ the 'instance method symbol / string' way whenever possible when defining guardi
1193
1208
  #### RSpec
1194
1209
 
1195
1210
  AASM provides some matchers for [RSpec](http://rspec.info):
1196
- *`transition_from`,
1211
+ * `transition_from`,
1197
1212
  * `have_state`, `allow_event`
1198
1213
  * and `allow_transition_to`.
1199
1214
 
@@ -23,6 +23,8 @@ Gem::Specification.new do |s|
23
23
  s.add_development_dependency 'rspec', ">= 3"
24
24
  s.add_development_dependency 'generator_spec'
25
25
  s.add_development_dependency 'appraisal'
26
+ s.add_development_dependency "simplecov"
27
+ s.add_development_dependency "codecov", ">= 0.1.10"
26
28
 
27
29
  # debugging
28
30
  # s.add_development_dependency 'debugger'
@@ -99,25 +99,10 @@ private
99
99
  begin
100
100
  old_state = aasm(state_machine_name).state_object_for_name(aasm(state_machine_name).current_state)
101
101
 
102
- event.fire_global_callbacks(
103
- :before_all_events,
104
- self,
105
- *process_args(event, aasm(state_machine_name).current_state, *args)
106
- )
107
-
108
- # new event before callback
109
- event.fire_callbacks(
110
- :before,
111
- self,
112
- *process_args(event, aasm(state_machine_name).current_state, *args)
113
- )
102
+ fire_default_callbacks(event, *process_args(event, aasm(state_machine_name).current_state, *args))
114
103
 
115
104
  if may_fire_to = event.may_fire?(self, *args)
116
- old_state.fire_callbacks(:before_exit, self,
117
- *process_args(event, aasm(state_machine_name).current_state, *args))
118
- old_state.fire_callbacks(:exit, self,
119
- *process_args(event, aasm(state_machine_name).current_state, *args))
120
-
105
+ fire_exit_callbacks(old_state, *process_args(event, aasm(state_machine_name).current_state, *args))
121
106
  if new_state_name = event.fire(self, {:may_fire => may_fire_to}, *args)
122
107
  aasm_fired(state_machine_name, event, old_state, new_state_name, options, *args, &block)
123
108
  else
@@ -137,25 +122,44 @@ private
137
122
  end
138
123
  end
139
124
 
125
+ def fire_default_callbacks(event, *processed_args)
126
+ event.fire_global_callbacks(
127
+ :before_all_events,
128
+ self,
129
+ *processed_args
130
+ )
131
+
132
+ # new event before callback
133
+ event.fire_callbacks(
134
+ :before,
135
+ self,
136
+ *processed_args
137
+ )
138
+ end
139
+
140
+ def fire_exit_callbacks(old_state, *processed_args)
141
+ old_state.fire_callbacks(:before_exit, self, *processed_args)
142
+ old_state.fire_callbacks(:exit, self, *processed_args)
143
+ end
144
+
140
145
  def aasm_fired(state_machine_name, event, old_state, new_state_name, options, *args)
141
146
  persist = options[:persist]
142
147
 
143
148
  new_state = aasm(state_machine_name).state_object_for_name(new_state_name)
149
+ callback_args = process_args(event, aasm(state_machine_name).current_state, *args)
144
150
 
145
- new_state.fire_callbacks(:before_enter, self,
146
- *process_args(event, aasm(state_machine_name).current_state, *args))
151
+ new_state.fire_callbacks(:before_enter, self, *callback_args)
147
152
 
148
- new_state.fire_callbacks(:enter, self,
149
- *process_args(event, aasm(state_machine_name).current_state, *args)) # TODO: remove for AASM 4?
153
+ new_state.fire_callbacks(:enter, self, *callback_args) # TODO: remove for AASM 4?
150
154
 
151
155
  persist_successful = true
152
156
  if persist
153
157
  persist_successful = aasm(state_machine_name).set_current_state_with_persistence(new_state_name)
154
158
  if persist_successful
155
159
  yield if block_given?
156
- event.fire_callbacks(:before_success, self)
160
+ event.fire_callbacks(:before_success, self, *callback_args)
157
161
  event.fire_transition_callbacks(self, *process_args(event, old_state.name, *args))
158
- event.fire_callbacks(:success, self)
162
+ event.fire_callbacks(:success, self, *callback_args)
159
163
  end
160
164
  else
161
165
  aasm(state_machine_name).current_state = new_state_name
@@ -168,10 +172,8 @@ private
168
172
  end
169
173
 
170
174
  if persist_successful
171
- old_state.fire_callbacks(:after_exit, self,
172
- *process_args(event, aasm(state_machine_name).current_state, *args))
173
- new_state.fire_callbacks(:after_enter, self,
174
- *process_args(event, aasm(state_machine_name).current_state, *args))
175
+ old_state.fire_callbacks(:after_exit, self, *callback_args)
176
+ new_state.fire_callbacks(:after_enter, self, *callback_args)
175
177
  event.fire_callbacks(
176
178
  :after,
177
179
  self,
@@ -59,6 +59,8 @@ module AASM
59
59
  @klass.send(:define_method, "#{@state_machine.config.column}=") do |state_name|
60
60
  if self.class.aasm(:"#{aasm_name}").state_machine.config.no_direct_assignment
61
61
  raise AASM::NoDirectAssignmentError.new('direct assignment of AASM column has been disabled (see AASM configuration for this class)')
62
+ else
63
+ super(state_name)
62
64
  end
63
65
  end
64
66
  end
@@ -133,6 +135,8 @@ module AASM
133
135
  aasm_fire_event(aasm_name, event, {:persist => false}, *args, &block)
134
136
  end
135
137
 
138
+ skip_instance_level_validation(event, name, aasm_name, klass)
139
+
136
140
  # Create aliases for the event methods. Keep the old names to maintain backwards compatibility.
137
141
  if namespace?
138
142
  klass.send(:alias_method, "may_#{name}_#{namespace}?", "may_#{name}?")
@@ -248,5 +252,20 @@ module AASM
248
252
  end
249
253
  end
250
254
 
255
+ def skip_instance_level_validation(event, name, aasm_name, klass)
256
+ # Overrides the skip_validation config for an instance (If skip validation is set to false in original config) and
257
+ # restores it back to the original value after the event is fired.
258
+ safely_define_method klass, "#{name}_without_validation!", ->(*args, &block) do
259
+ original_config = AASM::StateMachineStore.fetch(self.class, true).machine(aasm_name).config.skip_validation_on_save
260
+ begin
261
+ AASM::StateMachineStore.fetch(self.class, true).machine(aasm_name).config.skip_validation_on_save = true unless original_config
262
+ aasm(aasm_name).current_event = :"#{name}!"
263
+ aasm_fire_event(aasm_name, event, {:persist => true}, *args, &block)
264
+ ensure
265
+ AASM::StateMachineStore.fetch(self.class, true).machine(aasm_name).config.skip_validation_on_save = original_config
266
+ end
267
+ end
268
+ end
269
+
251
270
  end
252
271
  end
@@ -131,13 +131,13 @@ module AASM::Core
131
131
 
132
132
  if to_state == ::AASM::NO_VALUE
133
133
  to_state = nil
134
- elsif to_state.respond_to?(:to_sym) && transitions.map(&:to).flatten.include?(to_state.to_sym)
135
- # nop, to_state is a valid to-state
136
- else
134
+ elsif !(to_state.respond_to?(:to_sym) && transitions.map(&:to).flatten.include?(to_state.to_sym))
137
135
  # to_state is an argument
138
136
  args.unshift(to_state)
139
137
  to_state = nil
140
138
  end
139
+
140
+ # nop, to_state is a valid to-state
141
141
 
142
142
  transitions.each do |transition|
143
143
  next if to_state and !Array(transition.to).include?(to_state)
@@ -91,7 +91,7 @@ module AASM
91
91
  when Proc
92
92
  state.call(@instance)
93
93
  else
94
- raise NotImplementedError, "Unrecognized state-type given. Expected Symbol, String, or Proc."
94
+ raise NotImplementedError, "Unrecognized state-type given. Expected Symbol, String, or Proc."
95
95
  end
96
96
  end
97
97
 
@@ -104,11 +104,12 @@ module AASM
104
104
  end
105
105
 
106
106
  def fire(event_name, *args, &block)
107
- @instance.send(:aasm_fire_event, @name, event_name, {persist: false}, *args, &block)
107
+ @instance.send(event_name, *args, &block)
108
108
  end
109
109
 
110
110
  def fire!(event_name, *args, &block)
111
- @instance.send(:aasm_fire_event, @name, event_name, {persist: true}, *args, &block)
111
+ event_name = event_name.to_s.+("!").to_sym
112
+ @instance.send(event_name, *args, &block)
112
113
  end
113
114
 
114
115
  def set_current_state_with_persistence(state)
@@ -1,3 +1,3 @@
1
1
  module AASM
2
- VERSION = "5.0.5"
2
+ VERSION = "5.0.6"
3
3
  end
@@ -51,4 +51,9 @@ ActiveRecord::Migration.suppress_messages do
51
51
  t.string "search"
52
52
  t.string "sync"
53
53
  end
54
+
55
+ ActiveRecord::Migration.create_table "instance_level_skip_validation_examples", :force => true do |t|
56
+ t.string "state"
57
+ t.string "some_string"
58
+ end
54
59
  end
@@ -0,0 +1,19 @@
1
+ class InstanceLevelSkipValidationExample < ActiveRecord::Base
2
+ include AASM
3
+
4
+ aasm :state do
5
+ state :new, :initial => true
6
+ state :draft
7
+ state :complete
8
+
9
+ event :set_draft do
10
+ transitions from: :new, to: :draft
11
+ end
12
+
13
+ event :complete do
14
+ transitions from: %i[draft new], to: :complete
15
+ end
16
+ end
17
+
18
+ validates :some_string, presence: true
19
+ end
@@ -8,7 +8,7 @@ module Callbacks
8
8
  state :closed
9
9
  state :out_to_lunch
10
10
 
11
- event :close, :before => :before_method, :after => :after_method do
11
+ event :close, :before => :before_method, :after => :after_method, :before_success => :before_success_method, :success => :success_method3 do
12
12
  transitions :to => :closed, :from => [:open], :after => :transition_method, :success => :success_method
13
13
  transitions :to => :out_to_lunch, :from => [:open], :after => :transition_method2, :success => :success_method2
14
14
  end
@@ -16,6 +16,8 @@ module Callbacks
16
16
 
17
17
  def before_method(arg); end
18
18
 
19
+ def before_success_method(arg); end
20
+
19
21
  def after_method(arg); end
20
22
 
21
23
  def transition_method(arg); end
@@ -26,5 +28,7 @@ module Callbacks
26
28
 
27
29
  def success_method2(arg); end
28
30
 
31
+ def success_method3(arg); end
32
+
29
33
  end
30
34
  end
@@ -8,7 +8,7 @@ module Callbacks
8
8
  state :closed
9
9
  state :out_to_lunch
10
10
 
11
- event :close, :before => :before_method, :after => :after_method do
11
+ event :close, :before => :before_method, :after => :after_method, :before_success => :before_success_method, :success => :success_method do
12
12
  transitions :to => :closed, :from => [:open], :after => :transition_method
13
13
  transitions :to => :out_to_lunch, :from => [:open], :after => :transition_method2
14
14
  end
@@ -16,11 +16,14 @@ module Callbacks
16
16
 
17
17
  def before_method(arg); end
18
18
 
19
+ def before_success_method(arg); end
20
+
19
21
  def after_method(arg); end
20
22
 
21
23
  def transition_method(arg); end
22
24
 
23
25
  def transition_method2(arg); end
24
26
 
27
+ def success_method(arg); end
25
28
  end
26
29
  end
@@ -1,3 +1,13 @@
1
+ require 'simplecov'
2
+ SimpleCov.start do
3
+ add_filter '/spec/'
4
+ end
5
+
6
+ if ENV['CI'] == 'true'
7
+ require 'codecov'
8
+ SimpleCov.formatter = SimpleCov::Formatter::Codecov
9
+ end
10
+
1
11
  $LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__)))
2
12
  $LOAD_PATH.unshift(File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib')))
3
13
  require 'aasm'
@@ -154,6 +154,8 @@ describe 'callbacks for the new DSL' do
154
154
  expect(cb).to receive(:before_method).with(:arg1).once.ordered
155
155
  expect(cb).to receive(:transition_method).never
156
156
  expect(cb).to receive(:transition_method2).with(:arg1).once.ordered
157
+ expect(cb).to receive(:before_success_method).with(:arg1).once.ordered
158
+ expect(cb).to receive(:success_method).with(:arg1).once.ordered
157
159
  expect(cb).to receive(:after_method).with(:arg1).once.ordered
158
160
  cb.close!(:out_to_lunch, :arg1)
159
161
 
@@ -161,6 +163,8 @@ describe 'callbacks for the new DSL' do
161
163
  some_object = double('some object')
162
164
  expect(cb).to receive(:before_method).with(some_object).once.ordered
163
165
  expect(cb).to receive(:transition_method2).with(some_object).once.ordered
166
+ expect(cb).to receive(:before_success_method).with(some_object).once.ordered
167
+ expect(cb).to receive(:success_method).with(some_object).once.ordered
164
168
  expect(cb).to receive(:after_method).with(some_object).once.ordered
165
169
  cb.close!(:out_to_lunch, some_object)
166
170
  end
@@ -315,7 +315,9 @@ describe 'callbacks for the new DSL' do
315
315
  expect(cb).to receive(:before_method).with(:arg1).once.ordered
316
316
  expect(cb).to receive(:transition_method).with(:arg1).once.ordered
317
317
  expect(cb).to receive(:transition_method).never
318
+ expect(cb).to receive(:before_success_method).with(:arg1).once.ordered
318
319
  expect(cb).to receive(:success_method).with(:arg1).once.ordered
320
+ expect(cb).to receive(:success_method3).with(:arg1).once.ordered
319
321
  expect(cb).to receive(:success_method).never
320
322
  expect(cb).to receive(:after_method).with(:arg1).once.ordered
321
323
  cb.close!(:arg1)
@@ -325,7 +327,9 @@ describe 'callbacks for the new DSL' do
325
327
  expect(cb).to receive(:before_method).with(some_object).once.ordered
326
328
  expect(cb).to receive(:transition_method).with(some_object).once.ordered
327
329
  expect(cb).to receive(:transition_method).never
330
+ expect(cb).to receive(:before_success_method).with(some_object).once.ordered
328
331
  expect(cb).to receive(:success_method).with(some_object).once.ordered
332
+ expect(cb).to receive(:success_method3).with(some_object).once.ordered
329
333
  expect(cb).to receive(:success_method).never
330
334
  expect(cb).to receive(:after_method).with(some_object).once.ordered
331
335
  cb.close!(some_object)
@@ -90,5 +90,4 @@ describe 'when being unsuspended' do
90
90
  it "should not be able to fire unknown events" do
91
91
  expect(auth.aasm.may_fire_event?(:unknown)).to be false
92
92
  end
93
-
94
93
  end
@@ -294,6 +294,19 @@ describe 'current event' do
294
294
  pe.wakeup!
295
295
  expect(pe.aasm.current_event).to eql :wakeup!
296
296
  end
297
+
298
+ describe "when calling events with fire/fire!" do
299
+ it "fire should populate aasm.current_event and transition (sleeping to showering)" do
300
+ pe.aasm.fire(:wakeup)
301
+ expect(pe.aasm.current_event).to eq :wakeup
302
+ expect(pe.aasm.current_state).to eq :showering
303
+ end
304
+ it "fire! should populate aasm.current_event and transition (sleeping to showering)" do
305
+ pe.aasm.fire!(:wakeup)
306
+ expect(pe.aasm.current_event).to eq :wakeup!
307
+ expect(pe.aasm.current_state).to eq :showering
308
+ end
309
+ end
297
310
  end
298
311
 
299
312
  describe 'parametrised events' do
@@ -359,13 +359,13 @@ if defined?(ActiveRecord)
359
359
 
360
360
  # allow it temporarily
361
361
  MultipleNoDirectAssignment.aasm(:left).state_machine.config.no_direct_assignment = false
362
- obj.aasm_state = :pending
363
- expect(obj.aasm_state.to_sym).to eql :pending
362
+ obj.aasm_state = :running
363
+ expect(obj.aasm_state.to_sym).to eql :running
364
364
 
365
365
  # and forbid it again
366
366
  MultipleNoDirectAssignment.aasm(:left).state_machine.config.no_direct_assignment = true
367
- expect {obj.aasm_state = :running}.to raise_error(AASM::NoDirectAssignmentError)
368
- expect(obj.aasm_state.to_sym).to eql :pending
367
+ expect {obj.aasm_state = :pending}.to raise_error(AASM::NoDirectAssignmentError)
368
+ expect(obj.aasm_state.to_sym).to eql :running
369
369
  end
370
370
  end # direct assignment
371
371
 
@@ -393,13 +393,13 @@ if defined?(ActiveRecord)
393
393
 
394
394
  # allow it temporarily
395
395
  NoDirectAssignment.aasm.state_machine.config.no_direct_assignment = false
396
- obj.aasm_state = :pending
397
- expect(obj.aasm_state.to_sym).to eql :pending
396
+ obj.aasm_state = :running
397
+ expect(obj.aasm_state.to_sym).to eql :running
398
398
 
399
399
  # and forbid it again
400
400
  NoDirectAssignment.aasm.state_machine.config.no_direct_assignment = true
401
- expect {obj.aasm_state = :running}.to raise_error(AASM::NoDirectAssignmentError)
402
- expect(obj.aasm_state.to_sym).to eql :pending
401
+ expect {obj.aasm_state = :pending}.to raise_error(AASM::NoDirectAssignmentError)
402
+ expect(obj.aasm_state.to_sym).to eql :running
403
403
  end
404
404
  end # direct assignment
405
405
 
@@ -748,4 +748,26 @@ if defined?(ActiveRecord)
748
748
  expect { job.run }.to raise_error(AASM::InvalidTransition)
749
749
  end
750
750
  end
751
+
752
+ describe 'testing the instance_level skip validation with _without_validation method' do
753
+ let(:example) do
754
+ obj = InstanceLevelSkipValidationExample.new(state: 'new')
755
+ obj.save(validate: false)
756
+ obj
757
+ end
758
+
759
+ it 'should be able to change the state with invalid record' do
760
+ expect(example.valid?).to be_falsey
761
+ expect(example.complete!).to be_falsey
762
+ expect(example.complete_without_validation!).to be_truthy
763
+ expect(example.state).to eq('complete')
764
+ end
765
+
766
+ it 'shouldn\'t affect the behaviour of existing method after calling _without_validation! method' do
767
+ expect(example.set_draft!).to be_falsey
768
+ expect(example.set_draft_without_validation!).to be_truthy
769
+ expect(example.state).to eq('draft')
770
+ expect(example.complete!).to be_falsey
771
+ end
772
+ end
751
773
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aasm
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.0.5
4
+ version: 5.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thorsten Boettger
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2019-05-17 00:00:00.000000000 Z
12
+ date: 2019-09-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: concurrent-ruby
@@ -95,6 +95,34 @@ dependencies:
95
95
  - - ">="
96
96
  - !ruby/object:Gem::Version
97
97
  version: '0'
98
+ - !ruby/object:Gem::Dependency
99
+ name: simplecov
100
+ requirement: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ type: :development
106
+ prerelease: false
107
+ version_requirements: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ - !ruby/object:Gem::Dependency
113
+ name: codecov
114
+ requirement: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ version: 0.1.10
119
+ type: :development
120
+ prerelease: false
121
+ version_requirements: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - ">="
124
+ - !ruby/object:Gem::Version
125
+ version: 0.1.10
98
126
  - !ruby/object:Gem::Dependency
99
127
  name: pry
100
128
  requirement: !ruby/object:Gem::Requirement
@@ -117,6 +145,8 @@ extensions: []
117
145
  extra_rdoc_files: []
118
146
  files:
119
147
  - ".document"
148
+ - ".github/ISSUE_TEMPLATE/bug_report.md"
149
+ - ".github/ISSUE_TEMPLATE/feature_request.md"
120
150
  - ".gitignore"
121
151
  - ".travis.yml"
122
152
  - API
@@ -207,6 +237,7 @@ files:
207
237
  - spec/models/active_record/derivate_new_dsl.rb
208
238
  - spec/models/active_record/false_state.rb
209
239
  - spec/models/active_record/gate.rb
240
+ - spec/models/active_record/instance_level_skip_validation_example.rb
210
241
  - spec/models/active_record/invalid_persistor.rb
211
242
  - spec/models/active_record/localizer_test_model.rb
212
243
  - spec/models/active_record/no_direct_assignment.rb
@@ -410,6 +441,7 @@ test_files:
410
441
  - spec/models/active_record/derivate_new_dsl.rb
411
442
  - spec/models/active_record/false_state.rb
412
443
  - spec/models/active_record/gate.rb
444
+ - spec/models/active_record/instance_level_skip_validation_example.rb
413
445
  - spec/models/active_record/invalid_persistor.rb
414
446
  - spec/models/active_record/localizer_test_model.rb
415
447
  - spec/models/active_record/no_direct_assignment.rb