Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion tests/specs/integration/BaseEntity/AsQuerySpec.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,16 @@ component extends="tests.resources.ModuleIntegrationSpec" {
for ( var result in results ) {
result.createdDate = dateTimeFormat( result.createdDate, "yyyy-mm-dd hh:nn:ss" );
result.modifiedDate = dateTimeFormat( result.modifiedDate, "yyyy-mm-dd hh:nn:ss" );
var nullableKeys = [
"email",
"streetTwo",
"favoritePost_id"
];
for ( var key in nullableKeys ) {
if ( isNull( result[ key ] ) ) {
result[ key ] = "";
}
}
}

expect( results[ 1 ] ).toBeStruct();
Expand Down Expand Up @@ -74,7 +84,7 @@ component extends="tests.resources.ModuleIntegrationSpec" {
expect( results[ 1 ][ "latestPostId" ] ).toBe( 523526 );
expect( results[ 2 ] ).toBeStruct();
expect( results[ 2 ] ).toHaveKey( "latestPostId" );
expect( results[ 2 ][ "latestPostId" ] ).toBe( "" );
expect( isNull( results[ 2 ][ "latestPostId" ] ) ? "" : results[ 2 ][ "latestPostId" ] ).toBe( "" );
} );

it( "can do eager loading", function() {
Expand Down
2 changes: 0 additions & 2 deletions tests/specs/integration/BaseEntity/AttributeCastsSpec.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,10 @@ component extends="tests.resources.ModuleIntegrationSpec" {
it( "preserves null values when using BooleanCast", () => {
var pn = getInstance( "PhoneNumber" ).find( 3 );
expect( pn.isNullAttribute( "confirmed" ) ).toBeTrue( "[confirmed] should be considered null" );
expect( pn.getConfirmed() ).toBe( "" );

pn.update( { "active" : false } ).refresh();

expect( pn.isNullAttribute( "confirmed" ) ).toBeTrue( "[confirmed] should remain null after saving" );
expect( pn.getConfirmed() ).toBe( "" );
} );

it( "allows custom casts to handle null database values", () => {
Expand Down
8 changes: 7 additions & 1 deletion tests/specs/integration/BaseEntity/AttributeSpec.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,12 @@ component extends="tests.resources.ModuleIntegrationSpec" {
var memento = getInstance( "User" ).findOrFail( 1 ).getMemento();
memento.createdDate = dateTimeFormat( memento.createdDate, "yyyy-mm-dd hh:nn:ss" );
memento.modifiedDate = dateTimeFormat( memento.modifiedDate, "yyyy-mm-dd hh:nn:ss" );
if ( isNull( memento.email ) ) {
memento.email = "";
}
if ( isNull( memento.address.streetTwo ) ) {
memento.address.streetTwo = "";
}
expect( memento ).toBe( {
"id" : 1,
"username" : "elpete",
Expand All @@ -190,7 +196,7 @@ component extends="tests.resources.ModuleIntegrationSpec" {
"modifiedDate" : "2017-07-28 02:06:36",
"type" : "admin",
"email" : "",
"externalId" : "1234",
"externalID" : "1234",
"address" : {
"streetOne" : "123 Elm Street",
"streetTwo" : "",
Expand Down
6 changes: 6 additions & 0 deletions tests/specs/integration/BaseEntity/MementoSpec.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ component extends="tests.resources.ModuleIntegrationSpec" {
memento.publishedDate = dateTimeFormat( memento.publishedDate, "yyyy-mm-dd hh:nn:ss" );
memento.author.createdDate = dateTimeFormat( memento.author.createdDate, "yyyy-mm-dd hh:nn:ss" );
memento.author.modifiedDate = dateTimeFormat( memento.author.modifiedDate, "yyyy-mm-dd hh:nn:ss" );
if ( isNull( memento.author.email ) ) {
memento.author.email = "";
}
if ( isNull( memento.author.address.streetTwo ) ) {
memento.author.address.streetTwo = "";
}
expect( memento ).toBe( {
"post_pk" : "1245",
"body" : "My awesome post body",
Expand Down
6 changes: 3 additions & 3 deletions tests/specs/integration/BaseEntity/NullValuesSpec.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ component extends="tests.resources.ModuleIntegrationSpec" {

function run() {
describe( "Null Values Spec", function() {
it( "returns null values as a string by default", function() {
it( "returns database nulls as null attributes by default", function() {
var user = getInstance( "User" ).findOrFail( 3 );
expect( user.getCountryId() ).toBe( "" );
expect( user.getMemento().countryId ).toBe( "" );
expect( user.isNullAttribute( "countryId" ) ).toBeTrue();
expect( user.isNullValue( "countryId", user.getMemento().countryId ) ).toBeTrue();
} );

it( "saves a column containing an empty string as null in the database by default", function() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ component extends="tests.resources.ModuleIntegrationSpec" {
post.author()
.dissociate()
.save();
expect( post.retrieveAttribute( "user_id" ) ).toBe( "" );
expect( post.isNullAttribute( "user_id" ) ).toBeTrue();
expect(
getInstance( "User" )
.find( userId )
Expand Down
2 changes: 1 addition & 1 deletion tests/specs/integration/BaseEntity/SaveSpec.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ component extends="tests.resources.ModuleIntegrationSpec" {
existingUser.save();
var userRowsPostSave = queryExecute( "SELECT * FROM users" );
expect( userRowsPostSave ).toHaveLength( 5 );
expect( userRowsPostSave.email ).toBe( "" );
expect( getInstance( "User" ).findOrFail( 1 ).isNullAttribute( "email" ) ).toBeTrue();
} );

it( "uses the sqltype attribute if present for each column", function() {
Expand Down
Loading