Skip to content

Commit

Permalink
Refactor invalid resources
Browse files Browse the repository at this point in the history
  • Loading branch information
jarias committed Aug 6, 2015
1 parent 12f6288 commit 005b7a6
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 15 deletions.
25 changes: 16 additions & 9 deletions account_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@ import (
)

var _ = Describe("Account", func() {
invalidAccounts := []*Account{
&Account{Email: "test@test.org", GivenName: "test", Surname: "test"},
&Account{Username: "test", GivenName: "test", Surname: "test"},
&Account{Username: "test", Email: "test", GivenName: "test", Surname: "test"},
&Account{Username: "test", GivenName: "test", Surname: "test"},
&Account{Username: "test", Email: "test@test.org", Surname: "test"},
&Account{Username: "test", Email: "test@test.org", GivenName: "test"},
}

Describe("Validate", func() {
It("should return true if the account is valid", func() {
ok, err := newTestAccount().Validate()
Expand All @@ -17,15 +26,6 @@ var _ = Describe("Account", func() {
Expect(ok).To(BeTrue())
})
It("should return false if account is invalid", func() {
invalidAccounts := []*Account{
&Account{Email: "test@test.org", GivenName: "test", Surname: "test"},
&Account{Username: "test", GivenName: "test", Surname: "test"},
&Account{Username: "test", Email: "test", GivenName: "test", Surname: "test"},
&Account{Username: "test", GivenName: "test", Surname: "test"},
&Account{Username: "test", Email: "test@test.org", Surname: "test"},
&Account{Username: "test", Email: "test@test.org", GivenName: "test"},
}

for _, acct := range invalidAccounts {
ok, err := acct.Validate()

Expand All @@ -45,6 +45,13 @@ var _ = Describe("Account", func() {
})

Describe("Save", func() {
It("should not save if account is invalid", func() {
for _, acct := range invalidAccounts {
err := acct.Save()

Expect(err).To(HaveOccurred())
}
})
It("should update an existing account", func() {
account := newTestAccount()
app.RegisterAccount(account)
Expand Down
19 changes: 13 additions & 6 deletions application_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ import (
)

var _ = Describe("Application", func() {
invalidApps := []*Application{
&Application{},
&Application{Name: string256},
&Application{Name: "name", Description: string4001},
}

Describe("Validate", func() {
It("should return true if the application is valid", func() {
ok, err := NewApplication("test").Validate()
Expand All @@ -21,12 +27,6 @@ var _ = Describe("Application", func() {
Expect(ok).To(BeTrue())
})
It("should return false if application is invalid", func() {
invalidApps := []*Application{
&Application{},
&Application{Name: string256},
&Application{Name: "name", Description: string4001},
}

for _, app := range invalidApps {
ok, err := app.Validate()

Expand All @@ -46,6 +46,13 @@ var _ = Describe("Application", func() {
})

Describe("Save", func() {
It("should not save if application is invalid", func() {
for _, app := range invalidApps {
err := app.Save()

Expect(err).To(HaveOccurred())
}
})
It("should update an existing application", func() {
app.Name = "new-name" + randomName()
err := app.Save()
Expand Down

0 comments on commit 005b7a6

Please sign in to comment.