Skip to content
This repository has been archived by the owner on Mar 8, 2021. It is now read-only.

Commit

Permalink
adding a couple more test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
tymondesigns committed Apr 13, 2015
1 parent c81f2d6 commit d549d04
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 9 deletions.
11 changes: 8 additions & 3 deletions dist/angular-locker.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,15 @@
};

/**
* The driver instance
*
* @type {Storage}
*/
this._driver = this._resolveDriver(options.driver);

/**
* The namespace value
*
* @type {String}
*/
this._namespace = options.namespace;
Expand Down Expand Up @@ -289,8 +293,8 @@
if (! this._checkSupport()) _error('The browser does not support localStorage');

if (! this._exists(key)) return false;
this._driver.removeItem(this._getPrefix(key));

this._driver.removeItem(this._getPrefix(key));
this._event('locker.item.forgotten', { key: key });

return true;
Expand Down Expand Up @@ -334,11 +338,12 @@
*
* @param {Mixed} key
* @param {Mixed} value
* @param {Mixed} def
* @return {Boolean}
*/
add: function (key, value) {
add: function (key, value, def) {
if (! this.has(key)) {
this.put(key, value);
this.put(key, value, def);
return true;
}

Expand Down
2 changes: 1 addition & 1 deletion dist/angular-locker.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/angular-locker.min.js.map

Large diffs are not rendered by default.

11 changes: 8 additions & 3 deletions src/angular-locker.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,15 @@
};

/**
* The driver instance
*
* @type {Storage}
*/
this._driver = this._resolveDriver(options.driver);

/**
* The namespace value
*
* @type {String}
*/
this._namespace = options.namespace;
Expand Down Expand Up @@ -289,8 +293,8 @@
if (! this._checkSupport()) _error('The browser does not support localStorage');

if (! this._exists(key)) return false;
this._driver.removeItem(this._getPrefix(key));

this._driver.removeItem(this._getPrefix(key));
this._event('locker.item.forgotten', { key: key });

return true;
Expand Down Expand Up @@ -334,11 +338,12 @@
*
* @param {Mixed} key
* @param {Mixed} value
* @param {Mixed} def
* @return {Boolean}
*/
add: function (key, value) {
add: function (key, value, def) {
if (! this.has(key)) {
this.put(key, value);
this.put(key, value, def);
return true;
}

Expand Down
24 changes: 23 additions & 1 deletion test/spec/angular-locker.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ describe('angular-locker', function () {

it('should switch drivers when chained', function () {
module(function(lockerProvider) {
lockerProvider.defaults.driver = 'local';
lockerProvider.defaults().driver = 'local';
});

inject(function (locker) {
Expand Down Expand Up @@ -701,6 +701,28 @@ describe('angular-locker', function () {
expect( locker.getDriver() ).toEqual($window.localStorage);
expect( locker.driver('session').getDriver() ).toEqual($window.sessionStorage);
}));

it('should return the same instance if driver or namespace not changed', inject(function ($window, locker) {
expect( locker.getDriver() ).toEqual($window.localStorage);

var localInstance1 = locker;
var localInstance2 = locker.driver('local');
var sessionInstance = locker.driver('session');

expect( localInstance1 ).toEqual(localInstance2);
expect( localInstance1 ).not.toEqual(sessionInstance);
}));

it('should return the same instance if driver or namespace not changed', inject(function ($window, locker) {
expect( locker.getNamespace() ).toEqual('locker');

var defaultNamespace1 = locker;
var defaultNamespace2 = locker.namespace('locker');
var fooNamespace = locker.namespace('foo');

expect( defaultNamespace1 ).toEqual(defaultNamespace2);
expect( defaultNamespace2 ).not.toEqual(fooNamespace);
}));
});

});
Expand Down

0 comments on commit d549d04

Please sign in to comment.