Ruby 1.9 compat: shadowed vars, kcode
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8402 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
parent
cefea3c677
commit
aa4ad404c6
@ -119,8 +119,14 @@ def handler
|
||||
|
||||
# +utf8_pragma+ checks if it can send this string to the handlers. It makes sure @string isn't nil and $KCODE is
|
||||
# set to 'UTF8'.
|
||||
def utf8_pragma?
|
||||
!@string.nil? && ($KCODE == 'UTF8')
|
||||
if RUBY_VERSION < '1.9'
|
||||
def utf8_pragma?
|
||||
!@string.nil? && ($KCODE == 'UTF8')
|
||||
end
|
||||
else
|
||||
def utf8_pragma?
|
||||
!@string.nil? && (Encoding.default_external == Encoding::UTF_8)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -145,7 +145,7 @@ def test_indifferent_update
|
||||
assert_equal updated_with_mixed[:a], 1
|
||||
assert_equal updated_with_mixed['b'], 2
|
||||
|
||||
assert [updated_with_strings, updated_with_symbols, updated_with_mixed].all? {|hash| hash.keys.size == 2}
|
||||
assert [updated_with_strings, updated_with_symbols, updated_with_mixed].all? { |h| h.keys.size == 2 }
|
||||
end
|
||||
|
||||
def test_indifferent_merging
|
||||
@ -371,8 +371,8 @@ def test_one_level_with_skipping_types
|
||||
end
|
||||
|
||||
def test_one_level_with_yielding
|
||||
xml = { :name => "David", :street => "Paulina" }.to_xml(@xml_options) do |xml|
|
||||
xml.creator("Rails")
|
||||
xml = { :name => "David", :street => "Paulina" }.to_xml(@xml_options) do |x|
|
||||
x.creator("Rails")
|
||||
end
|
||||
|
||||
assert_equal "<person>", xml.first(8)
|
||||
|
@ -3,11 +3,15 @@
|
||||
module AttributeAliasing
|
||||
class Content
|
||||
attr_accessor :title, :Data
|
||||
|
||||
|
||||
def initialize
|
||||
@title, @Data = nil, nil
|
||||
end
|
||||
|
||||
def title?
|
||||
!title.nil?
|
||||
end
|
||||
|
||||
|
||||
def Data?
|
||||
!self.Data.nil?
|
||||
end
|
||||
|
@ -53,11 +53,10 @@ def test_hash_encoding
|
||||
end
|
||||
|
||||
def test_utf8_string_encoded_properly_when_kcode_is_utf8
|
||||
old_kcode, $KCODE = $KCODE, 'UTF8'
|
||||
assert_equal '"\\u20ac2.99"', '€2.99'.to_json
|
||||
assert_equal '"\\u270e\\u263a"', '✎☺'.to_json
|
||||
ensure
|
||||
$KCODE = old_kcode
|
||||
with_kcode 'UTF8' do
|
||||
assert_equal '"\\u20ac2.99"', '€2.99'.to_json
|
||||
assert_equal '"\\u270e\\u263a"', '✎☺'.to_json
|
||||
end
|
||||
end
|
||||
|
||||
def test_exception_raised_when_encoding_circular_reference
|
||||
@ -80,6 +79,19 @@ def test_hash_should_allow_key_filtering_with_except
|
||||
end
|
||||
|
||||
protected
|
||||
def with_kcode(code)
|
||||
if RUBY_VERSION < '1.9'
|
||||
begin
|
||||
old_kcode, $KCODE = $KCODE, 'UTF8'
|
||||
yield
|
||||
ensure
|
||||
$KCODE = old_kcode
|
||||
end
|
||||
else
|
||||
yield
|
||||
end
|
||||
end
|
||||
|
||||
def object_keys(json_object)
|
||||
json_object[1..-2].scan(/([^{}:,\s]+):/).flatten.sort
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user