'Cannot reach the password of the user after assigning it - RSpec

I am trying to write system tests. I want to run a classic login page test. I have a field for email, password, and submit button.

It is working in production env and alive without any problem.

my test file is like this:


it "can login" do
      user = User.create(email: '[email protected]', password: 'password', role:1, name: 'test user')
      user.save!

      visit '/'
      fill_in(:user_email, with: user.email)
      fill_in(:user_password, with: 'password')

      find(:button, 'Sign in').click
      expect(page).to have_content('Signed in.')
    end

Whenever I tried to create a user and try to use it in the system testing, it is not working. It is visiting the page, filling the places and clicking the button as it should but it cannot log in, giving error that email or password is not correct.

I believe there is a problem with password encryption or somehow I cannot match the passwords properly. I have printed out the user after creation in the test case, I have a valid user but somehow I cannot reach its password. I checked the model, there is not a 'password' field. ( I am working on a company project, that is why I am having difficulty to find the problem ) I can assign a password with using user.password = ... but I cannot call it back it seems. (I tried this in rails console, assigning worked, calling back did not and I could use the user and the password for logging in manually)

EDIT: I found out that the problem is database matching. I could create the user but the test is not using that user...



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source