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

Store routing context when mounting engine, Fix i18n path #14

Merged
merged 10 commits into from
Mar 8, 2018
Merged

Store routing context when mounting engine, Fix i18n path #14

merged 10 commits into from
Mar 8, 2018

Conversation

grekko
Copy link
Contributor

@grekko grekko commented Mar 3, 2018

Disclaimer: This is just a WIP proposal. I am not really sure where/how its best to store the routing configuration for later re-use. Also this needs a test :) Happy to contribute the test.

I noticed that Passwordless allows users to change the root path of the engine. E.g. from the README:

passwordless_for :users, at: '/', as: :auth

If the root path is changed though, the Mailer.magic_link fails to generate the proper token_sign_in_url.

The same happens e.g. in the passwordless/sessions/new.html.erb-view.

@session.authenticatable_type.underscore.pluralize
@magic_link =
send(authenticatable_resource_name).token_sign_in_url(session.token)
@magic_link = send(Passwordless.router_context).token_sign_in_url(session.token)

Choose a reason for hiding this comment

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

Line is too long. [86/80]

@session.authenticatable_type.underscore.pluralize
@magic_link =
send(authenticatable_resource_name).token_sign_in_url(session.token)
@magic_link = send(Passwordless.router_context).token_sign_in_url(session.token)

Choose a reason for hiding this comment

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

Line is too long. [86/80]

@grekko grekko mentioned this pull request Mar 3, 2018
@magic_link =
send(authenticatable_resource_name).token_sign_in_url(session.token)
@magic_link = send(Passwordless.router_context)
.token_sign_in_url(session.token)

Choose a reason for hiding this comment

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

Align .token_sign_in_url with send(Passwordless.router_context) on line 13.

@mikker
Copy link
Owner

mikker commented Mar 4, 2018

I actually have a friend stumble into this the other day and didn't have the time to investigate. Perfect! Thanks. I think I'd prefer to have the variable called mounted_at instead of routing_context. Or maybe have a Passwordless.context object with a nested .mounted_at. This gives us one place to save stuff like this if more shows up.

This is a very nice way to solve this problem 👍 thanks! A test case would be very welcome here as well.

},
headers: { 'HTTP_USER_AGENT' => 'Mosaic v.1' }
assert_equal 200, status
assert response.body.include?('If we found you in the system, we have sent you an email.')

Choose a reason for hiding this comment

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

Line is too long. [94/80]

assert_equal 'Not worthy!', flash['error']
follow_redirect!
assert_equal 200, status
assert_equal "/", path

Choose a reason for hiding this comment

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

Prefer single-quoted strings when you don't need string interpolation or special symbols.

# end
fixtures :users

test "the truth" do

Choose a reason for hiding this comment

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

Prefer single-quoted strings when you don't need string interpolation or special symbols.

},
headers: { 'HTTP_USER_AGENT' => 'Mosaic v.1' }
assert_equal 200, status
assert response.body.include?('If we found you in the system, we have sent you an email.')

Choose a reason for hiding this comment

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

Line is too long. [94/80]

assert_equal 'Not worthy!', flash['error']
follow_redirect!
assert_equal 200, status
assert_equal "/", path

Choose a reason for hiding this comment

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

Prefer single-quoted strings when you don't need string interpolation or special symbols.

# end
fixtures :users

test "the truth" do

Choose a reason for hiding this comment

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

Prefer single-quoted strings when you don't need string interpolation or special symbols.

@grekko grekko changed the title Store routing context when mounting for re-use in mailer/templates Store routing context when mounting engine, Fix i18n path Mar 7, 2018
@@ -4,7 +4,7 @@ en:
sessions:
create:
session_expired: 'Your session has expired, please sign in again.'
email_sent_if_record_found: "If we found you in the system, we've sent you an email."
email_sent_if_record_found: "If we found you in the system, we have sent you an email."
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I changed wording since rails actionview escapes the rendered content of we've into some html entities which were hard to capture in the integration test.

Another solution would be to stub the I18n.translate-call or change the backend/translations just for the test.

Open for discuission here.

Copy link
Owner

Choose a reason for hiding this comment

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

Wondered why you'd changed this. Reason sounds like a real hairball. Fine with this or third option below.

headers: { 'HTTP_USER_AGENT' => 'Mosaic v.1' }
assert_equal 200, status
assert response.body.include?(
'If we found you in the system, we have sent you an email.'
Copy link
Owner

Choose a reason for hiding this comment

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

response.body.include?('If we found you in the system') could be another solution to the ' business.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yea.. I tried swapping the i18n backend/translations or stubbing the calls to it but everything turned out to be extremely cumbersome for this single case.

So eventually I like to go w/ your proposed way of checking for the string partial.


assert_equal 200, status
assert_equal '/secret', path
assert_equal 'shhhh! secrets!', response.body
Copy link
Owner

Choose a reason for hiding this comment

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

Glorious! 🎉

@@ -4,7 +4,7 @@ en:
sessions:
create:
session_expired: 'Your session has expired, please sign in again.'
email_sent_if_record_found: "If we found you in the system, we've sent you an email."
email_sent_if_record_found: "If we found you in the system, we have sent you an email."
Copy link
Owner

Choose a reason for hiding this comment

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

Wondered why you'd changed this. Reason sounds like a real hairball. Fine with this or third option below.

@@ -1,4 +1,4 @@
<%= form_for @session, url: send(authenticatable_resource).sign_in_path do |f| %>
<%= form_for @session, url: send(Passwordless.mounted_as).sign_in_path do |f| %>
Copy link
Owner

Choose a reason for hiding this comment

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

Does this mean, we can remove that helper method?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch. Removed it!

@mikker
Copy link
Owner

mikker commented Mar 8, 2018

This is good 👍
Can I make you consolidate all the commits into one?

@grekko
Copy link
Contributor Author

grekko commented Mar 8, 2018

Can I make you consolidate all the commits into one?

Sure. But dont you just squash the commits when merging?

@mikker mikker merged commit 3e17a8b into mikker:master Mar 8, 2018
@mikker
Copy link
Owner

mikker commented Mar 8, 2018

💙💚💛💜❤️

@grekko
Copy link
Contributor Author

grekko commented Mar 8, 2018

Glad to help 🤗

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.

3 participants