Skip to content

Commit

Permalink
fix(QueryBuilder): Fix incorrect structAppend overwrites
Browse files Browse the repository at this point in the history
  • Loading branch information
elpete committed Jun 18, 2020
1 parent 004b045 commit ad770d2
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
2 changes: 1 addition & 1 deletion models/Grammars/AutoDiscover.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ component singleton {
property name="grammar";

function autoDiscoverGrammar() {
cfdbinfo( type="Version", name="local.dbInfo" );
cfdbinfo( type = "Version", name = "local.dbInfo" );

switch ( dbInfo.DATABASE_PRODUCTNAME ) {
case "MySQL":
Expand Down
4 changes: 2 additions & 2 deletions models/Query/QueryBuilder.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -2152,7 +2152,7 @@ component displayname="QueryBuilder" accessors="true" {
* @return query
*/
public any function update( struct values = {}, struct options = {}, boolean toSql = false ) {
structAppend( arguments.values, variables.updates );
structAppend( arguments.values, variables.updates, false );
var updateArray = arguments.values
.keyArray()
.map( function( column ) {
Expand Down Expand Up @@ -2636,7 +2636,7 @@ component displayname="QueryBuilder" accessors="true" {
* @return any
*/
private any function runQuery( required string sql, struct options = {}, string returnObject = "query" ) {
structAppend( arguments.options, getDefaultOptions() );
structAppend( arguments.options, getDefaultOptions(), false );
var result = grammar.runQuery(
sql,
getBindings(),
Expand Down
17 changes: 17 additions & 0 deletions tests/specs/Query/Abstract/QueryDefaultsSpec.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,23 @@ component extends="testbox.system.BaseSpec" {
expect( options ).toHaveKey( "datasource" );
expect( options.datasource ).toBe( "foo" );
} );

it( "can override default options at the call site", function() {
var grammar = getMockBox().createMock( "qb.models.Grammars.BaseGrammar" ).init();
var builder = getMockBox().createMock( "qb.models.Query.QueryBuilder" ).init( grammar );
builder.setDefaultOptions( { "datasource": "foo" } );
var expectedQuery = queryNew( "id", "integer", [ { id: 1 } ] );
grammar.$( "runQuery", expectedQuery );
builder
.select( "id" )
.from( "users" )
.get( options = { "datasource": "bar" } );
expect( grammar.$once( "runQuery" ) ).toBeTrue( "runQuery should have been called once." );
var options = grammar.$callLog().runQuery[ 1 ][ 3 ];
expect( options ).toBeStruct();
expect( options ).toHaveKey( "datasource" );
expect( options.datasource ).toBe( "bar" );
} );
} );
}

Expand Down

0 comments on commit ad770d2

Please sign in to comment.