module SeleniumHelper # This is slightly messy, when the test files are re-required # the classes turn up again in ObjectSpace and hence duplicates in # .subclasses, should probably figure out how to use Rails' # dynamic loading instead def test_unit_subclasses Test::Unit::TestCase.subclasses.uniq.collect { |k| k.constantize } end def view_path(view) path = File.dirname(__FILE__) + "/../views/#{view}" File.exists?(path) ? path : "#{path}.rhtml" end def selenium_path(file_name) File.expand_path(File.join(RAILS_ROOT, 'vendor/selenium', file_name)) end def load_fixtures raise "Tryed to load fixtures in production environment" if RAILS_ENV.to_s == 'production' without_key_checks do Dir.glob(File.join(RAILS_ROOT, 'test', 'fixtures', '*.{yml,csv}')).each do |fixture_file| Fixtures.create_fixtures(File.join(RAILS_ROOT, 'test', 'fixtures'), File.basename(fixture_file, '.*')) end end end def without_key_checks return yield unless ActiveRecord::Base.connection.class.is_a?(ActiveRecord::ConnectionAdapters::MysqlAdapter) ActiveRecord::Base.connection.execute 'SET FOREIGN_KEY_CHECKS=0' yield ActiveRecord::Base.connection.execute 'SET FOREIGN_KEY_CHECKS=1' end end