mirror of
https://github.com/aasm/aasm
synced 2023-03-27 23:22:41 -04:00
Use after_commit_everywhere
instead of after_commit_action
This commit is contained in:
parent
19406b27b4
commit
86920c68d9
13 changed files with 30 additions and 30 deletions
|
@ -57,7 +57,7 @@ end
|
|||
appraise 'norails' do
|
||||
gem 'sqlite3', '~> 1.3', '>= 1.3.5', platforms: :ruby
|
||||
gem 'rails', install_if: false
|
||||
gem 'after_commit_action', install_if: false
|
||||
gem 'after_commit_everywhere', install_if: false
|
||||
gem 'sequel'
|
||||
gem 'redis-objects'
|
||||
end
|
||||
|
|
2
Gemfile
2
Gemfile
|
@ -4,4 +4,4 @@ gemspec
|
|||
|
||||
gem 'sqlite3', '~> 1.3.5', :platforms => :ruby
|
||||
gem 'rails', '5.1.4'
|
||||
gem 'after_commit_action', '~> 1.0'
|
||||
gem 'after_commit_everywhere', '~> 0.1', '>= 0.1.5'
|
||||
|
|
|
@ -436,7 +436,7 @@ job.aasm.current_state # stage3
|
|||
### Multiple state machines per class
|
||||
|
||||
Multiple state machines per class are supported. Be aware though that _AASM_ has been
|
||||
built with one state machine per class in mind. Nonetheless, here's how to do it (see below). Please note that you will need to specify database columns for where your pertinent states will be stored - we have specified two columns `move_state` and `work_state` in the example below. See the [Column name & migration](https://github.com/aasm/aasm#column-name--migration) section for further info.
|
||||
built with one state machine per class in mind. Nonetheless, here's how to do it (see below). Please note that you will need to specify database columns for where your pertinent states will be stored - we have specified two columns `move_state` and `work_state` in the example below. See the [Column name & migration](https://github.com/aasm/aasm#column-name--migration) section for further info.
|
||||
|
||||
```ruby
|
||||
class SimpleMultipleExample
|
||||
|
@ -984,8 +984,8 @@ job.save! #notify_about_running_job is not run
|
|||
Please note that `:after_commit` AASM callbacks behaves around custom implementation
|
||||
of transaction pattern rather than a real-life DB transaction. This fact still causes
|
||||
the race conditions and redundant callback calls within nested transaction. In order
|
||||
to fix that it's highly recommended to add `gem 'after_commit_action', '~> 1.0'` to your
|
||||
`Gemfile`.
|
||||
to fix that it's highly recommended to add `gem 'after_commit_everywhere', '~> 0.1', '>= 0.1.5'`
|
||||
to your `Gemfile`.
|
||||
|
||||
If you want to encapsulate state changes within an own transaction, the behavior
|
||||
of this nested transaction might be confusing. Take a look at
|
||||
|
@ -1098,7 +1098,7 @@ end
|
|||
|
||||
### Log State Changes
|
||||
|
||||
Logging state change can be done using [paper_trail](https://github.com/paper-trail-gem/paper_trail) gem
|
||||
Logging state change can be done using [paper_trail](https://github.com/paper-trail-gem/paper_trail) gem
|
||||
|
||||
Example of implementation can be found here [https://github.com/nitsujri/aasm-papertrail-example](https://github.com/nitsujri/aasm-papertrail-example)
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@ source "https://rubygems.org"
|
|||
|
||||
gem "sqlite3", "~> 1.3", ">= 1.3.5", platforms: :ruby
|
||||
gem "rails", install_if: false
|
||||
gem "after_commit_action", install_if: false
|
||||
gem "after_commit_everywhere", install_if: false
|
||||
gem "sequel"
|
||||
gem "redis-objects"
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@ source "https://rubygems.org"
|
|||
|
||||
gem "sqlite3", "~> 1.3.5", platforms: :ruby
|
||||
gem "rails", "4.2.5"
|
||||
gem "after_commit_action", "~> 1.0"
|
||||
gem "after_commit_everywhere", "~> 0.1", ">= 0.1.5"
|
||||
gem "nokogiri", "1.6.8.1", platforms: [:ruby_19]
|
||||
gem "mime-types", "~> 2", platforms: [:ruby_19, :jruby]
|
||||
gem "mongoid", "~> 4.0"
|
||||
|
|
|
@ -4,7 +4,7 @@ source "https://rubygems.org"
|
|||
|
||||
gem "sqlite3", "~> 1.3.5", platforms: :ruby
|
||||
gem "rails", "4.2.5"
|
||||
gem "after_commit_action", "~> 1.0"
|
||||
gem "after_commit_everywhere", "~> 0.1", ">= 0.1.5"
|
||||
gem "mime-types", "~> 2", platforms: [:ruby_19, :jruby]
|
||||
gem "mongoid", "~> 5.0"
|
||||
gem "activerecord-jdbcsqlite3-adapter", "1.3.24", platforms: :jruby
|
||||
|
|
|
@ -4,7 +4,7 @@ source "https://rubygems.org"
|
|||
|
||||
gem "sqlite3", "~> 1.3.5", platforms: :ruby
|
||||
gem "rails", "4.2.5"
|
||||
gem "after_commit_action", "~> 1.0"
|
||||
gem "after_commit_everywhere", "~> 0.1", ">= 0.1.5"
|
||||
gem "nobrainer", "~> 0.33.0"
|
||||
|
||||
gemspec path: "../"
|
||||
|
|
|
@ -4,7 +4,7 @@ source "https://rubygems.org"
|
|||
|
||||
gem "sqlite3", "~> 1.3.5", platforms: :ruby
|
||||
gem "rails", "5.0.0"
|
||||
gem "after_commit_action", "~> 1.0"
|
||||
gem "after_commit_everywhere", "~> 0.1", ">= 0.1.5"
|
||||
gem "mongoid", "~> 6.0"
|
||||
gem "sequel"
|
||||
gem "dynamoid", "~> 1.3", platforms: :ruby
|
||||
|
|
|
@ -4,7 +4,7 @@ source "https://rubygems.org"
|
|||
|
||||
gem "sqlite3", "~> 1.3.5", platforms: :ruby
|
||||
gem "rails", "5.0.0"
|
||||
gem "after_commit_action", "~> 1.0"
|
||||
gem "after_commit_everywhere", "~> 0.1", ">= 0.1.5"
|
||||
gem "nobrainer", "~> 0.33.0"
|
||||
|
||||
gemspec path: "../"
|
||||
|
|
|
@ -4,7 +4,7 @@ source "https://rubygems.org"
|
|||
|
||||
gem "sqlite3", "~> 1.3.5", platforms: :ruby
|
||||
gem "rails", "5.1"
|
||||
gem "after_commit_action", "~> 1.0"
|
||||
gem "after_commit_everywhere", "~> 0.1", ">= 0.1.5"
|
||||
gem "mongoid", "~>6.0"
|
||||
gem "sequel"
|
||||
gem "dynamoid", "~> 1.3", platforms: :ruby
|
||||
|
|
|
@ -4,7 +4,7 @@ source "https://rubygems.org"
|
|||
|
||||
gem "sqlite3", "~> 1.3.5", platforms: :ruby
|
||||
gem "rails", "5.2"
|
||||
gem "after_commit_action", "~> 1.0"
|
||||
gem "after_commit_everywhere", "~> 0.1", ">= 0.1.5"
|
||||
gem "mongoid", "~>6.0"
|
||||
gem "sequel"
|
||||
gem "dynamoid", "~>2.2", platforms: :ruby
|
||||
|
|
|
@ -29,13 +29,13 @@ module AASM
|
|||
#
|
||||
def self.included(base)
|
||||
begin
|
||||
require 'after_commit_action'
|
||||
base.send(:include, ::AfterCommitAction) unless base.include?(::AfterCommitAction)
|
||||
base.send(:alias_method, :aasm_execute_after_commit, :execute_after_commit)
|
||||
require 'after_commit_everywhere'
|
||||
base.send(:include, ::AfterCommitEverywhere) unless base.include?(::AfterCommitEverywhere)
|
||||
base.send(:alias_method, :aasm_execute_after_commit, :after_commit)
|
||||
rescue LoadError
|
||||
warn <<-MSG
|
||||
[DEPRECATION] :after_commit AASM callback is not safe in terms of race conditions and redundant calls.
|
||||
Please add `gem 'after_commit_action', '~> 1.0'` to your Gemfile in order to fix that.
|
||||
Please add `gem 'after_commit_everywhere', '~> 0.1', '>= 0.1.5'` to your Gemfile in order to fix that.
|
||||
MSG
|
||||
end
|
||||
|
||||
|
|
|
@ -628,22 +628,22 @@ if defined?(ActiveRecord)
|
|||
expect(validator.name).to eq("name changed")
|
||||
expect(validator.reload).to be_running
|
||||
end
|
||||
end
|
||||
|
||||
it "should not fire :after_commit if root transaction failed" do
|
||||
validator = Validator.create(:name => 'name')
|
||||
expect(validator).to be_sleeping
|
||||
it "should not fire :after_commit if root transaction failed" do
|
||||
validator = Validator.create(:name => 'name')
|
||||
expect(validator).to be_sleeping
|
||||
|
||||
validator.transaction do
|
||||
validator.run!
|
||||
expect(validator.name).to eq("name")
|
||||
expect(validator).to be_running
|
||||
|
||||
raise ActiveRecord::Rollback, "failed on purpose"
|
||||
end
|
||||
|
||||
validator.transaction do
|
||||
validator.run!
|
||||
expect(validator.name).to eq("name")
|
||||
expect(validator).to be_running
|
||||
|
||||
raise ActiveRecord::Rollback, "failed on purpose"
|
||||
expect(validator.reload).to be_sleeping
|
||||
end
|
||||
|
||||
expect(validator.name).to eq("name")
|
||||
expect(validator.reload).to be_sleeping
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue