1
0
Fork 0
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:
Thorsten Böttger 2011-11-25 23:39:37 +01:00
parent 4dcc7a5862
commit b22ceb2792
3 changed files with 21 additions and 6 deletions

View file

@ -21,8 +21,8 @@ module AASM
super super
end end
def aasm(&block) def aasm(options={}, &block)
@aasm ||= AASM::Base.new(self) @aasm ||= AASM::Base.new(self, options)
@aasm.instance_eval(&block) if block @aasm.instance_eval(&block) if block
@aasm @aasm
end end

View file

@ -1,7 +1,9 @@
module AASM module AASM
class Base class Base
def initialize(clazz, &block) def initialize(clazz, options={}, &block)
@clazz = clazz @clazz = clazz
sm = AASM::StateMachine[@clazz]
sm.config.column = options[:column].to_sym if options[:column]
end end
def state(name, options={}) def state(name, options={})

View file

@ -46,9 +46,17 @@ class Simple < ActiveRecord::Base
aasm_column :status aasm_column :status
end end
class SimpleNewDsl < ActiveRecord::Base
include AASM
aasm :column => :status
end
class Derivate < Simple class Derivate < Simple
end end
class DerivateNewDsl < SimpleNewDsl
end
class Thief < ActiveRecord::Base class Thief < ActiveRecord::Base
set_table_name "thieves" set_table_name "thieves"
include AASM include AASM
@ -190,17 +198,22 @@ describe Gate, "instance methods" do
end end
describe 'Derivates' do 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 Derivate.aasm_states.should == Simple.aasm_states
end 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 Derivate.aasm_events.should == Simple.aasm_events
end 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 Derivate.aasm_column.should == :status
end 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 end
describe AASM::Persistence::ActiveRecordPersistence::NamedScopeMethods do describe AASM::Persistence::ActiveRecordPersistence::NamedScopeMethods do