Search code examples
ruby-on-railstestingrspecfactory-botsorcery

How do I test a FactoryGirl generated user with Sorcery?


I've tried all sorts of different things, and I can't get the following to work.

Here is my factory:

FactoryGirl.define do
  factory :user do
    username              "user"
    email                 "[email protected]"
    password              "userpass"
    password_confirmation "userpass"
  end
end

And here is my test:

describe "With valid information" do let(:user) { FactoryGirl.create(:user) }

  before do
    fill_in 'Username',   with: user.username.upcase
    fill_in 'Password',   with: user.password
    click_button 'Sign in'
    binding.pry
  end

edit: The binding.pry shows me that user.password is nil. Hardcoding the password seems to work, even though it's not as nice.


Solution

  • This works, but it requires hard-coding in the password:

    Here is my factory:

    FactoryGirl.define do
      factory :user do
        username              "user"
        email                 "[email protected]"
        password              "userpass"
        password_confirmation "userpass"
      end
    end
    

    And here is my test:

    describe "With valid information" do let(:user) { FactoryGirl.create(:user) }

      before do
        fill_in 'Username',   with: user.username
        fill_in 'Password',   with: "userpass"
        click_button 'Sign in'
      end