Skip to content

Commit

Permalink
Fallback to the default zone when a zone can't be found
Browse files Browse the repository at this point in the history
Previously we would only use the default if no parameter was give. If a parameter was a given that didn't match any zone, we return an empty result and this would cause problems.

We now default to the default zone when a zone cannot be found.
  • Loading branch information
jdudley1123 committed Nov 26, 2024
1 parent e5efaa8 commit 9cf92cd
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
6 changes: 3 additions & 3 deletions app/controllers/forecasts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions spec/controllers/forecasts_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 9cf92cd

Please sign in to comment.