require 'test_helper' class HtmlFormatTest < ActiveSupport::TestCase setup do HtmlFormat.default_options[:table_class] = ["foo"] end test "html_format" do assert_nil html_format(nil) assert_equal "
1
", html_format(1) end test "to_html" do assert_equal "
1
", 1.to_html assert_nil [].to_html assert_nil "".to_html end test "array of hash" do v = [ {id: 1, name: "alice", created_at: "2000-01-01"}, {id: 2, name: "bob", created_at: "2000-01-02"}, {id: 3, name: "carol", created_at: "2000-01-03"}, ] assert_equal "
idnamecreated_at
1alice2000-01-01
2bob2000-01-02
3carol2000-01-03
", v.to_html end test "hash"do v = {id: 1, name: "alice", created_at: "2000-01-01"} assert_equal "
id1
namealice
created_at2000-01-01
", v.to_html end test "array of array" do v = [ [1, 2, 3], [4, 5, 6], [7, 8, 9], ] assert_equal "
123
456
789
", v.to_html end test "array" do assert_equal "
0123
", [0, 1, 2, 3].to_html end test "title option" do assert_equal "

(title)

0
", [0].to_html(title: "(title)") end end