Sha256: 5487881a59083a27a0789eb93fde141cc87fec8e8d9b81e99adbf37a5a6f3db1

Contents?: true

Size: 1.25 KB

Versions: 1

Compression:

Stored size: 1.25 KB

Contents

require_relative 'test_helper'

class MachineWithScopesAndJoinsTest < BaseTestCase
  def setup
    @company = new_model(:company)
    MachineWithScopesAndJoinsTest.const_set('Company', @company)

    @vehicle = new_model(:vehicle) do
      connection.add_column table_name, :company_id, :integer
      belongs_to :company, :class_name => 'MachineWithScopesAndJoinsTest::Company'
    end
    MachineWithScopesAndJoinsTest.const_set('Vehicle', @vehicle)

    @company_machine = StateMachines::Machine.new(@company, :initial => :active)
    @vehicle_machine = StateMachines::Machine.new(@vehicle, :initial => :parked)
    @vehicle_machine.state :idling

    @ford = @company.create
    @mustang = @vehicle.create(:company => @ford)
  end

  def test_should_find_records_in_with_scope
    assert_equal [@mustang], @vehicle.with_states(:parked).joins(:company).where("#{@company.table_name}.state = \"active\"")
  end

  def test_should_find_records_in_without_scope
    assert_equal [@mustang], @vehicle.without_states(:idling).joins(:company).where("#{@company.table_name}.state = \"active\"")
  end

  def teardown
    MachineWithScopesAndJoinsTest.class_eval do
      remove_const('Vehicle')
      remove_const('Company')
    end

    clear_active_support_dependencies
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
state_machines-activerecord-0.9.0 test/machine_with_scopes_and_joins_test.rb