Ruby on rails RubyonRails教程,由M.Hartl编写。第十章失败测试
嗨,我是Hartl的新手。我被困在第十章的微操上了。当我跑的时候Ruby on rails RubyonRails教程,由M.Hartl编写。第十章失败测试,ruby-on-rails,ruby,ruby-on-rails-3,ruby-on-rails-3.1,Ruby On Rails,Ruby,Ruby On Rails 3,Ruby On Rails 3.1,嗨,我是Hartl的新手。我被困在第十章的微操上了。当我跑的时候 bundle exec rspec spec/requests/authentication_pages_spec.rb 终端返回以下失败消息: Failures: 1) authentication authorization in the Users controller submitting to the update action Failure/Error: before { put user_path(user
bundle exec rspec spec/requests/authentication_pages_spec.rb
终端返回以下失败消息:
Failures:
1) authentication authorization in the Users controller submitting to the update action
Failure/Error: before { put user_path(user) }
AbstractController::ActionNotFound:
The action 'update' could not be found for UsersController
# ./spec/requests/authentication_pages_spec.rb:78:in `block (5 levels) in <top (required)>'
2) authentication authorization in the Users controller as wrong user submitting a PUT request to the Users#update action
Failure/Error: before { put user_path(wrong_user) }
AbstractController::ActionNotFound:
The action 'update' could not be found for UsersController
# ./spec/requests/authentication_pages_spec.rb:110:in `block (6 levels) in <top (required)>'
3) authentication authorization in the Users controller as non-admin user submitting a DELETE request to the Users#destroy action
Failure/Error: before { delete user_path(user) }
AbstractController::ActionNotFound:
The action 'destroy' could not be found for UsersController
# ./spec/requests/authentication_pages_spec.rb:122:in `block (6 levels) in <top (required)>'
Finished in 1.54 seconds
21 examples, 3 failures
Failed examples:
rspec ./spec/requests/authentication_pages_spec.rb:79 # authentication authorization in the Users controller submitting to the update action
rspec ./spec/requests/authentication_pages_spec.rb:111 # authentication authorization in the Users controller as wrong user submitting a PUT request to the Users#update action
rspec ./spec/requests/authentication_pages_spec.rb:123 # authentication authorization in the Users controller as non-admin user submitting a DELETE request to the Users#destroy action
我不确定这是什么原因造成的。有什么想法吗?谢谢Simon您是否在user\u controller.rb中定义了更新和销毁操作 这是我的参考
class UsersController < ApplicationController
before_filter :signed_in_user, only: [:index, :edit, :update]
before_filter :correct_user, only: [:edit, :update]
before_filter :admin_user, only: :destroy
def index
@users = User.paginate(page: params[:page])
end
def show
@user = User.find(params[:id])
end
def new
@user = User.new
end
def create
@user = User.new(params[:user])
if @user.save
sign_in @user
flash[:success] = "Welcome to the Sample App!"
redirect_to @user
else
render 'new'
end
end
def edit
end
def update
if @user.update_attributes(params[:user])
sign_in @user
flash[:success] = "Profile updated"
redirect_to @user
else
render 'edit'
end
end
def destroy
User.find(params[:id]).destroy
flash[:success] = "User destroyed"
redirect_to users_path
end
private
def signed_in_user
unless signed_in?
store_location
redirect_to signin_path, notice: "Please sign in"
end
end
def correct_user
@user = User.find(params[:id])
redirect_to root_path unless current_user?(@user)
end
def admin_user
redirect_to root_path unless current_user.admin?
end
end
class UsersController
您是否在user\u controller.rb中定义了更新和销毁操作
这是我的参考
class UsersController < ApplicationController
before_filter :signed_in_user, only: [:index, :edit, :update]
before_filter :correct_user, only: [:edit, :update]
before_filter :admin_user, only: :destroy
def index
@users = User.paginate(page: params[:page])
end
def show
@user = User.find(params[:id])
end
def new
@user = User.new
end
def create
@user = User.new(params[:user])
if @user.save
sign_in @user
flash[:success] = "Welcome to the Sample App!"
redirect_to @user
else
render 'new'
end
end
def edit
end
def update
if @user.update_attributes(params[:user])
sign_in @user
flash[:success] = "Profile updated"
redirect_to @user
else
render 'edit'
end
end
def destroy
User.find(params[:id]).destroy
flash[:success] = "User destroyed"
redirect_to users_path
end
private
def signed_in_user
unless signed_in?
store_location
redirect_to signin_path, notice: "Please sign in"
end
end
def correct_user
@user = User.find(params[:id])
redirect_to root_path unless current_user?(@user)
end
def admin_user
redirect_to root_path unless current_user.admin?
end
end
class UsersController