Sha256: 96260fc09adb60356f320106113557c95861ccbed1aa52b5fe795a86fdcea265

Contents?: true

Size: 1.11 KB

Versions: 21

Compression:

Stored size: 1.11 KB

Contents

require File.expand_path('../abstract_unit', __FILE__)

class TestExists < ActiveSupport::TestCase
  fixtures :articles, :capitols, :departments, :dorms
  
  def test_id
    assert(Dorm.exists?(1))
    refute(Dorm.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?(['id = ? and location_id = ?', 1, 1]))
    assert(!Department.exists?(['id = ? and location_id = ?', 1, -1]))
  end

  def test_cpk_array_string_id
    assert(Capitol.exists?(['The Netherlands', 'Amsterdam']))
    assert(!Capitol.exists?(['The Netherlands', 'Paris']))
  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
composite_primary_keys-14.0.10 test/test_exists.rb
composite_primary_keys-13.0.9 test/test_exists.rb
composite_primary_keys-14.0.9 test/test_exists.rb
composite_primary_keys-14.0.8 test/test_exists.rb
composite_primary_keys-13.0.8 test/test_exists.rb
composite_primary_keys-14.0.7 test/test_exists.rb
composite_primary_keys-14.0.6 test/test_exists.rb
composite_primary_keys-13.0.7 test/test_exists.rb
composite_primary_keys-13.0.6 test/test_exists.rb
composite_primary_keys-14.0.5 test/test_exists.rb
composite_primary_keys-13.0.5 test/test_exists.rb
composite_primary_keys-13.0.4 test/test_exists.rb
composite_primary_keys-14.0.4 test/test_exists.rb
composite_primary_keys-14.0.3 test/test_exists.rb
composite_primary_keys-13.0.3 test/test_exists.rb
composite_primary_keys-14.0.2 test/test_exists.rb
composite_primary_keys-13.0.2 test/test_exists.rb
composite_primary_keys-14.0.1 test/test_exists.rb
composite_primary_keys-13.0.1 test/test_exists.rb
composite_primary_keys-13.0.0 test/test_exists.rb