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

Commit

Permalink
don't append slash to request history #bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
Leonardo Menezes committed Dec 1, 2015
1 parent 2dc6969 commit d3260f3
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 14 deletions.
7 changes: 4 additions & 3 deletions _site/dist/kopf.js
Original file line number Diff line number Diff line change
Expand Up @@ -1842,7 +1842,8 @@ kopf.controller('RestController', ['$scope', '$location', '$timeout',
$scope.editor.setValue(request.body);
};

$scope.addToHistory = function(request) {
$scope.addToHistory = function(path, method, body) {
var request = new Request(path, method, body);
var exists = false;
for (var i = 0; i < $scope.history.length; i++) {
if ($scope.history[i].equals(request)) {
Expand Down Expand Up @@ -1878,8 +1879,8 @@ kopf.controller('RestController', ['$scope', '$location', '$timeout',
path, {}, $scope.request.body,
function(response) {
successCallback(response);
$scope.addToHistory(new Request(path,
$scope.request.method, $scope.request.body));
$scope.addToHistory($scope.request.path,
$scope.request.method, $scope.request.body);
},
function(error, status) {
if (status !== 0) {
Expand Down
7 changes: 4 additions & 3 deletions src/kopf/controllers/rest.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ kopf.controller('RestController', ['$scope', '$location', '$timeout',
$scope.editor.setValue(request.body);
};

$scope.addToHistory = function(request) {
$scope.addToHistory = function(path, method, body) {
var request = new Request(path, method, body);
var exists = false;
for (var i = 0; i < $scope.history.length; i++) {
if ($scope.history[i].equals(request)) {
Expand Down Expand Up @@ -101,8 +102,8 @@ kopf.controller('RestController', ['$scope', '$location', '$timeout',
path, {}, $scope.request.body,
function(response) {
successCallback(response);
$scope.addToHistory(new Request(path,
$scope.request.method, $scope.request.body));
$scope.addToHistory($scope.request.path,
$scope.request.method, $scope.request.body);
},
function(error, status) {
if (status !== 0) {
Expand Down
20 changes: 12 additions & 8 deletions tests/jasmine/rest.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,39 +138,43 @@ describe('RestController', function() {
});

it('to not add duplicates to request to history', function() {
var request = new Request("/test_rest/_search", "POST", "{'uno': 'dos'}");
expect(this.scope.history.length).toEqual(0);
this.scope.addToHistory(request);
this.scope.addToHistory("/test_rest/_search", "POST", "{'uno': 'dos'}");
expect(this.scope.history.length).toEqual(1);
spyOn(localStorage, 'setItem').andReturn(true);
this.scope.addToHistory(request);
this.scope.addToHistory("/test_rest/_search", "POST", "{'uno': 'dos'}");
expect(this.scope.history.length).toEqual(1);
expect(localStorage.setItem).not.toHaveBeenCalled();
});

it('limit history request to 30', function() {
var request = new Request("/test_rest/_search", "POST", "{'uno': 'dos'}");
var history = [];
for (var i = 0; i < 30; i++) {
history.push(new Request("/test_rest/_search", "POST", "{'uno': '" + i + " '}"));
}
this.scope.history = history;
expect(this.scope.history.length).toEqual(30);
this.scope.addToHistory(request);
this.scope.addToHistory("/test_rest/_search", "POST", "{'uno': 'dos'}");
expect(this.scope.history.length).toEqual(30);
expect(this.scope.history[0].equals(request)).toEqual(true);
expect(this.scope.history[0].path).toEqual("/test_rest/_search");
expect(this.scope.history[0].method).toEqual("POST");
expect(this.scope.history[0].body).toEqual("{'uno': 'dos'}");
});

it('executes a correct request', function() {
this.scope.request = new Request("test_rest/_search", "POST", "{'uno': 'dos'}");
this.ElasticService.clusterRequest = function() {};
this.ElasticService.clusterRequest = function(m, p, h, b, success, failure) {
success(new ClusterMapping({}));
};
this.scope.editor = { format: function() { return "{'uno': 'dos'}"; } };
spyOn(this.AlertService, 'warn').andReturn(true);
spyOn(this.scope.editor, 'format').andCallThrough();
spyOn(this.ElasticService, 'clusterRequest').andReturn(true);
spyOn(this.ElasticService, 'clusterRequest').andCallThrough();
spyOn(this.scope, 'addToHistory').andReturn();
this.scope.sendRequest();
expect(this.ElasticService.clusterRequest).toHaveBeenCalledWith("POST", "/test_rest/_search", {}, "{'uno': 'dos'}", jasmine.any(Function), jasmine.any(Function));
expect(this.AlertService.warn).not.toHaveBeenCalled();
expect(this.scope.addToHistory).toHaveBeenCalledWith("test_rest/_search", "POST", "{'uno': 'dos'}");
});

it('executes a request without path', function() {
Expand Down

0 comments on commit d3260f3

Please sign in to comment.