test/unit/angularjs/rails/extensions/snapshotsSpec.js in angularjs-rails-resource-2.2.2 vs test/unit/angularjs/rails/extensions/snapshotsSpec.js in angularjs-rails-resource-2.3.0
- old
+ new
@@ -25,16 +25,16 @@
it('should store all keys', function () {
var book, data = {id: 1, $key: '1234', name: 'The Winds of Winter'};
book = new Book(data);
expect(book.snapshot()).toBe(0);
- expect(book.$snapshots).toBeDefined();
- expect(book.$snapshots.length).toBe(1);
- expect(book.$snapshots[0].$snapshots).toBeUndefined();
+ expect(book.$$snapshots).toBeDefined();
+ expect(book.$$snapshots.length).toBe(1);
+ expect(book.$$snapshots[0].$$snapshots).toBeUndefined();
expect(book).toEqualData(data);
- expect(book.$snapshots[0].$key).toBe('1234');
- expect(book.$snapshots[0]).toEqualData(data);
+ expect(book.$$snapshots[0].$key).toBe('1234');
+ expect(book.$$snapshots[0]).toEqualData(data);
});
it('should store deep copy', function () {
var book, data = {
id: 1,
@@ -47,13 +47,13 @@
};
book = new Book(data);
book.snapshot();
- expect(book.$snapshots[0].author).toBeDefined();
- expect(book.$snapshots[0].author.id).toBe(1);
- expect(book.$snapshots[0]).toEqualData(data);
+ expect(book.$$snapshots[0].author).toBeDefined();
+ expect(book.$$snapshots[0].author.id).toBe(1);
+ expect(book.$$snapshots[0]).toEqualData(data);
});
it('should store multiple snapshots', function () {
var book, data = {id: 1, $key: '1234', name: 'The Winds of Winter'};
book = new Book(data);
@@ -61,15 +61,15 @@
book.$key = '1235';
expect(book.snapshot()).toBe(1);
book.$key = '1236';
expect(book.snapshot()).toBe(2);
- expect(book.$snapshots).toBeDefined();
- expect(book.$snapshots.length).toBe(3);
- expect(book.$snapshots[0].$key).toBe('1234');
- expect(book.$snapshots[1].$key).toBe('1235');
- expect(book.$snapshots[2].$key).toBe('1236');
+ expect(book.$$snapshots).toBeDefined();
+ expect(book.$$snapshots.length).toBe(3);
+ expect(book.$$snapshots[0].$key).toBe('1234');
+ expect(book.$$snapshots[1].$key).toBe('1235');
+ expect(book.$$snapshots[2].$key).toBe('1236');
});
it('should rollback single version', function () {
var book, data = {id: 1, $key: '1234', name: 'The Winds of Winter'};
book = new Book(data);
@@ -78,12 +78,12 @@
book.snapshot();
book.$key = '1236';
book.rollback();
expect(book.$key).toBe('1235');
- expect(book.$snapshots).toBeDefined();
- expect(book.$snapshots.length).toBe(1);
+ expect(book.$$snapshots).toBeDefined();
+ expect(book.$$snapshots.length).toBe(1);
});
it('should rollback deep copy', function () {
var book, data = {
id: 1,
@@ -140,17 +140,17 @@
book.snapshot();
book.$key = '1236';
book.rollback();
expect(book.$key).toBe('1235');
- expect(book.$snapshots).toBeDefined();
- expect(book.$snapshots.length).toBe(1);
+ expect(book.$$snapshots).toBeDefined();
+ expect(book.$$snapshots.length).toBe(1);
book.rollback();
expect(book.$key).toBe('1234');
- expect(book.$snapshots).toBeDefined();
- expect(book.$snapshots.length).toBe(0);
+ expect(book.$$snapshots).toBeDefined();
+ expect(book.$$snapshots.length).toBe(0);
});
it('should rollback specified number of versions', function () {
var book, data = {id: 1, $key: '1234', name: 'The Winds of Winter'};
@@ -162,12 +162,12 @@
book.snapshot();
book.$key = '1237';
book.rollback(2);
expect(book.$key).toBe('1235');
- expect(book.$snapshots).toBeDefined();
- expect(book.$snapshots.length).toBe(1);
+ expect(book.$$snapshots).toBeDefined();
+ expect(book.$$snapshots.length).toBe(1);
});
it('should not change resource on rollback if no snapshots saved', function () {
var book, data = {id: 1, $key: '1234', name: 'The Winds of Winter'};
book = new Book(data);
@@ -186,12 +186,12 @@
book.$key = '1236';
book.snapshot();
book.rollback(-1);
expect(book.$key).toBe('1234');
- expect(book.$snapshots).toBeDefined();
- expect(book.$snapshots.length).toBe(0);
+ expect(book.$$snapshots).toBeDefined();
+ expect(book.$$snapshots.length).toBe(0);
});
it('should roll back to the first snapshot when versions exceeds available snapshots', function () {
var book, data = {id: 1, $key: '1234', name: 'The Winds of Winter'};
book = new Book(data);
@@ -201,12 +201,12 @@
book.$key = '1236';
book.snapshot();
book.rollback(1000);
expect(book.$key).toBe('1234');
- expect(book.$snapshots).toBeDefined();
- expect(book.$snapshots.length).toBe(0);
+ expect(book.$$snapshots).toBeDefined();
+ expect(book.$$snapshots.length).toBe(0);
});
it('should roll back to version in middle', function () {
var book, data = {id: 1, $key: '1234', name: 'The Winds of Winter'};
book = new Book(data);
@@ -216,12 +216,12 @@
book.$key = '1236';
book.snapshot();
book.rollbackTo(1);
expect(book.$key).toBe('1235');
- expect(book.$snapshots).toBeDefined();
- expect(book.$snapshots.length).toBe(1);
+ expect(book.$$snapshots).toBeDefined();
+ expect(book.$$snapshots.length).toBe(1);
});
it('should roll back to first version', function () {
var book, data = {id: 1, $key: '1234', name: 'The Winds of Winter'};
book = new Book(data);
@@ -231,12 +231,12 @@
book.$key = '1236';
book.snapshot();
book.rollbackTo(0);
expect(book.$key).toBe('1234');
- expect(book.$snapshots).toBeDefined();
- expect(book.$snapshots.length).toBe(0);
+ expect(book.$$snapshots).toBeDefined();
+ expect(book.$$snapshots.length).toBe(0);
});
it('should roll back to last version when version exceeds available versions', function () {
var book, data = {id: 1, $key: '1234', name: 'The Winds of Winter'};
book = new Book(data);
@@ -247,12 +247,12 @@
book.snapshot();
book.$key = '1237';
book.rollbackTo(100);
expect(book.$key).toBe('1236');
- expect(book.$snapshots).toBeDefined();
- expect(book.$snapshots.length).toBe(2);
+ expect(book.$$snapshots).toBeDefined();
+ expect(book.$$snapshots.length).toBe(2);
});
it('should reset snapshots on create', function () {
var book, data = {$key: '1234', name: 'The Winds of Winter'};
book = new Book(data);
@@ -262,12 +262,12 @@
$httpBackend.expectPOST('/books').respond(200, {book: {id: 1}});
book.save();
$httpBackend.flush();
expect(book.$key).toBe('1235');
- expect(book.$snapshots).toBeDefined();
- expect(book.$snapshots.length).toBe(0);
+ expect(book.$$snapshots).toBeDefined();
+ expect(book.$$snapshots.length).toBe(0);
});
it('should be able to save after rollback', function () {
var book, data = {$key: '1234', name: 'The Winds of Winter'};
book = new Book(data);
@@ -278,14 +278,34 @@
$httpBackend.expectPOST('/books').respond(200, {book: {id: 1}});
book.save();
$httpBackend.flush();
expect(book.$key).toBe('1234');
- expect(book.$snapshots).toBeDefined();
- expect(book.$snapshots.length).toBe(0);
+ expect(book.$$snapshots).toBeDefined();
+ expect(book.$$snapshots.length).toBe(0);
});
+ it('should not submit $$snapshots', function () {
+ var book, data = {id: 1, $key: '1234', name: 'The Winds of Winter'};
+ book = new Book(data);
+ book.snapshot();
+ book.$key = '1235';
+
+ $httpBackend.whenPUT('/books/1', function(putData) {
+ var json = JSON.parse(putData);
+ expect(json.book.$$snapshots).toBeUndefined();
+ return true;
+ }).respond(200, {book: {id: 1}});
+
+ book.save();
+ $httpBackend.flush();
+
+ expect(book.$key).toBe('1235');
+ expect(book.$$snapshots).toBeDefined();
+ expect(book.$$snapshots.length).toBe(0);
+ });
+
it('should reset snapshots on update', function () {
var book, data = {id: 1, $key: '1234', name: 'The Winds of Winter'};
book = new Book(data);
book.snapshot();
book.$key = '1235';
@@ -293,12 +313,12 @@
$httpBackend.expectPUT('/books/1').respond(200, {book: {id: 1}});
book.save();
$httpBackend.flush();
expect(book.$key).toBe('1235');
- expect(book.$snapshots).toBeDefined();
- expect(book.$snapshots.length).toBe(0);
+ expect(book.$$snapshots).toBeDefined();
+ expect(book.$$snapshots.length).toBe(0);
});
it('should reset snapshots on delete', function () {
var book, data = {id: 1, $key: '1234', name: 'The Winds of Winter'};
book = new Book(data);
@@ -308,12 +328,12 @@
$httpBackend.expectDELETE('/books/1').respond(200, {book: {id: 1}});
book.delete();
$httpBackend.flush();
expect(book.$key).toBe('1235');
- expect(book.$snapshots).toBeDefined();
- expect(book.$snapshots.length).toBe(0);
+ expect(book.$$snapshots).toBeDefined();
+ expect(book.$$snapshots.length).toBe(0);
});
it('should call rollback callback on rollback', function () {
var book, callbackCalled = false, data = {id: 1, $key: '1234', name: 'The Winds of Winter'};
book = new Book(data);
@@ -395,11 +415,11 @@
book = new Book(data);
book.snapshot();
book.author.name = 'George Orwell';
- expect(book.$snapshots[0].author).not.toBeDefined();
+ expect(book.$$snapshots[0].author).not.toBeDefined();
expect(book.author).toEqualData({id: 1, name: 'George Orwell'});
book.rollback();
// should still be George Orwell since it wasn't snapshotted
expect(book.author).toEqualData({id: 1, name: 'George Orwell'});
@@ -433,11 +453,11 @@
book = new Book(data);
book.snapshot();
book.$key = '1235';
book.author.name = 'George Orwell';
- expect(book.$snapshots[0].author).toBeDefined();
- expect(book.$snapshots[0].$key).not.toBeDefined();
+ expect(book.$$snapshots[0].author).toBeDefined();
+ expect(book.$$snapshots[0].$key).not.toBeDefined();
expect(book.$key).toBe('1235');
expect(book.author).toEqualData({id: 1, name: 'George Orwell'});
book.rollback();
// should be 1235 since it wasn't snapshotted
\ No newline at end of file