/
CompanyTests.groovy
46 lines (40 loc) · 1.36 KB
/
CompanyTests.groovy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package hub
import static org.junit.Assert.*
import grails.test.mixin.*
import grails.test.mixin.support.*
import org.junit.*
/**
* See the API for {@link grails.test.mixin.support.GrailsUnitTestMixin} for usage instructions
*/
@TestMixin(GrailsUnitTestMixin)
@TestFor(Company)
@Mock(Tag)
class CompanyTests {
void testEncryptPassword() {
def password = "foobar"
def company = new Company(password: password)
company.encrypt()
assert password != company.password
}
void testEncryptPasswordBeforeSave() {
def password = "foobar"
def company = new Company(password: password, name: "foo", email: "foo@bar.com")
company.beforeInsert()
company.save()
assert password != company.password
}
void testCreateTagsWhenACompanyIsTagged() {
def company = new Company(password: "foobar", name: "foo", email: "foo@bar.com")
.persistTags("java, groovy")
.save()
assert 2 == Tag.count()
assert 2 == company.tags.size()
}
void testDeleteTagsWhenACompanyIsTagged() {
def company = new Company(password: "foobar", name: "foo", email: "foo@bar.com")
.persistTags("java, groovy")
.save()
company.persistTags("groovy")
assert 1 == company.tags.size()
}
}