Skip to content

Commit

Permalink
fix(QueryBuilder): Add a type to the onMissingMethod exception
Browse files Browse the repository at this point in the history
Adding a type allows other libraries to better detect and provide
more context for missing methods.
  • Loading branch information
elpete committed Jan 25, 2020
1 parent 119e434 commit 90d1093
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 14 deletions.
2 changes: 1 addition & 1 deletion models/Grammars/BaseGrammar.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ component displayname="Grammar" accessors="true" singleton {
*
* @return qb.models.Grammars.BaseGrammar
*/
public BaseGrammar function init( qb.models.Query.QueryUtils utils = new qb.models.Query.QueryUtils( ) {
public BaseGrammar function init( qb.models.Query.QueryUtils utils = new qb.models.Query.QueryUtils() ) {
variables.utils = arguments.utils;
variables.tablePrefix = "";
// These are overwritten by WireBox, if it exists.
Expand Down
2 changes: 1 addition & 1 deletion models/Query/QueryBuilder.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -2625,7 +2625,7 @@ component displayname="QueryBuilder" accessors="true" {
return invoke( variables.parentQuery.populateQuery( this ), missingMethodName, missingMethodArguments );
}

throw( "Method does not exist on QueryBuilder [#missingMethodName#]" );
throw( type = "QBMissingMethod", message = "Method does not exist on QueryBuilder [#missingMethodName#]" );
}

/**
Expand Down
9 changes: 9 additions & 0 deletions test.cfc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
component {

function test() {
describe( "someting", function() {
query;
} );
}

}
28 changes: 23 additions & 5 deletions tests/resources/AbstractSchemaBuilderSpec.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,11 @@ component extends="testbox.system.BaseSpec" {
table.unicodeString( "first_name" );
table.unicodeString( "last_name" );
table.unicodeString( "password", 100 );
table;
table
.unsignedInteger( "country_id" )
.references( "id" )
.onTable( "countries" )
.onDelete( "CASCADE" );
table.timestamp( "created_date" ).setDefault( "CURRENT_TIMESTAMP" );
table.timestamp( "modified_date" ).setDefault( "CURRENT_TIMESTAMP" );
},
Expand Down Expand Up @@ -1301,7 +1305,10 @@ component extends="testbox.system.BaseSpec" {
return schema.create(
"posts",
function( table ) {
table;
table
.unsignedInteger( "author_id" )
.references( "id" )
.onTable( "users" );
},
{},
false
Expand All @@ -1315,7 +1322,10 @@ component extends="testbox.system.BaseSpec" {
"posts",
function( table ) {
table.unsignedInteger( "author_id" );
table;
table
.foreignKey( "author_id" )
.references( "id" )
.onTable( "users" );
},
{},
false
Expand All @@ -1328,7 +1338,11 @@ component extends="testbox.system.BaseSpec" {
return schema.create(
"posts",
function( table ) {
table;
table
.unsignedInteger( "author_id" )
.references( "id" )
.onTable( "users" )
.setName( "fk_author" );
},
{},
false
Expand All @@ -1342,7 +1356,11 @@ component extends="testbox.system.BaseSpec" {
"posts",
function( table ) {
table.unsignedInteger( "author_id" );
table;
table
.foreignKey( "author_id" )
.references( "id" )
.onTable( "users" )
.setName( "fk_author" );
},
{},
false
Expand Down
10 changes: 4 additions & 6 deletions tests/specs/Query/Abstract/BuilderGetSpec.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,9 @@ component extends="testbox.system.BaseSpec" {
} );

it( "retreives bindings in a flat array", function() {
query {
query.join( "second", function( join ) {
join.where( "second.locale", "=", "en-US" );
}
).where( "first.quantity", ">=", 10 );
} ).where( "first.quantity", ">=", 10 );

var bindings = query.getBindings();
expect( bindings ).toBeArray();
Expand All @@ -46,10 +45,9 @@ component extends="testbox.system.BaseSpec" {
} );

it( "retreives a map of bindings", function() {
query {
query.join( "second", function( join ) {
join.where( "second.locale", "=", "en-US" );
}
).where( "first.quantity", ">=", "10" );
} ).where( "first.quantity", ">=", "10" );

var bindings = query.getRawBindings();

Expand Down
9 changes: 8 additions & 1 deletion tests/specs/Query/Abstract/BuilderWhereSpec.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,14 @@ component extends="testbox.system.BaseSpec" {
} );

it( "can be specify the boolean combinator", function() {
query;
query
.where( "::some column::", "=", "::some value::" )
.where(
"::another column::",
"=",
"::another value::",
"or"
);
expect( query.getWheres() ).toBe( [
{
column: "::some column::",
Expand Down

0 comments on commit 90d1093

Please sign in to comment.