@@ -1961,3 +1961,45 @@ def test_in_order_of_with_enums_keys_coerced
19611961 Book . connection . add_index ( :books , [ :author_id , :name ] , unique : true )
19621962 end
19631963end
1964+
1965+ require "models/dashboard"
1966+ class QueryLogsTest < ActiveRecord ::TestCase
1967+ # Same as original coerced test except our SQL ends with binding.
1968+ # TODO: Remove coerce after Rails 7.1.0 (see https://github.com/rails/rails/pull/44053)
1969+ coerce_tests! :test_custom_basic_tags , :test_custom_proc_tags , :test_multiple_custom_tags , :test_custom_proc_context_tags
1970+ def test_custom_basic_tags_coerced
1971+ ActiveRecord ::QueryLogs . tags = [ :application , { custom_string : "test content" } ]
1972+
1973+ assert_sql ( %r{/\* application:active_record,custom_string:test content\* /} ) do
1974+ Dashboard . first
1975+ end
1976+ end
1977+
1978+ def test_custom_proc_tags_coerced
1979+ ActiveRecord ::QueryLogs . tags = [ :application , { custom_proc : -> { "test content" } } ]
1980+
1981+ assert_sql ( %r{/\* application:active_record,custom_proc:test content\* /} ) do
1982+ Dashboard . first
1983+ end
1984+ end
1985+
1986+ def test_multiple_custom_tags_coerced
1987+ ActiveRecord ::QueryLogs . tags = [
1988+ :application ,
1989+ { custom_proc : -> { "test content" } , another_proc : -> { "more test content" } } ,
1990+ ]
1991+
1992+ assert_sql ( %r{/\* application:active_record,custom_proc:test content,another_proc:more test content\* /} ) do
1993+ Dashboard . first
1994+ end
1995+ end
1996+
1997+ def test_custom_proc_context_tags_coerced
1998+ ActiveSupport ::ExecutionContext [ :foo ] = "bar"
1999+ ActiveRecord ::QueryLogs . tags = [ :application , { custom_context_proc : -> ( context ) { context [ :foo ] } } ]
2000+
2001+ assert_sql ( %r{/\* application:active_record,custom_context_proc:bar\* /} ) do
2002+ Dashboard . first
2003+ end
2004+ end
2005+ end
0 commit comments