Permalink
Browse files

Added tests for connected and disconnected tags

  • Loading branch information...
ssherriff committed Mar 9, 2013
1 parent b4168d1 commit a9003d8da8800f04fc7bb16afabb4c042dad9a28
Showing with 108 additions and 0 deletions.
  1. +108 −0 test/unit/uk/co/desirableobjects/oauth/scribe/OauthTagLibSpec.groovy
@@ -38,6 +38,90 @@ class OauthTagLibSpec extends Specification {
}
+ def 'an oauth connected tag body is rendered when token in session'() {
+
+ given:
+
+ tagLib.oauthService = new OauthService()
+ tagLib.oauthService.findSessionKeyForAccessToken('twitter') >> { return 'twitter:oasAccessToken' }
+
+ and:
+
+ tagLib.session['twitter:oasAccessToken'] = new Token('a', 'b', 'c')
+
+ when:
+
+ def output = tagLib.connected([provider:'twitter'], { 'Connected content' } )
+
+ then:
+
+ output == 'Connected content'
+
+ }
+
+ def 'an oauth connected tag body is NOT rendered when token does not exist in session'() {
+
+ given:
+
+ tagLib.oauthService = new OauthService()
+ tagLib.oauthService.findSessionKeyForAccessToken('twitter') >> { return 'twitter:oasAccessToken' }
+
+ and:
+
+ tagLib.session['twitter:oasAccessToken'] = null
+
+ when:
+
+ def output = tagLib.connected([provider:'twitter'], { 'Connected content' } )
+
+ then:
+
+ output == ''
+
+ }
+
+ def 'an oauth disconnected tag body is NOT rendered when token in session'() {
+
+ given:
+
+ tagLib.oauthService = new OauthService()
+ tagLib.oauthService.findSessionKeyForAccessToken('twitter') >> { return 'twitter:oasAccessToken' }
+
+ and:
+
+ tagLib.session['twitter:oasAccessToken'] = new Token('a', 'b', 'c')
+
+ when:
+
+ def output = tagLib.disconnected([provider:'twitter'], { 'Disconnected content' } )
+
+ then:
+
+ output == ''
+
+ }
+
+ def 'an oauth disconnected tag body is rendered when token does not exist in session'() {
+
+ given:
+
+ tagLib.oauthService = new OauthService()
+ tagLib.oauthService.findSessionKeyForAccessToken('twitter') >> { return 'twitter:oasAccessToken' }
+
+ and:
+
+ tagLib.session['twitter:oasAccessToken'] = null
+
+ when:
+
+ def output = tagLib.disconnected([provider:'twitter'], { 'Disconnected content' } )
+
+ then:
+
+ output == 'Disconnected content'
+
+ }
+
def 'an oauth link tag fails if provider is not specified'() {
when:
@@ -50,6 +134,30 @@ class OauthTagLibSpec extends Specification {
}
+ def 'an oauth connected tag fails if provider is not specified'() {
+
+ when:
+
+ tagLib.connected([:], { 'Connected content' } )
+
+ then:
+
+ thrown GrailsTagException
+
+ }
+
+ def 'an oauth disconnected tag fails if provider is not specified'() {
+
+ when:
+
+ tagLib.disconnected([:], { 'Disconnected content' } )
+
+ then:
+
+ thrown GrailsTagException
+
+ }
+
private boolean asExpectations() {
assertions.each { actual, expected ->

0 comments on commit a9003d8

Please sign in to comment.