activerecord - Rails test data, in the database -


This may be a basic misconception on my part. I have a bunch of logic in my app that sets data from several tables and adds them to memory structures. I want to write a test for that argument.

It looks like the fixtures, factory girl and similar equipment create examples of in-memory models. If I call activerecord, like Model.find (foo: 12) they apply only against records that were saved? Thanks!

In most cases, I agree with the opinion of @ MRBDRO: Like rpsec stub method but a rail As a programmer, I think you have to know both "stability" and "stub".

The fixtures, whatever your yaml file or factory girl data , will save in your database in your config / database.yml See the file for the place where they are. Actually this is useful when you want to make sure that during your testing, always some data in DB, such as "Admin User" with a fixed ID

Stubs, it is faster than stability because it will not be saved in DB, and probably very useful when you want to do a test that can not be implemented by "facts".

So, I suggest that you try both of them in your real coding life, and choose one of them according to the actual context.

Comments

Popular posts from this blog

java - NullPointerException for a 2d Array -

python - Assemble mpeg file unable to play in mediaplayer -

asp.net - MVC [HandleError] HandleErrorAttribute called twice when using global logging -