Skip to content

Commit

Permalink
Don't let encoded geodata near elasticsearch
Browse files Browse the repository at this point in the history
  • Loading branch information
mlandauer committed Aug 1, 2024
1 parent 938fb49 commit 5dc51b9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
6 changes: 5 additions & 1 deletion app/models/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ class Application < ApplicationRecord
def search_data
# lat and lon need to be symbols (rather than strings) in search_data
# to get valid data come through searchkick for some reason
attributes.symbolize_keys.merge(location: { lat:, lon: lng })
r = attributes.symbolize_keys.merge(location: { lat:, lon: lng })
# lonlat is encoded geo data and elasticsearch is unhappy to index this. So skip it.
# We're capturing the geodata anyway via the "location" key
r.delete(:lonlat)
r
end

# For the benefit of kaminari. Also sets the maximum number of
Expand Down
6 changes: 6 additions & 0 deletions spec/models/application_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -213,4 +213,10 @@
it { expect(application.official_submission_period_expired?).to be false }
end
end

describe "#search_data" do
it "does not try indexing the geo data directly because elasticsearch can't handle this" do
expect(create(:geocoded_application).search_data).not_to have_key(:lonlat)
end
end
end

0 comments on commit 5dc51b9

Please sign in to comment.