diff options
author | Jeffrey Hardy <packagethief@gmail.com> | 2009-03-23 23:15:47 -0400 |
---|---|---|
committer | Jeffrey Hardy <packagethief@gmail.com> | 2009-03-23 23:15:47 -0400 |
commit | 76556b08bb8d22dccd7c44e302f625442c5cc8f0 (patch) | |
tree | 560889c89fcaac57778b6cfe2ba135fd70a69f5c /activesupport/test/xml_mini | |
parent | 4b6458bf4cbf14007878b84a3fbc193f3365eebe (diff) | |
parent | f7bdfe8bb76f7830cc2946cf0fcda2bb6d5e3e78 (diff) | |
download | rails-76556b08bb8d22dccd7c44e302f625442c5cc8f0.tar.gz rails-76556b08bb8d22dccd7c44e302f625442c5cc8f0.tar.bz2 rails-76556b08bb8d22dccd7c44e302f625442c5cc8f0.zip |
Merge branch 'master' of git://github.com/lifo/docrails
* 'master' of git://github.com/lifo/docrails: (259 commits)
Fix a small typo
ensure authors get warnings about broken links, and ensure end users don't
in guides generator, warn about duplicate header IDs only if WARN_DUPLICATE_HEADERS
replace edit distance implementation with one written from scratch to avoid license issues
removes a wrong comment in the finders guide
updates fxn picture
thanks but release notes are mostly frozen once they are published, and provide only an overview of the new stuff
Added extra notes to nested model forms explanation in 2.3 release notes to cover has_one relationships
clarifies a bit more what's the issue with check boxes and arrays of parameters
be even more ambiguous about the order of generation of hidden input for check boxes in form helper guide
this page referred to an :href_options keyword hash, in fact the correct keyword (the one the code responds to) is :html
update explanation of check box generation according to f400209
Hidden field with check box goes first.
update rack fixture to be ruby 1.9 compat
Better error message to try to figure out why the CI build is failing
ruby 1.9 compat: Pathname doesn't support =~
update rack fixture to be ruby 1.9 compat
update metal fixtures to be ruby 1.9 compat
Fix brittle Time.now mock
Ensure our bundled version of rack is at the front of the load path
...
Diffstat (limited to 'activesupport/test/xml_mini')
-rw-r--r-- | activesupport/test/xml_mini/nokogiri_engine_test.rb | 157 | ||||
-rw-r--r-- | activesupport/test/xml_mini/rexml_engine_test.rb | 15 |
2 files changed, 172 insertions, 0 deletions
diff --git a/activesupport/test/xml_mini/nokogiri_engine_test.rb b/activesupport/test/xml_mini/nokogiri_engine_test.rb new file mode 100644 index 0000000000..e5174a0b57 --- /dev/null +++ b/activesupport/test/xml_mini/nokogiri_engine_test.rb @@ -0,0 +1,157 @@ +require 'abstract_unit' +require 'active_support/xml_mini' + +begin + gem 'nokogiri', '>= 1.1.1' +rescue Gem::LoadError + # Skip nokogiri tests +else + +require 'nokogiri' + +class NokogiriEngineTest < Test::Unit::TestCase + include ActiveSupport + + def setup + @default_backend = XmlMini.backend + XmlMini.backend = 'Nokogiri' + end + + def teardown + XmlMini.backend = @default_backend + end + + def test_file_from_xml + hash = Hash.from_xml(<<-eoxml) + <blog> + <logo type="file" name="logo.png" content_type="image/png"> + </logo> + </blog> + eoxml + assert hash.has_key?('blog') + assert hash['blog'].has_key?('logo') + + file = hash['blog']['logo'] + assert_equal 'logo.png', file.original_filename + assert_equal 'image/png', file.content_type + end + + def test_exception_thrown_on_expansion_attack + assert_raise Nokogiri::XML::SyntaxError do + attack_xml = <<-EOT + <?xml version="1.0" encoding="UTF-8"?> + <!DOCTYPE member [ + <!ENTITY a "&b;&b;&b;&b;&b;&b;&b;&b;&b;&b;"> + <!ENTITY b "&c;&c;&c;&c;&c;&c;&c;&c;&c;&c;"> + <!ENTITY c "&d;&d;&d;&d;&d;&d;&d;&d;&d;&d;"> + <!ENTITY d "&e;&e;&e;&e;&e;&e;&e;&e;&e;&e;"> + <!ENTITY e "&f;&f;&f;&f;&f;&f;&f;&f;&f;&f;"> + <!ENTITY f "&g;&g;&g;&g;&g;&g;&g;&g;&g;&g;"> + <!ENTITY g "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"> + ]> + <member> + &a; + </member> + EOT + Hash.from_xml(attack_xml) + end + end + + def test_setting_nokogiri_as_backend + XmlMini.backend = 'Nokogiri' + assert_equal XmlMini_Nokogiri, XmlMini.backend + end + + def test_blank_returns_empty_hash + assert_equal({}, XmlMini.parse(nil)) + assert_equal({}, XmlMini.parse('')) + end + + def test_array_type_makes_an_array + assert_equal_rexml(<<-eoxml) + <blog> + <posts type="array"> + <post>a post</post> + <post>another post</post> + </posts> + </blog> + eoxml + end + + def test_one_node_document_as_hash + assert_equal_rexml(<<-eoxml) + <products/> + eoxml + end + + def test_one_node_with_attributes_document_as_hash + assert_equal_rexml(<<-eoxml) + <products foo="bar"/> + eoxml + end + + def test_products_node_with_book_node_as_hash + assert_equal_rexml(<<-eoxml) + <products> + <book name="awesome" id="12345" /> + </products> + eoxml + end + + def test_products_node_with_two_book_nodes_as_hash + assert_equal_rexml(<<-eoxml) + <products> + <book name="awesome" id="12345" /> + <book name="america" id="67890" /> + </products> + eoxml + end + + def test_single_node_with_content_as_hash + assert_equal_rexml(<<-eoxml) + <products> + hello world + </products> + eoxml + end + + def test_children_with_children + assert_equal_rexml(<<-eoxml) + <root> + <products> + <book name="america" id="67890" /> + </products> + </root> + eoxml + end + + def test_children_with_text + assert_equal_rexml(<<-eoxml) + <root> + <products> + hello everyone + </products> + </root> + eoxml + end + + def test_children_with_non_adjacent_text + assert_equal_rexml(<<-eoxml) + <root> + good + <products> + hello everyone + </products> + morning + </root> + eoxml + end + + private + def assert_equal_rexml(xml) + hash = XmlMini.with_backend('REXML') { XmlMini.parse(xml) } + assert_equal(hash, XmlMini.parse(xml)) + end +end + +end diff --git a/activesupport/test/xml_mini/rexml_engine_test.rb b/activesupport/test/xml_mini/rexml_engine_test.rb new file mode 100644 index 0000000000..a412d8ca05 --- /dev/null +++ b/activesupport/test/xml_mini/rexml_engine_test.rb @@ -0,0 +1,15 @@ +require 'abstract_unit' +require 'active_support/xml_mini' + +class REXMLEngineTest < Test::Unit::TestCase + include ActiveSupport + + def test_default_is_rexml + assert_equal XmlMini_REXML, XmlMini.backend + end + + def test_set_rexml_as_backend + XmlMini.backend = 'REXML' + assert_equal XmlMini_REXML, XmlMini.backend + end +end |