diff --git a/app/controllers/availability_controller.rb b/app/controllers/availability_controller.rb index 18e2448c7..83e50c6f1 100644 --- a/app/controllers/availability_controller.rb +++ b/app/controllers/availability_controller.rb @@ -15,6 +15,6 @@ def redirect_bots end def redirect_no_ids - render json: [] unless params[:ids].present? + render json: [] unless Array(params[:ids]).compact_blank.present? end end diff --git a/app/services/live_lookup.rb b/app/services/live_lookup.rb index e664eb81f..ffbbff2c4 100644 --- a/app/services/live_lookup.rb +++ b/app/services/live_lookup.rb @@ -6,7 +6,7 @@ class LiveLookup delegate :as_json, :to_json, to: :records def initialize(ids) - @ids = [ids].flatten.compact + @ids = Array(ids).compact_blank end # Uses the LiveLookup service specified by Settings.live_lookup_service diff --git a/spec/controllers/availability_controller_spec.rb b/spec/controllers/availability_controller_spec.rb index 3082782cb..1c497040b 100644 --- a/spec/controllers/availability_controller_spec.rb +++ b/spec/controllers/availability_controller_spec.rb @@ -19,6 +19,14 @@ end end + describe "with a blank ID" do + it "should render a blank JSON array w/o making a live lookup request" do + expect(LiveLookup).not_to receive(:new) + get :index, params: { ids: [''] } + expect(response.body).to eq '[]' + end + end + describe "with IDs" do let(:lookup) { double('new') } let(:json) { [{ a: 'a', b: 'b' }] }