有关rails测试数据库

3 views
Skip to first unread message
Message has been deleted

hong1...@gmail.com

unread,
Mar 23, 2009, 2:07:25 AM3/23/09
to chinese question to english one
当运行测试代码时,只有fixtures里的数据保存在测试数据库里,而运行过程中由测试方法存贮的model没有保存在测试数据库里?例如:
#########
def test_save
user=User.new(...)
user.save
end
##########
当运行完这个测试方法后,user 没有存贮在测试数据库的表里?对吗?

daociyiyou

unread,
Mar 23, 2009, 3:40:17 AM3/23/09
to chinese question to english one

when testing codes, only the fixtures data are stored in the test
database table after running the test and the model saved during
runing test method is not stored in the test database table? For
example:
#########
def test_save
user=User.new(...)
user.save
end
##########
After running the test method,the user is not stored in the test
database table?
right?
Message has been deleted

hong107yan

unread,
Mar 23, 2009, 4:06:03 AM3/23/09
to chinese question to english one


Sort of. It is stored in the test database, but the entire test runs
within a transaction, which is rolled back at the end of the test.
Take a look in your app's test.log and you'll see for yourself.
Fred

daociyiyou

unread,
Mar 23, 2009, 4:07:34 AM3/23/09
to chinese question to english one

差不多。但user存贮在测试数据库里了,只不过整个测试在一个transaction里运行,
也就是在该测试结束时,这个 transaction 又做回滚或返回操作。看一下你的程序
的测试记录,你自己会明白的。

hong107yan

unread,
Mar 23, 2009, 4:08:58 AM3/23/09
to chinese question to english one
谢谢!我找到了这句在测试记录里:
[4;36;1mSQL (0.032000)[0m [0;1mROLLBACK [0m

daociyiyou

unread,
Mar 23, 2009, 4:10:38 AM3/23/09
to chinese question to english one
Thanks,i have found the following words in the test log:
Reply all
Reply to author
Forward
0 new messages