mirror of
https://github.com/Shopify/liquid.git
synced 2026-10-03 00:55:11 -07:00
Merge pull request #1534 from Shopify/context-test-cleanup
Context test cleanup
This commit is contained in:
@@ -24,7 +24,7 @@ class ContextSensitiveDrop < Liquid::Drop
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class Category < Liquid::Drop
|
class Category
|
||||||
attr_accessor :name
|
attr_accessor :name
|
||||||
|
|
||||||
def initialize(name)
|
def initialize(name)
|
||||||
@@ -36,8 +36,9 @@ class Category < Liquid::Drop
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class CategoryDrop
|
class CategoryDrop < Liquid::Drop
|
||||||
attr_accessor :category, :context
|
attr_accessor :category, :context
|
||||||
|
|
||||||
def initialize(category)
|
def initialize(category)
|
||||||
@category = category
|
@category = category
|
||||||
end
|
end
|
||||||
@@ -405,45 +406,42 @@ class ContextTest < Minitest::Test
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_lambda_is_called_once
|
def test_lambda_is_called_once
|
||||||
|
@global = 0
|
||||||
|
|
||||||
@context['callcount'] = proc {
|
@context['callcount'] = proc {
|
||||||
@global ||= 0
|
@global += 1
|
||||||
@global += 1
|
|
||||||
@global.to_s
|
@global.to_s
|
||||||
}
|
}
|
||||||
|
|
||||||
assert_equal('1', @context['callcount'])
|
assert_equal('1', @context['callcount'])
|
||||||
assert_equal('1', @context['callcount'])
|
assert_equal('1', @context['callcount'])
|
||||||
assert_equal('1', @context['callcount'])
|
assert_equal('1', @context['callcount'])
|
||||||
|
|
||||||
@global = nil
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_nested_lambda_is_called_once
|
def test_nested_lambda_is_called_once
|
||||||
|
@global = 0
|
||||||
|
|
||||||
@context['callcount'] = { "lambda" => proc {
|
@context['callcount'] = { "lambda" => proc {
|
||||||
@global ||= 0
|
@global += 1
|
||||||
@global += 1
|
|
||||||
@global.to_s
|
@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'])
|
||||||
assert_equal('1', @context['callcount.lambda'])
|
assert_equal('1', @context['callcount.lambda'])
|
||||||
|
|
||||||
@global = nil
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_lambda_in_array_is_called_once
|
def test_lambda_in_array_is_called_once
|
||||||
|
@global = 0
|
||||||
|
|
||||||
@context['callcount'] = [1, 2, proc {
|
@context['callcount'] = [1, 2, proc {
|
||||||
@global ||= 0
|
@global += 1
|
||||||
@global += 1
|
|
||||||
@global.to_s
|
@global.to_s
|
||||||
}, 4, 5]
|
}, 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]'])
|
||||||
assert_equal('1', @context['callcount[2]'])
|
assert_equal('1', @context['callcount[2]'])
|
||||||
|
|
||||||
@global = nil
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_access_to_context_from_proc
|
def test_access_to_context_from_proc
|
||||||
|
|||||||
Reference in New Issue
Block a user