Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: f5739f719c
Fetching contributors…

Cannot retrieve contributors at this time

194 lines (106 sloc) 4.258 kb
package uk.co.desirableobjects.oauth.scribe
import grails.plugin.spock.TagLibSpec
import org.gmock.WithGMock
import org.scribe.model.Token
import org.scribe.model.Verifier
import org.codehaus.groovy.grails.plugins.web.taglib.ApplicationTagLib
import grails.test.mixin.TestFor
import spock.lang.Specification
import org.codehaus.groovy.grails.web.taglib.exceptions.GrailsTagException
@TestFor(OauthTagLib)
class OauthTagLibSpec extends Specification {
Map assertions = [:]
void setup() {
assertions.clear()
}
def 'an oauth link tag can be rendered'() {
given:
OauthTagLib.metaClass.g.link = { attrs, body ->
assertions.put(body(), 'Click here to authorise')
}
when:
tagLib.connect([provider:'twitter'], { 'Click here to authorise' } )
then:
asExpectations()
}
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:
tagLib.connect([:], { 'Click here to authorise' } )
then:
thrown GrailsTagException
}
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 ->
if (actual != expected) {
throw new RuntimeException('Expectation failed: '+actual+" != "+expected)
}
}
return true
}
def 'an oauth link tag renders its arguments as passed'() {
given:
OauthTagLib.metaClass.g.link = { attrs, body ->
assertions.put(attrs.'class', 'ftw')
}
when:
tagLib.connect([provider: 'twitter', 'class':'ftw'], { 'Click here to authorise' } )
then:
asExpectations()
}
}
Jump to Line
Something went wrong with that request. Please try again.