-
Notifications
You must be signed in to change notification settings - Fork 198
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test for removeFrom with the in memory impl
- Loading branch information
1 parent
a6f29a6
commit 0c63b3c
Showing
1 changed file
with
59 additions
and
0 deletions.
There are no files selected for viewing
59 changes: 59 additions & 0 deletions
59
grails-datastore-gorm-test/src/test/groovy/grails/gorm/tests/RemoveFromSpec.groovy
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package grails.gorm.tests | ||
|
||
import grails.gorm.annotation.Entity | ||
import spock.lang.Issue | ||
|
||
class RemoveFromSpec extends GormDatastoreSpec { | ||
|
||
@Issue("https://github.com/grails/grails-data-mapping/issues/998") | ||
void "test removeFrom clears the back reference"() { | ||
given: | ||
new AuthorTest(name: "Joe").addToBooks(title: "Ready Player One").addToBooks(title: "Total Recall").save(flush: true, failOnError: true) | ||
new BookTest(title: "Unrelated").save(flush: true, failOnError: true) | ||
session.flush() | ||
session.clear() | ||
AuthorTest author = AuthorTest.first() | ||
BookTest book = author.books.find { it.title == "Total Recall" } | ||
|
||
expect: | ||
author.books.size() == 2 | ||
|
||
when: | ||
author.removeFromBooks(book) | ||
author.save() | ||
book.save() | ||
session.flush() | ||
session.clear() | ||
author = AuthorTest.first() | ||
|
||
then: | ||
author.books.size() == 1 | ||
BookTest.count == 2 | ||
} | ||
|
||
List getDomainClasses() { | ||
[AuthorTest, BookTest] | ||
} | ||
|
||
} | ||
|
||
@Entity | ||
class AuthorTest { | ||
String name | ||
|
||
static hasMany = [books: BookTest] | ||
|
||
static constraints = { | ||
} | ||
} | ||
|
||
@Entity | ||
class BookTest { | ||
String title | ||
|
||
static belongsTo = [author: AuthorTest] | ||
|
||
static constraints = { | ||
author nullable: true | ||
} | ||
} |