aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/test/core_ext
diff options
context:
space:
mode:
authorJon Leighton <j@jonathanleighton.com>2011-07-18 16:06:21 +0100
committerJon Leighton <j@jonathanleighton.com>2011-08-15 12:38:38 +0100
commit8bba95f293714283f6fc30cb213af54811cccff3 (patch)
tree57dc3f0455622ae001a45f20e4dbf80cee19c071 /activesupport/test/core_ext
parent6f4b405250157c76fea86c42c8b0854ca4a3c4b8 (diff)
downloadrails-8bba95f293714283f6fc30cb213af54811cccff3.tar.gz
rails-8bba95f293714283f6fc30cb213af54811cccff3.tar.bz2
rails-8bba95f293714283f6fc30cb213af54811cccff3.zip
Just do the method call directly in Module#delegate, if we can (we cannot for method names ending in '='). Two reasons: 1) it's faster, see https://gist.github.com/1089783 and 2) more importantly, delegate should not allow you to accidentally call private or protected methods.
Diffstat (limited to 'activesupport/test/core_ext')
-rw-r--r--activesupport/test/core_ext/module_test.rb22
1 files changed, 20 insertions, 2 deletions
diff --git a/activesupport/test/core_ext/module_test.rb b/activesupport/test/core_ext/module_test.rb
index a95cf1591f..074a3412d4 100644
--- a/activesupport/test/core_ext/module_test.rb
+++ b/activesupport/test/core_ext/module_test.rb
@@ -26,10 +26,20 @@ module Yz
end
end
-Somewhere = Struct.new(:street, :city)
+Somewhere = Struct.new(:street, :city) do
+ protected
+
+ def protected_method
+ end
+
+ private
+
+ def private_method
+ end
+end
Someone = Struct.new(:name, :place) do
- delegate :street, :city, :to_f, :to => :place
+ delegate :street, :city, :to_f, :protected_method, :private_method, :to => :place
delegate :upcase, :to => "place.city"
end
@@ -69,6 +79,14 @@ class ModuleTest < Test::Unit::TestCase
assert_equal "Chicago", @david.city
end
+ def test_delegation_to_protected_method
+ assert_raise(NoMethodError) { @david.protected_method }
+ end
+
+ def test_delegation_to_private_method
+ assert_raise(NoMethodError) { @david.private_method }
+ end
+
def test_delegation_down_hierarchy
assert_equal "CHICAGO", @david.upcase
end