-
Notifications
You must be signed in to change notification settings - Fork 228
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
5 changed files
with
52 additions
and
0 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
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 |
---|---|---|
|
@@ -85,6 +85,39 @@ | |
end | ||
end | ||
|
||
describe '#login!' do | ||
context 'when succeeds' do | ||
before do | ||
expect(User).to receive(:authenticate).with('[email protected]', 'secret') { |&block| block.call(user, nil) } | ||
get :test_login_bang, params: { email: '[email protected]', password: 'secret' } | ||
end | ||
|
||
it 'assigns user to @user variable' do | ||
expect(assigns[:user]).to eq user | ||
end | ||
|
||
it 'writes user id in session' do | ||
expect(session[:user_id]).to eq user.id.to_s | ||
end | ||
|
||
it 'sets csrf token in session' do | ||
expect(session[:_csrf_token]).not_to be_nil | ||
end | ||
end | ||
|
||
context 'when fails' do | ||
before do | ||
expect(User).to receive(:authenticate).with('[email protected]', 'opensesame!').and_return(nil) | ||
end | ||
|
||
it 'raises Sorcery::InvalidCredentials exception' do | ||
expect do | ||
get :test_login_bang, params: { email: '[email protected]', password: 'opensesame!' } | ||
end.to raise_error(Sorcery::InvalidCredentials) | ||
end | ||
end | ||
end | ||
|
||
describe '#logout' do | ||
it 'clears the session' do | ||
cookies[:remember_me_token] = nil | ||
|
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