Sha256: bed5c3df5a1e1ba9a8097b601f440b426d28457c0a590a590194c10704e96b8e

Contents?: true

Size: 1.25 KB

Versions: 5

Compression:

Stored size: 1.25 KB

Contents

require 'mongoid'
require 'mongoid/edge-state-machine'

class MongoOrder
  include Mongoid::Document
  include Mongoid::EdgeStateMachine

  field :state, :type => String
  field :order_number, :type => Integer
  field :paid_at, :type => DateTime
  field :prepared_on, :type => DateTime
  field :dispatched_at, :type => DateTime
  field :cancellation_date, :type => Date

  state_machine do
    state :opened
    state :placed
    state :paid
    state :prepared
    state :delivered
    state :cancelled

    # no timestamp col is being specified here - should be ignored
    event :place do
      transition :from => :opened, :to => :placed
    end

    # should set paid_at timestamp
    event :pay do
      transition :from => :placed, :to => :paid
    end

    # should set prepared_on
    event :prepare do
      transition :from => :paid, :to => :prepared
    end

    # should set dispatched_at
    event :deliver do
      transition :from => :prepared, :to => :delivered
    end

    # should set cancellation_date
    event :cancel do
      transition :from => [:placed, :paid, :prepared], :to => :cancelled
    end

    # should raise an exception as there is no timestamp col
    event :reopen do
      transition :from => :cancelled, :to => :opened
    end

  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
edge-state-machine-1.0.1 spec/mongoid/samples/order.rb
edge-state-machine-1.0.0 spec/mongoid/samples/order.rb
edge-state-machine-0.9.1 spec/mongoid/samples/order.rb
edge-state-machine-0.9.0 spec/mongoid/samples/order.rb
edge-state-machine-0.0.3 spec/mongoid/samples/order.rb