Skip to content

Commit

Permalink
Merge upstream/master, fix conflict in transition.rb
Browse files Browse the repository at this point in the history
  • Loading branch information
chriswoodrich committed Jan 10, 2016
2 parents bedf98a + 9ef7ce9 commit 80b941f
Show file tree
Hide file tree
Showing 54 changed files with 1,205 additions and 150 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -17,3 +17,4 @@ alto
.rspec
.bundle
tags
tmp
12 changes: 7 additions & 5 deletions .travis.yml
Expand Up @@ -11,18 +11,20 @@ rvm:
- 2.2
# - jruby-18mode # JRuby in 1.8 mode
- jruby-1.7 # JRuby in 1.9 mode
- rbx-2.2.1
- jruby-9.0.4.0
- rbx-2.5.8

services: mongodb

gemfile:
- gemfiles/rails_3.2.gemfile
- gemfiles/rails_3.2_stable.gemfile
- gemfiles/rails_4.0.gemfile
- gemfiles/rails_4.0_bson1.gemfile
- gemfiles/rails_4.0_mongo_mapper.gemfile
- gemfiles/rails_4.1.gemfile
- gemfiles/rails_4.1_bson1.gemfile
- gemfiles/rails_4.1_mongo_mapper.gemfile
- gemfiles/rails_4.2.gemfile
- gemfiles/rails_4.2_bson1.gemfile
- gemfiles/rails_4.2_mongoid_5.gemfile
- gemfiles/rails_4.2_mongo_mapper.gemfile

matrix:
allow_failures:
Expand Down
32 changes: 32 additions & 0 deletions CHANGELOG.md
@@ -1,5 +1,37 @@
# CHANGELOG

## 4.7.0

