Sha256: 81a5478d507e83f5ce575e757b118dc559cf6e0aa5306eda7772ff53778adfd5

Contents?: true

Size: 1.5 KB

Versions: 7

Compression:

Stored size: 1.5 KB

Contents

require_relative '../test_helper'

module Plugins
  # Unit Test for RocketJob::Job
  class StateMachineTest < Minitest::Test

    class Test
      include RocketJob::Plugins::Document
      include RocketJob::Plugins::StateMachine

      key :name
      key :state
      validates_presence_of :name, :state

      aasm column: :state do
        state :pending, initial: true
        state :enabled

        event :enable do
          transitions from: :pending, to: :enabled
        end
      end
    end

    describe RocketJob::Plugins::StateMachine do
      before do
        @doc = Test.new
      end

      after do
        @doc.destroy if @doc && !@doc.new_record?
      end

      describe '#aasm_write_state' do
        it 'raises an exception when a validation fails on create!' do
          assert_raises MongoMapper::DocumentNotValid do
            @doc = Test.create!
          end
        end

        it 'raises an exception when a validation fails on save' do
          assert_raises MongoMapper::DocumentNotValid do
            @doc.save!
          end
        end

        it 'raises an exception when a validation fails on state transition with save' do
          assert_raises MongoMapper::DocumentNotValid do
            @doc.enable!
          end
          assert @doc.pending?
          refute @doc.valid?
        end

        it 'does not raise an exception when a validation fails on state transition without save' do
          @doc.enable
          assert @doc.enabled?
        end

      end

    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
rocketjob-2.1.3 test/plugins/state_machine_test.rb
rocketjob-2.1.2 test/plugins/state_machine_test.rb
rocketjob-2.1.1 test/plugins/state_machine_test.rb
rocketjob-2.0.0 test/plugins/state_machine_test.rb
rocketjob-2.0.0.rc3 test/plugins/state_machine_test.rb
rocketjob-2.0.0.rc2 test/plugins/state_machine_test.rb
rocketjob-2.0.0.rc1 test/plugins/state_machine_test.rb