ruby-on-railsrspecfactory-botdevise-confirmable

Where do I confirm user created with FactoryGirl?


Using rails, devise, rspec & factorygirl:

Trying to create some tests for my site. I'm using the confirmable model for devise so when I create a user using FactoryGirl, the user isn't confirmed.

This is my factories.rb:

FactoryGirl.define do
  factory :user do
    full_name             "Aren Admin"
    email                 "aren@example.com"
    password              "arenaren"
    password_confirmation "arenaren"
    role_id               ADMIN
  end
end

And this is my rspec test file:

require 'spec_helper'

describe "Admin pages" do

  subject { page }

  describe "home page" do
    let(:user) { FactoryGirl.create(:user) }
    before { visit admin_home_path }

    it { should have_content("#{ROLE_TYPES[user.role_id]}") }
  end
end

I'm getting an error because the user is not confirmed. By searching around I'm pretty sure I need to use the method 'confirm!' and that it belongs in the factories.rb file, but I'm not sure where to put it.


Solution

  • Try user.confirm! in your before block

    found here