Skip to content

Commit

Permalink
Added new append method to TropoBuilder which allows to create more
Browse files Browse the repository at this point in the history
complex builders by appending existing builder objects.

This closes #2
  • Loading branch information
mpermar committed Aug 4, 2011
1 parent 45e0445 commit 07bb766
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 1 deletion.
2 changes: 1 addition & 1 deletion TropoWebapiGrailsGrailsPlugin.groovy
Original file line number Original file line Diff line number Diff line change
@@ -1,6 +1,6 @@
class TropoWebapiGrailsGrailsPlugin { class TropoWebapiGrailsGrailsPlugin {
// the plugin version // the plugin version
def version = "0.1.1" def version = "0.1.2"
// the version or versions of Grails the plugin is designed for // the version or versions of Grails the plugin is designed for
def grailsVersion = "1.3.6 > *" def grailsVersion = "1.3.6 > *"
// the other plugins this plugin depends on // the other plugins this plugin depends on
Expand Down
5 changes: 5 additions & 0 deletions src/groovy/com/tropo/grails/TropoBuilder.groovy
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -303,6 +303,11 @@ class TropoBuilder extends BuilderSupport {
def map = ["value":value] def map = ["value":value]
createNode(name,map) createNode(name,map)
} }
} else if (name == "append") {
JSONObject tropo = value.root['tropo']
tropo.entrySet().each {
createNode(it.key, it.value)
}
} }
return null; return null;
} }
Expand Down
36 changes: 36 additions & 0 deletions test/unit/com/tropo/grails/TropoBuilderTests.groovy
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -685,4 +685,40 @@ class TropoBuilderTests extends GroovyTestCase {
map = new TropoBuilder().parse(map) map = new TropoBuilder().parse(map)
assert map.session.userType == 'HUMAN' 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.