-
Notifications
You must be signed in to change notification settings - Fork 167
LG-9449: Configure ArcGIS token job to respect mock geocoder setting #8702
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| module ArcgisApi | ||
| class GeocoderFactory | ||
| def create | ||
| if IdentityConfig.store.arcgis_mock_fallback | ||
| ArcgisApi::Mock::Geocoder.new | ||
| else | ||
| ArcgisApi::Geocoder.new | ||
| end | ||
| end | ||
| end | ||
| end | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,7 @@ | |
| RSpec.describe ArcgisTokenJob, type: :job do | ||
| let(:job) { described_class.new } | ||
| let(:geocoder) { instance_double(ArcgisApi::Geocoder) } | ||
| let(:geocoder_factory) { instance_double(ArcgisApi::GeocoderFactory) } | ||
| let(:analytics) { instance_double(Analytics) } | ||
| describe 'arcgis token job' do | ||
| before do | ||
|
|
@@ -13,7 +14,8 @@ | |
| session: {}, | ||
| sp: nil, | ||
| ).and_return(analytics) | ||
| allow(ArcgisApi::Geocoder).to receive(:new).and_return(geocoder) | ||
| allow(ArcgisApi::GeocoderFactory).to receive(:new).and_return(geocoder_factory) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. bonus to switching to a class/module method: we don't need to stub |
||
| allow(geocoder_factory).to receive(:create).and_return(geocoder) | ||
| end | ||
|
|
||
| it 'fetches token and logs analytics' do | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| require 'rails_helper' | ||
|
|
||
| RSpec.describe ArcgisApi::GeocoderFactory do | ||
| subject(:geocoder_factory) { described_class.new } | ||
| context 'mock is enabled' do | ||
| it 'returns a mock geocoder' do | ||
| expect(IdentityConfig.store).to receive(:arcgis_mock_fallback). | ||
| and_return(true) | ||
| expect(geocoder_factory.create).to be_instance_of(ArcgisApi::Mock::Geocoder) | ||
| end | ||
| end | ||
|
|
||
| context 'mock is disabled' do | ||
| it 'returns a geocoder' do | ||
| expect(IdentityConfig.store).to receive(:arcgis_mock_fallback). | ||
| and_return(false) | ||
| expect(geocoder_factory.create).to be_instance_of(ArcgisApi::Geocoder) | ||
| end | ||
| end | ||
| end |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
proposal:
DocAuthRouterso callsites would look like:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Everything looks good in here. I like this suggestion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a factory pattern, so using
Factoryin the name makes more sense and is more informative to developers who aren't as familiar with this specific codebase. TheRouternaming is confusing because that is normally associated with routing web requests to a controller.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought about making this a module, but based on my prior experience using an instance tends to be more useful and reusable. The decision does seem a little arbitrary without more established conventions around IoC though.