2025-01-05 17:50:33 +08:00
|
|
|
require "test_helper"
|
|
|
|
|
|
|
|
class UsersIndexTest < ActionDispatch::IntegrationTest
|
|
|
|
def setup
|
2025-01-05 18:27:13 +08:00
|
|
|
@admin = users(:michael)
|
|
|
|
@non_admin = users(:archer)
|
2025-01-05 17:50:33 +08:00
|
|
|
end
|
|
|
|
|
2025-01-05 18:27:13 +08:00
|
|
|
test "index including pagination and delete links" do
|
|
|
|
log_in_as(@admin)
|
2025-01-05 17:50:33 +08:00
|
|
|
get users_path
|
|
|
|
assert_template "users/index"
|
|
|
|
assert_select "ul.pagination"
|
2025-01-05 18:27:13 +08:00
|
|
|
|
2025-01-07 13:18:16 +08:00
|
|
|
first_page_of_users = User.where(activated: true).page(1)
|
|
|
|
# first_page_of_users.first.toggle!(:activated)
|
2025-01-05 18:27:13 +08:00
|
|
|
first_page_of_users.each do |user|
|
2025-01-07 13:18:16 +08:00
|
|
|
assert user.activated?
|
2025-01-05 17:50:33 +08:00
|
|
|
assert_select "a[href=?]", user_path(user), text: user.name
|
2025-01-05 18:27:13 +08:00
|
|
|
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)
|
2025-01-05 17:50:33 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|