首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Chapter9 (授权)错误?

Chapter9 (授权)错误?
EN

Stack Overflow用户
提问于 2014-07-17 10:42:23
回答 1查看 385关注 0票数 1

身份验证测试生成错误,我无法理解。它说单元测试断言错误。

代码语言:javascript
复制
Authentication authorization for non-signed-in users in the Users controller submitting to the update action 
     Failure/Error: specify { expect(response).to redirect_to(signin_path) }
     NoMethodError:
       undefined method `assertions' for #<RSpec::Rails::TestUnitAssertionAdapter::AssertionDelegator:0xba527604>

authentication_pages_spec.rb

代码语言:javascript
复制
 describe "authorization" do

    describe "for non-signed-in users" do
      let(:user) { FactoryGirl.create(:user) }

      describe "in the Users controller" do

        describe "visiting the edit page" do
          before { visit edit_user_path(user) }
          it { should have_title('Sign in') }
        end

        describe "submitting to the update action" do
          before { patch user_path(user) }
          specify { expect(response).to redirect_to(signin_path) }
        end
      end
    end
  end

user_controller.rb

授权应用程序代码使用一个前置筛选器,它使用before_action命令安排在给定操作之前调用特定方法。(用于前置过滤器的命令以前称为before_filter,但Rails核心团队决定重命名它,以强调过滤器发生在特定控制器操作之前。)为了要求用户登录,我们定义了一个signed_in_user方法并使用before_action :signed_in_user调用它,如下所示

代码语言:javascript
复制
class UsersController < ApplicationController
  before_action :signed_in_user, only: [:edit, :update]
  private

    def user_params
      params.require(:user).permit(:name, :email, :password,
                                   :password_confirmation)
    end

    # Before filters

    def signed_in_user
      redirect_to signin_url, notice: "Please sign in." unless signed_in?
    end
end
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-07-17 14:33:49

尝试将下面的行添加到您的gem文件中,并从您的gem文件中删除旧的“”行。

代码语言:javascript
复制
gem "rspec-rails", '~> 2.14.0.rc1'

然后运行这些命令,

代码语言:javascript
复制
$ bundle update

$ bundle install

然后再检查一下测试结果。

票数 6
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/24801396

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档