summaryrefslogtreecommitdiff
path: root/spec/javascripts/models/cake_spec.js.coffee
blob: 96627032a69e3a97957119fe210b47970b016702 (plain)
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
describe "csx.Models.Cake", ->
  subject = (attributes) ->
    new csx.Models.Cake(attributes)

  describe "#validate", ->
    it "returns an error when the name is null", ->
      attributes =
        name: null
      cake = subject(attributes)
      expect(cake.validate(attributes, {})).not.toBe(null)
      expect(cake.isValid()).toBeFalsy()

    it "returns an error when the name is blank", ->
      attributes =
        name: ' '
      cake = subject(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 = subject(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 = subject(attributes)
      expect(cake.validate(attributes)).toBeUndefined()
      expect(cake.isValid()).toBeTruthy()

  describe "#public_url", ->
    it "returns the correct url", ->
      result = subject(slug: '123-cake').public_url()
      expect(result).toMatch(/^http:\/\/.+\/creations\/123-cake$/)