diff --git a/plugins/adva_safemode/lib/safemode/jail.rb b/plugins/adva_safemode/lib/safemode/jail.rb index ad30aecdf..5e07a78f6 100644 --- a/plugins/adva_safemode/lib/safemode/jail.rb +++ b/plugins/adva_safemode/lib/safemode/jail.rb @@ -12,6 +12,10 @@ def to_s @source.to_s end + def respond_to?(method) + self.class.allowed?(method) or super + end + def method_missing(method, *args, &block) unless self.class.allowed?(method) raise Safemode::NoMethodError.new(method, self.class.name, @source.class.name) diff --git a/plugins/adva_safemode/test/test_helper.rb b/plugins/adva_safemode/test/test_helper.rb index 0a87c8d3f..2cee80103 100644 --- a/plugins/adva_safemode/test/test_helper.rb +++ b/plugins/adva_safemode/test/test_helper.rb @@ -128,3 +128,14 @@ class Article::ExtendedJail < Article::Jail class Comment::Jail < Safemode::Jail allow :article, :text end + +class SpecialString < String + class Jail < Safemode::Jail + allow :special + end + + def special + "some special method" + end +end + diff --git a/plugins/adva_safemode/test/test_jail.rb b/plugins/adva_safemode/test/test_jail.rb index 960be0a25..d982abd06 100644 --- a/plugins/adva_safemode/test/test_jail.rb +++ b/plugins/adva_safemode/test/test_jail.rb @@ -25,17 +25,13 @@ def test_jail_instances_should_have_limited_methods end end - # def test_jail_instances_keep_try - # object = "string" - # object.instance_eval do - # def try(*args) - # "some try method which is so popular/useful nowadays" - # end - # end - # - # assert object.methods.include?("try"), "should have a try method without the jail" - # assert object.to_jail.methods.include?("try"), "should have kept the try method in the jail available" - # end + def test_jail_instances_can_be_tested_with_respond_to + object = SpecialString.new('String Subclass') + + assert object.respond_to?("special") + assert object.to_jail.respond_to?("special") + end + def test_jail_classes_should_have_limited_methods expected = ["new", "methods", "name", "inherited", "method_added", "inspect",