Guest User

Untitled

a guest
Aug 6th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.48 KB | None | 0 0
  1. grails: Behaviour of list.contains in code vs integration test
  2. def enabledLogins = toList(params.enabledLogins)
  3. def allLoginIds = params.allLoginIds.toString().split(',')
  4. loginService.updateLoginStatus(allLoginIds,enabledLogins)
  5.  
  6. def updateLoginStatus(String[] allLoginIds, List<Long> enabledLoginIds) {
  7. for (item in allLoginIds) {
  8. def login = Login.get(item.toLong())
  9. if (login) {
  10. login.enabled = enabledLoginIds.contains(item.toLong()) ? true : false
  11. login.save()
  12. if (login.hasErrors()) {
  13. login.errors.each { log.error(it) }
  14. }
  15. }
  16. }
  17. }
  18.  
  19. def testUpdateLoginStatus() {
  20. def id1 = createLogin().id
  21. def id2 = createLogin().id
  22.  
  23. String[] allLoginIds = [id1 as String, id2 as String]
  24. List<Long> enabledLoginIds = [id1]
  25.  
  26. loginService.updateLoginStatus(allLoginIds, enabledLoginIds)
  27.  
  28. def login1 = Login.get(id1)
  29. def login2 = Login.get(id2)
  30. assertTrue login1.enabled
  31. assertFalse login2.enabled
  32. }
  33. Login createLogin() {
  34. def now = System.currentTimeMillis()
  35.  
  36. def email = "int-test-" + now + "@somewhere.com"
  37. def password = "Pwd" + now + "pwD"
  38.  
  39. def login = new Login(username: email, password: password, firstName: "Integration", lastName: "Test")
  40. login.save(flush: true)
  41. assertNotNull login.id
  42.  
  43. return login
  44. }
  45.  
  46. def login = Login.get(item.toLong())
  47.  
  48. def enabledLogins = toList(params.enabledLogins)
  49.  
  50. ["1", "2"].contains("1")
  51.  
  52. ["1", "2"].contains(1)
Add Comment
Please, Sign In to add comment