Where does Rails store data created by storing activerecord objects during tests?
I thought I knew the answer to this question: obviously, in the _test database. But it seems that this is not true !
I used this system to check what happens with saved ActiveRecord data during rspec tests:
$ rails -d mysql test
$ cd test
$ nano config / database.yml ...
... create mysql databases test_test, test_development, test_production
$ script / generate rspec
$ script / generate rspec_model foo
change foo migration:
class CreateFoos
$ rake db: migrate
edit spec / models / foo_spec.rb:
require File.expand_path (File.dirname (__ FILE__) + '/../spec_helper')
describe Foo do
before (: each) do
@valid_attributes = {
: bar => 12345
}
end
it "should create a new instance given valid attributes" do
foo = Foo.new (@valid_attributes)
foo.save
puts "sleeping ..."
sleep (20)
end
end
$ rake spec
When you see "sleeping ...", change to another open terminal with a mysql session conneted to the test_test database and do:
mysql> select * from foos; Empty set (0.00 sec)
Why does the mysql session not show records in the test_test database during validation?
ruby database ruby-on-rails testing rspec
Rich apodaca
source share