diaspora/spec/javascripts/app/models/stream_spec.js
Florian Staudacher 1924c40d38 replace vendored backbone.js/underscore.js with 'backbone-on-rails' gem
- updates underscore to 1.5.2 and backbone to 1.1.0

backbone had some breaking changes:
- fix url/urlRoot handling in models & collections
- options are no longer attached to the view by default
- collections reset when 'fetch' is called, tell it to keep the existing
  models

other changes:
- fix some events triggering multiple times in connection with deleting
  a model
- use document fragments instead of an element array for stream entries
- adapt jasmine and cucumber specs to the changed code
  * no longer test the backbone router as part of our code
  * jasmine factory already returns model instances, no need to wrap
    that again
2014-01-16 23:23:30 +01:00

55 lines
1.8 KiB
JavaScript

describe("app.models.Stream", function() {
beforeEach(function(){
this.stream = new app.models.Stream(),
this.expectedPath = document.location.pathname;
})
describe(".fetch", function() {
var postFetch
beforeEach(function(){
postFetch = new $.Deferred()
spyOn(this.stream.items, "fetch").andCallFake(function(){
return postFetch
})
})
it("it fetches posts from the window's url, and ads them to the collection", function() {
this.stream.fetch()
expect(this.stream.items.fetch).toHaveBeenCalledWith({ remove: false, url: this.expectedPath});
});
it("returns the json path with max_time if the collection has models", function() {
var post = new app.models.Post();
spyOn(post, "createdAt").andReturn(1234);
this.stream.add(post);
this.stream.fetch()
expect(this.stream.items.fetch).toHaveBeenCalledWith({ remove: false, url: this.expectedPath + "?max_time=1234"});
});
it("triggers fetched on the stream when it is fetched", function(){
var fetchedSpy = jasmine.createSpy()
this.stream.bind('fetched', fetchedSpy)
this.stream.fetch()
postFetch.resolve([1,2,3])
expect(fetchedSpy).toHaveBeenCalled()
})
it("triggers allItemsLoaded on the stream when zero posts are returned", function(){
var fetchedSpy = jasmine.createSpy()
this.stream.bind('allItemsLoaded', fetchedSpy)
this.stream.fetch()
postFetch.resolve([])
expect(fetchedSpy).toHaveBeenCalled()
})
it("triggers allItemsLoaded on the stream when a Post is returned", function(){
var fetchedSpy = jasmine.createSpy()
this.stream.bind('allItemsLoaded', fetchedSpy)
this.stream.fetch()
postFetch.resolve(factory.post().attributes)
expect(fetchedSpy).toHaveBeenCalled()
})
});
});