If you want to read about migrating a basic Rails application from Devise to Rodauth, go to Basics.

Removing Devise

When writing controller or feature tests, you usually have a file in spec/support/devise.rb. It includes Devise test helpers, you can use sign_in @user in your RSpec tests. You can remove the file entirely:

- RSpec.configure do |config|
-   config.include Devise::Test::ControllerHelpers, type: :controller
-   config.include Devise::Test::ControllerHelpers, type: :view
- end

Updating the specs

Sadly, Rodauth doesn’t have an easy helper for the tests and recommends performing the authentication through the normal requests.

Request specs

For request specs, add the sign_in method to your tests. This will allow you to continue using the sign_in method.

RSpec.describe EventsController, type: :request do
  describe 'POST #create' do
+    def sign_in(user)
+      post '/login', params: { email: user.email, password: 'foobar' }
+    end

    it 'creates an event' do
      user = FactoryBot.create(:user, password: 'foobar')
      sign_in(user) 
      post '/events', params: { date: Date.current, title: 'Foo' }
      expect(response).to have_http_status(:ok)
    end
  end
end

Feature specs

RSpec.describe User, type: :feature do
+  def sign_in(user)
+    visit '/login'
+    fill_in 'E-Mail', with: user.email
+    fill_in 'Password', with: 'foobar'
+    click_button 'Login'
+  end

  it 'loads the root path', js: true do
    user = FactoryBot.create(:user)
    sign_in(user)
    visit root_path
    expect(page).to have_content('Events')
  end
end