Skip to content

Commit

Permalink
[#2807] Fix an issue in the autocomplete module
Browse files Browse the repository at this point in the history
Turns out that select2 calls query when loading the page. Now we
check that we have a valid object. Updated unit tests to reflect this.
  • Loading branch information
aron committed Aug 6, 2012
1 parent 38f824b commit 9a6d0be
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
4 changes: 3 additions & 1 deletion ckan/public/base/javascript/modules/autocomplete.js
Expand Up @@ -228,7 +228,9 @@ this.ckan.module('autocomplete', function (jQuery, _) {
* Returns nothing.
*/
_onQuery: function (options) {
this.lookup(options.term, options.callback);
if (options) {
this.lookup(options.term, options.callback);
}
},

/* Called when a key is pressed. If the key is a comma we block it and
Expand Down
6 changes: 6 additions & 0 deletions ckan/public/base/test/spec/modules/autocomplete.spec.js
Expand Up @@ -272,6 +272,12 @@ describe('ckan.modules.AutocompleteModule()', function () {
assert.called(target);
assert.calledWith(target, 'term', 'callback');
});

it('should do nothing if there is no options object', function () {
var target = sinon.stub(this.module, 'lookup');
this.module._onQuery();
assert.notCalled(target);
});
});

describe('._onKeydown(event)', function () {
Expand Down

0 comments on commit 9a6d0be

Please sign in to comment.