master
 1describe "csx.Models.Cake", ->
 2  subject = (attributes) ->
 3    new csx.Models.Cake(attributes)
 4
 5  describe "#validate", ->
 6    it "returns an error when the name is null", ->
 7      attributes =
 8        name: null
 9      cake = subject(attributes)
10      expect(cake.validate(attributes, {})).not.toBe(null)
11      expect(cake.isValid()).toBeFalsy()
12
13    it "returns an error when the name is blank", ->
14      attributes =
15        name: ' '
16      cake = subject(attributes)
17      expect(cake.validate(attributes, {})).not.toBe(null)
18      expect(cake.isValid()).toBeFalsy()
19
20
21    it 'returns an error when the category is blank', ->
22      attributes = 
23        name: 'hi'
24        category_id: null
25      cake = subject(attributes)
26      expect(cake.validate(attributes)).not.toBe(null)
27      expect(cake.isValid()).toBeFalsy()
28
29    it 'is valid when a name and category is specified', ->
30      attributes =
31        name: 'hi'
32        category_id: 1
33      cake = subject(attributes)
34      expect(cake.validate(attributes)).toBeUndefined()
35      expect(cake.isValid()).toBeTruthy()
36
37  describe "#public_url", ->
38    it "returns the correct url", ->
39      result = subject(slug: '123-cake').public_url()
40      expect(result).toMatch(/^http:\/\/.+\/creations\/123-cake$/)