I'm working on a course building a social network using Rails 4 & Devise.
I'm stuck trying to get a course to pass, this is the error I'm getting:
1) Error:
UserFriendshipsControllerTest#test_: #new when not logged in should get redirected to the login page. :
NoMethodError: undefined method `authenticate!' for nil:NilClass
test/controllers/user_friendships_controller_test.rb:8:in `block (3 levels) in <class:UserFriendshipsControllerTest>'
This is my users_friendships_controller_test.rb :
require 'test_helper'
class UserFriendshipsControllerTest < ActionController::TestCase
context "#new" do
context "when not logged in" do
should "get redirected to the login page" do
get :new
assert_response :redirect
end
end
end
end
My user_friendship.rb:
class UserFriendship < ActiveRecord::Base
belongs_to :user
belongs_to :friend, class_name: "User", foreign_key: "friend_id"
private
def friendship_params
params.require(:user).permit(:user_id, :friend_id, :friend)
end
end
The only thing I've added to my user_friendships_controller.rb is a blank new method and:
before_filter :authenticate_user!, only: [:new]
Please let me know if I should post any more code.
Thank you