Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
New workflow definition cleanly undefines the old convinience methods…
…, s. also #92, #69 * works on both subclassing and dynamic workflow spec assignment * solving problems caused by metaprogramming with even more metaprogramming ;-)
- Loading branch information
Showing
2 changed files
with
88 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
require File.join(File.dirname(__FILE__), 'test_helper') | ||
require 'workflow' | ||
class InheritanceTest < ActiveRecordTestCase | ||
|
||
test '#69 inheritance' do | ||
class Animal | ||
include Workflow | ||
|
||
workflow do | ||
|
||
state :conceived do | ||
event :birth, :transition_to => :born | ||
end | ||
|
||
state :born do | ||
|
||
end | ||
end | ||
end | ||
|
||
class Cat < Animal | ||
include Workflow | ||
workflow do | ||
|
||
state :upset do | ||
event :scratch, :transition_to => :hiding | ||
end | ||
|
||
state :hiding do | ||
|
||
end | ||
end | ||
end | ||
|
||
assert_equal [:born, :conceived] , Animal.workflow_spec.states.keys.sort | ||
assert_equal [:hiding, :upset], Cat.workflow_spec.states.keys.sort, "Workflow definitions are not inherited" | ||
|
||
animal = Animal.new | ||
cat = Cat.new | ||
|
||
animal.birth! | ||
|
||
assert_raise NoMethodError, 'Methods defined by the old workflow spec should have be gone away' do | ||
cat.birth! | ||
end | ||
|
||
assert_equal [:birth!, :halt!, :process_event!], bang_methods(animal) | ||
assert_equal [:halt!, :process_event!, :scratch!], bang_methods(cat) | ||
end | ||
|
||
def bang_methods(obj) | ||
(obj.public_methods-Object.public_methods).select {|m| m =~ /!$/}.sort | ||
end | ||
end |