0
我写用Rails 4.2的应用程序,我的控制器如下:Rails 4.2重定向状态200?
class PostsController < ApplicationController
before_action :require_admin, :except => [:index]
def index
@posts = Post.all
end
def show
@post = Post.find(params[:id])
end
def new
@post = Post.new
end
def require_admin
unless user_signed_in? && current_user.admin?
flash[:alert] = 'You require admin privileges for editing posts'
redirect_to root_path
end
end
所以当我使用REST客户端登录之前发送的请求,以显示或新的,我被重定向到登录页面,这是我想要的,并作为非管理员登录时,我被重定向到根路径,这也是我想要的,但是,在这两种情况下,状态代码是200(如果它不是302?)这是非常意外的,我试图为控制器编写测试,而且我很难测试重定向,测试失败Expected <redirect>, got <200>
任何人都可以请帮我指出这里发生了什么?
我使用的设计进行验证
我没有检查文件和也做了硬编码,但测试失败了上述错误。 – hld619