Why is devise not displaying authentication errors on sign in page?

前端 未结 4 1287
花落未央
花落未央 2020-12-29 14:41

I\'m using rails 4.2

I have a helper file called devise_helper.rb

module DeviseHelper
    def devise_error_messages!
        return \"\" if resource         


        
4条回答
  •  悲哀的现实
    2020-12-29 15:05

    For newer version of Rails/Devise I recommend:

    Instead of <%= devise_error_messages! %> do:

          <% if flash[:alert] %>
            <%= flash[:alert] %>
          <% end %>
    

    Your test may look something like this (note, you must make this a 'feature' functional test to have access to the "page" variable):

    RSpec.feature 'Sign In', :type => :feature do
    
      describe "correct error message w/ wrong password" do
        before :each do
          @user = create(:user)
          @user.confirm
    
          visit new_user_session_path
          fill_in "user_email", with: @user.email
          fill_in "user_password", with: "wrongpassword"
          click_button "Log in"
        end
    
        it "tells user on page 'Invalid Email or password'" do
          expect(page).to have_text("Invalid Email or password")
        end
      end
    
    end
    

提交回复
热议问题