aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/test/json
diff options
context:
space:
mode:
authorXavier Noria <fxn@hashref.com>2016-07-22 23:13:42 +0200
committerXavier Noria <fxn@hashref.com>2016-07-22 23:13:49 +0200
commitcfc91c31aa989826e992be29b6d5b181f654f853 (patch)
treeb5ec5569b22f8c796de89335c5ecc7de047130bc /activesupport/test/json
parentaea0e5cd709e0fc53e1ba4e87235b8ee3f4bc155 (diff)
downloadrails-cfc91c31aa989826e992be29b6d5b181f654f853.tar.gz
rails-cfc91c31aa989826e992be29b6d5b181f654f853.tar.bz2
rails-cfc91c31aa989826e992be29b6d5b181f654f853.zip
systematic revision of =~ usage in AS
Where appropriate prefer the more concise Regexp#match?, String#include?, String#start_with?, and String#end_with?
Diffstat (limited to 'activesupport/test/json')
-rw-r--r--activesupport/test/json/encoding_test.rb14
1 files changed, 10 insertions, 4 deletions
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