Rails 应用中的用户登录功能实现
1. 有效信息登录测试
在进行登录功能开发时,首先编写了关于有效信息登录的测试代码:
describe "with valid information" do
let(:user) { FactoryGirl.create(:user) }
before do
fill in "Email",
with: user.email
fill in "Password", with: user.password
click button "Sign in"
end
it { should have selector('title', text: user.name) }
it { should have link('Profile', href: user path(user)) }
it { should have link('Sign out', href: signout path) }
it { should not have link('Sign in', href: signin path) }
end
这里使用了 have_link 方法,该方法接受链接文本和可选的 :href 参数,确保锚标签 a 有正确的 href (URI)属性。
2. 登录表单开发
在测试就绪后,开始开发登录表单。与注册表单不同,登录表单没有 Se
超级会员免费看
订阅专栏 解锁全文
788

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



