Reputation: 586
Do I have to save a domain class to a mock table like this in 2.0:
def jdoe = new User(name:"John Doe", role:"user")
def suziq = new User(name:"Suzi Q", role:"admin")
def jsmith = new User(name:"Jane Smith", role:"user")
mockDomain(User, [jdoe, suziq, jsmith])
def test = User.get(1) //correct ?
Or is it enough just to use @Mock and @TestFor ?
@TestFor(MyController)
@Mock([User,Role])
{...
def jdoe = new User(name:"John Doe", role:"user")
def suziq = new User(name:"Suzi Q", role:"admin")
def jsmith = new User(name:"Jane Smith", role:"user")
def test = User.get(1) //will this work ?
}
Upvotes: 1
Views: 328
Reputation: 1043
use flushing in unit tests for domain objects and mixin!
@TestFor(MyController)
@Mock([User,Role])
@TestMixin(DomainClassUnitTestMixin)
{...
def jdoe = new User(name:"John Doe", role:"user").save(flush:true)
def suziq = new User(name:"Suzi Q", role:"admin").save(flush:true)
def jsmith = new User(name:"Jane Smith", role:"user").save(flush:true)
def test = User.get(1) //will this work ?
}
Upvotes: 1