use of response.reset()

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

use of response.reset()

Mauro
Action is:

def categoryList(Long id) {       
  if (id) {
    def categories = Sector.get(id).categories
    respond categories.sort { it.name }
}

the test is:


void "Test that categoryList action returns categories"() {
        Sector sector = new Sector(name:"Sec1").save()
        Category category1 = new Category(name:"Ctry1", sector: sector).save()
        Category category2 = new Category(name:"Ctry2", sector: sector).save()
        Category category3 = new Category(name:"Ctry3").save()
        Category category4 = new Category(name:"Ctry4").save()
       
        when:"The categoryList action is called with a Sector id"           
            controller.categoryList(sector.id)

        then:
            model.categoryInstanceList.size() == 2

        when:"The categoryList action is called without a Sector id"
            response.reset()
            controller.categoryList()

        then:
            model.categoryInstanceList == null     
}

does not pass because in the second test "The categoryList action is called without a Sector id" the categoryInstanceList is still == 2 while it should be null.
Error is:

Condition not satisfied:
model.categoryInstanceList == null
|     |                    |
|     [Ctry1, Ctry2]       false
[categoryInstanceList:[Ctry1, Ctry2]]

Test seems correct to me.
What I did wrong?