Skip to content

Commit

Permalink
tested logIn and logOut
Browse files Browse the repository at this point in the history
  • Loading branch information
VladyslavKutsevolov committed Oct 20, 2020
1 parent 242258c commit ca012a8
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
4 changes: 3 additions & 1 deletion app/controllers/sessions_controller.rb
Original file line number Diff line number Diff line change
@@ -1,9 1,11 @@
class SessionsController < ApplicationController
def create
if user = User.authenticate_with_credentials(params[:email], params[:password])
user = User.authenticate_with_credentials(session_params[:email], session_params[:password])
if user
session[:user_id] = user.id
redirect_to '/'
else
raise 'session user', user
flash[:error] = 'Invalid credentials'
redirect_to '/login'
end
Expand Down
1 change: 1 addition & 0 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 4,7 @@ def new

def create
@user = User.new(user_params)

if @user.save
session[:user_id] = @user.id
redirect_to '/'
Expand Down
23 changes: 23 additions & 0 deletions spec/features/user_login_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 1,23 @@
require 'rails_helper'

RSpec.feature "UserLogins", type: :feature, js: true do
before :each do
@user = User.create!(name: 'Vlad', email: '[email protected]', password: '1234', password_confirmation: '1234')
end

scenario "They can login" do
visit '/login'

fill_in "Email", with: @user.email
fill_in "Password", with: @user.password
click_button "LogIn"

expect(page).to have_content("Welcome #{@user.name}")

click_link 'Logout'

expect(page).to have_content("Login")

save_screenshot
end
end

0 comments on commit ca012a8

Please sign in to comment.