-
Notifications
You must be signed in to change notification settings - Fork 166
Bring back ahoy gem to track visits #803
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| Ahoy.mount = false | ||
| Ahoy.throttle = false | ||
| # Period of inactivity before a new visit is created | ||
| Ahoy.visit_duration = 30.minutes | ||
|
|
||
| module Ahoy | ||
| class Store < Ahoy::Stores::LogStore | ||
| end | ||
| end |
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,20 +9,23 @@ | |
| } | ||
| end | ||
|
|
||
| let(:ahoy) { instance_double(FakeAhoyTracker) } | ||
|
|
||
| before { allow(FakeAhoyTracker).to receive(:new).and_return(ahoy) } | ||
|
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. if we stubbed |
||
|
|
||
| describe '#track_event' do | ||
| it 'identifies the user and sends the event to the backend' do | ||
| user = build_stubbed(:user, uuid: '123') | ||
|
|
||
| analytics = Analytics.new(user, FakeRequest.new) | ||
|
|
||
| analytics_hash = { | ||
| event: 'Trackable Event', | ||
| properties: {}, | ||
| event_properties: {}, | ||
| user_id: user.uuid | ||
| } | ||
|
|
||
| expect(ANALYTICS_LOGGER).to receive(:info). | ||
| with(analytics_hash.merge(request_attributes)) | ||
| expect(ahoy).to receive(:track). | ||
| with('Trackable Event', analytics_hash.merge(request_attributes)) | ||
|
|
||
| analytics.track_event('Trackable Event') | ||
| end | ||
|
|
@@ -34,13 +37,12 @@ | |
| analytics = Analytics.new(current_user, FakeRequest.new) | ||
|
|
||
| analytics_hash = { | ||
| event: 'Trackable Event', | ||
| properties: {}, | ||
| event_properties: {}, | ||
| user_id: tracked_user.uuid | ||
| } | ||
|
|
||
| expect(ANALYTICS_LOGGER).to receive(:info). | ||
| with(analytics_hash.merge(request_attributes)) | ||
| expect(ahoy).to receive(:track). | ||
| with('Trackable Event', analytics_hash.merge(request_attributes)) | ||
|
|
||
| analytics.track_event('Trackable Event', user_id: tracked_user.uuid) | ||
| end | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| class FakeAhoyTracker | ||
|
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. I am not opposed to this strategy, but it probably makes sense to have a test that confirms that As is, I can imagine a scenario in which the ahoy lib requires new/different args for |
||
| def track(_name, _properties = {}, _options = {}) | ||
| # no-op | ||
| end | ||
| end | ||
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.
@zachmargolis I know you had made a comment about this technique in a previous PR, where you suggested to use
stub_constin tests, but it caused the tests to fail and caused me some head scratching due to an error message that didn't make sense and included the Ahoy gem in the stack trace.The problem was that I was stubbing
FakeAhoyTrackerforAhoy::Tracker, and because I didn't have aninitializemethod defined inFakeAhoyTracker, it complained about wrong number of arguments, pointing to Ahoy's controller initializer. It said 1 argument was passed, but 0 were expected. That didn't make sense becauseAhoy::Trackerclearly accepts arguments. Finally it dawned on me that the tests were usingFakeAhoyTracker, and stubbing the const meant that I had to implement all the methods called by the real class in my fake class.The whole point of the fake class is so that the tests use that class and only that class, and it shouldn't be necessary to implement all the methods from the real class in the fake class. I don't want the tests to touch the real class at all, which is why I prefer this way of doing it.
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.
Yeah that seems fair enough, would we have to implement all the methods or just a no-op
initialize?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.
Alternatively, we could do a
double().as_null_object? But up to you!