mirror of
https://github.com/aasm/aasm
synced 2023-03-27 23:22:41 -04:00
Merge branch 'master' of github.com:aasm/aasm
This commit is contained in:
commit
d23e75ef46
5 changed files with 46 additions and 9 deletions
12
CHANGELOG.md
12
CHANGELOG.md
|
@ -1,13 +1,15 @@
|
||||||
# CHANGELOG
|
# CHANGELOG
|
||||||
|
|
||||||
|
## unreleased
|
||||||
|
* Enable AASM scopes to be defined on abstract classes.
|
||||||
|
|
||||||
## 5.0.0
|
## 5.0.0
|
||||||
|
|
||||||
* Chore(invokers): Refactor callback invokers, add class-callbacks support [#541](https://github.com/aasm/aasm/pull/541), thanks to [pandomic](https://github.com/pandomic)
|
* Chore(invokers): Refactor callback invokers, add class-callbacks support [#541](https://github.com/aasm/aasm/pull/541), thanks to [pandomic](https://github.com/pandomic)
|
||||||
* Add docker setup to readme
|
* Add docker setup to readme
|
||||||
* Add support for Nobrainer (RethinkDB) [#522](https://github.com/aasm/aasm/pull/522), thanks to [zedtux] (https://github.com/zedtux)
|
* Add support for Nobrainer (RethinkDB) [#522](https://github.com/aasm/aasm/pull/522), thanks to [zedtux](https://github.com/zedtux)
|
||||||
* Patch `allow_event` to accept event with custom arguments [#419](https://github.com/aasm/aasm/pull/419), thanks to [czhc](https://github.com/czhc)
|
* Patch `allow_event` to accept event with custom arguments [#419](https://github.com/aasm/aasm/pull/419), thanks to [czhc](https://github.com/czhc)
|
||||||
|
|
||||||
|
|
||||||
## 4.12.3
|
## 4.12.3
|
||||||
|
|
||||||
* Add to AASM fire(event) and fire!(event) methods [#494](https://github.com/aasm/aasm/pull/494), thanks to [slayer](https://github.com/slayer)
|
* Add to AASM fire(event) and fire!(event) methods [#494](https://github.com/aasm/aasm/pull/494), thanks to [slayer](https://github.com/slayer)
|
||||||
|
@ -21,9 +23,9 @@
|
||||||
|
|
||||||
## 4.12.1
|
## 4.12.1
|
||||||
|
|
||||||
* DRY-up Mongoid and ActiveRecord Persistence, Add Sequel transactions and locking [#475](https://github.com/aasm/aasm/pull/475), thanks to [@Aryk] (https://github.com/Aryk)
|
* DRY-up Mongoid and ActiveRecord Persistence, Add Sequel transactions and locking [#475](https://github.com/aasm/aasm/pull/475), thanks to [@Aryk](https://github.com/Aryk)
|
||||||
* Add aliases for event methods [#476](https://github.com/aasm/aasm/pull/476), thanks to [@Aryk] (https://github.com/Aryk)
|
* Add aliases for event methods [#476](https://github.com/aasm/aasm/pull/476), thanks to [@Aryk](https://github.com/Aryk)
|
||||||
* Support Minitest spec expectations [#387](https://github.com/aasm/aasm/pull/387), thanks to [@faragorn] (https://github.com/faragorn)
|
* Support Minitest spec expectations [#387](https://github.com/aasm/aasm/pull/387), thanks to [@faragorn](https://github.com/faragorn)
|
||||||
## 4.12.0
|
## 4.12.0
|
||||||
|
|
||||||
* Fix thread safe issue with concurrent-ruby gem [see [pull-request #422](https://github.com/aasm/aasm/pull/442), thanks to [@reidmorrison](https://github.com/reidmorrison)
|
* Fix thread safe issue with concurrent-ruby gem [see [pull-request #422](https://github.com/aasm/aasm/pull/442), thanks to [@reidmorrison](https://github.com/reidmorrison)
|
||||||
|
|
|
@ -41,14 +41,15 @@ module AASM
|
||||||
|
|
||||||
module ClassMethods
|
module ClassMethods
|
||||||
def aasm_create_scope(state_machine_name, scope_name)
|
def aasm_create_scope(state_machine_name, scope_name)
|
||||||
conditions = {
|
|
||||||
table_name => { aasm(state_machine_name).attribute_name => scope_name.to_s }
|
|
||||||
}
|
|
||||||
if ActiveRecord::VERSION::MAJOR >= 3
|
if ActiveRecord::VERSION::MAJOR >= 3
|
||||||
|
conditions = { aasm(state_machine_name).attribute_name => scope_name.to_s }
|
||||||
class_eval do
|
class_eval do
|
||||||
scope scope_name, lambda { where(conditions) }
|
scope scope_name, lambda { where(table_name => conditions) }
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
|
conditions = {
|
||||||
|
table_name => { aasm(state_machine_name).attribute_name => scope_name.to_s }
|
||||||
|
}
|
||||||
class_eval do
|
class_eval do
|
||||||
named_scope scope_name, :conditions => conditions
|
named_scope scope_name, :conditions => conditions
|
||||||
end
|
end
|
||||||
|
|
|
@ -11,6 +11,9 @@ ActiveRecord::Migration.suppress_messages do
|
||||||
ActiveRecord::Migration.create_table "multiple_simple_new_dsls", :force => true do |t|
|
ActiveRecord::Migration.create_table "multiple_simple_new_dsls", :force => true do |t|
|
||||||
t.string "status"
|
t.string "status"
|
||||||
end
|
end
|
||||||
|
ActiveRecord::Migration.create_table "implemented_abstract_class_dsls", :force => true do |t|
|
||||||
|
t.string "status"
|
||||||
|
end
|
||||||
|
|
||||||
ActiveRecord::Migration.create_table "complex_active_record_examples", :force => true do |t|
|
ActiveRecord::Migration.create_table "complex_active_record_examples", :force => true do |t|
|
||||||
t.string "left"
|
t.string "left"
|
||||||
|
|
|
@ -15,3 +15,18 @@ class MultipleSimpleNewDsl < ActiveRecord::Base
|
||||||
state :new
|
state :new
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
class AbstractClassDsl < ActiveRecord::Base
|
||||||
|
include AASM
|
||||||
|
|
||||||
|
self.abstract_class = true
|
||||||
|
|
||||||
|
aasm :column => :status
|
||||||
|
aasm do
|
||||||
|
state :unknown_scope, :another_unknown_scope
|
||||||
|
state :new
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
class ImplementedAbstractClassDsl < AbstractClassDsl
|
||||||
|
end
|
||||||
|
|
|
@ -333,6 +333,22 @@ if defined?(ActiveRecord)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Scopes on abstract classes didn't work until Rails 5.
|
||||||
|
#
|
||||||
|
# Reference:
|
||||||
|
# https://github.com/rails/rails/issues/10658
|
||||||
|
if ActiveRecord::VERSION::MAJOR >= 5
|
||||||
|
context "For a descendant of an abstract model" do
|
||||||
|
it "should add the scope without the table_name" do
|
||||||
|
expect(ImplementedAbstractClassDsl).to respond_to(:unknown_scope)
|
||||||
|
expect(ImplementedAbstractClassDsl).to respond_to(:another_unknown_scope)
|
||||||
|
|
||||||
|
expect(ImplementedAbstractClassDsl.unknown_scope.is_a?(ActiveRecord::Relation)).to be_truthy
|
||||||
|
expect(ImplementedAbstractClassDsl.another_unknown_scope.is_a?(ActiveRecord::Relation)).to be_truthy
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
it "does not create scopes if requested" do
|
it "does not create scopes if requested" do
|
||||||
expect(NoScope).not_to respond_to(:pending)
|
expect(NoScope).not_to respond_to(:pending)
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue