Railstutorial - Chapter 8.4.3 - Test Database Not Clearing After Adding User in Integration Test

RailsTutorial - chapter 8.4.3 - Test database not clearing after adding user in integration test

As far as I'm concerned testing views leaves database in unclear state, you should try https://github.com/bmabey/database_cleaner it is used for cleaning after cucumber tests, but an example for Rspec is available on the main page.

Record persisting past test in Rails3

Note: I am the author of the Rails Tutorial. The config.cache_classes = false line got added after Peter Cooper reported that it was necessary to get RSpec and Spork to work together on his system. Since I have not found it necessary, and since it seemed to introduce lots of problems (such as those identified in this thread), that line has since been removed. If you use the latest version of the book you shouldn't run into this problem.

Rails 3 Tutorial Chapter 11 Validation failed: Email has already been taken error

I had trouble with the Integration tests shortly after Chapter 9.4. All of my controller tests and the request integration test blew up with the message 'Email has already been taken'

What I learned from RailsTutorial - chapter 8.4.3 - Test database not clearing after adding user in integration test is that you need to do something to clean up after integration tests, because unlike unit tests they may not clean up after themselves.

The solution presented there was to use the DatabaseCleaner gem, the implementation of which is also explained in the linked Question.

I think that if you don't implement some strategy for cleaning up after the integration test you will continue to have to use your 'shotgun' solution for cleaning up the DB every time you run the test suite. Definitely not fun.

Rails 3 + Rspec 2: Validation failed: Email has already been taken

When you define a factory with an association you need to give the factory an object to associate with whenever you use the factory.

This should work:

describe "User authenticated: " do
login_user
@bucket = Factory(:bucket, :user => @user)

it "should get index" do
get 'index'
response.should be_success
end
end

That way factorygirl knows to make a bucket which is associated with @user.



Related Topics



Leave a reply



Submit