Permalink
Browse files

Fix inconsistencies by being polite to the wrapped body. Needed for R…

…ack::Sendfile to function properly. See issue #1761.
  • Loading branch information...
1 parent 7e65b00 commit aba7a43273d0fe59474c0a833ed58f2851c10a9d @stevehodgkiss stevehodgkiss committed Jun 18, 2011
@@ -426,6 +426,14 @@ def initialize(body, testing = false)
@testing = testing
end
+ def method_missing(method_sym, *arguments, &block)
+ @body.send(method_sym, *arguments, &block)
+ end
+
+ def respond_to?(method_sym, include_private = false)
+ super || @body.respond_to?(method_sym)
+ end
+
def each(&block)
body.each(&block)
end
@@ -33,6 +33,14 @@ def initialize(original_cache_value, target)
@target = target
end
+ def method_missing(method_sym, *arguments, &block)
+ @target.send(method_sym, *arguments, &block)
+ end
+
+ def respond_to?(method_sym, include_private = false)
+ super || @target.respond_to?(method_sym)
+ end
+
def each(&block)
@target.each(&block)
end
@@ -77,6 +77,13 @@ def test_connections_not_closed_if_exception_and_test
@management.call(@env)
assert ActiveRecord::Base.connection_handler.active_connections?
end
+
+ test "proxy is polite to it's body and responds to it" do
+ body = Class.new(String) { def to_path; "/path"; end }.new
+ proxy = ConnectionManagement::Proxy.new(body)
+ assert proxy.respond_to?(:to_path)
+ assert_equal proxy.to_path, "/path"
+ end
end
end
end
@@ -203,3 +203,14 @@ def test_cache_is_expired_by_habtm_delete
end
end
end
+
+class QueryCacheBodyProxyTest < ActiveRecord::TestCase
+
+ test "is polite to it's body and responds to it" do
+ body = Class.new(String) { def to_path; "/path"; end }.new
+ proxy = ActiveRecord::QueryCache::BodyProxy.new(nil, body)
+ assert proxy.respond_to?(:to_path)
+ assert_equal proxy.to_path, "/path"
+ end
+
+end

0 comments on commit aba7a43

Please sign in to comment.