Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-platform
Commits
cfa094e4
Commit
cfa094e4
authored
Jul 02, 2013
by
David Baumgold
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Validation tests for Backbone models
parent
eba59280
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
50 additions
and
4 deletions
+50
-4
cms/static/coffee/spec/models/textbook_spec.coffee
+50
-4
No files found.
cms/static/coffee/spec/models/textbook_spec.coffee
View file @
cfa094e4
...
@@ -8,6 +8,7 @@ describe "CMS.Models.Textbook", ->
...
@@ -8,6 +8,7 @@ describe "CMS.Models.Textbook", ->
beforeEach
->
beforeEach
->
@
model
=
new
CMS
.
Models
.
Textbook
()
@
model
=
new
CMS
.
Models
.
Textbook
()
describe
"Basic"
,
->
it
"should have an empty name by default"
,
->
it
"should have an empty name by default"
,
->
expect
(
@
model
.
get
(
"name"
)).
toEqual
(
""
)
expect
(
@
model
.
get
(
"name"
)).
toEqual
(
""
)
...
@@ -43,10 +44,7 @@ describe "CMS.Models.Textbook", ->
...
@@ -43,10 +44,7 @@ describe "CMS.Models.Textbook", ->
@
model
.
setOriginalAttributes
()
@
model
.
setOriginalAttributes
()
expect
(
@
model
.
isDirty
()).
toBeFalsy
()
expect
(
@
model
.
isDirty
()).
toBeFalsy
()
describe
"Input/Output"
,
->
describe
"CMS.Models.Textbook input/output"
,
->
# replace with Backbone.Assocations.deepAttributes when
# https://github.com/dhruvaray/backbone-associations/pull/43 is merged
deepAttributes
=
(
obj
)
->
deepAttributes
=
(
obj
)
->
if
obj
instanceof
Backbone
.
Model
if
obj
instanceof
Backbone
.
Model
deepAttributes
(
obj
.
attributes
)
deepAttributes
(
obj
.
attributes
)
...
@@ -90,6 +88,40 @@ describe "CMS.Models.Textbook input/output", ->
...
@@ -90,6 +88,40 @@ describe "CMS.Models.Textbook input/output", ->
expect
(
deepAttributes
(
model
)).
toEqual
(
clientModelSpec
)
expect
(
deepAttributes
(
model
)).
toEqual
(
clientModelSpec
)
expect
(
model
.
toJSON
()).
toEqual
(
serverModelSpec
)
expect
(
model
.
toJSON
()).
toEqual
(
serverModelSpec
)
describe
"Validation"
,
->
it
"requires a name"
,
->
model
=
new
CMS
.
Models
.
Textbook
({
name
:
""
})
expect
(
model
.
isValid
()).
toBeFalsy
()
it
"requires at least one chapter"
,
->
model
=
new
CMS
.
Models
.
Textbook
({
name
:
"foo"
})
model
.
get
(
"chapters"
).
reset
()
expect
(
model
.
isValid
()).
toBeFalsy
()
it
"requires a valid chapter"
,
->
chapter
=
new
CMS
.
Models
.
Chapter
()
chapter
.
isValid
=
->
false
model
=
new
CMS
.
Models
.
Textbook
({
name
:
"foo"
})
model
.
get
(
"chapters"
).
reset
([
chapter
])
expect
(
model
.
isValid
()).
toBeFalsy
()
it
"requires all chapters to be valid"
,
->
chapter1
=
new
CMS
.
Models
.
Chapter
()
chapter1
.
isValid
=
->
true
chapter2
=
new
CMS
.
Models
.
Chapter
()
chapter2
.
isValid
=
->
false
model
=
new
CMS
.
Models
.
Textbook
({
name
:
"foo"
})
model
.
get
(
"chapters"
).
reset
([
chapter1
,
chapter2
])
expect
(
model
.
isValid
()).
toBeFalsy
()
it
"can pass validation"
,
->
chapter
=
new
CMS
.
Models
.
Chapter
()
chapter
.
isValid
=
->
true
model
=
new
CMS
.
Models
.
Textbook
({
name
:
"foo"
})
model
.
get
(
"chapters"
).
reset
([
chapter
])
expect
(
model
.
isValid
()).
toBeTruthy
()
describe
"CMS.Collections.TextbookSet"
,
->
describe
"CMS.Collections.TextbookSet"
,
->
beforeEach
->
beforeEach
->
CMS
.
URL
.
TEXTBOOK
=
"/textbooks"
CMS
.
URL
.
TEXTBOOK
=
"/textbooks"
...
@@ -111,6 +143,7 @@ describe "CMS.Models.Chapter", ->
...
@@ -111,6 +143,7 @@ describe "CMS.Models.Chapter", ->
beforeEach
->
beforeEach
->
@
model
=
new
CMS
.
Models
.
Chapter
()
@
model
=
new
CMS
.
Models
.
Chapter
()
describe
"Basic"
,
->
it
"should have a name by default"
,
->
it
"should have a name by default"
,
->
expect
(
@
model
.
get
(
"name"
)).
toEqual
(
""
)
expect
(
@
model
.
get
(
"name"
)).
toEqual
(
""
)
...
@@ -123,6 +156,19 @@ describe "CMS.Models.Chapter", ->
...
@@ -123,6 +156,19 @@ describe "CMS.Models.Chapter", ->
it
"should be empty by default"
,
->
it
"should be empty by default"
,
->
expect
(
@
model
.
isEmpty
()).
toBeTruthy
()
expect
(
@
model
.
isEmpty
()).
toBeTruthy
()
describe
"Validation"
,
->
it
"requires a name"
,
->
model
=
new
CMS
.
Models
.
Chapter
({
name
:
""
,
asset_path
:
"a.pdf"
})
expect
(
model
.
isValid
()).
toBeFalsy
()
it
"requires an asset_path"
,
->
model
=
new
CMS
.
Models
.
Chapter
({
name
:
"a"
,
asset_path
:
""
})
expect
(
model
.
isValid
()).
toBeFalsy
()
it
"can pass validation"
,
->
model
=
new
CMS
.
Models
.
Chapter
({
name
:
"a"
,
asset_path
:
"a.pdf"
})
expect
(
model
.
isValid
()).
toBeTruthy
()
describe
"CMS.Collections.ChapterSet"
,
->
describe
"CMS.Collections.ChapterSet"
,
->
beforeEach
->
beforeEach
->
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment