aasm 4.1.1 → 4.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -1
- data/CODE_OF_CONDUCT.md +13 -0
- data/Gemfile +1 -1
- data/LICENSE +1 -1
- data/README.md +9 -0
- data/aasm.gemspec +1 -1
- data/lib/aasm/base.rb +12 -4
- data/lib/aasm/persistence/active_record_persistence.rb +1 -1
- data/lib/aasm/version.rb +1 -1
- data/spec/models/active_record/derivate_new_dsl.rb +3 -0
- data/spec/models/active_record/false_state.rb +17 -0
- data/spec/models/active_record/gate.rb +19 -0
- data/spec/models/active_record/localizer_test_model.rb +34 -0
- data/spec/models/active_record/no_direct_assignment.rb +10 -0
- data/spec/models/active_record/no_scope.rb +10 -0
- data/spec/models/active_record/persisted_state.rb +12 -0
- data/spec/models/active_record/provided_and_persisted_state.rb +24 -0
- data/spec/models/active_record/reader.rb +7 -0
- data/spec/models/active_record/simple_new_dsl.rb +8 -0
- data/spec/models/active_record/thief.rb +14 -0
- data/spec/models/active_record/transient.rb +6 -0
- data/spec/models/active_record/with_enum.rb +19 -0
- data/spec/models/active_record/with_false_enum.rb +15 -0
- data/spec/models/active_record/with_true_enum.rb +19 -0
- data/spec/models/active_record/writer.rb +6 -0
- data/spec/models/{auth_machine.rb → complex_example.rb} +1 -1
- data/spec/models/default_state.rb +12 -0
- data/spec/models/initial_state_proc.rb +15 -0
- data/spec/models/{bar.rb → no_initial_state.rb} +1 -4
- data/spec/models/provided_state.rb +24 -0
- data/spec/models/simple_example.rb +15 -0
- data/spec/models/state_machine_with_failed_event.rb +12 -0
- data/spec/models/sub_class.rb +3 -0
- data/spec/models/sub_class_with_more_states.rb +7 -0
- data/spec/models/super_class.rb +18 -0
- data/spec/models/{argument.rb → valid_state_name.rb} +1 -1
- data/spec/models/validator.rb +4 -4
- data/spec/spec_helper.rb +1 -1
- data/spec/unit/api_spec.rb +6 -1
- data/spec/unit/complex_example_spec.rb +2 -2
- data/spec/unit/event_naming_spec.rb +2 -15
- data/spec/unit/initial_state_spec.rb +3 -18
- data/spec/unit/inspection_spec.rb +7 -7
- data/spec/unit/localizer_spec.rb +0 -38
- data/spec/unit/persistence/active_record_persistence_spec.rb +21 -3
- data/spec/unit/simple_example_spec.rb +26 -42
- data/spec/unit/subclassing_spec.rb +10 -10
- metadata +60 -19
- data/spec/models/active_record/api.rb +0 -75
- data/spec/models/father.rb +0 -21
- data/spec/models/persistence.rb +0 -164
- data/spec/models/son.rb +0 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cd80c470206244734a77fe540848e299e87dab9f
|
4
|
+
data.tar.gz: 28b464e9012345a46ddc5595d29541d52a358bf4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 46d54cc3e2e66387916f7f1edfe03f3de9cb09578a8b485ea084bd68ba854f9003d1fd00de18a6d7c40984a0b0d2fe1b2d7bc4b3610e7d421c724e2f5af7a9f1
|
7
|
+
data.tar.gz: cb2506c237a22fc3dc04869791d15f85614ac33096ccff60fa5a6dd40830d2325375ed13cdc3abf2adc02c958a336362027393c6ee0351bc463cf47cb0b9020f
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,11 @@
|
|
1
1
|
# CHANGELOG
|
2
2
|
|
3
|
-
## 4.
|
3
|
+
## 4.3.0 (not yet released)
|
4
|
+
|
5
|
+
## 4.2.0
|
6
|
+
|
7
|
+
* support turning off and on the configuration option for `no_direct_assignment` (see [issue #223](https://github.com/aasm/aasm/issues/223) for details)
|
8
|
+
* event arguments are now passed to `:after_commit` callbacks as well (see [issue #238](https://github.com/aasm/aasm/pull/238), thanks to [@kuinak](https://github.com/kuinak))
|
4
9
|
|
5
10
|
## 4.1.1
|
6
11
|
|
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
|
4
|
+
|
5
|
+
We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
|
6
|
+
|
7
|
+
Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
|
8
|
+
|
9
|
+
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
|
10
|
+
|
11
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
|
12
|
+
|
13
|
+
This Code of Conduct is adapted from the [Contributor Covenant](http:contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
|
data/Gemfile
CHANGED
@@ -4,7 +4,7 @@ gem "sqlite3", :platforms => :ruby
|
|
4
4
|
gem 'rubysl', :platforms => :rbx
|
5
5
|
gem "jruby-openssl", :platforms => :jruby
|
6
6
|
gem "activerecord-jdbcsqlite3-adapter", :platforms => :jruby
|
7
|
-
gem "rails", "~>4.
|
7
|
+
gem "rails", "~>4.2"
|
8
8
|
gem 'mongoid', '~>4.0' if Gem::Version.create(RUBY_VERSION.dup) >= Gem::Version.create('1.9.3')
|
9
9
|
gem 'sequel'
|
10
10
|
# Since mongoid V4 requires incompatible bson V2, cannot have mongoid (V4 or greater)
|
data/LICENSE
CHANGED
data/README.md
CHANGED
@@ -679,6 +679,15 @@ Feel free to
|
|
679
679
|
* [Thorsten Böttger](http://github.com/alto) (since 2011)
|
680
680
|
|
681
681
|
|
682
|
+
## Contributing ##
|
683
|
+
|
684
|
+
1. Read the [Contributor Code of Conduct](https://github.com/aasm/aasm/blob/master/CODE_OF_CONDUCT.md)
|
685
|
+
2. Fork it
|
686
|
+
3. Create your feature branch (git checkout -b my-new-feature)
|
687
|
+
4. Commit your changes (git commit -am 'Added some feature')
|
688
|
+
5. Push to the branch (git push origin my-new-feature)
|
689
|
+
6. Create new Pull Request
|
690
|
+
|
682
691
|
## Warranty ##
|
683
692
|
|
684
693
|
This software is provided "as is" and without any express or
|
data/aasm.gemspec
CHANGED
@@ -18,7 +18,7 @@ Gem::Specification.new do |s|
|
|
18
18
|
|
19
19
|
s.add_development_dependency 'rake'
|
20
20
|
s.add_development_dependency 'sdoc'
|
21
|
-
s.add_development_dependency 'rspec'
|
21
|
+
s.add_development_dependency 'rspec', ">= 3"
|
22
22
|
|
23
23
|
# debugging
|
24
24
|
# s.add_development_dependency 'debugger'
|
data/lib/aasm/base.rb
CHANGED
@@ -27,11 +27,19 @@ module AASM
|
|
27
27
|
|
28
28
|
configure :enum, nil
|
29
29
|
|
30
|
-
if
|
31
|
-
|
32
|
-
|
30
|
+
# make sure to raise an error if no_direct_assignment is enabled
|
31
|
+
# and attribute is directly assigned though
|
32
|
+
@klass.class_eval %Q(
|
33
|
+
def #{@state_machine.config.column}=(state_name)
|
34
|
+
if self.class.aasm.state_machine.config.no_direct_assignment
|
35
|
+
raise AASM::NoDirectAssignmentError.new(
|
36
|
+
'direct assignment of AASM column has been disabled (see AASM configuration for this class)'
|
37
|
+
)
|
38
|
+
else
|
39
|
+
super
|
40
|
+
end
|
33
41
|
end
|
34
|
-
|
42
|
+
)
|
35
43
|
end
|
36
44
|
|
37
45
|
# This method is both a getter and a setter
|
data/lib/aasm/version.rb
CHANGED
@@ -0,0 +1,17 @@
|
|
1
|
+
class FalseState < ActiveRecord::Base
|
2
|
+
include AASM
|
3
|
+
|
4
|
+
def initialize(*args)
|
5
|
+
super
|
6
|
+
self.aasm_state = false
|
7
|
+
end
|
8
|
+
|
9
|
+
aasm do
|
10
|
+
state :opened
|
11
|
+
state :closed
|
12
|
+
|
13
|
+
event :view do
|
14
|
+
transitions :to => :read, :from => [:needs_attention]
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
class Gate < ActiveRecord::Base
|
2
|
+
include AASM
|
3
|
+
|
4
|
+
# Fake this column for testing purposes
|
5
|
+
# attr_accessor :aasm_state
|
6
|
+
|
7
|
+
def value
|
8
|
+
'value'
|
9
|
+
end
|
10
|
+
|
11
|
+
aasm do
|
12
|
+
state :opened
|
13
|
+
state :closed
|
14
|
+
|
15
|
+
event :view do
|
16
|
+
transitions :to => :read, :from => [:needs_attention]
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
class LocalizerTestModel < ActiveRecord::Base
|
2
|
+
include AASM
|
3
|
+
|
4
|
+
aasm do
|
5
|
+
state :opened, :initial => true
|
6
|
+
state :closed
|
7
|
+
event :close
|
8
|
+
event :open
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
describe 'localized state names' do
|
13
|
+
before(:all) do
|
14
|
+
I18n.load_path << 'spec/en.yml'
|
15
|
+
I18n.default_locale = :en
|
16
|
+
I18n.reload!
|
17
|
+
end
|
18
|
+
|
19
|
+
after(:all) do
|
20
|
+
I18n.load_path.clear
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'should localize' do
|
24
|
+
state = LocalizerTestModel.aasm.states.detect {|s| s == :opened}
|
25
|
+
expect(state.localized_name).to eq("It's open now!")
|
26
|
+
expect(state.human_name).to eq("It's open now!")
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'should use fallback' do
|
30
|
+
state = LocalizerTestModel.aasm.states.detect {|s| s == :closed}
|
31
|
+
expect(state.localized_name).to eq('Closed')
|
32
|
+
expect(state.human_name).to eq('Closed')
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
class PersistedState < ActiveRecord::Base
|
2
|
+
attr_accessor :transient_store, :persisted_store
|
3
|
+
include AASM
|
4
|
+
aasm do
|
5
|
+
state :alpha, :initial => true
|
6
|
+
state :beta
|
7
|
+
state :gamma
|
8
|
+
event :release do
|
9
|
+
transitions :from => [:alpha, :beta, :gamma], :to => :beta
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
class ProvidedAndPersistedState < ActiveRecord::Base
|
2
|
+
attr_accessor :transient_store, :persisted_store
|
3
|
+
include AASM
|
4
|
+
aasm do
|
5
|
+
state :alpha, :initial => true
|
6
|
+
state :beta
|
7
|
+
state :gamma
|
8
|
+
event :release do
|
9
|
+
transitions :from => [:alpha, :beta, :gamma], :to => :beta
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def aasm_read_state
|
14
|
+
:gamma
|
15
|
+
end
|
16
|
+
|
17
|
+
def aasm_write_state(new_state)
|
18
|
+
@persisted_store = new_state
|
19
|
+
end
|
20
|
+
|
21
|
+
def aasm_write_state_without_persistence(new_state)
|
22
|
+
@transient_store = new_state
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
class Thief < ActiveRecord::Base
|
2
|
+
if ActiveRecord::VERSION::MAJOR >= 3
|
3
|
+
self.table_name = 'thieves'
|
4
|
+
else
|
5
|
+
set_table_name "thieves"
|
6
|
+
end
|
7
|
+
include AASM
|
8
|
+
aasm do
|
9
|
+
state :rich
|
10
|
+
state :jailed
|
11
|
+
initial_state Proc.new {|thief| thief.skilled ? :rich : :jailed }
|
12
|
+
end
|
13
|
+
attr_accessor :skilled, :aasm_state
|
14
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
class WithEnum < ActiveRecord::Base
|
2
|
+
include AASM
|
3
|
+
|
4
|
+
# Fake this column for testing purposes
|
5
|
+
attr_accessor :aasm_state
|
6
|
+
|
7
|
+
def self.test
|
8
|
+
{}
|
9
|
+
end
|
10
|
+
|
11
|
+
aasm :enum => :test do
|
12
|
+
state :opened
|
13
|
+
state :closed
|
14
|
+
|
15
|
+
event :view do
|
16
|
+
transitions :to => :read, :from => [:needs_attention]
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
class WithFalseEnum < ActiveRecord::Base
|
2
|
+
include AASM
|
3
|
+
|
4
|
+
# Fake this column for testing purposes
|
5
|
+
attr_accessor :aasm_state
|
6
|
+
|
7
|
+
aasm :enum => false do
|
8
|
+
state :opened
|
9
|
+
state :closed
|
10
|
+
|
11
|
+
event :view do
|
12
|
+
transitions :to => :read, :from => [:needs_attention]
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
class WithTrueEnum < ActiveRecord::Base
|
2
|
+
include AASM
|
3
|
+
|
4
|
+
# Fake this column for testing purposes
|
5
|
+
attr_accessor :aasm_state
|
6
|
+
|
7
|
+
def value
|
8
|
+
'value'
|
9
|
+
end
|
10
|
+
|
11
|
+
aasm :enum => true do
|
12
|
+
state :opened
|
13
|
+
state :closed
|
14
|
+
|
15
|
+
event :view do
|
16
|
+
transitions :to => :read, :from => [:needs_attention]
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
class DefaultState
|
2
|
+
attr_accessor :transient_store, :persisted_store
|
3
|
+
include AASM
|
4
|
+
aasm do
|
5
|
+
state :alpha, :initial => true
|
6
|
+
state :beta
|
7
|
+
state :gamma
|
8
|
+
event :release do
|
9
|
+
transitions :from => [:alpha, :beta, :gamma], :to => :beta
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
class InitialStateProc
|
2
|
+
RICH = 1_000_000
|
3
|
+
|
4
|
+
attr_accessor :balance
|
5
|
+
|
6
|
+
include AASM
|
7
|
+
aasm do
|
8
|
+
state :retired
|
9
|
+
state :selling_bad_mortgages
|
10
|
+
initial_state Proc.new { |banker| banker.rich? ? :retired : :selling_bad_mortgages }
|
11
|
+
end
|
12
|
+
|
13
|
+
def initialize(balance = 0); self.balance = balance; end
|
14
|
+
def rich?; self.balance >= RICH; end
|
15
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
class ProvidedState
|
2
|
+
attr_accessor :transient_store, :persisted_store
|
3
|
+
include AASM
|
4
|
+
aasm do
|
5
|
+
state :alpha, :initial => true
|
6
|
+
state :beta
|
7
|
+
state :gamma
|
8
|
+
event :release do
|
9
|
+
transitions :from => [:alpha, :beta, :gamma], :to => :beta
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def aasm_read_state
|
14
|
+
:beta
|
15
|
+
end
|
16
|
+
|
17
|
+
def aasm_write_state(new_state)
|
18
|
+
@persisted_store = new_state
|
19
|
+
end
|
20
|
+
|
21
|
+
def aasm_write_state_without_persistence(new_state)
|
22
|
+
@transient_store = new_state
|
23
|
+
end
|
24
|
+
end
|