我在Hartl教程第9.2.3节的测试中得到了这个错误
1) Authentication signin with valid information
Failure/Error: click_button 'Sign in'
ArgumentError:
wrong number of arguments (0 for 1)
# ./app/helpers/sessions_helper.rb:34:in `redirect_back_or'
# ./app/controllers/sessions_controller.rb:11:in `create'
# (eval):2:in `click_button'
# ./spec/requests/authentication_pages_spec.rb:37:in `block (4 levels) in <top (required)>'
它来自会话控制器中的这种方法:
应用程序/控制器/ sesssions_controllers.rb
def create
user = User.find_by_email(params[:session][:email])
if user && user.authenticate(params[:session][:password])
sign_in user
redirect_back_or user
else
flash.now[:error] = "Invalid email/password combination"
render 'new'
end
'redirect_back_or'方法来自会话助手: 应用程序/助手/ sessions_helper.rb
def redirect_back_or(default)
redirect_to(session[:return_to] || default)
session.delete.(:return_to)
end
在此之前,会话控制器创建方法将...
redirect_to user
将其更改为redirect_back_or几乎失败了我的所有测试。使用redirect_to用户已经通过了大部分测试。
以下是相关测试: spec / requests / authentication_pages_spec.rb
describe "Authorization" do
describe "for non signed in users" do
let(:user) {FactoryGirl.create(:user) }
describe "when attempting to visit a protected page" do
before do
visit edit_user_path(user)
fill_in "Email", with: user.email
fill_in "Password", with: user.password
click_button "Sign in"
end
describe "after signing in" do
it "should render the desired protected page" do
page.should have_selector('title', text: "Edit user")
end
end
end
end
我不知道该怎么做。为什么我得到错误的参数数量错误?
我已经回过头了但是我不确定要去哪里。我觉得我仔细检查了书中的所有代码......但我仍然得到这个错误。 谢谢你是另一双眼睛。请帮我解决这个问题。
答案 0 :(得分:1)
此行中有一个额外的点:
session.delete.(:return_to)
将其更改为:
session.delete(:return_to)