Skip to content

Commit

Permalink
Remove the need to return a query in a when callback.
Browse files Browse the repository at this point in the history
  • Loading branch information
Eric Peterson authored and Eric Peterson committed Nov 29, 2016
1 parent e19dae3 commit 657d47c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
7 changes: 6 additions & 1 deletion models/Query/Builder.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,12 @@ component displayname="Builder" accessors="true" {
onTrue,
onFalse = function( q ) { return q; }
) {
return condition ? onTrue( this ) : onFalse( this );
if ( condition ) {
onTrue( this );
} else {
onFalse( this );
}
return this;
}

// group by
Expand Down
12 changes: 6 additions & 6 deletions tests/specs/Query/Builder+GrammarSpec.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,7 @@ component extends="testbox.system.BaseSpec" {
describe( """when"" callbacks", function() {
it( "executes the callback when the condition is true", function() {
var callback = function( query ) {
return query.where( "id", "=", 1 );
query.where( "id", "=", 1 );
};

var builder = getBuilder();
Expand All @@ -566,7 +566,7 @@ component extends="testbox.system.BaseSpec" {

it( "does not execute the callback when the condition is false", function() {
var callback = function( query ) {
return query.where( "id", "=", 1 );
query.where( "id", "=", 1 );
};

var builder = getBuilder();
Expand All @@ -582,11 +582,11 @@ component extends="testbox.system.BaseSpec" {

it( "executes the default callback when the condition is false", function() {
var callback = function( query ) {
return query.where( "id", "=", 1 );
query.where( "id", "=", 1 );
};

var default = function( query ) {
return query.where( "id", "=", 2 );
query.where( "id", "=", 2 );
};

var builder = getBuilder();
Expand All @@ -602,11 +602,11 @@ component extends="testbox.system.BaseSpec" {

it( "does not execute the default callback when the condition is true", function() {
var callback = function( query ) {
return query.where( "id", "=", 1 );
query.where( "id", "=", 1 );
};

var default = function( query ) {
return query.where( "id", "=", 2 );
query.where( "id", "=", 2 );
};

var builder = getBuilder();
Expand Down

0 comments on commit 657d47c

Please sign in to comment.