From 803548c46b32d1be760b21da80477f43b801b8e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Sat, 7 May 2011 22:44:33 +0200 Subject: xml_mini_test.rb now runs. --- activesupport/lib/active_support/xml_mini.rb | 1 + activesupport/test/test_xml_mini.rb | 100 --------------------------- activesupport/test/xml_mini_test.rb | 92 ++++++++++++++++++++++++ 3 files changed, 93 insertions(+), 100 deletions(-) delete mode 100644 activesupport/test/test_xml_mini.rb create mode 100644 activesupport/test/xml_mini_test.rb (limited to 'activesupport') diff --git a/activesupport/lib/active_support/xml_mini.rb b/activesupport/lib/active_support/xml_mini.rb index cddfcddb57..dff8a8f4c4 100644 --- a/activesupport/lib/active_support/xml_mini.rb +++ b/activesupport/lib/active_support/xml_mini.rb @@ -1,4 +1,5 @@ require 'active_support/core_ext/module/delegation' +require 'active_support/core_ext/string/inflections' module ActiveSupport # = XmlMini diff --git a/activesupport/test/test_xml_mini.rb b/activesupport/test/test_xml_mini.rb deleted file mode 100644 index 6dbcd1f40b..0000000000 --- a/activesupport/test/test_xml_mini.rb +++ /dev/null @@ -1,100 +0,0 @@ -require 'abstract_unit' -require 'active_support/xml_mini' -require 'active_support/builder' - -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 - - def test_rename_key_does_nothing_with_dasherize_true - assert_equal "my-key", ActiveSupport::XmlMini.rename_key("my_key", :dasherize => true) - end - - def test_rename_key_does_nothing_with_dasherize_false - assert_equal "my_key", ActiveSupport::XmlMini.rename_key("my_key", :dasherize => false) - end - - def test_rename_key_camelizes_with_camelize_false - assert_equal "my_key", ActiveSupport::XmlMini.rename_key("my_key", :camelize => false) - end - - def test_rename_key_camelizes_with_camelize_nil - assert_equal "my_key", ActiveSupport::XmlMini.rename_key("my_key", :camelize => nil) - end - - def test_rename_key_camelizes_with_camelize_true - assert_equal "MyKey", ActiveSupport::XmlMini.rename_key("my_key", :camelize => true) - end - - def test_rename_key_lower_camelizes_with_camelize_lower - assert_equal "myKey", ActiveSupport::XmlMini.rename_key("my_key", :camelize => :lower) - end - - def test_rename_key_lower_camelizes_with_camelize_upper - assert_equal "MyKey", ActiveSupport::XmlMini.rename_key("my_key", :camelize => :upper) - end - - def test_rename_key_does_not_dasherize_leading_underscores - assert_equal "_id", ActiveSupport::XmlMini.rename_key("_id") - end - - def test_rename_key_with_leading_underscore_dasherizes_interior_underscores - assert_equal "_my-key", ActiveSupport::XmlMini.rename_key("_my_key") - end - - def test_rename_key_does_not_dasherize_trailing_underscores - assert_equal "id_", ActiveSupport::XmlMini.rename_key("id_") - end - - def test_rename_key_with_trailing_underscore_dasherizes_interior_underscores - assert_equal "my-key_", ActiveSupport::XmlMini.rename_key("my_key_") - end - - def test_rename_key_does_not_dasherize_multiple_leading_underscores - assert_equal "__id", ActiveSupport::XmlMini.rename_key("__id") - end - - 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 "
" - 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 "tag" - 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 "tag" - end - - test "#to_tag accepts arbitrary objects responding to #to_str" do - @xml.to_tag(:b, "Howdy", @options) - assert_xml "Howdy" - end - # TODO: test the remaining functions hidden in #to_tag. - end -end diff --git a/activesupport/test/xml_mini_test.rb b/activesupport/test/xml_mini_test.rb new file mode 100644 index 0000000000..bf6b0b283d --- /dev/null +++ b/activesupport/test/xml_mini_test.rb @@ -0,0 +1,92 @@ +require 'abstract_unit' +require 'active_support/xml_mini' +require 'active_support/builder' + +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 + + def test_rename_key_does_nothing_with_dasherize_true + assert_equal "my-key", ActiveSupport::XmlMini.rename_key("my_key", :dasherize => true) + end + + def test_rename_key_does_nothing_with_dasherize_false + assert_equal "my_key", ActiveSupport::XmlMini.rename_key("my_key", :dasherize => false) + end + + def test_rename_key_camelizes_with_camelize_true + assert_equal "MyKey", ActiveSupport::XmlMini.rename_key("my_key", :camelize => true) + end + + def test_rename_key_lower_camelizes_with_camelize_lower + assert_equal "myKey", ActiveSupport::XmlMini.rename_key("my_key", :camelize => :lower) + end + + def test_rename_key_lower_camelizes_with_camelize_upper + assert_equal "MyKey", ActiveSupport::XmlMini.rename_key("my_key", :camelize => :upper) + end + + def test_rename_key_does_not_dasherize_leading_underscores + assert_equal "_id", ActiveSupport::XmlMini.rename_key("_id") + end + + def test_rename_key_with_leading_underscore_dasherizes_interior_underscores + assert_equal "_my-key", ActiveSupport::XmlMini.rename_key("_my_key") + end + + def test_rename_key_does_not_dasherize_trailing_underscores + assert_equal "id_", ActiveSupport::XmlMini.rename_key("id_") + end + + def test_rename_key_with_trailing_underscore_dasherizes_interior_underscores + assert_equal "my-key_", ActiveSupport::XmlMini.rename_key("my_key_") + end + + def test_rename_key_does_not_dasherize_multiple_leading_underscores + assert_equal "__id", ActiveSupport::XmlMini.rename_key("__id") + end + + 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 "
" + 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 "tag" + 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 "tag" + end + + test "#to_tag accepts arbitrary objects responding to #to_str" do + @xml.to_tag(:b, "Howdy", @options) + assert_xml "Howdy" + end + # TODO: test the remaining functions hidden in #to_tag. + end +end -- cgit v1.2.3