Merge lp:~cjwatson/launchpad/fix-bug-picker-search into lp:launchpad

Proposed by Colin Watson on 2015-10-19
Status: Merged
Merged at revision: 17827
Proposed branch: lp:~cjwatson/launchpad/fix-bug-picker-search
Merge into: lp:launchpad
Diff against target: 50 lines (+19/-4)
2 files modified
lib/lp/bugs/javascript/bug_picker.js (+5/-1)
lib/lp/bugs/javascript/tests/test_bug_picker.js (+14/-3)
To merge this branch: bzr merge lp:~cjwatson/launchpad/fix-bug-picker-search
Reviewer Review Type Date Requested Status
William Grant code 2015-10-19 Approve on 2015-10-19
Review via email: mp+274910@code.launchpad.net

Commit Message

Fix the bug picker to pass the bug ID as a number, not a string.

Description of the Change

Fix the bug picker to pass the bug ID as a number, not a string.

r17816 regressed this; I incorrectly adjusted the test rather than making sure the code continued to pass a number. All of the other tests changed in the same revision were for code that really was passing a string of some kind, so are correct.

To post a comment you must log in.
William Grant (wgrant) :
review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/bugs/javascript/bug_picker.js'
2--- lib/lp/bugs/javascript/bug_picker.js 2015-10-13 11:07:08 +0000
3+++ lib/lp/bugs/javascript/bug_picker.js 2015-10-19 15:51:26 +0000
4@@ -130,7 +130,11 @@
5 * @protected
6 */
7 _find_bug: function(data) {
8- var bug_id = Y.Lang.trim(data.id);
9+ var bug_id = parseInt(Y.Lang.trim(data.id), 10);
10+ if (isNaN(bug_id)) {
11+ this.set('error', 'Please enter a valid bug number.');
12+ return;
13+ }
14 var qs_data
15 = Y.lp.client.append_qs("", "ws.accept", "application.json");
16 qs_data = Y.lp.client.append_qs(qs_data, "ws.op", "getBugData");
17
18=== modified file 'lib/lp/bugs/javascript/tests/test_bug_picker.js'
19--- lib/lp/bugs/javascript/tests/test_bug_picker.js 2015-10-13 11:07:08 +0000
20+++ lib/lp/bugs/javascript/tests/test_bug_picker.js 2015-10-19 15:51:26 +0000
21@@ -20,7 +20,7 @@
22 this.mockio.last_request.url);
23 var expected_data =
24 'ws.accept=application.json&ws.op=getBugData&' +
25- 'bug_id=%22' + bug_id + '%22';
26+ 'bug_id=' + bug_id;
27 if (Y.Lang.isValue(LP.cache.bug)) {
28 var bug_uri = encodeURIComponent('api/devel/bugs/1');
29 expected_data += '&related_bug=%22' + bug_uri + '%22';
30@@ -73,8 +73,19 @@
31 Y.one('.yui3-picker-search').set('value', '');
32 Y.one('.lazr-search').simulate('click');
33 Y.Assert.isNull(this.mockio.last_request);
34- this._assert_error_display(
35- 'Please enter a valid bug number.');
36+ this._assert_error_display('Please enter a valid bug number.');
37+ this._assert_form_state(false);
38+ },
39+
40+ // Attempt to enter a non-number and an error is displayed.
41+ test_bug_id_not_a_number: function() {
42+ this.widget = this._createWidget();
43+ Y.one('.pick-bug').simulate('click');
44+ this.mockio.last_request = null;
45+ Y.one('.yui3-picker-search').set('value', 'some-string');
46+ Y.one('.lazr-search').simulate('click');
47+ Y.Assert.isNull(this.mockio.last_request);
48+ this._assert_error_display('Please enter a valid bug number.');
49 this._assert_form_state(false);
50 },
51