Navigation Menu

Skip to content

Commit

Permalink
Merge pull request #42 from marcins/issue-37-defaultargs
Browse files Browse the repository at this point in the history
Add useful tests for debugging #37
  • Loading branch information
seancorfield committed Apr 6, 2013
2 parents 861be7d + 3b3e99f commit fe2a4c7
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 0 deletions.
1 change: 1 addition & 0 deletions ioc.cfc
Expand Up @@ -551,6 +551,7 @@ component {
accumulator.bean = bean;
} else {
missingBean( beanName );
return {};
}
return accumulator;
}
Expand Down
18 changes: 18 additions & 0 deletions tests/defaultarg.cfc
Expand Up @@ -5,6 +5,24 @@ component extends="mxunit.framework.TestCase" {
var user37 = factory.getBean( "user37" );
assertEquals( "sample", user37.getDSN() );
assertEquals( 0, user37.getID() );

var user37b = factory.getBean( "user37b" );
assertEquals( "sample", user37b.getDSN() );
assertEquals( 0, user37b.getID() );
}

function checkDefaultInitArgThreeArgs() {
var factory = new ioc( "/tests/model", { constants = { dsn = "sample" } } );
var user37c = factory.getBean( "user37c" );
assertEquals( "sample", user37c.getDSN() );
assertEquals( 0, user37c.getID() );
assertEquals( "Bob", user37c.getName() );

factory = new ioc( "/tests/model", { constants = { dsn = "sample", name="John" } } );
user37c = factory.getBean( "user37c" );
assertEquals( "sample", user37c.getDSN() );
assertEquals( 0, user37c.getID() );
assertEquals( "John", user37c.getName() );

}
}
11 changes: 11 additions & 0 deletions tests/model/beans/user37b.cfc
@@ -0,0 +1,11 @@
component accessors="true" {
property name="DSN";
property name="ID";

// to reveal an ordering bug changed ID to cd just so it comes before dsn
public any function init( dsn, cd = 0 ) {
variables.dsn = dsn;
variables.ID = cd;
return this;
}
}
12 changes: 12 additions & 0 deletions tests/model/beans/user37c.cfc
@@ -0,0 +1,12 @@
component accessors="true" {
property name="DSN";
property name="ID";
property name="name";

public any function init( dsn, ID = 0, NAME = "Bob") {
variables.dsn = dsn;
variables.ID = ID;
variables.name = name;
return this;
}
}

0 comments on commit fe2a4c7

Please sign in to comment.