Sha256: 912c9204bbd5de1ab8305613cde15f143b5e6391c25077441f334e85fb95a6de

Contents?: true

Size: 954 Bytes

Versions: 7

Compression:

Stored size: 954 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

7 entries across 7 versions & 1 rubygems

Version Path
composite_primary_keys-4.0.0.beta7 test/test_exists.rb
composite_primary_keys-4.0.0.beta6 test/test_exists.rb
composite_primary_keys-4.0.0.beta5 test/test_exists.rb
composite_primary_keys-4.0.0.beta4 test/test_exists.rb
composite_primary_keys-4.0.0.beta3 test/test_exists.rb
composite_primary_keys-4.0.0.beta2 test/test_exists.rb
composite_primary_keys-4.0.0.beta1 test/test_exists.rb