Skip to content

Commit

Permalink
added a respond_to?-method to the jail
Browse files Browse the repository at this point in the history
  • Loading branch information
kronn committed Apr 23, 2010
1 parent a18a667 commit 022c81d
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 11 deletions.
4 changes: 4 additions & 0 deletions plugins/adva_safemode/lib/safemode/jail.rb
Expand Up @@ -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)
Expand Down
11 changes: 11 additions & 0 deletions plugins/adva_safemode/test/test_helper.rb
Expand Up @@ -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

18 changes: 7 additions & 11 deletions plugins/adva_safemode/test/test_jail.rb
Expand Up @@ -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",
Expand Down

0 comments on commit 022c81d

Please sign in to comment.