Ask A Question

Notifications

You’re not receiving notifications from this thread.

Warden and System Tests are driving me insane.

Niklas Nson asked in Testing

Im using Warden for authentication and are now trying to write system test. But when I run a system test I get the following error:

Failure/Error: if current_user.admin?
 NoMethodError: 
  undefined method `admin?' for nil:NilClass 

Meaning current_user is not set. How to fix this? I have set up so I can do controller tests with Warden and that works. But I can not figure this out and I don't find any documentation with working code.

Please help me out, I'm going crazy!

Reply

signin_helper.rb

module SigninHelper
  def sign_in_as(user)
    visit signin_path
    fill_in 'authentications_email', with: user.email
    fill_in 'authentications_password', with: user.password
    click_button 'Logga in'
  end

  def sign_out
    click_link "Logga ut"
  end
end

exempel testcase:

require 'rails_helper'
require 'pry'


RSpec.describe "UserEdits", type: :system do
  let(:user) { Fabricate(:confirmed_user) }

  it "should update a users email" do 
    sign_in_as(user)
    visit user_url(user.guid)
    click_link 'Ändra medlemsuppgifter'
    fill_in 'user_email', with: "newusereamail@yahoo.com"
    expect {
      click_button 'Uppdatera uppgifter'
      user.reload
    }.to change { user.email }
  end
end
Reply

I was trying to use "driven_by :rack_test" when changing to driven_by :selenium_chrome_headless it works as expected.

Reply
Join the discussion
Create an account Log in

Want to stay up-to-date with Ruby on Rails?

Join 82,329+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.