0

Configuration

Webpacker application using Rails 5.1 with Vue.js 2.5

I've been trying to diagnose this bug for 3 days now and I am at my wits end. I've started to add system tests using Capybara using standard selenium-webdriver.

Problems occur when I am trying to access authenticatable routes, for example, user settings:

RSpec.describe 'home page', type: :system do
  before(:context) do
    WebMock.disable_net_connect!(allow_localhost: true)
  end

  after do
    Warden.test_reset!
  end

  context 'when logged in' do
    context 'as an average user' do

      before do
        @profile = create(:profile)
        @user = @profile.user
        @user.update(confirmed_at: Time.now)

        login_as(@user, scope: :user)
      end

      it 'redirects to Account Settings page after pressing Account Settings' do
        visit '/'

        find('.profile-menu').hover
        find('.settings').click

        expect(page).to have_content 'Account Settings'
      end
    end
  end
end

this is not a link and is handled in my .vue file, which just redirects to the route I need location.href = "/users/edit";

When I am on the root page, I am signed in, current_user returns the user and all is great. But as soon as I press that link, at some point it gets reset as I get redirected to the standard Devise Login page.

If I directly go to that page visit '/users/edit, but current_user is set and its all fine.

This is my test devise setup:

require 'devise'

RSpec.configure do |config|
  config.include Warden::Test::Helpers
end

Let me know if you need some extra information, I think I've provided all the crucial bits but could have missed something.

Maxim Fedotov
  • 1,349
  • 1
  • 18
  • 38
  • Are you sure the `@user.update(confirmed_at: Time.now)` is succeeding? Also are you calling `Warden::test_reset!` in an after block? – Thomas Walpole Apr 14 '18 at 15:58
  • Yup, it's confirmed and I do `test_reset!` after each example. The `current_user` just becomes `nil` @ThomasWalpole – Maxim Fedotov Apr 15 '18 at 11:18

1 Answers1

0

I seem to have fixed this issue. I've tried a couple things mentioned in this SO answer. As far as I can tell, what fixed it was fixing my configuration from:

 RSpec.configure do |config|
   config.include Warden::Test::Helpers
 end

to

 RSpec.configure do |config|
   config.include Devise::Test::IntegrationHelpers, type: :system
 end

This also allowed me to drop:

  after(:each) do
    Warden.test_reset!
  end

in all my tests. I've run quite a few tests and they don't fail anymore, so I am for now assuming this has been indeed fixed.

Maxim Fedotov
  • 1,349
  • 1
  • 18
  • 38