diff options
author | James Lal <james@lightsofapollo.com> | 2012-09-19 11:32:01 -0700 |
---|---|---|
committer | James Lal <james@lightsofapollo.com> | 2012-09-19 11:32:01 -0700 |
commit | e5aaf7365f2b0ea0160357e5e1a4ee47379d372a (patch) | |
tree | 14251e6aee59d1b0b82a3e9fe7070d21ed3603a5 | |
parent | 0cac01e4243b112f3c0820c89d9de2bf38005c79 (diff) | |
download | jsCalDAV-e5aaf7365f2b0ea0160357e5e1a4ee47379d372a.tar.gz |
add #hasProp, #removeProp from Request.Propfind closes #4
-rw-r--r-- | lib/caldav/request/propfind.js | 31 | ||||
-rw-r--r-- | test/caldav/request/propfind_test.js | 5 |
2 files changed, 35 insertions, 1 deletions
diff --git a/lib/caldav/request/propfind.js b/lib/caldav/request/propfind.js index e54b669..e731b98 100644 --- a/lib/caldav/request/propfind.js +++ b/lib/caldav/request/propfind.js @@ -46,6 +46,37 @@ this._props.push(this.template.tag(tagDesc, attr, content)); }, + /** + * Removes property from request. + * Must use same arguments as 'prop' to remove prop. + * + * @param {String|Array} tagDesc tag description. + * @param {Object} [attr] optional tag attrs. + * @param {Obj} [content] optional content. + */ + removeProp: function(tagDesc, attr, content) { + var prop = this.template.tag(tagDesc, attr, content); + var idx = this._props.indexOf(prop); + + if (idx !== -1) { + this._props.splice(idx, 1); + return true; + } + return false; + }, + + /** + * Checks if prop has been added to the request. + * + * @param {String|Array} tagDesc tag description. + * @param {Object} [attr] optional tag attrs. + * @param {Obj} [content] optional content. + */ + hasProp: function(tagDesc, attr, content) { + var prop = this.template.tag(tagDesc, attr, content); + return this._props.indexOf(prop) !== -1; + }, + _createPayload: function() { var content = this.template.tag('prop', this._props.join('')); return this.template.render(content); diff --git a/test/caldav/request/propfind_test.js b/test/caldav/request/propfind_test.js index 58677f4..d38cb5a 100644 --- a/test/caldav/request/propfind_test.js +++ b/test/caldav/request/propfind_test.js @@ -51,12 +51,15 @@ suite('caldav/request/propfind', function() { assert.equal(subject.xhr.method, 'PROPFIND'); }); - test('#prop', function() { + test('#(has|remove)prop', function() { var expected = subject.template.tag('test'); subject.prop('test'); assert.deepEqual(subject._props, [expected]); + assert.isTrue(subject.hasProp('test'), 'has prop'); + subject.removeProp('test'); + assert.isFalse(subject.hasProp('test'), 'removed prop'); }); test('.depth', function() { |