parent
a70c656690
commit
4d3971113f
13 changed files with 196 additions and 0 deletions
27
test/controllers/sessions_controller_test.rb
Normal file
27
test/controllers/sessions_controller_test.rb
Normal file
|
@ -0,0 +1,27 @@
|
|||
require "test_helper"
|
||||
|
||||
class SessionsControllerTest < ActionDispatch::IntegrationTest
|
||||
test "should get new" do
|
||||
get new_session_url
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
test "should create session" do
|
||||
user = users(:one)
|
||||
params = {
|
||||
session: {
|
||||
email: user.email,
|
||||
password: "secret"
|
||||
}
|
||||
}
|
||||
post sessions_url, params: params
|
||||
|
||||
assert_redirected_to root_url
|
||||
end
|
||||
|
||||
test "should destroy session" do
|
||||
delete session_url(@session)
|
||||
|
||||
assert_redirected_to root_url
|
||||
end
|
||||
end
|
25
test/models/session_test.rb
Normal file
25
test/models/session_test.rb
Normal file
|
@ -0,0 +1,25 @@
|
|||
require "test_helper"
|
||||
|
||||
class SessionTest < ActiveSupport::TestCase
|
||||
def test_save_when_exists
|
||||
user = users(:one)
|
||||
|
||||
session = Session.new(email: user.email, password: "secret")
|
||||
|
||||
assert session.save
|
||||
end
|
||||
|
||||
def test_save_when_not_exists
|
||||
session = Session.new(email: "fake@example.org", password: "secret")
|
||||
|
||||
assert_not session.save
|
||||
end
|
||||
|
||||
def test_save_when_password_incorrect
|
||||
user = users(:one)
|
||||
|
||||
session = Session.new(email: user.email, password: "bad_password")
|
||||
|
||||
assert_not session.save
|
||||
end
|
||||
end
|
25
test/system/sessions_test.rb
Normal file
25
test/system/sessions_test.rb
Normal file
|
@ -0,0 +1,25 @@
|
|||
require "application_system_test_case"
|
||||
|
||||
class SessionsTest < ApplicationSystemTestCase
|
||||
setup do
|
||||
@user = users(:one)
|
||||
end
|
||||
|
||||
test "should create session" do
|
||||
visit new_session_url
|
||||
|
||||
fill_in "Email", with: @user.email
|
||||
fill_in "Password", with: "secret"
|
||||
|
||||
click_on "Create Session"
|
||||
|
||||
assert_text "Session was successfully created"
|
||||
end
|
||||
|
||||
test "should destroy Session" do
|
||||
visit root_url
|
||||
click_on "Log out", match: :first
|
||||
|
||||
assert_text "Session was successfully destroyed"
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue