diff --git a/Gemfile b/Gemfile index 15eb04b8..fc99cc76 100755 --- a/Gemfile +++ b/Gemfile @@ -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 diff --git a/Gemfile.lock b/Gemfile.lock index 29eba437..e6accd8d 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -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! diff --git a/app/controllers/maps_controller.rb b/app/controllers/maps_controller.rb index 3c1dd0ce..478a53b0 100644 --- a/app/controllers/maps_controller.rb +++ b/app/controllers/maps_controller.rb @@ -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 diff --git a/app/models/event.rb b/app/models/event.rb index 6ed1bb22..78dbfaec 100644 --- a/app/models/event.rb +++ b/app/models/event.rb @@ -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) diff --git a/app/models/nonprofit.rb b/app/models/nonprofit.rb index c06a1c89..f2aca7f2 100755 --- a/app/models/nonprofit.rb +++ b/app/models/nonprofit.rb @@ -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 diff --git a/app/models/supporter.rb b/app/models/supporter.rb index 610c2448..371df250 100644 --- a/app/models/supporter.rb +++ b/app/models/supporter.rb @@ -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 diff --git a/app/models/user.rb b/app/models/user.rb index 9fdb48d7..dc5ab0de 100755 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -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" diff --git a/config/initializers/geocode.rb b/config/initializers/geocode.rb deleted file mode 100644 index 2795e6b8..00000000 --- a/config/initializers/geocode.rb +++ /dev/null @@ -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 -) \ No newline at end of file diff --git a/lib/geocode_model.rb b/lib/geocode_model.rb deleted file mode 100644 index 1dd3e939..00000000 --- a/lib/geocode_model.rb +++ /dev/null @@ -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 diff --git a/lib/update/update_supporter.rb b/lib/update/update_supporter.rb index ffad5f61..d8a6fef5 100644 --- a/lib/update/update_supporter.rb +++ b/lib/update/update_supporter.rb @@ -5,7 +5,6 @@ module UpdateSupporter def self.from_info(supporter, params) supporter.update(params) - # GeocodeModel.delay.geocode(supporter) supporter end diff --git a/spec/lib/insert/insert_duplicate_spec.rb b/spec/lib/insert/insert_duplicate_spec.rb index dc591b0c..c6cb4592 100644 --- a/spec/lib/insert/insert_duplicate_spec.rb +++ b/spec/lib/insert/insert_duplicate_spec.rb @@ -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 diff --git a/spec/lib/update/update_tickets_spec.rb b/spec/lib/update/update_tickets_spec.rb index c441c91f..a91d9dba 100644 --- a/spec/lib/update/update_tickets_spec.rb +++ b/spec/lib/update/update_tickets_spec.rb @@ -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 diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index 73ab6956..cb2d2756 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -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 diff --git a/spec/support/contexts/shared_donation_charge_context.rb b/spec/support/contexts/shared_donation_charge_context.rb index e8162143..37197be6 100644 --- a/spec/support/contexts/shared_donation_charge_context.rb +++ b/spec/support/contexts/shared_donation_charge_context.rb @@ -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) } diff --git a/spec/support/contexts/shared_rd_donation_value_context.rb b/spec/support/contexts/shared_rd_donation_value_context.rb index 64c6eb3c..0071dd78 100644 --- a/spec/support/contexts/shared_rd_donation_value_context.rb +++ b/spec/support/contexts/shared_rd_donation_value_context.rb @@ -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 = {})