-
Notifications
You must be signed in to change notification settings - Fork 37
Expand file tree
/
Copy pathShouldWrapValuesSpec.cfc
More file actions
61 lines (40 loc) · 2.81 KB
/
Copy pathShouldWrapValuesSpec.cfc
File metadata and controls
61 lines (40 loc) · 2.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
component extends="testbox.system.BaseSpec" {
function run() {
describe( "shouldWrapValues setting", function() {
it( "defaults to true in BaseGrammar", function() {
var utils = getMockBox().createMock( "qb.models.Query.QueryUtils" ).init();
var grammar = getMockBox().createMock( "qb.models.Grammars.PostgresGrammar" ).init( utils );
expect( grammar.getShouldWrapValues() ).toBeTrue( "shouldWrapValues should default to true" );
} );
it( "wraps identifiers in double quotes when shouldWrapValues is true", function() {
var utils = getMockBox().createMock( "qb.models.Query.QueryUtils" ).init();
var grammar = getMockBox().createMock( "qb.models.Grammars.PostgresGrammar" ).init( utils );
grammar.setShouldWrapValues( true );
var builder = getMockBox().createMock( "qb.models.Query.QueryBuilder" ).init( grammar );
var sql = builder.from( "users" ).select( "name" ).toSQL();
expect( sql ).toBe( 'SELECT "name" FROM "users"' );
sql = builder.from( "users" ).select( "id" ).where( "email", "test@test.com" ).toSQL( withBindings = true );
expect( sql ).toBe( 'SELECT "id" FROM "users" WHERE "email" = ?' );
} );
it( "does not wrap identifiers when shouldWrapValues is false", function() {
var utils = getMockBox().createMock( "qb.models.Query.QueryUtils" ).init();
var grammar = getMockBox().createMock( "qb.models.Grammars.PostgresGrammar" ).init( utils );
grammar.setShouldWrapValues( false );
var builder = getMockBox().createMock( "qb.models.Query.QueryBuilder" ).init( grammar );
var sql = builder.from( "users" ).select( "name" ).toSQL();
expect( sql ).toBe( "SELECT name FROM users" );
sql = builder.from( "users" ).select( "id" ).where( "email", "test@test.com" ).toSQL();
expect( sql ).toBe( "SELECT id FROM users WHERE email = ?" );
} );
it( "per-query withoutWrappingValues overrides grammar default", function() {
var utils = getMockBox().createMock( "qb.models.Query.QueryUtils" ).init();
var grammar = getMockBox().createMock( "qb.models.Grammars.PostgresGrammar" ).init( utils );
grammar.setShouldWrapValues( true );
var builder = getMockBox().createMock( "qb.models.Query.QueryBuilder" ).init( grammar );
// Grammar default is true, but per-query override to false
var sql = builder.withoutWrappingValues().from( "users" ).select( "name" ).toSQL();
expect( sql ).toBe( "SELECT name FROM users" );
} );
} );
}
}