开发者

How to test changes to the database after an http request in rails 2 automated testing?

开发者 https://www.devze.com 2023-02-04 08:54 出处:网络
I\'m trying to write a good, comprehensive test suite for a rails 2.3.5 app, but I\'ve discovered that apparently in functional tests each http request is wrapped in a transaction.Which means you can\

I'm trying to write a good, comprehensive test suite for a rails 2.3.5 app, but I've discovered that apparently in functional tests each http request is wrapped in a transaction. Which means you can't test what has changed in the database after an action has run. I have discovered, and am using, assert_difference, but it's not quite enough. I would like to test that associations have been established, which doesn't appear to work. Is this impossible with the built in rails testing framework? Should I be using integration tests? Should I have more of my logic factored out into my m开发者_高级运维odel? I'm really not sure which convention I'm breaking, but it certainly feels like my app has gotten off the rails in this regard. Would like to stop riding on the railroad ties. =/


I may be misunderstanding what you're doing, but I have integration tests that update the database and then read back those values from the database and assert on them within the same test. By default (in Rails 2.3.5 anyway) the transaction should only be rolled-back at the end of each test.

TBH, I've found functional tests of less use to me than integration tests. For example, my test user usually needs to log into my app in order to do anything useful and that involves (in most Rails authentication plugins I've seen) calling into two controllers - and that can only be done in an integration test.

0

精彩评论

暂无评论...
验证码 换一张
取 消