mirror of
https://github.com/aasm/aasm
synced 2023-03-27 23:22:41 -04:00
Merge branch 'master' into multiple_state_machines_per_class
Conflicts: lib/aasm/persistence/active_record_persistence.rb
This commit is contained in:
commit
8f5778f13c
9 changed files with 65 additions and 14 deletions
|
@ -1,6 +1,11 @@
|
|||
# CHANGELOG
|
||||
|
||||
## 4.2.0 (not yet released)
|
||||
## 4.3.0 (not yet released)
|
||||
|
||||
## 4.2.0
|
||||
|
||||
* support turning off and on the configuration option for `no_direct_assignment` (see [issue #223](https://github.com/aasm/aasm/issues/223) for details)
|
||||
* 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.1.1
|
||||
|
||||
|
|
13
CODE_OF_CONDUCT.md
Normal file
13
CODE_OF_CONDUCT.md
Normal file
|
@ -0,0 +1,13 @@
|
|||
# Contributor Code of Conduct
|
||||
|
||||
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.
|
||||
|
||||
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.
|
||||
|
||||
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.
|
||||
|
||||
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.
|
||||
|
||||
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
|
||||
|
||||
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/)
|
|
@ -679,6 +679,15 @@ Feel free to
|
|||
* [Thorsten Böttger](http://github.com/alto) (since 2011)
|
||||
|
||||
|
||||
## Contributing ##
|
||||
|
||||
1. Read the [Contributor Code of Conduct](https://github.com/aasm/aasm/blob/master/CODE_OF_CONDUCT.md)
|
||||
2. Fork it
|
||||
3. Create your feature branch (git checkout -b my-new-feature)
|
||||
4. Commit your changes (git commit -am 'Added some feature')
|
||||
5. Push to the branch (git push origin my-new-feature)
|
||||
6. Create new Pull Request
|
||||
|
||||
## Warranty ##
|
||||
|
||||
This software is provided "as is" and without any express or
|
||||
|
|
|
@ -29,11 +29,19 @@ module AASM
|
|||
|
||||
configure :enum, nil
|
||||
|
||||
if @state_machine.config.no_direct_assignment
|
||||
@klass.send(:define_method, "#{@state_machine.config.column}=") do |state_name|
|
||||
raise AASM::NoDirectAssignmentError.new('direct assignment of AASM column has been disabled (see AASM configuration for this class)')
|
||||
# make sure to raise an error if no_direct_assignment is enabled
|
||||
# and attribute is directly assigned though
|
||||
@klass.class_eval %Q(
|
||||
def #{@state_machine.config.column}=(state_name)
|
||||
if self.class.aasm.state_machine.config.no_direct_assignment
|
||||
raise AASM::NoDirectAssignmentError.new(
|
||||
'direct assignment of AASM column has been disabled (see AASM configuration for this class)'
|
||||
)
|
||||
else
|
||||
super
|
||||
end
|
||||
end
|
||||
)
|
||||
end
|
||||
|
||||
# This method is both a getter and a setter
|
||||
|
|
|
@ -178,7 +178,7 @@ module AASM
|
|||
|
||||
if success && options[:persist]
|
||||
event = self.class.aasm(state_machine_name).state_machine.events[name]
|
||||
event.fire_callbacks(:after_commit, self)
|
||||
event.fire_callbacks(:after_commit, self, *args)
|
||||
end
|
||||
|
||||
success
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
module AASM
|
||||
VERSION = "4.1.1"
|
||||
VERSION = "4.2.0"
|
||||
end
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
class LocalizerTestModel < ActiveRecord::Base
|
||||
include AASM
|
||||
|
||||
attr_accessor :aasm_state
|
||||
|
||||
aasm do
|
||||
state :opened, :initial => true
|
||||
state :closed
|
||||
|
|
|
@ -12,8 +12,8 @@ class Validator < ActiveRecord::Base
|
|||
transitions :to => :running, :from => :sleeping
|
||||
end
|
||||
event :sleep do
|
||||
after_commit do
|
||||
change_name_on_sleep
|
||||
after_commit do |name|
|
||||
change_name_on_sleep name
|
||||
end
|
||||
transitions :to => :sleeping, :from => :running
|
||||
end
|
||||
|
@ -29,8 +29,8 @@ class Validator < ActiveRecord::Base
|
|||
save!
|
||||
end
|
||||
|
||||
def change_name_on_sleep
|
||||
self.name = "sleeper"
|
||||
def change_name_on_sleep name
|
||||
self.name = name
|
||||
save!
|
||||
end
|
||||
|
||||
|
|
|
@ -321,6 +321,24 @@ describe "direct assignment" do
|
|||
expect {obj.aasm_state = :running}.to raise_error(AASM::NoDirectAssignmentError)
|
||||
expect(obj.aasm_state.to_sym).to eql :pending
|
||||
end
|
||||
|
||||
it 'can be turned off and on again' do
|
||||
obj = NoDirectAssignment.create
|
||||
expect(obj.aasm_state.to_sym).to eql :pending
|
||||
|
||||
expect {obj.aasm_state = :running}.to raise_error(AASM::NoDirectAssignmentError)
|
||||
expect(obj.aasm_state.to_sym).to eql :pending
|
||||
|
||||
# allow it temporarily
|
||||
NoDirectAssignment.aasm.state_machine.config.no_direct_assignment = false
|
||||
obj.aasm_state = :pending
|
||||
expect(obj.aasm_state.to_sym).to eql :pending
|
||||
|
||||
# and forbid it again
|
||||
NoDirectAssignment.aasm.state_machine.config.no_direct_assignment = true
|
||||
expect {obj.aasm_state = :running}.to raise_error(AASM::NoDirectAssignmentError)
|
||||
expect(obj.aasm_state.to_sym).to eql :pending
|
||||
end
|
||||
end # direct assignment
|
||||
|
||||
describe 'initial states' do
|
||||
|
@ -436,7 +454,7 @@ describe 'transitions with persistence' do
|
|||
expect(validator).to be_running
|
||||
expect(validator.name).to eq("name changed")
|
||||
|
||||
validator.sleep!
|
||||
validator.sleep!("sleeper")
|
||||
expect(validator).to be_sleeping
|
||||
expect(validator.name).to eq("sleeper")
|
||||
end
|
||||
|
|
Loading…
Add table
Reference in a new issue