-
Notifications
You must be signed in to change notification settings - Fork 87
Enhancement: Cache array, object, gradual feeding #402
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,76 @@ describe('RMPackerCache', function() { | |
}); | ||
})); | ||
|
||
describe('feed', function() { | ||
|
||
it('shouldnt fail if packer not initialized', function() { | ||
expect(function() { | ||
packerCache.feed("test", []); | ||
}).not.toThrow(); | ||
}); | ||
|
||
it('should feed data if passed as array at start', function() { | ||
packerCache.feed('bikes', [ { id: 1, model: 'Meta' }, { id: 2, model: 'Slash' } ]); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Line is too long. |
||
var bike = packerCache.resolve(Bike.$new(1)); | ||
expect(bike.model).toEqual('Meta'); | ||
}); | ||
|
||
it('should feed data if passed as object at start', function() { | ||
packerCache.feed('bikes', { id: 3, model: 'Mango' }); | ||
var bike = packerCache.resolve(Bike.$new(3)); | ||
expect(bike.model).toEqual('Mango'); | ||
}); | ||
|
||
it('should feed array is passed after array', function() { | ||
packerCache.feed('bikes', [ { id: 4, model: 'Apple' }, { id: 5, model: 'Mango' } ]); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Line is too long. |
||
packerCache.feed('bikes', [ { id: 6, model: 'Banana' }, { id: 7, model: 'Dates' } ]); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Line is too long. |
||
var bike = packerCache.resolve(Bike.$new(4)), | ||
bike2 = packerCache.resolve(Bike.$new(6)); | ||
expect(bike.model).toEqual('Apple'); | ||
expect(bike2.model).toEqual('Banana'); | ||
}); | ||
|
||
it('should feed object is passed after array', function() { | ||
packerCache.feed('bikes', [ { id: 8, model: 'Apple' }, { id: 9, model: 'Mango' } ]); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Line is too long. |
||
packerCache.feed('bikes', { id: 10, model: 'Banana' }); | ||
var bike = packerCache.resolve(Bike.$new(8)), | ||
bike2 = packerCache.resolve(Bike.$new(10)); | ||
expect(bike.model).toEqual('Apple'); | ||
expect(bike2.model).toEqual('Banana'); | ||
}); | ||
|
||
it('should feed array is passed after object', function() { | ||
packerCache.feed('bikes', { id: 11, model: 'Banana' }); | ||
packerCache.feed('bikes', [ { id: 12, model: 'Apple' }, { id: 13, model: 'Mango' } ]); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Line is too long. |
||
var bike = packerCache.resolve(Bike.$new(12)), | ||
bike2 = packerCache.resolve(Bike.$new(11)); | ||
expect(bike.model).toEqual('Apple'); | ||
expect(bike2.model).toEqual('Banana'); | ||
}); | ||
|
||
it('should feed object is passed after object', function() { | ||
packerCache.feed('bikes', { id: 14, model: 'Apple' }); | ||
packerCache.feed('bikes', { id: 15, model: 'Banana' }); | ||
var bike = packerCache.resolve(Bike.$new(14)), | ||
bike2 = packerCache.resolve(Bike.$new(15)); | ||
expect(bike.model).toEqual('Apple'); | ||
expect(bike2.model).toEqual('Banana'); | ||
}); | ||
|
||
it('should resolve with latest object fed', function() { | ||
packerCache.feed('bikes', { id: 16, model: 'Apple' }); | ||
packerCache.feed('bikes', { id: 16, model: 'Banana' }); | ||
var bike = packerCache.resolve(Bike.$new(16)); | ||
expect(bike.model).toEqual('Banana'); | ||
}); | ||
|
||
it('should return false if passed data is invalid', function() { | ||
var ret = packerCache.feed('bikes', "Invalid"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Mixed double and single quotes. |
||
expect(ret).toEqual(false); | ||
}); | ||
|
||
}); | ||
|
||
describe('restore', function() { | ||
|
||
it('shouldnt fail if packer not initialized', function() { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mixed double and single quotes.