mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
added tests for XmlMini#to_tag.
This commit is contained in:
parent
eba8411652
commit
54f3aa8633
1 changed files with 93 additions and 54 deletions
|
@ -1,7 +1,9 @@
|
|||
require 'abstract_unit'
|
||||
require 'active_support/xml_mini'
|
||||
require 'active_support/builder'
|
||||
|
||||
class XmlMiniTest < Test::Unit::TestCase
|
||||
module XmlMiniTest
|
||||
class RenameKeyTest < Test::Unit::TestCase
|
||||
def test_rename_key_dasherizes_by_default
|
||||
assert_equal "my-key", ActiveSupport::XmlMini.rename_key("my_key")
|
||||
end
|
||||
|
@ -57,5 +59,42 @@ class XmlMiniTest < Test::Unit::TestCase
|
|||
def test_rename_key_does_not_dasherize_multiple_leading_underscores
|
||||
assert_equal "id__", ActiveSupport::XmlMini.rename_key("id__")
|
||||
end
|
||||
end
|
||||
|
||||
class ToTagTest < ActiveSupport::TestCase
|
||||
def assert_xml(xml)
|
||||
assert_equal xml, @options[:builder].target!
|
||||
end
|
||||
|
||||
setup do
|
||||
@xml = ActiveSupport::XmlMini
|
||||
@options = {:skip_instruct => true, :builder => Builder::XmlMarkup.new}
|
||||
end
|
||||
|
||||
test "#to_tag accepts a callable object and passes options with the builder" do
|
||||
@xml.to_tag(:some_tag, lambda {|o| o[:builder].br }, @options)
|
||||
assert_xml "<br/>"
|
||||
end
|
||||
|
||||
test "#to_tag accepts a callable object and passes options and tag name" do
|
||||
@xml.to_tag(:tag, lambda {|o, t| o[:builder].b(t) }, @options)
|
||||
assert_xml "<b>tag</b>"
|
||||
end
|
||||
|
||||
test "#to_tag accepts an object responding to #to_xml and passes the options, where :root is key" do
|
||||
obj = Object.new
|
||||
obj.instance_eval do
|
||||
def to_xml(options) options[:builder].yo(options[:root].to_s) end
|
||||
end
|
||||
|
||||
@xml.to_tag(:tag, obj, @options)
|
||||
assert_xml "<yo>tag</yo>"
|
||||
end
|
||||
|
||||
test "#to_tag accepts arbitrary objects responding to #to_str" do
|
||||
@xml.to_tag(:b, "Howdy", @options)
|
||||
assert_xml "<b>Howdy</b>"
|
||||
end
|
||||
# TODO: test the remaining functions hidden in #to_tag.
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue