Skip to content
Browse files

Abstracted bool to integer conversion into the storage module

  • Loading branch information...
1 parent 1ad3074 commit a32143ba625a5dc5fa86b9f47a0aa7d408be5277 @danielstocks committed Aug 9, 2012
View
4 spec/jquery.collapse_spec.coffee
@@ -329,9 +329,9 @@ describe "jQuery Collapse", ->
it "should write to storage that the third item was opened", ->
@jq.open(2)
- expect(@jq.db.write).toHaveBeenCalledWith(2,1)
+ expect(@jq.db.write).toHaveBeenCalledWith(2,true)
it "should write to storage that the third item was closed", ->
@jq.close(2)
- expect(@jq.db.write).toHaveBeenCalledWith(2,0)
+ expect(@jq.db.write).toHaveBeenCalledWith(2,false)
View
8 spec/jquery.collapse_storage_spec.coffee
@@ -15,21 +15,21 @@ describe 'jQuery Collapse Storage', ->
expect(@storage.data).toBeArray()
it 'should set the data array to five zero-values', ->
- @storage.write(4,0)
+ @storage.write(4,false)
expect(@storage.data).toEqual [0,0,0,0,0]
it 'should set the 3:rd value in array to 1', ->
- @storage.write(2,1)
+ @storage.write(2,true)
expect(@storage.data).toEqual [0,0,1]
it 'should write stringified array to storage backend', ->
- @storage.write(4,1)
+ @storage.write(4,true)
arg = JSON.stringify("xyz" : [0,0,0,0,1])
expect(@storage.db.setItem).toHaveBeenCalledWith("jQuery-Collapse", arg)
it 'should re-save previously written items from storage', ->
@stub(@storage.db, 'getItem').returns('{ "abc" : [1] }')
- @storage.write(1,0)
+ @storage.write(1,false)
obj =
"abc": [1]
"xyz": [0,0]
View
2 src/jquery.collapse.js
@@ -121,7 +121,7 @@
_this.$details.attr("aria-hidden", state == "close");
_this.parent.$el.trigger(state, _this);
if(_this.parent.db) {
- _this.parent.db.write(_this._index(), state == "open" ? 1 : 0);
+ _this.parent.db.write(_this._index(), _this.isOpen);
}
}
}
View
2 src/jquery.collapse_storage.js
@@ -21,7 +21,7 @@
Storage.prototype = {
write: function(position, state) {
var _this = this;
- _this.data[position] = state;
+ _this.data[position] = state ? 1 : 0;
// Pad out data array with zero values
$.each(_this.data, function(i) {
if(typeof _this.data[i] == 'undefined') {

0 comments on commit a32143b

Please sign in to comment.
Something went wrong with that request. Please try again.