Skip to content

Commit ad474d6

Browse files
committed
Add test for removeFrom with the in memory impl
1 parent bf9b147 commit ad474d6

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
package grails.gorm.tests
2+
3+
import grails.gorm.annotation.Entity
4+
import spock.lang.Issue
5+
6+
class RemoveFromSpec extends GormDatastoreSpec {
7+
8+
@Issue("https://github.com/grails/grails-data-mapping/issues/998")
9+
void "test removeFrom clears the back reference"() {
10+
given:
11+
new AuthorTest(name: "Joe").addToBooks(title: "Ready Player One").addToBooks(title: "Total Recall").save(flush: true, failOnError: true)
12+
new BookTest(title: "Unrelated").save(flush: true, failOnError: true)
13+
session.flush()
14+
session.clear()
15+
AuthorTest author = AuthorTest.first()
16+
BookTest book = author.books.find { it.title == "Total Recall" }
17+
18+
expect:
19+
author.books.size() == 2
20+
21+
when:
22+
author.removeFromBooks(book)
23+
author.save()
24+
book.save()
25+
session.flush()
26+
session.clear()
27+
author = AuthorTest.first()
28+
29+
then:
30+
author.books.size() == 1
31+
BookTest.count == 2
32+
}
33+
34+
List getDomainClasses() {
35+
[AuthorTest, BookTest]
36+
}
37+
38+
}
39+
40+
@Entity
41+
class AuthorTest {
42+
String name
43+
44+
static hasMany = [books: BookTest]
45+
46+
static constraints = {
47+
}
48+
}
49+
50+
@Entity
51+
class BookTest {
52+
String title
53+
54+
static belongsTo = [author: AuthorTest]
55+
56+
static constraints = {
57+
author nullable: true
58+
}
59+
}

0 commit comments

Comments
 (0)