问题描述
app/helpers/sessions_helper.rb
app/helpers/sessions_helper.rb
module SessionsHelper
def sign_in(user)
cookies.permanent[:remember_token] = user.remember_token
self.current_user = user
end
def sign_out
self.current_user = nil
cookies.delete(:remember_token)
end
def signed_in?
!current_user.nil?
end
def current_user=(user)
@current_user = user
end
def current_user
@current_user ||= User.find_by_remember_token(cookies[:remember_token])
end
end
9.2.1 要求登录用户
部分中定义的测试失败:-起初我找不到 sign_in 方法然后我添加了
Tests defined in section 9.2.1 Requiring signed-in users
are failing:-At first I was getting sign_in method not found then I added
include SessionsHelper
在 spec/utilities.rb 文件之后,我开始遇到以下错误,说 Rake::Test::CookieJar 中不存在名称为 permanent
的方法.
in spec/utilities.rb file after that I started getting below error, saying no method with name permanent
exists in Rake::Test::CookieJar.
是不是因为某些 Gem 版本问题.
Is it due to some Gem version issue.
1) User Pages edit page
Failure/Error: before { sign_in user}
NoMethodError:
undefined method `permanent' for #<Rack::Test::CookieJar:0x007ff12c661e88>
# ./app/helpers/sessions_helper.rb:3:in `sign_in'
# ./spec/requests/user_pages_spec.rb:55:in `block (3 levels) in <top (required)>'
推荐答案
刚遇到同样的问题并修复了.
Just ran into the same problem and got it fixed.
似乎他们指的不是 sessions_helper.rb
中的 sign_in
方法,而是 spec/support 中的
sign_in
方法/utilities.rb
It seems they are not referring to the sign_in
method in sessions_helper.rb
but the the sign_in
method in spec/support/utilities.rb
在我的例子中,utilities.rb
中的这个辅助方法有一个不同的名字,重命名后一切正常:-)
In my case this helper method in utilities.rb
had a different name, after renaming it everything worked fine :-)
这篇关于RailsTutorial: NoMethodError 'permanent' Rake::Test::CookieJar的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!