ruby-on-rails – RailsTutorial登录flash无法正常工作
发布时间:2020-12-17 02:10:56 所属栏目:百科 来源:网络整理
导读:我试图让错误flash出现在railstutorial.org示例应用程序中.到目前为止,这就是我所做的.任何人都可以帮我找到错误: 我的RSPEC测试失败: 1) SessionsController POST 'create' invalid signin should have a flash.now messageFailure/Error: flash.now[:err
我试图让错误flash出现在railstutorial.org示例应用程序中.到目前为止,这就是我所做的.任何人都可以帮我找到错误:
我的RSPEC测试失败: 1) SessionsController POST 'create' invalid signin should have a flash.now message Failure/Error: flash.now[:error].should =~ /invalid/i expected: /invalid/i got: nil (using =~) ./spec/controllers/sessions_controller_spec.rb:27 控制器代码: def create user = User.authenticate(params[:session][:email],params[:session][:password]) if user.nil? flash.now[:error] = "Invalid email/password combination." @title = "Sign in" render 'new' else # Sign the user in and redirect to the user's show page. end end 测试代码: describe "POST 'create'" do describe "invalid signin" do before(:each) do @attr = { :email => "example@gmail.com",:password => "invalid"} end it "should re-render the new page" do post :create,:session => @attr response.should render_template('new') end it "should have a flash.now message" do post :create,:session => @attr flash.now[:error].should =~ /invalid/i end end 解决方法
它看起来像你的app / controllers / sessions_controller.rb,你在底部声明了第二个创建方法,它只是说:
def create render 'new' end 第二个声明正在取代文件中较早的预期create方法.只需删除这三行(文件中为20-22),你的规格就会以漂亮的颜色传递,我的意思是只有一种颜色,即绿色. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |