Updates to ensure new tab is opened for all pledges #200
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.
Resolves #195
Description
This PR is in response to issue #195 which described an issue where a logged in user was not getting a new tab opened to the item's amazon page when they clicked on 'Pledge to Donate' from the home page. After initial review, the issue looked to be much broader in scope - and is described below:
Expected Behavior:
As a user (logged in or not)
When I visit the root page
And click on 'Pledge To Donate'
A new tab is opened with the item's amazon url
And the current page is redirected to the pledges page
Then when I click on 'home'
And click on 'Pledge to Donate'
A new tab is opened with the item's amazon url
And the current page is redirected to the pledges page
Actual Behavior:
As a user (logged in or not)
When I visit the root page
And click on 'Pledge To Donate'
A new tab is opened with the item's amazon url
And the current page is redirected to the pledges page
Then when I click on 'home'
And click on 'Pledge to Donate'
Then the current page is redirected to the pledges page
-- OR --
As a user (logged in or not)
When I visit the root page
And click on 'Pledge To Donate'
A new tab is opened with the item's amazon url
And the current page is redirected to the pledges page
Then when I click on my browser's back button
A new tab is opened with the item's amazon url
And the current page is redirected to the pledges page
As outlined above, the issue is that the expected behavior (a new tab being opened) is only happening the first time the home page is loaded and subsequently, only if the browser's back button is used. The fix should allow for the expected behavior regardless of the user's method of returning to the home page.
This pull request fixes this issue by changing the document ready function in pledges.js to be triggered when turbolinks loads, rather than when the page loads. With turbolinks enabled, the home page is not being fully loaded when the home button is clicked, and so the previous configuration was missing the pickup of the new tab event listener. The change to turbolinks:load from page:load fixes the issue for all users, whether logged in, or not.
Type of change
How Has This Been Tested?
I have user-tested this locally with chrome, firefox and safari with the steps outlined below:
As a guest:
rails server
As a logged in user:
rails server