Permalink
Browse files

Changed append method. Now it is only applicable at the first level of

the closure. 

Fixed the issue that prevented us from appending builders with more
than one statement on it.
  • Loading branch information...
1 parent fee8b5d commit 8958ab5339afb8e2d9deccbacc84215b17210d3a @mpermar mpermar committed Aug 11, 2011
@@ -304,9 +304,14 @@ class TropoBuilder extends BuilderSupport {
createNode(name,map)
}
} else if (name == "append") {
- JSONObject tropo = value.root['tropo']
- tropo.entrySet().each {
- createNode(it.key, it.value)
+ def builder = value.root['tropo']
+ def rootArray = root['tropo']
+ if (builder instanceof JSONObject) {
+ rootArray.add(builder)
+ } else if (builder instanceof JSONArray) {
+ builder.each {
+ rootArray.add(it)
+ }
}
}
return null;
@@ -686,29 +686,30 @@ class TropoBuilderTests extends GroovyTestCase {
assert map.session.userType == 'HUMAN'
}
-
- public void testAppendTropo() {
+ public void testAppendOnBlock() {
- def builder1 = new TropoBuilder()
+ def builder1 = new TropoBuilder()
builder1.tropo {
- say('Please say your account number')
+ on(event:'success',next:'/result.json')
}
def builder2 = new TropoBuilder()
builder2.tropo {
- ask(name : 'foo', bargein: true, timeout: 30, required: true, choices: '[5 DIGITS]') {
- append(builder1)
+ ask(name : 'foo', bargein: true, timeout: 30, required: true) {
+ say('Please say your account number')
+ choices(value: '[5 DIGITS]')
}
+ append(builder1)
}
-
- assert builder2.text() == "{\"tropo\":[{\"ask\":{\"name\":\"foo\",\"bargein\":true,\"timeout\":30,\"required\":true,\"choices\":[\"5 DIGITS\"],\"say\":[{\"value\":\"Please say your account number\"}]}}]}"
+ assert builder2.text() == "{\"tropo\":[{\"ask\":{\"name\":\"foo\",\"bargein\":true,\"timeout\":30,\"required\":true,\"say\":[{\"value\":\"Please say your account number\"}],\"choices\":{\"value\":\"[5 DIGITS]\"}}},{\"on\":{\"event\":\"success\",\"next\":\"/result.json\"}}]}"
}
- public void testAppendOnBlock() {
+ public void testAppendBlockWithMultipleElements() {
- def builder1 = new TropoBuilder()
+ def builder1 = new TropoBuilder()
builder1.tropo {
- on(event:'success',next:'/result.json')
+ say('Hello tropo')
+ hangup()
}
def builder2 = new TropoBuilder()
@@ -719,7 +720,7 @@ class TropoBuilderTests extends GroovyTestCase {
}
append(builder1)
}
- assert builder2.text() == "{\"tropo\":[{\"ask\":{\"name\":\"foo\",\"bargein\":true,\"timeout\":30,\"required\":true,\"say\":[{\"value\":\"Please say your account number\"}],\"choices\":{\"value\":\"[5 DIGITS]\"}}},{\"on\":{\"event\":\"success\",\"next\":\"/result.json\"}}]}"
+ assert builder2.text() == "{\"tropo\":[{\"ask\":{\"name\":\"foo\",\"bargein\":true,\"timeout\":30,\"required\":true,\"say\":[{\"value\":\"Please say your account number\"}],\"choices\":{\"value\":\"[5 DIGITS]\"}}},{\"say\":[{\"value\":\"Hello tropo\"}]},{\"hangup\":null}]}"
}
public void testIsEmpty() {

0 comments on commit 8958ab5

Please sign in to comment.