Sha256: 40c743185b3a76733235256619ab5706fe4e5e942052d6e006d2bf8d4d2295f3

Contents?: true

Size: 874 Bytes

Versions: 18

Compression:

Stored size: 874 Bytes

Contents

require_relative 'test_helper'

class MachineWithStateDrivenValidationsTest < BaseTestCase
  def setup
    @model = new_model do
      include ActiveModel::Validations
      attr_accessor :seatbelt
    end

    @machine = StateMachines::Machine.new(@model)
    @machine.state :first_gear, :second_gear do
      validates_presence_of :seatbelt
    end
    @machine.other_states :parked
  end

  def test_should_be_valid_if_validation_fails_outside_state_scope
    record = @model.new(state: 'parked', seatbelt: nil)
    assert record.valid?
  end

  def test_should_be_invalid_if_validation_fails_within_state_scope
    record = @model.new(state: 'first_gear', seatbelt: nil)
    assert !record.valid?
  end

  def test_should_be_valid_if_validation_succeeds_within_state_scope
    record = @model.new(state: 'second_gear', seatbelt: true)
    assert record.valid?
  end
end

Version data entries

18 entries across 18 versions & 2 rubygems

Version Path
state_machines-activemodel-0.9.0 test/machine_with_state_driven_validations_test.rb
state_machines-activemodel-0.8.0 test/machine_with_state_driven_validations_test.rb
state_machines-activemodel-0.7.1 test/machine_with_state_driven_validations_test.rb
state_machines-activemodel-0.7.0 test/machine_with_state_driven_validations_test.rb
state_machines-activemodel-0.6.0 test/machine_with_state_driven_validations_test.rb
state_machines-activemodel-0.5.1 test/machine_with_state_driven_validations_test.rb
state_machines-activemodel-0.5.0 test/machine_with_state_driven_validations_test.rb
state_machines-activemodel-0.4.1 test/machine_with_state_driven_validations_test.rb
state_machines-activemodel-0.4.0 test/machine_with_state_driven_validations_test.rb
state_machines-activemodel-0.4.0.pre test/machine_with_state_driven_validations_test.rb
solidus_backend-1.0.0.pre3 vendor/bundle/gems/state_machines-activemodel-0.1.2/test/machine_with_state_driven_validations_test.rb
solidus_backend-1.0.0.pre2 vendor/bundle/gems/state_machines-activemodel-0.1.2/test/machine_with_state_driven_validations_test.rb
solidus_backend-1.0.0.pre vendor/bundle/gems/state_machines-activemodel-0.1.2/test/machine_with_state_driven_validations_test.rb
state_machines-activemodel-0.3.0 test/machine_with_state_driven_validations_test.rb
state_machines-activemodel-0.2.0 test/machine_with_state_driven_validations_test.rb
state_machines-activemodel-0.1.2 test/machine_with_state_driven_validations_test.rb
state_machines-activemodel-0.1.1 test/machine_with_state_driven_validations_test.rb
state_machines-activemodel-0.0.3 test/machine_with_state_driven_validations_test.rb