Skip to content

Instantly share code, notes, and snippets.

View neokoenig's full-sized avatar

Tom King neokoenig

View GitHub Profile
@neokoenig
neokoenig / routes.cfm
Created June 18, 2017 10:30
CFWheels 2.x routing
mapper()
.resources("users")
.root(to="wheels##wheels", method="get")
.end()
@neokoenig
neokoenig / routes.cfm
Created June 18, 2017 10:25
Old CFWheels 1.x style routing
addRoute(name="users", pattern="/users/[action]/[key]", controller="users");
addRoute(name="users", pattern="/users/[action]/", controller="users");
addRoute(name="users", pattern="/users/", controller="users", action="index");
<cfscript>
mapper()
.namespace("admin")
.resources("users")
.end()
.wildcard()
.root(to="wheels##wheels", method="get")
.end()
</cfscript>
component extends="Admin" {
function config() {
super.config();
verifies(except="index,new,create", params="key", paramsTypes="integer", handler="objectNotFound");
verifies(post=true, only="create,update,delete");
}
function index() {
users=model("user").findAll();
component extends="app.controllers.Controller"
{
function config() {
filters(through="checkAdminPermissions");
}
// This is highly simplified for illustration only
private function checkAdminPermissions(){
if(session.user.role != "admin"){
abort;
// asserts that a failed user update returns a 302 http response, an error exists in the flash and will be redirected to the error page
function testStatusFlashAndRedirect() {
local.params = {
controller = "users",
action = "update"
};
result = processRequest(params=local.params, method="post", rollback=true, returnAs="struct");
assert("result.status == 302");
assert("StructKeyExists(result.flash, 'error') == true");
assert("result.redirect == '/common/error'");
function test_addme() {
  actual = addMe(1, 2);
  expected = 3;
  assert("actual eq expected");
}
@neokoenig
neokoenig / .travis.yml
Created May 15, 2017 11:29
Travis Commandbox Plugin Test
language: java
sudo: required
jdk:
- oraclejdk8
before_install:
# Get Commandbox
- sudo apt-key adv --keyserver keys.gnupg.net --recv 6DA70622
- sudo echo "deb http://downloads.ortussolutions.com/debs/noarch /" | sudo tee -a /etc/apt/sources.list.d/commandbox.list
install:
# Install Commandbox
/**
* Add your description here
*
* [section: Plugins]
* [category: Your Plugin Name]
*
* @myParam A description of this parameter
*/
public array function awesomeFunction(required string myParam){
local.rv=[];
/**
* Removes all HTML tags from a string.
*
* [section: View Helpers]
* [category: Sanitization Functions]
*
* @html The HTML to remove tag markup from.
*/
public string function stripTags(required string html) {
local.rv = REReplaceNoCase(arguments.html, "<\ *[a-z].*?>", "", "all");