summaryrefslogtreecommitdiff
path: root/spec/javascripts
diff options
context:
space:
mode:
authormo khan <mo@mokhan.ca>2014-07-07 20:59:40 -0600
committermo khan <mo@mokhan.ca>2014-07-07 20:59:40 -0600
commitd1ef295914b0f9689b0c43aed4ac632b20d6aa74 (patch)
tree7fd354e5df6ce851a8239a3d57ff1589116df441 /spec/javascripts
parent01c7ed283d90effb6fb6b360d0ba1cc5055fa2ed (diff)
add validate specs for cake.
Diffstat (limited to 'spec/javascripts')
-rw-r--r--spec/javascripts/backbone/models/cake_spec.js.coffee35
1 files changed, 35 insertions, 0 deletions
diff --git a/spec/javascripts/backbone/models/cake_spec.js.coffee b/spec/javascripts/backbone/models/cake_spec.js.coffee
new file mode 100644
index 00000000..7e9f5f23
--- /dev/null
+++ b/spec/javascripts/backbone/models/cake_spec.js.coffee
@@ -0,0 +1,35 @@
+describe "CakeSide.Models.Cake", ->
+ createSUT = (attributes) ->
+ new CakeSide.Models.Cake(attributes)
+
+ describe "#validate", ->
+ it "returns an error when the name is null", ->
+ attributes =
+ name: null
+ cake = createSUT(attributes)
+ expect(cake.validate(attributes, {})).not.toBe(null)
+ expect(cake.isValid()).toBeFalsy()
+
+ it "returns an error when the name is blank", ->
+ attributes =
+ name: ' '
+ cake = createSUT(attributes)
+ expect(cake.validate(attributes, {})).not.toBe(null)
+ expect(cake.isValid()).toBeFalsy()
+
+
+ it 'returns an error when the category is blank', ->
+ attributes =
+ name: 'hi'
+ category_id: null
+ cake = createSUT(attributes)
+ expect(cake.validate(attributes)).not.toBe(null)
+ expect(cake.isValid()).toBeFalsy()
+
+ it 'is valid when a name and category is specified', ->
+ attributes =
+ name: 'hi'
+ category_id: 1
+ cake = createSUT(attributes)
+ expect(cake.validate(attributes)).toBeUndefined()
+ expect(cake.isValid()).toBeTruthy()