Sha256: c15b2d9051455d649fb42946b4369e68bc8ee8d7690e00b281ce0c745101d993
Contents?: true
Size: 1.17 KB
Versions: 1
Compression:
Stored size: 1.17 KB
Contents
module Transactionata # # Hook for creating test data ONCE alongside fixtures that will then be rolled back # via transactions after each test, so you can set up complex data via Factories etc. # without the speed drop. # # Please note that you'll have to set up empty fixture files (and load them, see # the list of fixtures above) in order to clean up the database before you launch # your tests. # # Usage: In your test class, do: # test_data do # Factory.create(:foobar) # # etc... # end # # The foobar record will be available in all your tests and rolls back even if you # modify it in your test cases thanks to transactions. # def test_data(&blk) self.class_eval do class << self attr_accessor :test_data_block end alias_method :original_load_fixtures, :load_fixtures def load_fixtures original_load_fixtures self.class.test_data_block.call Fixtures.reset_cache # Required to enforce purging tables for every test file end end self.test_data_block = blk end end if defined?(ActiveSupport::TestCase) ActiveSupport::TestCase.send :extend, Transactionata end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
transactionata-0.2.0 | lib/transactionata.rb |