parent
c23f58a6df
commit
a70c656690
21 changed files with 309 additions and 2 deletions
55
test/controllers/users_controller_test.rb
Normal file
55
test/controllers/users_controller_test.rb
Normal file
|
@ -0,0 +1,55 @@
|
|||
require "test_helper"
|
||||
|
||||
class UsersControllerTest < ActionDispatch::IntegrationTest
|
||||
setup do
|
||||
@user = users(:one)
|
||||
end
|
||||
|
||||
test "should get index" do
|
||||
get users_url
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
test "should get new" do
|
||||
get new_user_url
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
test "should create user" do
|
||||
assert_difference("User.count") do
|
||||
params = {
|
||||
user: {
|
||||
email: "userthree@example.local",
|
||||
password: "secret",
|
||||
password_confirmation: "secret"
|
||||
}
|
||||
}
|
||||
post users_url, params: params
|
||||
end
|
||||
|
||||
assert_redirected_to user_url(User.last)
|
||||
end
|
||||
|
||||
test "should show user" do
|
||||
get user_url(@user)
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
test "should get edit" do
|
||||
get edit_user_url(@user)
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
test "should update user" do
|
||||
patch user_url(@user), params: { user: { email: @user.email, password: "secret", password_confirmation: "secret" } }
|
||||
assert_redirected_to user_url(@user)
|
||||
end
|
||||
|
||||
test "should destroy user" do
|
||||
assert_difference("User.count", -1) do
|
||||
delete user_url(@user)
|
||||
end
|
||||
|
||||
assert_redirected_to users_url
|
||||
end
|
||||
end
|
9
test/fixtures/users.yml
vendored
Normal file
9
test/fixtures/users.yml
vendored
Normal file
|
@ -0,0 +1,9 @@
|
|||
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
|
||||
|
||||
one:
|
||||
email: userone@example.local
|
||||
password_digest: <%= BCrypt::Password.create("secret") %>
|
||||
|
||||
two:
|
||||
email: usertwo@example.local
|
||||
password_digest: <%= BCrypt::Password.create("secret") %>
|
7
test/models/user_test.rb
Normal file
7
test/models/user_test.rb
Normal file
|
@ -0,0 +1,7 @@
|
|||
require "test_helper"
|
||||
|
||||
class UserTest < ActiveSupport::TestCase
|
||||
# test "the truth" do
|
||||
# assert true
|
||||
# end
|
||||
end
|
45
test/system/users_test.rb
Normal file
45
test/system/users_test.rb
Normal file
|
@ -0,0 +1,45 @@
|
|||
require "application_system_test_case"
|
||||
|
||||
class UsersTest < ApplicationSystemTestCase
|
||||
setup do
|
||||
@user = users(:one)
|
||||
end
|
||||
|
||||
test "visiting the index" do
|
||||
visit users_url
|
||||
assert_selector "h1", text: "Users"
|
||||
end
|
||||
|
||||
test "should create user" do
|
||||
visit users_url
|
||||
click_on "New user"
|
||||
|
||||
fill_in "Email", with: "userthree@example.local"
|
||||
fill_in "Password", with: "secret"
|
||||
fill_in "Password confirmation", with: "secret"
|
||||
click_on "Create User"
|
||||
|
||||
assert_text "User was successfully created"
|
||||
click_on "Back"
|
||||
end
|
||||
|
||||
test "should update User" do
|
||||
visit user_url(@user)
|
||||
click_on "Edit this user", match: :first
|
||||
|
||||
fill_in "Email", with: "newemail@example.local"
|
||||
fill_in "Password", with: "newpassword"
|
||||
fill_in "Password confirmation", with: "newpassword"
|
||||
click_on "Update User"
|
||||
|
||||
assert_text "User was successfully updated"
|
||||
click_on "Back"
|
||||
end
|
||||
|
||||
test "should destroy User" do
|
||||
visit user_url(@user)
|
||||
click_on "Destroy this user", match: :first
|
||||
|
||||
assert_text "User was successfully destroyed"
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue