Sha256: 20068df356cb602c346b766772f458c562b58fb795fbe73aceb7df155f97f387

Contents?: true

Size: 1.18 KB

Versions: 16

Compression:

Stored size: 1.18 KB

Contents

require_relative 'test_helper'

class MachineWithValidationsTest < BaseTestCase
  def setup
    @model = new_model
    @machine = StateMachines::Machine.new(@model)
    @machine.state :parked

    @record = @model.new
  end

  def test_should_invalidate_using_errors
    I18n.backend = I18n::Backend::Simple.new
    @record.state = 'parked'

    @machine.invalidate(@record, :state, :invalid_transition, [[:event, 'park']])
    assert_equal ['State cannot transition via "park"'], @record.errors.full_messages
  end

  def test_should_auto_prefix_custom_attributes_on_invalidation
    @machine.invalidate(@record, :event, :invalid)

    assert_equal ['State event is invalid'], @record.errors.full_messages
  end

  def test_should_clear_errors_on_reset
    @record.state = 'parked'
    @record.errors.add(:state, 'is invalid')

    @machine.reset(@record)
    assert_equal [], @record.errors.full_messages
  end

  def test_should_be_valid_if_state_is_known
    @record.state = 'parked'

    assert @record.valid?
  end

  def test_should_not_be_valid_if_state_is_unknown
    @record.state = 'invalid'

    refute @record.valid?
    assert_equal ['State is invalid'], @record.errors.full_messages
  end
end

Version data entries

16 entries across 16 versions & 2 rubygems

Version Path
state_machines-activerecord-0.9.0 test/machine_with_validations_test.rb
state_machines-activerecord-0.8.0 test/machine_with_validations_test.rb
state_machines-activerecord-0.6.0 test/machine_with_validations_test.rb
state_machines-activerecord-0.5.2 test/machine_with_validations_test.rb
state_machines-activerecord-0.5.1 test/machine_with_validations_test.rb
state_machines-activerecord-0.5.0 test/machine_with_validations_test.rb
state_machines-activerecord-0.4.1 test/machine_with_validations_test.rb
state_machines-activerecord-0.4.0 test/machine_with_validations_test.rb
state_machines-activerecord-0.4.0.pre test/machine_with_validations_test.rb
solidus_backend-1.0.0.pre3 vendor/bundle/gems/state_machines-activerecord-0.2.0/test/machine_with_validations_test.rb
solidus_backend-1.0.0.pre2 vendor/bundle/gems/state_machines-activerecord-0.2.0/test/machine_with_validations_test.rb
state_machines-activerecord-0.3.0 test/machine_with_validations_test.rb
solidus_backend-1.0.0.pre vendor/bundle/gems/state_machines-activerecord-0.2.0/test/machine_with_validations_test.rb
state_machines-activerecord-0.2.0 test/machine_with_validations_test.rb
state_machines-activerecord-0.1.0 test/machine_with_validations_test.rb
state_machines-activerecord-0.0.1 test/machine_with_validations_test.rb