I am trying to do the following in a Test/Unit integration test using Capybara. Very basic Rails 3 app, Ruby 1.9.2 just with the pg and capybara gems, thats it.
Everything works except that the Person object I create manually in the test does not show in the test database… or any other database I can find! But Person.all returns him, so he is getting created somewhere. Then, when Capybara/Selenium go to the browser which I have verified does hit the test database fine (through another test), I get an empty list of people on the index page.
Capybara/Selenium have the Rails.env correct in terms of hitting the db correctly. The Test itself says Rails.env = “test”, the data does not go into the test db. Where is the data getting saved? And how can I manually set up data in an Integration test before running Capybara? I thought maybe that Capybara was somehow triggering the database being emptied but the sequence below proves this is not the case:
person = Person.new
person.name = “Yoohoo”
person.email = “email@example.com”
assert person.save # passes
assert Person.find_by_name(“Yoohoo”) # passes but in dbconsole “select * from people” in the test database (or dev database) returns no rows
assert_equal Rails.env, “test” # passes
visit "/people" # page loads fine.... Capybara/Selenium working.... assert page.has_content?('Yoohoo') # fails (page has empty list.... the list passes fine on another page so issue is not the view) assert page.has_content?('firstname.lastname@example.org')