From b22ceb279248f85003cc50bb158fa4d0db9dc4d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorsten=20Bo=CC=88ttger?= Date: Fri, 25 Nov 2011 23:39:37 +0100 Subject: [PATCH] new dsl now supports changing the states column name --- lib/aasm/aasm.rb | 4 ++-- lib/aasm/base.rb | 4 +++- spec/unit/active_record_persistence_spec.rb | 19 ++++++++++++++++--- 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/lib/aasm/aasm.rb b/lib/aasm/aasm.rb index 07ad46b..c286d7c 100644 --- a/lib/aasm/aasm.rb +++ b/lib/aasm/aasm.rb @@ -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 diff --git a/lib/aasm/base.rb b/lib/aasm/base.rb index 852af09..9b9e8b2 100644 --- a/lib/aasm/base.rb +++ b/lib/aasm/base.rb @@ -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={}) diff --git a/spec/unit/active_record_persistence_spec.rb b/spec/unit/active_record_persistence_spec.rb index 61135dc..36373f3 100644 --- a/spec/unit/active_record_persistence_spec.rb +++ b/spec/unit/active_record_persistence_spec.rb @@ -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