add test to use variable in where_exp condition

This commit is contained in:
Florian Thomas 2016-08-31 00:43:07 +02:00 committed by Parker Moore
parent 61cdebf272
commit b76b4a4e8a
No known key found for this signature in database
GPG Key ID: 193CDEBA72063C58
1 changed files with 15 additions and 6 deletions

View File

@ -9,7 +9,7 @@ class TestFilters < JekyllUnitTest
def initialize(opts = {}) def initialize(opts = {})
@site = Jekyll::Site.new(opts.merge("skip_config_files" => true)) @site = Jekyll::Site.new(opts.merge("skip_config_files" => true))
@context = Liquid::Context.new({}, {}, { :site => @site }) @context = Liquid::Context.new(@site.site_payload, {}, { :site => @site })
end end
end end
@ -26,12 +26,13 @@ class TestFilters < JekyllUnitTest
context "filters" do context "filters" do
setup do setup do
@sample_time = Time.utc(2013, 3, 27, 11, 22, 33)
@filter = make_filter_mock({ @filter = make_filter_mock({
"timezone" => "UTC", "timezone" => "UTC",
"url" => "http://example.com", "url" => "http://example.com",
"baseurl" => "/base", "baseurl" => "/base",
"dont_show_posts_before" => @sample_time,
}) })
@sample_time = Time.utc(2013, 3, 27, 11, 22, 33)
@sample_date = Date.parse("2013-03-27") @sample_date = Date.parse("2013-03-27")
@time_as_string = "September 11, 2001 12:46:30 -0000" @time_as_string = "September 11, 2001 12:46:30 -0000"
@time_as_numeric = 1_399_680_607 @time_as_numeric = 1_399_680_607
@ -816,6 +817,14 @@ class TestFilters < JekyllUnitTest
results = @filter.where_exp(SelectDummy.new, "obj", "1 == 1") results = @filter.where_exp(SelectDummy.new, "obj", "1 == 1")
assert_equal [], results assert_equal [], results
end end
should "filter by variable values" do
@filter.site.tap(&:read)
posts = @filter.site.site_payload["site"]["posts"]
results = @filter.where_exp(posts, "post",
"post.date > site.dont_show_posts_before")
assert_equal posts.select { |p| p.date > @sample_time }.count, results.length
end
end end
context "group_by_exp filter" do context "group_by_exp filter" do