Skip to content
This repository was archived by the owner on Jan 15, 2023. It is now read-only.

Commit

Permalink
Disabled geocoding by default, and made the gem an optional dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
ankane committed Aug 13, 2021
1 parent fd15169 commit a4777a7
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 8 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 0.4.0 (unreleased)

- Disabled geocoding by default
- Made the `geocoder` gem an optional dependency

## 0.3.1 (2021-03-03)

- Added `--lockbox` option to install generator
Expand Down
3 changes: 3 additions & 0 deletions app/jobs/auth_trail/geocode_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ def perform(login_activity)
result =
begin
Geocoder.search(login_activity.ip).first
rescue NameError
# geocoder gem not installed
raise
rescue => e
Rails.logger.info "Geocode failed: #{e.message}"
nil
Expand Down
1 change: 0 additions & 1 deletion authtrail.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,4 @@ Gem::Specification.new do |spec|
spec.add_dependency "railties", ">= 5.2"
spec.add_dependency "activerecord", ">= 5.2"
spec.add_dependency "warden"
spec.add_dependency "geocoder"
end
3 changes: 1 addition & 2 deletions lib/authtrail.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# dependencies
require "geocoder"
require "warden"

# modules
Expand All @@ -11,7 +10,7 @@ module AuthTrail
class << self
attr_accessor :exclude_method, :geocode, :track_method, :identity_method, :job_queue, :transform_method
end
self.geocode = true
self.geocode = false
self.identity_method = lambda do |request, opts, user|
if user
user.try(:email)
Expand Down
4 changes: 2 additions & 2 deletions lib/generators/authtrail/templates/initializer.rb.tt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# set to true for geocoding
# we recommend configuring local geocoding first
# set to true for geocoding (and add the geocoder gem to your Gemfile)
# we recommend configuring local geocoding as well
# see https://github.com/ankane/authtrail#geocoding
AuthTrail.geocode = false

Expand Down
13 changes: 10 additions & 3 deletions test/authtrail_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,10 @@ def test_track_method_error
end

def test_geocode_true
assert_enqueued_with(job: AuthTrail::GeocodeJob, queue: "default") do
post user_session_url, params: {user: {email: "[email protected]", password: "secret"}}
with_options(geocode: true) do
assert_enqueued_with(job: AuthTrail::GeocodeJob, queue: "default") do
post user_session_url, params: {user: {email: "[email protected]", password: "secret"}}
end
end
end

Expand All @@ -81,8 +83,13 @@ def test_geocode_false
end
end

def test_geocode_default
post user_session_url, params: {user: {email: "[email protected]", password: "secret"}}
assert_equal 0, enqueued_jobs.size
end

def test_job_queue
with_options(job_queue: :low_priority) do
with_options(geocode: true, job_queue: :low_priority) do
assert_enqueued_with(job: AuthTrail::GeocodeJob, queue: "low_priority") do
post user_session_url, params: {user: {email: "[email protected]", password: "secret"}}
end
Expand Down

0 comments on commit a4777a7

Please sign in to comment.