sample_rails_tailwind/test/integration/users_index_test.rb
songtianlun f2c7d02eed feat: add user deletion functionality
- Implement user destroy action in UsersController
- Add admin check for user deletion
- Update user view to include delete link for admins
- Add migration to add admin attribute to users
- Update tests to cover new admin functionality

This commit introduces the ability for admin users to delete
other users from the system. It includes necessary checks to
ensure that only admins can perform this action, along with
updates to the user interface and tests to validate the
new behavior.
2025-01-05 18:27:13 +08:00

28 lines
677 B
Ruby

require "test_helper"
class UsersIndexTest < ActionDispatch::IntegrationTest
def setup
@admin = users(:michael)
@non_admin = users(:archer)
end
test "index including pagination and delete links" do
log_in_as(@admin)
get users_path
assert_template "users/index"
assert_select "ul.pagination"
first_page_of_users = User.page(1)
first_page_of_users.each do |user|
assert_select "a[href=?]", user_path(user), text: user.name
unless user == @admin
assert_select "a[href=?]", user_path(user), text: "delete"
end
end
assert_difference "User.count", -1 do
delete user_path(@non_admin)
end
end
end