Sha256: 94829e799a6a98d6d4eeac1297d665b24d006b06df5d256c80b4151e2a6f98d4

Contents?: true

Size: 1.45 KB

Versions: 26

Compression:

Stored size: 1.45 KB

Contents

require 'spec_helper'

describe 'state machine' do
  let(:simple) { SimpleExample.new }

  it 'starts with an initial state' do
    expect(simple.aasm.current_state).to eq(:initialised)
    expect(simple).to respond_to(:initialised?)
    expect(simple).to be_initialised
  end

  it 'allows transitions to other states' do
    expect(simple).to respond_to(:fill_out)
    expect(simple).to respond_to(:fill_out!)
    simple.fill_out!
    expect(simple).to respond_to(:filled_out?)
    expect(simple).to be_filled_out

    expect(simple).to respond_to(:authorise)
    expect(simple).to respond_to(:authorise!)
    simple.authorise
    expect(simple).to respond_to(:authorised?)
    expect(simple).to be_authorised
  end

  it 'denies transitions to other states' do
    expect {simple.authorise}.to raise_error(AASM::InvalidTransition)
    expect {simple.authorise!}.to raise_error(AASM::InvalidTransition)
    simple.fill_out
    expect {simple.fill_out}.to raise_error(AASM::InvalidTransition)
    expect {simple.fill_out!}.to raise_error(AASM::InvalidTransition)
    simple.authorise
    expect {simple.fill_out}.to raise_error(AASM::InvalidTransition)
    expect {simple.fill_out!}.to raise_error(AASM::InvalidTransition)
  end

  it 'defines constants for each state name' do
    expect(SimpleExample::STATE_INITIALISED).to eq(:initialised)
    expect(SimpleExample::STATE_FILLED_OUT).to eq(:filled_out)
    expect(SimpleExample::STATE_AUTHORISED).to eq(:authorised)
  end
end

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
aasm-5.0.6 spec/unit/simple_example_spec.rb
aasm-5.0.5 spec/unit/simple_example_spec.rb
aasm-5.0.4 spec/unit/simple_example_spec.rb
aasm-5.0.3 spec/unit/simple_example_spec.rb
aasm-5.0.2 spec/unit/simple_example_spec.rb
aasm-5.0.1 spec/unit/simple_example_spec.rb
aasm-5.0.0 spec/unit/simple_example_spec.rb
aasm-4.12.3 spec/unit/simple_example_spec.rb
aasm-4.12.2 spec/unit/simple_example_spec.rb
aasm-4.12.1 spec/unit/simple_example_spec.rb
aasm-4.12.0 spec/unit/simple_example_spec.rb
aasm-4.11.1 spec/unit/simple_example_spec.rb
aasm-4.11.0 spec/unit/simple_example_spec.rb
aasm-4.10.1 spec/unit/simple_example_spec.rb
aasm-4.10.0 spec/unit/simple_example_spec.rb
aasm-4.9.0 spec/unit/simple_example_spec.rb
aasm-4.8.0 spec/unit/simple_example_spec.rb
aasm-4.7.0 spec/unit/simple_example_spec.rb
aasm-4.6.0 spec/unit/simple_example_spec.rb
aasm-4.5.2 spec/unit/simple_example_spec.rb