用户管理:更新、展示与删除的实现
在用户管理系统中,确保用户数据的安全性和友好的用户体验至关重要。以下将详细介绍用户信息更新、展示所有用户等功能的实现,包括权限验证、友好转发、用户索引页面的构建以及分页处理等方面。
1. 权限验证
- 仅允许正确用户编辑信息 :用户登录后,应仅能编辑自己的信息。可以通过测试来验证这一点,先以错误用户身份登录,然后尝试访问编辑和更新操作。若用户尝试编辑其他用户的信息,应重定向到根URL,而非登录页面。
# spec/requests/authentication_pages_spec.rb
require 'spec helper'
describe "Authentication" do
describe "authorization" do
describe "as wrong user" do
let(:user) { FactoryGirl.create(:user) }
let(:wrong_user) { FactoryGirl.create(:user, email: "wrong@example.com") }
before { sign_in user }
describe "visiting Users#edit page" do
before { visit edit_user_path(wrong_user) }
it { should not have selector('title', text: full_ti
超级会员免费看
订阅专栏 解锁全文
172万+

被折叠的 条评论
为什么被折叠?



