Class: RunningMan::ActiveRecordBlock
- Includes:
- TestHelper
- Defined in:
- lib/running_man/active_record_block.rb
Overview
Allow simple setup:
RunningMan.setup_on Test::Unit::TestCase, :ActiveRecordBlock
See README for instructions on use.
Defined Under Namespace
Modules: TestClassMethods, TestHelper
Instance Method Summary collapse
-
#run(binding) ⇒ Object
Sets up an ActiveRecord transition before every test.
-
#run_once(binding) ⇒ Object
Clear the database before running the block.
-
#set_ivar(binding, ivar, value) ⇒ Object
reload any AR instances.
-
#setup(test_class) ⇒ Object
Ensure the block is setup to run first, and that the test run is wrapped in a database transaction.
Methods included from TestHelper
#clear_database, #setup_transaction, #teardown_transaction
Methods inherited from Block
#initialize, #run_always, #run_once?
Constructor Details
This class inherits a constructor from RunningMan::Block
Instance Method Details
#run(binding) ⇒ Object
Sets up an ActiveRecord transition before every test.
61 62 63 64 |
# File 'lib/running_man/active_record_block.rb', line 61 def run(binding) super setup_transaction end |
#run_once(binding) ⇒ Object
Clear the database before running the block.
55 56 57 58 |
# File 'lib/running_man/active_record_block.rb', line 55 def run_once(binding) clear_database super end |
#set_ivar(binding, ivar, value) ⇒ Object
reload any AR instances
67 68 69 70 71 72 |
# File 'lib/running_man/active_record_block.rb', line 67 def set_ivar(binding, ivar, value) if value.class.respond_to?(:find) value = value.class.find(value.id) end super(binding, ivar, value) end |
#setup(test_class) ⇒ Object
Ensure the block is setup to run first, and that the test run is wrapped in a database transaction.
48 49 50 51 52 |
# File 'lib/running_man/active_record_block.rb', line 48 def setup(test_class) block = self test_class.setup { block.run(self) } test_class.teardown { block.teardown_transaction } end |