* fix: allow :send as event name (see [issue #257](https://github.com/aasm/aasm/issues/257) for details)
* add new callbacks: transactions, all events, ensure (see [issue #282](https://github.com/aasm/aasm/issues/282) for details, thanks to [@HoyaBoya](https://github.com/HoyaBoya))

## 4.6.0

* fix: make sure the column is actually present for _ActiveRecord_ enums (see [issue #265](https://github.com/aasm/aasm/issues/265) and [issue #152](https://github.com/aasm/aasm/issues/152) for details, thanks to [@anilmaurya](https://github.com/anilmaurya))
* add generators to configure active_record and mongoid after install (see [issue #261](https://github.com/aasm/aasm/issues/261) for details, thanks to [@anilmaurya](https://github.com/anilmaurya))

## 4.5.2

* fix arity difference between Procs and lambdas (see [issue #293](https://github.com/aasm/aasm/issues/293) for details)

## 4.5.1

* make sure to use override configuration options if state machine is defined more than once (see [issue #287](https://github.com/aasm/aasm/issues/287) for details)

## 4.5.0

* add RSpec matchers `have_state`, `allow_event` and `allow_transition_to` (see [issue #147](https://github.com/aasm/aasm/issues/147) for details)
* add RSpec matcher `transition_from` (see [issue #178](https://github.com/aasm/aasm/issues/178) for details, thanks to [@thomasstephane](https://github.com/thomasstephane))

## 4.4.1

* add support for rejecting certain events on inspection (see [issue #272](https://github.com/aasm/aasm/issues/272) for details, thanks to [@dubroe](https://github.com/dubroe))

## 4.4.0

* add support global transation callbacks (see [issue #221](https://github.com/aasm/aasm/issues/221) and [issue #253](https://github.com/aasm/aasm/issues/253) for details)
* add support (bugfix) for Mongoid >= 5.0 (see [issue #277](https://github.com/aasm/aasm/issues/277) and [issue #278](https://github.com/aasm/aasm/issues/278) for details)

## 4.3.0

* add support for multiple state machines per class (see [issue #158](https://github.com/aasm/aasm/issues/158) and [issue #240](https://github.com/aasm/aasm/issues/240) for details)
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
@@ -1,4 +1,4 @@
Copyright (c) 2006-2015 Scott Barron
Copyright (c) 2006-2016 Scott Barron

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
Expand Down
19 changes: 0 additions & 19 deletions PLANNED_CHANGES.md
Expand Up @@ -7,24 +7,5 @@

# Currently working on

* support for global callbacks (see #221 and #253)


# Changes so far

## version 4.3

* add support for multiple state machines per class
* class- and instance-level `aasm` methods accept a state machine selector
(aka the state machine _name_)
* if no selector/name is provided, `:default` will be used
* duplicate definitions of states and events will issue warnings
* check all tests
* _ActiveRecord_
* _Mongoid_
* _MongoMapper_
* _Sequel_
* what happen's if someone accesses `aasm`, but has defined a
state machine for `aasm(:my_name)`?
* documentation
* drop support for find_in_state, count_in_state, calculate_in_state, with_state_scope
93 changes: 89 additions & 4 deletions README.md
Expand Up @@ -98,6 +98,8 @@ class Job
state :sleeping, :initial => true, :before_enter => :do_something
state :running

after_all_transitions :log_status_change

event :run, :after => :notify_somebody do
before do
log('Preparing to run')
Expand All @@ -117,6 +119,10 @@ class Job
end
end

def log_status_change
puts "changing from #{aasm.from_state} to #{aasm.to_state} (event: #{aasm.current_event})"
end

def set_process(name)
...
end
Expand All @@ -140,11 +146,13 @@ Here you can see a list of all possible callbacks, together with their order of

```ruby
begin
event before_all_events
event before
event guards
transition guards
old_state before_exit
old_state exit
after_all_transitions
transition after
new_state before_enter
new_state enter
Expand All @@ -153,8 +161,13 @@ begin
old_state after_exit
new_state after_enter
event after
event after_all_events
rescue
event error
event error_on_all_events
ensure
event ensure
event ensure_on_all_events
end
```

Expand All @@ -172,8 +185,9 @@ Note that when passing arguments to a state transition, the first argument must
In case of an error during the event processing the error is rescued and passed to `:error`
callback, which can handle it or re-raise it for further propagation.

During the transition's `:after` callback (and reliably only then) you can access the
originating state (the from-state) and the target state (the to state), like this:
During the transition's `:after` callback (and reliably only then, or in the global
`after_all_transitions` callback) you can access the originating state (the from-state)
and the target state (the to state), like this:

```ruby
def set_process(name)
Expand Down Expand Up @@ -606,8 +620,19 @@ Since version *3.0.13* AASM supports ActiveRecord transactions. So whenever a tr
callback or the state update fails, all changes to any database record are rolled back.
Mongodb does not support transactions.

There are currently 3 transactional callbacks that can be handled on the event, and 2 transactional callbacks for all events.

```ruby
event before_all_transactions
event before_transaction
event aasm_fire_event (within transaction)
event after_commit (if event successful)
event after_transaction
event after_all_transactions
```

If you want to make sure a depending action happens only after the transaction is committed,
use the `after_commit` callback, like this:
use the `after_commit` callback along with the auto-save (bang) methods, like this:

```ruby
class Job < ActiveRecord::Base
Expand All @@ -626,6 +651,18 @@ class Job < ActiveRecord::Base
...
end
end

job = Job.where(state: 'sleeping').first!
job.run! # Saves the model and triggers the after_commit callback
```

Note that the following will not run the `after_commit` callbacks because
the auto-save method is not used:

```ruby
job = Job.where(state: 'sleeping').first!
job.run
job.save! #notify_about_running_job is not run
```

If you want to encapsulate state changes within an own transaction, the behavior
Expand Down Expand Up @@ -704,13 +741,50 @@ job.aasm.states(:permitted => true).map(&:name)
# show all possible (triggerable) events (allowed by transitions)
job.aasm.events.map(&:name)
=> [:sleep]
job.aasm.events(:reject => :sleep).map(&:name)
=> []

# list states for select
Job.aasm.states_for_select
=> [["Sleeping", "sleeping"], ["Running", "running"], ["Cleaning", "cleaning"]]
```


### Testing

AASM provides some matchers for [RSpec](http://rspec.info): `transition_from`, `have_state`, `allow_event` and `allow_transition_to`. Add `require 'aasm/rspec'` to your `spec_helper.rb` file and use them like this

```ruby
# classes with only the default state machine
job = Job.new
expect(job).to transition_from(:sleeping).to(:running).on_event(:run)
expect(job).not_to transition_from(:sleeping).to(:cleaning).on_event(:run)
expect(job).to have_state(:sleeping)
expect(job).not_to have_state(:running)
expect(job).to allow_event :run
expect(job).to_not allow_event :clean
expect(job).to allow_transition_to(:running)
expect(job).to_not allow_transition_to(:cleaning)

# classes with multiple state machine
multiple = SimpleMultipleExample.new
expect(multiple).to transition_from(:standing).to(:walking).on_event(:walk).on(:move)
expect(multiple).to_not transition_from(:standing).to(:running).on_event(:walk).on(:move)
expect(multiple).to have_state(:standing).on(:move)
expect(multiple).not_to have_state(:walking).on(:move)
expect(multiple).to allow_event(:walk).on(:move)
expect(multiple).to_not allow_event(:hold).on(:move)
expect(multiple).to allow_transition_to(:walking).on(:move)
expect(multiple).to_not allow_transition_to(:running).on(:move)
expect(multiple).to transition_from(:sleeping).to(:processing).on_event(:start).on(:work)
expect(multiple).to_not transition_from(:sleeping).to(:sleeping).on_event(:start).on(:work)
expect(multiple).to have_state(:sleeping).on(:work)
expect(multiple).not_to have_state(:processing).on(:work)
expect(multiple).to allow_event(:start).on(:move)
expect(multiple).to_not allow_event(:stop).on(:move)
expect(multiple).to allow_transition_to(:processing).on(:move)
expect(multiple).to_not allow_transition_to(:sleeping).on(:move)
```

## <a id="installation">Installation ##

Expand All @@ -734,6 +808,17 @@ gem 'aasm'
% sudo gem install pkg/aasm-x.y.z.gem
```

### Generators

After installing Aasm you can run generator:

```sh
% rails generate aasm NAME [COLUMN_NAME]
```
Replace NAME with the Model name, COLUMN_NAME is optional(default is 'aasm_state').
This will create a model (if one does not exist) and configure it with aasm block.
For Active record orm a migration file is added to add aasm state column to table.

## Latest changes ##

Take a look at the [CHANGELOG](https://github.com/aasm/aasm/blob/master/CHANGELOG.md) for details about recent changes to the current version.
Expand Down Expand Up @@ -771,7 +856,7 @@ purpose.

## License ##

Copyright (c) 2006-2015 Scott Barron
Copyright (c) 2006-2016 Scott Barron

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
Expand Down
1 change: 1 addition & 0 deletions aasm.gemspec
Expand Up @@ -19,6 +19,7 @@ Gem::Specification.new do |s|
s.add_development_dependency 'rake'
s.add_development_dependency 'sdoc'
s.add_development_dependency 'rspec', ">= 3"
s.add_development_dependency 'generator_spec'

# debugging
# s.add_development_dependency 'debugger'
Expand Down
Expand Up @@ -5,10 +5,11 @@ gem 'rubysl', :platforms => :rbx
gem 'rubinius-developer_tools', :platforms => :rbx
gem "jruby-openssl", :platforms => :jruby
gem "activerecord-jdbcsqlite3-adapter", :platforms => :jruby
gem "rails", "3.2.21"
gem "rails", :github => "rails/rails", :branch => "3-2-stable"
gem 'mongoid', '~>3.1' if Gem::Version.create(RUBY_VERSION.dup) >= Gem::Version.create('1.9.3')
gem 'sequel'
gem 'mongo_mapper', '~>0.13'
gem 'bson_ext', :platforms => :ruby
gem 'test-unit', '~> 3.0'

gemspec :path => "../"
File renamed without changes.
2 changes: 1 addition & 1 deletion gemfiles/rails_4.1.gemfile
Expand Up @@ -5,7 +5,7 @@ gem 'rubysl', :platforms => :rbx
gem 'rubinius-developer_tools', :platforms => :rbx
gem "jruby-openssl", :platforms => :jruby
gem "activerecord-jdbcsqlite3-adapter", :platforms => :jruby
gem "rails", "4.1.9"
gem "rails", "4.1.14"
gem 'mongoid', '~>4.0' if Gem::Version.create(RUBY_VERSION.dup) >= Gem::Version.create('1.9.3')
gem 'sequel'

Expand Down
Expand Up @@ -6,7 +6,7 @@ gem 'rubysl', :platforms => :rbx
gem 'rubinius-developer_tools', :platforms => :rbx
gem "jruby-openssl", :platforms => :jruby
gem "activerecord-jdbcsqlite3-adapter", :platforms => :jruby
gem "rails", "4.1.9"
gem "rails", "4.1.14"
gem 'sequel'
gem 'mongo_mapper', '~> 0.13'
gem 'bson_ext', :platforms => :ruby
Expand Down
2 changes: 1 addition & 1 deletion gemfiles/rails_4.2.gemfile
Expand Up @@ -5,7 +5,7 @@ gem 'rubysl', :platforms => :rbx
gem 'rubinius-developer_tools', :platforms => :rbx
gem "jruby-openssl", :platforms => :jruby
gem "activerecord-jdbcsqlite3-adapter", :platforms => :jruby
gem "rails", "4.2.0"
gem "rails", "4.2.5"
gem 'mongoid', '~>4.0' if Gem::Version.create(RUBY_VERSION.dup) >= Gem::Version.create('1.9.3')
gem 'sequel'

Expand Down
Expand Up @@ -6,7 +6,7 @@ gem 'rubysl', :platforms => :rbx
gem 'rubinius-developer_tools', :platforms => :rbx
gem "jruby-openssl", :platforms => :jruby
gem "activerecord-jdbcsqlite3-adapter", :platforms => :jruby
gem "rails", "4.2.0"
gem "rails", "4.2.5"
gem 'sequel'
gem 'mongo_mapper'
gem 'bson_ext', :platforms => :ruby
Expand Down
12 changes: 12 additions & 0 deletions gemfiles/rails_4.2_mongoid_5.gemfile
@@ -0,0 +1,12 @@
source "https://rubygems.org"

gem "sqlite3", :platforms => :ruby
gem 'rubysl', :platforms => :rbx
gem 'rubinius-developer_tools', :platforms => :rbx
gem "jruby-openssl", :platforms => :jruby
gem "activerecord-jdbcsqlite3-adapter", :platforms => :jruby
gem "rails", "4.2.5"
gem 'mongoid', '~>5.0' if Gem::Version.create(RUBY_VERSION.dup) >= Gem::Version.create('1.9.3')
gem 'sequel'

gemspec :path => "../"

0 comments on commit 80b941f

Please sign in to comment.