diff --git a/app/controllers/forecasts_controller.rb b/app/controllers/forecasts_controller.rb index dc722fd3..32f808e6 100644 --- a/app/controllers/forecasts_controller.rb +++ b/app/controllers/forecasts_controller.rb @@ -48,9 +48,9 @@ def forecast_for_day(day, forecasts) end def zone - return Zone.default unless params[:zone] - - Zone.find_by(name: params[:zone]) + Zone.find_by!(name: params[:zone]) + rescue ActiveRecord::RecordNotFound + Zone.default end def date diff --git a/spec/controllers/forecasts_controller_spec.rb b/spec/controllers/forecasts_controller_spec.rb index aeedec25..667077b5 100644 --- a/spec/controllers/forecasts_controller_spec.rb +++ b/spec/controllers/forecasts_controller_spec.rb @@ -3,7 +3,6 @@ let(:barnet) { double("Barnet") } before do - allow(Zone).to receive(:find_by).and_return(barnet) allow(Zone).to receive(:default).and_return(central_london) allow(CercForecastService).to receive(:latest_forecasts_for).and_return(forecasts) end @@ -23,7 +22,9 @@ context "when zone IS given" do it "obtains forecasts for the given zone from the CercForecastService" do - get :show, params: {zone: double} + allow(Zone).to receive(:find_by).and_return(barnet) + + get :show, params: {zone: "Barnet"} expect(CercForecastService).to have_received(:latest_forecasts_for).with(barnet) end