mirror of
https://github.com/aasm/aasm
synced 2023-03-27 23:22:41 -04:00
Take state column for AR persistance out of class variables and add them to the
StateMachine object.
This commit is contained in:
parent
2d87b4b3b1
commit
3d69497ee3
5 changed files with 36 additions and 6 deletions
lib
spec
|
@ -8,6 +8,9 @@ module AASM
|
|||
end
|
||||
|
||||
def self.included(base) #:nodoc:
|
||||
# TODO - need to ensure that a machine is being created because
|
||||
# AASM was either included or arrived at via inheritance. It
|
||||
# cannot be both.
|
||||
base.extend AASM::ClassMethods
|
||||
AASM::Persistence.set_persistence(base)
|
||||
AASM::StateMachine[base] = AASM::StateMachine.new('')
|
||||
|
|
|
@ -79,11 +79,14 @@ module AASM
|
|||
# This method is both a getter and a setter
|
||||
def aasm_column(column_name=nil)
|
||||
if column_name
|
||||
@aasm_column = column_name.to_sym
|
||||
AASM::StateMachine[self].config.column = column_name.to_sym
|
||||
# @aasm_column = column_name.to_sym
|
||||
else
|
||||
@aasm_column ||= :aasm_state
|
||||
AASM::StateMachine[self].config.column ||= :aasm_state
|
||||
# @aasm_column ||= :aasm_state
|
||||
end
|
||||
@aasm_column
|
||||
# @aasm_column
|
||||
AASM::StateMachine[self].config.column
|
||||
end
|
||||
|
||||
def find_in_state(number, state, *args)
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
require 'ostruct'
|
||||
|
||||
module AASM
|
||||
class StateMachine
|
||||
def self.[](*args)
|
||||
|
@ -9,7 +11,7 @@ module AASM
|
|||
(@machines ||= {})[args] = val
|
||||
end
|
||||
|
||||
attr_accessor :states, :events, :initial_state
|
||||
attr_accessor :states, :events, :initial_state, :config
|
||||
attr_reader :name
|
||||
|
||||
def initialize(name)
|
||||
|
@ -17,6 +19,7 @@ module AASM
|
|||
@initial_state = nil
|
||||
@states = []
|
||||
@events = {}
|
||||
@config = OpenStruct.new
|
||||
end
|
||||
|
||||
def create_state(name, options)
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
require File.join(File.dirname(__FILE__), 'conversation')
|
||||
|
||||
describe Conversation, 'description' do
|
||||
it '.aasm_states should contain all of the states' do
|
||||
Conversation.aasm_states.should == [:needs_attention, :read, :closed, :awaiting_response, :junk]
|
||||
|
|
|
@ -43,6 +43,14 @@ begin
|
|||
include AASM
|
||||
end
|
||||
|
||||
class June < ActiveRecord::Base
|
||||
include AASM
|
||||
aasm_column :status
|
||||
end
|
||||
|
||||
class Beaver < June
|
||||
end
|
||||
|
||||
describe "aasm model", :shared => true do
|
||||
it "should include AASM::Persistence::ActiveRecordPersistence" do
|
||||
@klass.included_modules.should be_include(AASM::Persistence::ActiveRecordPersistence)
|
||||
|
@ -178,6 +186,21 @@ begin
|
|||
|
||||
end
|
||||
|
||||
describe 'Beavers' do
|
||||
it "should have the same states as it's parent" do
|
||||
Beaver.aasm_states.should == June.aasm_states
|
||||
end
|
||||
|
||||
it "should have the same events as it's parent" do
|
||||
Beaver.aasm_events.should == June.aasm_events
|
||||
end
|
||||
|
||||
it "should have the same column as it's parent" do
|
||||
Beaver.aasm_column.should == :status
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
# TODO: figure out how to test ActiveRecord reload! without a database
|
||||
|
||||
rescue LoadError => e
|
||||
|
|
Loading…
Add table
Reference in a new issue