Ruby 1.9.1 bugfixes

Signed-off-by: Tobias Lütke <[email protected]>
This commit is contained in:
Jakub Kuźma
2009-04-17 06:33:25 +08:00
committed by Tobias Lütke
parent 37580976db
commit 8d27864845
5 changed files with 175 additions and 178 deletions
-3
View File
@@ -87,7 +87,6 @@ module Liquid
end end
def interpret_condition(left, right, op, context) def interpret_condition(left, right, op, context)
# If the operator is empty this means that the decision statement is just # If the operator is empty this means that the decision statement is just
# a single variable. We can just poll this variable from the context and # a single variable. We can just poll this variable from the context and
# return this as the result. # return this as the result.
@@ -95,7 +94,6 @@ module Liquid
left, right = context[left], context[right] left, right = context[left], context[right]
operation = self.class.operators[op] || raise(ArgumentError.new("Unknown operator #{op}")) operation = self.class.operators[op] || raise(ArgumentError.new("Unknown operator #{op}"))
if operation.respond_to?(:call) if operation.respond_to?(:call)
@@ -110,7 +108,6 @@ module Liquid
class ElseCondition < Condition class ElseCondition < Condition
def else? def else?
true true
end end
+3 -2
View File
@@ -29,7 +29,9 @@ module Liquid
# called by liquid to invoke a drop # called by liquid to invoke a drop
def invoke_drop(method) def invoke_drop(method)
if self.class.public_instance_methods.include?(method.to_s) # for backward compatibility with Ruby 1.8
methods = self.class.public_instance_methods.map { |m| m.to_s }
if methods.include?(method.to_s)
send(method.to_sym) send(method.to_sym)
else else
before_method(method) before_method(method)
@@ -46,5 +48,4 @@ module Liquid
alias :[] :invoke_drop alias :[] :invoke_drop
end end
end end
+10 -11
View File
@@ -190,9 +190,10 @@ class ContextTest < Test::Unit::TestCase
end end
context = Context.new(@template) context = Context.new(@template)
methods = context.strainer.methods methods_before = context.strainer.methods.map { |method| method.to_s }
context.add_filters(filter) context.add_filters(filter)
assert_equal (methods + ['hi']).sort, context.strainer.methods.sort methods_after = context.strainer.methods.map { |method| method.to_s }
assert_equal (methods_before + ["hi"]).sort, methods_after.sort
end end
def test_add_item_in_outer_scope def test_add_item_in_outer_scope
@@ -289,11 +290,9 @@ class ContextTest < Test::Unit::TestCase
end end
def test_access_hashes_with_hash_notation def test_access_hashes_with_hash_notation
@context['products'] = {'count' => 5, 'tags' => ['deepsnow', 'freestyle'] } @context['products'] = {'count' => 5, 'tags' => ['deepsnow', 'freestyle'] }
@context['product'] = {'variants' => [ {'title' => 'draft151cm'}, {'title' => 'element151cm'} ]} @context['product'] = {'variants' => [ {'title' => 'draft151cm'}, {'title' => 'element151cm'} ]}
assert_equal 5, @context['products["count"]'] assert_equal 5, @context['products["count"]']
assert_equal 'deepsnow', @context['products["tags"][0]'] assert_equal 'deepsnow', @context['products["tags"][0]']
assert_equal 'deepsnow', @context['products["tags"].first'] assert_equal 'deepsnow', @context['products["tags"].first']
@@ -417,25 +416,25 @@ class ContextTest < Test::Unit::TestCase
end end
def test_lambda_as_variable def test_lambda_as_variable
@context['dynamic'] = lambda { 'Hello' } @context['dynamic'] = proc { 'Hello' }
assert_equal 'Hello', @context['dynamic'] assert_equal 'Hello', @context['dynamic']
end end
def test_nested_lambda_as_variable def test_nested_lambda_as_variable
@context['dynamic'] = { "lambda" => lambda { 'Hello' } } @context['dynamic'] = { "lambda" => proc { 'Hello' } }
assert_equal 'Hello', @context['dynamic.lambda'] assert_equal 'Hello', @context['dynamic.lambda']
end end
def test_array_containing_lambda_as_variable def test_array_containing_lambda_as_variable
@context['dynamic'] = [1,2, lambda { 'Hello' } ,4,5] @context['dynamic'] = [1,2, proc { 'Hello' } ,4,5]
assert_equal 'Hello', @context['dynamic[2]'] assert_equal 'Hello', @context['dynamic[2]']
end end
def test_lambda_is_called_once def test_lambda_is_called_once
@context['callcount'] = lambda { @global ||= 0; @global += 1; @global.to_s } @context['callcount'] = proc { @global ||= 0; @global += 1; @global.to_s }
assert_equal '1', @context['callcount'] assert_equal '1', @context['callcount']
assert_equal '1', @context['callcount'] assert_equal '1', @context['callcount']
@@ -445,7 +444,7 @@ class ContextTest < Test::Unit::TestCase
end end
def test_nested_lambda_is_called_once def test_nested_lambda_is_called_once
@context['callcount'] = { "lambda" => lambda { @global ||= 0; @global += 1; @global.to_s } } @context['callcount'] = { "lambda" => proc { @global ||= 0; @global += 1; @global.to_s } }
assert_equal '1', @context['callcount.lambda'] assert_equal '1', @context['callcount.lambda']
assert_equal '1', @context['callcount.lambda'] assert_equal '1', @context['callcount.lambda']
@@ -455,7 +454,7 @@ class ContextTest < Test::Unit::TestCase
end end
def test_lambda_in_array_is_called_once def test_lambda_in_array_is_called_once
@context['callcount'] = [1,2, lambda { @global ||= 0; @global += 1; @global.to_s } ,4,5] @context['callcount'] = [1,2, proc { @global ||= 0; @global += 1; @global.to_s } ,4,5]
assert_equal '1', @context['callcount[2]'] assert_equal '1', @context['callcount[2]']
assert_equal '1', @context['callcount[2]'] assert_equal '1', @context['callcount[2]']
@@ -467,7 +466,7 @@ class ContextTest < Test::Unit::TestCase
def test_access_to_context_from_proc def test_access_to_context_from_proc
@context.registers[:magic] = 345392 @context.registers[:magic] = 345392
@context['magic'] = lambda { @context.registers[:magic] } @context['magic'] = proc { @context.registers[:magic] }
assert_equal 345392, @context['magic'] assert_equal 345392, @context['magic']
end end