forked from rpmessner/fluid
-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #23 from art4ride/master
global_filter
- Loading branch information
Showing
6 changed files
with
87 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
Code.require_file "../../test_helper.exs", __ENV__.file | ||
defmodule Liquid.GlobalFilterTest do | ||
use ExUnit.Case, async: false | ||
alias Liquid.Template | ||
|
||
defmodule MyFilter do | ||
def counting_sheeps(input) when is_binary(input), do: input <>" One, two, thr.. z-zz.." | ||
def counting_bees(input) when is_binary(input), do: input <>" One, tw.. Ouch!" | ||
end | ||
|
||
setup_all do | ||
Application.put_env(:liquid, :global_filter, &MyFilter.counting_sheeps/1) | ||
Liquid.start | ||
on_exit fn -> Liquid.stop Application.delete_env(:liquid, :global_filter) end | ||
:ok | ||
end | ||
|
||
test "env default filter applied" do | ||
assert_template_result "Initial One, two, thr.. z-zz..", "{{ 'initial' | capitalize }}" | ||
end | ||
|
||
test "preset filter overrides default applied" do | ||
assert_template_result "Initial One, tw.. Ouch!", | ||
"{{ 'initial' | capitalize }}", %{global_filter: &MyFilter.counting_bees/1} | ||
end | ||
|
||
|
||
defp assert_template_result(expected, markup, assigns \\ %{}) do | ||
assert_result(expected, markup, assigns) | ||
end | ||
|
||
defp assert_result(expected, markup, assigns) do | ||
template = Template.parse(markup) | ||
with { :ok, result, _ } <- Template.render(template, assigns) do | ||
assert result == expected | ||
else | ||
{ :error, message, _ } -> | ||
assert message == expected | ||
end | ||
end | ||
|
||
end |