Welcome to mirror list, hosted at ThFree Co, Russian Federation.

post_spec.js « models « app « javascripts « spec - github.com/diaspora/diaspora.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 90dbca87cca0b3368f37bb04ffe5e14b2b16480f (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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
describe("app.models.Post", function() {
  beforeEach(function(){
    this.post = new app.models.Post();
  })

  describe("headline and body", function(){
    describe("headline", function(){
      beforeEach(function(){
        this.post.set({text :"     yes    "})
      })

      it("the headline is the entirety of the post", function(){
        expect(this.post.headline()).toBe("yes")
      })

      it("takes up until the new line", function(){
        this.post.set({text : "love\nis avery powerful force"})
        expect(this.post.headline()).toBe("love")
      })
    })

    describe("body", function(){
      it("takes after the new line", function(){
        this.post.set({text : "Inflamatory Title\nwith text that substantiates a less absolutist view of the title."})
        expect(this.post.body()).toBe("with text that substantiates a less absolutist view of the title.")
      })
    })
  })

  describe("createdAt", function() {
    it("returns the post's created_at as an integer", function() {
      var date = new Date;
      this.post.set({ created_at: +date * 1000 });

      expect(typeof this.post.createdAt()).toEqual("number");
      expect(this.post.createdAt()).toEqual(+date);
    });
  });

  describe("toggleLike", function(){
    it("calls unliked when the user_like exists", function(){
      this.post.set({user_like : "123"});
      spyOn(this.post, "unlike").andReturn(true);

      this.post.toggleLike();
      expect(this.post.unlike).toHaveBeenCalled();
    })

    it("calls liked when the user_like does not exist", function(){
      this.post.set({user_like : null});
      spyOn(this.post, "like").andReturn(true);

      this.post.toggleLike();
      expect(this.post.like).toHaveBeenCalled();
    })
  })

  describe("like", function(){
    it("calls create on the likes collection", function(){
      spyOn(this.post.likes, "create");

      this.post.like();
      expect(this.post.likes.create).toHaveBeenCalled();
    })
  })

  describe("unlike", function(){
    it("calls destroy on the likes collection", function(){
      var like = new app.models.Like();
      this.post.set({user_like : like.toJSON()})

      spyOn(app.models.Like.prototype, "destroy");

      this.post.unlike();
      expect(app.models.Like.prototype.destroy).toHaveBeenCalled();
    })
  })
});