There are comments in the rails database indicating that the test database should be reset between runs
rake -T
rake test:all
rake test:all:db
config / database.yml
test:
This is not like me.
I am using a factory girl to generate test models, here is a factory example
FactoryGirl.define do
factory :podcast do
sequence(:title) { |n| "Podcast #{n}" }
sequence(:feed_url) { |n| "http://podcast.com/#{n}" }
end
end
A podcast must have a unique feed_url, so I check its uniqueness in the model.
class Podcast < ActiveRecord::Base
validates :feed_url, uniqueness: true, presence: true
end
Q test_helper.rbI will tie all the plants
ENV["RAILS_ENV"] ||= "test"
require File.expand_path('../../config/environment', __FILE__)
require 'rails/test_help'
require 'minitest/autorun'
FactoryGirl.lint
My test creates a podcast, builds another with the same name, and then claims that the second is invalid.
require 'test_helper'
describe Podcast do
describe '#feed_url' do
it 'must be unique' do
podcast = create(:podcast)
new_podcast = build(:podcast, feed_url: podcast.name)
assert_invalid podcast, :feed_url, 'has already been taken'
end
end
end
The first time you run the tests, it runs without errors and all tests pass. The second time I run the tests, Girl lint fails because the podcast feed_url is already done.
Why doesn't the test database rebuild between runs?