Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

drop functionality from the view to leave just bare loading

  • Loading branch information...
commit 7594af8c86aaa20821f588e52aedd9477d641b3a 1 parent 82f5085
@petrjanda authored
Showing with 0 additions and 174 deletions.
  1. +0 −174 spec/viewSpec.js
View
174 spec/viewSpec.js
@@ -1,6 +1,4 @@
var util = require('util'),
- couchdb = require('../lib/repository/couchRepository').createRepository(),
- repository = require('../lib/repository').getInstance(),
storage = require('../lib/storage/couchStorage').createStorage(),
View = require('../lib/view');
@@ -8,20 +6,12 @@ describe('View', function() {
var view, MyView;
beforeEach(function() {
- repository.strategy = couchdb;
-
MyView = function(callback) {
View.call(this, 'myview', 'foo', callback);
-
- this.snapshots = true;
}
util.inherits(MyView, View);
- spyOn(repository, 'getEventsByName').andCallFake(function(names, from, callback) {
- callback([]);
- });
-
view = new MyView();
})
@@ -31,149 +21,6 @@ describe('View', function() {
})
})
- describe('.build', function() {
-
- describe('with disabled storage', function() {
- it('should directly call getEventsByName', function() {
- view.snapshots = false;
-
- view.build();
-
- expect(repository.getEventsByName).toHaveBeenCalledWith( 'foo', 1, jasmine.any(Function) );;
- })
- })
-
- it('should load data from storage', function() {
- spyOn(storage, 'loadView');
- view.uid = '45fsgs45gh';
-
- view.build();
-
- expect(storage.loadView).toHaveBeenCalledWith('45fsgs45gh', jasmine.any(Function));
- })
-
- describe('with explicit storage ofload', function() {
- it('should directly call getEventsByName', function() {
- spyOn(storage, 'loadView');
- view.uid = '45fsgs45gh';
-
- view.build(true);
-
- expect(storage.loadView).not.toHaveBeenCalled();
- })
- })
-
- describe('callback', function() {
-
- beforeEach(function() {
- spyOn(storage, 'loadView').andCallFake(function(uid, callback) {
- callback({
- uid : 'f8s7h5dggs',
- lastEvent : 1325721336913,
- data : { foo : 'bar' }
- })
- })
- })
-
- it('should store data to the view', function() {
- view.build();
-
- expect(view.data).toEqual({ foo : 'bar' })
- })
-
- it('should store data to the view', function() {
- view.build();
-
- expect(view.lastEvent).toEqual(1325721336913);
- })
-
-
- it('should load events increment data from repository', function() {
- view.build();
-
- expect(repository.getEventsByName).toHaveBeenCalledWith( 'foo', 1325721336914, jasmine.any(Function) );
- })
-
-
- it( 'should call apply, for all events', function() {
- var event = {foo: 'bar'};
-
- spyOn(view, 'apply');
- repository.getEventsByName.andCallFake(function(names, from, callback) {
- callback([event]);
- });
-
- view.build();
-
- expect( view.apply ).toHaveBeenCalledWith( event, jasmine.any(Function) );
- })
-
- describe( 'snapshooting', function() {
- var event = {foo: 'bar'};
-
- beforeEach(function() {
- spyOn(view, 'apply').andCallFake(function(event, callback) {
- callback()
- });
-
- spyOn(storage, 'purgeView');
- spyOn(storage, 'storeView');
- })
-
- function fakeGetEvents(events) {
- repository.getEventsByName.andCallFake(function(names, from, callback) {
- callback(events);
- });
- }
-
- describe( 'with events increment', function() {
- it( 'should store view if events increment was loaded', function() {
- fakeGetEvents([event]);
-
- view.build();
-
- expect( storage.storeView ).toHaveBeenCalledWith(view);
- })
-
- it( 'should store view if events increment was loaded', function() {
- fakeGetEvents([event]);
-
- view.build();
-
- expect( storage.purgeView ).toHaveBeenCalledWith(view.uid);
- })
- })
-
-
- it( 'should not store view if no events were loaded', function() {
- fakeGetEvents([]);
-
- view.build();
-
- expect( storage.storeView ).not.toHaveBeenCalledWith(view);
- })
-
- it( 'should not store view if snapshooting is disabled', function() {
- fakeGetEvents([event]);
- view.snapshots = false;
-
- view.build();
-
- expect( storage.storeView ).not.toHaveBeenCalled();
- })
- })
-
- it( 'should call callback if specified', function() {
- this.handler = function() {}
- spyOn( this, 'handler')
-
- view.build(this.handler);
-
- expect( this.handler ).toHaveBeenCalled();
- })
- })
- })
-
describe('.load', function() {
it('should load data from storage', function() {
@@ -231,25 +78,4 @@ describe('View', function() {
})
})
-
- describe('.apply', function() {
-
- it('should call raise error if handler is missing', function() {
- var event = {name: 'myEvent'};
-
- expect(function(){ view.apply(event) }).toThrow('There is no handler for \'MyEvent\' event!');
- })
-
- it('shoud call appropriate handler', function() {
- var event = {name: 'myEvent'},
- f = function() {};
-
- MyView.prototype.onMyEvent = function() {}
- spyOn(view, 'onMyEvent');
-
- view.apply(event, f);
-
- expect(view.onMyEvent).toHaveBeenCalledWith(event, f);
- })
- })
})
Please sign in to comment.
Something went wrong with that request. Please try again.