Skip to content

Commit

Permalink
Merge pull request #1420 from MushroomObserver/jdc-allow-county-18444…
Browse files Browse the repository at this point in the history
…9491

Allow city + county
  • Loading branch information
JoeCohen authored Mar 15, 2023
2 parents 4b3e8a7 + 2c1893f commit c1f5262
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 27 deletions.
19 changes: 0 additions & 19 deletions app/models/location.rb
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,6 @@ def self.dubious_name?(name, provide_reasons = false, check_db = true)
unless check_db && location_exists(name)
reasons += check_for_empty_name(name)
reasons += check_for_dubious_commas(name)
reasons += check_for_dubious_county(name)
reasons += check_for_bad_country_or_state(name)
reasons += check_for_bad_terms(name)
reasons += check_for_bad_chars(name)
Expand All @@ -551,14 +550,6 @@ def self.check_for_dubious_commas(name)
[:location_dubious_commas.l]
end

def self.check_for_dubious_county(name)
return [] if name.blank?
return [] if /Forest,|Park,|near /.match?(name)
return [] unless has_dubious_county?(name)

[:location_dubious_redundant_county.l]
end

def self.check_for_bad_country_or_state(name)
reasons = []
return [] if name.blank?
Expand Down Expand Up @@ -650,16 +641,6 @@ def self.dubious_country?(name)
!understood_country?(country(name))
end

def self.has_dubious_county?(name)
tokens = name.split(", ")
return if tokens.length < 2

alt = [tokens[0]]
tokens[1..].each { |t| alt.push(t) if t[-4..] != " Co." }
result = alt.join(", ")
result == name ? nil : result
end

def self.fix_country(name)
c = country(name)
name[0..(name.rindex(c) - 1)] + COUNTRY_FIXES[c]
Expand Down
1 change: 0 additions & 1 deletion config/locales/en.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1715,7 +1715,6 @@
location_dubious_bad_term: For consistency, we prefer '[good]' instead of '[bad]'.
location_dubious_commas: All commas should be followed by a space and another word
location_dubious_empty: Empty location given
location_dubious_redundant_county: County may not be required in this name; for greatest consistency we prefer that you not include the county for towns and cities.
location_dubious_redundant_state: Both '[state]' and '[country]' are on the list of countries and continents. A common mistake is to include the continent in addition to the country; this is unnecessary.
location_dubious_unknown_country: Unknown country '[country]'
location_dubious_unknown_state: Unrecognized state or province '[state]' for '[country]'.
Expand Down
8 changes: 4 additions & 4 deletions test/controllers/observations_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1940,24 +1940,24 @@ def test_construct_observation_dubious_place_names
generic_construct_observation({
observation: { place_name: where },
naming: { name: "Unknown" }
}, 0, 0, 0)
}, 1, 0, 0)
where = "USA, California, Los Angeles Co., Burbank"
generic_construct_observation({
observation: { place_name: where },
naming: { name: "Unknown" }
}, 0, 0, 0, roy)
}, 1, 0, 0, roy)

# Test mix of city and county
where = "Falmouth, Barnstable Co., Massachusetts, USA"
generic_construct_observation({
observation: { place_name: where },
naming: { name: "Unknown" }
}, 0, 0, 0)
}, 1, 0, 0)
where = "USA, Massachusetts, Barnstable Co., Falmouth"
generic_construct_observation({
observation: { place_name: where },
naming: { name: "Unknown" }
}, 0, 0, 0, roy)
}, 1, 0, 0, roy)

# Test some bad terms
where = "Some County, Ohio, USA"
Expand Down
8 changes: 6 additions & 2 deletions test/integration/rails-dom-testing/post_observation_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def submit_location_form_with_errors
submit_form_with_changes(create_location_form_first_changes,
/create/i, "#location_form")
assert_template(CREATE_LOCATION_TEMPLATE)
assert_has_location_warning(/County may not be required/)
assert_has_location_warning(/Contains unexpected character/)
assert_form_has_correct_values(
create_location_form_values_after_first_changes
)
Expand Down Expand Up @@ -341,7 +341,10 @@ def create_location_form_defaults

def create_location_form_first_changes
{
"location_display_name" => "Pasadena, Some Co., California, USA",

# "location_display_name" => "({[;:|]}), California, USA",
"location_display_name" =>
"Pasadena: Disneyland, Some Co., California, USA",
"location_high" => 8765,
"location_low" => 4321,
"location_notes" => "oops"
Expand All @@ -350,6 +353,7 @@ def create_location_form_first_changes

def create_location_form_second_changes
{
"location_display_name" => "Pasadena, Some Co., California, USA",
"location_high" => 5678,
"location_low" => 1234,
"location_notes" => "Notes for location"
Expand Down
2 changes: 1 addition & 1 deletion test/models/location_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ def test_dubious_name
bad_location("USA, North America")
bad_location("San Francisco, USA")
bad_location("San Francisco, CA, USA")
bad_location("San Francisco, San Francisco Co., California, USA")
# bad_location("Tilden Park, California, USA") - can't detect
# bad_location("Tilden Park, Kensington, California, USA") - can't detect
bad_location("Albis Mountain Range, Zurich area, Switzerland")
Expand All @@ -38,6 +37,7 @@ def test_dubious_name
good_location("Earth")
good_location("North America")
good_location("San Francisco, California, USA")
good_location("San Francisco, San Francisco Co., California, USA")
good_location("Tilden Park, Contra Costa Co., California, USA")
good_location("Albis Mountain Range, near Zurich, Switzerland")
good_location("Southern California, USA")
Expand Down

0 comments on commit c1f5262

Please sign in to comment.