mirror of
https://github.com/aasm/aasm
synced 2023-03-27 23:22:41 -04:00
new dsl now supports changing the states column name
This commit is contained in:
parent
4dcc7a5862
commit
b22ceb2792
3 changed files with 21 additions and 6 deletions
|
@ -21,8 +21,8 @@ module AASM
|
|||
super
|
||||
end
|
||||
|
||||
def aasm(&block)
|
||||
@aasm ||= AASM::Base.new(self)
|
||||
def aasm(options={}, &block)
|
||||
@aasm ||= AASM::Base.new(self, options)
|
||||
@aasm.instance_eval(&block) if block
|
||||
@aasm
|
||||
end
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
module AASM
|
||||
class Base
|
||||
def initialize(clazz, &block)
|
||||
def initialize(clazz, options={}, &block)
|
||||
@clazz = clazz
|
||||
sm = AASM::StateMachine[@clazz]
|
||||
sm.config.column = options[:column].to_sym if options[:column]
|
||||
end
|
||||
|
||||
def state(name, options={})
|
||||
|
|
|
@ -46,9 +46,17 @@ class Simple < ActiveRecord::Base
|
|||
aasm_column :status
|
||||
end
|
||||
|
||||
class SimpleNewDsl < ActiveRecord::Base
|
||||
include AASM
|
||||
aasm :column => :status
|
||||
end
|
||||
|
||||
class Derivate < Simple
|
||||
end
|
||||
|
||||
class DerivateNewDsl < SimpleNewDsl
|
||||
end
|
||||
|
||||
class Thief < ActiveRecord::Base
|
||||
set_table_name "thieves"
|
||||
include AASM
|
||||
|
@ -190,17 +198,22 @@ describe Gate, "instance methods" do
|
|||
end
|
||||
|
||||
describe 'Derivates' do
|
||||
it "should have the same states as it's parent" do
|
||||
it "should have the same states as its parent" do
|
||||
Derivate.aasm_states.should == Simple.aasm_states
|
||||
end
|
||||
|
||||
it "should have the same events as it's parent" do
|
||||
it "should have the same events as its parent" do
|
||||
Derivate.aasm_events.should == Simple.aasm_events
|
||||
end
|
||||
|
||||
it "should have the same column as it's parent" do
|
||||
it "should have the same column as its parent" do
|
||||
Derivate.aasm_column.should == :status
|
||||
end
|
||||
|
||||
it "should have the same column as its parent even for the new dsl" do
|
||||
SimpleNewDsl.aasm_column.should == :status
|
||||
DerivateNewDsl.aasm_column.should == :status
|
||||
end
|
||||
end
|
||||
|
||||
describe AASM::Persistence::ActiveRecordPersistence::NamedScopeMethods do
|
||||
|
|
Loading…
Reference in a new issue