Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 1) Failure:
- UsersSignupTest#test_valid_signup_information [/home/ubuntu/workspace/test/integration/users_signup_test.rb:25]:
- expecting <"users/show"> but rendering with <["statics/home", "layouts/_shim", "layouts/_header", "layouts/_footer", "layouts/application"]>
- 2) Error:
- UsersLoginTest#test_login_with_valid_information_followed_by_logout:
- NoMethodError: undefined method `[]' for nil:NilClass
- app/controllers/sessions_controller.rb:7:in `create'
- test/integration/user_login_test.rb:21:in `block in <class:UsersLoginTest>'
- 3) Error:
- UsersLoginTest#test_login_with_invalid_information:
- NoMethodError: undefined method `[]' for nil:NilClass
- app/controllers/sessions_controller.rb:7:in `create'
- test/integration/user_login_test.rb:12:in `block in <class:UsersLoginTest>'
- require 'test_helper'
- class UsersSignupTest < ActionDispatch::IntegrationTest
- test "invalid signup information" do
- get signup_path
- assert_no_difference 'User.count' do
- post users_path, user: { name: "",
- email: "user@invalid",
- password: "foo",
- password_confirmation: "bar" }
- end
- assert_template 'users/new'
- end
- test "valid signup information" do
- get signup_path
- assert_difference 'User.count', 1 do
- post users_path, user: { name: "Example User",
- email: "user@stpauls.school.nz",
- password: "password",
- password_confirmation: "password" }
- end
- follow_redirect!
- assert_template 'users/show'
- assert is_logged_in?
- end
- end
- require 'test_helper'
- class UsersLoginTest < ActionDispatch::IntegrationTest
- def setup
- @user = users(:someName)
- end
- test "login with invalid information" do
- get login_path
- assert_template 'sessions/new'
- post login_path, params: { 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, params: { 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
- 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
- end
- class SessionsController < ApplicationController
- def new
- end
- def create
- user = User.find_by(email: params[:session][:email].downcase)
- if user && user.authenticate(params[:session][:password])
- log_in user
- redirect_to root_url
- else
- flash.now[:danger] = 'Invalid email/password combination'
- render 'new'
- end
- end
- def destroy
- log_out
- flash.now[:success] = 'Successfully logged out!'
- redirect_to root_url
- end
- end
- ENV['RAILS_ENV'] ||= 'test'
- require File.expand_path('../../config/environment', __FILE__)
- require 'rails/test_help'
- class ActiveSupport::TestCase
- # Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order.
- fixtures :all
- # Add more helper methods to be used by all tests here...
- def is_logged_in?
- !session[:user_id].nil?
- end
- def log_in_as(user, options = {})
- password = options[:password] || 'example'
- end
- end
- module SessionsHelper
- # Logs in the given user.
- def log_in(user)
- session[:user_id] = user.id
- end
- # Returns the current logged-in user (if any).
- def current_user
- @current_user ||= User.find_by(id: session[:user_id])
- end
- # Returns true if the user is logged in, false otherwise.
- def logged_in?
- !current_user.nil?
- end
- # Logs out the current user.
- def log_out
- session.delete(:user_id)
- @current_user = nil
- end
- end
- somename:
- name: "SomeName"
- email: "somename@someemail.com"
- password_digest: <%= User.digest('password') %>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement