@@ -1961,3 +1961,44 @@ 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+ coerce_tests! :test_custom_basic_tags , :test_custom_proc_tags , :test_multiple_custom_tags , :test_custom_proc_context_tags
1969+ def test_custom_basic_tags_coerced
1970+ ActiveRecord ::QueryLogs . tags = [ :application , { custom_string : "test content" } ]
1971+
1972+ assert_sql ( %r{/\* application:active_record,custom_string:test content\* /} ) do
1973+ Dashboard . first
1974+ end
1975+ end
1976+
1977+ def test_custom_proc_tags_coerced
1978+ ActiveRecord ::QueryLogs . tags = [ :application , { custom_proc : -> { "test content" } } ]
1979+
1980+ assert_sql ( %r{/\* application:active_record,custom_proc:test content\* /} ) do
1981+ Dashboard . first
1982+ end
1983+ end
1984+
1985+ def test_multiple_custom_tags_coerced
1986+ ActiveRecord ::QueryLogs . tags = [
1987+ :application ,
1988+ { custom_proc : -> { "test content" } , another_proc : -> { "more test content" } } ,
1989+ ]
1990+
1991+ assert_sql ( %r{/\* application:active_record,custom_proc:test content,another_proc:more test content\* /} ) do
1992+ Dashboard . first
1993+ end
1994+ end
1995+
1996+ def test_custom_proc_context_tags_coerced
1997+ ActiveSupport ::ExecutionContext [ :foo ] = "bar"
1998+ ActiveRecord ::QueryLogs . tags = [ :application , { custom_context_proc : -> ( context ) { context [ :foo ] } } ]
1999+
2000+ assert_sql ( %r{/\* application:active_record,custom_context_proc:bar\* /} ) do
2001+ Dashboard . first
2002+ end
2003+ end
2004+ end
0 commit comments