【问题标题】:rails devise testing issue using a fixture (unauthorized access)rails 使用夹具设计测试问题(未经授权的访问)
【发布时间】:2023-03-13 14:11:01
【问题描述】:

我在使用 minitest 测试基本设计登录时遇到了一些问题。

我的测试:

 test "user can sign in" do
    @user = users(:someoneelse)
    get new_user_session_path
    assert_select "strong", "log in"
    post user_session_path, user: {  email:       @user.email,
                                   password:    @user.password,
                                   }
   assert_redirected_to root_path
  end

夹具

someoneelse:
  email: someoneelse@whatever.com
  encrypted_password: <%= Devise::Encryptor.digest(User, 'password') %>
  created_at: <%= Time.zone.now %>

测试结果:

 test_user_can_sign_in#UserFlowTest (0.81s)
        Expected response to be a <3XX: redirect>, but was a <200: OK>
        test/integration/user_flow_test.rb:17:in `block in <class:UserFlowTest>'

原木尾

Started POST "/users/sign_in" for 127.0.0.1 at 2017-02-19 14:06:28 -0600
Processing by Devise::SessionsController#create as HTML
  Parameters: {"user"=>{"email"=>"someoneelse@whatever.com", "password"=>"[FILTERED]"}}
Completed **401 Unauthorized in 1ms** (ActiveRecord: 0.0ms)
Processing by Devise::SessionsController#new as HTML

看起来用户未经授权。夹具有问题吗?

另外,我怎样才能让 minitest 更详细?

谢谢。

【问题讨论】:

    标签: ruby-on-rails devise integration-testing ruby-on-rails-5 minitest


    【解决方案1】:

    在您的测试中使用'password',而不是使用@user.password。模型保存后不知道自己存储了什么密码。

    【讨论】:

      猜你喜欢
      • 2017-02-26
      • 2015-03-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-05-27
      • 1970-01-01
      • 2016-08-12
      • 2014-07-01
      相关资源
      最近更新 更多