Commit d62fc6cd by Đường Sỹ Hoàng

Updated files

parent 9495aaca
...@@ -2,6 +2,7 @@ michael: ...@@ -2,6 +2,7 @@ michael:
name: Michael Example name: Michael Example
email: michael@example.com email: michael@example.com
password_digest: <%= User.digest("password") %> password_digest: <%= User.digest("password") %>
admin: true
archer: archer:
name: Sterling Archer name: Sterling Archer
......
require "test_helper" require "test_helper"
class UsersIndexTest < ActionDispatch::IntegrationTest class UsersIndexTest < ActionDispatch::IntegrationTest
def setup def setup
@user = users(:michael) @admin = users(:michael)
@non_admin = users(:archer)
end end
test "index including pagination" do test "index as admin including pagination and delete links" do
log_in_as(@user) log_in_as(@admin)
get users_path get users_path
assert_template "users/index" assert_template "users/index"
assert_select "div.pagination" assert_select "div.pagination"
User.paginate(page: 1).each do |user| first_page_of_users = User.paginate(page: 1)
first_page_of_users.each do |user|
assert_select "a[href=?]", user_path(user), text: user.name assert_select "a[href=?]", user_path(user), text: user.name
unless user == @admin
assert_select "a[href=?]", user_path(user), text: "delete"
end
end end
assert_difference "User.count", -1 do
delete user_path(@non_admin)
end
end
test "index as non-admin" do
log_in_as(@non_admin)
get users_path
assert_select "a", text: "delete", count: 0
end end
end end
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment