-
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
*
feature
: Added constraintProfiles
to allow you to define which…
… fields to validate according to defined profiles: #37
- Loading branch information
Showing
13 changed files
with
321 additions
and
141 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,21 @@ | ||
component accessors="true"{ | ||
component accessors="true" { | ||
|
||
property name="username" default=""; | ||
property name="password" default=""; | ||
property name="email" default=""; | ||
|
||
this.constraintProfiles = { | ||
new : "username,password,email", | ||
update : "username,email" | ||
}; | ||
this.constraints = { | ||
username = {required=true, size="2..20"}, | ||
password = {required=true, size="2..20"} | ||
username : { required : true, size : "2..20" }, | ||
password : { required : true, size : "2..20" }, | ||
email : { required : true, type : "email" } | ||
}; | ||
|
||
function init(){ | ||
return this; | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,8 @@ component extends="coldbox.system.testing.BaseTestCase" appMapping="/root" { | |
function run(){ | ||
describe( "Integrations Specs", function(){ | ||
beforeEach( function( currentSpec ){ | ||
structDelete( application, "cbController" ); | ||
structDelete( application, "wirebox" ); | ||
// Setup as a new ColdBox request, VERY IMPORTANT. ELSE EVERYTHING LOOKS LIKE THE SAME REQUEST. | ||
setup(); | ||
} ); | ||
|
@@ -71,6 +73,7 @@ component extends="coldbox.system.testing.BaseTestCase" appMapping="/root" { | |
params = { | ||
username : "luis", | ||
password : "luis", | ||
email : "[email protected]", | ||
bogus : now(), | ||
anotherBogus : now() | ||
}, | ||
|
@@ -83,7 +86,63 @@ component extends="coldbox.system.testing.BaseTestCase" appMapping="/root" { | |
} ); | ||
} ); | ||
} ); | ||
|
||
|
||
story( "I want to Validate with contraint profiles", function(){ | ||
given( "a single profile", function(){ | ||
then( "it must validate it with only those fields in that profile", function(){ | ||
var e = this.request( | ||
route = "/main/validateOrFailWithProfiles", | ||
params = { | ||
username : "luis", | ||
email : "[email protected]", | ||
bogus : now(), | ||
anotherBogus : now(), | ||
_profiles : "update" | ||
}, | ||
method = "post" | ||
); | ||
|
||
var object = e.getPrivateValue( "object" ); | ||
debug( object ); | ||
expect( object ).toBeComponent(); | ||
}); | ||
}); | ||
given( "a multiple profiles", function(){ | ||
then( "it must validate it with only distinct fields in those profiles", function(){ | ||
var e = this.request( | ||
route = "/main/validateOrFailWithProfiles", | ||
params = { | ||
username : "luis", | ||
email : "[email protected]", | ||
password : "luis", | ||
anotherBogus : now(), | ||
_profiles : "update,new,bogus" | ||
}, | ||
method = "post" | ||
); | ||
|
||
var object = e.getPrivateValue( "object" ); | ||
debug( object ); | ||
expect( object ).toBeComponent(); | ||
}); | ||
}); | ||
given( "a single profile and invalid data", function(){ | ||
then( "then throw the exception", function(){ | ||
|
||
expect( function(){ | ||
this.request( route = "/main/validateOrFailWithProfiles", params = { | ||
username : "luis" | ||
}, method = "post" ); | ||
} ).toThrow(); | ||
|
||
}); | ||
}); | ||
}); | ||
|
||
|
||
} ); | ||
|
||
} | ||
|
||
} |
Oops, something went wrong.