Initial removal of geocoding, need to remove db

This commit is contained in:
Eric Schultz 2021-02-03 19:18:07 -06:00 committed by Eric Schultz
parent d47c80594c
commit 825feea620
15 changed files with 2 additions and 111 deletions

View file

@ -24,7 +24,6 @@ gem 'sprockets', '~> 3.7'
# Helpers
gem 'chronic', '~> 0.10.2' # For nat lang parsing of dates
gem 'countries', '~> 3.0'
gem 'geocoder', '~> 1.6.3' # for adding latitude and longitude to location-based tables http://www.rubygeocoder.com/
gem 'i18n-js', '~> 3.8', git: 'https://github.com/houdiniproject/i18n-js.git', branch: 'houdini-tweaks'
gem 'lograge', '~> 0.11.2' # make logging less terrible in rails
gem 'nearest_time_zone', '~> 0.0.4' # for detecting timezone from lat/lng https://github.com/buytruckload/nearest_time_zone

View file

@ -168,7 +168,6 @@ GEM
ffi (1.14.2)
font_assets (0.1.14)
rack
geocoder (1.6.4)
globalid (0.4.2)
activesupport (>= 4.2.0)
hamster (3.0.0)
@ -434,7 +433,6 @@ DEPENDENCIES
factory_bot_rails (~> 5.0, >= 5.0.2)
fast_blank
font_assets (~> 0.1.14)
geocoder (~> 1.6.3)
hamster (~> 3.0)
heroku-deflater (~> 0.6.3)
houdini_full_contact!

View file

@ -9,13 +9,6 @@ class MapsController < ApplicationController
before_action :authenticate_super_associate!, only: :all_supporters
before_action :authenticate_nonprofit_user!, only: %i[all_npo_supporters specific_npo_supporters]
# used on admin/nonprofits_map and front page
def all_npos
respond_to do |format|
format.html { redirect_to :root }
format.json { @map_data = Nonprofit.where('latitude IS NOT NULL').last(1000) }
end
end
# used on admin/supporters_map
def all_supporters

View file

@ -62,7 +62,7 @@ class Event < ApplicationRecord
has_many :comments, as: :host, dependent: :destroy
has_many :activities, as: :host, dependent: :destroy
geocoded_by :full_address
accepts_nested_attributes_for :ticket_levels, allow_destroy: true
has_one_attached :main_image
@ -94,8 +94,6 @@ class Event < ApplicationRecord
self
end
after_validation :geocode
after_create do
user = profile.user
Role.create(name: :event_editor, user_id: user.id, host: self)

View file

@ -34,8 +34,6 @@ class Nonprofit < ApplicationRecord
# :published, # boolean; whether to display this profile
# :vetted, # bool: Whether a super admin (one of CommitChange's employees) have approved this org
# :verification_status, # str (either 'pending', 'unverified', 'escalated', 'verified' -- whether the org has submitted the identity verification form and it has been approved)
# :latitude, # float: geocoder gem
# :longitude, # float: geocoder gem
# :timezone, # str
# :address, # text
# :thank_you_note, # text
@ -126,7 +124,7 @@ class Nonprofit < ApplicationRecord
serialize :achievements, Array
serialize :categories, Array
geocoded_by :full_address
before_validation(on: :create) do
set_slugs

View file

@ -75,18 +75,6 @@ class Supporter < ApplicationRecord
end
end
geocoded_by :full_address
reverse_geocoded_by :latitude, :longitude do |obj, results|
geo = results.first
if geo # absorb zip code automatically
obj.zip_code = geo.postal_code if obj.zip_code.blank?
obj.state_code = geo.state_code if obj.state_code.blank?
obj.city = geo.city if obj.city.blank?
obj.address = geo.address if obj.address.blank?
obj.country = geo.country if obj.country.blank?
end
end
def profile_picture(size = :normal)
return unless profile

View file

@ -26,8 +26,6 @@ class User < ApplicationRecord
# :profile_attributes,
# :phone
geocoded_by :location
devise :async, :database_authenticatable, :registerable, :confirmable, :recoverable, :rememberable, :trackable, :validatable
attr_accessor :offsite_donation_id, :current_password
@ -94,11 +92,6 @@ class User < ApplicationRecord
raw
end
def geocode!
# self.geocode
# self.save
end
def to_builder(*expand)
Jbuilder.new do |json|
json.object "user"

