Created
September 7, 2017 16:06
-
-
Save sdelamo/c65434a3bace81f8309adc5c4e41098d to your computer and use it in GitHub Desktop.
Don't do this, call save when you want to update or save
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package demo | |
class Note { | |
String msg | |
} | |
package demo | |
import grails.gorm.transactions.ReadOnly | |
import grails.gorm.transactions.Transactional | |
import groovy.transform.CompileStatic | |
@CompileStatic | |
class NoteService { | |
@ReadOnly | |
Note read(Serializable id) { | |
Note.read(id) | |
} | |
@Transactional | |
Note saveNote(String msg) { | |
Note note = new Note(msg: msg) | |
note.save() | |
} | |
@Transactional | |
Note updateMsg(Serializable id, String msg) { | |
Note note = Note.get(id) | |
note.msg = msg | |
note | |
} | |
} | |
package demo | |
import grails.testing.mixin.integration.Integration | |
import org.springframework.beans.factory.annotation.Autowired | |
import spock.lang.Specification | |
@Integration | |
class NoteSpec extends Specification { | |
@Autowired | |
NoteService noteService | |
def "test without calling save"() { | |
when: | |
Note note = noteService.saveNote('Note A') | |
Serializable noteId = note.id | |
then: | |
noteService.read(noteId).msg == 'Note A' | |
when: | |
noteService.updateMsg(noteId, 'Note B') | |
then: | |
noteService.read(noteId).msg == 'Note B' | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment