Sha256: b6c20167185b977d0f53d53a73ded936b212a721b09c42f11f134bdc3f9aa101

Contents?: true

Size: 956 Bytes

Versions: 3

Compression:

Stored size: 956 Bytes

Contents

require './abstract_unit'

class TestExists < ActiveSupport::TestCase
  fixtures :articles, :departments
  
  def test_id
    assert(Article.exists?(1))
    assert(!Article.exists?(-1))
  end

  def test_array
    assert(Article.exists?(['name = ?', 'Article One']))
    assert(!Article.exists?(['name = ?', 'Article -1']))
  end

  def test_hash
    assert(Article.exists?('name' => 'Article One'))
    assert(!Article.exists?('name' => 'Article -1'))
  end

  def test_cpk_id
    assert(Department.exists?(CompositePrimaryKeys::CompositeKeys.new([1,1])))
    assert(!Department.exists?(CompositePrimaryKeys::CompositeKeys.new([1,-1])))
  end

  def test_cpk_array_id
    assert(Department.exists?([1,1]))
    assert(!Department.exists?([1,-1]))
  end

  def test_cpk_array_condition
    assert(Department.exists?(['department_id = ? and location_id = ?', 1, 1]))
    assert(!Department.exists?(['department_id = ? and location_id = ?', 1, -1]))
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
composite_primary_keys-4.0.0 test/test_exists.rb
composite_primary_keys-4.0.0.beta9 test/test_exists.rb
composite_primary_keys-4.0.0.beta8 test/test_exists.rb