应用程序/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 Requiring signed-in users
失败:-起初我找不到sign_in方法,然后我添加了
include SessionsHelper
在 spec/utilities.rb 文件中,之后我开始出现以下错误,说permanent
Rake::Test::CookieJar 中不存在具有名称的方法。
是不是因为某些 Gem 版本问题。
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)>'