Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 4 additions & 2 deletions lib/sorcery/controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,13 @@ def login(*credentials)
end
end

def login!(...)
user = login(...)
def login!(*credentials)
user = login(*credentials)

raise Sorcery::InvalidCredentials if user.nil?

yield(user, nil) if block_given?

user
end

Expand Down
6 changes: 5 additions & 1 deletion spec/controllers/sorcery_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -129,14 +129,18 @@
expect(session[:user_id]).to eq user.id.to_s
end

it 'assigns user to @user variable' do
expect(assigns[:user]).to eq user
end

it 'redirects to root' do
expect(response).to redirect_to(root_url)
end
end

context 'when fails' do
before do
allow(User).to receive(:authenticate).with('bla@example.com', 'opensesame!').and_return(nil)
allow(User).to receive(:authenticate).with('bla@example.com', 'opensesame!').and_yield(user, :invalid_password)
end

it 'raises InvalidCredentials exception' do
Expand Down