I'm trying to test a filter in Grails 2.2.1 that stores a value in the global session
object anytime somebody hits any URL in my application. Here's what I came up with, thanks to this fine post:
package drummer
class SessionExpirationFilters {
def filters = {
all(controller: '*', action: '*') {
before = {
session.foo = 'bar'
}
}
}
}
I'm able to see that the filter works by outputting session.foo
in a controller method, but the integration test fails:
package drummer
import grails.plugin.spock.IntegrationSpec
class QuestionControllerIntegrationSpec extends IntegrationSpec {
def 'filter sets session foo to bar'() {
given:
def controller = new QuestionController()
when:
controller.list()
then:
assert 'bar' == controller.session.foo // fails, session.foo is null
}
}
So why isn't the 'foo' session object property set in the integration test?