strange StateMachine behaviour

E

ErkA

hello I've strange problem with state machine

in my model

state_machine :user_state, :initial => :unconfirmed do
state :unconfirmed, :value => 0
state :confirmed, :value => 1
state :trusted, :value => 2

event :verify do
transition :unconfirmed => :confirmed
end

event :trust do
transition [ :unconfirmed, :confirmed] => :trusted
end
end
-----------

x ==> #<Price id: 88, user_id: 1, station_id: 13157,
session_id: "201924b30b53bd38250d396c252b2847", user_type: 2, price:
#<BigDecimal:9f0bdc0,'0.34E2',4(8)>, user_state: 0, created_at:
"2009-12-10 06:22:06", updated_at: "2009-12-10 07:46:33", ip:
"10.10.10.1">
-----------

x.user_state_transitions
==> [#<StateMachine::Transition attribute=:user_state
event=:verify from=0 from_name=:unconfirmed to=1 to_name=:confirmed>,
#<StateMachine::Transition attribute=:user_state event=:trust from=0
from_name=:unconfirmed to=2 to_name=:trusted>]
-----------
events.valid_for(x)
==> [#<StateMachine::Event name=:verify transitions=[:unconfirmed
=> :confirmed]>, #<StateMachine::Event name=:trust transitions=
[[:unconfirmed, :confirmed] => :trusted]>]

-------- and here we go:
x.verify!
StateMachine::InvalidTransition: Cannot transition user_state
via :verify from :unconfirmed

x.trust!
StateMachine::InvalidTransition: Cannot transition user_state
via :trust from :unconfirmed

on log Im getting only:

SQL (0.0ms) BEGIN
SQL (1.8ms) ROLLBACK

but if I use
x.verify false
==> true

what Im doing wrong or where is the problem?




best regards
ErkA
 
B

Brian Candler

ErkA said:
what Im doing wrong or where is the problem?

No idea. But you haven't said what this StateMachine class is or where
you got it from.

If it's a Rails plugin, you'd be better off asking on a Rails mailing
list. Better still, see if this StateMachine has its own mailing list.
 
A

Aldric Giacomoni

ErkA said:
hello I've strange problem with state machine

in my model

state_machine :user_state, :initial => :unconfirmed do
state :unconfirmed, :value => 0
state :confirmed, :value => 1
state :trusted, :value => 2

event :verify do
transition :unconfirmed => :confirmed
end

event :trust do
transition [ :unconfirmed, :confirmed] => :trusted
end
end
-----------
what Im doing wrong or where is the problem?

I second what Brian said. What -is- this?
Also, you're not actually using :user_state anywhere. What good is it?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,968
Messages
2,570,154
Members
46,701
Latest member
XavierQ83

Latest Threads

Top