Permalink
Browse files

/Antony /Lukasz Allow restful disabling and enabling of features.

  • Loading branch information...
1 parent 2589fe3 commit f1945745cefbf164681f8d4b1562e37d737191ed popcorn committed Jan 18, 2013
@@ -1,6 +1,6 @@
class FeatureSwitchGrailsPlugin {
- def version = "0.4"
+ def version = "0.5"
def grailsVersion = "2.0 > *"
def dependsOn = [:]
def observe = ["controllers"]
@@ -1,5 +1,4 @@
#Grails Metadata file
#Wed Dec 12 16:48:52 GMT 2012
-app.grails.version=2.1.1
+app.grails.version=2.2.0
app.name=feature-switch
-plugins.rest-client-builder=1.0.3
@@ -6,6 +6,12 @@ grails.project.target.level = 1.6
grails.release.scm.enabled = false
+version {
+ spock = '0.7'
+ geb = '0.9.0-SNAPSHOT'
+ selenium = '2.28.0'
+}
+
grails.project.dependency.resolution = {
// inherit Grails' default dependencies
inherits("global") {
@@ -14,34 +20,30 @@ grails.project.dependency.resolution = {
}
log "warn" // log level of Ivy resolver, either 'error', 'warn', 'info', 'debug' or 'verbose'
- def seleniumVersion = "2.25.0"
- def gebVersion = "0.7.1"
-
repositories {
grailsCentral()
- // uncomment the below to enable remote dependency resolution
- // from public Maven repositories
mavenLocal
mavenCentral()
- //mavenRepo "http://snapshots.repository.codehaus.org"
- //mavenRepo "http://repository.codehaus.org"
- //mavenRepo "http://download.java.net/maven/2/"
- //mavenRepo "http://repository.jboss.com/maven2/"
+ mavenRepo 'https://oss.sonatype.org/content/repositories/snapshots'
}
dependencies {
- test("org.seleniumhq.selenium:selenium-firefox-driver:$seleniumVersion")
- test "org.codehaus.geb:geb-spock:$gebVersion"
+ test "org.seleniumhq.selenium:selenium-firefox-driver:${version.selenium}",
+ "org.gebish:geb-spock:${version.geb}",
+ "org.spockframework:spock-grails-support:${version.spock}-groovy-2.0"
build 'org.codehaus.groovy.modules.http-builder:http-builder:0.6'
}
plugins {
- test ':spock:0.6',
- ":geb:$gebVersion"
+ test ":spock:${version.spock}", {
+ exclude "spock-grails-support"
+ }
+
+ test ":geb:${version.geb}"
- build(":tomcat:$grailsVersion",
+ build ":tomcat:$grailsVersion",
":rest-client-builder:1.0.3",
- ":release:2.2.0") {
+ ":release:2.2.0", {
export = false
}
@@ -3,5 +3,6 @@ class FeatureSwitchUrlMappings {
static mappings = {
"/admin/features"(controller: 'featureSwitchAdmin', action: 'switches')
"/admin/features/toggle"(controller: 'featureSwitchAdmin', action: 'toggle')
+ "/admin/features/$feature/$action"(controller: 'featureSwitchAdmin')
}
}
@@ -9,5 +9,5 @@ class UrlMappings {
"/"(view:"/index")
"500"(view:'/error')
- }
+ }
}
@@ -1,7 +1,20 @@
package uk.co.desirableobjects.featureswitch
+import grails.converters.JSON
+
class FeatureSwitchAdminController {
+ def beforeInterceptor = [action: this.&validateFeature, except: 'switches']
+
+ private validateFeature() {
+
+ String feature = params.feature
+ if (!grailsApplication.config.features.containsKey(feature)) {
+ throw new IllegalArgumentException("Feature ${feature} does not exist.")
+ }
+
+ }
+
def switches() {
Map<String, Boolean> model = [:]
@@ -20,4 +33,14 @@ class FeatureSwitchAdminController {
redirect action: 'switches'
}
+
+ def enable(String feature) {
+ grailsApplication.config.features[feature].enabled = true
+ render text: [(feature): 'enabled'] as JSON
+ }
+
+ def disable(String feature) {
+ grailsApplication.config.features[feature].enabled = false
+ render text: [(feature): 'disabled'] as JSON
+ }
}
@@ -1,6 +1,7 @@
package uk.co.desirableobjects.featureswitch
import geb.spock.GebSpec
+import spock.lang.Unroll
import uk.co.desirableobjects.featureswitch.page.SwitchesPage
class AdminSwitchesSpec extends GebSpec {
@@ -67,4 +68,34 @@ class AdminSwitchesSpec extends GebSpec {
!switches(2).enabled
}
+ @Unroll
+ def 'a user can #action a feature by simply hitting an endpoint'() {
+
+ given:
+ String url = browser.baseUrl+SwitchesPage.url+'/toggle-me/'+action
+
+ when:
+ String response = new URL(url).text
+
+ then:
+ response == """{"toggle-me":"${action}d"}"""
+
+ where:
+ action << ['enable', 'disable']
+
+ }
+
+ def 'a user cannot toggle an unknown feature'() {
+
+ given:
+ String url = browser.baseUrl+SwitchesPage.url+'/non-existent/enable'
+
+ when:
+ String response = new URL(url).text
+
+ then:
+ thrown IOException
+
+ }
+
}

0 comments on commit f194574

Please sign in to comment.