aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport
diff options
context:
space:
mode:
authorJon Moss <me@jonathanmoss.me>2016-11-20 09:06:17 -0500
committerJon Moss <me@jonathanmoss.me>2016-11-20 10:45:58 -0500
commit2bdc4ddc065cb395f287f1511f9cb14059a66652 (patch)
treecf8e66db7139fbaa696e40018068e7ac2dfe8143 /activesupport
parent305e2922a4b358f0ae5630672b6144d3013b603d (diff)
downloadrails-2bdc4ddc065cb395f287f1511f9cb14059a66652.tar.gz
rails-2bdc4ddc065cb395f287f1511f9cb14059a66652.tar.bz2
rails-2bdc4ddc065cb395f287f1511f9cb14059a66652.zip
Code styling cleanup
Diffstat (limited to 'activesupport')
-rw-r--r--activesupport/test/xml_mini/common.rb238
-rw-r--r--activesupport/test/xml_mini/jdom_engine_test.rb16
-rw-r--r--activesupport/test/xml_mini/libxml_engine_test.rb12
-rw-r--r--activesupport/test/xml_mini/libxmlsax_engine_test.rb12
-rw-r--r--activesupport/test/xml_mini/nokogiri_engine_test.rb12
-rw-r--r--activesupport/test/xml_mini/nokogirisax_engine_test.rb12
-rw-r--r--activesupport/test/xml_mini/rexml_engine_test.rb12
7 files changed, 162 insertions, 152 deletions
diff --git a/activesupport/test/xml_mini/common.rb b/activesupport/test/xml_mini/common.rb
index 900fb31ba3..c97bbf7e35 100644
--- a/activesupport/test/xml_mini/common.rb
+++ b/activesupport/test/xml_mini/common.rb
@@ -1,22 +1,24 @@
module CommonXMLMiniAdapterTest
def setup
@default_backend = ActiveSupport::XmlMini.backend
- ActiveSupport::XmlMini.backend = adapter_name
+ ActiveSupport::XmlMini.backend = engine
+ super
end
def teardown
ActiveSupport::XmlMini.backend = @default_backend
+ super
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")
+ <blog>
+ <logo type="file" name="logo.png" content_type="image/png">
+ </logo>
+ </blog>
+ eoxml
+ assert hash.key?("blog")
+ assert hash["blog"].key?("logo")
file = hash["blog"]["logo"]
assert_equal "logo.png", file.original_filename
@@ -25,29 +27,26 @@ module CommonXMLMiniAdapterTest
def test_exception_thrown_on_expansion_attack
assert_raise expansion_attack_error 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)
+ Hash.from_xml(<<-eoxml)
+ <?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>
+ eoxml
end
end
def test_setting_backend
- ActiveSupport::XmlMini.backend = adapter_name
- assert_equal ActiveSupport.const_get("XmlMini_#{adapter_name}"), ActiveSupport::XmlMini.backend
- #assert_equal ActiveSupport::XmlMini_Nokogiri
+ assert_engine_class ActiveSupport::XmlMini.backend
end
def test_blank_returns_empty_hash
@@ -57,161 +56,164 @@ module CommonXMLMiniAdapterTest
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
+ <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/>
+ <products/>
eoxml
end
def test_one_node_with_attributes_document_as_hash
assert_equal_rexml(<<-eoxml)
- <products foo="bar"/>
+ <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
+ <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
+ <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
+ <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
+ <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
+ <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
+ <root>
+ good
+ <products>
+ hello everyone
+ </products>
+ morning
+ </root>
+ eoxml
end
def test_parse_from_io
- jdom_skip
-
- io = StringIO.new(<<-eoxml)
- <root>
- good
- <products>
- hello everyone
- </products>
- morning
- </root>
- eoxml
- assert_equal_rexml(io)
+ skip_unless_extended_engine
+
+ assert_equal_rexml(StringIO.new(<<-eoxml))
+ <root>
+ good
+ <products>
+ hello everyone
+ </products>
+ morning
+ </root>
+ eoxml
end
def test_children_with_simple_cdata
- jdom_skip
+ skip_unless_extended_engine
assert_equal_rexml(<<-eoxml)
- <root>
- <products>
- <![CDATA[cdatablock]]>
- </products>
- </root>
- eoxml
+ <root>
+ <products>
+ <![CDATA[cdatablock]]>
+ </products>
+ </root>
+ eoxml
end
def test_children_with_multiple_cdata
- jdom_skip
+ skip_unless_extended_engine
assert_equal_rexml(<<-eoxml)
- <root>
- <products>
- <![CDATA[cdatablock1]]><![CDATA[cdatablock2]]>
- </products>
- </root>
- eoxml
+ <root>
+ <products>
+ <![CDATA[cdatablock1]]><![CDATA[cdatablock2]]>
+ </products>
+ </root>
+ eoxml
end
def test_children_with_text_and_cdata
- jdom_skip
+ skip_unless_extended_engine
assert_equal_rexml(<<-eoxml)
- <root>
- <products>
- hello <![CDATA[cdatablock]]>
- morning
- </products>
- </root>
- eoxml
+ <root>
+ <products>
+ hello <![CDATA[cdatablock]]>
+ morning
+ </products>
+ </root>
+ eoxml
end
def test_children_with_blank_text
- jdom_skip
+ skip_unless_extended_engine
assert_equal_rexml(<<-eoxml)
- <root>
- <products> </products>
- </root>
- eoxml
+ <root>
+ <products> </products>
+ </root>
+ eoxml
end
def test_children_with_blank_text_and_attribute
- jdom_skip
+ skip_unless_extended_engine
assert_equal_rexml(<<-eoxml)
- <root>
- <products type="file"> </products>
- </root>
- eoxml
+ <root>
+ <products type="file"> </products>
+ </root>
+ eoxml
end
private
- def adapter_name
+ def engine
raise NotImplementedError
end
+ def assert_engine_class(actual)
+ assert_equal ActiveSupport.const_get("XmlMini_#{engine}"), actual
+ end
+
def assert_equal_rexml(xml)
parsed_xml = ActiveSupport::XmlMini.parse(xml)
xml.rewind if xml.respond_to?(:rewind)
@@ -223,7 +225,11 @@ module CommonXMLMiniAdapterTest
raise NotImplementedError
end
- def jdom_skip
- skip "JDOM does not support this test" if adapter_name == "JDOM"
+ def extended_engine?
+ true
+ end
+
+ def skip_unless_extended_engine
+ skip "#{engine} is not an extended engine" unless extended_engine?
end
end
diff --git a/activesupport/test/xml_mini/jdom_engine_test.rb b/activesupport/test/xml_mini/jdom_engine_test.rb
index f42fc195cc..3034bc7148 100644
--- a/activesupport/test/xml_mini/jdom_engine_test.rb
+++ b/activesupport/test/xml_mini/jdom_engine_test.rb
@@ -42,12 +42,16 @@ if RUBY_PLATFORM.include?("java")
private
- def adapter_name
- "JDOM"
- end
+ def engine
+ "JDOM"
+ end
- def expansion_attack_error
- Java::OrgXmlSax::SAXParseException
- end
+ def expansion_attack_error
+ Java::OrgXmlSax::SAXParseException
+ end
+
+ def extended_engine?
+ false
+ end
end
end
diff --git a/activesupport/test/xml_mini/libxml_engine_test.rb b/activesupport/test/xml_mini/libxml_engine_test.rb
index ff4759b082..13f66cdfe7 100644
--- a/activesupport/test/xml_mini/libxml_engine_test.rb
+++ b/activesupport/test/xml_mini/libxml_engine_test.rb
@@ -18,12 +18,12 @@ else
private
- def adapter_name
- "LibXML"
- end
+ def engine
+ "LibXML"
+ end
- def expansion_attack_error
- LibXML::XML::Error
- end
+ def expansion_attack_error
+ LibXML::XML::Error
+ end
end
end
diff --git a/activesupport/test/xml_mini/libxmlsax_engine_test.rb b/activesupport/test/xml_mini/libxmlsax_engine_test.rb
index 73eff9ac44..eb128d533d 100644
--- a/activesupport/test/xml_mini/libxmlsax_engine_test.rb
+++ b/activesupport/test/xml_mini/libxmlsax_engine_test.rb
@@ -13,12 +13,12 @@ else
private
- def adapter_name
- "LibXMLSAX"
- end
+ def engine
+ "LibXMLSAX"
+ end
- def expansion_attack_error
- LibXML::XML::Error
- end
+ def expansion_attack_error
+ LibXML::XML::Error
+ end
end
end
diff --git a/activesupport/test/xml_mini/nokogiri_engine_test.rb b/activesupport/test/xml_mini/nokogiri_engine_test.rb
index b0c4985a50..3f976a3b57 100644
--- a/activesupport/test/xml_mini/nokogiri_engine_test.rb
+++ b/activesupport/test/xml_mini/nokogiri_engine_test.rb
@@ -13,12 +13,12 @@ else
private
- def expansion_attack_error
- Nokogiri::XML::SyntaxError
- end
+ def engine
+ "Nokogiri"
+ end
- def adapter_name
- "Nokogiri"
- end
+ def expansion_attack_error
+ Nokogiri::XML::SyntaxError
+ end
end
end
diff --git a/activesupport/test/xml_mini/nokogirisax_engine_test.rb b/activesupport/test/xml_mini/nokogirisax_engine_test.rb
index 5be339b826..823c6243bb 100644
--- a/activesupport/test/xml_mini/nokogirisax_engine_test.rb
+++ b/activesupport/test/xml_mini/nokogirisax_engine_test.rb
@@ -13,12 +13,12 @@ else
private
- def adapter_name
- "NokogiriSAX"
- end
+ def engine
+ "NokogiriSAX"
+ end
- def expansion_attack_error
- RuntimeError
- end
+ def expansion_attack_error
+ RuntimeError
+ end
end
end
diff --git a/activesupport/test/xml_mini/rexml_engine_test.rb b/activesupport/test/xml_mini/rexml_engine_test.rb
index 0f4e690746..4222436ae8 100644
--- a/activesupport/test/xml_mini/rexml_engine_test.rb
+++ b/activesupport/test/xml_mini/rexml_engine_test.rb
@@ -20,11 +20,11 @@ class REXMLEngineTest < ActiveSupport::TestCase
private
- def adapter_name
- "REXML"
- end
+ def engine
+ "REXML"
+ end
- def expansion_attack_error
- RuntimeError
- end
+ def expansion_attack_error
+ RuntimeError
+ end
end