View file

@ -1,11 +0,0 @@
# frozen_string_literal: true
# License: AGPL-3.0-or-later WITH WTO-AP-3.0-or-later
# Full license explanation at https://github.com/houdiniproject/houdini/blob/master/LICENSE
Geocoder.configure(
cache: Rails.cache,
lookup: Rails.env == 'test' ? :test : :google,
use_https: true,
api_key: ENV['GOOGLE_API_KEY'],
timeout: 10
)

View file

@ -1,47 +0,0 @@
# frozen_string_literal: true
# License: AGPL-3.0-or-later WITH WTO-AP-3.0-or-later
# Full license explanation at https://github.com/houdiniproject/houdini/blob/master/LICENSE
module GeocodeModel
def self.supporter(id)
supp = Supporter.find_by_id(id)
with_reverse(supp) if supp.address && supp.state_code && supp.city
end
# Just a wrapper around a model's geocode method for delaying with:
# GeocodeModel.delay.geocode(user)
def self.geocode(model)
begin
model.geocode
rescue Exception => e
puts e
end
model.save
model
end
def self.with_reverse(model)
begin
model.geocode
model.reverse_geocode
rescue Exception => e
puts e
end
model.save
model
end
# Geocode and get the timezone for a model
def self.with_timezone(model)
begin
geocode(model)
rescue Exception => e
puts e
end
return model unless model.latitude && model.longitude
model.timezone = NearestTimeZone.to(model.latitude, model.longitude)
model.save
model
end
end

View file

@ -5,7 +5,6 @@
module UpdateSupporter
def self.from_info(supporter, params)
supporter.update(params)
# GeocodeModel.delay.geocode(supporter)
supporter
end

View file

@ -181,7 +181,6 @@ describe InsertDuplicate do
before(:each) do
set_event_start_time(dates[:ten_days_from_now], dates[:ten_days_from_now_plus_4_hours])
allow_any_instance_of(Event).to receive(:geocode).and_return(nil)
end
let(:event) do

View file

@ -6,7 +6,6 @@ require 'rails_helper'
describe UpdateTickets do
let(:ticket) do
allow_any_instance_of(Event).to receive(:geocode).and_return([1, 1])
create(:ticket, :has_card, :has_event)
end

View file

@ -73,16 +73,4 @@ RSpec.configure do |config|
config.include Devise::Test::ControllerHelpers, type: :controller
config.include Devise::Test::IntegrationHelpers, type: :request
config.include RSpec::Rails::RequestExampleGroup, type: :request, file_path: %r{spec/api}
Geocoder::Lookup::Test.set_default_stub(
[
{
'coordinates' => [44.2876041,-88.4671082],
'address' => 'Appleton, WI, USA',
'state' => 'Appleton',
'state_code' => 'WI',
'country' => 'United States',
'country_code' => 'US'
}
]
)
end

View file

@ -20,11 +20,9 @@ RSpec.shared_context :shared_donation_charge_context do
let(:campaign) { force_create(:campaign, nonprofit: nonprofit, goal_amount: 500) }
let(:other_campaign) { force_create(:campaign, nonprofit: other_nonprofit) }
let(:event) do
allow_any_instance_of(Event).to receive(:geocode).and_return([1, 1])
force_create(:event, nonprofit: nonprofit)
end
let(:other_event) do
allow_any_instance_of(Event).to receive(:geocode).and_return([1, 1])
force_create(:event, nonprofit: other_nonprofit)
end
let(:event_discount) { force_create(:event_discount, event: event, percent: 20) }

View file

@ -22,7 +22,6 @@ RSpec.shared_context :shared_rd_donation_value_context do
let(:default_edit_token) { '7903e34c-10fe-11e8-9ead-d302c690bee4' }
before(:each) do
allow_any_instance_of(Event).to receive(:geocode).and_return([1, 1])
end
def generate_expected(donation_id, payment_id, charge_id, card, supporter, nonprofit, stripe_charge_id, data = {})