Rails应用的认证、管理与国际化实现
1. 认证辅助模块与测试集成
在Rails应用开发中,认证功能是很重要的一部分。为了方便测试认证相关功能,我们创建了一个认证辅助模块 AuthenticationHelpers ,并将其集成到测试用例中。以下是具体代码:
module AuthenticationHelpers
def login_as(user)
if respond_to? :visit
visit login_url
fill_in :name, with: user.name
fill_in :password, with: 'secret'
click_on 'Login'
else
post login_url, params: { name: user.name, password: 'secret' }
end
end
def logout
delete logout_url
end
def setup
login_as users(:one)
end
end
class ActionDispatch::IntegrationTest
include AuthenticationHelpers
end
class ActionDispatch::SystemTestCase
include AuthenticationHelpers
end
这个模块提供了 login_as 和
超级会员免费看
订阅专栏 解锁全文
62

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



