Skip to content
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

Rename login_url method to login_url_with_optional_shop to avoid ambiguity with Rails' route helper method of the same name #585

Merged
merged 2 commits into from
Jul 2, 2019

Conversation

swalkinshaw
Copy link
Contributor

login_url potentially conflicts with Rails' route helper methods which are auto generated. Since this engine defines a login route, login_url would be the generated method.

While this doesn't cause problems in normal use cases, if the same route is defined in the main app's route to point to a customized sessions controller (for example), the route helper method login_url will take precedence causing redirects to happen without the shop param.

ie:

Rails.application.routes.draw do
  get 'login', to: 'sessions#new', as: :login

  mount ShopifyApp::Engine, at: '/'
end

Even though this is guarding against an uncommon edge case, there's no reason to keep the conflicting method name.

This simply renames it to login_url_with_optional_shop.

NOTE: I guess this is a potentially breaking change if anyone had overridden login_url previously even though it's a protected method.

Copy link
Member

@Hammadk Hammadk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense. Unfortunately, a ton of apps use protected methods so this will be a breaking change for some folks.

Should this be a major version change?

Putting this here so it's top of mind, but I would love for us to move away from protected methods all together.

@vfonic
Copy link
Contributor

vfonic commented May 3, 2018

I've also hit this issue: Issue with login_url being redefined #552

I'd love to see this change. Maybe in v9.

Copy link
Contributor

@chrisbutcher chrisbutcher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, and I agree about the bump to 9.0

@vfonic
Copy link
Contributor

vfonic commented May 27, 2019

I've again spent several days tracking down this issue. Can you please merge it? That would be really appreciated!
This PR was submitted more than a year ago...

@chrisbutcher
Copy link
Contributor

I'll rebase and ship this today.

@swalkinshaw swalkinshaw requested a review from a team as a code owner May 27, 2019 14:46
@chrisbutcher chrisbutcher removed the request for review from jamiemtdwyer May 27, 2019 14:50
@chrisbutcher
Copy link
Contributor

cc: @Hammadk @EiNSTeiN- Can I get another quick review of this PR?

Copy link
Contributor

@EiNSTeiN- EiNSTeiN- left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@chrisbutcher
Copy link
Contributor

👋 @Shopify/platform-dev-tools-education Can I also get another review from one of you?

Copy link
Contributor

@nwtn nwtn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good. @chrisbutcher lmk if you need me to 🎩, otherwise feel free to merge.

+1 to doing a major release for this. there may be some other breaking changes we can bundle in with a release this week

@chrisbutcher
Copy link
Contributor

chrisbutcher commented May 27, 2019

Thanks @nwtn !

lmk if you need me to 🎩

Actually, that would be super helpful, if you don't mind :)

@vfonic
Copy link
Contributor

vfonic commented May 27, 2019

Thanks guys for getting back on this right away! 👍

Edit: I guess the major version bump is to v10 now.

@chrisbutcher chrisbutcher changed the title Rename login_url method Rename login_url method to login_url_with_optional_shop May 27, 2019
@chrisbutcher chrisbutcher changed the title Rename login_url method to login_url_with_optional_shop Rename login_url method to login_url_with_optional_shop to avoid ambiguity with Rails' route helper method of the same name May 27, 2019
@chrisbutcher
Copy link
Contributor

@swalkinshaw would like to get another PR merged into shopify_app alongside this change before we bump major gem versions

Copy link
Contributor

@nwtn nwtn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎩✔️

@vfonic
Copy link
Contributor

vfonic commented Jul 1, 2019

I was really hoping this change got merged into the new major version bump... :(

swalkinshaw and others added 2 commits July 2, 2019 12:22
`login_url` potentially conflicts with Rails' route helper methods which
are auto generated. Since this engine defines a `login` route,
`login_url` would be the generated method.

While this doesn't cause problems in normal use cases, if the same route
is defined in the main app's route to point to a customized sessions
controller (for example), the route helper method `login_url` will take
precedence causing redirects to happen *without* the `shop` param.

ie:

```ruby
Rails.application.routes.draw do
  get 'login', to: 'sessions#new', as: :login

  mount ShopifyApp::Engine, at: '/'
end
```

Even though this is guarding against an uncommon edge case, there's no
reason to keep the conflicting method name.

This simply renames it to `login_url_with_optional_shop`.
@chrisbutcher chrisbutcher merged commit 84184b6 into master Jul 2, 2019
@chrisbutcher chrisbutcher deleted the rename-login-url-method branch July 2, 2019 18:34
@chrisbutcher chrisbutcher temporarily deployed to rubygems July 3, 2019 14:49 Inactive
@vfonic
Copy link
Contributor

vfonic commented Jul 3, 2019

I just saw this got merged in v11. Wow! Thank you so much, for making a major version bump just for this PR! I really appreciate it! ❤️ 🎉

@chrisbutcher
Copy link
Contributor

No worries! Sorry it slipped from our list of changes to include in v10 :)

@ric2b
Copy link

ric2b commented Apr 1, 2020

Could this be documented in the README as a breaking change when upgrading to v11? It's only mentioned in the changelog.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants