Sha256: 4c446e5a2cca83dbc09d90b830b4a93d92ad72a6b088621e3879069d5f5d5f31
Contents?: true
Size: 1.75 KB
Versions: 2
Compression:
Stored size: 1.75 KB
Contents
describe "Joosy.Resource.RESTCollection", -> class Test extends Joosy.Resource.REST @entity 'test' data = '[{"id": 1, "name": "test1"}, {"id": 2, "name": "test2"}]' checkData = (collection) -> expect(collection.data.length).toEqual 2 expect(collection.data[0].constructor == Test).toBeTruthy() expect(collection.data[0].e.name).toEqual 'test1' spoofData = (server) -> target = server.requests.last() expect(target.method).toEqual 'GET' expect(target.url).toMatch /^\/tests\/\?(page=\d+&)?_=\d+/ target.respond 200, 'Content-Type': 'application/json', data beforeEach -> @server = sinon.fakeServer.create() @collection = new Joosy.Resource.RESTCollection(Test) afterEach -> @server.restore() it "should fetch", -> @collection.fetch() spoofData @server checkData @collection it "should paginate", -> @collection.fetch() spoofData @server checkData @collection @collection.page 2, callback=sinon.spy() spoofData @server expect(callback.callCount).toEqual 1 expect(@collection.data.length).toEqual 2 expect(@collection.data[0].constructor == Test).toBeTruthy() expect(@collection.data[0].e.name).toEqual 'test1' # Again from cache @collection.page 2, callback=sinon.spy() spoofData @server expect(callback.callCount).toEqual 1 expect(@collection.data.length).toEqual 2 expect(@collection.data[0].constructor == Test).toBeTruthy() expect(@collection.data[0].e.name).toEqual 'test1' it "should trigger changes", -> @collection.bind 'changed', callback = sinon.spy() @collection.fetch() spoofData @server expect(callback.callCount).toEqual 1 @collection.page 2 spoofData @server expect(callback.callCount).toEqual 2
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
joosy-0.1.0.RC3 | spec/javascripts/joosy/core/resource/rest_collection_spec.js.coffee |
joosy-0.1.0.RC2 | spec/javascripts/joosy/core/resource/rest_collection_spec.js.coffee |