我有一个应用程序,我正在扩展 Devise 的 RegistrationsController 以添加一些我自己的功能,但由于某种原因,我无法通过我的帐户创建测试。在开发中一切正常,所以我几乎可以肯定这与我编写测试的方式有关,但老实说,我现在愿意尝试任何事情。太令人沮丧了。
这是我的测试的摘录。您会看到它正在检查新用户,但没有找到。
describe RegistrationsController do
before :each do
@request.env['devise.mapping'] = Devise.mappings[:user]
@new_user = { 'fname' => 'Stizzle',
'lname' => 'Mcgizzle',
'email' => 'qwerty@example.com',
'password' => 'foobar'
}
end
describe "During a regular registration, " do
it "filling out the fields correctly should create a new user" do
RegistrationsController.stub(:verify_recaptcha).and_return(true)
expect do
post :create,
:user => @new_user,
:recaptcha_response_field => 'foobar',
'tos-agree' => 'true'
end.to change(User.all, :count).by(1)
end
我的控制器动作:
def create
build_resource
if verify_recaptcha(:model => resource, :message => "The text you entered did not match. Please try again.") && resource.save
if resource.active_for_authentication?
set_flash_message :notice, :signed_up if is_navigational_format?
sign_in(resource_name, resource)
respond_with resource, :location => after_sign_up_path_for(resource)
else
set_flash_message :notice, :"signed_up_but_#{resource.inactive_message}" if is_navigational_format?
expire_session_data_after_sign_in!
respond_with resource, :location => after_inactive_sign_up_path_for(resource)
end
else
clean_up_passwords resource
render :action => 'new'
end
end
我尝试从控制器中删除 CAPTCHA 只是为了看看这是否会造成一些麻烦,但它没有任何效果。
想法?