Sha256: d8f3abcd5e58f020b246630852fe49ad6f61cbd6e419a91d02096e73cc19b216

Contents?: true

Size: 1.25 KB

Versions: 15

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
    ActiveSupport::Dependencies.clear
  end
end

Version data entries

15 entries across 15 versions & 2 rubygems

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