How to test after_sign_in_path_for(resource)?

后端 未结 5 985
日久生厌
日久生厌 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 10:48

    I found this answer through Google recently and thought I would add my solution. I didn't like the accepted answer because it was testing the return value of a method on the application controller vs testing the desired behavior of the app.

    I ended up just testing the call to create a new sessions as a request spec.

    RSpec.describe "Sessions", type: :request do
        it "redirects to the internal home page" do
            user = FactoryBot.create(:user, password: 'password 123', password_confirmation: 'password 123')
            post user_session_path, params: {user: {email: user.email, password: 'password 123'}}
            expect(response).to redirect_to(internal_home_index_path)
        end
    end
    

    (Rails 5, Devise 4, RSpec 3)

提交回复
热议问题