jeudi 31 décembre 2015

Chapter 10 ruby on rails Expected nil to not be nil fail

Well i am having some problems with the tests, They are constantly failing and i guess i have an idea, but since you guys are more experienced i am asking for help!

This is the error :

DEPRECATION WARNING: You attempted to assign a value which is not explicitly `true` or `false` to a boolean column. Currently this value casts to `false`. This will change to match Ruby's semantics, and will cast to `true` in Rails 5. If you would like to maintain the current behavior, you should explicitly handle the values you would like cast to `false`. (called from create at /home/ubuntu/workspace/sample_app/app/controllers/sessions_controller.rb:9)
DEPRECATION WARNING: You attempted to assign a value which is not explicitly `true` or `false` to a boolean column. Currently this value casts to `false`. This will change to match Ruby's semantics, and will cast to `true` in Rails 5. If you would like to maintain the current behavior, you should explicitly handle the values you would like cast to `false`. (called from create at /home/ubuntu/workspace/sample_app/app/controllers/sessions_controller.rb:9)
 FAIL["test_login_with_valid_information_followed_by_logout", UsersLoginTest, 1.5503864830825478]
 test_login_with_valid_information_followed_by_logout#UsersLoginTest (1.55s)
        Failed assertion, no message given.
        test/integration/users_login_test.rb:22:in `block in <class:UsersLoginTest>'

and this is the second error i get

DEPRECATION WARNING: You attempted to assign a value which is not explicitly `true` or `false` to a boolean column. Currently this value casts to `false`. This will change to match Ruby's semantics, and will cast to `true` in Rails 5. If you would like to maintain the current behavior, you should explicitly handle the values you would like cast to `false`. (called from create at /home/ubuntu/workspace/sample_app/app/controllers/sessions_controller.rb:9)
 FAIL["test_login_with_remembering", UsersLoginTest, 0.4226432810537517]
 test_login_with_remembering#UsersLoginTest (0.42s)
        Expected nil to not be nil.
        test/integration/users_login_test.rb:42:in `block in <class:UsersLoginTest>'

This is my test/integration/users_login_test.rb

require 'test_helper'

class UsersLoginTest < ActionDispatch::IntegrationTest

    def setup
        @user = users(:michael)
    end

    test "login with invalid information" do
    get login_path
    assert_template 'sessions/new'
    post login_path, session: { email: "", password: "" }
    assert_template 'sessions/new'
    assert_not flash.empty?
    get root_path
    assert flash.empty?
    end 

  test "login with valid information followed by logout" do
    get login_path
    post login_path, session: { email: @user.email, password: 'password' }
    assert is_logged_in?
    assert_redirected_to @user
    follow_redirect!
    assert_template 'users/show'
    assert_select "a[href=?]", login_path, count: 0
    assert_select "a[href=?]", logout_path
    assert_select "a[href=?]", user_path(@user)
    delete logout_path
    assert_not is_logged_in?
    assert_redirected_to root_url
    #simula al usuario saliendo de la sesion en otra ventana
    delete logout_path
    follow_redirect!
    assert_select "a[href=?]", login_path
    assert_select "a[href=?]", logout_path,      count: 0
    assert_select "a[href=?]", user_path(@user), count: 0
    end  

    test "login with remembering" do
            log_in_as(@user, remember_me: '1')
            assert_not_nil cookies['remember_token']
    end
    test "login without remembering" do
            log_in_as(@user, remember_me: '0')
            assert_nil cookies['remember_token']
    end
end

and this if is neccesary session controller.rb

class SessionsController < ApplicationController
  def new
  end

  def create
    user = User.find_by(email: params[:session][:email].downcase)
    if user && user.authenticate(params[:session][:password])
      # loguea al usuario y redirecciona a la pagina del usuario
      if user.activated?
      log_in user
      params[:session][:remember_me] == '1'? remember(user) : forget(user)
      redirect_back_or user
      else
      message = "Cuenta no activada"
      message += "Por favor y no te lo repito mas anda a tu mail para activar tu cuenta forro"
      flash[:warning] = message
      redirect_to root_url
      end
    else
      # Crea un mensaje de error
      flash.now[:danger] = "email/contraseña incorrectos"
     render 'new'
    end  
  end

  def destroy
    log_out if logged_in?
    redirect_to root_url
  end
end

what i am doing wrong? thanks in advance!

Aucun commentaire:

Enregistrer un commentaire