diff options
author | Jeremy Evans <code@jeremyevans.net> | 2019-08-08 09:55:33 -0700 |
---|---|---|
committer | Jeremy Evans <code@jeremyevans.net> | 2020-11-20 15:26:43 -0800 |
commit | 08686e71d5c48325ee1bd41c8d7ebcd6c37fa496 (patch) | |
tree | ff711636c0746b3dcce4b543699a4aa1e1773cda /test | |
parent | 1f7b557890c41e59b461d42a5fb9e1f25da9b33d (diff) | |
download | ruby-08686e71d5c48325ee1bd41c8d7ebcd6c37fa496.tar.gz |
Do not allow Module#include to insert modules before the origin in the lookup chain
Module#include should only be able to insert modules after the origin,
otherwise it ends up working like Module#prepend.
This fixes the case where one of the modules in the included module
chain is included in a module that is already prepended to the receiver.
Fixes [Bug #7844]
Diffstat (limited to 'test')
-rw-r--r-- | test/ruby/test_module.rb | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/test/ruby/test_module.rb b/test/ruby/test_module.rb index 6c0fe6b4a5..d63f31a56f 100644 --- a/test/ruby/test_module.rb +++ b/test/ruby/test_module.rb @@ -631,6 +631,16 @@ class TestModule < Test::Unit::TestCase assert_equal([m1, m2], m3.included_modules) end + def test_include_with_prepend + c = Class.new{def m; [:c] end} + p = Module.new{def m; [:p] + super end} + q = Module.new{def m; [:q] + super end; include p} + r = Module.new{def m; [:r] + super end; prepend q} + s = Module.new{def m; [:s] + super end; include r} + a = Class.new(c){def m; [:a] + super end; prepend p; include s} + assert_equal([:p, :a, :s, :q, :r, :c], a.new.m) + end + def test_instance_methods assert_equal([:user, :user2], User.instance_methods(false).sort) assert_equal([:user, :user2, :mixin].sort, User.instance_methods(true).sort) |