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

interacations_spec.js « post « models « app « javascripts « spec - github.com/diaspora/diaspora.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: f6a5be3ad6d92f150e1e26bb065e7b1796a18786 (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
describe("app.models.Post.Interactions", function(){
  beforeEach(function(){
    this.interactions = factory.post()
    this.interactions = this.interactions.interactions
    this.author = factory.author({guid: "loggedInAsARockstar"})
    loginAs({guid: "loggedInAsARockstar"})

    this.userLike = new app.models.Like({author : this.author})
  })
  
  describe("toggleLike", function(){
    it("calls unliked when the user_like exists", function(){
      this.interactions.likes.add(this.userLike)
      spyOn(this.interactions, "unlike").andReturn(true);
      this.interactions.toggleLike();
      expect(this.interactions.unlike).toHaveBeenCalled();
    })

    it("calls liked when the user_like does not exist", function(){
      this.interactions.likes.reset([]);
      spyOn(this.interactions, "like").andReturn(true);
      this.interactions.toggleLike();
      expect(this.interactions.like).toHaveBeenCalled();
    })
  })

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

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

  describe("unlike", function(){
    it("calls destroy on the likes collection", function(){
      this.interactions.likes.add(this.userLike)
      spyOn(this.userLike, "destroy");

      this.interactions.unlike();
      expect(this.userLike.destroy).toHaveBeenCalled();
    })
  })
})