A collection of helper functions that are generally useful for testing Mongrel2::Handlers.
Inclusion callback – install some hooks
# File lib/mongrel2/testing.rb, line 20
def self::included( context )
context.before( :all ) do
setup_config_db
end
context.around( :each ) do |example|
if (( setting = example.metadata[:db] ))
if setting == :no_transaction || setting == :without_transaction
Loggability[ Mongrel2 ].debug " running without a transaction"
example.run
else
Loggability[ Mongrel2 ].debug " running with a transaction"
Mongrel2::Config.db.transaction( rollback: :always ) do
example.run
end
end
else
example.run
end
end
super
end
Truncate all the tables in the current config DB.
# File lib/mongrel2/testing.rb, line 54
def clean_config_db
Mongrel2::Config.db.tables.collect {|t| Mongrel2::Config.db[t] }.each( &:truncate )
end
Set up a Mongrel2
configuration database in memory.
# File lib/mongrel2/testing.rb, line 47
def setup_config_db
Mongrel2::Config.db ||= Mongrel2::Config.in_memory_db
Mongrel2::Config.init_database!
end