添加帐户激活邮件程序后,用户编辑测试现在失败(Rails教程第11章)

时间:2017-02-26 11:56:56

标签: ruby-on-rails integration-testing ruby-on-rails-5 railstutorial.org

我得到了section 11.3.3的Rails教程,我惊讶地发现以下错误:

  

失败[" test_unsuccessful_edit",UsersEditTest,90.26555655000266]    test_unsuccessful_edit #UsersEditTest(90.27s)           期待<&##;用户/编辑">但使用< []>进行渲染           test / integration / users_edit_test.rb:13:在`block in'

     

失败[" test_successful_edit_with_friendly_forwarding",UsersEditTest,   90.43167781096417] test_successful_edit_with_friendly_forwarding #UsersEditTest(90.43s)           预期的响应是重定向,但是重定向到   www.example.com/> ;.           预期" www.example.com/users/637627528/edit"成为===" www.example.com /"。           test / integration / users_edit_test.rb:23:在`block in'

以下是失败的测试:

test "unsuccessful edit" do
    log_in_as(@user)
    get edit_user_path(@user)
    assert_template 'users/edit'
    patch user_path(@user), params: { user: { name: "", email: "foo@invalid", password: "foo", password_confirmation: "bar" } }
    assert_template 'users/edit'
    assert_select 'div.alert', "The form contains 4 errors."
    assert_select 'div.alert-danger'
  end 

 test "successful edit with friendly forwarding" do
    get edit_user_path(@user)
    log_in_as(@user)
    assert_redirected_to edit_user_path(@user)
    assert session[:forwarding_url] == nil
    name = "Foo bar"
    email = "foo@bar.com"
    patch user_path(@user), params: { user: { name: name, email: email, password: "", password_confirmation: "" } }
    assert_not flash.empty?
    assert_redirected_to @user
    @user.reload # Reloads the user's values from the database
    assert_equal name, @user.name
    assert_equal email, @user.email
  end

以下内容位于users_controller.rb:

def update
    @user = User.find(params[:id])
    if @user.update_attributes(user_params)
      flash[:success] = "Profile updated"
      redirect_to @user
    else
      render 'edit'
    end
  end

由于某些原因,我更新会话控制器以包括帐户激活后出现这些错误。所以如果它以某种方式相关,这里是我更新的sessions_controller.rb的一部分:

def create
    user = User.find_by(email: params[:session][:email].downcase)
    if user && user.authenticate(params[:session][:password])
      if user.activated?
        log_in user
        params[:session][:remember_me] == '1' ? remember(user) : forget(user)
        redirect_back_or user
      else
        message  = "Account not activated. "
        message += "Check your email for the activation link."
        flash[:warning] = message
        redirect_to root_url
      end
    else
      flash.now[:danger] = 'Invalid email/password combination'
      render 'new'
    end
  end

我尝试使用byebug,但我似乎无法找到问题所在!有什么想法吗?

1 个答案:

答案 0 :(得分:0)

我有一个类似的错误(更具体地说,this error),我可以通过遵循一个评论者的建议并在命令行运行stop spring然后像往常一样恢复我的测试来解决这个错误。 / p>