Prev | Current Page 313 | Next

Kevin Marshall, Chad Pytel, and Jon Yurek

"Pro Active Record: Databases with Ruby and Rails"

Our create_fixtures method call told our code to look
for an accounts.yml file in our C:\ruby directory, so let??™s create that file now (we??™ll talk more
about the YAML format in just a minute).
# Test data set in YAML format saved as account.yml
Kevin:
id: 1
username: Kevin
CHAPTER 6 ?–  ACTIVE RECORD TESTING AND DEBUGGING 140
Now, we should be able to run our test successfully against our fixture data. To confirm
that the tests really are using the data from your fixtures, go ahead and change the username
value in your account.yml file and rerun the test. Your test should now fail, confirming that you
are using fixtures.
Transaction Support with Fixtures
Fixtures also have support for transactions so that your test cases use the begin/rollback
approach instead of the default insert/delete. Using transactions is, of course, a pretty simple
task??”you just set the use_transactional_fixtures method to a value of true, as shown in the
following example:
# test_artest.rb Unit Test example
require 'artest'
require 'test/unit'
require 'active_record/fixtures'
Fixtures.


Pages:
301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325