Instiki 0.16.5

Update to Rails 2.3.2 (the stable Rails 2.3 release).
Add audio/speex support
Update CHANGELOG
Bump version number
This commit is contained in:
Jacques Distler 2009-03-16 09:55:30 -05:00
parent 801d307405
commit e2ccdfd812
264 changed files with 4850 additions and 1906 deletions

View file

@ -19,19 +19,19 @@ class ClassTest < Test::Unit::TestCase
def test_removing_class_in_root_namespace
assert A.is_a?(Class)
Class.remove_class(A)
assert_raises(NameError) { A.is_a?(Class) }
assert_raise(NameError) { A.is_a?(Class) }
end
def test_removing_class_in_one_level_namespace
assert X::B.is_a?(Class)
Class.remove_class(X::B)
assert_raises(NameError) { X::B.is_a?(Class) }
assert_raise(NameError) { X::B.is_a?(Class) }
end
def test_removing_class_in_two_level_namespace
assert Y::Z::C.is_a?(Class)
Class.remove_class(Y::Z::C)
assert_raises(NameError) { Y::Z::C.is_a?(Class) }
assert_raise(NameError) { Y::Z::C.is_a?(Class) }
end
def test_retrieving_subclasses

View file

@ -174,6 +174,13 @@ class HashExtTest < Test::Unit::TestCase
assert_equal 2, hash['b']
end
def test_indifferent_reverse_merging
hash = HashWithIndifferentAccess.new('some' => 'value', 'other' => 'value')
hash.reverse_merge!(:some => 'noclobber', :another => 'clobber')
assert_equal 'value', hash[:some]
assert_equal 'clobber', hash[:another]
end
def test_indifferent_deleting
get_hash = proc{ { :a => 'foo' }.with_indifferent_access }
hash = get_hash.call
@ -234,7 +241,7 @@ class HashExtTest < Test::Unit::TestCase
{ :failure => "stuff", :funny => "business" }.assert_valid_keys(:failure, :funny)
end
assert_raises(ArgumentError, "Unknown key(s): failore") do
assert_raise(ArgumentError, "Unknown key(s): failore") do
{ :failore => "stuff", :funny => "business" }.assert_valid_keys([ :failure, :funny ])
{ :failore => "stuff", :funny => "business" }.assert_valid_keys(:failure, :funny)
end
@ -490,6 +497,15 @@ class HashToXmlTest < Test::Unit::TestCase
assert xml.include?(%(<addresses type="array"><address><streets type="array"><street><name>))
end
def test_timezoned_attributes
xml = {
:created_at => Time.utc(1999,2,2),
:local_created_at => Time.utc(1999,2,2).in_time_zone('Eastern Time (US & Canada)')
}.to_xml(@xml_options)
assert_match %r{<created-at type=\"datetime\">1999-02-02T00:00:00Z</created-at>}, xml
assert_match %r{<local-created-at type=\"datetime\">1999-02-01T19:00:00-05:00</local-created-at>}, xml
end
def test_single_record_from_xml
topic_xml = <<-EOT
<topic>
@ -884,7 +900,13 @@ class QueryTest < Test::Unit::TestCase
end
def test_expansion_count_is_limited
assert_raises RuntimeError do
expected = {
'ActiveSupport::XmlMini_REXML' => 'RuntimeError',
'ActiveSupport::XmlMini_Nokogiri' => 'Nokogiri::XML::SyntaxError',
'ActiveSupport::XmlMini_LibXML' => 'LibXML::XML::Error',
}[ActiveSupport::XmlMini.backend.name].constantize
assert_raise expected do
attack_xml = <<-EOT
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE member [

View file

@ -2,10 +2,10 @@ require 'abstract_unit'
class TestMissingSourceFile < Test::Unit::TestCase
def test_with_require
assert_raises(MissingSourceFile) { require 'no_this_file_don\'t_exist' }
assert_raise(MissingSourceFile) { require 'no_this_file_don\'t_exist' }
end
def test_with_load
assert_raises(MissingSourceFile) { load 'nor_does_this_one' }
assert_raise(MissingSourceFile) { load 'nor_does_this_one' }
end
def test_path
begin load 'nor/this/one.rb'

View file

@ -28,14 +28,14 @@ class SynchronizationTest < Test::Unit::TestCase
end
def test_synchronize_with_no_mutex_raises_an_argument_error
assert_raises(ArgumentError) do
assert_raise(ArgumentError) do
@target.synchronize :to_s
end
end
def test_double_synchronize_raises_an_argument_error
@target.synchronize :to_s, :with => :mutex
assert_raises(ArgumentError) do
assert_raise(ArgumentError) do
@target.synchronize :to_s, :with => :mutex
end
end

View file

@ -92,8 +92,8 @@ class ModuleTest < Test::Unit::TestCase
end
def test_missing_delegation_target
assert_raises(ArgumentError) { eval($nowhere) }
assert_raises(ArgumentError) { eval($noplace) }
assert_raise(ArgumentError) { eval($nowhere) }
assert_raise(ArgumentError) { eval($noplace) }
end
def test_delegation_prefix
@ -141,7 +141,7 @@ class ModuleTest < Test::Unit::TestCase
def test_delegation_without_allow_nil_and_nil_value
david = Someone.new("David")
assert_raises(NoMethodError) { david.street }
assert_raise(NoMethodError) { david.street }
end
def test_parent
@ -314,7 +314,7 @@ class MethodAliasingTest < Test::Unit::TestCase
alias_method_chain :duck, :orange
end
assert_raises NoMethodError do
assert_raise NoMethodError do
@instance.duck
end
@ -330,7 +330,7 @@ class MethodAliasingTest < Test::Unit::TestCase
alias_method_chain :duck, :orange
end
assert_raises NoMethodError do
assert_raise NoMethodError do
@instance.duck
end

View file

@ -109,7 +109,7 @@ end
class ObjectTests < Test::Unit::TestCase
def test_suppress_re_raises
assert_raises(LoadError) { suppress(ArgumentError) {raise LoadError} }
assert_raise(LoadError) { suppress(ArgumentError) {raise LoadError} }
end
def test_suppress_supresses
suppress(ArgumentError) { raise ArgumentError }
@ -256,7 +256,7 @@ class ObjectTryTest < Test::Unit::TestCase
def test_nonexisting_method
method = :undefined_method
assert !@string.respond_to?(method)
assert_raises(NoMethodError) { @string.try(method) }
assert_raise(NoMethodError) { @string.try(method) }
end
def test_valid_method

View file

@ -77,6 +77,24 @@ class StringInflectionsTest < Test::Unit::TestCase
end
end
def test_string_parameterized_normal
StringToParameterized.each do |normal, slugged|
assert_equal(normal.parameterize, slugged)
end
end
def test_string_parameterized_no_separator
StringToParameterizeWithNoSeparator.each do |normal, slugged|
assert_equal(normal.parameterize(''), slugged)
end
end
def test_string_parameterized_underscore
StringToParameterizeWithUnderscore.each do |normal, slugged|
assert_equal(normal.parameterize('_'), slugged)
end
end
def test_humanize
UnderscoreToHuman.each do |underscore, human|
assert_equal(human, underscore.humanize)

View file

@ -751,7 +751,7 @@ class TimeWithZoneMethodsForTimeAndDateTimeTest < Test::Unit::TestCase
def test_use_zone_with_exception_raised
Time.zone = 'Alaska'
assert_raises RuntimeError do
assert_raise RuntimeError do
Time.use_zone('Hawaii') { raise RuntimeError }
end
assert_equal ActiveSupport::TimeZone['Alaska'], Time.zone

View file

@ -43,7 +43,7 @@ class DependenciesTest < Test::Unit::TestCase
end
def test_missing_dependency_raises_missing_source_file
assert_raises(MissingSourceFile) { require_dependency("missing_service") }
assert_raise(MissingSourceFile) { require_dependency("missing_service") }
end
def test_missing_association_raises_nothing
@ -136,10 +136,10 @@ class DependenciesTest < Test::Unit::TestCase
def test_non_existing_const_raises_name_error
with_loading 'autoloading_fixtures' do
assert_raises(NameError) { DoesNotExist }
assert_raises(NameError) { NoModule::DoesNotExist }
assert_raises(NameError) { A::DoesNotExist }
assert_raises(NameError) { A::B::DoesNotExist }
assert_raise(NameError) { DoesNotExist }
assert_raise(NameError) { NoModule::DoesNotExist }
assert_raise(NameError) { A::DoesNotExist }
assert_raise(NameError) { A::B::DoesNotExist }
end
end
@ -206,8 +206,8 @@ class DependenciesTest < Test::Unit::TestCase
def failing_test_access_thru_and_upwards_fails
with_loading 'autoloading_fixtures' do
assert ! defined?(ModuleFolder)
assert_raises(NameError) { ModuleFolder::Object }
assert_raises(NameError) { ModuleFolder::NestedClass::Object }
assert_raise(NameError) { ModuleFolder::Object }
assert_raise(NameError) { ModuleFolder::NestedClass::Object }
Object.__send__ :remove_const, :ModuleFolder
end
end
@ -382,7 +382,7 @@ class DependenciesTest < Test::Unit::TestCase
with_loading 'autoloading_fixtures' do
require_dependency '././counting_loader'
assert_equal 1, $counting_loaded_times
assert_raises(ArgumentError) { ActiveSupport::Dependencies.load_missing_constant Object, :CountingLoader }
assert_raise(ArgumentError) { ActiveSupport::Dependencies.load_missing_constant Object, :CountingLoader }
assert_equal 1, $counting_loaded_times
end
end
@ -421,7 +421,7 @@ class DependenciesTest < Test::Unit::TestCase
def test_nested_load_error_isnt_rescued
with_loading 'dependencies' do
assert_raises(MissingSourceFile) do
assert_raise(MissingSourceFile) do
RequiresNonexistent1
end
end
@ -494,7 +494,7 @@ class DependenciesTest < Test::Unit::TestCase
def test_unloadable_should_fail_with_anonymous_modules
with_loading 'autoloading_fixtures' do
m = Module.new
assert_raises(ArgumentError) { m.unloadable }
assert_raise(ArgumentError) { m.unloadable }
end
end
@ -584,7 +584,7 @@ class DependenciesTest < Test::Unit::TestCase
end
def test_new_constants_in_with_illegal_module_name_raises_correct_error
assert_raises(NameError) do
assert_raise(NameError) do
ActiveSupport::Dependencies.new_constants_in("Illegal-Name") {}
end
end

View file

@ -116,6 +116,12 @@ class InflectorTest < Test::Unit::TestCase
end
end
def test_parameterize_with_multi_character_separator
StringToParameterized.each do |some_string, parameterized_string|
assert_equal(parameterized_string.gsub('-', '__sep__'), ActiveSupport::Inflector.parameterize(some_string, '__sep__'))
end
end
def test_classify
ClassNameToTableName.each do |class_name, table_name|
assert_equal(class_name, ActiveSupport::Inflector.classify(table_name))
@ -161,13 +167,13 @@ class InflectorTest < Test::Unit::TestCase
assert_nothing_raised { assert_equal Ace::Base::Case, ActiveSupport::Inflector.constantize("::Ace::Base::Case") }
assert_nothing_raised { assert_equal InflectorTest, ActiveSupport::Inflector.constantize("InflectorTest") }
assert_nothing_raised { assert_equal InflectorTest, ActiveSupport::Inflector.constantize("::InflectorTest") }
assert_raises(NameError) { ActiveSupport::Inflector.constantize("UnknownClass") }
assert_raises(NameError) { ActiveSupport::Inflector.constantize("An invalid string") }
assert_raises(NameError) { ActiveSupport::Inflector.constantize("InvalidClass\n") }
assert_raise(NameError) { ActiveSupport::Inflector.constantize("UnknownClass") }
assert_raise(NameError) { ActiveSupport::Inflector.constantize("An invalid string") }
assert_raise(NameError) { ActiveSupport::Inflector.constantize("InvalidClass\n") }
end
def test_constantize_does_lexical_lookup
assert_raises(NameError) { ActiveSupport::Inflector.constantize("Ace::Base::InflectorTest") }
assert_raise(NameError) { ActiveSupport::Inflector.constantize("Ace::Base::InflectorTest") }
end
def test_ordinal

View file

@ -154,6 +154,22 @@ module InflectorTestCases
"Squeeze separators" => "squeeze-separators"
}
StringToParameterizeWithNoSeparator = {
"Donald E. Knuth" => "donaldeknuth",
"Random text with *(bad)* characters" => "randomtextwithbadcharacters",
"Trailing bad characters!@#" => "trailingbadcharacters",
"!@#Leading bad characters" => "leadingbadcharacters",
"Squeeze separators" => "squeezeseparators"
}
StringToParameterizeWithUnderscore = {
"Donald E. Knuth" => "donald_e_knuth",
"Random text with *(bad)* characters" => "random_text_with_bad_characters",
"Trailing bad characters!@#" => "trailing_bad_characters",
"!@#Leading bad characters" => "leading_bad_characters",
"Squeeze separators" => "squeeze_separators"
}
# Ruby 1.9 doesn't do Unicode normalization yet.
if RUBY_VERSION >= '1.9'
StringToParameterizedAndNormalized = {

View file

@ -28,7 +28,11 @@ class TestJSONDecoding < Test::Unit::TestCase
%(null) => nil,
%(true) => true,
%(false) => false,
%q("http:\/\/test.host\/posts\/1") => "http://test.host/posts/1"
%q("http:\/\/test.host\/posts\/1") => "http://test.host/posts/1",
%q("\u003cunicode\u0020escape\u003e") => "<unicode escape>",
%q("\\\\u0020skip double backslashes") => "\\u0020skip double backslashes",
%q({a: "\u003cbr /\u003e"}) => {'a' => "<br />"},
%q({b:["\u003ci\u003e","\u003cb\u003e","\u003cu\u003e"]}) => {'b' => ["<i>","<b>","<u>"]}
}
TESTS.each do |json, expected|
@ -40,6 +44,6 @@ class TestJSONDecoding < Test::Unit::TestCase
end
def test_failed_json_decoding
assert_raises(ActiveSupport::JSON::ParseError) { ActiveSupport::JSON.decode(%({: 1})) }
assert_raise(ActiveSupport::JSON::ParseError) { ActiveSupport::JSON.decode(%({: 1})) }
end
end

View file

@ -75,7 +75,7 @@ class TestJSONEncoding < Test::Unit::TestCase
def test_exception_raised_when_encoding_circular_reference
a = [1]
a << a
assert_raises(ActiveSupport::JSON::CircularReferenceError) { a.to_json }
assert_raise(ActiveSupport::JSON::CircularReferenceError) { a.to_json }
end
def test_hash_key_identifiers_are_always_quoted

View file

@ -4,10 +4,12 @@ class MemoizableTest < Test::Unit::TestCase
class Person
extend ActiveSupport::Memoizable
attr_reader :name_calls, :age_calls
attr_reader :name_calls, :age_calls, :is_developer_calls
def initialize
@name_calls = 0
@age_calls = 0
@is_developer_calls = 0
end
def name
@ -31,6 +33,14 @@ class MemoizableTest < Test::Unit::TestCase
end
memoize :name, :age
private
def is_developer?
@is_developer_calls += 1
"Yes"
end
memoize :is_developer?
end
class Company
@ -223,4 +233,15 @@ class MemoizableTest < Test::Unit::TestCase
company.memoize :name
assert_raise(RuntimeError) { company.memoize :name }
end
def test_private_method_memoization
person = Person.new
assert_raise(NoMethodError) { person.is_developer? }
assert_equal "Yes", person.send(:is_developer?)
assert_equal 1, person.is_developer_calls
assert_equal "Yes", person.send(:is_developer?)
assert_equal 1, person.is_developer_calls
end
end

View file

@ -33,7 +33,7 @@ class MessageEncryptorTest < Test::Unit::TestCase
private
def assert_not_decrypted(value)
assert_raises(ActiveSupport::MessageEncryptor::InvalidMessage) do
assert_raise(ActiveSupport::MessageEncryptor::InvalidMessage) do
@encryptor.decrypt(value)
end
end

View file

@ -18,7 +18,7 @@ class MessageVerifierTest < Test::Unit::TestCase
end
def assert_not_verified(message)
assert_raises(ActiveSupport::MessageVerifier::InvalidSignature) do
assert_raise(ActiveSupport::MessageVerifier::InvalidSignature) do
@verifier.verify(message)
end
end

View file

@ -26,7 +26,7 @@ class MultibyteCharsTest < Test::Unit::TestCase
assert_nothing_raised do
@chars.__method_for_multibyte_testing
end
assert_raises NoMethodError do
assert_raise NoMethodError do
@chars.__unknown_method
end
end
@ -71,7 +71,7 @@ class MultibyteCharsTest < Test::Unit::TestCase
end
def test_unpack_raises_encoding_error_on_broken_strings
assert_raises(ActiveSupport::Multibyte::EncodingError) do
assert_raise(ActiveSupport::Multibyte::EncodingError) do
@proxy_class.u_unpack(BYTE_STRING)
end
end
@ -123,7 +123,6 @@ class MultibyteCharsUTF8BehaviourTest < Test::Unit::TestCase
[:rstrip!, :lstrip!, :strip!, :reverse!, :upcase!, :downcase!, :capitalize!].each do |method|
assert_equal @chars.object_id, @chars.send(method).object_id
end
assert_equal @chars.object_id, @chars.slice!(1).object_id
end
def test_overridden_bang_methods_change_wrapped_string
@ -133,10 +132,6 @@ class MultibyteCharsUTF8BehaviourTest < Test::Unit::TestCase
proxy.send(method)
assert_not_equal original, proxy.to_s
end
proxy = chars('Café')
proxy.slice!(3)
assert_equal 'é', proxy.to_s
proxy = chars('òu')
proxy.capitalize!
assert_equal 'Òu', proxy.to_s
@ -214,8 +209,8 @@ class MultibyteCharsUTF8BehaviourTest < Test::Unit::TestCase
end
def test_insert_throws_index_error
assert_raises(IndexError) { @chars.insert(-12, 'わ')}
assert_raises(IndexError) { @chars.insert(12, 'わ') }
assert_raise(IndexError) { @chars.insert(-12, 'わ')}
assert_raise(IndexError) { @chars.insert(12, 'わ') }
end
def test_should_know_if_one_includes_the_other
@ -227,7 +222,7 @@ class MultibyteCharsUTF8BehaviourTest < Test::Unit::TestCase
end
def test_include_raises_type_error_when_nil_is_passed
assert_raises(TypeError) do
assert_raise(TypeError) do
@chars.include?(nil)
end
end
@ -262,22 +257,22 @@ class MultibyteCharsUTF8BehaviourTest < Test::Unit::TestCase
def test_indexed_insert_should_raise_on_index_overflow
before = @chars.to_s
assert_raises(IndexError) { @chars[10] = 'a' }
assert_raises(IndexError) { @chars[10, 4] = 'a' }
assert_raises(IndexError) { @chars[/ii/] = 'a' }
assert_raises(IndexError) { @chars[/()/, 10] = 'a' }
assert_raise(IndexError) { @chars[10] = 'a' }
assert_raise(IndexError) { @chars[10, 4] = 'a' }
assert_raise(IndexError) { @chars[/ii/] = 'a' }
assert_raise(IndexError) { @chars[/()/, 10] = 'a' }
assert_equal before, @chars
end
def test_indexed_insert_should_raise_on_range_overflow
before = @chars.to_s
assert_raises(RangeError) { @chars[10..12] = 'a' }
assert_raise(RangeError) { @chars[10..12] = 'a' }
assert_equal before, @chars
end
def test_rjust_should_raise_argument_errors_on_bad_arguments
assert_raises(ArgumentError) { @chars.rjust(10, '') }
assert_raises(ArgumentError) { @chars.rjust }
assert_raise(ArgumentError) { @chars.rjust(10, '') }
assert_raise(ArgumentError) { @chars.rjust }
end
def test_rjust_should_count_characters_instead_of_bytes
@ -294,8 +289,8 @@ class MultibyteCharsUTF8BehaviourTest < Test::Unit::TestCase
end
def test_ljust_should_raise_argument_errors_on_bad_arguments
assert_raises(ArgumentError) { @chars.ljust(10, '') }
assert_raises(ArgumentError) { @chars.ljust }
assert_raise(ArgumentError) { @chars.ljust(10, '') }
assert_raise(ArgumentError) { @chars.ljust }
end
def test_ljust_should_count_characters_instead_of_bytes
@ -312,8 +307,8 @@ class MultibyteCharsUTF8BehaviourTest < Test::Unit::TestCase
end
def test_center_should_raise_argument_errors_on_bad_arguments
assert_raises(ArgumentError) { @chars.center(10, '') }
assert_raises(ArgumentError) { @chars.center }
assert_raise(ArgumentError) { @chars.center(10, '') }
assert_raise(ArgumentError) { @chars.center }
end
def test_center_should_count_charactes_instead_of_bytes
@ -391,6 +386,15 @@ class MultibyteCharsUTF8BehaviourTest < Test::Unit::TestCase
assert_equal nil, @chars.slice(7..6)
end
def test_slice_bang_returns_sliced_out_substring
assert_equal 'にち', @chars.slice!(1..2)
end
def test_slice_bang_removes_the_slice_from_the_receiver
@chars.slice!(1..2)
assert_equal 'こわ', @chars
end
def test_slice_should_throw_exceptions_on_invalid_arguments
assert_raise(TypeError) { @chars.slice(2..3, 1) }
assert_raise(TypeError) { @chars.slice(1, 2..3) }
@ -436,7 +440,7 @@ class MultibyteCharsExtrasTest < Test::Unit::TestCase
if RUBY_VERSION >= '1.9'
def test_tidy_bytes_is_broken_on_1_9_0
assert_raises(ArgumentError) do
assert_raise(ArgumentError) do
assert_equal_codepoints [0xfffd].pack('U'), chars("\xef\xbf\xbd").tidy_bytes
end
end

View file

@ -10,6 +10,6 @@ class StringInquirerTest < Test::Unit::TestCase
end
def test_missing_question_mark
assert_raises(NoMethodError) { ActiveSupport::StringInquirer.new("production").production }
assert_raise(NoMethodError) { ActiveSupport::StringInquirer.new("production").production }
end
end

View file

@ -244,7 +244,7 @@ class TimeZoneTest < Test::Unit::TestCase
assert_nil ActiveSupport::TimeZone["bogus"]
assert_instance_of ActiveSupport::TimeZone, ActiveSupport::TimeZone["Central Time (US & Canada)"]
assert_instance_of ActiveSupport::TimeZone, ActiveSupport::TimeZone[8]
assert_raises(ArgumentError) { ActiveSupport::TimeZone[false] }
assert_raise(ArgumentError) { ActiveSupport::TimeZone[false] }
end
def test_new

View file

@ -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

View file

@ -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