Sha256: 653121cab059dd7bc1d1e541471d737606a266e37ff9a7edfd74dbde13a40b5f

Contents?: true

Size: 1.42 KB

Versions: 18

Compression:

Stored size: 1.42 KB

Contents

require 'spec_helper'

describe 'subclassing' do

  it 'should have the parent states' do
    SuperClass.aasm.states.each do |state|
      expect(SubClassWithMoreStates.aasm.states).to include(state)
    end
    expect(SubClass.aasm.states).to eq(SuperClass.aasm.states)
  end

  it 'should not add the child states to the parent machine' do
    expect(SuperClass.aasm.states).not_to include(:foo)
  end

  it 'should have the same events as its parent' do
    expect(SubClass.aasm.events).to eq(SuperClass.aasm.events)
  end

  it 'should know how to respond to question methods' do
    expect(SubClass.new.may_foo?).to be_truthy
  end

  it 'should not break if I call methods from super class' do
    son = SubClass.new
    son.update_state
    expect(son.aasm.current_state).to eq(:ended)
  end

  it 'should allow the child to modify its state machine' do
    son = SubClass.new
    expect(son.called_after).to eq(nil)
    son.foo
    expect(son.called_after).to eq(true)
    global_callbacks = SubClass.aasm.state_machine.global_callbacks
    expect(global_callbacks).to_not be_empty
    expect(global_callbacks[:after_all_transitions]).to eq :after_all_event
  end

  it 'should not modify the parent state machine' do
    super_class_event = SuperClass.aasm.events.select { |event| event.name == :foo }.first
    expect(super_class_event.options).to be_empty
    expect(SuperClass.aasm.state_machine.global_callbacks).to be_empty
  end

end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
aasm-5.3.1 spec/unit/subclassing_spec.rb
aasm-5.3.0 spec/unit/subclassing_spec.rb
aasm-5.2.0 spec/unit/subclassing_spec.rb
aasm-5.1.1 spec/unit/subclassing_spec.rb
aasm-5.1.0 spec/unit/subclassing_spec.rb
aasm-5.0.8 spec/unit/subclassing_spec.rb
aasm-5.0.7 spec/unit/subclassing_spec.rb
aasm-5.0.6 spec/unit/subclassing_spec.rb
aasm-5.0.5 spec/unit/subclassing_spec.rb
aasm-5.0.4 spec/unit/subclassing_spec.rb
aasm-5.0.3 spec/unit/subclassing_spec.rb
aasm-5.0.2 spec/unit/subclassing_spec.rb
aasm-5.0.1 spec/unit/subclassing_spec.rb
aasm-5.0.0 spec/unit/subclassing_spec.rb
aasm-4.12.3 spec/unit/subclassing_spec.rb
aasm-4.12.2 spec/unit/subclassing_spec.rb
aasm-4.12.1 spec/unit/subclassing_spec.rb
aasm-4.12.0 spec/unit/subclassing_spec.rb