executeUpdate query not working on grails spock test

依然范特西╮ 提交于 2019-12-11 20:12:21

问题


Now willing to do integration test as below but problem is that

MerchantTier.executeUpdate('update MerchantTier..........'), 

here update does not working

but if I make update with

def merchant = MerchantTier.get(params.id.toLong())

merchant.setValue(merchantTierVal)

instead of execute update it works

Is there is any prolem with executeUpdate Query?

def merchantTier

def setup() {

merchantTier = new MerchantTier(
     startTier: tier,
     endTier: tier,
     value: 2.02).save(flush: true)
}


void "for given merchantTierId update merchantTier"(){

     setup:
     params = [id:merchantTier.id,tierVal:2]

     when:
     testData = updateIndividualSuperResellerTier(params)

     then:"return data"
     merchantTier.value==params.tierVal
}

def updateIndividualSuperResellerTier(params) {

     def merchantTierVal = 0
     if (params.tierVal) {
         merchantTierVal = params.tierVal.toDouble()
     }
     def merchantTier = MerchantTier.get(params.id.toLong())
     def updateMerchantTier = MerchantTier.executeUpdate('update MerchantTier mt set mt.value=:mrValue where mt.id=:mtId', [mrValue: merchantTierVal, mtId: params.id.toLong()])
}

回答1:


There seems to be no problem with executeUpdate, the problem here could be, that executeUpdate did not return an object, it just return the number of rows updated so updateMerchantTier doesnot contain updatedObject.

Also you should again fetch the object as it is updated by executeUpdate in your void "for given merchantTierId update merchantTier"() then: statement

then:"return data"
 merchantTier.value==params.tierVal

here merchantTier is still an old object hence will not be having value equal to params.tierVal

in your other case you are using setter explicitly to set the property and hence it passed your Integration test.

 def merchant = MerchantTier.get(params.id.toLong())
 merchant.setValue(merchantTierVal)

hope this helps. Thanks



来源:https://stackoverflow.com/questions/33411653/executeupdate-query-not-working-on-grails-spock-test

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!