From cfc91c31aa989826e992be29b6d5b181f654f853 Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Fri, 22 Jul 2016 23:13:42 +0200 Subject: systematic revision of =~ usage in AS Where appropriate prefer the more concise Regexp#match?, String#include?, String#start_with?, and String#end_with? --- activesupport/test/json/encoding_test.rb | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'activesupport/test/json') diff --git a/activesupport/test/json/encoding_test.rb b/activesupport/test/json/encoding_test.rb index 5fc2e16336..8cb3b1a9bb 100644 --- a/activesupport/test/json/encoding_test.rb +++ b/activesupport/test/json/encoding_test.rb @@ -1,6 +1,7 @@ require 'securerandom' require 'abstract_unit' require 'active_support/core_ext/string/inflections' +require 'active_support/core_ext/regexp' require 'active_support/json' require 'active_support/time' require 'time_zone_test_helpers' @@ -10,8 +11,11 @@ class TestJSONEncoding < ActiveSupport::TestCase include TimeZoneTestHelpers def sorted_json(json) - return json unless json =~ /^\{.*\}$/ - '{' + json[1..-2].split(',').sort.join(',') + '}' + if json.start_with?('{') && json.end_with?('}') + '{' + json[1..-2].split(',').sort.join(',') + '}' + else + json + end end JSONTest::EncodingTestCases.constants.each do |class_tests| @@ -19,8 +23,10 @@ class TestJSONEncoding < ActiveSupport::TestCase begin prev = ActiveSupport.use_standard_json_time_format - ActiveSupport.escape_html_entities_in_json = class_tests !~ /^Standard/ - ActiveSupport.use_standard_json_time_format = class_tests =~ /^Standard/ + standard_class_tests = /Standard/.match?(class_tests) + + ActiveSupport.escape_html_entities_in_json = !standard_class_tests + ActiveSupport.use_standard_json_time_format = standard_class_tests JSONTest::EncodingTestCases.const_get(class_tests).each do |pair| assert_equal pair.last, sorted_json(ActiveSupport::JSON.encode(pair.first)) end -- cgit v1.2.3