Sha256: 039d15b4a72a5f11858c76da1fe1beaf981a70c3dc244a7589e2013fc1cbbc40

Contents?: true

Size: 1.09 KB

Versions: 20

Compression:

Stored size: 1.09 KB

Contents

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

class TestEqual < ActiveSupport::TestCase
  fixtures :departments

  include CompositePrimaryKeys::Predicates

  def test_or
    dep = Arel::Table.new(:departments)

    predicates = Array.new

    3.times do |i|
      predicates << dep[:id].eq(i)
    end

    connection = ActiveRecord::Base.connection
    quoted = "#{connection.quote_table_name('departments')}.#{connection.quote_column_name('id')}"
    expected = "((#{quoted} = 0) OR (#{quoted} = 1) OR (#{quoted} = 2))"

    pred = cpk_or_predicate(predicates)
    assert_equal(with_quoted_identifiers(expected), pred.to_s)
  end

  def test_and
    dep = Arel::Table.new(:departments)

    predicates = Array.new

    3.times do |i|
      predicates << dep[:id].eq(i)
    end

    connection = ActiveRecord::Base.connection
    quoted = "#{connection.quote_table_name('departments')}.#{connection.quote_column_name('id')}"
    expected = "#{quoted} = 0 AND #{quoted} = 1 AND #{quoted} = 2"

    pred = cpk_and_predicate(predicates)
    assert_equal(with_quoted_identifiers(expected), pred.to_sql)
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
composite_primary_keys-6.0.8 test/test_predicates.rb
composite_primary_keys-6.0.7 test/test_predicates.rb
composite_primary_keys-6.0.6 test/test_predicates.rb
composite_primary_keys-6.0.5 test/test_predicates.rb
composite_primary_keys-6.0.3 test/test_predicates.rb
composite_primary_keys-5.0.14 test/test_predicates.rb
composite_primary_keys-6.0.1 test/test_predicates.rb
composite_primary_keys-6.0.0 test/test_predicates.rb
composite_primary_keys-5.0.13 test/test_predicates.rb
composite_primary_keys-5.0.12 test/test_predicates.rb
composite_primary_keys-5.0.11 test/test_predicates.rb
composite_primary_keys-5.0.10 test/test_predicates.rb
composite_primary_keys-5.0.9 test/test_predicates.rb
composite_primary_keys-5.0.8 test/test_predicates.rb
composite_primary_keys-5.0.6 test/test_predicates.rb
composite_primary_keys-5.0.5 test/test_predicates.rb
composite_primary_keys-5.0.4 test/test_predicates.rb
composite_primary_keys-5.0.2 test/test_predicates.rb
composite_primary_keys-5.0.1 test/test_predicates.rb
composite_primary_keys-5.0.0 test/test_predicates.rb