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

Add default flash notice on SessionsController#destroy #178

Merged
merged 3 commits into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
..
  • Loading branch information
mikker committed Nov 7, 2023
commit c59f60435a8541e7572a7a6cc8d1e9bd16828fb8
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

# Unreleased

### Added

- Add default flash notice for sign out (#178)

## 1.0.1

### Fixed
Expand Down
10 changes: 5 additions & 5 deletions app/controllers/passwordless/sessions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,11 @@ def confirm
def destroy
sign_out(authenticatable_class)

redirect_to_response_options = {
notice: I18n.t("passwordless.sessions.destroy.signed_out")
}.merge(redirect_to_options)

redirect_to(passwordless_sign_out_redirect_path, redirect_to_response_options)
redirect_to(
passwordless_sign_out_redirect_path,
notice: I18n.t("passwordless.sessions.destroy.signed_out"),
**redirect_to_options
)
end

protected
Expand Down
22 changes: 4 additions & 18 deletions test/controllers/passwordless/sessions_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -196,29 +196,15 @@ class << User

assert_equal 200, status
assert_equal "/", path
assert_match I18n.t("passwordless.sessions.destroy.signed_out"), flash[:notice]
assert_match "Signed out successfully", flash[:notice]
assert pwless_session(User).blank?
end

test("DELETE /:passwordless_for/sign_out :: When response options are configured ") do
Passwordless.configure do |config|
config.redirect_to_response_options = {
notice: "my custom notice"
}
with_config(redirect_to_response_options: {notice: "my custom notice"}) do
get "/users/sign_out"
assert_match "my custom notice", flash[:notice]
end

user = User.create(email: "a@a")
passwordless_session = create_pwless_session(authenticatable: user, token: "hi")

get "/users/sign_in/#{passwordless_session.id}/#{passwordless_session.token}"
assert_not_nil pwless_session(User)

get "/users/sign_out"
follow_redirect!

assert_equal 200, status
assert pwless_session(User).blank?
assert_match "my custom notice", flash[:notice]
end

class Helpers
Expand Down