1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Merge pull request #16232 from egilburg/activesupport_coverage

Added some missing activesupport test coverage
This commit is contained in:
Rafael Mendonça França 2014-07-21 14:25:51 -03:00
commit cee2c85b07
11 changed files with 114 additions and 4 deletions

View file

@ -34,6 +34,11 @@ class BacktraceCleanerSilencerTest < ActiveSupport::TestCase
[ "/other/class.rb" ],
@bc.clean([ "/mongrel/class.rb", "/other/class.rb", "/mongrel/stuff.rb" ])
end
test "backtrace cleaner should allow removing silencer" do
@bc.remove_silencers!
assert_equal ["/mongrel/stuff.rb"], @bc.clean(["/mongrel/stuff.rb"])
end
end
class BacktraceCleanerMultipleSilencersTest < ActiveSupport::TestCase

View file

@ -162,6 +162,10 @@ class DurationTest < ActiveSupport::TestCase
assert_equal counter, 60
end
def test_as_json
assert_equal 172800, 2.days.as_json
end
def test_to_json
assert_equal '172800', 2.days.to_json
end

View file

@ -706,7 +706,7 @@ class HashExtTest < ActiveSupport::TestCase
{ :failore => "stuff", :funny => "business" }.assert_valid_keys(:failure, :funny)
end
assert_equal "Unknown key: :failore. Valid keys are: :failure, :funny", exception.message
exception = assert_raise ArgumentError do
{ :failore => "stuff", :funny => "business" }.assert_valid_keys([ :failure ])
end
@ -1500,6 +1500,16 @@ class HashToXmlTest < ActiveSupport::TestCase
end
end
def test_from_xml_array_one
expected = { 'numbers' => { 'type' => 'Array', 'value' => '1' }}
assert_equal expected, Hash.from_xml('<numbers type="Array"><value>1</value></numbers>')
end
def test_from_xml_array_many
expected = { 'numbers' => { 'type' => 'Array', 'value' => [ '1', '2' ] }}
assert_equal expected, Hash.from_xml('<numbers type="Array"><value>1</value><value>2</value></numbers>')
end
def test_from_trusted_xml_allows_symbol_and_yaml_types
expected = { 'product' => { 'name' => :value }}
assert_equal expected, Hash.from_trusted_xml('<product><name type="symbol">value</name></product>')

View file

@ -14,6 +14,15 @@ class TestMissingSourceFile < ActiveSupport::TestCase
assert_equal 'nor/this/one.rb', e.path
end
end
def test_is_missing
begin load 'nor_does_this_one'
rescue MissingSourceFile => e
assert e.is_missing?('nor_does_this_one')
assert e.is_missing?('nor_does_this_one.rb')
assert_not e.is_missing?('some_other_file')
end
end
end
class TestLoadError < ActiveSupport::TestCase
@ -29,4 +38,4 @@ class TestLoadError < ActiveSupport::TestCase
assert_equal 'nor/this/one.rb', e.path
end
end
end
end

View file

@ -46,6 +46,10 @@ class ToQueryTest < ActiveSupport::TestCase
:person => {:id => [20, 10]}
end
def test_empty_array
assert_equal "person%5B%5D=", [].to_query('person')
end
def test_nested_empty_hash
assert_equal '',
{}.to_query

View file

@ -12,7 +12,7 @@ class RangeTest < ActiveSupport::TestCase
date_range = Time.utc(2005, 12, 10, 15, 30)..Time.utc(2005, 12, 10, 17, 30)
assert_equal "BETWEEN '2005-12-10 15:30:00' AND '2005-12-10 17:30:00'", date_range.to_s(:db)
end
def test_date_range
assert_instance_of Range, DateTime.new..DateTime.new
assert_instance_of Range, DateTime::Infinity.new..DateTime::Infinity.new
@ -116,4 +116,9 @@ class RangeTest < ActiveSupport::TestCase
datetime = DateTime.now
assert ((datetime - 1.hour)..datetime).each {}
end
def test_date_time_with_step
datetime = DateTime.now
assert ((datetime - 1.hour)..datetime).step(1) {}
end
end

View file

@ -775,6 +775,14 @@ class OutputSafetyTest < ActiveSupport::TestCase
string = "<b>hello</b>".html_safe
assert_equal string, ERB::Util.html_escape(string)
end
test "ERB::Util.html_escape_once only escapes once" do
string = '1 < 2 &amp; 3'
escaped_string = "1 &lt; 2 &amp; 3"
assert_equal escaped_string, ERB::Util.html_escape_once(string)
assert_equal escaped_string, ERB::Util.html_escape_once(escaped_string)
end
end
class StringExcludeTest < ActiveSupport::TestCase

View file

@ -367,6 +367,7 @@ class TimeWithZoneTest < ActiveSupport::TestCase
end
def test_acts_like_time
assert @twz.acts_like_time?
assert @twz.acts_like?(:time)
assert ActiveSupport::TimeWithZone.new(DateTime.civil(2000), @time_zone).acts_like?(:time)
end

View file

@ -7,7 +7,7 @@ class URIExtTest < ActiveSupport::TestCase
def test_uri_decode_handle_multibyte
str = "\xE6\x97\xA5\xE6\x9C\xAC\xE8\xAA\x9E" # Ni-ho-nn-go in UTF-8, means Japanese.
parser = URI::Parser.new
parser = URI.parser
assert_equal str, parser.unescape(parser.escape(str))
end
end

View file

@ -29,4 +29,34 @@ class KeyGeneratorTest < ActiveSupport::TestCase
end
end
class CachingKeyGeneratorTest < ActiveSupport::TestCase
def setup
@secret = SecureRandom.hex(64)
@generator = ActiveSupport::KeyGenerator.new(@secret, :iterations=>2)
@caching_generator = ActiveSupport::CachingKeyGenerator.new(@generator)
end
test "Generating a cached key for same salt and key size" do
derived_key = @caching_generator.generate_key("some_salt", 32)
cached_key = @caching_generator.generate_key("some_salt", 32)
assert_equal derived_key, cached_key
assert_equal derived_key.object_id, cached_key.object_id
end
test "Does not cache key for different salt" do
derived_key = @caching_generator.generate_key("some_salt", 32)
different_salt_key = @caching_generator.generate_key("other_salt", 32)
assert_not_equal derived_key, different_salt_key
end
test "Does not cache key for different length" do
derived_key = @caching_generator.generate_key("some_salt", 32)
different_length_key = @caching_generator.generate_key("some_salt", 64)
assert_not_equal derived_key, different_length_key
end
end
end

View file

@ -0,0 +1,34 @@
# encoding: utf-8
require 'abstract_unit'
class MultibyteProxyText < ActiveSupport::TestCase
class AsciiOnlyEncoder
attr_reader :wrapped_string
alias to_s wrapped_string
def initialize(string)
@wrapped_string = string.gsub(/[^\u0000-\u007F]/, '?')
end
end
def with_custom_encoder(encoder)
original_proxy_class = ActiveSupport::Multibyte.proxy_class
begin
ActiveSupport::Multibyte.proxy_class = encoder
yield
ensure
ActiveSupport::Multibyte.proxy_class = original_proxy_class
end
end
test "custom multibyte encoder" do
with_custom_encoder(AsciiOnlyEncoder) do
assert_equal "s?me string 123", "søme string 123".mb_chars.to_s
end
assert_equal "søme string 123", "søme string 123".mb_chars.to_s
end
end