Невозможно устранить ошибку в руководстве по рельсам - PullRequest
0 голосов
/ 16 мая 2018

Я слежу за онлайн-учебником по рельсам и не могу решить проблему ниже

FAIL["test_valid_signup_information_with_account_activation", UsersSignupTest, 5.62457
6674999844]
test_valid_signup_information_with_account_activation#UsersSignupTest (5.63s)
Expected false to be truthy.
test/integration/users_signup_test.rb:38:in block in <class:UsersSignupTest>

require 'test_helper'

class UsersSignupTest < ActionDispatch::IntegrationTest

  def setup
    ActionMailer::Base.deliveries.clear
  end

  test "invalid signup information" do
    get signup_path
    assert_no_difference 'User.count' do
      post users_path, params: { user: { name: "", email: "user@invalid", password: "foo", password_confirmation: "bar" } }
    end
    assert_template 'users/new'
    assert_select 'div#error_explanation'
    assert_select 'div.field_with_errors'
  end

  test "valid signup information with account activation" do
    get signup_path
    assert_difference 'User.count', 1 do
      post users_path, params: { user: { name:  "Example User", email: "user@example.com", password: "foobar12", password_confirmation: "foobar12" } }
    end
    assert_equal 1, ActionMailer::Base.deliveries.size
    user = assigns(:user)
    assert_not user.activated?
    # Try to log in before activation.
    log_in_as(user)
    assert_not is_logged_in?
    # Invalid activation token
    get edit_account_activation_path("invalid token")
    assert_not is_logged_in?
    # Valid token, wrong email
    get edit_account_activation_path(user.activation_token, email: 'wrong')
    assert_not is_logged_in?
    # Valid activation token
    get edit_account_activation_path(user.activation_token, email: user.email)
    **assert user.reload.activated?** 
    # Problem is here, but unsure why??
    follow_redirect!
    assert_template 'users/show'
    assert is_logged_in?
  end
end

Вот код для контроллера активации учетных записей в соответствии с запросом:

class AccountActivationsController < ApplicationController

def edit
 user = User.find_by(email: params[:email])
 if user && !user.activated? && user.authenticated?(:activation, params[:id])
 # user.activate
 user.update_attribute(:activated, true)
 user.update_attribute(:activated_at, Time.zone.now)
 log_in user
 flash[:success] = "Account activated!"
 redirect_to user
else
        flash[:danger] = "Invalid activation link"
        redirect_to root_url
      end
     end
    end

1 Ответ

0 голосов
/ 16 мая 2018

Может быть, ошибка и раньше, а вы не заметили.Это будет синтаксис для rails 4.2 (без параметров :):

assert_difference 'User.count', 1 do
      post users_path, user: { name: 'Example User',
                               email: 'user@example.com',
                               password: 'foo12',
                               password_confirmation: 'foo12' }
end
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...