How to test after_sign_in_path_for(resource)?

后端 未结 5 987
日久生厌
日久生厌 2020-12-09 10:07

I have devise authentication and registration set up on my Rails app. I\'m using after_sign_in_path_for() to customise the redirect when the user signs in based

5条回答
  •  南笙
    南笙 (楼主)
    2020-12-09 11:00

    Oddly, I was wondering this very thing today. Here's what I came up with. I created an anonymous subclass of ApplicationController. In this anonymous subclass, I exposed the protected methods that I wanted to test as public methods. Then I tested them directly.

    describe ApplicationController do
      controller do
        def after_sign_in_path_for(resource)
            super resource
        end
      end
    
      before (:each) do
        @user = FactoryGirl.create(:user)
      end
    
      describe "After sigin-in" do
        it "redirects to the /jobs page" do
            controller.after_sign_in_path_for(@user).should == jobs_path
        end
      end
    
    end
    

提交回复
热议问题