diff options
author | Pat Allan <pat@freelancing-gods.com> | 2017-06-19 19:03:10 +1000 |
---|---|---|
committer | Pat Allan <pat@freelancing-gods.com> | 2017-06-20 18:04:44 +1000 |
commit | 036bdee4d5bdad3b3fa1d57ca292214afe746a09 (patch) | |
tree | 8eabc5fa599dce65e6266f7056fa8ff3252285a9 /activesupport/test | |
parent | b37aa68ff637c4ce1cfd9f6eaec659bc98a1e1b5 (diff) | |
download | rails-036bdee4d5bdad3b3fa1d57ca292214afe746a09.tar.gz rails-036bdee4d5bdad3b3fa1d57ca292214afe746a09.tar.bz2 rails-036bdee4d5bdad3b3fa1d57ca292214afe746a09.zip |
Make ActiveSupport frozen string literal friendly.
The ActiveSupport test suite only passes currently if it uses the latest unreleased commits for dalli, and a patch for Builder:
https://github.com/tenderlove/builder/pull/6
Beyond that, all external dependencies (at least, to the extent they’re used by ActiveSupport) are happy, including Nokogiri as of 1.8.0.
Diffstat (limited to 'activesupport/test')
-rw-r--r-- | activesupport/test/cache/behaviors/cache_store_behavior.rb | 4 | ||||
-rw-r--r-- | activesupport/test/cache/behaviors/encoded_key_cache_behavior.rb | 6 | ||||
-rw-r--r-- | activesupport/test/cache/cache_key_test.rb | 4 | ||||
-rw-r--r-- | activesupport/test/core_ext/string_ext_test.rb | 19 | ||||
-rw-r--r-- | activesupport/test/logger_test.rb | 4 | ||||
-rw-r--r-- | activesupport/test/multibyte_chars_test.rb | 28 | ||||
-rw-r--r-- | activesupport/test/multibyte_test_helpers.rb | 2 |
7 files changed, 34 insertions, 33 deletions
diff --git a/activesupport/test/cache/behaviors/cache_store_behavior.rb b/activesupport/test/cache/behaviors/cache_store_behavior.rb index 03c366e164..4631e6aee8 100644 --- a/activesupport/test/cache/behaviors/cache_store_behavior.rb +++ b/activesupport/test/cache/behaviors/cache_store_behavior.rb @@ -196,7 +196,7 @@ module CacheStoreBehavior end def test_original_store_objects_should_not_be_immutable - bar = "bar" + bar = "bar".dup @cache.write("foo", bar) assert_nothing_raised { bar.gsub!(/.*/, "baz") } end @@ -285,7 +285,7 @@ module CacheStoreBehavior end def test_really_long_keys - key = "" + key = "".dup 900.times { key << "x" } assert @cache.write(key, "bar") assert_equal "bar", @cache.read(key) diff --git a/activesupport/test/cache/behaviors/encoded_key_cache_behavior.rb b/activesupport/test/cache/behaviors/encoded_key_cache_behavior.rb index 4d8e2946b2..6adef2916d 100644 --- a/activesupport/test/cache/behaviors/encoded_key_cache_behavior.rb +++ b/activesupport/test/cache/behaviors/encoded_key_cache_behavior.rb @@ -4,7 +4,7 @@ module EncodedKeyCacheBehavior Encoding.list.each do |encoding| define_method "test_#{encoding.name.underscore}_encoded_values" do - key = "foo".force_encoding(encoding) + key = "foo".dup.force_encoding(encoding) assert @cache.write(key, "1", raw: true) assert_equal "1", @cache.read(key) assert_equal "1", @cache.fetch(key) @@ -16,7 +16,7 @@ module EncodedKeyCacheBehavior end def test_common_utf8_values - key = "\xC3\xBCmlaut".force_encoding(Encoding::UTF_8) + key = "\xC3\xBCmlaut".dup.force_encoding(Encoding::UTF_8) assert @cache.write(key, "1", raw: true) assert_equal "1", @cache.read(key) assert_equal "1", @cache.fetch(key) @@ -27,7 +27,7 @@ module EncodedKeyCacheBehavior end def test_retains_encoding - key = "\xC3\xBCmlaut".force_encoding(Encoding::UTF_8) + key = "\xC3\xBCmlaut".dup.force_encoding(Encoding::UTF_8) assert @cache.write(key, "1", raw: true) assert_equal Encoding::UTF_8, key.encoding end diff --git a/activesupport/test/cache/cache_key_test.rb b/activesupport/test/cache/cache_key_test.rb index 149d0f66ee..ea39d7a299 100644 --- a/activesupport/test/cache/cache_key_test.rb +++ b/activesupport/test/cache/cache_key_test.rb @@ -45,7 +45,7 @@ class CacheKeyTest < ActiveSupport::TestCase end def test_expand_cache_key_respond_to_cache_key - key = "foo" + key = "foo".dup def key.cache_key :foo_key end @@ -53,7 +53,7 @@ class CacheKeyTest < ActiveSupport::TestCase end def test_expand_cache_key_array_with_something_that_responds_to_cache_key - key = "foo" + key = "foo".dup def key.cache_key :foo_key end diff --git a/activesupport/test/core_ext/string_ext_test.rb b/activesupport/test/core_ext/string_ext_test.rb index a98951e889..daa8c3f2ef 100644 --- a/activesupport/test/core_ext/string_ext_test.rb +++ b/activesupport/test/core_ext/string_ext_test.rb @@ -233,7 +233,7 @@ class StringInflectionsTest < ActiveSupport::TestCase def test_string_squish original = %{\u205f\u3000 A string surrounded by various unicode spaces, - with tabs(\t\t), newlines(\n\n), unicode nextlines(\u0085\u0085) and many spaces( ). \u00a0\u2007} + with tabs(\t\t), newlines(\n\n), unicode nextlines(\u0085\u0085) and many spaces( ). \u00a0\u2007}.dup expected = "A string surrounded by various unicode spaces, " \ "with tabs( ), newlines( ), unicode nextlines( ) and many spaces( )." @@ -303,8 +303,8 @@ class StringInflectionsTest < ActiveSupport::TestCase end def test_truncate_multibyte - assert_equal "\354\225\204\353\246\254\353\236\221 \354\225\204\353\246\254 ...".force_encoding(Encoding::UTF_8), - "\354\225\204\353\246\254\353\236\221 \354\225\204\353\246\254 \354\225\204\353\235\274\353\246\254\354\230\244".force_encoding(Encoding::UTF_8).truncate(10) + assert_equal "\354\225\204\353\246\254\353\236\221 \354\225\204\353\246\254 ...".dup.force_encoding(Encoding::UTF_8), + "\354\225\204\353\246\254\353\236\221 \354\225\204\353\246\254 \354\225\204\353\235\274\353\246\254\354\230\244".dup.force_encoding(Encoding::UTF_8).truncate(10) end def test_truncate_should_not_be_html_safe @@ -325,7 +325,7 @@ class StringInflectionsTest < ActiveSupport::TestCase end def test_remove! - original = "This is a very good day to die" + original = "This is a very good day to die".dup assert_equal "This is a good day to die", original.remove!(" very") assert_equal "This is a good day to die", original assert_equal "This is a good day", original.remove!(" to ", /die/) @@ -658,7 +658,7 @@ end class OutputSafetyTest < ActiveSupport::TestCase def setup - @string = "hello" + @string = "hello".dup @object = Class.new(Object) do def to_s "other" @@ -734,7 +734,7 @@ class OutputSafetyTest < ActiveSupport::TestCase end test "Concatting safe onto unsafe yields unsafe" do - @other_string = "other" + @other_string = "other".dup string = @string.html_safe @other_string.concat(string) @@ -757,7 +757,7 @@ class OutputSafetyTest < ActiveSupport::TestCase end test "Concatting safe onto unsafe with << yields unsafe" do - @other_string = "other" + @other_string = "other".dup string = @string.html_safe @other_string << string @@ -813,7 +813,7 @@ class OutputSafetyTest < ActiveSupport::TestCase test "Concatting an integer to safe always yields safe" do string = @string.html_safe string = string.concat(13) - assert_equal "hello".concat(13), string + assert_equal "hello".dup.concat(13), string assert string.html_safe? end @@ -868,7 +868,8 @@ end class StringIndentTest < ActiveSupport::TestCase test "does not indent strings that only contain newlines (edge cases)" do - ["", "\n", "\n" * 7].each do |str| + ["", "\n", "\n" * 7].each do |string| + str = string.dup assert_nil str.indent!(8) assert_equal str, str.indent(8) assert_equal str, str.indent(1, "\t") diff --git a/activesupport/test/logger_test.rb b/activesupport/test/logger_test.rb index 3f04783401..1bc443ae65 100644 --- a/activesupport/test/logger_test.rb +++ b/activesupport/test/logger_test.rb @@ -37,7 +37,7 @@ class LoggerTest < ActiveSupport::TestCase logger = Logger.new f logger.level = Logger::DEBUG - str = "\x80" + str = "\x80".dup str.force_encoding("ASCII-8BIT") logger.add Logger::DEBUG, str @@ -55,7 +55,7 @@ class LoggerTest < ActiveSupport::TestCase logger = Logger.new f logger.level = Logger::DEBUG - str = "\x80" + str = "\x80".dup str.force_encoding("ASCII-8BIT") logger.add Logger::DEBUG, str diff --git a/activesupport/test/multibyte_chars_test.rb b/activesupport/test/multibyte_chars_test.rb index d80d340986..16a7d488c7 100644 --- a/activesupport/test/multibyte_chars_test.rb +++ b/activesupport/test/multibyte_chars_test.rb @@ -51,7 +51,7 @@ class MultibyteCharsTest < ActiveSupport::TestCase end def test_forwarded_method_with_non_string_result_should_be_returned_verbatim - str = "" + str = "".dup str.singleton_class.class_eval { def __method_for_multibyte_testing_with_integer_result; 1; end } @chars.wrapped_string.singleton_class.class_eval { def __method_for_multibyte_testing_with_integer_result; 1; end } @@ -59,14 +59,14 @@ class MultibyteCharsTest < ActiveSupport::TestCase end def test_should_concatenate - mb_a = "a".mb_chars - mb_b = "b".mb_chars + mb_a = "a".dup.mb_chars + mb_b = "b".dup.mb_chars assert_equal "ab", mb_a + "b" assert_equal "ab", "a" + mb_b assert_equal "ab", mb_a + mb_b assert_equal "ab", mb_a << "b" - assert_equal "ab", "a" << mb_b + assert_equal "ab", "a".dup << mb_b assert_equal "abb", mb_a << mb_b end @@ -78,7 +78,7 @@ class MultibyteCharsTest < ActiveSupport::TestCase def test_concatenation_should_return_a_proxy_class_instance assert_equal ActiveSupport::Multibyte.proxy_class, ("a".mb_chars + "b").class - assert_equal ActiveSupport::Multibyte.proxy_class, ("a".mb_chars << "b").class + assert_equal ActiveSupport::Multibyte.proxy_class, ("a".dup.mb_chars << "b").class end def test_ascii_strings_are_treated_at_utf8_strings @@ -88,8 +88,8 @@ class MultibyteCharsTest < ActiveSupport::TestCase def test_concatenate_should_return_proxy_instance assert(("a".mb_chars + "b").kind_of?(@proxy_class)) assert(("a".mb_chars + "b".mb_chars).kind_of?(@proxy_class)) - assert(("a".mb_chars << "b").kind_of?(@proxy_class)) - assert(("a".mb_chars << "b".mb_chars).kind_of?(@proxy_class)) + assert(("a".dup.mb_chars << "b").kind_of?(@proxy_class)) + assert(("a".dup.mb_chars << "b".mb_chars).kind_of?(@proxy_class)) end def test_should_return_string_as_json @@ -115,12 +115,12 @@ class MultibyteCharsUTF8BehaviourTest < ActiveSupport::TestCase %w{capitalize downcase lstrip reverse rstrip swapcase upcase}.each do |method| class_eval(<<-EOTESTS, __FILE__, __LINE__ + 1) def test_#{method}_bang_should_return_self_when_modifying_wrapped_string - chars = ' él piDió Un bUen café ' + chars = ' él piDió Un bUen café '.dup assert_equal chars.object_id, chars.send("#{method}!").object_id end def test_#{method}_bang_should_change_wrapped_string - original = ' él piDió Un bUen café ' + original = ' él piDió Un bUen café '.dup proxy = chars(original.dup) proxy.send("#{method}!") assert_not_equal original, proxy.to_s @@ -133,7 +133,7 @@ class MultibyteCharsUTF8BehaviourTest < ActiveSupport::TestCase end def test_tidy_bytes_bang_should_change_wrapped_string - original = " Un bUen café \x92" + original = " Un bUen café \x92".dup proxy = chars(original.dup) proxy.tidy_bytes! assert_not_equal original, proxy.to_s @@ -150,7 +150,7 @@ class MultibyteCharsUTF8BehaviourTest < ActiveSupport::TestCase end def test_string_methods_are_chainable - assert chars("").insert(0, "").kind_of?(ActiveSupport::Multibyte.proxy_class) + assert chars("".dup).insert(0, "").kind_of?(ActiveSupport::Multibyte.proxy_class) assert chars("").rjust(1).kind_of?(ActiveSupport::Multibyte.proxy_class) assert chars("").ljust(1).kind_of?(ActiveSupport::Multibyte.proxy_class) assert chars("").center(1).kind_of?(ActiveSupport::Multibyte.proxy_class) @@ -195,7 +195,7 @@ class MultibyteCharsUTF8BehaviourTest < ActiveSupport::TestCase end def test_should_use_character_offsets_for_insert_offsets - assert_equal "", "".mb_chars.insert(0, "") + assert_equal "", "".dup.mb_chars.insert(0, "") assert_equal "こわにちわ", @chars.insert(1, "わ") assert_equal "こわわわにちわ", @chars.insert(2, "わわ") assert_equal "わこわわわにちわ", @chars.insert(0, "わ") @@ -418,13 +418,13 @@ class MultibyteCharsUTF8BehaviourTest < ActiveSupport::TestCase end def test_slice_bang_removes_the_slice_from_the_receiver - chars = "úüù".mb_chars + chars = "úüù".dup.mb_chars chars.slice!(0, 2) assert_equal "ù", chars end def test_slice_bang_returns_nil_and_does_not_modify_receiver_if_out_of_bounds - string = "úüù" + string = "úüù".dup chars = string.mb_chars assert_nil chars.slice!(4, 5) assert_equal "úüù", chars diff --git a/activesupport/test/multibyte_test_helpers.rb b/activesupport/test/multibyte_test_helpers.rb index a70516bb08..e1e0ae86d9 100644 --- a/activesupport/test/multibyte_test_helpers.rb +++ b/activesupport/test/multibyte_test_helpers.rb @@ -23,7 +23,7 @@ module MultibyteTestHelpers UNICODE_STRING = "こにちわ".freeze ASCII_STRING = "ohayo".freeze - BYTE_STRING = "\270\236\010\210\245".force_encoding("ASCII-8BIT").freeze + BYTE_STRING = "\270\236\010\210\245".dup.force_encoding("ASCII-8BIT").freeze def chars(str) ActiveSupport::Multibyte::Chars.new(str) |