-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #305 from projectblacklight/bad_range_limit_params
bad query params to #range_limit action should not result in uncaught exception
- Loading branch information
Showing
2 changed files
with
70 additions
and
0 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
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,61 @@ | ||
require 'spec_helper' | ||
|
||
RSpec.describe CatalogController, type: :controller do | ||
# Note that ActionController::BadRequest is caught by rails and turned into a 400 | ||
# response, and ActionController::RoutingError is caught by raisl and turned into 404 | ||
describe "bad params" do | ||
let (:facet_field) { "pub_date_si" } | ||
|
||
it "without start param present raise BadRequest " do | ||
expect { | ||
get :range_limit, params: { | ||
"range_field"=> facet_field, | ||
"range_start"=>"1931" | ||
} | ||
}.to raise_error(ActionController::BadRequest) | ||
end | ||
|
||
it "without end param raise BadRequest " do | ||
expect { | ||
get :range_limit, params: { | ||
"range_field"=> facet_field, | ||
"range_start"=>"1931" | ||
} | ||
}.to raise_error(ActionController::BadRequest) | ||
end | ||
|
||
it "without either boundary raise BadRequest" do | ||
expect { | ||
get :range_limit, params: { | ||
"range_field"=> facet_field, | ||
} | ||
}.to raise_error(ActionController::BadRequest) | ||
end | ||
|
||
it "without a range_field raise RoutingError" do | ||
expect { | ||
get :range_limit, params: {} | ||
}.to raise_error(ActionController::RoutingError) | ||
end | ||
|
||
it "with params out of order raise BadRequest" do | ||
expect { | ||
get :range_limit, params: { | ||
"range_field"=> facet_field, | ||
"range_start"=>"1940", | ||
"range_end"=>"1930" | ||
} | ||
}.to raise_error(ActionController::BadRequest) | ||
end | ||
|
||
it "with one of the params is an array raise BadRequest" do | ||
expect { | ||
get :range_limit, params: { | ||
"range_field"=> facet_field, | ||
"range_start"=>"1931", | ||
"range_end"=>["1940"] | ||
} | ||
}.to raise_error(ActionController::BadRequest) | ||
end | ||
end | ||
end |