Add tests.

Need to fix up the assertions to match the output.
This commit is contained in:
Parker Moore 2014-11-05 11:37:51 -08:00
parent 9a15a09028
commit b29fd6d380
1 changed files with 17 additions and 6 deletions

View File

@ -148,13 +148,24 @@ class TestFilters < Test::Unit::TestCase
assert_equal "[{\"name\":\"Jack\"},{\"name\":\"Smith\"}]", @filter.jsonify([{:name => 'Jack'}, {:name => 'Smith'}])
end
should "call #to_liquid " do
class AThing < Struct.new(:name)
def to_liquid
{ "name" => name, :v => 1 }
end
class M < Struct.new(:message)
def to_liquid
[message]
end
assert_equal "[{\"name\":\"Jeremiah\",\"v\":1},{\"name\":\"Smathers\",\"v\":1}]", @filter.jsonify([AThing.new("Jeremiah"), AThing.new("Smathers")])
end
class T < Struct.new(:name)
def to_liquid
{ "name" => name, :v => 1, :thing => M.new({:kay => "jewelers"}) }
end
end
should "call #to_liquid " do
assert_equal "[{\"name\":\"Jeremiah\",\"v\":1},{\"name\":\"Smathers\",\"v\":1}]", @filter.jsonify([T.new("Jeremiah"), T.new("Smathers")])
end
should "handle hashes with all sorts of weird keys and values" do
my_hash = { "posts" => Array.new(5) { |i| T.new(i) } }
assert_equal "{}", @filter.jsonify(my_hash)
end
end