diff options
author | Tomas Valent <equivalent@eq8.eu> | 2018-02-20 10:38:19 +0100 |
---|---|---|
committer | Tomas Valent <equivalent@eq8.eu> | 2018-02-26 20:16:03 +0100 |
commit | 06f067506854d9fbecf9694c210468323208d6bb (patch) | |
tree | 379da94baefaa6ac3b8845e6f706ee142baa921f /activesupport/test/core_ext | |
parent | 87de79e9cc25fe6ac02095a1d0c014941a39ede8 (diff) | |
download | rails-06f067506854d9fbecf9694c210468323208d6bb.tar.gz rails-06f067506854d9fbecf9694c210468323208d6bb.tar.bz2 rails-06f067506854d9fbecf9694c210468323208d6bb.zip |
add private: true option for ActiveSupport delegate
Diffstat (limited to 'activesupport/test/core_ext')
-rw-r--r-- | activesupport/test/core_ext/module_test.rb | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/activesupport/test/core_ext/module_test.rb b/activesupport/test/core_ext/module_test.rb index ebbe9c304c..36cfd885d7 100644 --- a/activesupport/test/core_ext/module_test.rb +++ b/activesupport/test/core_ext/module_test.rb @@ -440,4 +440,61 @@ class ModuleTest < ActiveSupport::TestCase assert_not_respond_to place, :the_city assert place.respond_to?(:the_city, true) end + + def test_private_delegate_with_private_option + location = Class.new do + def initialize(place) + @place = place + end + + delegate(:street, :city, to: :@place, private: true) + end + + place = location.new(Somewhere.new("Such street", "Sad city")) + + assert_not_respond_to place, :street + assert_not_respond_to place, :city + + assert place.respond_to?(:street, true) # Asking for private method + assert place.respond_to?(:city, true) + end + + def test_some_public_some_private_delegate_with_private_option + location = Class.new do + def initialize(place) + @place = place + end + + delegate(:street, to: :@place) + delegate(:city, to: :@place, private: true) + end + + place = location.new(Somewhere.new("Such street", "Sad city")) + + assert_respond_to place, :street + assert_not_respond_to place, :city + + assert place.respond_to?(:city, true) # Asking for private method + end + + def test_private_delegate_prefixed_with_private_option + location = Class.new do + def initialize(place) + @place = place + end + end + + assert_equal %i(the_street the_city), + location.delegate(:street, :city, to: :@place, prefix: :the, private: true) + + place = location.new(Somewhere.new("Such street", "Sad city")) + + assert_not_respond_to place, :street + assert_not_respond_to place, :city + + assert_not_respond_to place, :the_street + assert place.respond_to?(:the_street, true) + assert_not_respond_to place, :the_city + assert place.respond_to?(:the_city, true) + end end |