Permalink
Browse files

Add 'cover_all' task to generate coverage for all installed AR versions.

Fix tests on AR < 2.2, add testing for connected? and connection_pool
methods.
  • Loading branch information...
1 parent de38e1a commit 28881ebe870ee682a4a687e4ff067ea8b18b42d0 @mperham mperham committed Dec 1, 2008
Showing with 29 additions and 12 deletions.
  1. +12 −5 Rakefile
  2. +4 −4 lib/data_fabric/ar22.rb
  3. +1 −1 test/connection_test.rb
  4. +12 −2 test/database_test.rb
View
@@ -90,19 +90,26 @@ def create_mysql(create, db_name)
end
# Test coverage
+gem 'spicycode-rcov' rescue nil
begin
- gem 'spicycode-rcov'
require 'rcov/rcovtask'
- task :cover => [:pretest, :rcov]
+ desc "Generate coverage numbers for all locally installed versions of ActiveRecord"
+ task :cover_all do
+ Gem.source_index.search(Gem::Dependency.new('activerecord', '>=2.0')).each do |spec|
+ puts `rake cover AR_VERSION=#{spec.version}`
+ end
+ end
+
+ task :cover => [:pretest, :rcov_impl]
- Rcov::RcovTask.new('rcov') do |t|
+ Rcov::RcovTask.new('rcov_impl') do |t|
t.libs << "test"
t.test_files = FileList["test/*_test.rb"]
- t.output_dir = "coverage"
+ t.output_dir = "coverage/#{ENV['AR_VERSION']}"
t.verbose = true
t.rcov_opts = ['--text-report', '--exclude', "test,Library,#{ENV['GEM_HOME']}", '--sort', 'coverage']
end
-rescue GemError => e
+rescue LoadError => e
puts 'Test coverage support requires \'gem install spicycode-rcov\''
end
View
@@ -81,6 +81,10 @@ def with_master
set_role(old_role)
end
+ def connected?
+ current_pool.connected?
+ end
+
private
def in_transaction?
@@ -134,10 +138,6 @@ def connection
current_pool.connection
end
- def active?
- DataFabric.shard_active_for?(@shard_group)
- end
-
def set_role(role)
Thread.current[:data_fabric_role] = role
end
View
@@ -99,7 +99,7 @@ def setup_configuration_for(clazz, name)
if ar22?
flexmock(ActiveRecord::ConnectionAdapters::ConnectionPool).new_instances.should_receive(:new_connection).and_return(AdapterMock.new(RawConnection.new))
else
- flexmock(klass).should_receive(:mysql_connection).and_return(AdapterMock.new(RawConnection.new))
+ flexmock(clazz).should_receive(:mysql_connection).and_return(AdapterMock.new(RawConnection.new))
end
ActiveRecord::Base.configurations ||= HashWithIndifferentAccess.new
ActiveRecord::Base.configurations[name] = HashWithIndifferentAccess.new({ :adapter => 'mysql', :database => name, :host => 'localhost'})
View
@@ -10,17 +10,27 @@ class DatabaseTest < Test::Unit::TestCase
def setup
ActiveRecord::Base.configurations = load_database_yml
- DataFabric::ConnectionProxy.shard_pools.clear
+ if ar22?
+ DataFabric::ConnectionProxy.shard_pools.clear
+ end
end
def test_live_burrito
DataFabric.activate_shard :city => :dallas do
assert_equal 'fiveruns_city_dallas_test_slave', TheWholeBurrito.connection.connection_name
+ assert_raises RuntimeError do
+ TheWholeBurrito.connection_pool
+ end
+
+ assert !TheWholeBurrito.connected?
+
# Should use the slave
burrito = TheWholeBurrito.find(1)
assert_match 'vr_dallas_slave', burrito.name
-
+
+ assert TheWholeBurrito.connected?
+
# Should use the master
burrito.reload
assert_match 'vr_dallas_master', burrito.name

0 comments on commit 28881eb

Please sign in to comment.