Sha256: 925f1dadb6a0489a90f943432493827173e9b18d3e622eb788d2d929339451cf
Contents?: true
Size: 915 Bytes
Versions: 4
Compression:
Stored size: 915 Bytes
Contents
# frozen_string_literal: true require "cases/helper" require "models/reply" module ActiveRecord class PredicateBuilderTest < ActiveRecord::TestCase def setup Topic.predicate_builder.register_handler(Regexp, proc do |column, value| Arel::Nodes::InfixOperation.new("~", column, Arel::Nodes.build_quoted(value.source)) end) end def teardown Topic.class_eval { @predicate_builder = nil } end def test_registering_new_handlers assert_match %r{#{Regexp.escape(topic_title)} ~ 'rails'}i, Topic.where(title: /rails/).to_sql end def test_registering_new_handlers_for_association assert_match %r{#{Regexp.escape(topic_title)} ~ 'rails'}i, Reply.joins(:topic).where(topics: { title: /rails/ }).to_sql end private def topic_title Topic.connection.quote_table_name("topics.title") end end end
Version data entries
4 entries across 4 versions & 1 rubygems