Sha256: cbf083b3442a11baebe4ef693734939d699419411fe1bd49132a5449aeda1f82

Contents?: true

Size: 1.5 KB

Versions: 1

Compression:

Stored size: 1.5 KB

Contents

require 'gemdev'
require 'test/unit/subsets'
require 'active_record'
require 'active_record/fixtures'
require 'joinfix'
require 'tempfile'

# Try to extablish a connection to the configured database
# if this doesn't work, then none of the database_tests will run
config = YAML.load_file(File.dirname(__FILE__) + '/config.yml').symbolize_keys
ActiveRecord::Base.establish_connection(config)
begin
	ActiveRecord::Base.connection
	
	# Not sure what these configurations should point to, but 
	# setup_with_fixtures requires that configurations is not empty
	# in order to run, so...
	ActiveRecord::Base.configurations["joinfix"] = config
rescue
	puts "ActiveRecord connection could not be established using:"
	pp config
end

class Test::Unit::TestCase
	# With the setup in fixtures, I had to override setup and teardown so
	# that by default, the setup_with_fixtures method is not called
	#
	# I do want to call setup_with_fixtures, but only in the context
	# of database test
	
	def setup
	end
	
	def teardown
	end
	
	def database_test(*migrations, &block)
		switch_test( ActiveRecord::Base.connected? ) do 
			ActiveRecord::Migration.verbose = false
			
			begin
				migrations.each {|migration| migration.up}
				setup_with_fixtures
				yield(ActiveRecord::Base.connection)
			ensure
				teardown_with_fixtures
				migrations.each {|migration| migration.down}
			end
		end
	end
end

# set the fixture path
Test::Unit::TestCase.fixture_path = File.dirname(__FILE__) + "/fixtures"

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
joinfix-0.1.0 test/joinfix_test_helper.rb