diff options
author | Matthew Draper <matthew@trebex.net> | 2017-07-06 00:25:40 +0930 |
---|---|---|
committer | Matthew Draper <matthew@trebex.net> | 2017-07-06 00:26:16 +0930 |
commit | 019238385cae6bc0454155c0c4bf23325d9a6204 (patch) | |
tree | d7df325f08593d52ecbe41f6871586301917ddb5 /activesupport/test | |
parent | 990a4dbbca5b7a8cf3d01861cb66deae456d370e (diff) | |
parent | 8eea74c965b0f66eac3848f1eaaf495d5dc1092e (diff) | |
download | rails-019238385cae6bc0454155c0c4bf23325d9a6204.tar.gz rails-019238385cae6bc0454155c0c4bf23325d9a6204.tar.bz2 rails-019238385cae6bc0454155c0c4bf23325d9a6204.zip |
Merge pull request #29687 from k3rni/private-prefixed-delegate
Return prefixed method names from `Module.delegate`, if using prefixes
Diffstat (limited to 'activesupport/test')
-rw-r--r-- | activesupport/test/core_ext/module_test.rb | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/activesupport/test/core_ext/module_test.rb b/activesupport/test/core_ext/module_test.rb index a4d4444d69..cba60ef013 100644 --- a/activesupport/test/core_ext/module_test.rb +++ b/activesupport/test/core_ext/module_test.rb @@ -392,4 +392,42 @@ 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 |