Failures:
1) AuthenticationPages GET /authentication_pages should hava the title 'sign in'
Failure/Error: visit signin_path
ActionController::RoutingError:
uninitialized constant ApplicationController::SeesionsHelper
# ./app/controllers/application_controller.rb:6:in `<class:ApplicationController>'
# ./app/controllers/application_controller.rb:1:in `<top (required)>'
# ./app/controllers/sessions_controller.rb:1:in `<top (required)>'
# ./spec/requests/authentication_pages_spec.rb:15:in `block (3 levels) in <top (required)>'
2) AuthenticationPages signin with valid information
Failure/Error: click_button "Sign in"
NoMethodError:
undefined method `sign_in' for #<SessionsController:0x007f9dbf089210>
# ./app/controllers/sessions_controller.rb:9:in `create'
# (eval):2:in `click_button'
# ./spec/requests/authentication_pages_spec.rb:40:in `block (4 levels) in <top (required)>'
3) AuthenticationPages signin with valid information
Failure/Error: click_button "Sign in"
NoMethodError:
undefined method `sign_in' for #<SessionsController:0x007f9dbf4308f0>
# ./app/controllers/sessions_controller.rb:9:in `create'
# (eval):2:in `click_button'
# ./spec/requests/authentication_pages_spec.rb:40:in `block (4 levels) in <top (required)>'
4) AuthenticationPages signin with valid information
Failure/Error: click_button "Sign in"
NoMethodError:
undefined method `sign_in' for #<SessionsController:0x007f9dbf643e58>
# ./app/controllers/sessions_controller.rb:9:in `create'
# (eval):2:in `click_button'
# ./spec/requests/authentication_pages_spec.rb:40:in `block (4 levels) in <top (required)>'
5) AuthenticationPages signin with valid information
Failure/Error: click_button "Sign in"
NoMethodError:
undefined method `sign_in' for #<SessionsController:0x007f9dbf791a80>
# ./app/controllers/sessions_controller.rb:9:in `create'
# (eval):2:in `click_button'
# ./spec/requests/authentication_pages_spec.rb:40:in `block (4 levels) in <top (required)>'
6) AuthenticationPages signin with valid information with invalid information
Failure/Error: click_button "Sign in"
NoMethodError:
undefined method `sign_in' for #<SessionsController:0x007f9dbf0a8638>
# ./app/controllers/sessions_controller.rb:9:in `create'
# (eval):2:in `click_button'
# ./spec/requests/authentication_pages_spec.rb:40:in `block (4 levels) in <top (required)>'
7) AuthenticationPages signin with valid information with invalid information
Failure/Error: click_button "Sign in"
NoMethodError:
undefined method `sign_in' for #<SessionsController:0x007f9dbf438ca8>
# ./app/controllers/sessions_controller.rb:9:in `create'
# (eval):2:in `click_button'
# ./spec/requests/authentication_pages_spec.rb:40:in `block (4 levels) in <top (required)>'
8) AuthenticationPages signin with valid information with invalid information after visiting another page
Failure/Error: click_button "Sign in"
NoMethodError:
undefined method `sign_in' for #<SessionsController:0x007f9dbf6496a0>
# ./app/controllers/sessions_controller.rb:9:in `create'
# (eval):2:in `click_button'
# ./spec/requests/authentication_pages_spec.rb:40:in `block (4 levels) in <top (required)>'
Finished in 1.05 seconds
42 examples, 8 failures
Failed examples:
rspec ./spec/requests/authentication_pages_spec.rb:14 # AuthenticationPages GET /authentication_pages should hava the title 'sign in'
rspec ./spec/requests/authentication_pages_spec.rb:44 # AuthenticationPages signin with valid information
rspec ./spec/requests/authentication_pages_spec.rb:45 # AuthenticationPages signin with valid information
rspec ./spec/requests/authentication_pages_spec.rb:43 # AuthenticationPages signin with valid information
rspec ./spec/requests/authentication_pages_spec.rb:46 # AuthenticationPages signin with valid information
rspec ./spec/requests/authentication_pages_spec.rb:28 # AuthenticationPages signin with valid information with invalid information
rspec ./spec/requests/authentication_pages_spec.rb:29 # AuthenticationPages signin with valid information with invalid information
rspec ./spec/requests/authentication_pages_spec.rb:32 # AuthenticationPages signin with valid information with invalid information after visiting another page
----------------
application_controller.rb文件
```shell
class ApplicationController < ActionController::Base
# Prevent CSRF attacks by raising an exception.
# For APIs, you may want to use :null_session instead.
# protect_from_forgery with: :exception
protect_from_forgery
include SessionsHelper
end
sessions_helper.rb 文件
module SessionsHelper
def sign_in(user)
cookies.permanent[:remember_token] = user.remember_token
self.current_user = user
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