Skip to content

Commit

Permalink
Use abbreviated form for distance because it's well understood and co…
Browse files Browse the repository at this point in the history
…ncise

"m" instead of "metres", "km" instead of "kilometres"
  • Loading branch information
mlandauer committed Sep 23, 2024
1 parent 82818df commit 8766521
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 14 deletions.
6 changes: 3 additions & 3 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,12 @@ def nav_item(url, &block)
def meters_in_words(meters)
if meters < 1000
value = meters.to_f
units = "metre"
units = "m"
else
value = meters / 1000.0
units = "kilometre"
units = "km"
end
pluralize(significant_figure_remove_trailing_zero(value, 2), units)
"#{significant_figure_remove_trailing_zero(value, 2)} #{units}"
end

sig { params(value: Float, sig_figs: Integer).returns(T.untyped) }
Expand Down
6 changes: 3 additions & 3 deletions spec/controllers/api_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -359,19 +359,19 @@
it "finds recent applications near the point" do
get :point, params: { key: key.value, format: "rss", lat: 1.0, lng: 2.0, radius: 4000 }
expect(assigns[:applications]).to eq(result)
expect(assigns[:description]).to eq("Recent applications within 4 kilometres of 1.0,2.0")
expect(assigns[:description]).to eq("Recent applications within 4 km of 1.0,2.0")
end

it "finds recent applications near the point using the old parameter name" do
get :point, params: { key: key.value, format: "rss", lat: 1.0, lng: 2.0, area_size: 4000 }
expect(assigns[:applications]).to eq(result)
expect(assigns[:description]).to eq("Recent applications within 4 kilometres of 1.0,2.0")
expect(assigns[:description]).to eq("Recent applications within 4 km of 1.0,2.0")
end

it "uses a search radius of 2000 when none is specified" do
get :point, params: { key: key.value, format: "rss", lat: 1.0, lng: 2.0 }
expect(assigns[:applications]).to eq(result)
expect(assigns[:description]).to eq("Recent applications within 2 kilometres of 1.0,2.0")
expect(assigns[:description]).to eq("Recent applications within 2 km of 1.0,2.0")
end

it "logs the api call" do
Expand Down
2 changes: 1 addition & 1 deletion spec/features/manage_alerts_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
select("800")
click_on("Update distance")

expect(page).to have_content("Your alert for 24 Bruce Rd, Glenbrook now has a size of 800 metres")
expect(page).to have_content("Your alert for 24 Bruce Rd, Glenbrook now has a size of 800 m")
expect(Alert.active.find_by(address: "24 Bruce Rd, Glenbrook", radius_meters: "800", user: User.find_by(email: "[email protected]"))).not_to be_nil
end
end
14 changes: 7 additions & 7 deletions spec/helpers/application_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,25 @@
describe ApplicationHelper do
describe "#meters_in_words" do
it "converts a distance in metres to simple concise text" do
expect(helper.meters_in_words(2000.0)).to eq("2 kilometres")
expect(helper.meters_in_words(500.0)).to eq("500 metres")
expect(helper.meters_in_words(2000.0)).to eq("2 km")
expect(helper.meters_in_words(500.0)).to eq("500 m")
end

it "rounds distances in km to the nearest 100m" do
expect(helper.meters_in_words(2345.0)).to eq("2.3 kilometres")
expect(helper.meters_in_words(2345.0)).to eq("2.3 km")
end

it "rounds distances in metres to nearest 10m" do
expect(helper.meters_in_words(923.45)).to eq("920 metres")
expect(helper.meters_in_words(923.45)).to eq("920 m")
end

it "rounds distances less than 100 metres to nearest metre" do
expect(helper.meters_in_words(84.23)).to eq("84 metres")
expect(helper.meters_in_words(84.23)).to eq("84 m")
end

it "uses the singular when appropriate" do
expect(helper.meters_in_words(1000.0)).to eq("1 kilometre")
expect(helper.meters_in_words(1.0)).to eq("1 metre")
expect(helper.meters_in_words(1000.0)).to eq("1 km")
expect(helper.meters_in_words(1.0)).to eq("1 m")
end
end

Expand Down

0 comments on commit 8766521

Please sign in to comment.