-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
allow rails 4 and 5 params in wms layer
- Loading branch information
1 parent
475a086
commit 1ce58f8
Showing
3 changed files
with
82 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,15 @@ | ||
class WmsController < ApplicationController | ||
def handle | ||
response = Geoblacklight::WmsLayer.new(params).feature_info | ||
response = Geoblacklight::WmsLayer.new(wms_params).feature_info | ||
|
||
respond_to do |format| | ||
format.json { render json: response } | ||
end | ||
end | ||
|
||
private | ||
|
||
def wms_params | ||
params.permit('URL', 'LAYERS', 'BBOX', 'WIDTH', 'HEIGHT', 'QUERY_LAYERS', 'X', 'Y') | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
require 'spec_helper' | ||
|
||
describe Geoblacklight::WmsController, type: :controller do | ||
let(:wms_layer) { instance_double('Geoblacklight::WmsLayer') } | ||
let(:feature_info) { { values: ['fid', 'layer:example'] } } | ||
let(:params) do | ||
{ format: 'json', 'URL' => 'http://www.example.com/', 'LAYERS' => 'layer:example', | ||
'BBOX' => '-74, 40, -68, 43', 'WIDTH' => '500', 'HEIGHT' => '400', | ||
'QUERY_LAYERS' => 'layer:example', 'X' => '277', 'Y' => '195' } | ||
end | ||
|
||
before do | ||
allow(Geoblacklight::WmsLayer).to receive(:new).and_return(wms_layer) | ||
allow(wms_layer).to receive(:feature_info).and_return(feature_info) | ||
end | ||
|
||
describe '#handle' do | ||
it 'returns feature info as json' do | ||
get :handle, params: params | ||
expect(response.body).to eq(feature_info.to_json) | ||
end | ||
end | ||
|
||
describe '#wms_params' do | ||
let(:wms_params) { controller.instance_eval { wms_params } } | ||
|
||
it 'returns only permitted params' do | ||
get :handle, params: params | ||
expect(wms_params.to_h).not_to eq(params) | ||
params.delete(:format) | ||
expect(wms_params.to_h).to eq(params) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters