Sha256: 17b7d2a7a03a478742a1554f82bd49d521610bd032879221617493ce67e9e269

Contents?: true

Size: 1.66 KB

Versions: 14

Compression:

Stored size: 1.66 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

      field :name, type: String
      field :state, type: String
      validates_presence_of :name, :state

      aasm column: :state, whiny_persistence: true 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 '#create!' do
        it 'raises an exception when a validation fails on create!' do
          assert_raises Mongoid::Errors::Validations do
            @doc = Test.create!
          end
        end
      end

      describe '#save!' do
        it 'raises an exception when a validation fails on save' do
          assert_raises Mongoid::Errors::Validations do
            @doc.save!
          end
        end
      end

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

      describe '#transition' do
        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

14 entries across 14 versions & 1 rubygems

Version Path
rocketjob-3.4.3 test/plugins/state_machine_test.rb
rocketjob-3.4.2 test/plugins/state_machine_test.rb
rocketjob-3.4.1 test/plugins/state_machine_test.rb
rocketjob-3.4.0 test/plugins/state_machine_test.rb
rocketjob-3.3.4 test/plugins/state_machine_test.rb
rocketjob-3.3.3 test/plugins/state_machine_test.rb
rocketjob-3.3.2 test/plugins/state_machine_test.rb
rocketjob-3.3.1 test/plugins/state_machine_test.rb
rocketjob-3.3.0 test/plugins/state_machine_test.rb
rocketjob-3.2.1 test/plugins/state_machine_test.rb
rocketjob-3.2.0 test/plugins/state_machine_test.rb
rocketjob-3.1.0 test/plugins/state_machine_test.rb
rocketjob-3.0.5 test/plugins/state_machine_test.rb
rocketjob-3.0.4 test/plugins/state_machine_test.rb