aasm 5.0.1 → 5.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +21 -6
- data/Appraisals +1 -11
- data/CHANGELOG.md +11 -0
- data/Dockerfile +6 -1
- data/Gemfile +1 -1
- data/README.md +28 -3
- data/gemfiles/rails_3.2.gemfile +2 -1
- data/gemfiles/rails_4.2.gemfile +1 -1
- data/gemfiles/rails_4.2_mongoid_5.gemfile +1 -1
- data/gemfiles/rails_4.2_nobrainer.gemfile +1 -1
- data/gemfiles/rails_5.0.gemfile +1 -1
- data/gemfiles/rails_5.0_nobrainer.gemfile +1 -1
- data/gemfiles/rails_5.1.gemfile +1 -1
- data/lib/aasm/core/event.rb +6 -1
- data/lib/aasm/errors.rb +2 -1
- data/lib/aasm/version.rb +1 -1
- data/lib/generators/aasm/orm_helpers.rb +6 -0
- data/lib/generators/active_record/aasm_generator.rb +3 -1
- data/spec/database.rb +4 -0
- data/spec/generators/active_record_generator_spec.rb +6 -0
- data/spec/models/active_record/work.rb +3 -0
- data/spec/unit/callbacks_spec.rb +26 -0
- metadata +4 -3
- data/gemfiles/rails_4.0.gemfile +0 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 972a54f67c50af93041d8c104cb61069ad8ae6f4
|
4
|
+
data.tar.gz: e4004fe73c08fdcf208afb45fa4e91904d2d97e0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3e2da17ffaa34ca4a299b3c9b7e7d8832c7fb09cfb07fbfe1315092fbea01cbdb4ee7b7ceca3847533b421a60db97c151b71a57a8c75f42c0e4627881ad5b9f0
|
7
|
+
data.tar.gz: f759c915e858f503d4b168c93b909aa497ba6ac4a3327ad51593dcbe44301e485166f76a5d09a4cd5c470c75cbb98b0085a675c2767e5267cfc0925ad32b777b
|
data/.travis.yml
CHANGED
@@ -2,9 +2,15 @@ sudo: false
|
|
2
2
|
language: ruby
|
3
3
|
cache: bundler
|
4
4
|
|
5
|
+
before_install:
|
6
|
+
- rvm list
|
7
|
+
- gem uninstall -v '>= 2' -i $(rvm gemdir)@global -ax bundler || true
|
8
|
+
- gem install bundler -v '1.16.1'
|
9
|
+
- bundle _1.16.1_ install
|
10
|
+
|
5
11
|
rvm:
|
6
|
-
- 2.
|
7
|
-
- 2.
|
12
|
+
- 2.3.0
|
13
|
+
- 2.5.0
|
8
14
|
- jruby-9.1.12.0
|
9
15
|
|
10
16
|
services:
|
@@ -16,7 +22,6 @@ addons:
|
|
16
22
|
|
17
23
|
gemfile:
|
18
24
|
- gemfiles/rails_3.2.gemfile
|
19
|
-
- gemfiles/rails_4.0.gemfile
|
20
25
|
- gemfiles/rails_4.2.gemfile
|
21
26
|
- gemfiles/rails_4.2_mongoid_5.gemfile
|
22
27
|
- gemfiles/rails_4.2_nobrainer.gemfile
|
@@ -36,10 +41,20 @@ script:
|
|
36
41
|
|
37
42
|
matrix:
|
38
43
|
exclude:
|
39
|
-
- rvm: 2.
|
40
|
-
gemfile: gemfiles/
|
41
|
-
- rvm: 2.3.
|
44
|
+
- rvm: 2.3.0
|
45
|
+
gemfile: gemfiles/rails_5.0.gemfile
|
46
|
+
- rvm: 2.3.0
|
47
|
+
gemfile: gemfiles/rails_5.0_nobrainer.gemfile
|
48
|
+
- rvm: 2.3.0
|
49
|
+
gemfile: gemfiles/rails_5.1.gemfile
|
50
|
+
- rvm: 2.5.0
|
42
51
|
gemfile: gemfiles/rails_3.2.gemfile
|
52
|
+
- rvm: 2.5.0
|
53
|
+
gemfile: gemfiles/rails_4.2.gemfile
|
54
|
+
- rvm: 2.5.0
|
55
|
+
gemfile: gemfiles/rails_4.2_mongoid_5.gemfile
|
56
|
+
- rvm: 2.5.0
|
57
|
+
gemfile: gemfiles/rails_4.2_nobrainer.gemfile
|
43
58
|
- rvm: jruby-9.1.12.0
|
44
59
|
gemfile: gemfiles/rails_5.0.gemfile
|
45
60
|
- rvm: jruby-9.1.12.0
|
data/Appraisals
CHANGED
@@ -4,17 +4,7 @@ appraise 'rails_3.2' do
|
|
4
4
|
gem 'sequel'
|
5
5
|
gem 'bson_ext', platforms: :ruby
|
6
6
|
gem 'test-unit', '~> 3.0'
|
7
|
-
gem '
|
8
|
-
end
|
9
|
-
|
10
|
-
appraise 'rails_4.0' do
|
11
|
-
gem 'mime-types', '~> 2', platforms: %i[ruby_19 jruby]
|
12
|
-
gem 'rails', '4.0.13'
|
13
|
-
gem 'mongoid', '~> 4.0'
|
14
|
-
gem 'sequel'
|
15
|
-
gem 'dynamoid', '~> 1', platforms: :ruby
|
16
|
-
gem 'aws-sdk', '~> 2', platforms: :ruby
|
17
|
-
gem 'redis-objects'
|
7
|
+
gem 'minitest'
|
18
8
|
gem 'activerecord-jdbcsqlite3-adapter', '1.3.24', platforms: :jruby
|
19
9
|
end
|
20
10
|
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,17 @@
|
|
2
2
|
|
3
3
|
## unreleased
|
4
4
|
|
5
|
+
## 5.0.2
|
6
|
+
|
7
|
+
* Clear failed callbacks, [#600](https://github.com/aasm/aasm/pull/600), thanks to
|
8
|
+
[nedgar](https://github.com/nedgar)
|
9
|
+
* README improvements, [#594](https://github.com/aasm/aasm/pull/594),
|
10
|
+
[#589](https://github.com/aasm/aasm/pull/589), [#587](https://github.com/aasm/aasm/pull/587),
|
11
|
+
[#597](https://github.com/aasm/aasm/pull/597), thanks to [jackscotti](https://github.com/jackscotti), [krmbzds](https://github.com/krmbzds),
|
12
|
+
[zegomesjf](https://github.com/zegomesjf), [BKSpurgeon](https://github.com/BKSpurgeon)
|
13
|
+
* Update InvalidTransition to include state_machine_name [#592](https://github.com/aasm/aasm/pull/592), thanks to [a14m](https://github.com/a14m)
|
14
|
+
* Do not add migration if model and column already exists [#586](https://github.com/aasm/aasm/pull/586), thanks to [KiranJosh](https://github.com/KiranJosh)
|
15
|
+
|
5
16
|
## 5.0.1
|
6
17
|
|
7
18
|
* Fix failures array in transition not being reset [#383](https://github.com/aasm/aasm/issues/383)
|
data/Dockerfile
CHANGED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -2,7 +2,6 @@
|
|
2
2
|
|
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
|
-
[![Dependency Status](https://gemnasium.com/aasm/aasm.svg)](https://gemnasium.com/aasm/aasm)
|
6
5
|
[![Code Climate](https://codeclimate.com/github/aasm/aasm/badges/gpa.svg)](https://codeclimate.com/github/aasm/aasm)
|
7
6
|
|
8
7
|
## Index
|
@@ -385,6 +384,21 @@ If you prefer a more Ruby-like guard syntax, you can use `if` and `unless` as we
|
|
385
384
|
end
|
386
385
|
```
|
387
386
|
|
387
|
+
You can invoke a Class instead a method since this Class responds to `call`
|
388
|
+
|
389
|
+
```ruby
|
390
|
+
event :sleep do
|
391
|
+
transitions :from => :running, :to => :sleeping, :guards => Dog
|
392
|
+
end
|
393
|
+
```
|
394
|
+
```ruby
|
395
|
+
class Dog
|
396
|
+
def call
|
397
|
+
cleaning_needed? && walked?
|
398
|
+
end
|
399
|
+
...
|
400
|
+
end
|
401
|
+
```
|
388
402
|
|
389
403
|
### Transitions
|
390
404
|
|
@@ -1178,7 +1192,15 @@ the 'instance method symbol / string' way whenever possible when defining guardi
|
|
1178
1192
|
|
1179
1193
|
#### RSpec
|
1180
1194
|
|
1181
|
-
AASM provides some matchers for [RSpec](http://rspec.info):
|
1195
|
+
AASM provides some matchers for [RSpec](http://rspec.info):
|
1196
|
+
*`transition_from`,
|
1197
|
+
* `have_state`, `allow_event`
|
1198
|
+
* and `allow_transition_to`.
|
1199
|
+
|
1200
|
+
##### Installation Instructions:
|
1201
|
+
* Add `require 'aasm/rspec'` to your `spec_helper.rb` file.
|
1202
|
+
|
1203
|
+
##### Examples Of Usage in Rspec:
|
1182
1204
|
|
1183
1205
|
```ruby
|
1184
1206
|
# classes with only the default state machine
|
@@ -1191,7 +1213,7 @@ expect(job).to allow_event :run
|
|
1191
1213
|
expect(job).to_not allow_event :clean
|
1192
1214
|
expect(job).to allow_transition_to(:running)
|
1193
1215
|
expect(job).to_not allow_transition_to(:cleaning)
|
1194
|
-
# on_event also accept arguments
|
1216
|
+
# on_event also accept multiple arguments
|
1195
1217
|
expect(job).to transition_from(:sleeping).to(:running).on_event(:run, :defragmentation)
|
1196
1218
|
|
1197
1219
|
# classes with multiple state machine
|
@@ -1225,6 +1247,9 @@ AASM provides assertions and rspec-like expectations for [Minitest](https://gith
|
|
1225
1247
|
|
1226
1248
|
List of supported assertions: `assert_have_state`, `refute_have_state`, `assert_transitions_from`, `refute_transitions_from`, `assert_event_allowed`, `refute_event_allowed`, `assert_transition_to_allowed`, `refute_transition_to_allowed`.
|
1227
1249
|
|
1250
|
+
|
1251
|
+
##### Examples Of Usage (Minitest):
|
1252
|
+
|
1228
1253
|
Add `require 'aasm/minitest'` to your `test_helper.rb` file and use them like this:
|
1229
1254
|
|
1230
1255
|
```ruby
|
data/gemfiles/rails_3.2.gemfile
CHANGED
@@ -2,12 +2,13 @@
|
|
2
2
|
|
3
3
|
source "https://rubygems.org"
|
4
4
|
|
5
|
-
gem "sqlite3", platforms: :ruby
|
5
|
+
gem "sqlite3", "~> 1.3.5", platforms: :ruby
|
6
6
|
gem "rails", "~> 3.2.22"
|
7
7
|
gem "mongoid", "~> 3.1"
|
8
8
|
gem "sequel"
|
9
9
|
gem "bson_ext", platforms: :ruby
|
10
10
|
gem "test-unit", "~> 3.0"
|
11
|
+
gem "minitest"
|
11
12
|
gem "activerecord-jdbcsqlite3-adapter", "1.3.24", platforms: :jruby
|
12
13
|
|
13
14
|
gemspec path: "../"
|
data/gemfiles/rails_4.2.gemfile
CHANGED
data/gemfiles/rails_5.0.gemfile
CHANGED
data/gemfiles/rails_5.1.gemfile
CHANGED
data/lib/aasm/core/event.rb
CHANGED
@@ -125,6 +125,7 @@ module AASM::Core
|
|
125
125
|
|
126
126
|
def _fire(obj, options={}, to_state=::AASM::NO_VALUE, *args)
|
127
127
|
result = options[:test_only] ? false : nil
|
128
|
+
clear_failed_callbacks
|
128
129
|
transitions = @transitions.select { |t| t.from == obj.aasm(state_machine.name).current_state || t.from == nil}
|
129
130
|
return result if transitions.size == 0
|
130
131
|
|
@@ -139,7 +140,6 @@ module AASM::Core
|
|
139
140
|
end
|
140
141
|
|
141
142
|
transitions.each do |transition|
|
142
|
-
transition.failures.clear #https://github.com/aasm/aasm/issues/383
|
143
143
|
next if to_state and !Array(transition.to).include?(to_state)
|
144
144
|
if (options.key?(:may_fire) && transition.eql?(options[:may_fire])) ||
|
145
145
|
(!options.key?(:may_fire) && transition.allowed?(obj, *args))
|
@@ -158,6 +158,11 @@ module AASM::Core
|
|
158
158
|
result
|
159
159
|
end
|
160
160
|
|
161
|
+
def clear_failed_callbacks
|
162
|
+
# https://github.com/aasm/aasm/issues/383, https://github.com/aasm/aasm/issues/599
|
163
|
+
transitions.each { |transition| transition.failures.clear }
|
164
|
+
end
|
165
|
+
|
161
166
|
def invoke_callbacks(code, record, args)
|
162
167
|
Invoker.new(code, record, args)
|
163
168
|
.with_default_return_value(false)
|
data/lib/aasm/errors.rb
CHANGED
@@ -3,10 +3,11 @@ module AASM
|
|
3
3
|
class UnknownStateMachineError < RuntimeError; end
|
4
4
|
|
5
5
|
class InvalidTransition < RuntimeError
|
6
|
-
attr_reader :object, :event_name, :originating_state, :failures
|
6
|
+
attr_reader :object, :event_name, :originating_state, :failures, :state_machine_name
|
7
7
|
|
8
8
|
def initialize(object, event_name, state_machine_name, failures = [])
|
9
9
|
@object, @event_name, @originating_state, @failures = object, event_name, object.aasm(state_machine_name).current_state, failures
|
10
|
+
@state_machine_name = state_machine_name
|
10
11
|
super("Event '#{event_name}' cannot transition from '#{originating_state}'.#{reasoning}")
|
11
12
|
end
|
12
13
|
|
data/lib/aasm/version.rb
CHANGED
@@ -22,6 +22,12 @@ RUBY
|
|
22
22
|
|
23
23
|
private
|
24
24
|
|
25
|
+
def column_exists?
|
26
|
+
table_name.singularize.humanize.constantize.column_names.include?(column_name.to_s)
|
27
|
+
rescue NameError
|
28
|
+
false
|
29
|
+
end
|
30
|
+
|
25
31
|
def model_exists?
|
26
32
|
File.exists?(File.join(destination_root, model_path))
|
27
33
|
end
|
@@ -11,7 +11,9 @@ module ActiveRecord
|
|
11
11
|
source_root File.expand_path("../templates", __FILE__)
|
12
12
|
|
13
13
|
def copy_aasm_migration
|
14
|
-
if
|
14
|
+
if column_exists?
|
15
|
+
puts "Both model and column exists"
|
16
|
+
elsif model_exists?
|
15
17
|
migration_template "migration_existing.rb", "db/migrate/add_#{column_name}_to_#{table_name}.rb"
|
16
18
|
else
|
17
19
|
migration_template "migration.rb", "db/migrate/aasm_create_#{table_name}.rb"
|
data/spec/database.rb
CHANGED
@@ -20,6 +20,10 @@ ActiveRecord::Migration.suppress_messages do
|
|
20
20
|
t.string "right"
|
21
21
|
end
|
22
22
|
|
23
|
+
ActiveRecord::Migration.create_table "works", :force => true do |t|
|
24
|
+
t.string "status"
|
25
|
+
end
|
26
|
+
|
23
27
|
%w(validators multiple_validators workers invalid_persistors multiple_invalid_persistors silent_persistors multiple_silent_persistors).each do |table_name|
|
24
28
|
ActiveRecord::Migration.create_table table_name, :force => true do |t|
|
25
29
|
t.string "name"
|
@@ -43,5 +43,11 @@ if defined?(ActiveRecord)
|
|
43
43
|
assert_migration "db/migrate/add_state_to_jobs.rb"
|
44
44
|
end
|
45
45
|
|
46
|
+
it "dont add column if column is already exists" do
|
47
|
+
require 'models/active_record/work.rb'
|
48
|
+
load_schema
|
49
|
+
run_generator %w(work status)
|
50
|
+
assert_no_migration "db/migrate/add_status_to_jobs.rb"
|
51
|
+
end
|
46
52
|
end
|
47
53
|
end
|
data/spec/unit/callbacks_spec.rb
CHANGED
@@ -203,6 +203,32 @@ describe 'callbacks for the new DSL' do
|
|
203
203
|
}.to raise_error(AASM::InvalidTransition)
|
204
204
|
end
|
205
205
|
|
206
|
+
it "does not propagate failures to next attempt of same transition" do
|
207
|
+
callback = Callbacks::Basic.new(:log => false, :fail_transition_guard => true)
|
208
|
+
|
209
|
+
expect {
|
210
|
+
callback.close!
|
211
|
+
}.to raise_error(AASM::InvalidTransition, "Event 'close' cannot transition from 'open'. Failed callback(s): [:transition_guard].")
|
212
|
+
|
213
|
+
expect {
|
214
|
+
callback.close!
|
215
|
+
}.to raise_error(AASM::InvalidTransition, "Event 'close' cannot transition from 'open'. Failed callback(s): [:transition_guard].")
|
216
|
+
end
|
217
|
+
|
218
|
+
it "does not propagate failures to next attempt of same event when no transition is applicable" do
|
219
|
+
callback = Callbacks::Basic.new(:log => false, :fail_transition_guard => true)
|
220
|
+
|
221
|
+
expect {
|
222
|
+
callback.close!
|
223
|
+
}.to raise_error(AASM::InvalidTransition, "Event 'close' cannot transition from 'open'. Failed callback(s): [:transition_guard].")
|
224
|
+
|
225
|
+
callback.aasm.current_state = :closed
|
226
|
+
|
227
|
+
expect {
|
228
|
+
callback.close!
|
229
|
+
}.to raise_error(AASM::InvalidTransition, "Event 'close' cannot transition from 'closed'.")
|
230
|
+
end
|
231
|
+
|
206
232
|
it "does not run transition_guard twice for multiple permitted transitions" do
|
207
233
|
show_debug_log = false
|
208
234
|
callback = Callbacks::MultipleTransitionsTransitionGuard.new(:log => show_debug_log, :fail_transition_guard => true)
|
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.
|
4
|
+
version: 5.0.2
|
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:
|
12
|
+
date: 2019-03-08 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: concurrent-ruby
|
@@ -138,7 +138,6 @@ files:
|
|
138
138
|
- callbacks.txt
|
139
139
|
- docker-compose.yml
|
140
140
|
- gemfiles/rails_3.2.gemfile
|
141
|
-
- gemfiles/rails_4.0.gemfile
|
142
141
|
- gemfiles/rails_4.2.gemfile
|
143
142
|
- gemfiles/rails_4.2_mongoid_5.gemfile
|
144
143
|
- gemfiles/rails_4.2_nobrainer.gemfile
|
@@ -224,6 +223,7 @@ files:
|
|
224
223
|
- spec/models/active_record/with_enum_without_column.rb
|
225
224
|
- spec/models/active_record/with_false_enum.rb
|
226
225
|
- spec/models/active_record/with_true_enum.rb
|
226
|
+
- spec/models/active_record/work.rb
|
227
227
|
- spec/models/active_record/worker.rb
|
228
228
|
- spec/models/active_record/writer.rb
|
229
229
|
- spec/models/basic_two_state_machines_example.rb
|
@@ -424,6 +424,7 @@ test_files:
|
|
424
424
|
- spec/models/active_record/with_enum_without_column.rb
|
425
425
|
- spec/models/active_record/with_false_enum.rb
|
426
426
|
- spec/models/active_record/with_true_enum.rb
|
427
|
+
- spec/models/active_record/work.rb
|
427
428
|
- spec/models/active_record/worker.rb
|
428
429
|
- spec/models/active_record/writer.rb
|
429
430
|
- spec/models/basic_two_state_machines_example.rb
|
data/gemfiles/rails_4.0.gemfile
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
# This file was generated by Appraisal
|
2
|
-
|
3
|
-
source "https://rubygems.org"
|
4
|
-
|
5
|
-
gem "sqlite3", platforms: :ruby
|
6
|
-
gem "rails", "4.0.13"
|
7
|
-
gem "mime-types", "~> 2", platforms: [:ruby_19, :jruby]
|
8
|
-
gem "mongoid", "~> 4.0"
|
9
|
-
gem "sequel"
|
10
|
-
gem "dynamoid", "~> 1", platforms: :ruby
|
11
|
-
gem "aws-sdk", "~> 2", platforms: :ruby
|
12
|
-
gem "redis-objects"
|
13
|
-
gem "activerecord-jdbcsqlite3-adapter", "1.3.24", platforms: :jruby
|
14
|
-
|
15
|
-
gemspec path: "../"
|