File: machine_with_scopes_and_owner_subclass_test.rb

package info (click to toggle)
ruby-state-machines-activerecord 0.9.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 340 kB
  • sloc: ruby: 1,922; makefile: 5
file content (27 lines) | stat: -rw-r--r-- 912 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
require_relative 'test_helper'

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

    @subclass = Class.new(@model)
    @subclass_machine = @subclass.state_machine(:state) {}
    @subclass_machine.state :parked, :idling, :first_gear
  end

  def test_should_only_include_records_with_subclass_states_in_with_scope
    parked = @subclass.create :state => 'parked'
    idling = @subclass.create :state => 'idling'

    assert_equal [parked, idling], @subclass.with_states(:parked, :idling).all
  end

  def test_should_only_include_records_without_subclass_states_in_without_scope
    parked = @subclass.create :state => 'parked'
    idling = @subclass.create :state => 'idling'
    @subclass.create :state => 'first_gear'

    assert_equal [parked, idling], @subclass.without_states(:first_gear).all
  end
end