Permalink
Browse files

made some fixes

  • Loading branch information...
1 parent ec3127e commit 0400caf399f2cc02ce3980c735f35a549288ffb1 slagyr committed May 18, 2007
View
10 CHANGES
@@ -1,5 +1,15 @@
= Statemachine Changelog
+== Version 0.4.0
+
+Feature enhancements
+* enabled nested superstate history
+* TransitionMissingException's are raised when the statemachine can't respond to an event
+* Statmachine overrides respond_to? to respond to valid events.
+
+Behavior Fixes
+* fixed default transition so that superstate transitions have priority over default
+
== Version 0.3.0
Feature enhancements
View
2 TODO
@@ -1,4 +1,4 @@
-
+Specific Exceptions... so missing events can be identified.
Maybe:
Implement superstate endstate with automatic transition
@@ -3,6 +3,9 @@ module Statemachine
class StatemachineException < Exception
end
+ class TransitionMissingException < Exception
+ end
+
# Used at runtime to execute the behavior of the statemachine.
# Should be created by using the Statemachine.build method.
#
@@ -86,7 +89,7 @@ def process_event(event, *args)
if transition
transition.invoke(@state, self, args)
else
- raise StatemachineException.new("#{@state} does not respond to the '#{event}' event.")
+ raise TransitionMissingException.new("#{@state} does not respond to the '#{event}' event.")
end
else
raise StatemachineException.new("The state machine isn't in any state while processing the '#{event}' event.")
@@ -104,8 +107,7 @@ def get_state(id) #:nodoc:
superstate_id = base_id(id)
superstate = @states[superstate_id]
raise StatemachineException.new("No history exists for #{superstate} since it is not a super state.") if superstate.is_concrete?
- raise StatemachineException.new("#{superstate} doesn't have any history yet.") if not superstate.history
- return superstate.history
+ return load_history(superstate)
else
state = State.new(id, @root, self)
@states[id] = state
@@ -125,13 +127,24 @@ def has_state(id) #:nodoc:
end
end
+ def respond_to?(message)
+ return true if super(message)
+ return true if @state.transition_for(message)
+ return false
+ end
+
def method_missing(message, *args) #:nodoc:
if @state and @state.transition_for(message)
- method = self.method(:process_event)
- params = [message.to_sym].concat(args)
- method.call(*params)
+ process_event(message.to_sym, *args)
+ # method = self.method(:process_event)
+ # params = [message.to_sym].concat(args)
+ # method.call(*params)
else
- super(message, args)
+ begin
+ super(message, args)
+ rescue NoMethodError
+ process_event(message.to_sym, *args)
+ end
end
end
@@ -145,6 +158,18 @@ def base_id(history_id)
return history_id.to_s[0...-2].to_sym
end
+ def load_history(superstate)
+ 100.times do
+ history = superstate.history
+ raise StatemachineException.new("#{superstate} doesn't have any history yet.") if not history
+ if history.is_concrete?
+ return history
+ else
+ superstate = history
+ end
+ end
+ raise StatemachineException.new("No history found within 100 levels of nested superstates.")
+ end
+
end
-
end
@@ -1,6 +1,6 @@
require File.dirname(__FILE__) + '/../spec_helper'
-context "The AdminController" do
+describe "The AdminController" do
# fixtures :admins
controller_name :admin
@@ -1,38 +1,38 @@
require File.dirname(__FILE__) + '/../spec_helper'
-context "The MainController" do
+describe "The MainController" do
controller_name :main
end
-context "Index View spec" do
+describe "Index View spec" do
controller_name :main
integrate_views
- setup do
+ before(:each) do
@vm = VendingMachine.new
@product = @vm.add_product(10, "Glue", 100)
@vm.save!
post :index, :id => @vm.id
end
- specify "Has required divs" do
- response.should_have_tag :img, :attributes => { :id => "vending_machine_body" }
- response.should_have_tag :img, :attributes => { :id => "money_panel" }
- response.should_have_tag :a, :attributes => { :id => "cash_release_button" }
- response.should_have_tag :div, :attributes => { :id => "product_list" }
- response.should_have_tag :img, :attributes => { :id => "change" }
- response.should_have_tag :div, :attributes => { :id => "change_amount" }
- response.should_have_tag :div, :attributes => { :id => "cash" }
- response.should_have_tag :div, :attributes => { :id => "quartz_screen" }
- response.should_have_tag :div, :attributes => { :id => "dispenser" }
- response.should_have_tag :div, :attributes => { :id => "info" }
+ it "Has required divs" do
+ response.should have_tag(:img, :attributes)=> { :id => "vending_machine_body" }
+ response.should have_tag(:img, :attributes)=> { :id => "money_panel" }
+ response.should have_tag(:a, :attributes)=> { :id => "cash_release_button" }
+ response.should have_tag(:div, :attributes)=> { :id => "product_list" }
+ response.should have_tag(:img, :attributes)=> { :id => "change" }
+ response.should have_tag(:div, :attributes)=> { :id => "change_amount" }
+ response.should have_tag(:div, :attributes)=> { :id => "cash" }
+ response.should have_tag(:div, :attributes)=> { :id => "quartz_screen" }
+ response.should have_tag(:div, :attributes)=> { :id => "dispenser" }
+ response.should have_tag(:div, :attributes)=> { :id => "info" }
end
- specify "products" do
- response.should_have_tag :a, :attributes => { :id => "product_#{@product.id}" }
- response.should_have_tag :span, :attributes => { :id => "product_#{@product.id}_price" }
+ it "products" do
+ response.should have_tag(:a, :attributes)=> { :id => "product_#{@product.id}" }
+ response.should have_tag(:span, :attributes)=> { :id => "product_#{@product.id}_price" }
end
end
@@ -1,5 +1,5 @@
require File.dirname(__FILE__) + '/../spec_helper'
-context "The AdminHelper" do
+describe "The AdminHelper" do
helper_name :admin
end
@@ -1,5 +1,5 @@
require File.dirname(__FILE__) + '/../spec_helper'
-context "The MainHelper" do
+describe "The MainHelper" do
helper_name :main
end
@@ -1,15 +1,15 @@
require File.dirname(__FILE__) + '/../spec_helper'
-context "Product class with fixtures loaded" do
+describe "Product class with fixtures loaded" do
fixtures :products
- specify "Saved with name and price" do
+ it "Saved with name and price" do
saved = Product.new(:name => "Water", :price => 150)
saved.save!
loaded = Product.find(saved.id)
- loaded.name.should_eql "Water"
- loaded.price.should_be 150
+ loaded.name.should eql("Water")
+ loaded.price.should equal 150
end
Oops, something went wrong.

0 comments on commit 0400caf

Please sign in to comment.