Use sets to check if methods are invokable without symbolizing.

This commit is contained in:
Dylan Smith
2013-02-05 14:45:08 -05:00
parent 1300210f05
commit 38b4543bf1
5 changed files with 43 additions and 38 deletions
+7
View File
@@ -115,6 +115,13 @@ class DropsTest < Test::Unit::TestCase
assert_equal ' ', output
end
def test_object_methods_not_allowed
[:dup, :clone, :singleton_class, :eval, :class_eval, :inspect].each do |method|
output = Liquid::Template.parse(" {{ product.#{method} }} ").render('product' => ProductDrop.new)
assert_equal ' ', output
end
end
def test_scope
assert_equal '1', Liquid::Template.parse( '{{ context.scopes }}' ).render('context' => ContextDrop.new)
assert_equal '2', Liquid::Template.parse( '{%for i in dummy%}{{ context.scopes }}{%endfor%}' ).render('context' => ContextDrop.new, 'dummy' => [1])
+11 -18
View File
@@ -14,22 +14,21 @@ class StrainerTest < Test::Unit::TestCase
private :private_filter
end
module TestingFilter
def test1
"test1"
end
def test2
"test2"
end
end
Strainer.global_filter(AccessScopeFilters)
Strainer.global_filter(TestingFilter)
def test_strainer
strainer = Strainer.create(nil)
assert_equal 5, strainer.invoke('size', 'input')
assert_equal "public", strainer.invoke("public_filter")
end
def test_strainer_only_invokes_public_filter_methods
strainer = Strainer.create(nil)
assert_equal "public", strainer.invoke("public_filter")
assert_equal false, strainer.invokable?('__test__')
assert_equal false, strainer.invokable?('test')
assert_equal false, strainer.invokable?('instance_eval')
assert_equal false, strainer.invokable?('__send__')
assert_equal true, strainer.invokable?('size') # from the standard lib
end
def test_strainer_returns_nil_if_no_filter_method_found
@@ -43,12 +42,6 @@ class StrainerTest < Test::Unit::TestCase
assert_equal "password", strainer.invoke("undef_the_method", "password")
end
def test_strainer_allows_multiple_filters
strainer = Strainer.create(nil)
assert_equal "test1", strainer.invoke("test1")
assert_equal "test2", strainer.invoke("test2")
end
def test_strainer_only_allows_methods_defined_in_filters
strainer = Strainer.create(nil)
assert_equal "1 + 1", strainer.invoke("instance_eval", "1 + 1")