-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
56 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
### | ||
# Controller for handling login/logout and redirecting with flash messages. | ||
### | ||
class AuthenticationController < ApplicationController | ||
def login | ||
flash[:success] = 'You have been successfully logged in.' | ||
redirect_to params[:referrer] || :back | ||
end | ||
|
||
def logout | ||
flash[:notice] = 'You have been successfully logged out.' | ||
redirect_to params[:referrer] || :back | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
require 'rails_helper' | ||
|
||
describe AuthenticationController do | ||
before do | ||
request.env['HTTP_REFERER'] = 'https://example.com' | ||
end | ||
describe 'login' do | ||
it 'should redirect back to the provided referrer' do | ||
get :login, referrer: '/' | ||
expect(response).to redirect_to('/') | ||
end | ||
it 'should redirect back when there is no provided referrer' do | ||
get :login | ||
expect(response).to redirect_to('https://example.com') | ||
end | ||
it 'should have a flash success message informing the user they logged in' do | ||
get :login | ||
expect(flash[:success]).to eq 'You have been successfully logged in.' | ||
end | ||
end | ||
describe 'logout' do | ||
it 'should redirect back to the provided referrer' do | ||
get :logout, referrer: '/' | ||
expect(response).to redirect_to('/') | ||
end | ||
it 'should redirect back when there is no provided referrer' do | ||
get :logout | ||
expect(response).to redirect_to('https://example.com') | ||
end | ||
it 'should have a flash notice message informing the user they logged out' do | ||
get :logout | ||
expect(flash[:notice]).to eq 'You have been successfully logged out.' | ||
end | ||
end | ||
end |