From 8eea74c965b0f66eac3848f1eaaf495d5dc1092e Mon Sep 17 00:00:00 2001 From: Krzysztof Zych Date: Wed, 5 Jul 2017 15:38:54 +0200 Subject: Use `map` in `delegate` so that actual prefixed method names are returned, if using prefix version. --- activesupport/test/core_ext/module_test.rb | 39 ++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) (limited to 'activesupport/test/core_ext/module_test.rb') diff --git a/activesupport/test/core_ext/module_test.rb b/activesupport/test/core_ext/module_test.rb index a4d4444d69..14e166351a 100644 --- a/activesupport/test/core_ext/module_test.rb +++ b/activesupport/test/core_ext/module_test.rb @@ -392,4 +392,43 @@ class ModuleTest < ActiveSupport::TestCase event = Event.new(Tester.new) assert_equal 1, event.foo end + + def test_private_delegate + location = Class.new do + def initialize(place) + @place = place + end + + private *delegate(:street, :city, to: :@place) + end + + place = location.new(Somewhere.new("Such street", "Sad city")) + + assert_not place.respond_to?(:street) + assert_not place.respond_to?(:city) + + assert place.respond_to?(:street, true) # Asking for private method + assert place.respond_to?(:city, true) + end + + def test_private_delegate_prefixed + location = Class.new do + def initialize(place) + @place = place + end + + private *delegate(:street, :city, to: :@place, prefix: :the) + end + + place = location.new(Somewhere.new("Such street", "Sad city")) + + assert_not place.respond_to?(:street) + assert_not place.respond_to?(:city) + + + assert_not place.respond_to?(:the_street) + assert place.respond_to?(:the_street, true) + assert_not place.respond_to?(:the_city) + assert place.respond_to?(:the_city, true) + end end -- cgit v1.2.3