-
-
Notifications
You must be signed in to change notification settings - Fork 88
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
Conversation
app/mailers/passwordless/mailer.rb
Outdated
@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) |
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.
Line is too long. [86/80]
app/mailers/passwordless/mailer.rb
Outdated
@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) |
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.
Line is too long. [86/80]
app/mailers/passwordless/mailer.rb
Outdated
@magic_link = | ||
send(authenticatable_resource_name).token_sign_in_url(session.token) | ||
@magic_link = send(Passwordless.router_context) | ||
.token_sign_in_url(session.token) |
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.
Align .token_sign_in_url with send(Passwordless.router_context) on line 13.
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 This is a very nice way to solve this problem 👍 thanks! A test case would be very welcome here as well. |
test/integration/navigation_test.rb
Outdated
}, | ||
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.') |
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.
Line is too long. [94/80]
test/integration/navigation_test.rb
Outdated
assert_equal 'Not worthy!', flash['error'] | ||
follow_redirect! | ||
assert_equal 200, status | ||
assert_equal "/", path |
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.
Prefer single-quoted strings when you don't need string interpolation or special symbols.
test/integration/navigation_test.rb
Outdated
# end | ||
fixtures :users | ||
|
||
test "the truth" do |
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.
Prefer single-quoted strings when you don't need string interpolation or special symbols.
test/integration/navigation_test.rb
Outdated
}, | ||
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.') |
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.
Line is too long. [94/80]
test/integration/navigation_test.rb
Outdated
assert_equal 'Not worthy!', flash['error'] | ||
follow_redirect! | ||
assert_equal 200, status | ||
assert_equal "/", path |
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.
Prefer single-quoted strings when you don't need string interpolation or special symbols.
test/integration/navigation_test.rb
Outdated
# end | ||
fixtures :users | ||
|
||
test "the truth" do |
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.
Prefer single-quoted strings when you don't need string interpolation or special symbols.
config/locales/en.yml
Outdated
@@ -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." |
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 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.
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.
Wondered why you'd changed this. Reason sounds like a real hairball. Fine with this or third option below.
test/integration/navigation_test.rb
Outdated
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.' |
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.
response.body.include?('If we found you in the system')
could be another solution to the '
business.
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.
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 |
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.
Glorious! 🎉
config/locales/en.yml
Outdated
@@ -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." |
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.
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| %> |
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.
Does this mean, we can remove that helper method?
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.
Good catch. Removed it!
This is good 👍 |
Sure. But dont you just squash the commits when merging? |
💙💚💛💜❤️ |
Glad to help 🤗 |
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:
If the root path is changed though, the
Mailer.magic_link
fails to generate the propertoken_sign_in_url
.The same happens e.g. in the
passwordless/sessions/new.html.erb
-view.