On Sun, Dec 12, 2010 at 9:11 AM, David Kahn <d...@structuralartistry.com>wrote:
> 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: > > def test_see_yoohoo > person = Person.new > person.name = "Yoohoo" > person.email = "yoo...@gmail.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?('yoo...@gmail.com') > end TestUnit methods are wrapped in a transaction, with every transaction being rollbacked after the method finishes. You can set use_transactional_fixtures = false if you want to change this behavior. http://api.rubyonrails.org/classes/Fixtures.html HTH -- Erol M. Fornoles http://github.com/Erol http://twitter.com/erolfornoles http://ph.linkedin.com/in/erolfornoles -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-t...@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.