Sha256: 1321ab1b43faf80bb5b0d5543537234fb2586d083d3c962905e71ef0173e652c

Contents?: true

Size: 1.09 KB

Versions: 17

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_sql)
  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

17 entries across 17 versions & 1 rubygems

Version Path
composite_primary_keys-7.0.15 test/test_predicates.rb
composite_primary_keys-8.1.1 test/test_predicates.rb
composite_primary_keys-7.0.14 test/test_predicates.rb
composite_primary_keys-8.1.0 test/test_predicates.rb
composite_primary_keys-7.0.13 test/test_predicates.rb
composite_primary_keys-8.0.0 test/test_predicates.rb
composite_primary_keys-7.0.12 test/test_predicates.rb
composite_primary_keys-7.0.11 test/test_predicates.rb
composite_primary_keys-7.0.10 test/test_predicates.rb
composite_primary_keys-7.0.9 test/test_predicates.rb
composite_primary_keys-7.0.8 test/test_predicates.rb
composite_primary_keys-7.0.7 test/test_predicates.rb
composite_primary_keys-7.0.6 test/test_predicates.rb
composite_primary_keys-7.0.5 test/test_predicates.rb
composite_primary_keys-7.0.4 test/test_predicates.rb
composite_primary_keys-7.0.3 test/test_predicates.rb
composite_primary_keys-7.0.2 test/test_predicates.rb