Skip to content
Browse files

Implement respond_to? on ConnectionProxy to match what the class actu…

…ally performs via method_missing.
  • Loading branch information...
1 parent be67fd7 commit 9ba09b9321ab251b96b9e7ae06a98f3abf0530b1 @braintreeps committed Oct 27, 2011
Showing with 24 additions and 3 deletions.
  1. +5 −1 lib/data_fabric/connection_proxy.rb
  2. +19 −2 test/connection_test.rb
View
6 lib/data_fabric/connection_proxy.rb
@@ -89,6 +89,10 @@ def transaction(start_db_transaction = true, &block)
end
end
+ def respond_to?(method)
+ super || connection.respond_to?(method)
+ end
+
def method_missing(method, *args, &block)
DataFabric.logger.debug { "Calling #{method} on #{connection}" }
connection.send(method, *args, &block)
@@ -177,4 +181,4 @@ def master
end
end
-end
+end
View
21 test/connection_test.rb
@@ -78,7 +78,24 @@ def test_shard_connection_name
ShardModel.connection.connection_name
end
end
-
+
+ def test_respond_to_connection_methods
+ setup_configuration_for ShardModel, 'city_austin_test'
+ DataFabric.activate_shard(:city => 'austin', :category => 'art') do
+ assert ShardModel.connection.respond_to?(:columns)
+ assert ShardModel.connection.respond_to?(:primary_key)
+ assert !ShardModel.connection.respond_to?(:nonexistent_method)
+ end
+ end
+
+ def test_respond_to_connection_proxy_methods
+ setup_configuration_for ShardModel, 'city_austin_test'
+ DataFabric.activate_shard(:city => 'austin', :category => 'art') do
+ assert ShardModel.connection.respond_to?(:with_master)
+ assert !ShardModel.connection.respond_to?(:nonexistent_method)
+ end
+ end
+
def test_enchilada
setup_configuration_for TheWholeEnchilada, 'fiveruns_city_dallas_test_slave'
setup_configuration_for TheWholeEnchilada, 'fiveruns_city_dallas_test_master'
@@ -121,4 +138,4 @@ def setup_configuration_for(clazz, name)
ActiveRecord::Base.configurations ||= HashWithIndifferentAccess.new
ActiveRecord::Base.configurations[name] = HashWithIndifferentAccess.new({ :adapter => 'mysql', :database => name, :host => 'localhost'})
end
-end
+end

0 comments on commit 9ba09b9

Please sign in to comment.
Something went wrong with that request. Please try again.