mercredi 31 mars 2021

How to pass a variable in callbacks during rspec testing?

I have callback name authenticatie_admin_user . It will return true if current user email ID is "adminuser@admin.com"

def authenticate_admin_user!
 if Current.user.blank? || Current.user.email != "adminuser@admin.com"
  redirect_to courses_path, danger: "Admin login required" 
 end 
end

This callback runs when I call new action . While testing the new action I have to set Current.user value

describe "GET /new" do
    describe "Create course with admin login"
      it "will not renders a new course page" do
        get new_course_url
        expect(response).to_not be_successful
      end
      it "will render a new course page" do
        get new_course_url
        expect(response).to be_successful
      end
  end

How can I set the value of Current.user? PS: Here Current is a ActiveSupport::Currentattributes model and user is a attribute inside Current class.

Aucun commentaire:

Enregistrer un commentaire