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
Sort a Collection of Objects by Number (Highest First) Then by Letter (Alphabetical)
Ruby Modulo 3 with Negative Numbers Is Unintuitive
Parse Email Addresses for "From" and "To" Fields in Ruby
What Is the Ruby Equivalent of Python's Getattr
The Number of Trailing Zeros in a Factorial of a Given Number - Ruby
What Do I Need to Do to Get the Blog to Work in Rails 4.2
How to Install Ruby 2.0.0 Correctly on Ubuntu 12.04
Trouble Comparing Time with Rspec
Vim Slow with Ruby Syntax Highlighting
How to Read Whole File in Ruby
In Ruby, Is There No Way to Dynamically Define a Local Variable in the Current Context
An Algorithm for Converting a Base-10 Number to a Base-N Number
Inserting an Array Using Sequel Gem in Postgresql
What's the Best Way to Unit Test Protected & Private Methods in Ruby