From 3230af3ce8be17c8cd4969f6aa96319837267030 Mon Sep 17 00:00:00 2001 From: Marcin Szczepanski Date: Sat, 6 Apr 2013 21:06:44 +1100 Subject: [PATCH 1/4] Add test that fails on Railo for #37 --- tests/defaultarg.cfc | 4 ++++ tests/model/beans/user37b.cfc | 11 +++++++++++ 2 files changed, 15 insertions(+) create mode 100644 tests/model/beans/user37b.cfc diff --git a/tests/defaultarg.cfc b/tests/defaultarg.cfc index 9ce7ea9..f1fcd93 100644 --- a/tests/defaultarg.cfc +++ b/tests/defaultarg.cfc @@ -5,6 +5,10 @@ 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() ); } } diff --git a/tests/model/beans/user37b.cfc b/tests/model/beans/user37b.cfc new file mode 100644 index 0000000..603a7df --- /dev/null +++ b/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; + } +} From 102241650510d181e441c99cd9dc6570809524a3 Mon Sep 17 00:00:00 2001 From: Marcin Szczepanski Date: Sat, 6 Apr 2013 21:07:50 +1100 Subject: [PATCH 2/4] Fix for constructor args with missing beans Return an empty structure when argument does not have a correspodning bean to ensure that it does not have a value set. --- ioc.cfc | 1 + 1 file changed, 1 insertion(+) diff --git a/ioc.cfc b/ioc.cfc index 8d9cd08..5970a02 100644 --- a/ioc.cfc +++ b/ioc.cfc @@ -551,6 +551,7 @@ component { accumulator.bean = bean; } else { missingBean( beanName ); + return {}; } return accumulator; } From a0feaf5d3e7c28a29f732086e8ebfc5fbda0dfde Mon Sep 17 00:00:00 2001 From: Marcin Szczepanski Date: Sat, 6 Apr 2013 21:41:50 +1100 Subject: [PATCH 3/4] Add a third test with "bookended" args Just testing the case where there's a bean, no bean and then bean again to make sure that the fix hasn't introduced any issues in that case. --- tests/defaultarg.cfc | 14 ++++++++++++++ tests/model/beans/user37c.cfc | 13 +++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 tests/model/beans/user37c.cfc diff --git a/tests/defaultarg.cfc b/tests/defaultarg.cfc index f1fcd93..b388980 100644 --- a/tests/defaultarg.cfc +++ b/tests/defaultarg.cfc @@ -11,4 +11,18 @@ component extends="mxunit.framework.TestCase" { 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() ); + + } } diff --git a/tests/model/beans/user37c.cfc b/tests/model/beans/user37c.cfc new file mode 100644 index 0000000..9013522 --- /dev/null +++ b/tests/model/beans/user37c.cfc @@ -0,0 +1,13 @@ +component accessors="true" { + property name="DSN"; + property name="ID"; + property name="name"; + + // to reveal an ordering bug changed ID to cd just so it comes before dsn + public any function init( dsn, ID = 0, NAME = "Bob") { + variables.dsn = dsn; + variables.ID = ID; + variables.name = name; + return this; + } +} From 3b3e99fad6b872b690b6d3dff2465913da53d6cb Mon Sep 17 00:00:00 2001 From: Marcin Szczepanski Date: Sat, 6 Apr 2013 21:43:37 +1100 Subject: [PATCH 4/4] Remove incorrect comment from latest test --- tests/model/beans/user37c.cfc | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/model/beans/user37c.cfc b/tests/model/beans/user37c.cfc index 9013522..78aa607 100644 --- a/tests/model/beans/user37c.cfc +++ b/tests/model/beans/user37c.cfc @@ -3,7 +3,6 @@ component accessors="true" { property name="ID"; property name="name"; - // to reveal an ordering bug changed ID to cd just so it comes before dsn public any function init( dsn, ID = 0, NAME = "Bob") { variables.dsn = dsn; variables.ID = ID;