我目前正在尝试使用 Rspec 测试我的应用程序的登录和注销 JSON 端点。我使用的色器件和devise_token_auth,以建立JSON端点我认证的宝石。
我可以成功登录用户,但是当注销时,注销功能需要存在多个请求标头才能找到正确的用户并完成。
我已经尝试将标头添加到我当前的 Rack 会话中,但它似乎在创建请求时删除了它们。这是我到目前为止的代码:
辅助方法 ( spec/support/api_helper.rb
):
def login_user
user = create(:user)
post '/api/v1/auth/sign_in', email: user.email, password: user.password, format: :json
return {
'token-type' => 'Bearer',
'uid' => last_response.headers['uid'],
'access-token' => last_response.headers['access-token'],
'client' => last_response.headers['client'],
'expiry' => last_response.headers['expiry']
}
end
Run Code Online (Sandbox Code Playgroud)
我的 Rspec 示例 ( spec/api/v1/authentication_spec.rb
):
describe 'DELETE /api/v1/auth/sign_out' do
it 'should destroy your current session and log you out' do
login_user
delete '/api/v1/auth/sign_out', {}, login_user
expect(last_response.status).to eq 200 …
Run Code Online (Sandbox Code Playgroud) 我有一个脚本,它验证表单的每个阶段,如果验证没有错误,则为每个部分添加一个勾选或交叉.
这是我的代码:
var error = 1;
var hasError = false;
$('.edit_artist').children(':nth-child(' + parseInt(step) + ')').find('input:not(button)').each(function() {
var $this = $(this);
var valueLength = jQuery.trim($this.val()).length;
if(valueLength == '') {
hasError = true;
}
Run Code Online (Sandbox Code Playgroud)
我不希望在所有输入字段上进行验证,因此我希望能够按类验证输入.有没有办法按班级查找输入,还是我需要沿着另一条路线去实现这一目标?
谢谢