mirror of
https://github.com/kemko/liquid.git
synced 2026-01-06 02:05:41 +03:00
Three tests in the test suite use the Liquid::Template.register_filter function to register custom filters with Liquid::Strainer. The problem is that these register_filter calls leave the Liquid::Strainer object in an altered state. As an example, the FiltersTest's test_local_filter relies on the default behavior of Liquid::Strainer operator, and the test was failing if register_function had been called earlier. The same thing was happening with FiltersInTemplate's test_local_global. The problem was present when the Filters test classes were loaded inside a single ruby process that also loaded HashOrderingTest. One example is "rake test", which runs "require" on every test file. Another basic example is the following command: ruby -Itest -e "require 'integration/hash_ordering_test'; require 'integration/filter_test'" Update the tests to always reset Liquid::Strainer's filters back to the default list of filters. With this change, FiltersTest and FiltersInTemplate now pass.
37 lines
865 B
Ruby
37 lines
865 B
Ruby
require 'test_helper'
|
|
|
|
class ContextTest < Minitest::Test
|
|
include Liquid
|
|
|
|
def test_override_global_filter
|
|
global = Module.new do
|
|
def notice(output)
|
|
"Global #{output}"
|
|
end
|
|
end
|
|
|
|
local = Module.new do
|
|
def notice(output)
|
|
"Local #{output}"
|
|
end
|
|
end
|
|
|
|
original_filters = Array.new(Strainer.class_eval('@@filters'))
|
|
Template.register_filter(global)
|
|
assert_equal 'Global test', Template.parse("{{'test' | notice }}").render!
|
|
assert_equal 'Local test', Template.parse("{{'test' | notice }}").render!({}, :filters => [local])
|
|
ensure
|
|
Strainer.class_eval('@@filters = ' + original_filters.to_s)
|
|
end
|
|
|
|
def test_has_key_will_not_add_an_error_for_missing_keys
|
|
Template.error_mode = :strict
|
|
|
|
context = Context.new
|
|
|
|
context.has_key?('unknown')
|
|
|
|
assert_empty context.errors
|
|
end
|
|
end
|