Sha256: 95e42717bb2c979142316876866507082af6dbad6ebd6e3d6feb26b841c86e2a

Contents?: true

Size: 1.11 KB

Versions: 3

Compression:

Stored size: 1.11 KB

Contents

require_relative 'test_helper'

class MachineWithColumnStateAttributeTest < BaseTestCase
  def setup
    @model = new_model
    @machine = StateMachines::Machine.new(@model, :initial => :parked)
    @machine.other_states(:idling)

    @record = @model.new
  end

  def test_should_not_override_the_column_reader
    @record[:state] = 'parked'
    assert_equal 'parked', @record.state
  end

  def test_should_not_override_the_column_writer
    @record.state = 'parked'
    assert_equal 'parked', @record[:state]
  end

  def test_should_have_an_attribute_predicate
    assert @record.respond_to?(:state?)
  end

  def test_should_test_for_existence_on_predicate_without_parameters
    assert @record.state?

    @record.state = nil
    assert !@record.state?
  end

  def test_should_return_false_for_predicate_if_does_not_match_current_value
    assert !@record.state?(:idling)
  end

  def test_should_return_true_for_predicate_if_matches_current_value
    assert @record.state?(:parked)
  end

  def test_should_raise_exception_for_predicate_if_invalid_state_specified
    assert_raises(IndexError) { @record.state?(:invalid) }
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
state_machines-mongoid-0.2.0 test/machine_with_column_state_attribute_test.rb
state_machines-mongoid-0.1.1 test/machine_with_column_state_attribute_test.rb
state_machines-mongoid-0.1.0 test/machine_with_column_state_attribute_test.rb