def METHOD_NAME(
    self,
    field,
    connection,
    resource_id,
    lang=None,
    cast=False,
    method="gist",
):
    field = u'"{0}"'.format(field)
    if cast:
        field = u"cast({0} AS text)".format(field)
    if lang is not None:
        sql_str = (
            u'ON "resource_id" '
            u"USING {method}(to_tsvector('{lang}', {field}))"
        )
        sql_str = sql_str.format(method=method, lang=lang, field=field)
    else:
        sql_str = u"USING {method}({field})".format(
            method=method, field=field
        )
    calls = connection.execute.call_args_list
    was_called = [call for call in calls if call[0][0].find(sql_str) != -1]
    assert was_called, (
        "Expected 'connection.execute' to have been "
        "called with a string containing '%s'" % sql_str
    )