aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/test
diff options
context:
space:
mode:
authorJon Leighton <j@jonathanleighton.com>2011-08-25 18:51:17 +0100
committerJon Leighton <j@jonathanleighton.com>2011-08-25 22:30:42 +0100
commit8ba491acc31bf08cf63a83ea0a3c314c52cd020f (patch)
tree617a8a8133b700811cca12942f802bb4c0167904 /activesupport/test
parentbad6803570f5f3b09d277b15c9f272bfae7408da (diff)
downloadrails-8ba491acc31bf08cf63a83ea0a3c314c52cd020f.tar.gz
rails-8ba491acc31bf08cf63a83ea0a3c314c52cd020f.tar.bz2
rails-8ba491acc31bf08cf63a83ea0a3c314c52cd020f.zip
Revert all the stuff to do with disallowing non-public methods for Module#delegate
Diffstat (limited to 'activesupport/test')
-rw-r--r--activesupport/test/core_ext/module_test.rb20
-rw-r--r--activesupport/test/core_ext/object/public_send_test.rb117
2 files changed, 1 insertions, 136 deletions
diff --git a/activesupport/test/core_ext/module_test.rb b/activesupport/test/core_ext/module_test.rb
index d4ce81fdfa..449d3810e2 100644
--- a/activesupport/test/core_ext/module_test.rb
+++ b/activesupport/test/core_ext/module_test.rb
@@ -28,20 +28,10 @@ end
Somewhere = Struct.new(:street, :city) do
attr_accessor :name
-
- protected
-
- def protected_method
- end
-
- private
-
- def private_method
- end
end
class Someone < Struct.new(:name, :place)
- delegate :street, :city, :to_f, :protected_method, :private_method, :to => :place
+ delegate :street, :city, :to_f, :to => :place
delegate :name=, :to => :place, :prefix => true
delegate :upcase, :to => "place.city"
@@ -93,14 +83,6 @@ class ModuleTest < Test::Unit::TestCase
assert_equal "Fred", @david.place.name
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
diff --git a/activesupport/test/core_ext/object/public_send_test.rb b/activesupport/test/core_ext/object/public_send_test.rb
deleted file mode 100644
index 7dc542e51c..0000000000
--- a/activesupport/test/core_ext/object/public_send_test.rb
+++ /dev/null
@@ -1,117 +0,0 @@
-require 'abstract_unit'
-require 'active_support/core_ext/object/public_send'
-
-module PublicSendReceiver
- def receive_public_method(*args)
- return args + [yield]
- end
-
- protected
-
- def receive_protected_method(*args)
- return args + [yield]
- end
-
- private
-
- def receive_private_method(*args)
- return args + [yield]
- end
-end
-
-# Note, running this on 1.9 will be testing the Ruby core implementation, but it is good to
-# do this to ensure that our backport functions the same as Ruby core in 1.9
-class PublicSendTest < Test::Unit::TestCase
- def instance
- @instance ||= begin
- klass = Class.new do
- include PublicSendReceiver
- end
- klass.new
- end
- end
-
- def singleton_instance
- @singleton_instance ||= begin
- object = Object.new
- object.singleton_class.send(:include, PublicSendReceiver)
- object
- end
- end
-
- def test_should_receive_public_method
- assert_equal(
- [:foo, :bar, :baz],
- instance.public_send(:receive_public_method, :foo, :bar) { :baz }
- )
- end
-
- def test_should_receive_public_singleton_method
- assert_equal(
- [:foo, :bar, :baz],
- singleton_instance.public_send(:receive_public_method, :foo, :bar) { :baz }
- )
- end
-
- def test_should_raise_on_protected_method
- assert_raises(NoMethodError) do
- instance.public_send(:receive_protected_method, :foo, :bar) { :baz }
- end
- end
-
- def test_should_raise_on_protected_singleton_method
- assert_raises(NoMethodError) do
- singleton_instance.public_send(:receive_protected_method, :foo, :bar) { :baz }
- end
- end
-
- def test_should_raise_on_private_method
- assert_raises(NoMethodError) do
- instance.public_send(:receive_private_method, :foo, :bar) { :baz }
- end
- end
-
- def test_should_raise_on_singleton_private_method
- assert_raises(NoMethodError) do
- singleton_instance.public_send(:receive_private_method, :foo, :bar) { :baz }
- end
- end
-
- def test_should_raise_on_undefined_method
- assert_raises(NoMethodError) do
- instance.public_send(:receive_undefined_method, :foo, :bar) { :baz }
- end
- end
-
- def test_protected_method_message
- instance.public_send(:receive_protected_method, :foo, :bar) { :baz }
- rescue NoMethodError => exception
- assert_equal(
- "protected method `receive_protected_method' called for #{instance.inspect}",
- exception.message
- )
- end
-
- def test_private_method_message
- instance.public_send(:receive_private_method, :foo, :bar) { :baz }
- rescue NoMethodError => exception
- assert_equal(
- "private method `receive_private_method' called for #{instance.inspect}",
- exception.message
- )
- end
-
- def test_undefined_method_message
- instance.public_send(:receive_undefined_method, :foo, :bar) { :baz }
- rescue NoMethodError => exception
- assert_equal(
- "undefined method `receive_undefined_method' for #{instance.inspect}",
- exception.message
- )
- end
-
- def test_receiver_with_no_singleton
- assert_equal "5", 5.public_send(:to_s)
- assert_equal "foo", :foo.public_send(:to_s)
- end
-end