Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ensure correct precedence in concatenated sql clauses #144

Merged
merged 1 commit into from
Sep 21, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 19 additions & 4 deletions spec/Providers/FeatureLayerSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ describe('L.esri.Geosearch.FeatureLayer', function () {
]
});

it('should get suggestions based on text', function (done) {
it('should query based on text', function (done) {
var request = provider.suggestions('Pla', null, function (error, results) {
expect(results.length).to.equal(2);
expect(results[0].text).to.equal('Place 1');
Expand All @@ -115,7 +115,7 @@ describe('L.esri.Geosearch.FeatureLayer', function () {
request.respond(200, { 'Content-Type': 'text/plain; charset=utf-8' }, sampleQueryResponse);
});

it('should use bounds to get suggestions', function (done) {
it('should incorporate bounds in queries', function (done) {
var request = provider.suggestions('Pla', L.latLngBounds([[0, 0], [100, 100]]), function (error, results) {
expect(results.length).to.equal(2);
expect(results[0].text).to.equal('Place 1');
Expand All @@ -130,7 +130,7 @@ describe('L.esri.Geosearch.FeatureLayer', function () {
request.respond(200, { 'Content-Type': 'text/plain; charset=utf-8' }, sampleQueryResponse);
});

it('should geocode with a magic key', function (done) {
it('should query with a magic key', function (done) {
var request = provider.results('Place 1', '1', null, function (error, results) {
expect(results[0].latlng.lat).to.equal(45.48);
expect(results[0].latlng.lng).to.equal(-122.81);
Expand All @@ -143,7 +143,7 @@ describe('L.esri.Geosearch.FeatureLayer', function () {
request.respond(200, { 'Content-Type': 'text/plain; charset=utf-8' }, sampleObjectQuery);
});

it('should geocode for partial text', function (done) {
it('should query for partial text', function (done) {
var request = provider.suggestions('Pla', null, function (error, results) {
expect(results.length).to.equal(2);
expect(results[0].text).to.equal('Place 1');
Expand All @@ -157,4 +157,19 @@ describe('L.esri.Geosearch.FeatureLayer', function () {
request.respond(200, { 'Content-Type': 'text/plain; charset=utf-8' }, sampleQueryResponse);
});

it('should honor a filter on the feature layer', function (done) {
provider.options.where = "foo='bar'";
var request = provider.suggestions('Pla', null, function (error, results) {
expect(results.length).to.equal(2);
expect(results[0].text).to.equal('Place 1');
expect(results[0].magicKey).to.equal(1);
done();
});

expect(request.url).to.contain('http://example.com/arcgis/arcgis/rest/services/MockService/0/query');
expect(request.url).to.contain("where=foo%3D\'bar\'%20AND%20(upper(%22Name%22)%20LIKE%20upper('%25Pla%25'))");

request.respond(200, { 'Content-Type': 'text/plain; charset=utf-8' }, sampleQueryResponse);
});

});
2 changes: 1 addition & 1 deletion src/Providers/FeatureLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export var FeatureLayerProvider = FeatureLayerService.extend({
}

if (this.options.where) {
return this.options.where + ' AND ' + queryString.join(' OR ');
return this.options.where + ' AND (' + queryString.join(' OR ') + ')';
} else {
return queryString.join(' OR ');
}
Expand Down