…StandardError represents application level exceptions.
Initial state was set using before_validation, which resulted in a nil state for new records. Instead of using the before_validate hook, use the after_initialize hook to make sure the state is properly set.
When an object is freshly initialized, the current_State virtual attribute calls on read_state to get an object's current state, which in turn calls to_sym on the `state` attribute. However, the state attribute of a newly initialized object might return nil, and this causes an exception to be thrown.
When you have a conditional validation, for example: validates(:name, :presence => true, :if => :red?) Then `save!' should raise an exception if transitioning to `red' and `name' isn't valid. Adds a test and changes the `write_state' method for active record to revert to previous state on a failed save.
If it isn't cleared, the returned state may not be consistent with the value of the state attribute.