Skip to content

Commit

Permalink
Merge pull request mperham#15 from braintreeps/respond_to
Browse files Browse the repository at this point in the history
Implement respond_to? on ConnectionProxy to match what the class actually
  • Loading branch information
mperham committed Oct 27, 2011
2 parents 6ea1d91 + 9ba09b9 commit eb9cf5a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
6 changes: 5 additions & 1 deletion lib/data_fabric/connection_proxy.rb
Expand Up @@ -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)
Expand Down Expand Up @@ -177,4 +181,4 @@ def master
end
end

end
end
21 changes: 19 additions & 2 deletions test/connection_test.rb
Expand Up @@ -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'
Expand Down Expand Up @@ -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 eb9cf5a

Please sign in to comment.