Browse files

Added new append method to TropoBuilder which allows to create more

complex builders by appending existing builder objects.

This closes #2
  • Loading branch information...
1 parent 45e0445 commit 07bb7660f73d3fd8aeae1a18cd35ce4c5e265b79 @mpermar mpermar committed Aug 4, 2011
View
2 TropoWebapiGrailsGrailsPlugin.groovy
@@ -1,6 +1,6 @@
class TropoWebapiGrailsGrailsPlugin {
// the plugin version
- def version = "0.1.1"
+ def version = "0.1.2"
// the version or versions of Grails the plugin is designed for
def grailsVersion = "1.3.6 > *"
// the other plugins this plugin depends on
View
5 src/groovy/com/tropo/grails/TropoBuilder.groovy
@@ -303,6 +303,11 @@ class TropoBuilder extends BuilderSupport {
def map = ["value":value]
createNode(name,map)
}
+ } else if (name == "append") {
+ JSONObject tropo = value.root['tropo']
+ tropo.entrySet().each {
+ createNode(it.key, it.value)
+ }
}
return null;
}
View
36 test/unit/com/tropo/grails/TropoBuilderTests.groovy
@@ -685,4 +685,40 @@ class TropoBuilderTests extends GroovyTestCase {
map = new TropoBuilder().parse(map)
assert map.session.userType == 'HUMAN'
}
+
+
+ public void testAppendTropo() {
+
+ def builder1 = new TropoBuilder()
+ builder1.tropo {
+ say('Please say your account number')
+ }
+
+ def builder2 = new TropoBuilder()
+ builder2.tropo {
+ ask(name : 'foo', bargein: true, timeout: 30, required: true, choices: '[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\"}]}}]}"
+ }
+
+ public void testAppendOnBlock() {
+
+ def builder1 = new TropoBuilder()
+ builder1.tropo {
+ on(event:'success',next:'/result.json')
+ }
+
+ def builder2 = new TropoBuilder()
+ builder2.tropo {
+ 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,\"say\":[{\"value\":\"Please say your account number\"}],\"choices\":{\"value\":\"[5 DIGITS]\"}}},{\"on\":{\"event\":\"success\",\"next\":\"/result.json\"}}]}"
+ }
}

0 comments on commit 07bb766

Please sign in to comment.