jeudi 30 novembre 2017

Rails: How do I ensure that he db reverts to its original state after tests?

I'm trying to write a test that involves creating a new user. However, the test fails all but the first time because the user remains permanently in the db after the initial run.

require 'test_helper'
require 'minitest/autorun'

describe UserMailer < ActionMailer::TestCase do
  it 'will send an email when a new user is created' do
    original_mail_count = ActionMailer::Base.deliveries.count
    User.create(email: "new_user@test.com", password: "password").save
    ActionMailer::Base.deliveries.count.must_equal original_mail_count + 1
  end
end

How do I ensure that the db returns to its pre-test state after the test is run?

Aucun commentaire:

Enregistrer un commentaire