Sha256: 988b1e1b0d21557c3fa837ff844478e20f0cc33af0addd88890c9fc11febc753

Contents?: true

Size: 852 Bytes

Versions: 3

Compression:

Stored size: 852 Bytes

Contents

require 'abstract_unit'
require 'fixtures/article'
require 'fixtures/department'

class TestExists < ActiveSupport::TestCase
  fixtures :articles, :departments
  
  def test_single_key_exists_giving_id
    assert Article.exists?(1)
  end
  
  def test_single_key_exists_giving_condition
    assert Article.exists?(['name = ?', 'Article One'])
  end
  
  def test_composite_key_exists_giving_ids_as_string
    assert Department.exists?('1,1,')
  end
  
  def test_composite_key_exists_giving_ids_as_array
    assert Department.exists?([1,1])
    assert_equal(false, Department.exists?([1111,1111]))
  end
  
  def test_composite_key_exists_giving_ids_as_condition
    assert Department.exists?(['department_id = ? and location_id = ?', 1, 1])
    assert_equal(false, Department.exists?(['department_id = ? and location_id = ?', 11111, 11111]))
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
composite_primary_keys-2.3.5.1 test/test_exists.rb
composite_primary_keys-2.3.5 test/test_exists.rb
composite_primary_keys-2.3.2 test/test_exists.rb