From fadb882166ca589872ae954ae02baf60cb3652b9 Mon Sep 17 00:00:00 2001 From: Eric Peterson Date: Mon, 28 Nov 2016 07:20:06 -0700 Subject: [PATCH] Reformat according to new style guidelines --- models/Query/Builder.cfc | 184 ++++----- models/Query/Grammars/Grammar.cfc | 80 ++-- models/Query/Grammars/GrammarInterface.cfc | 4 +- models/Query/Grammars/OracleGrammar.cfc | 80 ++-- models/Query/JoinClause.cfc | 78 ++-- models/Query/QueryUtils.cfc | 62 +-- tests/Application.cfc | 4 +- tests/specs/Query/Builder+GrammarSpec.cfc | 134 +++---- .../Builder/BuilderCollaboratorsSpec.cfc | 34 +- tests/specs/Query/Builder/BuilderGetSpec.cfc | 70 ++-- tests/specs/Query/Builder/BuilderJoinSpec.cfc | 326 ++++++++-------- .../specs/Query/Builder/BuilderSelectSpec.cfc | 124 +++--- .../specs/Query/Builder/BuilderWhereSpec.cfc | 260 ++++++------- tests/specs/Query/Builder/JoinClauseSpec.cfc | 244 ++++++------ .../Query/Grammar/GrammarCompileSQLSpec.cfc | 354 +++++++++--------- tests/specs/Query/QueryUtilsSpec.cfc | 108 +++--- 16 files changed, 1072 insertions(+), 1074 deletions(-) diff --git a/models/Query/Builder.cfc b/models/Query/Builder.cfc index 85a7d68c..eca089c1 100644 --- a/models/Query/Builder.cfc +++ b/models/Query/Builder.cfc @@ -1,4 +1,4 @@ -component displayname='Builder' { +component displayname="Builder" { property name="grammar" inject="Grammar@Quick"; property name="utils" inject="QueryUtils@Quick"; @@ -32,7 +32,7 @@ component displayname='Builder' { private void function setDefaultValues() { variables.isDistinct = false; - variables.columns = ["*"]; + variables.columns = [ "*" ]; variables.joins = []; variables.from = ""; variables.wheres = []; @@ -47,39 +47,39 @@ component displayname='Builder' { return this; } - public Builder function select(required any columns) { + public Builder function select( required any columns ) { // This block is necessary for ACF 10. // It can't be extracted to a function because // the arguments struct doesn't get passed correctly. var args = {}; - var count = structCount(arguments); - for (var arg in arguments) { - args[count] = arguments[arg]; + var count = structCount( arguments ); + for ( var arg in arguments ) { + args[ count ] = arguments[ arg ]; count--; } - variables.columns = normalizeToArray(argumentCollection = args); + variables.columns = normalizeToArray( argumentCollection = args ); return this; } - public Builder function addSelect(required any columns) { + public Builder function addSelect( required any columns ) { // This block is necessary for ACF 10. // It can't be extracted to a function because // the arguments struct doesn't get passed correctly. var args = {}; - var count = structCount(arguments); - for (var arg in arguments) { - args[count] = arguments[arg]; + var count = structCount( arguments ); + for ( var arg in arguments ) { + args[ count ] = arguments[ arg ]; count--; } - arrayAppend(variables.columns, normalizeToArray(argumentCollection = args), true); + arrayAppend( variables.columns, normalizeToArray( argumentCollection = args ), true ); return this; } // from methods - public Builder function from(required string from) { + public Builder function from( required string from ) { variables.from = arguments.from; return this; } @@ -91,32 +91,32 @@ component displayname='Builder' { any first, string operator, string second, - string type = 'inner', + string type = "inner", any conditions ) { - var joinClause = wirebox.getInstance(name = 'JoinClause@Quick', initArguments = { + var joinClause = wirebox.getInstance( name = "JoinClause@Quick", initArguments = { type = arguments.type, table = arguments.table - }); + } ); - if (structKeyExists(arguments, 'first') && isClosure(arguments.first)) { + if ( structKeyExists( arguments, "first" ) && isClosure( arguments.first ) ) { arguments.conditions = arguments.first; } - if (structKeyExists(arguments, 'conditions') && isClosure(arguments.conditions)) { - conditions(joinClause); + if ( structKeyExists( arguments, "conditions" ) && isClosure( arguments.conditions ) ) { + conditions( joinClause ); } else { joinClause.on( first = arguments.first, operator = arguments.operator, second = arguments.second, - combinator = 'and' + combinator = "and" ); } - arrayAppend(variables.joins, joinClause); - arrayAppend(bindings.join, joinClause.getBindings(), true); + arrayAppend( variables.joins, joinClause ); + arrayAppend( bindings.join, joinClause.getBindings(), true ); return this; } @@ -128,8 +128,8 @@ component displayname='Builder' { string second, any conditions ) { - arguments.type = 'left'; - return join(argumentCollection = arguments); + arguments.type = "left"; + return join( argumentCollection = arguments ); } public Builder function rightJoin( @@ -139,63 +139,63 @@ component displayname='Builder' { string second, any conditions ) { - arguments.type = 'right'; - return join(argumentCollection = arguments); + arguments.type = "right"; + return join( argumentCollection = arguments ); } // where methods - public Builder function where(column, operator, value, combinator) { - var argCount = argumentCount(arguments); + public Builder function where( column, operator, value, combinator ) { + var argCount = argumentCount( arguments ); - if (isNull(arguments.combinator)) { - arguments.combinator = 'AND'; + if ( isNull( arguments.combinator ) ) { + arguments.combinator = "AND"; } - else if (isInvalidCombinator(arguments.combinator)) { + else if ( isInvalidCombinator( arguments.combinator ) ) { throw( - type = 'InvalidSQLType', - message = 'Illegal combinator' + type = "InvalidSQLType", + message = "Illegal combinator" ); } - if (! structKeyExists(arguments, 'value')) { + if ( ! structKeyExists( arguments, "value" ) ) { arguments.value = arguments.operator; - arguments.operator = '='; + arguments.operator = "="; } - else if (isInvalidOperator(arguments.operator)) { + else if ( isInvalidOperator( arguments.operator ) ) { throw( - type = 'InvalidSQLType', - message = 'Illegal operator' + type = "InvalidSQLType", + message = "Illegal operator" ); } - var binding = utils.extractBinding(arguments.value); + var binding = utils.extractBinding( arguments.value ); - arrayAppend(variables.wheres, { + arrayAppend( variables.wheres, { column = arguments.column, operator = arguments.operator, value = arguments.value, combinator = arguments.combinator - }); + } ); - arrayAppend(bindings.where, binding); + arrayAppend( bindings.where, binding ); return this; } - public Builder function orWhere(column, operator, value) { - arguments.combinator = 'or'; - return where(argumentCollection = arguments); + public Builder function orWhere( column, operator, value ) { + arguments.combinator = "or"; + return where( argumentCollection = arguments ); } - public Builder function whereIn(column, value, combinator) { - arguments.operator = 'in'; - return where(argumentCollection = arguments); + public Builder function whereIn( column, value, combinator ) { + arguments.operator = "in"; + return where( argumentCollection = arguments ); } - public Builder function whereNotIn(column, value, combinator) { - arguments.operator = 'not in'; - return where(argumentCollection = arguments); + public Builder function whereNotIn( column, value, combinator ) { + arguments.operator = "not in"; + return where( argumentCollection = arguments ); } // Accessors @@ -221,12 +221,12 @@ component displayname='Builder' { } public array function getBindings() { - var bindingOrder = ['join', 'where']; + var bindingOrder = [ "join", "where" ]; var flatBindings = []; - for (var key in bindingOrder) { - if (structKeyExists(bindings, key)) { - arrayAppend(flatBindings, bindings[key], true); + for ( var key in bindingOrder ) { + if ( structKeyExists( bindings, key ) ) { + arrayAppend( flatBindings, bindings[ key ], true ); } } @@ -241,90 +241,90 @@ component displayname='Builder' { // Collaborators public string function toSQL() { - return grammar.compileSelect(this); + return grammar.compileSelect( this ); } - public query function get(struct options = {}) { - return queryExecute(this.toSQL(), this.getBindings(), options); + public query function get( struct options = {} ) { + return queryExecute( this.toSQL(), this.getBindings(), options ); } // Unused(?) private array function normalizeToArray() { - if (isVariadicFunction(args = arguments)) { - return normalizeVariadicArgumentsToArray(args = arguments); + if ( isVariadicFunction( args = arguments ) ) { + return normalizeVariadicArgumentsToArray( args = arguments ); } - var arg = arguments[1]; - if (! isArray(arg)) { - return normalizeListArgumentsToArray(arg); + var arg = arguments[ 1 ]; + if ( ! isArray( arg ) ) { + return normalizeListArgumentsToArray( arg ); } return arg; } - private boolean function isVariadicFunction(required struct args) { - return structCount(args) > 1; + private boolean function isVariadicFunction( required struct args ) { + return structCount( args ) > 1; } - private array function normalizeVariadicArgumentsToArray(required struct args) { + private array function normalizeVariadicArgumentsToArray( required struct args ) { var normalizedArgs = []; - for (var arg in arguments.args) { - arrayAppend(normalizedArgs, arguments.args[arg]); + for ( var arg in arguments.args ) { + arrayAppend( normalizedArgs, arguments.args[ arg ] ); } return normalizedArgs; } - private array function normalizeListArgumentsToArray(required string list) { - var listAsArray = listToArray(arguments.list); + private array function normalizeListArgumentsToArray( required string list ) { + var listAsArray = listToArray( arguments.list ); var items = []; - for (var item in listAsArray) { - arrayAppend(items, trim(item)); + for ( var item in listAsArray ) { + arrayAppend( items, trim( item ) ); } return items; } - private boolean function isInvalidOperator(required string operator) { - return ! arrayContains(operators, operator); + private boolean function isInvalidOperator( required string operator ) { + return ! arrayContains( operators, operator ); } - private boolean function isInvalidCombinator(required string combinator) { - for (var validCombinator in variables.combinators) { - if (validCombinator == arguments.combinator) { + private boolean function isInvalidCombinator( required string combinator ) { + for ( var validCombinator in variables.combinators ) { + if ( validCombinator == arguments.combinator ) { return false; } } return true; } - private function argumentCount(args) { + private function argumentCount( args ) { var count = 0; - for (var key in args) { - if (! isNull(args[key])) { + for ( var key in args ) { + if ( ! isNull( args[ key ] ) ) { count++; } } return count; } - public any function onMissingMethod(string missingMethodName, struct missingMethodArguments) { - if (! arrayIsEmpty(REMatchNoCase('^where(.+)', missingMethodName))) { - var args = { '1' = mid(missingMethodName, 6, len(missingMethodName) - 5) }; - for (var key in missingMethodArguments) { - args[key + 1] = missingMethodArguments[key]; + public any function onMissingMethod( string missingMethodName, struct missingMethodArguments ) { + if ( ! arrayIsEmpty( REMatchNoCase( "^where(.+)", missingMethodName ) ) ) { + var args = { "1" = mid( missingMethodName, 6, len( missingMethodName ) - 5 ) }; + for ( var key in missingMethodArguments ) { + args[ key + 1 ] = missingMethodArguments[ key ]; } - return where(argumentCollection = args); + return where( argumentCollection = args ); } - if (! arrayIsEmpty(REMatchNoCase('^orWhere(.+)', missingMethodName))) { - var args = { '1' = mid(missingMethodName, 8, len(missingMethodName) - 7) }; - for (var key in missingMethodArguments) { - args[key + 1] = missingMethodArguments[key]; + if ( ! arrayIsEmpty( REMatchNoCase( "^orWhere(.+)", missingMethodName ) ) ) { + var args = { "1" = mid( missingMethodName, 8, len( missingMethodName ) - 7 ) }; + for ( var key in missingMethodArguments ) { + args[ key + 1 ] = missingMethodArguments[ key ]; } - return orWhere(argumentCollection = args); + return orWhere( argumentCollection = args ); } - throw("Method does not exist [#missingMethodName#]"); + throw( "Method does not exist [#missingMethodName#]" ); } } \ No newline at end of file diff --git a/models/Query/Grammars/Grammar.cfc b/models/Query/Grammars/Grammar.cfc index a5067137..9fbfbf38 100644 --- a/models/Query/Grammars/Grammar.cfc +++ b/models/Query/Grammars/Grammar.cfc @@ -1,100 +1,100 @@ -component displayname='Grammar' implements='Quick.models.Query.Grammars.GrammarInterface' { +component displayname="Grammar" implements="Quick.models.Query.Grammars.GrammarInterface" { variables.selectComponents = [ - 'columns', 'from', 'joins', 'wheres' + "columns", "from", "joins", "wheres" ]; - public string function compileSelect(required Quick.models.Query.Builder query) { + public string function compileSelect( required Quick.models.Query.Builder query ) { var sql = []; - for (var component in selectComponents) { - var componentResult = invoke(query, 'get' & component); - var func = variables['compile#component#']; + for ( var component in selectComponents ) { + var componentResult = invoke( query, "get" & component ); + var func = variables[ "compile#component#" ]; var args = { - 'query' = query, - '#component#' = componentResult + "query" = query, + "#component#" = componentResult }; - arrayAppend(sql, func(argumentCollection = args)); + arrayAppend( sql, func( argumentCollection = args ) ); } - return concatenate(sql); + return concatenate( sql ); } - private string function compileColumns(required Quick.models.Query.Builder query, required array columns) { - var select = query.getDistinct() ? 'SELECT DISTINCT ' : 'SELECT '; - return select & ArrayToList(columns); + private string function compileColumns( required Quick.models.Query.Builder query, required array columns ) { + var select = query.getDistinct() ? "SELECT DISTINCT " : "SELECT "; + return select & arrayToList( columns ); } - private string function compileFrom(required Quick.models.Query.Builder query, required string from) { - return 'FROM ' & from; + private string function compileFrom( required Quick.models.Query.Builder query, required string from ) { + return "FROM " & from; } - private string function compileJoins(required Quick.models.Query.Builder query, required array joins) { + private string function compileJoins( required Quick.models.Query.Builder query, required array joins ) { var joinsArray = []; - for (var join in arguments.joins) { + for ( var join in arguments.joins ) { var firstOne = true; var clausesArray = []; - for (var clause in join.getClauses()) { - if (firstOne) { + for ( var clause in join.getClauses() ) { + if ( firstOne ) { firstOne = false; arrayAppend( clausesArray, - '#clause.first# #UCase(clause.operator)# #clause.second#' + "#clause.first# #uCase( clause.operator )# #clause.second#" ); } else { arrayAppend( clausesArray, - '#UCase(clause.combinator)# #clause.first# #UCase(clause.operator)# #clause.second#' + "#uCase( clause.combinator )# #clause.first# #uCase( clause.operator )# #clause.second#" ); } } - var clauses = arrayToList(clausesArray, ' '); - arrayAppend(joinsArray, '#UCase(join.getType())# JOIN #join.getTable()# ON #clauses#'); + var clauses = arrayToList( clausesArray, " " ); + arrayAppend( joinsArray, "#uCase( join.getType() )# JOIN #join.getTable()# ON #clauses#" ); } - return arrayToList(joinsArray, ' '); + return arrayToList( joinsArray, " " ); } - private string function compileWheres(required Quick.models.Query.Builder query, requierd array wheres) { + private string function compileWheres( required Quick.models.Query.Builder query, requierd array wheres ) { var wheresArray = []; var firstOne = true; - for (var where in arguments.wheres) { - if (! isStruct(where)) { + for ( var where in arguments.wheres ) { + if ( ! isStruct( where ) ) { continue; } - var placeholder = '?'; - if (where.operator == 'in' || where.operator == 'not in') { - placeholder = '(#placeholder#)'; + var placeholder = "?"; + if ( where.operator == "in" || where.operator == "not in" ) { + placeholder = "(#placeholder#)"; } - if (firstOne) { + if ( firstOne ) { firstOne = false; arrayAppend( wheresArray, - '#where.column# #UCase(where.operator)# #placeholder#' + "#where.column# #uCase( where.operator )# #placeholder#" ); } else { arrayAppend( wheresArray, - '#uCase(where.combinator)# #where.column# #UCase(where.operator)# #placeholder#' + "#uCase( where.combinator )# #where.column# #uCase( where.operator )# #placeholder#" ); } } - if (arrayIsEmpty(wheresArray)) { - return ''; + if ( arrayIsEmpty( wheresArray ) ) { + return ""; } - return "WHERE #ArrayToList(wheresArray, ' ')#"; + return "WHERE #arrayToList( wheresArray, " " )#"; } - private string function concatenate(required array sql) { - return arrayToList(arrayFilter(sql, function(item) { - return item != ''; - }), ' '); + private string function concatenate( required array sql ) { + return arrayToList( arrayFilter( sql, function( item ) { + return item != ""; + } ), " " ); } } \ No newline at end of file diff --git a/models/Query/Grammars/GrammarInterface.cfc b/models/Query/Grammars/GrammarInterface.cfc index 4d48d9dd..7efa78c5 100644 --- a/models/Query/Grammars/GrammarInterface.cfc +++ b/models/Query/Grammars/GrammarInterface.cfc @@ -1,3 +1,3 @@ -interface displayname='GrammarInterface' { - public string function compileSelect(required Quick.models.Query.Builder query); +interface displayname="GrammarInterface" { + public string function compileSelect( required Quick.models.Query.Builder query ); } \ No newline at end of file diff --git a/models/Query/Grammars/OracleGrammar.cfc b/models/Query/Grammars/OracleGrammar.cfc index 37a77a18..1a5a0fb2 100644 --- a/models/Query/Grammars/OracleGrammar.cfc +++ b/models/Query/Grammars/OracleGrammar.cfc @@ -1,100 +1,100 @@ -component displayname='OracleGrammar' implements='Quick.models.Query.Grammars.GrammarInterface' { +component displayname="OracleGrammar" implements="Quick.models.Query.Grammars.GrammarInterface" { variables.selectComponents = [ - 'columns', 'from', 'joins', 'wheres' + "columns", "from", "joins", "wheres" ]; - public string function compileSelect(required Quick.models.Query.Builder query) { + public string function compileSelect( required Quick.models.Query.Builder query ) { var sql = []; - for (var component in selectComponents) { - var componentResult = invoke(query, 'get' & component); - var func = variables['compile#component#']; + for ( var component in selectComponents ) { + var componentResult = invoke( query, "get" & component ); + var func = variables[ "compile#component#" ]; var args = { - 'query' = query, - '#component#' = componentResult + "query" = query, + "#component#" = componentResult }; - arrayAppend(sql, func(argumentCollection = args)); + arrayAppend( sql, func( argumentCollection = args ) ); } - return concatenate(sql); + return concatenate( sql ); } - private string function compileColumns(required Quick.models.Query.Builder query, required array columns) { - var select = query.getDistinct() ? 'SELECT DISTINCT ' : 'SELECT '; - return select & ArrayToList(columns); + private string function compileColumns( required Quick.models.Query.Builder query, required array columns ) { + var select = query.getDistinct() ? "SELECT DISTINCT " : "SELECT "; + return select & arrayToList( columns ); } - private string function compileFrom(required Quick.models.Query.Builder query, required string from) { - return 'FROM ' & from; + private string function compileFrom( required Quick.models.Query.Builder query, required string from ) { + return "FROM " & from; } - private string function compileJoins(required Quick.models.Query.Builder query, required array joins) { + private string function compileJoins( required Quick.models.Query.Builder query, required array joins ) { var joinsArray = []; - for (var join in arguments.joins) { + for ( var join in arguments.joins ) { var firstOne = true; var clausesArray = []; - for (var clause in join.getClauses()) { - if (firstOne) { + for ( var clause in join.getClauses() ) { + if ( firstOne ) { firstOne = false; arrayAppend( clausesArray, - '#clause.first# #UCase(clause.operator)# #clause.second#' + "#clause.first# #uCase( clause.operator )# #clause.second#" ); } else { arrayAppend( clausesArray, - '#UCase(clause.combinator)# #clause.first# #UCase(clause.operator)# #clause.second#' + "#uCase( clause.combinator )# #clause.first# #uCase( clause.operator )# #clause.second#" ); } } - var clauses = arrayToList(clausesArray, ' '); - arrayAppend(joinsArray, '#UCase(join.getType())# JOIN #join.getTable()# ON #clauses#'); + var clauses = arrayToList( clausesArray, " " ); + arrayAppend( joinsArray, "#uCase( join.getType() )# JOIN #join.getTable()# ON #clauses#" ); } - return arrayToList(joinsArray, ' '); + return arrayToList( joinsArray, " " ); } - private string function compileWheres(required Quick.models.Query.Builder query, requierd array wheres) { + private string function compileWheres( required Quick.models.Query.Builder query, requierd array wheres ) { var wheresArray = []; var firstOne = true; - for (var where in arguments.wheres) { - if (! isStruct(where)) { + for ( var where in arguments.wheres ) { + if ( ! isStruct( where ) ) { continue; } - var placeholder = '?'; - if (where.operator == 'in' || where.operator == 'not in') { - placeholder = '(#placeholder#)'; + var placeholder = "?"; + if ( where.operator == "in" || where.operator == "not in" ) { + placeholder = "(#placeholder#)"; } - if (firstOne) { + if ( firstOne ) { firstOne = false; arrayAppend( wheresArray, - '#where.column# #UCase(where.operator)# #placeholder#' + "#where.column# #uCase( where.operator )# #placeholder#" ); } else { arrayAppend( wheresArray, - '#uCase(where.combinator)# #where.column# #UCase(where.operator)# #placeholder#' + "#uCase( where.combinator )# #where.column# #uCase( where.operator )# #placeholder#" ); } } - if (arrayIsEmpty(wheresArray)) { - return ''; + if ( arrayIsEmpty( wheresArray ) ) { + return ""; } - return "WHERE #ArrayToList(wheresArray, ' ')#"; + return "WHERE #arrayToList( wheresArray, " " )#"; } - private string function concatenate(required array sql) { - return arrayToList(arrayFilter(sql, function(item) { - return item != ''; - }), ' '); + private string function concatenate( required array sql ) { + return arrayToList( arrayFilter( sql, function( item ) { + return item != ""; + } ), " " ); } } \ No newline at end of file diff --git a/models/Query/JoinClause.cfc b/models/Query/JoinClause.cfc index d1307a2f..4f65df34 100644 --- a/models/Query/JoinClause.cfc +++ b/models/Query/JoinClause.cfc @@ -1,24 +1,24 @@ -component displayname='JoinClause' { +component displayname="JoinClause" { - property name='utils' inject='QueryUtils@Quick'; + property name="utils" inject="QueryUtils@Quick"; - property name='type' type='string'; - property name='table' type='string'; - property name='clauses' type='array'; - property name='bindings' type='array'; + property name="type" type="string"; + property name="table" type="string"; + property name="clauses" type="array"; + property name="bindings" type="array"; variables.operators = [ - '=', '<', '>', '<=', '>=', '<>', '!=', - 'like', 'like binary', 'not like', 'between', 'ilike', - '&', '|', '^', '<<', '>>', - 'rlike', 'regexp', 'not regexp', - '~', '~*', '!~', '!~*', 'similar to', - 'not similar to' + "=", "<", ">", "<=", ">=", "<>", "!=", + "like", "like binary", "not like", "between", "ilike", + "&", "|", "^", "<<", ">>", + "rlike", "regexp", "not regexp", + "~", "~*", "!~", "!~*", "similar to", + "not similar to" ]; variables.types = [ - 'inner', 'full', 'cross', - 'left', 'left outer', 'right', 'right outer' + "inner", "full", "cross", + "left", "left outer", "right", "right outer" ]; public JoinClause function init( @@ -26,13 +26,13 @@ component displayname='JoinClause' { required string table ) { var typeIsValid = false; - for (var validType in variables.types) { - if (validType == arguments.type) { + for ( var validType in variables.types ) { + if ( validType == arguments.type ) { typeIsValid = true; } } - if (! typeIsValid) { - throw(type = 'InvalidSQLType', message = '[#type#] is not a valid sql join type'); + if ( ! typeIsValid ) { + throw( type = "InvalidSQLType", message = "[#type#] is not a valid sql join type" ); } variables.type = arguments.type; @@ -44,48 +44,48 @@ component displayname='JoinClause' { return this; } - public JoinClause function on(first, operator, second, combinator = 'and', where = false) { + public JoinClause function on( first, operator, second, combinator = "and", where = false ) { // If we only receive the first two arguments, this is the shortcut where statement - if (! structKeyExists(arguments, 'second')) { + if ( ! structKeyExists( arguments, "second" ) ) { arguments.second = arguments.operator; - arguments.operator = '='; + arguments.operator = "="; } var operatorIsValid = false; - for (var validOperator in variables.operators) { - if (validOperator == arguments.operator) { + for ( var validOperator in variables.operators ) { + if ( validOperator == arguments.operator ) { operatorIsValid = true; } } - if (! operatorIsValid) { - throw(type = 'InvalidSQLType', message = '[#operator#] is not a valid sql operator type'); + if ( ! operatorIsValid ) { + throw( type = "InvalidSQLType", message = "[#operator#] is not a valid sql operator type" ); } - if (arguments.where) { - var binding = utils.extractBinding(arguments.second); - arrayAppend(bindings, binding); - arguments.second = '?'; + if ( arguments.where ) { + var binding = utils.extractBinding( arguments.second ); + arrayAppend( bindings, binding ); + arguments.second = "?"; } - arrayAppend(clauses, { + arrayAppend( clauses, { first = arguments.first, operator = arguments.operator, second = arguments.second, combinator = arguments.combinator, where = arguments.where - }); + } ); return this; } - public JoinClause function orOn(first, operator, second, where = false) { - arguments.combinator = 'or'; - return on(argumentCollection = arguments); + public JoinClause function orOn( first, operator, second, where = false ) { + arguments.combinator = "or"; + return on( argumentCollection = arguments ); } - public JoinClause function where(first, operator, second, combinator) { + public JoinClause function where( first, operator, second, combinator ) { arguments.where = true; - return on(argumentCollection = arguments); + return on( argumentCollection = arguments ); } public string function getType() { @@ -104,15 +104,15 @@ component displayname='JoinClause' { return bindings; } - private struct function extractBindings(required any value) { + private struct function extractBindings( required any value ) { var binding = {}; - if (isStruct(arguments.value)) { + if ( isStruct( arguments.value ) ) { binding = arguments.value; arguments.value = arguments.value.value; } - if (! structKeyExists(binding, 'value')) { + if ( ! structKeyExists( binding, "value" ) ) { binding.value = arguments.value; } diff --git a/models/Query/QueryUtils.cfc b/models/Query/QueryUtils.cfc index 12a8b62e..1f62ba66 100644 --- a/models/Query/QueryUtils.cfc +++ b/models/Query/QueryUtils.cfc @@ -1,64 +1,64 @@ -component displayname='QueryUtils' { - public struct function extractBinding(required any value) { - var binding = isStruct(value) ? value : { value = normalizeSqlValue(value) }; +component displayname="QueryUtils" { + public struct function extractBinding( required any value ) { + var binding = isStruct( value ) ? value : { value = normalizeSqlValue( value ) }; - structAppend(binding, { - cfsqltype = inferSqlType(binding.value), - list = isList(binding.value), + structAppend( binding, { + cfsqltype = inferSqlType( binding.value ), + list = isList( binding.value ), null = false - }, false); + }, false ); return binding; } - public string function inferSqlType(required any value) { - if (isList(arguments.value)) { - arguments.value = listToArray(arguments.value); + public string function inferSqlType( required any value ) { + if ( isList( arguments.value ) ) { + arguments.value = listToArray( arguments.value ); } - if (isArray(value)) { - return arraySame(value, function(val) { - return inferSqlType(val); - }, 'CF_SQL_VARCHAR'); + if ( isArray( value ) ) { + return arraySame( value, function( val ) { + return inferSqlType( val ); + }, "CF_SQL_VARCHAR" ); } - if (isNumeric(value)) { - return 'CF_SQL_NUMERIC'; + if ( isNumeric( value ) ) { + return "CF_SQL_NUMERIC"; } - if (isDate(value)) { - return 'CF_SQL_TIMESTAMP'; + if ( isDate( value ) ) { + return "CF_SQL_TIMESTAMP"; } - return 'CF_SQL_VARCHAR'; + return "CF_SQL_VARCHAR"; } - private string function normalizeSqlValue(required any value) { - if (isArray(arguments.value)) { - return arrayToList(arguments.value); + private string function normalizeSqlValue( required any value ) { + if ( isArray( arguments.value ) ) { + return arrayToList( arguments.value ); } return arguments.value; } - private boolean function isList(required any value) { - if (isStruct(value) || isArray(value)) { + private boolean function isList( required any value ) { + if ( isStruct( value ) || isArray( value ) ) { return false; } - var listAsArray = listToArray(arguments.value); - return arrayLen(listAsArray) > 1; + var listAsArray = listToArray( arguments.value ); + return arrayLen( listAsArray ) > 1; } - private any function arraySame(required array args, required any closure, any defaultValue = '') { - if (arrayLen(arguments.args) == 0) { + private any function arraySame( required array args, required any closure, any defaultValue = "" ) { + if ( arrayLen( arguments.args ) == 0 ) { return arguments.defaultValue; } - var initial = closure(arguments.args[1]); + var initial = closure( arguments.args[ 1 ] ); - for (var arg in arguments.args) { - if (closure(arg) != initial) { + for ( var arg in arguments.args ) { + if ( closure( arg ) != initial ) { return defaultValue; } } diff --git a/tests/Application.cfc b/tests/Application.cfc index b9e40469..ab13923f 100644 --- a/tests/Application.cfc +++ b/tests/Application.cfc @@ -1,4 +1,4 @@ component { - this.mappings["/tests"] = getDirectoryFromPath(getCurrentTemplatePath()); - this.mappings["/Quick"] = expandPath("/"); + this.mappings[ "/tests" ] = getDirectoryFromPath( getCurrentTemplatePath() ); + this.mappings[ "/Quick" ] = expandPath( "/" ); } \ No newline at end of file diff --git a/tests/specs/Query/Builder+GrammarSpec.cfc b/tests/specs/Query/Builder+GrammarSpec.cfc index aa118a08..694eca9a 100644 --- a/tests/specs/Query/Builder+GrammarSpec.cfc +++ b/tests/specs/Query/Builder+GrammarSpec.cfc @@ -6,25 +6,25 @@ component extends="testbox.system.BaseSpec" { it( "can select all columns from a table", function() { var builder = getBuilder(); builder.select( "*" ).from( "users" ); - expect( builder.toSql() ).toBe( 'SELECT * FROM "users"' ); + expect( builder.toSql() ).toBe( "SELECT * FROM ""users""" ); } ); it( "can specify the column to select", function() { var builder = getBuilder(); builder.select( "name" ).from( "users" ); - expect( builder.toSql() ).toBe( 'SELECT "name" FROM "users"' ); + expect( builder.toSql() ).toBe( "SELECT ""name"" FROM ""users""" ); } ); it( "can select multiple columns using variadic parameters", function() { var builder = getBuilder(); builder.select( "id", "name" ).from( "users" ); - expect( builder.toSql() ).toBe( 'SELECT "id", "name" FROM "users"' ); + expect( builder.toSql() ).toBe( "SELECT ""id"", ""name"" FROM ""users""" ); } ); it( "can select multiple columns using an array", function() { var builder = getBuilder(); builder.select( [ "name", builder.raw( "COUNT(*)" ) ] ).from( "users" ); - expect( builder.toSql() ).toBe( 'SELECT "name", COUNT(*) FROM "users"' ); + expect( builder.toSql() ).toBe( "SELECT ""name"", COUNT(*) FROM ""users""" ); } ); it( "can add selects to a query", function() { @@ -35,7 +35,7 @@ component extends="testbox.system.BaseSpec" { .addSelect( "fe", "fi", "fo" ) .from( "users" ); expect( builder.toSql() ).toBe( - 'SELECT "foo", "bar", "baz", "boom", "fe", "fi", "fo" FROM "users"' + "SELECT ""foo"", ""bar"", ""baz"", ""boom"", ""fe"", ""fi"", ""fo"" FROM ""users""" ); } ); @@ -43,7 +43,7 @@ component extends="testbox.system.BaseSpec" { var builder = getBuilder(); builder.distinct().select( "foo", "bar" ).from( "users" ); expect( builder.toSql() ).toBe( - 'SELECT DISTINCT "foo", "bar" FROM "users"' + "SELECT DISTINCT ""foo"", ""bar"" FROM ""users""" ); } ); @@ -51,7 +51,7 @@ component extends="testbox.system.BaseSpec" { var builder = getBuilder(); builder.select( "foo as bar" ).from( "users" ); expect( builder.toSql() ).toBe( - 'SELECT "foo" AS "bar" from "users"' + "SELECT ""foo"" AS ""bar"" from ""users""" ); } ); @@ -59,7 +59,7 @@ component extends="testbox.system.BaseSpec" { var builder = getBuilder(); builder.select( "x.y as foo.bar" ).from( "public.users" ); expect( builder.toSql() ).toBe( - 'SELECT "x"."y" AS "foo.bar" from "public"."users"' + "SELECT ""x"".""y"" AS ""foo.bar"" from ""public"".""users""" ); } ); } ); @@ -70,7 +70,7 @@ component extends="testbox.system.BaseSpec" { builder.getGrammar().setTablePrefix( "prefix_" ); builder.select( "*" ).from( "users" ); expect( builder.toSql() ).toBe( - 'SELECT * FROM "prefix_users"' + "SELECT * FROM ""prefix_users""" ); } ); @@ -79,7 +79,7 @@ component extends="testbox.system.BaseSpec" { builder.getGrammar().setTablePrefix( "prefix_" ); builder.select( "*" ).from( "users as people" ); expect( builder.toSql() ).toBe( - 'SELECT * FROM "prefix_users" AS "prefix_people"' + "SELECT * FROM ""prefix_users"" AS ""prefix_people""" ); } ); } ); @@ -90,7 +90,7 @@ component extends="testbox.system.BaseSpec" { var builder = getBuilder(); builder.select( "*" ).from( "users" ).where( "id", "=", 1 ); expect( builder.toSql() ).toBe( - 'SELECT * FROM "users" WHERE "id" = ?' + "SELECT * FROM ""users"" WHERE ""id"" = ?" ); expect( builder.getBindings() ).toBe( [ 1 ] ); } ); @@ -100,7 +100,7 @@ component extends="testbox.system.BaseSpec" { builder.select( "*" ).from( "users" ) .where( "id", "=", 1 ).orWhere( "email", "foo" ); expect( builder.toSql() ).toBe( - 'SELECT * FROM "users" WHERE "id" = ? OR "email" = ?' + "SELECT * FROM ""users"" WHERE ""id"" = ? OR ""email"" = ?" ); expect( builder.getBindings() ).toBe( [ 1, "foo" ] ); } ); @@ -109,7 +109,7 @@ component extends="testbox.system.BaseSpec" { var builder = getBuilder(); builder.select( "*" ).from( "users" ).whereRaw( "id = ? or email = ?", [ 1, "foo" ] ); expect( builder.toSql() ).toBe( - 'SELECT * FROM "users" WHERE "id" = ? OR "email" = ?' + "SELECT * FROM ""users"" WHERE ""id"" = ? OR ""email"" = ?" ); expect( builder.getBindings() ).toBe( [ 1, "foo" ] ); } ); @@ -119,7 +119,7 @@ component extends="testbox.system.BaseSpec" { builder.select( "*" ).from( "users" ) .where( "id", "=", 1 ).orWhereRaw( "email = ?", [ "foo" ] ); expect( builder.toSql() ).toBe( - 'SELECT * FROM "users" WHERE "id" = ? OR "email" = ?' + "SELECT * FROM ""users"" WHERE ""id"" = ? OR ""email"" = ?" ); expect( builder.getBindings() ).toBe( [ 1, "foo" ] ); } ); @@ -130,7 +130,7 @@ component extends="testbox.system.BaseSpec" { .whereColumn( "first_name", "last_name" ) .orWhereColumn( "updated_date", ">", "created_date" ); expect( builder.toSql() ).toBe( - 'SELECT * FROM "users" WHERE "first_name" = "last_name" OR "updated_date" > "created_date"' + "SELECT * FROM ""users"" WHERE ""first_name"" = ""last_name"" OR ""updated_date"" > ""created_date""" ); expect( builder.getBindings() ).toBe( [] ); } ); @@ -142,7 +142,7 @@ component extends="testbox.system.BaseSpec" { q.where( "name", "bar" ).where( "age", ">=", "21" ); } ); expect( builder.toSql() ).toBe( - 'SELECT * FROM "users" WHERE "email" = ? OR ("name" = ? AND "age" >= ?)' + "SELECT * FROM ""users"" WHERE ""email"" = ? OR (""name"" = ? AND ""age"" >= ?)" ); expect( builder.getBindings() ).toBe( [ "foo", "bar", 21 ] ); } ); @@ -155,7 +155,7 @@ component extends="testbox.system.BaseSpec" { .where( "email", "bar" ); } ); expect( builder.toSql() ).toBe( - 'SELECT * FROM "users" WHERE "email" = ? OR id = (SELECT MAX(id) FROM "users" WHERE "email" = ?)' + "SELECT * FROM ""users"" WHERE ""email"" = ? OR id = (SELECT MAX(id) FROM ""users"" WHERE ""email"" = ?)" ); expect( builder.getBindings() ).toBe( [ "foo", "bar" ] ); } ); @@ -167,10 +167,10 @@ component extends="testbox.system.BaseSpec" { builder.select( "*" ).from( "orders" ) .whereExists( function( q ) { q.select( q.raw( 1 ) ).from( "products" ) - .where( "products.id", "=", q.raw( '"orders"."id"' ) ); + .where( "products.id", "=", q.raw( """orders"".""id""" ) ); } ); expect( builder.toSql() ).toBe( - 'SELECT * FROM "orders" WHERE EXISTS (SELECT 1 FROM "products" WHERE "products"."id" = "orders"."id")' + "SELECT * FROM ""orders"" WHERE EXISTS (SELECT 1 FROM ""products"" WHERE ""products"".""id"" = ""orders"".""id"")" ); expect( builder.getBindings() ).toBe( [] ); } ); @@ -181,10 +181,10 @@ component extends="testbox.system.BaseSpec" { .where( "id", 1 ) .orWhereExists( function( q ) { q.select( q.raw( 1 ) ).from( "products" ) - .where( "products.id", "=", q.raw( '"orders"."id"' ) ); + .where( "products.id", "=", q.raw( """orders"".""id""" ) ); } ); expect( builder.toSql() ).toBe( - 'SELECT * FROM "orders" WHERE "id" = ? OR EXISTS (SELECT 1 FROM "products" WHERE "products"."id" = "orders"."id")' + "SELECT * FROM ""orders"" WHERE ""id"" = ? OR EXISTS (SELECT 1 FROM ""products"" WHERE ""products"".""id"" = ""orders"".""id"")" ); expect( builder.getBindings() ).toBe( [ 1 ] ); } ); @@ -194,10 +194,10 @@ component extends="testbox.system.BaseSpec" { builder.select( "*" ).from( "orders" ) .whereNotExists( function( q ) { q.select( q.raw( 1 ) ).from( "products" ) - .where( "products.id", "=", q.raw( '"orders"."id"' ) ); + .where( "products.id", "=", q.raw( """orders"".""id""" ) ); } ); expect( builder.toSql() ).toBe( - 'SELECT * FROM "orders" WHERE NOT EXISTS (SELECT 1 FROM "products" WHERE "products"."id" = "orders"."id")' + "SELECT * FROM ""orders"" WHERE NOT EXISTS (SELECT 1 FROM ""products"" WHERE ""products"".""id"" = ""orders"".""id"")" ); expect( builder.getBindings() ).toBe( [] ); } ); @@ -208,10 +208,10 @@ component extends="testbox.system.BaseSpec" { .where( "id", 1 ) .orWhereNotExists( function( q ) { q.select( q.raw( 1 ) ).from( "products" ) - .where( "products.id", "=", q.raw( '"orders"."id"' ) ); + .where( "products.id", "=", q.raw( """orders"".""id""" ) ); } ); expect( builder.toSql() ).toBe( - 'SELECT * FROM "orders" WHERE "id" = ? OR NOT EXISTS (SELECT 1 FROM "products" WHERE "products"."id" = "orders"."id")' + "SELECT * FROM ""orders"" WHERE ""id"" = ? OR NOT EXISTS (SELECT 1 FROM ""products"" WHERE ""products"".""id"" = ""orders"".""id"")" ); expect( builder.getBindings() ).toBe( [ 1 ] ); } ); @@ -222,7 +222,7 @@ component extends="testbox.system.BaseSpec" { var builder = getBuilder(); builder.select( "*" ).from( "users" ).whereNull( "id" ); expect( builder.toSql() ).toBe( - 'SELECT * FROM "users" WHERE "id" IS NULL' + "SELECT * FROM ""users"" WHERE ""id"" IS NULL" ); expect( builder.getBindings() ).toBe( [] ); } ); @@ -232,7 +232,7 @@ component extends="testbox.system.BaseSpec" { builder.select( "*" ).from( "users" ) .where( "id", 1 ).orWhereNull( "id" ); expect( builder.toSql() ).toBe( - 'SELECT * FROM "users" WHERE "id" = ? OR "id" IS NULL' + "SELECT * FROM ""users"" WHERE ""id"" = ? OR ""id"" IS NULL" ); expect( builder.getBindings() ).toBe( [ 1 ] ); } ); @@ -241,7 +241,7 @@ component extends="testbox.system.BaseSpec" { var builder = getBuilder(); builder.select( "*" ).from( "users" ).whereNull( "id" ); expect( builder.toSql() ).toBe( - 'SELECT * FROM "users" WHERE "id" IS NOT NULL' + "SELECT * FROM ""users"" WHERE ""id"" IS NOT NULL" ); expect( builder.getBindings() ).toBe( [] ); } ); @@ -251,7 +251,7 @@ component extends="testbox.system.BaseSpec" { builder.select( "*" ).from( "users" ) .where( "id", 1 ).orWhereNotNull( "id" ); expect( builder.toSql() ).toBe( - 'SELECT * FROM "users" WHERE "id" = ? OR "id" IS NOT NULL' + "SELECT * FROM ""users"" WHERE ""id"" = ? OR ""id"" IS NOT NULL" ); expect( builder.getBindings() ).toBe( [ 1 ] ); } ); @@ -260,9 +260,9 @@ component extends="testbox.system.BaseSpec" { describe( "where between", function() { it( "can add where between statements", function() { var builder = getBuilder(); - builder.select( "*" ).from( "users" ).whereBetween( "id", [ 1, 2 ]); + builder.select( "*" ).from( "users" ).whereBetween( "id", [ 1, 2 ] ); expect( builder.toSql() ).toBe( - 'SELECT * FROM "users" WHERE "id" BETWEEN ? AND ?' + "SELECT * FROM ""users"" WHERE ""id"" BETWEEN ? AND ?" ); expect( builder.getBindings() ).toBe( [ 1, 2 ] ); } ); @@ -271,7 +271,7 @@ component extends="testbox.system.BaseSpec" { var builder = getBuilder(); builder.select( "*" ).from( "users" ).whereNotBetween( "id", [ 1, 2 ] ); expect( builder.toSql() ).toBe( - 'SELECT * FROM "users" WHERE "id" NOT BETWEEN ? AND ?' + "SELECT * FROM ""users"" WHERE ""id"" NOT BETWEEN ? AND ?" ); expect( builder.getBindings() ).toBe( [ 1, 2 ] ); } ); @@ -283,7 +283,7 @@ component extends="testbox.system.BaseSpec" { builder.select( "*" ).from( "users" ) .whereIn( "id", [ 1, 2, 3 ] ); expect( builder.toSql() ).toBe( - 'SELECT * FROM "users" WHERE "id" IN (?, ?, ?)' + "SELECT * FROM ""users"" WHERE ""id"" IN (?, ?, ?)" ); expect( builder.getBindings() ).toBe( [ 1, 2, 3 ] ); } ); @@ -294,7 +294,7 @@ component extends="testbox.system.BaseSpec" { .where( "email", "foo" ) .orWhereIn( "id", [ 1, 2, 3 ] ); expect( builder.toSql() ).toBe( - 'SELECT * FROM "users" WHERE "email" = ? OR "id" IN (?, ?, ?)' + "SELECT * FROM ""users"" WHERE ""email"" = ? OR ""id"" IN (?, ?, ?)" ); expect( builder.getBindings() ).toBe( [ "foo", 1, 2, 3 ] ); } ); @@ -304,7 +304,7 @@ component extends="testbox.system.BaseSpec" { builder.select( "*" ).from( "users" ) .whereIn( "id", [ builder.raw( 1 ) ] ); expect( builder.toSql() ).toBe( - 'SELECT * FROM "users" WHERE "id" IN (1)' + "SELECT * FROM ""users"" WHERE ""id"" IN (1)" ); expect( builder.getBindings() ).toBe( [] ); } ); @@ -314,7 +314,7 @@ component extends="testbox.system.BaseSpec" { builder.select( "*" ).from( "users" ) .whereIn( "id", [] ); expect( builder.toSql() ).toBe( - 'SELECT * FROM "users" WHERE 0 = 1' + "SELECT * FROM ""users"" WHERE 0 = 1" ); expect( builder.getBindings() ).toBe( [] ); } ); @@ -324,7 +324,7 @@ component extends="testbox.system.BaseSpec" { builder.select( "*" ).from( "users" ) .whereNotIn( "id", [] ); expect( builder.toSql() ).toBe( - 'SELECT * FROM "users" WHERE 1 = 1' + "SELECT * FROM ""users"" WHERE 1 = 1" ); expect( builder.getBindings() ).toBe( [] ); } ); @@ -335,7 +335,7 @@ component extends="testbox.system.BaseSpec" { q.select( "id" ).from( "users" ).where( "age", ">", 25 ); } ); expect( builder.toSql() ).toBe( - 'SELECT * FROM "users" WHERE "id" IN (SELECT "id" FROM "users" WHERE "age" > ?)' + "SELECT * FROM ""users"" WHERE ""id"" IN (SELECT ""id"" FROM ""users"" WHERE ""age"" > ?)" ); expect( builder.getBindings() ).toBe( [ 25 ] ); } ); @@ -348,7 +348,7 @@ component extends="testbox.system.BaseSpec" { builder.select( "*" ).from( "users" ) .join( "contacts", "users.id", "=", "contacts.id" ); expect( builder.toSql() ).toBe( - 'SELECT * FROM "users" INNER JOIN "contacts" ON "users"."id" = "contacts"."id"' + "SELECT * FROM ""users"" INNER JOIN ""contacts"" ON ""users"".""id"" = ""contacts"".""id""" ); expect( builder.getBindings() ).toBe( [] ); } ); @@ -358,7 +358,7 @@ component extends="testbox.system.BaseSpec" { builder.select( "*" ).from( "users" ) .join( "contacts", "users.id", "contacts.id" ); expect( builder.toSql() ).toBe( - 'SELECT * FROM "users" INNER JOIN "contacts" ON "users"."id" = "contacts"."id"' + "SELECT * FROM ""users"" INNER JOIN ""contacts"" ON ""users"".""id"" = ""contacts"".""id""" ); expect( builder.getBindings() ).toBe( [] ); } ); @@ -369,7 +369,7 @@ component extends="testbox.system.BaseSpec" { .join( "contacts", "users.id", "contacts.id" ) .join( "addresses as a", "a.contact_id", "contacts.id" ); expect( builder.toSql() ).toBe( - 'SELECT * FROM "users" INNER JOIN "contacts" ON "users"."id" = "contacts"."id" INNER JOIN "addresses" AS "a" ON "a"."contact_id" = "contacts"."id"' + "SELECT * FROM ""users"" INNER JOIN ""contacts"" ON ""users"".""id"" = ""contacts"".""id"" INNER JOIN ""addresses"" AS ""a"" ON ""a"".""contact_id"" = ""contacts"".""id""" ); expect( builder.getBindings() ).toBe( [] ); } ); @@ -380,7 +380,7 @@ component extends="testbox.system.BaseSpec" { builder.select( "*" ).from( "users" ) .joinWhere( "contacts", "contacts.balance", "<", 100 ); expect( builder.toSql() ).toBe( - 'SELECT * FROM "users" INNER JOIN "contacts" ON "contacts"."balance" < ?' + "SELECT * FROM ""users"" INNER JOIN ""contacts"" ON ""contacts"".""balance"" < ?" ); expect( builder.getBindings() ).toBe( [ 100 ] ); } ); @@ -391,7 +391,7 @@ component extends="testbox.system.BaseSpec" { builder.select( "*" ).from( "users" ) .leftJoin( "orders", "users.id", "orders.user_id" ); expect( builder.toSql() ).toBe( - 'SELECT * FROM "users" LEFT JOIN "orders" ON "users"."id" = "orders"."user_id"' + "SELECT * FROM ""users"" LEFT JOIN ""orders"" ON ""users"".""id"" = ""orders"".""user_id""" ); expect( builder.getBindings() ).toBe( [] ); } ); @@ -401,7 +401,7 @@ component extends="testbox.system.BaseSpec" { builder.select( "*" ).from( "orders" ) .rightJoin( "users", "orders.user_id", "users.id" ); expect( builder.toSql() ).toBe( - 'SELECT * FROM "orders" LEFT JOIN "users" ON "orders"."user_id" = "users"."id"' + "SELECT * FROM ""orders"" LEFT JOIN ""users"" ON ""orders"".""user_id"" = ""users"".""id""" ); expect( builder.getBindings() ).toBe( [] ); } ); @@ -410,7 +410,7 @@ component extends="testbox.system.BaseSpec" { var builder = getBuilder(); builder.select( "*" ).from( "sizes" ).crossJoin( "colors" ); expect( builder.toSql() ).toBe( - 'SELECT * FROM "sizes" CROSS JOIN "colors"' + "SELECT * FROM ""sizes"" CROSS JOIN ""colors""" ); } ); @@ -424,7 +424,7 @@ component extends="testbox.system.BaseSpec" { } ); expect( builder.toSql() ).toBe( - 'SELECT * FROM "users" INNER JOIN "contacts" ON "users"."id" = "contacts"."id" OR "users"."name" = "contacts"."name" OR "users"."admin" = ?' + "SELECT * FROM ""users"" INNER JOIN ""contacts"" ON ""users"".""id"" = ""contacts"".""id"" OR ""users"".""name"" = ""contacts"".""name"" OR ""users"".""admin"" = ?" ); expect( builder.getBindings() ).toBe( [ 1 ] ); } ); @@ -438,7 +438,7 @@ component extends="testbox.system.BaseSpec" { } ); expect( builder.toSql() ).toBe( - 'SELECT * FROM "users" INNER JOIN "contacts" ON "users"."id" = "contacts"."id" AND "contacts"."deleted_date" IS NULL' + "SELECT * FROM ""users"" INNER JOIN ""contacts"" ON ""users"".""id"" = ""contacts"".""id"" AND ""contacts"".""deleted_date"" IS NULL" ); expect( builder.getBindings() ).toBe( [] ); } ); @@ -452,7 +452,7 @@ component extends="testbox.system.BaseSpec" { } ); expect( builder.toSql() ).toBe( - 'SELECT * FROM "users" INNER JOIN "contacts" ON "users"."id" = "contacts"."id" OR "contacts"."deleted_date" IS NULL' + "SELECT * FROM ""users"" INNER JOIN ""contacts"" ON ""users"".""id"" = ""contacts"".""id"" OR ""contacts"".""deleted_date"" IS NULL" ); expect( builder.getBindings() ).toBe( [] ); } ); @@ -466,7 +466,7 @@ component extends="testbox.system.BaseSpec" { } ); expect( builder.toSql() ).toBe( - 'SELECT * FROM "users" INNER JOIN "contacts" ON "users"."id" = "contacts"."id" AND "contacts"."deleted_date" IS NOT NULL' + "SELECT * FROM ""users"" INNER JOIN ""contacts"" ON ""users"".""id"" = ""contacts"".""id"" AND ""contacts"".""deleted_date"" IS NOT NULL" ); expect( builder.getBindings() ).toBe( [] ); } ); @@ -480,7 +480,7 @@ component extends="testbox.system.BaseSpec" { } ); expect( builder.toSql() ).toBe( - 'SELECT * FROM "users" INNER JOIN "contacts" ON "users"."id" = "contacts"."id" OR "contacts"."deleted_date" IS NOT NULL' + "SELECT * FROM ""users"" INNER JOIN ""contacts"" ON ""users"".""id"" = ""contacts"".""id"" OR ""contacts"".""deleted_date"" IS NOT NULL" ); expect( builder.getBindings() ).toBe( [] ); } ); @@ -493,7 +493,7 @@ component extends="testbox.system.BaseSpec" { .whereIn( "contacts.id", [ 1, 2, 3 ] ); } ); expect( builder.toSql() ).toBe( - 'SELECT * FROM "users" INNER JOIN "contacts" ON "users"."id" = "contacts"."id" AND "contacts"."id" IN (?, ?, ?)' + "SELECT * FROM ""users"" INNER JOIN ""contacts"" ON ""users"".""id"" = ""contacts"".""id"" AND ""contacts"".""id"" IN (?, ?, ?)" ); expect( builder.getBindings() ).toBe( [ 1, 2, 3 ] ); } ); @@ -506,7 +506,7 @@ component extends="testbox.system.BaseSpec" { .orWhereIn( "contacts.id", [ 1, 2, 3 ] ); } ); expect( builder.toSql() ).toBe( - 'SELECT * FROM "users" INNER JOIN "contacts" ON "users"."id" = "contacts"."id" OR "contacts"."id" IN (?, ?, ?)' + "SELECT * FROM ""users"" INNER JOIN ""contacts"" ON ""users"".""id"" = ""contacts"".""id"" OR ""contacts"".""id"" IN (?, ?, ?)" ); expect( builder.getBindings() ).toBe( [ 1, 2, 3 ] ); } ); @@ -519,7 +519,7 @@ component extends="testbox.system.BaseSpec" { .whereNotIn( "contacts.id", [ 1, 2, 3 ] ); } ); expect( builder.toSql() ).toBe( - 'SELECT * FROM "users" INNER JOIN "contacts" ON "users"."id" = "contacts"."id" AND "contacts"."id" NOT IN (?, ?, ?)' + "SELECT * FROM ""users"" INNER JOIN ""contacts"" ON ""users"".""id"" = ""contacts"".""id"" AND ""contacts"".""id"" NOT IN (?, ?, ?)" ); expect( builder.getBindings() ).toBe( [ 1, 2, 3 ] ); } ); @@ -532,13 +532,13 @@ component extends="testbox.system.BaseSpec" { .orWhereNotIn( "contacts.id", [ 1, 2, 3 ] ); } ); expect( builder.toSql() ).toBe( - 'SELECT * FROM "users" INNER JOIN "contacts" ON "users"."id" = "contacts"."id" OR "contacts"."id" NOT IN (?, ?, ?)' + "SELECT * FROM ""users"" INNER JOIN ""contacts"" ON ""users"".""id"" = ""contacts"".""id"" OR ""contacts"".""id"" NOT IN (?, ?, ?)" ); expect( builder.getBindings() ).toBe( [ 1, 2, 3 ] ); } ); } ); - describe( '"when" callbacks', function() { + describe( """when"" callbacks", function() { it( "executes the callback when the condition is true", function() { var callback = function( query ) { return query.where( "id", "=", 1 ); @@ -550,7 +550,7 @@ component extends="testbox.system.BaseSpec" { .when( true, callback ) .where( "email", "foo" ); expect( builder.toSql() ).toBe( - 'SELECT * FROM "users" WHERE "id" = ? AND "email" = ?' + "SELECT * FROM ""users"" WHERE ""id"" = ? AND ""email"" = ?" ); expect( builder.getBindings() ).toBe( [ 1, "foo" ] ); } ); @@ -566,7 +566,7 @@ component extends="testbox.system.BaseSpec" { .when( false, callback ) .where( "email", "foo" ); expect( builder.toSql() ).toBe( - 'SELECT * FROM "users" WHERE "email" = ?' + "SELECT * FROM ""users"" WHERE ""email"" = ?" ); expect( builder.getBindings() ).toBe( [ "foo" ] ); } ); @@ -586,7 +586,7 @@ component extends="testbox.system.BaseSpec" { .when( false, callback, default ) .where( "email", "foo" ); expect( builder.toSql() ).toBe( - 'SELECT * FROM "users" WHERE "id" = ? AND "email" = ?' + "SELECT * FROM ""users"" WHERE ""id"" = ? AND ""email"" = ?" ); expect( builder.getBindings() ).toBe( [ 2, "foo" ] ); } ); @@ -606,7 +606,7 @@ component extends="testbox.system.BaseSpec" { .when( true, callback, default ) .where( "email", "foo" ); expect( builder.toSql() ).toBe( - 'SELECT * FROM "users" WHERE "id" = ? AND "email" = ?' + "SELECT * FROM ""users"" WHERE ""id"" = ? AND ""email"" = ?" ); expect( builder.getBindings() ).toBe( [ 1, "foo" ] ); } ); @@ -617,7 +617,7 @@ component extends="testbox.system.BaseSpec" { var builder = getBuilder(); builder.select( "*" ).from( "users" ).groupBy( "email" ); expect( builder.toSql() ).toBe( - 'SELECT * FROM "users" GROUP BY "email"' + "SELECT * FROM ""users"" GROUP BY ""email""" ); expect( builder.getBindings() ).toBe( [] ); } ); @@ -626,7 +626,7 @@ component extends="testbox.system.BaseSpec" { var builder = getBuilder(); builder.select( "*" ).from( "users" ).groupBy( "id", "email" ); expect( builder.toSql() ).toBe( - 'SELECT * FROM "users" GROUP BY "id", "email"' + "SELECT * FROM ""users"" GROUP BY ""id"", ""email""" ); expect( builder.getBindings() ).toBe( [] ); } ); @@ -635,7 +635,7 @@ component extends="testbox.system.BaseSpec" { var builder = getBuilder(); builder.select( "*" ).from( "users" ).groupBy( [ "id", "email" ] ); expect( builder.toSql() ).toBe( - 'SELECT * FROM "users" GROUP BY "id", "email"' + "SELECT * FROM ""users"" GROUP BY ""id"", ""email""" ); expect( builder.getBindings() ).toBe( [] ); } ); @@ -645,7 +645,7 @@ component extends="testbox.system.BaseSpec" { builder.select( "*" ).from( "users" ) .groupBy( builder.raw( "DATE(created_at)" ) ); expect( builder.toSql() ).toBe( - 'SELECT * FROM "users" GROUP BY DATE(created_at)' + "SELECT * FROM ""users"" GROUP BY DATE(created_at)" ); expect( builder.getBindings() ).toBe( [] ); } ); @@ -656,7 +656,7 @@ component extends="testbox.system.BaseSpec" { var builder = getBuilder(); builder.select( "*" ).from( "users" ).orderBy( "email" ); expect( builder.toSql() ).toBe( - 'SELECT * FROM "users" ORDER BY "email" ASC' + "SELECT * FROM ""users"" ORDER BY ""email"" ASC" ); expect( builder.getBindings() ).toBe( [] ); } ); @@ -665,7 +665,7 @@ component extends="testbox.system.BaseSpec" { var builder = getBuilder(); builder.select( "*" ).from( "users" ).orderBy( "email", "desc" ); expect( builder.toSql() ).toBe( - 'SELECT * FROM "users" ORDER BY "email" DESC' + "SELECT * FROM ""users"" ORDER BY ""email"" DESC" ); expect( builder.getBindings() ).toBe( [] ); } ); @@ -675,7 +675,7 @@ component extends="testbox.system.BaseSpec" { builder.select( "*" ).from( "users" ) .orderBy( "id" ).orderBy( "email", "desc" ); expect( builder.toSql() ).toBe( - 'SELECT * FROM "users" ORDER BY "id" ASC, "email" DESC' + "SELECT * FROM ""users"" ORDER BY ""id"" ASC, ""email"" DESC" ); expect( builder.getBindings() ).toBe( [] ); } ); @@ -685,7 +685,7 @@ component extends="testbox.system.BaseSpec" { builder.select( "*" ).from( "users" ) .groupBy( builder.raw( "DATE(created_at)" ) ); expect( builder.toSql() ).toBe( - 'SELECT * FROM "users" ORDER BY(created_at)' + "SELECT * FROM ""users"" ORDER BY(created_at)" ); expect( builder.getBindings() ).toBe( [] ); } ); diff --git a/tests/specs/Query/Builder/BuilderCollaboratorsSpec.cfc b/tests/specs/Query/Builder/BuilderCollaboratorsSpec.cfc index c2c4e94f..82261cda 100644 --- a/tests/specs/Query/Builder/BuilderCollaboratorsSpec.cfc +++ b/tests/specs/Query/Builder/BuilderCollaboratorsSpec.cfc @@ -1,16 +1,16 @@ -component extends='testbox.system.BaseSpec' { +component extends="testbox.system.BaseSpec" { function run() { - describe('interaction with collaborators', function() { - beforeEach(function() { - variables.mockGrammar = getMockBox().createStub(implements = 'Quick.models.Query.Grammars.GrammarInterface'); + describe( "interaction with collaborators", function() { + beforeEach( function() { + variables.mockGrammar = getMockBox().createStub( implements = "Quick.models.Query.Grammars.GrammarInterface" ); variables.query = new Quick.models.Query.Builder(); - getMockBox().prepareMock(query); - query.$property(propertyName = 'grammar', mock = mockGrammar); - }); + getMockBox().prepareMock( query ); + query.$property( propertyName = "grammar", mock = mockGrammar ); + } ); - describe('interaction with grammar', function() { - describe('toSQL()', function() { - xit('returns the result of sending itself to its grammar', function() { + describe( "interaction with grammar", function() { + describe( "toSQL()", function() { + xit( "returns the result of sending itself to its grammar", function() { // Expecting the query to be passed in $args() is not working here. // Even stranger is the fact that the callLog shows a call, // isArray() says it's an array, but arrayLen() says 0 and @@ -21,12 +21,12 @@ component extends='testbox.system.BaseSpec' { // debug(isArray(callLog)); // debug(arrayLen(callLog)); - mockGrammar.$('compileSelect').$results('::compiled SQL::'); - expect(query.toSQL()).toBe('::compiled SQL::'); - expect(mockGrammar.$once('compileSelect')).toBeTrue('compileSelect() should have been called once.'); - }); - }); - }); - }); + mockGrammar.$( "compileSelect" ).$results( "::compiled SQL::" ); + expect( query.toSQL() ).toBe( "::compiled SQL::" ); + expect( mockGrammar.$once( "compileSelect" ) ).toBeTrue( "compileSelect() should have been called once." ); + } ); + } ); + } ); + } ); } } \ No newline at end of file diff --git a/tests/specs/Query/Builder/BuilderGetSpec.cfc b/tests/specs/Query/Builder/BuilderGetSpec.cfc index f4a87afb..874fb937 100644 --- a/tests/specs/Query/Builder/BuilderGetSpec.cfc +++ b/tests/specs/Query/Builder/BuilderGetSpec.cfc @@ -1,52 +1,52 @@ -component extends='testbox.system.BaseSpec' { +component extends="testbox.system.BaseSpec" { function run() { - describe('get methods', function() { - beforeEach(function() { + describe( "get methods", function() { + beforeEach( function() { variables.query = new Quick.models.Query.Builder(); - getMockBox().prepareMock(query); + getMockBox().prepareMock( query ); var utils = new Quick.models.Query.QueryUtils(); - query.$property(propertyName = 'utils', mock = utils); + query.$property( propertyName = "utils", mock = utils ); var mockWirebox = getMockBox().createStub(); var mockJoinClause = getMockBox() - .prepareMock(new Quick.models.Query.JoinClause('inner', 'second')); - mockJoinClause.$property(propertyName = 'utils', mock = utils); + .prepareMock( new Quick.models.Query.JoinClause( "inner", "second" ) ); + mockJoinClause.$property( propertyName = "utils", mock = utils ); mockWirebox - .$('getInstance') - .$args(name = 'JoinClause@Quick', initArguments = { - type = 'inner', - table = 'second' - }) - .$results(mockJoinClause); - query.$property(propertyName = 'wirebox', mock = mockWirebox); - }); + .$( "getInstance" ) + .$args( name = "JoinClause@Quick", initArguments = { + type = "inner", + table = "second" + } ) + .$results( mockJoinClause ); + query.$property( propertyName = "wirebox", mock = mockWirebox ); + } ); - it('retreives bindings in a flat array', function() { - query.join('second', function(join) { - join.where('second.locale', '=', 'en-US'); - }).where('first.quantity', '>=', '10'); + it( "retreives bindings in a flat array", function() { + query.join( "second", function( join ) { + join.where( "second.locale", "=", "en-US" ); + } ).where( "first.quantity", ">=", "10" ); var bindings = query.getBindings(); - expect(bindings).toBeArray(); - expect(arrayLen(bindings)).toBe(2, '2 bindings should exist'); - var binding = bindings[1]; - expect(binding.value).toBe('en-US'); - expect(binding.cfsqltype).toBe('cf_sql_varchar'); - var binding = bindings[2]; - expect(binding.value).toBe(10); - expect(binding.cfsqltype).toBe('cf_sql_numeric'); - }); + expect( bindings ).toBeArray(); + expect( arrayLen( bindings ) ).toBe( 2, "2 bindings should exist" ); + var binding = bindings[ 1 ]; + expect( binding.value ).toBe( "en-US" ); + expect( binding.cfsqltype ).toBe( "cf_sql_varchar" ); + var binding = bindings[ 2 ]; + expect( binding.value ).toBe( 10 ); + expect( binding.cfsqltype ).toBe( "cf_sql_numeric" ); + } ); - it('retreives a map of bindings', function() { - query.join('second', function(join) { - join.where('second.locale', '=', 'en-US'); - }).where('first.quantity', '>=', '10'); + it( "retreives a map of bindings", function() { + query.join( "second", function( join ) { + join.where( "second.locale", "=", "en-US" ); + } ).where( "first.quantity", ">=", "10" ); var bindings = query.getRawBindings(); - expect(bindings).toBeStruct(); - }); - }); + expect( bindings ).toBeStruct(); + } ); + } ); } } \ No newline at end of file diff --git a/tests/specs/Query/Builder/BuilderJoinSpec.cfc b/tests/specs/Query/Builder/BuilderJoinSpec.cfc index 4f178bc3..7d1a11d6 100644 --- a/tests/specs/Query/Builder/BuilderJoinSpec.cfc +++ b/tests/specs/Query/Builder/BuilderJoinSpec.cfc @@ -1,207 +1,207 @@ -component extends='testbox.system.BaseSpec' { +component extends="testbox.system.BaseSpec" { function run() { - describe('join methods', function() { - beforeEach(function() { + describe( "join methods", function() { + beforeEach( function() { variables.query = new Quick.models.Query.Builder(); - getMockBox().prepareMock(query); + getMockBox().prepareMock( query ); variables.utils = new Quick.models.Query.QueryUtils(); - query.$property(propertyName = 'utils', mock = utils); + query.$property( propertyName = "utils", mock = utils ); variables.mockWirebox = getMockBox().createStub(); var mockJoinClause = getMockBox() - .prepareMock(new Quick.models.Query.JoinClause('inner', 'second')); - mockJoinClause.$property(propertyName = 'utils', mock = utils); + .prepareMock( new Quick.models.Query.JoinClause( "inner", "second" ) ); + mockJoinClause.$property( propertyName = "utils", mock = utils ); mockWirebox - .$('getInstance') - .$args(name = 'JoinClause@Quick', initArguments = { - type = 'inner', - table = 'second' - }) - .$results(mockJoinClause); - query.$property(propertyName = 'wirebox', mock = mockWirebox); - }); - - it('does a simple inner join', function() { + .$( "getInstance" ) + .$args( name = "JoinClause@Quick", initArguments = { + type = "inner", + table = "second" + } ) + .$results( mockJoinClause ); + query.$property( propertyName = "wirebox", mock = mockWirebox ); + } ); + + it( "does a simple inner join", function() { var mockJoinClause = getMockBox() - .prepareMock(new Quick.models.Query.JoinClause('inner', 'second')); - mockJoinClause.$property(propertyName = 'utils', mock = utils); + .prepareMock( new Quick.models.Query.JoinClause( "inner", "second" ) ); + mockJoinClause.$property( propertyName = "utils", mock = utils ); mockWirebox - .$('getInstance') - .$args(name = 'JoinClause@Quick', initArguments = { - type = 'inner', - table = 'second' - }) - .$results(mockJoinClause); + .$( "getInstance" ) + .$args( name = "JoinClause@Quick", initArguments = { + type = "inner", + table = "second" + } ) + .$results( mockJoinClause ); - query.join('second', 'first.id', '=', 'second.first_id'); + query.join( "second", "first.id", "=", "second.first_id" ); var joins = query.getJoins(); - expect(arrayLen(joins)).toBe(1, 'Only one join should exist'); + expect( arrayLen( joins ) ).toBe( 1, "Only one join should exist" ); - var join = joins[1]; - expect(join).toBeInstanceOf('Quick.models.Query.JoinClause'); - expect(join.getType()).toBe('inner'); - expect(join.getTable()).toBe('second'); + var join = joins[ 1 ]; + expect( join ).toBeInstanceOf( "Quick.models.Query.JoinClause" ); + expect( join.getType() ).toBe( "inner" ); + expect( join.getTable() ).toBe( "second" ); var clauses = join.getClauses(); - expect(arrayLen(clauses)).toBe(1, 'Only one join clause should exist'); - - var clause = clauses[1]; - expect(clause).toBeStruct(); - expect(clause.first).toBe('first.id', 'First column should be [first.id]'); - expect(clause.operator).toBe('=', 'Operator should be [=]'); - expect(clause.second).toBe('second.first_id', 'First column should be [second.first_id]'); - expect(clause.combinator).toBe('and'); - expect(clause.where).toBe(false); - }); - - it('does a left join', function() { + expect( arrayLen( clauses ) ).toBe( 1, "Only one join clause should exist" ); + + var clause = clauses[ 1 ]; + expect( clause ).toBeStruct(); + expect( clause.first ).toBe( "first.id", "First column should be [first.id]" ); + expect( clause.operator ).toBe( "=", "Operator should be [=]" ); + expect( clause.second ).toBe( "second.first_id", "First column should be [second.first_id]" ); + expect( clause.combinator ).toBe( "and" ); + expect( clause.where ).toBe( false ); + } ); + + it( "does a left join", function() { var mockJoinClause = getMockBox() - .prepareMock(new Quick.models.Query.JoinClause('left', 'second')); - mockJoinClause.$property(propertyName = 'utils', mock = utils); + .prepareMock( new Quick.models.Query.JoinClause( "left", "second" ) ); + mockJoinClause.$property( propertyName = "utils", mock = utils ); mockWirebox - .$('getInstance') - .$args(name = 'JoinClause@Quick', initArguments = { - type = 'left', - table = 'second' - }) - .$results(mockJoinClause); + .$( "getInstance" ) + .$args( name = "JoinClause@Quick", initArguments = { + type = "left", + table = "second" + } ) + .$results( mockJoinClause ); - query.leftJoin('second', 'first.id', '=', 'second.first_id'); + query.leftJoin( "second", "first.id", "=", "second.first_id" ); var joins = query.getJoins(); - expect(arrayLen(joins)).toBe(1, 'Only one join should exist'); + expect( arrayLen( joins ) ).toBe( 1, "Only one join should exist" ); - var join = joins[1]; - expect(join).toBeInstanceOf('Quick.models.Query.JoinClause'); - expect(join.getType()).toBe('left'); - expect(join.getTable()).toBe('second'); + var join = joins[ 1 ]; + expect( join ).toBeInstanceOf( "Quick.models.Query.JoinClause" ); + expect( join.getType() ).toBe( "left" ); + expect( join.getTable() ).toBe( "second" ); var clauses = join.getClauses(); - expect(arrayLen(clauses)).toBe(1, 'Only one join clause should exist'); - - var clause = clauses[1]; - expect(clause).toBeStruct(); - expect(clause.first).toBe('first.id', 'First column should be [first.id]'); - expect(clause.operator).toBe('=', 'Operator should be [=]'); - expect(clause.second).toBe('second.first_id', 'First column should be [second.first_id]'); - expect(clause.combinator).toBe('and'); - expect(clause.where).toBe(false); - }); - - it('does a right join', function() { + expect( arrayLen( clauses ) ).toBe( 1, "Only one join clause should exist" ); + + var clause = clauses[ 1 ]; + expect( clause ).toBeStruct(); + expect( clause.first ).toBe( "first.id", "First column should be [first.id]" ); + expect( clause.operator ).toBe( "=", "Operator should be [=]" ); + expect( clause.second ).toBe( "second.first_id", "First column should be [second.first_id]" ); + expect( clause.combinator ).toBe( "and" ); + expect( clause.where ).toBe( false ); + } ); + + it( "does a right join", function() { var mockJoinClause = getMockBox() - .prepareMock(new Quick.models.Query.JoinClause('right', 'second')); - mockJoinClause.$property(propertyName = 'utils', mock = utils); + .prepareMock( new Quick.models.Query.JoinClause( "right", "second" ) ); + mockJoinClause.$property( propertyName = "utils", mock = utils ); mockWirebox - .$('getInstance') - .$args(name = 'JoinClause@Quick', initArguments = { - type = 'right', - table = 'second' - }) - .$results(mockJoinClause); + .$( "getInstance" ) + .$args( name = "JoinClause@Quick", initArguments = { + type = "right", + table = "second" + } ) + .$results( mockJoinClause ); - query.rightJoin('second', 'first.id', '=', 'second.first_id'); + query.rightJoin( "second", "first.id", "=", "second.first_id" ); var joins = query.getJoins(); - expect(arrayLen(joins)).toBe(1, 'Only one join should exist'); + expect( arrayLen( joins ) ).toBe( 1, "Only one join should exist" ); - var join = joins[1]; - expect(join).toBeInstanceOf('Quick.models.Query.JoinClause'); - expect(join.getType()).toBe('right'); - expect(join.getTable()).toBe('second'); + var join = joins[ 1 ]; + expect( join ).toBeInstanceOf( "Quick.models.Query.JoinClause" ); + expect( join.getType() ).toBe( "right" ); + expect( join.getTable() ).toBe( "second" ); var clauses = join.getClauses(); - expect(arrayLen(clauses)).toBe(1, 'Only one join clause should exist'); - - var clause = clauses[1]; - expect(clause).toBeStruct(); - expect(clause.first).toBe('first.id', 'First column should be [first.id]'); - expect(clause.operator).toBe('=', 'Operator should be [=]'); - expect(clause.second).toBe('second.first_id', 'First column should be [second.first_id]'); - expect(clause.combinator).toBe('and'); - expect(clause.where).toBe(false); - }); - - it('can use a callback to specify advanced join clauses', function() { - query.join(table = 'second', conditions = function(join) { - join.on('first.id', '=', 'second.first_id') - .on('first.locale', '=', 'second.locale'); - }); + expect( arrayLen( clauses ) ).toBe( 1, "Only one join clause should exist" ); + + var clause = clauses[ 1 ]; + expect( clause ).toBeStruct(); + expect( clause.first ).toBe( "first.id", "First column should be [first.id]" ); + expect( clause.operator ).toBe( "=", "Operator should be [=]" ); + expect( clause.second ).toBe( "second.first_id", "First column should be [second.first_id]" ); + expect( clause.combinator ).toBe( "and" ); + expect( clause.where ).toBe( false ); + } ); + + it( "can use a callback to specify advanced join clauses", function() { + query.join( table = "second", conditions = function( join ) { + join.on( "first.id", "=", "second.first_id" ) + .on( "first.locale", "=", "second.locale" ); + } ); var joins = query.getJoins(); - expect(arrayLen(joins)).toBe(1, 'Only one join should exist'); + expect( arrayLen( joins ) ).toBe( 1, "Only one join should exist" ); - var join = joins[1]; - expect(join).toBeInstanceOf('Quick.models.Query.JoinClause'); - expect(join.getType()).toBe('inner'); - expect(join.getTable()).toBe('second'); + var join = joins[ 1 ]; + expect( join ).toBeInstanceOf( "Quick.models.Query.JoinClause" ); + expect( join.getType() ).toBe( "inner" ); + expect( join.getTable() ).toBe( "second" ); var clauses = join.getClauses(); - expect(arrayLen(clauses)).toBe(2, 'Two join clauses should exist'); - - var clauseOne = clauses[1]; - expect(clauseOne).toBeStruct(); - expect(clauseOne.first).toBe('first.id', 'First column should be [first.id]'); - expect(clauseOne.operator).toBe('=', 'Operator should be [=]'); - expect(clauseOne.second).toBe('second.first_id', 'First column should be [second.first_id]'); - expect(clauseOne.combinator).toBe('and'); - expect(clauseOne.where).toBe(false); - - var clauseTwo = clauses[2]; - expect(clauseTwo).toBeStruct(); - expect(clauseTwo.first).toBe('first.locale', 'First column should be [first.locale]'); - expect(clauseTwo.operator).toBe('=', 'Operator should be [=]'); - expect(clauseTwo.second).toBe('second.locale', 'First column should be [second.locale]'); - expect(clauseTwo.combinator).toBe('and'); - expect(clauseTwo.where).toBe(false); - }); - - it('can pass the callback as the second parameter when using positional parameters', function() { - query.join('second', function(join) { - join.on('first.id', '=', 'second.first_id') - .on('first.locale', '=', 'second.locale'); - }); + expect( arrayLen( clauses ) ).toBe( 2, "Two join clauses should exist" ); + + var clauseOne = clauses[ 1 ]; + expect( clauseOne ).toBeStruct(); + expect( clauseOne.first ).toBe( "first.id", "First column should be [first.id]" ); + expect( clauseOne.operator ).toBe( "=", "Operator should be [=]" ); + expect( clauseOne.second ).toBe( "second.first_id", "First column should be [second.first_id]" ); + expect( clauseOne.combinator ).toBe( "and" ); + expect( clauseOne.where ).toBe( false ); + + var clauseTwo = clauses[ 2 ]; + expect( clauseTwo ).toBeStruct(); + expect( clauseTwo.first ).toBe( "first.locale", "First column should be [first.locale]" ); + expect( clauseTwo.operator ).toBe( "=", "Operator should be [=]" ); + expect( clauseTwo.second ).toBe( "second.locale", "First column should be [second.locale]" ); + expect( clauseTwo.combinator ).toBe( "and" ); + expect( clauseTwo.where ).toBe( false ); + } ); + + it( "can pass the callback as the second parameter when using positional parameters", function() { + query.join( "second", function( join ) { + join.on( "first.id", "=", "second.first_id" ) + .on( "first.locale", "=", "second.locale" ); + } ); var joins = query.getJoins(); - expect(arrayLen(joins)).toBe(1, 'Only one join should exist'); + expect( arrayLen( joins ) ).toBe( 1, "Only one join should exist" ); - var join = joins[1]; - expect(join).toBeInstanceOf('Quick.models.Query.JoinClause'); - expect(join.getType()).toBe('inner'); - expect(join.getTable()).toBe('second'); + var join = joins[ 1 ]; + expect( join ).toBeInstanceOf( "Quick.models.Query.JoinClause" ); + expect( join.getType() ).toBe( "inner" ); + expect( join.getTable() ).toBe( "second" ); var clauses = join.getClauses(); - expect(arrayLen(clauses)).toBe(2, 'Two join clauses should exist'); - - var clauseOne = clauses[1]; - expect(clauseOne).toBeStruct(); - expect(clauseOne.first).toBe('first.id', 'First column should be [first.id]'); - expect(clauseOne.operator).toBe('=', 'Operator should be [=]'); - expect(clauseOne.second).toBe('second.first_id', 'First column should be [second.first_id]'); - expect(clauseOne.combinator).toBe('and'); - expect(clauseOne.where).toBe(false); - - var clauseTwo = clauses[2]; - expect(clauseTwo).toBeStruct(); - expect(clauseTwo.first).toBe('first.locale', 'First column should be [first.locale]'); - expect(clauseTwo.operator).toBe('=', 'Operator should be [=]'); - expect(clauseTwo.second).toBe('second.locale', 'First column should be [second.locale]'); - expect(clauseTwo.combinator).toBe('and'); - expect(clauseTwo.where).toBe(false); - }); - - it('adds the join bindings to the builder bindings', function() { - query.join('second', function(join) { - join.where('second.locale', '=', 'en-US'); - }); + expect( arrayLen( clauses ) ).toBe( 2, "Two join clauses should exist" ); + + var clauseOne = clauses[ 1 ]; + expect( clauseOne ).toBeStruct(); + expect( clauseOne.first ).toBe( "first.id", "First column should be [first.id]" ); + expect( clauseOne.operator ).toBe( "=", "Operator should be [=]" ); + expect( clauseOne.second ).toBe( "second.first_id", "First column should be [second.first_id]" ); + expect( clauseOne.combinator ).toBe( "and" ); + expect( clauseOne.where ).toBe( false ); + + var clauseTwo = clauses[ 2 ]; + expect( clauseTwo ).toBeStruct(); + expect( clauseTwo.first ).toBe( "first.locale", "First column should be [first.locale]" ); + expect( clauseTwo.operator ).toBe( "=", "Operator should be [=]" ); + expect( clauseTwo.second ).toBe( "second.locale", "First column should be [second.locale]" ); + expect( clauseTwo.combinator ).toBe( "and" ); + expect( clauseTwo.where ).toBe( false ); + } ); + + it( "adds the join bindings to the builder bindings", function() { + query.join( "second", function( join ) { + join.where( "second.locale", "=", "en-US" ); + } ); var bindings = query.getRawBindings().join; - expect(bindings).toBeArray(); - expect(arrayLen(bindings)).toBe(1, '1 binding should exist'); - var binding = bindings[1]; - expect(binding.value).toBe('en-US'); - expect(binding.cfsqltype).toBe('cf_sql_varchar'); - }); - }); + expect( bindings ).toBeArray(); + expect( arrayLen( bindings ) ).toBe( 1, "1 binding should exist" ); + var binding = bindings[ 1 ]; + expect( binding.value ).toBe( "en-US" ); + expect( binding.cfsqltype ).toBe( "cf_sql_varchar" ); + } ); + } ); } } \ No newline at end of file diff --git a/tests/specs/Query/Builder/BuilderSelectSpec.cfc b/tests/specs/Query/Builder/BuilderSelectSpec.cfc index 8d74947c..e99e4d84 100644 --- a/tests/specs/Query/Builder/BuilderSelectSpec.cfc +++ b/tests/specs/Query/Builder/BuilderSelectSpec.cfc @@ -1,79 +1,79 @@ -component extends='testbox.system.BaseSpec' { +component extends="testbox.system.BaseSpec" { function run() { - describe('select methods', function() { - beforeEach(function() { - variables.mockGrammar = getMockBox().createStub(implements = 'Quick.models.Query.Grammars.GrammarInterface'); - variables.query = new Quick.models.Query.Builder(variables.mockGrammar); - }); + describe( "select methods", function() { + beforeEach( function() { + variables.mockGrammar = getMockBox().createStub( implements = "Quick.models.Query.Grammars.GrammarInterface" ); + variables.query = new Quick.models.Query.Builder( variables.mockGrammar ); + } ); - describe('select()', function() { - it ('defaults to all columns', function() { - expect(query.getColumns()).toBe(['*']); - }); + describe( "select()", function() { + it ( "defaults to all columns", function() { + expect( query.getColumns() ).toBe( [ "*" ] ); + } ); - it('can specify a single column from a query', function() { - query.select('::some_column::'); - expect(query.getColumns()).toBe(['::some_column::']); - }); + it( "can specify a single column from a query", function() { + query.select( "::some_column::" ); + expect( query.getColumns() ).toBe( [ "::some_column::" ] ); + } ); - describe('can specify multiple columns in a query', function() { - it('using a list', function() { - query.select('::some_column::, ::another_column::'); - expect(query.getColumns()).toBe(['::some_column::', '::another_column::']); - }); + describe( "can specify multiple columns in a query", function() { + it( "using a list", function() { + query.select( "::some_column::, ::another_column::" ); + expect( query.getColumns() ).toBe( [ "::some_column::", "::another_column::" ] ); + } ); - it('using an array', function() { - query.select(['::some_column::', '::another_column::']); - expect(query.getColumns()).toBe(['::some_column::', '::another_column::']); - }); + it( "using an array", function() { + query.select( [ "::some_column::", "::another_column::" ] ); + expect( query.getColumns() ).toBe( [ "::some_column::", "::another_column::" ] ); + } ); - it('using variadic parameters', function() { - query.select('::some_column::', '::another_column::'); - expect(query.getColumns()).toBe(['::some_column::', '::another_column::']); - }); - }); - }); + it( "using variadic parameters", function() { + query.select( "::some_column::", "::another_column::" ); + expect( query.getColumns() ).toBe( [ "::some_column::", "::another_column::" ] ); + } ); + } ); + } ); - describe('addSelect()', function() { - beforeEach(function() { - query.select('::some_column::'); - expect(query.getColumns()).toBe(['::some_column::']); - }); + describe( "addSelect()", function() { + beforeEach( function() { + query.select( "::some_column::" ); + expect( query.getColumns() ).toBe( [ "::some_column::" ] ); + } ); - it('can add a single column to an existing query', function() { - query.addSelect('::another_column::'); - expect(query.getColumns()).toBe(['::some_column::', '::another_column::']); - }); + it( "can add a single column to an existing query", function() { + query.addSelect( "::another_column::" ); + expect( query.getColumns() ).toBe( [ "::some_column::", "::another_column::" ] ); + } ); - describe('can add multiple columns to an existing query', function() { - it('using a list', function() { - query.addSelect('::another_column::, ::yet_another_column::'); - expect(query.getColumns()).toBe(['::some_column::', '::another_column::', '::yet_another_column::']); - }); + describe( "can add multiple columns to an existing query", function() { + it( "using a list", function() { + query.addSelect( "::another_column::, ::yet_another_column::" ); + expect( query.getColumns() ).toBe( [ "::some_column::", "::another_column::", "::yet_another_column::" ] ); + } ); - it('using an array', function() { - query.addSelect(['::another_column::', '::yet_another_column::']); - expect(query.getColumns()).toBe(['::some_column::', '::another_column::', '::yet_another_column::']); - }); + it( "using an array", function() { + query.addSelect( [ "::another_column::", "::yet_another_column::" ] ); + expect( query.getColumns() ).toBe( [ "::some_column::", "::another_column::", "::yet_another_column::" ] ); + } ); - it('using variadic parameters', function() { - query.addSelect('::another_column::', '::yet_another_column::'); - expect(query.getColumns()).toBe(['::some_column::', '::another_column::', '::yet_another_column::']); - }); - }); - }); + it( "using variadic parameters", function() { + query.addSelect( "::another_column::", "::yet_another_column::" ); + expect( query.getColumns() ).toBe( [ "::some_column::", "::another_column::", "::yet_another_column::" ] ); + } ); + } ); + } ); - describe('distinct()', function() { - it('sets the distinct flag', function() { - expect(query.getDistinct()).toBe(false, - 'Queries are not distinct by default'); + describe( "distinct()", function() { + it( "sets the distinct flag", function() { + expect( query.getDistinct() ).toBe( false, + "Queries are not distinct by default" ); query.distinct(); - expect(query.getDistinct()).toBe(true, - 'Distinct should be set to true'); - }); - }); - }); + expect( query.getDistinct() ).toBe( true, + "Distinct should be set to true" ); + } ); + } ); + } ); } } \ No newline at end of file diff --git a/tests/specs/Query/Builder/BuilderWhereSpec.cfc b/tests/specs/Query/Builder/BuilderWhereSpec.cfc index 254feab1..d7bcb694 100644 --- a/tests/specs/Query/Builder/BuilderWhereSpec.cfc +++ b/tests/specs/Query/Builder/BuilderWhereSpec.cfc @@ -1,150 +1,150 @@ -component extends='testbox.system.BaseSpec' { +component extends="testbox.system.BaseSpec" { function run() { - describe('where methods', function() { - beforeEach(function() { + describe( "where methods", function() { + beforeEach( function() { variables.query = new Quick.models.Query.Builder(); - getMockBox().prepareMock(query); - query.$property(propertyName = 'utils', mock = new Quick.models.Query.QueryUtils()); - }); - - it('defaults to empty', function() { - expect(query.getWheres()).toBeEmpty('Default `wheres` should be empty.'); - }); - - describe('where', function() { - it('specifices a where clause', function() { - query.where('::some column::', '=', '::some value::'); - expect(query.getWheres()).toBe([{ - column = '::some column::', - operator = '=', - value = '::some value::', - combinator = 'and' - }]); - }); - - it('only infers the = when only two arguments', function() { - query.where('::some column::', '::some value::'); - expect(query.getWheres()).toBe([{ - column = '::some column::', - operator = '=', - value = '::some value::', - combinator = 'and' - }]); - }); - - it('can be specify the boolean combinator', function() { - query.where('::some column::', '=', '::some value::') - .where('::another column::', '=', '::another value::', 'or'); - expect(query.getWheres()).toBe([ + getMockBox().prepareMock( query ); + query.$property( propertyName = "utils", mock = new Quick.models.Query.QueryUtils() ); + } ); + + it( "defaults to empty", function() { + expect( query.getWheres() ).toBeEmpty( "Default `wheres` should be empty." ); + } ); + + describe( "where", function() { + it( "specifices a where clause", function() { + query.where( "::some column::", "=", "::some value::" ); + expect( query.getWheres() ).toBe( [ { + column = "::some column::", + operator = "=", + value = "::some value::", + combinator = "and" + } ] ); + } ); + + it( "only infers the = when only two arguments", function() { + query.where( "::some column::", "::some value::" ); + expect( query.getWheres() ).toBe( [ { + column = "::some column::", + operator = "=", + value = "::some value::", + combinator = "and" + } ] ); + } ); + + it( "can be specify the boolean combinator", function() { + query.where( "::some column::", "=", "::some value::" ) + .where( "::another column::", "=", "::another value::", "or" ); + expect( query.getWheres() ).toBe( [ { - column = '::some column::', - operator = '=', - value = '::some value::', - combinator = 'and' + column = "::some column::", + operator = "=", + value = "::some value::", + combinator = "and" }, { - column = '::another column::', - operator = '=', - value = '::another value::', - combinator = 'or' + column = "::another column::", + operator = "=", + value = "::another value::", + combinator = "or" } - ]); - }); + ] ); + } ); - describe('specialized where methods', function() { - it('has a whereIn shortcut', function() { - query.whereIn('::some column::', ['::value one::', '::value two::']); + describe( "specialized where methods", function() { + it( "has a whereIn shortcut", function() { + query.whereIn( "::some column::", [ "::value one::", "::value two::" ] ); var wheres = query.getWheres(); - expect(wheres).toBeArray(); - expect(arrayLen(wheres)).toBe(1, '1 where clause should exist'); - var where = wheres[1]; - expect(where.column).toBe('::some column::'); - expect(where.operator).toBe('in'); - expect(where.value).toBe(['::value one::', '::value two::']); - expect(where.combinator).toBe('and'); - }); - - it('has a whereNotIn shortcut', function() { - query.whereNotIn('::some column::', ['::value one::', '::value two::']); + expect( wheres ).toBeArray(); + expect( arrayLen( wheres ) ).toBe( 1, "1 where clause should exist" ); + var where = wheres[ 1 ]; + expect( where.column ).toBe( "::some column::" ); + expect( where.operator ).toBe( "in" ); + expect( where.value ).toBe( [ "::value one::", "::value two::" ] ); + expect( where.combinator ).toBe( "and" ); + } ); + + it( "has a whereNotIn shortcut", function() { + query.whereNotIn( "::some column::", [ "::value one::", "::value two::" ] ); var wheres = query.getWheres(); - expect(wheres).toBeArray(); - expect(arrayLen(wheres)).toBe(1, '1 where clause should exist'); - var where = wheres[1]; - expect(where.column).toBe('::some column::'); - expect(where.operator).toBe('not in'); - expect(where.value).toBe(['::value one::', '::value two::']); - expect(where.combinator).toBe('and'); - }); - - it('has a orWhere shortcut', function() { - query.orWhere('::some column::', '<>', '::some value::'); + expect( wheres ).toBeArray(); + expect( arrayLen( wheres ) ).toBe( 1, "1 where clause should exist" ); + var where = wheres[ 1 ]; + expect( where.column ).toBe( "::some column::" ); + expect( where.operator ).toBe( "not in" ); + expect( where.value ).toBe( [ "::value one::", "::value two::" ] ); + expect( where.combinator ).toBe( "and" ); + } ); + + it( "has a orWhere shortcut", function() { + query.orWhere( "::some column::", "<>", "::some value::" ); var wheres = query.getWheres(); - expect(wheres).toBeArray(); - expect(arrayLen(wheres)).toBe(1, '1 where clause should exist'); - var where = wheres[1]; - expect(where.column).toBe('::some column::'); - expect(where.operator).toBe('<>'); - expect(where.value).toBe('::some value::'); - expect(where.combinator).toBe('or'); - }); - }); - - describe('bindings', function() { - it('adds the bindings for where statements received', function() { - query.where('::some column::', '=', '::some value::'); + expect( wheres ).toBeArray(); + expect( arrayLen( wheres ) ).toBe( 1, "1 where clause should exist" ); + var where = wheres[ 1 ]; + expect( where.column ).toBe( "::some column::" ); + expect( where.operator ).toBe( "<>" ); + expect( where.value ).toBe( "::some value::" ); + expect( where.combinator ).toBe( "or" ); + } ); + } ); + + describe( "bindings", function() { + it( "adds the bindings for where statements received", function() { + query.where( "::some column::", "=", "::some value::" ); var bindings = query.getRawBindings().where; - expect(bindings).toBeArray(); - expect(arrayLen(bindings)).toBe(1, '1 binding should exist'); - var binding = bindings[1]; - expect(binding.value).toBe('::some value::'); - expect(binding.cfsqltype).toBe('cf_sql_varchar'); - }); - }); - - describe('dynamic where statements', function() { - it('translates whereColumn in to where("column"', function() { - query.whereSomeColumn('::some value::'); + expect( bindings ).toBeArray(); + expect( arrayLen( bindings ) ).toBe( 1, "1 binding should exist" ); + var binding = bindings[ 1 ]; + expect( binding.value ).toBe( "::some value::" ); + expect( binding.cfsqltype ).toBe( "cf_sql_varchar" ); + } ); + } ); + + describe( "dynamic where statements", function() { + it( "translates whereColumn in to where(""column""", function() { + query.whereSomeColumn( "::some value::" ); - expect(query.getWheres()).toBe([{ - column = 'somecolumn', - operator = '=', - value = '::some value::', - combinator = 'and' - }]); - }); - - it('also translates orWhereColumn in to orWhere("column"', function() { - query.orWhereSomeColumn('::some value::'); + expect( query.getWheres() ).toBe( [ { + column = "somecolumn", + operator = "=", + value = "::some value::", + combinator = "and" + } ] ); + } ); + + it( "also translates orWhereColumn in to orWhere(""column""", function() { + query.orWhereSomeColumn( "::some value::" ); - expect(query.getWheres()).toBe([{ - column = 'somecolumn', - operator = '=', - value = '::some value::', - combinator = 'or' - }]); - }); - - it('returns the query instance to continue chaining', function() { - var q = query.whereSomeColumn('::some value::'); - expect(q).toBeInstanceOf('Quick.models.Query.Builder'); - }); - }); - - describe('operators', function() { - it('throws an exception on illegal operators', function() { - expect(function() { - query.where('::some column::', '::invalid operator::', '::some value::'); - }).toThrow( - type = 'InvalidArgumentException', - regex = 'Illegal operator' + expect( query.getWheres() ).toBe( [ { + column = "somecolumn", + operator = "=", + value = "::some value::", + combinator = "or" + } ] ); + } ); + + it( "returns the query instance to continue chaining", function() { + var q = query.whereSomeColumn( "::some value::" ); + expect( q ).toBeInstanceOf( "Quick.models.Query.Builder" ); + } ); + } ); + + describe( "operators", function() { + it( "throws an exception on illegal operators", function() { + expect( function() { + query.where( "::some column::", "::invalid operator::", "::some value::" ); + } ).toThrow( + type = "InvalidArgumentException", + regex = "Illegal operator" ); - }); - }); - }); - }); + } ); + } ); + } ); + } ); } } \ No newline at end of file diff --git a/tests/specs/Query/Builder/JoinClauseSpec.cfc b/tests/specs/Query/Builder/JoinClauseSpec.cfc index a19f76d6..f7fe23c9 100644 --- a/tests/specs/Query/Builder/JoinClauseSpec.cfc +++ b/tests/specs/Query/Builder/JoinClauseSpec.cfc @@ -1,149 +1,149 @@ -component extends='testbox.system.BaseSpec' { +component extends="testbox.system.BaseSpec" { function run() { - describe('initialization', function() { - it('requires a type and a table', function() { - expect(function() { new Quick.models.Query.JoinClause(); }).toThrow(); - expect(function() { new Quick.models.Query.JoinClause('inner'); }).toThrow(); - expect(function() { new Quick.models.Query.JoinClause('inner', 'sometable'); }).notToThrow(); - }); - - it('validates the type is a valid sql join type', function() { - expect(function() { new Quick.models.Query.JoinClause('gibberish', 'sometable'); }).toThrow(); - expect(function() { new Quick.models.Query.JoinClause('left typo', 'sometable'); }).toThrow(); - expect(function() { new Quick.models.Query.JoinClause('left', 'sometable'); }).notToThrow(); - expect(function() { new Quick.models.Query.JoinClause('left outer', 'sometable'); }).notToThrow(); - }); - }); - - describe('adding join conditions', function() { - beforeEach(function() { - variables.join = new Quick.models.Query.JoinClause('inner', 'second'); - getMockBox().prepareMock(join); - join.$property(propertyName = 'utils', mock = new Quick.models.Query.QueryUtils()); - }); - - afterEach(function() { - structDelete(variables, 'join'); - }); - - describe('on()', function() { - it('can add a single join condition', function() { - join.on('first.id', '=', 'second.first_id', 'and', false); + describe( "initialization", function() { + it( "requires a type and a table", function() { + expect( function() { new Quick.models.Query.JoinClause(); } ).toThrow(); + expect( function() { new Quick.models.Query.JoinClause( "inner" ); } ).toThrow(); + expect( function() { new Quick.models.Query.JoinClause( "inner", "sometable" ); } ).notToThrow(); + } ); + + it( "validates the type is a valid sql join type", function() { + expect( function() { new Quick.models.Query.JoinClause( "gibberish", "sometable" ); } ).toThrow(); + expect( function() { new Quick.models.Query.JoinClause( "left typo", "sometable" ); } ).toThrow(); + expect( function() { new Quick.models.Query.JoinClause( "left", "sometable" ); } ).notToThrow(); + expect( function() { new Quick.models.Query.JoinClause( "left outer", "sometable" ); } ).notToThrow(); + } ); + } ); + + describe( "adding join conditions", function() { + beforeEach( function() { + variables.join = new Quick.models.Query.JoinClause( "inner", "second" ); + getMockBox().prepareMock( join ); + join.$property( propertyName = "utils", mock = new Quick.models.Query.QueryUtils() ); + } ); + + afterEach( function() { + structDelete( variables, "join" ); + } ); + + describe( "on()", function() { + it( "can add a single join condition", function() { + join.on( "first.id", "=", "second.first_id", "and", false ); var clauses = join.getClauses(); - expect(arrayLen(clauses)).toBe(1, 'Only one clause should exist in the join statement'); + expect( arrayLen( clauses ) ).toBe( 1, "Only one clause should exist in the join statement" ); - var clause = clauses[1]; - expect(clause.first).toBe('first.id', 'First column should be [first.id]'); - expect(clause.operator).toBe('=', 'Operator should be [=]'); - expect(clause.second).toBe('second.first_id', 'First column should be [second.first_id]'); - expect(clause.combinator).toBe('and'); - expect(clause.where).toBe(false); - }); + var clause = clauses[ 1 ]; + expect( clause.first ).toBe( "first.id", "First column should be [first.id]" ); + expect( clause.operator ).toBe( "=", "Operator should be [=]" ); + expect( clause.second ).toBe( "second.first_id", "First column should be [second.first_id]" ); + expect( clause.combinator ).toBe( "and" ); + expect( clause.where ).toBe( false ); + } ); - it('defaults to "and" for the combinator and "false" for the where flag', function() { - join.on('first.id', '=', 'second.first_id'); + it( "defaults to ""and"" for the combinator and ""false"" for the where flag", function() { + join.on( "first.id", "=", "second.first_id" ); var clauses = join.getClauses(); - expect(arrayLen(clauses)).toBe(1, 'Only one clause should exist in the join statement'); + expect( arrayLen( clauses ) ).toBe( 1, "Only one clause should exist in the join statement" ); - var clause = clauses[1]; - expect(clause.first).toBe('first.id', 'First column should be [first.id]'); - expect(clause.operator).toBe('=', 'Operator should be [=]'); - expect(clause.second).toBe('second.first_id', 'First column should be [second.first_id]'); - expect(clause.combinator).toBe('and'); - expect(clause.where).toBe(false); - }); + var clause = clauses[ 1 ]; + expect( clause.first ).toBe( "first.id", "First column should be [first.id]" ); + expect( clause.operator ).toBe( "=", "Operator should be [=]" ); + expect( clause.second ).toBe( "second.first_id", "First column should be [second.first_id]" ); + expect( clause.combinator ).toBe( "and" ); + expect( clause.where ).toBe( false ); + } ); - it('can add multiple join clauses', function() { - join.on('first.id', '=', 'second.first_id'); - join.on('first.locale', '=', 'second.locale'); + it( "can add multiple join clauses", function() { + join.on( "first.id", "=", "second.first_id" ); + join.on( "first.locale", "=", "second.locale" ); var clauses = join.getClauses(); - expect(arrayLen(clauses)).toBe(2, 'Two clauses should exist in the join statement'); - - var clauseOne = clauses[1]; - expect(clauseOne.first).toBe('first.id', 'First column should be [first.id]'); - expect(clauseOne.operator).toBe('=', 'Operator should be [=]'); - expect(clauseOne.second).toBe('second.first_id', 'First column should be [second.first_id]'); - expect(clauseOne.combinator).toBe('and'); - expect(clauseOne.where).toBe(false); - - var clauseTwo = clauses[2]; - expect(clauseTwo.first).toBe('first.locale', 'First column should be [first.locale]'); - expect(clauseTwo.operator).toBe('=', 'Operator should be [=]'); - expect(clauseTwo.second).toBe('second.locale', 'First column should be [second.locale]'); - expect(clauseTwo.combinator).toBe('and'); - expect(clauseTwo.where).toBe(false); - }); - - it('validates that the operator is a valid sql operator', function() { - expect(function() { - join.on('first.id', '==', 'second.first_id'); - }).toThrow(); - - expect(function() { - join.on('first.id', '<>', 'second.first_id'); - }).notToThrow(); - }); - }); - - describe('orOn()', function() { - it('can add a single join condition', function() { - join.orOn('first.another_value', '>=', 'second.another_value'); + expect( arrayLen( clauses ) ).toBe( 2, "Two clauses should exist in the join statement" ); + + var clauseOne = clauses[ 1 ]; + expect( clauseOne.first ).toBe( "first.id", "First column should be [first.id]" ); + expect( clauseOne.operator ).toBe( "=", "Operator should be [=]" ); + expect( clauseOne.second ).toBe( "second.first_id", "First column should be [second.first_id]" ); + expect( clauseOne.combinator ).toBe( "and" ); + expect( clauseOne.where ).toBe( false ); + + var clauseTwo = clauses[ 2 ]; + expect( clauseTwo.first ).toBe( "first.locale", "First column should be [first.locale]" ); + expect( clauseTwo.operator ).toBe( "=", "Operator should be [=]" ); + expect( clauseTwo.second ).toBe( "second.locale", "First column should be [second.locale]" ); + expect( clauseTwo.combinator ).toBe( "and" ); + expect( clauseTwo.where ).toBe( false ); + } ); + + it( "validates that the operator is a valid sql operator", function() { + expect( function() { + join.on( "first.id", "==", "second.first_id" ); + } ).toThrow(); + + expect( function() { + join.on( "first.id", "<>", "second.first_id" ); + } ).notToThrow(); + } ); + } ); + + describe( "orOn()", function() { + it( "can add a single join condition", function() { + join.orOn( "first.another_value", ">=", "second.another_value" ); var clauses = join.getClauses(); - expect(arrayLen(clauses)).toBe(1, 'Only one clause should exist in the join statement'); + expect( arrayLen( clauses ) ).toBe( 1, "Only one clause should exist in the join statement" ); - var clause = clauses[1]; - expect(clause.first).toBe('first.another_value', 'First column should be [first.another_value]'); - expect(clause.operator).toBe('>=', 'Operator should be [>=]'); - expect(clause.second).toBe('second.another_value', 'First column should be [second.another_value]'); - expect(clause.combinator).toBe('or'); - expect(clause.where).toBe(false); - }); - }); + var clause = clauses[ 1 ]; + expect( clause.first ).toBe( "first.another_value", "First column should be [first.another_value]" ); + expect( clause.operator ).toBe( ">=", "Operator should be [>=]" ); + expect( clause.second ).toBe( "second.another_value", "First column should be [second.another_value]" ); + expect( clause.combinator ).toBe( "or" ); + expect( clause.where ).toBe( false ); + } ); + } ); - describe('where()', function() { - it('adds a where statement to a join clause', function() { - join.where('second.locale', '=', 'en-US'); + describe( "where()", function() { + it( "adds a where statement to a join clause", function() { + join.where( "second.locale", "=", "en-US" ); var clauses = join.getClauses(); - expect(arrayLen(clauses)).toBe(1, 'Only one clause should exist in the join statement'); + expect( arrayLen( clauses ) ).toBe( 1, "Only one clause should exist in the join statement" ); - var clause = clauses[1]; - expect(clause.first).toBe('second.locale', 'First column should be [second.locale]'); - expect(clause.operator).toBe('=', 'Operator should be [>=]'); - expect(clause.second).toBe('?', 'First column should be a binding placeholder [?]'); - expect(clause.combinator).toBe('and'); - expect(clause.where).toBe(true, 'The where flag should be true'); - }); + var clause = clauses[ 1 ]; + expect( clause.first ).toBe( "second.locale", "First column should be [second.locale]" ); + expect( clause.operator ).toBe( "=", "Operator should be [>=]" ); + expect( clause.second ).toBe( "?", "First column should be a binding placeholder [?]" ); + expect( clause.combinator ).toBe( "and" ); + expect( clause.where ).toBe( true, "The where flag should be true" ); + } ); - it('can use the shortcut where statement when the operator is equals (=)', function() { - join.where('second.locale', 'en-US'); + it( "can use the shortcut where statement when the operator is equals (=)", function() { + join.where( "second.locale", "en-US" ); var clauses = join.getClauses(); - expect(arrayLen(clauses)).toBe(1, 'Only one clause should exist in the join statement'); + expect( arrayLen( clauses ) ).toBe( 1, "Only one clause should exist in the join statement" ); - var clause = clauses[1]; - expect(clause.first).toBe('second.locale', 'First column should be [second.locale]'); - expect(clause.operator).toBe('=', 'Operator should be [>=]'); - expect(clause.second).toBe('?', 'First column should be a binding placeholder [?]'); - expect(clause.combinator).toBe('and'); - expect(clause.where).toBe(true, 'The where flag should be true'); - }); + var clause = clauses[ 1 ]; + expect( clause.first ).toBe( "second.locale", "First column should be [second.locale]" ); + expect( clause.operator ).toBe( "=", "Operator should be [>=]" ); + expect( clause.second ).toBe( "?", "First column should be a binding placeholder [?]" ); + expect( clause.combinator ).toBe( "and" ); + expect( clause.where ).toBe( true, "The where flag should be true" ); + } ); - it('adds the where value to the bindings', function() { - join.where('second.locale', '=', 'en-US'); + it( "adds the where value to the bindings", function() { + join.where( "second.locale", "=", "en-US" ); var bindings = join.getBindings(); - expect(arrayLen(bindings)).toBe(1, 'Only one clause should exist in the join statement'); - - var binding = bindings[1]; - expect(binding.value).toBe('en-US'); - expect(binding.cfsqltype).toBe('cf_sql_varchar'); - }); - }); - }); + expect( arrayLen( bindings ) ).toBe( 1, "Only one clause should exist in the join statement" ); + + var binding = bindings[ 1 ]; + expect( binding.value ).toBe( "en-US" ); + expect( binding.cfsqltype ).toBe( "cf_sql_varchar" ); + } ); + } ); + } ); } } \ No newline at end of file diff --git a/tests/specs/Query/Grammar/GrammarCompileSQLSpec.cfc b/tests/specs/Query/Grammar/GrammarCompileSQLSpec.cfc index 0e2f2a9d..4c12c463 100644 --- a/tests/specs/Query/Grammar/GrammarCompileSQLSpec.cfc +++ b/tests/specs/Query/Grammar/GrammarCompileSQLSpec.cfc @@ -1,198 +1,196 @@ -component extends='testbox.system.BaseSpec' { +component extends="testbox.system.BaseSpec" { function run() { - describe('compileSelect', function() { - beforeEach(function() { + describe( "compileSelect", function() { + beforeEach( function() { variables.grammar = new Quick.models.Query.Grammars.OracleGrammar(); - variables.mockQuery = getMockBox().createMock('Quick.models.Query.Builder'); - mockQuery.$('getDistinct', false); - mockQuery.$('getColumns', ['*']); - mockQuery.$('getFrom', 'sometable'); - mockQuery.$('getJoins', []); - mockQuery.$('getWheres', []); - }); - - describe('compiling distinct', function() { - it('correctly sets the distinct option', function() { - mockQuery.$('getDistinct', true); - var sql = grammar.compileSelect(mockQuery); - expect(sql).toBe('SELECT DISTINCT * FROM sometable'); - }); - }); - - describe('compiling columns', function() { - it('transforms a query builder object to a SQL statement', function() { - mockQuery.$('getColumns', ['*']); - var sql = grammar.compileSelect(mockQuery); - expect(sql).toBe('SELECT * FROM sometable'); - }); - - it('correctly compiles a query with a single specific column', function() { - mockQuery.$('getColumns', ['column_one']); - var sql = grammar.compileSelect(mockQuery); - expect(sql).toBe('SELECT column_one FROM sometable'); - }); - - it('correctly compiles a query with multiple columns', function() { - mockQuery.$('getColumns', ['somecolumn', 'anothercolumn']); - var sql = grammar.compileSelect(mockQuery); - expect(sql).toBe('SELECT somecolumn,anothercolumn FROM sometable'); - }); - }); - - describe('compiling from', function() { - it('correctly sets the from table', function() { - mockQuery.$('getFrom', 'sometable'); - var sql = grammar.compileSelect(mockQuery); - expect(sql).toBe('SELECT * FROM sometable'); - }); - }); - - describe('compiling joins', function() { - it('adds a single join', function() { - var mockJoin = getMockBox().createMock('Quick.models.Query.JoinClause'); - mockJoin.$('getType', 'inner'); - mockJoin.$('getTable', 'othertable'); - mockJoin.$('getClauses', [{ - first = 'sometable.id', - operator = '=', - second = 'othertable.sometable_id', - combinator = 'and' - }]); - mockQuery.$('getJoins', [ mockJoin ]); - - var sql = grammar.compileSelect(mockQuery); - expect(sql) - .toBe('SELECT * FROM sometable INNER JOIN othertable ON sometable.id = othertable.sometable_id'); - }); - - it('adds multiple joins', function() { - var mockJoinOne = getMockBox().createMock('Quick.models.Query.JoinClause'); - mockJoinOne.$('getType', 'inner'); - mockJoinOne.$('getTable', 'othertable'); - mockJoinOne.$('getClauses', [{ - first = 'sometable.id', - operator = '=', - second = 'othertable.sometable_id', - combinator = 'and' - }]); - var mockJoinTwo = getMockBox().createMock('Quick.models.Query.JoinClause'); - mockJoinTwo.$('getType', 'left'); - mockJoinTwo.$('getTable', 'anothertable'); - mockJoinTwo.$('getClauses', [{ - first = 'othertable.id', - operator = '<=', - second = 'anothertable.othertable_id', - combinator = 'and' - }]); - mockQuery.$('getJoins', [ mockJoinOne, mockJoinTwo ]); - - var sql = grammar.compileSelect(mockQuery); - expect(sql) - .toBe('SELECT * FROM sometable INNER JOIN othertable ON sometable.id = othertable.sometable_id LEFT JOIN anothertable ON othertable.id <= anothertable.othertable_id'); - }); - - it('compiles where statements in joins', function() { - var mockJoin = getMockBox().createMock('Quick.models.Query.JoinClause'); - mockJoin.$('getType', 'inner'); - mockJoin.$('getTable', 'othertable'); - mockJoin.$('getClauses', [{ - first = 'othertable.locale', - operator = '=', - second = '?', - combinator = 'and' - }]); - mockQuery.$('getJoins', [ mockJoin ]); - - var sql = grammar.compileSelect(mockQuery); - - expect(sql) - .toBe('SELECT * FROM sometable INNER JOIN othertable ON othertable.locale = ?'); - }); - - it('adds all the clauses in a join', function() { - var mockJoin = getMockBox().createMock('Quick.models.Query.JoinClause'); - mockJoin.$('getType', 'inner'); - mockJoin.$('getTable', 'othertable'); - mockJoin.$('getClauses', [ + variables.mockQuery = getMockBox().createMock( "Quick.models.Query.Builder" ); + mockQuery.$( "getDistinct", false ); + mockQuery.$( "getColumns", [ "*" ] ); + mockQuery.$( "getFrom", "sometable" ); + mockQuery.$( "getJoins", [] ); + mockQuery.$( "getWheres", [] ); + } ); + + describe( "compiling distinct", function() { + it( "correctly sets the distinct option", function() { + mockQuery.$( "getDistinct", true ); + var sql = grammar.compileSelect( mockQuery ); + expect( sql ).toBe( "SELECT DISTINCT * FROM sometable" ); + } ); + } ); + + describe( "compiling columns", function() { + it( "transforms a query builder object to a SQL statement", function() { + mockQuery.$( "getColumns", [ "*" ] ); + var sql = grammar.compileSelect( mockQuery ); + expect( sql ).toBe( "SELECT * FROM sometable" ); + } ); + + it( "correctly compiles a query with a single specific column", function() { + mockQuery.$( "getColumns", [ "column_one" ] ); + var sql = grammar.compileSelect( mockQuery ); + expect( sql ).toBe( "SELECT column_one FROM sometable" ); + } ); + + it( "correctly compiles a query with multiple columns", function() { + mockQuery.$( "getColumns", [ "somecolumn", "anothercolumn" ] ); + var sql = grammar.compileSelect( mockQuery ); + expect( sql ).toBe( "SELECT somecolumn,anothercolumn FROM sometable" ); + } ); + } ); + + describe( "compiling from", function() { + it( "correctly sets the from table", function() { + mockQuery.$( "getFrom", "sometable" ); + var sql = grammar.compileSelect( mockQuery ); + expect( sql ).toBe( "SELECT * FROM sometable" ); + } ); + } ); + + describe( "compiling joins", function() { + it( "adds a single join", function() { + var mockJoin = getMockBox().createMock( "Quick.models.Query.JoinClause" ); + mockJoin.$( "getType", "inner" ); + mockJoin.$( "getTable", "othertable" ); + mockJoin.$( "getClauses", [ { + first = "sometable.id", + operator = "=", + second = "othertable.sometable_id", + combinator = "and" + } ] ); + mockQuery.$( "getJoins", [ mockJoin ] ); + + var sql = grammar.compileSelect( mockQuery ); + expect( sql ) + .toBe( "SELECT * FROM sometable INNER JOIN othertable ON sometable.id = othertable.sometable_id" ); + } ); + + it( "adds multiple joins", function() { + var mockJoinOne = getMockBox().createMock( "Quick.models.Query.JoinClause" ); + mockJoinOne.$( "getType", "inner" ); + mockJoinOne.$( "getTable", "othertable" ); + mockJoinOne.$( "getClauses", [ { + first = "sometable.id", + operator = "=", + second = "othertable.sometable_id", + combinator = "and" + } ] ); + var mockJoinTwo = getMockBox().createMock( "Quick.models.Query.JoinClause" ); + mockJoinTwo.$( "getType", "left" ); + mockJoinTwo.$( "getTable", "anothertable" ); + mockJoinTwo.$( "getClauses", [ { + first = "othertable.id", + operator = "<=", + second = "anothertable.othertable_id", + combinator = "and" + } ] ); + mockQuery.$( "getJoins", [ mockJoinOne, mockJoinTwo ] ); + + var sql = grammar.compileSelect( mockQuery ); + expect( sql ) + .toBe( "SELECT * FROM sometable INNER JOIN othertable ON sometable.id = othertable.sometable_id LEFT JOIN anothertable ON othertable.id <= anothertable.othertable_id" ); + } ); + + it( "compiles where statements in joins", function() { + var mockJoin = getMockBox().createMock( "Quick.models.Query.JoinClause" ); + mockJoin.$( "getType", "inner" ); + mockJoin.$( "getTable", "othertable" ); + mockJoin.$( "getClauses", [ { + first = "othertable.locale", + operator = "=", + second = "?", + combinator = "and" + } ] ); + mockQuery.$( "getJoins", [ mockJoin ] ); + + var sql = grammar.compileSelect( mockQuery ); + + expect( sql ) + .toBe( "SELECT * FROM sometable INNER JOIN othertable ON othertable.locale = ?" ); + } ); + + it( "adds all the clauses in a join", function() { + var mockJoin = getMockBox().createMock( "Quick.models.Query.JoinClause" ); + mockJoin.$( "getType", "inner" ); + mockJoin.$( "getTable", "othertable" ); + mockJoin.$( "getClauses", [ { - first = 'sometable.id', - operator = '=', - second = 'othertable.sometable_id', - combinator = 'and' + first = "sometable.id", + operator = "=", + second = "othertable.sometable_id", + combinator = "and" }, { - first = 'sometable.locale', - operator = '=', - second = 'othertable.locale', - combinator = 'and' + first = "sometable.locale", + operator = "=", + second = "othertable.locale", + combinator = "and" } - ]); - mockQuery.$('getJoins', [ mockJoin ]); - - var sql = grammar.compileSelect(mockQuery); - expect(sql) - .toBe('SELECT * FROM sometable INNER JOIN othertable ON sometable.id = othertable.sometable_id AND sometable.locale = othertable.locale'); - }); - }); - - describe('compiling wheres', function() { - it('adds where clauses to the SQL statement', function() { - mockQuery.$('getWheres', [ + ] ); + mockQuery.$( "getJoins", [ mockJoin ] ); + + var sql = grammar.compileSelect( mockQuery ); + expect( sql ) + .toBe( "SELECT * FROM sometable INNER JOIN othertable ON sometable.id = othertable.sometable_id AND sometable.locale = othertable.locale" ); + } ); + } ); + + describe( "compiling wheres", function() { + it( "adds where clauses to the SQL statement", function() { + mockQuery.$( "getWheres", [ { - column = 'some_column', - operator = '=', - value = '::does not matter::', - combinator = 'and' + column = "some_column", + operator = "=", + value = "::does not matter::", + combinator = "and" } - ]); - var sql = grammar.compileSelect(mockQuery); - expect(sql).toBe('SELECT * FROM sometable WHERE some_column = ?'); - }); + ] ); + var sql = grammar.compileSelect( mockQuery ); + expect( sql ).toBe( "SELECT * FROM sometable WHERE some_column = ?" ); + } ); - it('compiles multiple where claueses', function() { - mockQuery.$('getWheres', [ + it( "compiles multiple where claueses", function() { + mockQuery.$( "getWheres", [ { - column = 'some_column', - operator = '=', - value = '::does not matter::', - combinator = 'and' + column = "some_column", + operator = "=", + value = "::does not matter::", + combinator = "and" }, { - column = 'another_column', - operator = '=', - value = '::still does not matter::', - combinator = 'and' + column = "another_column", + operator = "=", + value = "::still does not matter::", + combinator = "and" } - ]); - var sql = grammar.compileSelect(mockQuery); - expect(sql).toBe('SELECT * FROM sometable WHERE some_column = ? AND another_column = ?'); - }); + ] ); + var sql = grammar.compileSelect( mockQuery ); + expect( sql ).toBe( "SELECT * FROM sometable WHERE some_column = ? AND another_column = ?" ); + } ); - it('compiles different boolean combinators', function() { - mockQuery.$('getWheres', [ + it( "compiles different boolean combinators", function() { + mockQuery.$( "getWheres", [ { - column = 'some_column', - operator = '=', - value = '::does not matter::', - combinator = 'AND' + column = "some_column", + operator = "=", + value = "::does not matter::", + combinator = "AND" }, { - column = 'another_column', - operator = '=', - value = '::still does not matter::', - combinator = 'OR' + column = "another_column", + operator = "=", + value = "::still does not matter::", + combinator = "OR" } - ]); - var sql = grammar.compileSelect(mockQuery); - expect(sql).toBe('SELECT * FROM sometable WHERE some_column = ? OR another_column = ?'); - }); - }); - - describe('data sanitization', function() { - xit('escapes double quotes in value statements', function() { - - }); - }); - }); + ] ); + var sql = grammar.compileSelect( mockQuery ); + expect( sql ).toBe( "SELECT * FROM sometable WHERE some_column = ? OR another_column = ?" ); + } ); + } ); + + describe( "data sanitization", function() { + xit( "escapes double quotes in value statements", function() {} ); + } ); + } ); } } \ No newline at end of file diff --git a/tests/specs/Query/QueryUtilsSpec.cfc b/tests/specs/Query/QueryUtilsSpec.cfc index 05e6527f..dec8f74c 100644 --- a/tests/specs/Query/QueryUtilsSpec.cfc +++ b/tests/specs/Query/QueryUtilsSpec.cfc @@ -1,74 +1,74 @@ -component displayname='QueryUtilsSpec' extends='testbox.system.BaseSpec' { +component displayname="QueryUtilsSpec" extends="testbox.system.BaseSpec" { function beforeAll() { variables.utils = new Quick.models.Query.QueryUtils(); } function run() { - describe('inferSqlType()', function() { - it('strings', function() { - expect(utils.inferSqlType('a string')).toBe('CF_SQL_VARCHAR'); - }); + describe( "inferSqlType()", function() { + it( "strings", function() { + expect( utils.inferSqlType( "a string" ) ).toBe( "CF_SQL_VARCHAR" ); + } ); - it('numbers', function() { - expect(utils.inferSqlType(100)).toBe('CF_SQL_NUMERIC'); - }); + it( "numbers", function() { + expect( utils.inferSqlType( 100 ) ).toBe( "CF_SQL_NUMERIC" ); + } ); - it('dates', function() { - expect(utils.inferSqlType(Now())).toBe('CF_SQL_TIMESTAMP'); - }); + it( "dates", function() { + expect( utils.inferSqlType( now() ) ).toBe( "CF_SQL_TIMESTAMP" ); + } ); - describe('it infers the sql type from the members of a list', function() { - it('if all the members of the list are the same', function() { - expect(utils.inferSqlType('1,2')).toBe('CF_SQL_NUMERIC'); - }); + describe( "it infers the sql type from the members of a list", function() { + it( "if all the members of the list are the same", function() { + expect( utils.inferSqlType( "1,2" ) ).toBe( "CF_SQL_NUMERIC" ); + } ); - it('but defaults to CF_SQL_VARCHAR if they are different', function() { - expect(utils.inferSqlType('1,2,3,test')).toBe('CF_SQL_VARCHAR'); - }); - }); + it( "but defaults to CF_SQL_VARCHAR if they are different", function() { + expect( utils.inferSqlType( "1,2,3,test" ) ).toBe( "CF_SQL_VARCHAR" ); + } ); + } ); - describe('it infers the sql type from the members of an array', function() { - it('if all the members of the array are the same', function() { - expect(utils.inferSqlType([1, 2])).toBe('CF_SQL_NUMERIC'); - }); + describe( "it infers the sql type from the members of an array", function() { + it( "if all the members of the array are the same", function() { + expect( utils.inferSqlType( [ 1, 2 ] ) ).toBe( "CF_SQL_NUMERIC" ); + } ); - it('but defaults to CF_SQL_VARCHAR if they are different', function() { - expect(utils.inferSqlType([1, 2, 3, DateFormat('05/01/2016', 'MM/DD/YYYY')])).toBe('CF_SQL_VARCHAR'); - }); - }); - }); + it( "but defaults to CF_SQL_VARCHAR if they are different", function() { + expect( utils.inferSqlType( [ 1, 2, 3, dateFormat( "05/01/2016", "MM/DD/YYYY" ) ] ) ).toBe( "CF_SQL_VARCHAR" ); + } ); + } ); + } ); - describe('extractBinding()', function() { - it('includes sensible defaults', function() { - var binding = utils.extractBinding('05/10/2016'); + describe( "extractBinding()", function() { + it( "includes sensible defaults", function() { + var binding = utils.extractBinding( "05/10/2016" ); - expect(binding).toBeStruct(); - expect(binding.value).toBe('05/10/2016'); - expect(binding.cfsqltype).toBe('CF_SQL_TIMESTAMP'); - expect(binding.list).toBe(false); - expect(binding.null).toBe(false); - }); + expect( binding ).toBeStruct(); + expect( binding.value ).toBe( "05/10/2016" ); + expect( binding.cfsqltype ).toBe( "CF_SQL_TIMESTAMP" ); + expect( binding.list ).toBe( false ); + expect( binding.null ).toBe( false ); + } ); - it('detects arrays and converts them in to lists', function() { - var binding = utils.extractBinding(['one', 'two']); + it( "detects arrays and converts them in to lists", function() { + var binding = utils.extractBinding( [ "one", "two" ] ); - expect(binding).toBeStruct(); - expect(binding.value).toBe('one,two'); - expect(binding.cfsqltype).toBe('CF_SQL_VARCHAR'); - expect(binding.list).toBe(true); - expect(binding.null).toBe(false); - }); + expect( binding ).toBeStruct(); + expect( binding.value ).toBe( "one,two" ); + expect( binding.cfsqltype ).toBe( "CF_SQL_VARCHAR" ); + expect( binding.list ).toBe( true ); + expect( binding.null ).toBe( false ); + } ); - it('detects lists and sets the list property to true', function() { - var binding = utils.extractBinding('yes,no'); + it( "detects lists and sets the list property to true", function() { + var binding = utils.extractBinding( "yes,no" ); - expect(binding).toBeStruct(); - expect(binding.value).toBe('yes,no'); - expect(binding.cfsqltype).toBe('CF_SQL_VARCHAR'); - expect(binding.list).toBe(true); - expect(binding.null).toBe(false); - }); - }); + expect( binding ).toBeStruct(); + expect( binding.value ).toBe( "yes,no" ); + expect( binding.cfsqltype ).toBe( "CF_SQL_VARCHAR" ); + expect( binding.list ).toBe( true ); + expect( binding.null ).toBe( false ); + } ); + } ); } } \ No newline at end of file