|
| 1 | +require 'spec_helper' |
| 2 | + |
| 3 | +RSpec.describe CatalogController, type: :controller do |
| 4 | + # Note that ActionController::BadRequest is caught by rails and turned into a 400 |
| 5 | + # response, and ActionController::RoutingError is caught by raisl and turned into 404 |
| 6 | + describe "bad params" do |
| 7 | + let (:facet_field) { "pub_date_si" } |
| 8 | + |
| 9 | + it "without start param present raise BadRequest " do |
| 10 | + expect { |
| 11 | + get :range_limit, params: { |
| 12 | + "range_field"=> facet_field, |
| 13 | + "range_start"=>"1931" |
| 14 | + } |
| 15 | + }.to raise_error(ActionController::BadRequest) |
| 16 | + end |
| 17 | + |
| 18 | + it "without end param raise BadRequest " do |
| 19 | + expect { |
| 20 | + get :range_limit, params: { |
| 21 | + "range_field"=> facet_field, |
| 22 | + "range_start"=>"1931" |
| 23 | + } |
| 24 | + }.to raise_error(ActionController::BadRequest) |
| 25 | + end |
| 26 | + |
| 27 | + it "without either boundary raise BadRequest" do |
| 28 | + expect { |
| 29 | + get :range_limit, params: { |
| 30 | + "range_field"=> facet_field, |
| 31 | + } |
| 32 | + }.to raise_error(ActionController::BadRequest) |
| 33 | + end |
| 34 | + |
| 35 | + it "without a range_field raise RoutingError" do |
| 36 | + expect { |
| 37 | + get :range_limit, params: {} |
| 38 | + }.to raise_error(ActionController::RoutingError) |
| 39 | + end |
| 40 | + |
| 41 | + it "with params out of order raise BadRequest" do |
| 42 | + expect { |
| 43 | + get :range_limit, params: { |
| 44 | + "range_field"=> facet_field, |
| 45 | + "range_start"=>"1940", |
| 46 | + "range_end"=>"1930" |
| 47 | + } |
| 48 | + }.to raise_error(ActionController::BadRequest) |
| 49 | + end |
| 50 | + |
| 51 | + it "with one of the params is an array raise BadRequest" do |
| 52 | + expect { |
| 53 | + get :range_limit, params: { |
| 54 | + "range_field"=> facet_field, |
| 55 | + "range_start"=>"1931", |
| 56 | + "range_end"=>["1940"] |
| 57 | + } |
| 58 | + }.to raise_error(ActionController::BadRequest) |
| 59 | + end |
| 60 | + end |
| 61 | +end |
0 commit comments