Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- grails: Behaviour of list.contains in code vs integration test
- def enabledLogins = toList(params.enabledLogins)
- def allLoginIds = params.allLoginIds.toString().split(',')
- loginService.updateLoginStatus(allLoginIds,enabledLogins)
- def updateLoginStatus(String[] allLoginIds, List<Long> enabledLoginIds) {
- for (item in allLoginIds) {
- def login = Login.get(item.toLong())
- if (login) {
- login.enabled = enabledLoginIds.contains(item.toLong()) ? true : false
- login.save()
- if (login.hasErrors()) {
- login.errors.each { log.error(it) }
- }
- }
- }
- }
- def testUpdateLoginStatus() {
- def id1 = createLogin().id
- def id2 = createLogin().id
- String[] allLoginIds = [id1 as String, id2 as String]
- List<Long> enabledLoginIds = [id1]
- loginService.updateLoginStatus(allLoginIds, enabledLoginIds)
- def login1 = Login.get(id1)
- def login2 = Login.get(id2)
- assertTrue login1.enabled
- assertFalse login2.enabled
- }
- Login createLogin() {
- def now = System.currentTimeMillis()
- def email = "int-test-" + now + "@somewhere.com"
- def password = "Pwd" + now + "pwD"
- def login = new Login(username: email, password: password, firstName: "Integration", lastName: "Test")
- login.save(flush: true)
- assertNotNull login.id
- return login
- }
- def login = Login.get(item.toLong())
- def enabledLogins = toList(params.enabledLogins)
- ["1", "2"].contains("1")
- ["1", "2"].contains(1)
Add Comment
Please, Sign In to add comment