-
Notifications
You must be signed in to change notification settings - Fork 208
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
- Loading branch information
Vladimir Dobriakov
committed
Aug 2, 2019
1 parent
ace6a11
commit e639523
Showing
2 changed files
with
50 additions
and
10 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,36 @@ | ||
require File.join(File.dirname(__FILE__), 'test_helper') | ||
require 'workflow' | ||
|
||
# Example from the README, TODO: integrate other way around via asciidoctor code inclusion | ||
class Article | ||
include Workflow | ||
workflow do | ||
state :new do | ||
event :submit, :transitions_to => :awaiting_review | ||
end | ||
state :awaiting_review do | ||
event :review, :transitions_to => :being_reviewed | ||
end | ||
state :being_reviewed do | ||
event :accept, :transitions_to => :accepted | ||
event :reject, :transitions_to => :rejected | ||
end | ||
state :accepted | ||
state :rejected | ||
end | ||
end | ||
|
||
class MainTest < Minitest::Test | ||
test 'reflection' do | ||
article2 = Article.new | ||
article2.submit! | ||
article2.review! | ||
assert_equal 2, article2.current_state.events.length | ||
# Please note the usage of `first`, since coditional event transitions can | ||
# define multiple event definitions with the same name | ||
|
||
# tag::reflect[] | ||
assert_equal :rejected, article2.current_state.events[:reject].first.transitions_to | ||
# end::reflect[] | ||
end | ||
end |