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:
parent
801d307405
commit
e2ccdfd812
264 changed files with 4850 additions and 1906 deletions
8
vendor/rails/activesupport/CHANGELOG
vendored
8
vendor/rails/activesupport/CHANGELOG
vendored
|
@ -1,4 +1,7 @@
|
|||
*2.3.1 [RC2] (March 5, 2009)*
|
||||
*2.3.2 [Final] (March 15, 2009)*
|
||||
|
||||
* XmlMini supports LibXML and Nokogiri backends. #2084, #2190 [Bart ten Brinke, Aaron Patterson]
|
||||
Example: XmlMini.backend = 'Nokogiri'
|
||||
|
||||
* Vendorize i18n 0.1.3 gem (fixes issues with incompatible character encodings in Ruby 1.9) #2038 [Akira Matsuda]
|
||||
|
||||
|
@ -12,9 +15,6 @@
|
|||
|
||||
* Introduce Array.wrap(foo) to wrap the argument in an array unless it's already an array. Wraps nil as an empty array. Use instead of Array(foo) and foo.to_a since they treat String as Enumerable. [Jeremy Kemper]
|
||||
|
||||
|
||||
*2.3.0 [RC1] (February 1st, 2009)*
|
||||
|
||||
* TimeWithZone#xmlschema accepts optional fraction_digits argument [#1725 state:resolved] [Nicholas Dainty]
|
||||
|
||||
* Object#tap shim for Ruby < 1.8.7. Similar to Object#returning, tap yields self then returns self. [Jeremy Kemper]
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
module ActiveSupport #:nodoc:
|
||||
module CoreExtensions #:nodoc:
|
||||
module Date #:nodoc:
|
||||
# Enables the use of time calculations within Time itself
|
||||
# Enables the use of time calculations within Date itself
|
||||
module Calculations
|
||||
def self.included(base) #:nodoc:
|
||||
base.extend ClassMethods
|
||||
|
|
|
@ -24,11 +24,12 @@ module ActiveSupport #:nodoc:
|
|||
"Bignum" => "integer",
|
||||
"BigDecimal" => "decimal",
|
||||
"Float" => "float",
|
||||
"TrueClass" => "boolean",
|
||||
"FalseClass" => "boolean",
|
||||
"Date" => "date",
|
||||
"DateTime" => "datetime",
|
||||
"Time" => "datetime",
|
||||
"TrueClass" => "boolean",
|
||||
"FalseClass" => "boolean"
|
||||
"ActiveSupport::TimeWithZone" => "datetime"
|
||||
} unless defined?(XML_TYPE_NAMES)
|
||||
|
||||
XML_FORMATTING = {
|
||||
|
|
|
@ -91,6 +91,12 @@ class HashWithIndifferentAccess < Hash
|
|||
self.dup.update(hash)
|
||||
end
|
||||
|
||||
# Performs the opposite of merge, with the keys and values from the first hash taking precedence over the second.
|
||||
# This overloaded definition prevents returning a regular hash, if reverse_merge is called on a HashWithDifferentAccess.
|
||||
def reverse_merge(other_hash)
|
||||
super other_hash.with_indifferent_access
|
||||
end
|
||||
|
||||
# Removes a specified key from the hash.
|
||||
def delete(key)
|
||||
super(convert_key(key))
|
||||
|
|
|
@ -102,8 +102,8 @@ module ActiveSupport #:nodoc:
|
|||
#
|
||||
# <%= link_to(@person.name, person_path %>
|
||||
# # => <a href="/person/1-donald-e-knuth">Donald E. Knuth</a>
|
||||
def parameterize
|
||||
Inflector.parameterize(self)
|
||||
def parameterize(sep = '-')
|
||||
Inflector.parameterize(self, sep)
|
||||
end
|
||||
|
||||
# Creates the name of a table like Rails does for models to table names. This method
|
||||
|
|
|
@ -257,15 +257,17 @@ module ActiveSupport
|
|||
# <%= link_to(@person.name, person_path(@person)) %>
|
||||
# # => <a href="/person/1-donald-e-knuth">Donald E. Knuth</a>
|
||||
def parameterize(string, sep = '-')
|
||||
re_sep = Regexp.escape(sep)
|
||||
# replace accented chars with ther ascii equivalents
|
||||
parameterized_string = transliterate(string)
|
||||
# Turn unwanted chars into the seperator
|
||||
parameterized_string.gsub!(/[^a-z0-9\-_\+]+/i, sep)
|
||||
# No more than one of the separator in a row.
|
||||
parameterized_string.squeeze!(sep)
|
||||
# Remove leading/trailing separator.
|
||||
parameterized_string.gsub!(/^#{re_sep}|#{re_sep}$/i, '')
|
||||
unless sep.blank?
|
||||
re_sep = Regexp.escape(sep)
|
||||
# No more than one of the separator in a row.
|
||||
parameterized_string.gsub!(/#{re_sep}{2,}/, sep)
|
||||
# Remove leading/trailing separator.
|
||||
parameterized_string.gsub!(/^#{re_sep}|#{re_sep}$/i, '')
|
||||
end
|
||||
parameterized_string.downcase
|
||||
end
|
||||
|
||||
|
|
|
@ -43,14 +43,32 @@ module ActiveSupport
|
|||
end
|
||||
|
||||
if marks.empty?
|
||||
json.gsub(/\\\//, '/')
|
||||
json.gsub(/\\([\\\/]|u[[:xdigit:]]{4})/) do
|
||||
ustr = $1
|
||||
if ustr.starts_with?('u')
|
||||
[ustr[1..-1].to_i(16)].pack("U")
|
||||
elsif ustr == '\\'
|
||||
'\\\\'
|
||||
else
|
||||
ustr
|
||||
end
|
||||
end
|
||||
else
|
||||
left_pos = [-1].push(*marks)
|
||||
right_pos = marks << scanner.pos + scanner.rest_size
|
||||
output = []
|
||||
left_pos.each_with_index do |left, i|
|
||||
scanner.pos = left.succ
|
||||
output << scanner.peek(right_pos[i] - scanner.pos + 1)
|
||||
output << scanner.peek(right_pos[i] - scanner.pos + 1).gsub(/\\([\\\/]|u[[:xdigit:]]{4})/) do
|
||||
ustr = $1
|
||||
if ustr.starts_with?('u')
|
||||
[ustr[1..-1].to_i(16)].pack("U")
|
||||
elsif ustr == '\\'
|
||||
'\\\\'
|
||||
else
|
||||
ustr
|
||||
end
|
||||
end
|
||||
end
|
||||
output = output * " "
|
||||
|
||||
|
|
|
@ -88,6 +88,10 @@ module ActiveSupport
|
|||
#{original_method}(*args) # _unmemoized_mime_type(*args)
|
||||
end # end
|
||||
end # end
|
||||
end # end
|
||||
#
|
||||
if private_method_defined?(#{original_method.inspect}) # if private_method_defined?(:_unmemoized_mime_type)
|
||||
private #{symbol.inspect} # private :mime_type
|
||||
end # end
|
||||
EOS
|
||||
end
|
||||
|
|
|
@ -344,7 +344,19 @@ module ActiveSupport #:nodoc:
|
|||
end
|
||||
alias_method :[], :slice
|
||||
|
||||
# Converts first character in the string to Unicode value
|
||||
# Like <tt>String#slice!</tt>, except instead of byte offsets you specify character offsets.
|
||||
#
|
||||
# Example:
|
||||
# s = 'こんにちは'
|
||||
# s.mb_chars.slice!(2..3).to_s #=> "にち"
|
||||
# s #=> "こんは"
|
||||
def slice!(*args)
|
||||
slice = self[*args]
|
||||
self[*args] = ''
|
||||
slice
|
||||
end
|
||||
|
||||
# Returns the codepoint of the first character in the string.
|
||||
#
|
||||
# Example:
|
||||
# 'こんにちは'.mb_chars.ord #=> 12371
|
||||
|
@ -432,7 +444,7 @@ module ActiveSupport #:nodoc:
|
|||
chars(self.class.tidy_bytes(@wrapped_string))
|
||||
end
|
||||
|
||||
%w(lstrip rstrip strip reverse upcase downcase slice tidy_bytes capitalize).each do |method|
|
||||
%w(lstrip rstrip strip reverse upcase downcase tidy_bytes capitalize).each do |method|
|
||||
define_method("#{method}!") do |*args|
|
||||
unless args.nil?
|
||||
@wrapped_string = send(method, *args).to_s
|
||||
|
|
|
@ -45,7 +45,12 @@ module ActiveSupport
|
|||
return if @method_name.to_s == "default_test"
|
||||
|
||||
if using_mocha = respond_to?(:mocha_verify)
|
||||
assertion_counter = Mocha::TestCaseAdapter::AssertionCounter.new(result)
|
||||
assertion_counter_klass = if defined?(Mocha::TestCaseAdapter::AssertionCounter)
|
||||
Mocha::TestCaseAdapter::AssertionCounter
|
||||
else
|
||||
Mocha::Integration::TestUnit::AssertionCounter
|
||||
end
|
||||
assertion_counter = assertion_counter_klass.new(result)
|
||||
end
|
||||
|
||||
yield(Test::Unit::TestCase::STARTED, name)
|
||||
|
|
|
@ -116,10 +116,10 @@ class I18nTest < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
def test_localize_nil_raises_argument_error
|
||||
assert_raises(I18n::ArgumentError) { I18n.l nil }
|
||||
assert_raise(I18n::ArgumentError) { I18n.l nil }
|
||||
end
|
||||
|
||||
def test_localize_object_raises_argument_error
|
||||
assert_raises(I18n::ArgumentError) { I18n.l Object.new }
|
||||
assert_raise(I18n::ArgumentError) { I18n.l Object.new }
|
||||
end
|
||||
end
|
||||
|
|
|
@ -155,7 +155,7 @@ class I18nSimpleBackendTranslateTest < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
def test_translate_given_an_array_of_inexistent_keys_it_raises_missing_translation_data
|
||||
assert_raises I18n::MissingTranslationData do
|
||||
assert_raise I18n::MissingTranslationData do
|
||||
@backend.translate('en', :does_not_exist, :scope => [:foo], :default => [:does_not_exist_2, :does_not_exist_3])
|
||||
end
|
||||
end
|
||||
|
@ -180,11 +180,11 @@ class I18nSimpleBackendTranslateTest < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
def test_translate_given_nil_as_a_locale_raises_an_argument_error
|
||||
assert_raises(I18n::InvalidLocale){ @backend.translate nil, :bar }
|
||||
assert_raise(I18n::InvalidLocale){ @backend.translate nil, :bar }
|
||||
end
|
||||
|
||||
def test_translate_with_a_bogus_key_and_no_default_raises_missing_translation_data
|
||||
assert_raises(I18n::MissingTranslationData){ @backend.translate 'de', :bogus }
|
||||
assert_raise(I18n::MissingTranslationData){ @backend.translate 'de', :bogus }
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -230,15 +230,15 @@ class I18nSimpleBackendPluralizeTest < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
def test_interpolate_given_incomplete_pluralization_data_raises_invalid_pluralization_data
|
||||
assert_raises(I18n::InvalidPluralizationData){ @backend.send(:pluralize, nil, {:one => 'bar'}, 2) }
|
||||
assert_raise(I18n::InvalidPluralizationData){ @backend.send(:pluralize, nil, {:one => 'bar'}, 2) }
|
||||
end
|
||||
|
||||
# def test_interpolate_given_a_string_raises_invalid_pluralization_data
|
||||
# assert_raises(I18n::InvalidPluralizationData){ @backend.send(:pluralize, nil, 'bar', 2) }
|
||||
# assert_raise(I18n::InvalidPluralizationData){ @backend.send(:pluralize, nil, 'bar', 2) }
|
||||
# end
|
||||
#
|
||||
# def test_interpolate_given_an_array_raises_invalid_pluralization_data
|
||||
# assert_raises(I18n::InvalidPluralizationData){ @backend.send(:pluralize, nil, ['bar'], 2) }
|
||||
# assert_raise(I18n::InvalidPluralizationData){ @backend.send(:pluralize, nil, ['bar'], 2) }
|
||||
# end
|
||||
end
|
||||
|
||||
|
@ -267,13 +267,13 @@ class I18nSimpleBackendInterpolateTest < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
def test_interpolate_given_an_unicode_value_hash_into_a_non_unicode_multibyte_string_raises_encoding_compatibility_error
|
||||
assert_raises(Encoding::CompatibilityError) do
|
||||
assert_raise(Encoding::CompatibilityError) do
|
||||
@backend.send(:interpolate, nil, euc_jp('こんにちは、{{name}}さん!'), :name => 'ゆきひろ')
|
||||
end
|
||||
end
|
||||
|
||||
def test_interpolate_given_a_non_unicode_multibyte_value_hash_into_an_unicode_string_raises_encoding_compatibility_error
|
||||
assert_raises(Encoding::CompatibilityError) do
|
||||
assert_raise(Encoding::CompatibilityError) do
|
||||
@backend.send(:interpolate, nil, 'こんにちは、{{name}}さん!', :name => euc_jp('ゆきひろ'))
|
||||
end
|
||||
end
|
||||
|
@ -292,11 +292,11 @@ class I18nSimpleBackendInterpolateTest < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
def test_interpolate_given_an_empty_values_hash_raises_missing_interpolation_argument
|
||||
assert_raises(I18n::MissingInterpolationArgument) { @backend.send(:interpolate, nil, 'Hi {{name}}!', {}) }
|
||||
assert_raise(I18n::MissingInterpolationArgument) { @backend.send(:interpolate, nil, 'Hi {{name}}!', {}) }
|
||||
end
|
||||
|
||||
def test_interpolate_given_a_string_containing_a_reserved_key_raises_reserved_interpolation_key
|
||||
assert_raises(I18n::ReservedInterpolationKey) { @backend.send(:interpolate, nil, '{{default}}', {:default => nil}) }
|
||||
assert_raise(I18n::ReservedInterpolationKey) { @backend.send(:interpolate, nil, '{{default}}', {:default => nil}) }
|
||||
end
|
||||
|
||||
private
|
||||
|
@ -352,11 +352,11 @@ class I18nSimpleBackendLocalizeDateTest < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
def test_localize_nil_raises_argument_error
|
||||
assert_raises(I18n::ArgumentError) { @backend.localize 'de', nil }
|
||||
assert_raise(I18n::ArgumentError) { @backend.localize 'de', nil }
|
||||
end
|
||||
|
||||
def test_localize_object_raises_argument_error
|
||||
assert_raises(I18n::ArgumentError) { @backend.localize 'de', Object.new }
|
||||
assert_raise(I18n::ArgumentError) { @backend.localize 'de', Object.new }
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -486,7 +486,7 @@ class I18nSimpleBackendLoadTranslationsTest < Test::Unit::TestCase
|
|||
include I18nSimpleBackendTestSetup
|
||||
|
||||
def test_load_translations_with_unknown_file_type_raises_exception
|
||||
assert_raises(I18n::UnknownFileType) { @backend.load_translations "#{@locale_dir}/en.xml" }
|
||||
assert_raise(I18n::UnknownFileType) { @backend.load_translations "#{@locale_dir}/en.xml" }
|
||||
end
|
||||
|
||||
def test_load_translations_with_ruby_file_type_does_not_raise_exception
|
||||
|
|
|
@ -2,7 +2,7 @@ module ActiveSupport
|
|||
module VERSION #:nodoc:
|
||||
MAJOR = 2
|
||||
MINOR = 3
|
||||
TINY = 1
|
||||
TINY = 2
|
||||
|
||||
STRING = [MAJOR, MINOR, TINY].join('.')
|
||||
end
|
||||
|
|
|
@ -1,113 +1,31 @@
|
|||
# = XmlMini
|
||||
# This is a derivitive work of XmlSimple 1.0.11
|
||||
# Author:: Joseph Holsten <joseph@josephholsten.com>
|
||||
# Copyright:: Copyright (c) 2008 Joseph Holsten
|
||||
# Copyright:: Copyright (c) 2003-2006 Maik Schmidt <contact@maik-schmidt.de>
|
||||
# License:: Distributes under the same terms as Ruby.
|
||||
module ActiveSupport
|
||||
# = XmlMini
|
||||
#
|
||||
# To use the much faster libxml parser:
|
||||
# gem 'libxml-ruby', '=0.9.7'
|
||||
# XmlMini.backend = 'LibXML'
|
||||
module XmlMini
|
||||
extend self
|
||||
|
||||
CONTENT_KEY = '__content__'.freeze
|
||||
attr_reader :backend
|
||||
delegate :parse, :to => :backend
|
||||
|
||||
# Parse an XML Document string into a simple hash
|
||||
#
|
||||
# Same as XmlSimple::xml_in but doesn't shoot itself in the foot,
|
||||
# and uses the defaults from ActiveSupport
|
||||
#
|
||||
# string::
|
||||
# XML Document string to parse
|
||||
def parse(string)
|
||||
require 'rexml/document' unless defined?(REXML::Document)
|
||||
doc = REXML::Document.new(string)
|
||||
merge_element!({}, doc.root)
|
||||
def backend=(name)
|
||||
if name.is_a?(Module)
|
||||
@backend = name
|
||||
else
|
||||
require "active_support/xml_mini/#{name.to_s.downcase}.rb"
|
||||
@backend = ActiveSupport.const_get("XmlMini_#{name}")
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
# Convert an XML element and merge into the hash
|
||||
#
|
||||
# hash::
|
||||
# Hash to merge the converted element into.
|
||||
# element::
|
||||
# XML element to merge into hash
|
||||
def merge_element!(hash, element)
|
||||
merge!(hash, element.name, collapse(element))
|
||||
end
|
||||
|
||||
# Actually converts an XML document element into a data structure.
|
||||
#
|
||||
# element::
|
||||
# The document element to be collapsed.
|
||||
def collapse(element)
|
||||
hash = get_attributes(element)
|
||||
|
||||
if element.has_elements?
|
||||
element.each_element {|child| merge_element!(hash, child) }
|
||||
merge_texts!(hash, element) unless empty_content?(element)
|
||||
hash
|
||||
else
|
||||
merge_texts!(hash, element)
|
||||
end
|
||||
end
|
||||
|
||||
# Merge all the texts of an element into the hash
|
||||
#
|
||||
# hash::
|
||||
# Hash to add the converted emement to.
|
||||
# element::
|
||||
# XML element whose texts are to me merged into the hash
|
||||
def merge_texts!(hash, element)
|
||||
unless element.has_text?
|
||||
hash
|
||||
else
|
||||
# must use value to prevent double-escaping
|
||||
merge!(hash, CONTENT_KEY, element.texts.sum(&:value))
|
||||
end
|
||||
end
|
||||
|
||||
# Adds a new key/value pair to an existing Hash. If the key to be added
|
||||
# already exists and the existing value associated with key is not
|
||||
# an Array, it will be wrapped in an Array. Then the new value is
|
||||
# appended to that Array.
|
||||
#
|
||||
# hash::
|
||||
# Hash to add key/value pair to.
|
||||
# key::
|
||||
# Key to be added.
|
||||
# value::
|
||||
# Value to be associated with key.
|
||||
def merge!(hash, key, value)
|
||||
if hash.has_key?(key)
|
||||
if hash[key].instance_of?(Array)
|
||||
hash[key] << value
|
||||
else
|
||||
hash[key] = [hash[key], value]
|
||||
end
|
||||
elsif value.instance_of?(Array)
|
||||
hash[key] = [value]
|
||||
else
|
||||
hash[key] = value
|
||||
end
|
||||
hash
|
||||
end
|
||||
|
||||
# Converts the attributes array of an XML element into a hash.
|
||||
# Returns an empty Hash if node has no attributes.
|
||||
#
|
||||
# element::
|
||||
# XML element to extract attributes from.
|
||||
def get_attributes(element)
|
||||
attributes = {}
|
||||
element.attributes.each { |n,v| attributes[n] = v }
|
||||
attributes
|
||||
end
|
||||
|
||||
# Determines if a document element has text content
|
||||
#
|
||||
# element::
|
||||
# XML element to be checked.
|
||||
def empty_content?(element)
|
||||
element.texts.join.blank?
|
||||
end
|
||||
def with_backend(name)
|
||||
old_backend, self.backend = backend, name
|
||||
yield
|
||||
ensure
|
||||
self.backend = old_backend
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
XmlMini.backend = 'REXML'
|
||||
end
|
||||
|
|
133
vendor/rails/activesupport/lib/active_support/xml_mini/libxml.rb
vendored
Normal file
133
vendor/rails/activesupport/lib/active_support/xml_mini/libxml.rb
vendored
Normal file
|
@ -0,0 +1,133 @@
|
|||
require 'libxml'
|
||||
|
||||
# = XmlMini LibXML implementation
|
||||
module ActiveSupport
|
||||
module XmlMini_LibXML #:nodoc:
|
||||
extend self
|
||||
|
||||
# Parse an XML Document string into a simple hash using libxml.
|
||||
# string::
|
||||
# XML Document string to parse
|
||||
def parse(string)
|
||||
LibXML::XML.default_keep_blanks = false
|
||||
|
||||
if string.blank?
|
||||
{}
|
||||
else
|
||||
LibXML::XML::Parser.string(string.strip).parse.to_hash
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
module LibXML
|
||||
module Conversions
|
||||
module Document
|
||||
def to_hash
|
||||
root.to_hash
|
||||
end
|
||||
end
|
||||
|
||||
module Node
|
||||
CONTENT_ROOT = '__content__'
|
||||
LIB_XML_LIMIT = 30000000 # Hardcoded LibXML limit
|
||||
|
||||
# Convert XML document to hash
|
||||
#
|
||||
# hash::
|
||||
# Hash to merge the converted element into.
|
||||
def to_hash(hash={})
|
||||
if text?
|
||||
raise LibXML::XML::Error if content.length >= LIB_XML_LIMIT
|
||||
hash[CONTENT_ROOT] = content
|
||||
else
|
||||
sub_hash = insert_name_into_hash(hash, name)
|
||||
attributes_to_hash(sub_hash)
|
||||
if array?
|
||||
children_array_to_hash(sub_hash)
|
||||
elsif yaml?
|
||||
children_yaml_to_hash(sub_hash)
|
||||
else
|
||||
children_to_hash(sub_hash)
|
||||
end
|
||||
end
|
||||
hash
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
# Insert name into hash
|
||||
#
|
||||
# hash::
|
||||
# Hash to merge the converted element into.
|
||||
# name::
|
||||
# name to to merge into hash
|
||||
def insert_name_into_hash(hash, name)
|
||||
sub_hash = {}
|
||||
if hash[name]
|
||||
if !hash[name].kind_of? Array
|
||||
hash[name] = [hash[name]]
|
||||
end
|
||||
hash[name] << sub_hash
|
||||
else
|
||||
hash[name] = sub_hash
|
||||
end
|
||||
sub_hash
|
||||
end
|
||||
|
||||
# Insert children into hash
|
||||
#
|
||||
# hash::
|
||||
# Hash to merge the children into.
|
||||
def children_to_hash(hash={})
|
||||
each { |child| child.to_hash(hash) }
|
||||
attributes_to_hash(hash)
|
||||
hash
|
||||
end
|
||||
|
||||
# Convert xml attributes to hash
|
||||
#
|
||||
# hash::
|
||||
# Hash to merge the attributes into
|
||||
def attributes_to_hash(hash={})
|
||||
each_attr { |attr| hash[attr.name] = attr.value }
|
||||
hash
|
||||
end
|
||||
|
||||
# Convert array into hash
|
||||
#
|
||||
# hash::
|
||||
# Hash to merge the array into
|
||||
def children_array_to_hash(hash={})
|
||||
hash[child.name] = map do |child|
|
||||
returning({}) { |sub_hash| child.children_to_hash(sub_hash) }
|
||||
end
|
||||
hash
|
||||
end
|
||||
|
||||
# Convert yaml into hash
|
||||
#
|
||||
# hash::
|
||||
# Hash to merge the yaml into
|
||||
def children_yaml_to_hash(hash = {})
|
||||
hash[CONTENT_ROOT] = content unless content.blank?
|
||||
hash
|
||||
end
|
||||
|
||||
# Check if child is of type array
|
||||
def array?
|
||||
child? && child.next? && child.name == child.next.name
|
||||
end
|
||||
|
||||
# Check if child is of type yaml
|
||||
def yaml?
|
||||
attributes.collect{|x| x.value}.include?('yaml')
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
LibXML::XML::Document.send(:include, LibXML::Conversions::Document)
|
||||
LibXML::XML::Node.send(:include, LibXML::Conversions::Node)
|
77
vendor/rails/activesupport/lib/active_support/xml_mini/nokogiri.rb
vendored
Normal file
77
vendor/rails/activesupport/lib/active_support/xml_mini/nokogiri.rb
vendored
Normal file
|
@ -0,0 +1,77 @@
|
|||
require 'nokogiri'
|
||||
|
||||
# = XmlMini Nokogiri implementation
|
||||
module ActiveSupport
|
||||
module XmlMini_Nokogiri #:nodoc:
|
||||
extend self
|
||||
|
||||
# Parse an XML Document string into a simple hash using libxml / nokogiri.
|
||||
# string::
|
||||
# XML Document string to parse
|
||||
def parse(string)
|
||||
if string.blank?
|
||||
{}
|
||||
else
|
||||
doc = Nokogiri::XML(string)
|
||||
raise doc.errors.first if doc.errors.length > 0
|
||||
doc.to_hash
|
||||
end
|
||||
end
|
||||
|
||||
module Conversions
|
||||
module Document
|
||||
def to_hash
|
||||
root.to_hash
|
||||
end
|
||||
end
|
||||
|
||||
module Node
|
||||
CONTENT_ROOT = '__content__'
|
||||
|
||||
# Convert XML document to hash
|
||||
#
|
||||
# hash::
|
||||
# Hash to merge the converted element into.
|
||||
def to_hash(hash = {})
|
||||
hash[name] ||= attributes_as_hash
|
||||
|
||||
walker = lambda { |memo, parent, child, callback|
|
||||
next if child.blank? && 'file' != parent['type']
|
||||
|
||||
if child.text?
|
||||
(memo[CONTENT_ROOT] ||= '') << child.content
|
||||
next
|
||||
end
|
||||
|
||||
name = child.name
|
||||
|
||||
child_hash = child.attributes_as_hash
|
||||
if memo[name]
|
||||
memo[name] = [memo[name]].flatten
|
||||
memo[name] << child_hash
|
||||
else
|
||||
memo[name] = child_hash
|
||||
end
|
||||
|
||||
# Recusively walk children
|
||||
child.children.each { |c|
|
||||
callback.call(child_hash, child, c, callback)
|
||||
}
|
||||
}
|
||||
|
||||
children.each { |c| walker.call(hash[name], self, c, walker) }
|
||||
hash
|
||||
end
|
||||
|
||||
def attributes_as_hash
|
||||
Hash[*(attribute_nodes.map { |node|
|
||||
[node.node_name, node.value]
|
||||
}.flatten)]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Nokogiri::XML::Document.send(:include, Conversions::Document)
|
||||
Nokogiri::XML::Node.send(:include, Conversions::Node)
|
||||
end
|
||||
end
|
108
vendor/rails/activesupport/lib/active_support/xml_mini/rexml.rb
vendored
Normal file
108
vendor/rails/activesupport/lib/active_support/xml_mini/rexml.rb
vendored
Normal file
|
@ -0,0 +1,108 @@
|
|||
# = XmlMini ReXML implementation
|
||||
module ActiveSupport
|
||||
module XmlMini_REXML #:nodoc:
|
||||
extend self
|
||||
|
||||
CONTENT_KEY = '__content__'.freeze
|
||||
|
||||
# Parse an XML Document string into a simple hash
|
||||
#
|
||||
# Same as XmlSimple::xml_in but doesn't shoot itself in the foot,
|
||||
# and uses the defaults from ActiveSupport
|
||||
#
|
||||
# string::
|
||||
# XML Document string to parse
|
||||
def parse(string)
|
||||
require 'rexml/document' unless defined?(REXML::Document)
|
||||
doc = REXML::Document.new(string)
|
||||
merge_element!({}, doc.root)
|
||||
end
|
||||
|
||||
private
|
||||
# Convert an XML element and merge into the hash
|
||||
#
|
||||
# hash::
|
||||
# Hash to merge the converted element into.
|
||||
# element::
|
||||
# XML element to merge into hash
|
||||
def merge_element!(hash, element)
|
||||
merge!(hash, element.name, collapse(element))
|
||||
end
|
||||
|
||||
# Actually converts an XML document element into a data structure.
|
||||
#
|
||||
# element::
|
||||
# The document element to be collapsed.
|
||||
def collapse(element)
|
||||
hash = get_attributes(element)
|
||||
|
||||
if element.has_elements?
|
||||
element.each_element {|child| merge_element!(hash, child) }
|
||||
merge_texts!(hash, element) unless empty_content?(element)
|
||||
hash
|
||||
else
|
||||
merge_texts!(hash, element)
|
||||
end
|
||||
end
|
||||
|
||||
# Merge all the texts of an element into the hash
|
||||
#
|
||||
# hash::
|
||||
# Hash to add the converted emement to.
|
||||
# element::
|
||||
# XML element whose texts are to me merged into the hash
|
||||
def merge_texts!(hash, element)
|
||||
unless element.has_text?
|
||||
hash
|
||||
else
|
||||
# must use value to prevent double-escaping
|
||||
merge!(hash, CONTENT_KEY, element.texts.sum(&:value))
|
||||
end
|
||||
end
|
||||
|
||||
# Adds a new key/value pair to an existing Hash. If the key to be added
|
||||
# already exists and the existing value associated with key is not
|
||||
# an Array, it will be wrapped in an Array. Then the new value is
|
||||
# appended to that Array.
|
||||
#
|
||||
# hash::
|
||||
# Hash to add key/value pair to.
|
||||
# key::
|
||||
# Key to be added.
|
||||
# value::
|
||||
# Value to be associated with key.
|
||||
def merge!(hash, key, value)
|
||||
if hash.has_key?(key)
|
||||
if hash[key].instance_of?(Array)
|
||||
hash[key] << value
|
||||
else
|
||||
hash[key] = [hash[key], value]
|
||||
end
|
||||
elsif value.instance_of?(Array)
|
||||
hash[key] = [value]
|
||||
else
|
||||
hash[key] = value
|
||||
end
|
||||
hash
|
||||
end
|
||||
|
||||
# Converts the attributes array of an XML element into a hash.
|
||||
# Returns an empty Hash if node has no attributes.
|
||||
#
|
||||
# element::
|
||||
# XML element to extract attributes from.
|
||||
def get_attributes(element)
|
||||
attributes = {}
|
||||
element.attributes.each { |n,v| attributes[n] = v }
|
||||
attributes
|
||||
end
|
||||
|
||||
# Determines if a document element has text content
|
||||
#
|
||||
# element::
|
||||
# XML element to be checked.
|
||||
def empty_content?(element)
|
||||
element.texts.join.blank?
|
||||
end
|
||||
end
|
||||
end
|
|
@ -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
|
||||
|
|
|
@ -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 [
|
||||
|
|
|
@ -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'
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 = {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
157
vendor/rails/activesupport/test/xml_mini/nokogiri_engine_test.rb
vendored
Normal file
157
vendor/rails/activesupport/test/xml_mini/nokogiri_engine_test.rb
vendored
Normal 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
|
15
vendor/rails/activesupport/test/xml_mini/rexml_engine_test.rb
vendored
Normal file
15
vendor/rails/activesupport/test/xml_mini/rexml_engine_test.rb
vendored
Normal 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
|
Loading…
Add table
Add a link
Reference in a new issue