From 80e66cc4d90bf8c15d1a5f6e3152e90147f00772 Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Sat, 6 Aug 2016 19:55:02 +0200 Subject: normalizes indentation and whitespace across the project --- activesupport/test/autoload_test.rb | 2 +- activesupport/test/autoloading_fixtures/a/b.rb | 2 +- activesupport/test/autoloading_fixtures/a/c/d.rb | 2 +- .../test/autoloading_fixtures/a/c/em/f.rb | 2 +- .../test/autoloading_fixtures/conflict.rb | 2 +- .../autoloading_fixtures/cross_site_dependency.rb | 2 +- activesupport/test/autoloading_fixtures/d.rb | 2 +- activesupport/test/autoloading_fixtures/em.rb | 2 +- .../load_path/loaded_constant.rb | 1 - .../module_folder/nested_sibling.rb | 2 +- .../module_with_custom_const_missing/a/b.rb | 2 +- .../test/autoloading_fixtures/requires_constant.rb | 1 - activesupport/test/autoloading_fixtures/typo.rb | 1 - activesupport/test/caching_test.rb | 14 +- activesupport/test/core_ext/date_ext_test.rb | 1 - .../test/core_ext/module/anonymous_test.rb | 2 +- .../module/attribute_accessor_per_thread_test.rb | 8 +- .../test/core_ext/module/qualified_const_test.rb | 8 +- .../test/core_ext/module/reachable_test.rb | 2 +- activesupport/test/core_ext/module_test.rb | 6 +- .../test/core_ext/object/inclusion_test.rb | 4 +- activesupport/test/dependencies/conflict.rb | 2 +- .../test/dependencies/cross_site_depender.rb | 2 +- activesupport/test/dependencies/service_one.rb | 2 +- activesupport/test/dependencies/service_two.rb | 2 +- activesupport/test/dependencies_test_helpers.rb | 2 +- .../test/descendants_tracker_test_cases.rb | 34 ++-- .../test/fixtures/autoload/another_class.rb | 2 +- activesupport/test/fixtures/autoload/some_class.rb | 2 +- activesupport/test/inflector_test_cases.rb | 36 ++-- activesupport/test/json/decoding_test.rb | 15 +- activesupport/test/key_generator_test.rb | 114 ++++++------ activesupport/test/lazy_load_hooks_test.rb | 2 +- activesupport/test/message_encryptor_test.rb | 26 +-- activesupport/test/multibyte_chars_test.rb | 22 +-- activesupport/test/share_lock_test.rb | 124 ++++++------- activesupport/test/subscriber_test.rb | 6 +- activesupport/test/xml_mini/jdom_engine_test.rb | 12 +- activesupport/test/xml_mini/libxml_engine_test.rb | 194 ++++++++++----------- .../test/xml_mini/libxmlsax_engine_test.rb | 160 ++++++++--------- .../test/xml_mini/nokogiri_engine_test.rb | 182 +++++++++---------- .../test/xml_mini/nokogirisax_engine_test.rb | 182 +++++++++---------- activesupport/test/xml_mini/rexml_engine_test.rb | 4 +- 43 files changed, 595 insertions(+), 600 deletions(-) (limited to 'activesupport/test') diff --git a/activesupport/test/autoload_test.rb b/activesupport/test/autoload_test.rb index 6a0ce5f3dd..c4d6a69212 100644 --- a/activesupport/test/autoload_test.rb +++ b/activesupport/test/autoload_test.rb @@ -78,4 +78,4 @@ class TestAutoloadModule < ActiveSupport::TestCase assert !$LOADED_FEATURES.include?(@another_class_path) assert_nothing_raised { ::Fixtures::AnotherClass } end -end \ No newline at end of file +end diff --git a/activesupport/test/autoloading_fixtures/a/b.rb b/activesupport/test/autoloading_fixtures/a/b.rb index 9c9e6454cf..0dbbbbd181 100644 --- a/activesupport/test/autoloading_fixtures/a/b.rb +++ b/activesupport/test/autoloading_fixtures/a/b.rb @@ -1,2 +1,2 @@ class A::B -end \ No newline at end of file +end diff --git a/activesupport/test/autoloading_fixtures/a/c/d.rb b/activesupport/test/autoloading_fixtures/a/c/d.rb index 0f40d6fbc4..2c0ec5f182 100644 --- a/activesupport/test/autoloading_fixtures/a/c/d.rb +++ b/activesupport/test/autoloading_fixtures/a/c/d.rb @@ -1,2 +1,2 @@ class A::C::D -end \ No newline at end of file +end diff --git a/activesupport/test/autoloading_fixtures/a/c/em/f.rb b/activesupport/test/autoloading_fixtures/a/c/em/f.rb index 8b28e19148..3ff1b7efa0 100644 --- a/activesupport/test/autoloading_fixtures/a/c/em/f.rb +++ b/activesupport/test/autoloading_fixtures/a/c/em/f.rb @@ -1,2 +1,2 @@ class A::C::EM::F -end \ No newline at end of file +end diff --git a/activesupport/test/autoloading_fixtures/conflict.rb b/activesupport/test/autoloading_fixtures/conflict.rb index 4ac6201902..d7f42b5d5f 100644 --- a/activesupport/test/autoloading_fixtures/conflict.rb +++ b/activesupport/test/autoloading_fixtures/conflict.rb @@ -1 +1 @@ -Conflict = 2 \ No newline at end of file +Conflict = 2 diff --git a/activesupport/test/autoloading_fixtures/cross_site_dependency.rb b/activesupport/test/autoloading_fixtures/cross_site_dependency.rb index 21ee554e92..de941bf271 100644 --- a/activesupport/test/autoloading_fixtures/cross_site_dependency.rb +++ b/activesupport/test/autoloading_fixtures/cross_site_dependency.rb @@ -1,2 +1,2 @@ class CrossSiteDependency -end \ No newline at end of file +end diff --git a/activesupport/test/autoloading_fixtures/d.rb b/activesupport/test/autoloading_fixtures/d.rb index 45c794d4ca..52850e1e1a 100644 --- a/activesupport/test/autoloading_fixtures/d.rb +++ b/activesupport/test/autoloading_fixtures/d.rb @@ -1,2 +1,2 @@ class D -end \ No newline at end of file +end diff --git a/activesupport/test/autoloading_fixtures/em.rb b/activesupport/test/autoloading_fixtures/em.rb index 16a1838667..e47024999e 100644 --- a/activesupport/test/autoloading_fixtures/em.rb +++ b/activesupport/test/autoloading_fixtures/em.rb @@ -1,2 +1,2 @@ class EM -end \ No newline at end of file +end diff --git a/activesupport/test/autoloading_fixtures/load_path/loaded_constant.rb b/activesupport/test/autoloading_fixtures/load_path/loaded_constant.rb index e3d1218c96..d2c4f6b0c5 100644 --- a/activesupport/test/autoloading_fixtures/load_path/loaded_constant.rb +++ b/activesupport/test/autoloading_fixtures/load_path/loaded_constant.rb @@ -1,3 +1,2 @@ module LoadedConstant end - diff --git a/activesupport/test/autoloading_fixtures/module_folder/nested_sibling.rb b/activesupport/test/autoloading_fixtures/module_folder/nested_sibling.rb index 80244b8bab..04c426833e 100644 --- a/activesupport/test/autoloading_fixtures/module_folder/nested_sibling.rb +++ b/activesupport/test/autoloading_fixtures/module_folder/nested_sibling.rb @@ -1,2 +1,2 @@ class ModuleFolder::NestedSibling -end \ No newline at end of file +end diff --git a/activesupport/test/autoloading_fixtures/module_with_custom_const_missing/a/b.rb b/activesupport/test/autoloading_fixtures/module_with_custom_const_missing/a/b.rb index d12d02f3aa..4f2020c503 100644 --- a/activesupport/test/autoloading_fixtures/module_with_custom_const_missing/a/b.rb +++ b/activesupport/test/autoloading_fixtures/module_with_custom_const_missing/a/b.rb @@ -1 +1 @@ -ModuleWithCustomConstMissing::A::B = "10" \ No newline at end of file +ModuleWithCustomConstMissing::A::B = "10" diff --git a/activesupport/test/autoloading_fixtures/requires_constant.rb b/activesupport/test/autoloading_fixtures/requires_constant.rb index 14804a0de0..f04dcc4091 100644 --- a/activesupport/test/autoloading_fixtures/requires_constant.rb +++ b/activesupport/test/autoloading_fixtures/requires_constant.rb @@ -2,4 +2,3 @@ require "loaded_constant" module RequiresConstant end - diff --git a/activesupport/test/autoloading_fixtures/typo.rb b/activesupport/test/autoloading_fixtures/typo.rb index 8e047f5fd4..0ffe07c2b3 100644 --- a/activesupport/test/autoloading_fixtures/typo.rb +++ b/activesupport/test/autoloading_fixtures/typo.rb @@ -1,2 +1 @@ TypO = 1 - diff --git a/activesupport/test/caching_test.rb b/activesupport/test/caching_test.rb index 422b7f0834..072a2530ba 100644 --- a/activesupport/test/caching_test.rb +++ b/activesupport/test/caching_test.rb @@ -130,13 +130,13 @@ class CacheKeyTest < ActiveSupport::TestCase private - def with_env(kv) - old_values = {} - kv.each { |key, value| old_values[key], ENV[key] = ENV[key], value } - yield - ensure - old_values.each { |key, value| ENV[key] = value} - end + def with_env(kv) + old_values = {} + kv.each { |key, value| old_values[key], ENV[key] = ENV[key], value } + yield + ensure + old_values.each { |key, value| ENV[key] = value} + end end class CacheStoreSettingTest < ActiveSupport::TestCase diff --git a/activesupport/test/core_ext/date_ext_test.rb b/activesupport/test/core_ext/date_ext_test.rb index 0c9b88d861..0655197335 100644 --- a/activesupport/test/core_ext/date_ext_test.rb +++ b/activesupport/test/core_ext/date_ext_test.rb @@ -407,4 +407,3 @@ class DateExtBehaviorTest < ActiveSupport::TestCase end end end - diff --git a/activesupport/test/core_ext/module/anonymous_test.rb b/activesupport/test/core_ext/module/anonymous_test.rb index 36aecfa4c8..f885444284 100644 --- a/activesupport/test/core_ext/module/anonymous_test.rb +++ b/activesupport/test/core_ext/module/anonymous_test.rb @@ -11,4 +11,4 @@ class AnonymousTest < ActiveSupport::TestCase assert !Kernel.anonymous? assert !Object.anonymous? end -end \ No newline at end of file +end diff --git a/activesupport/test/core_ext/module/attribute_accessor_per_thread_test.rb b/activesupport/test/core_ext/module/attribute_accessor_per_thread_test.rb index 903c7206cd..cda5a34442 100644 --- a/activesupport/test/core_ext/module/attribute_accessor_per_thread_test.rb +++ b/activesupport/test/core_ext/module/attribute_accessor_per_thread_test.rb @@ -65,15 +65,15 @@ class ModuleAttributeAccessorPerThreadTest < ActiveSupport::TestCase threads << Thread.new do @class.foo = "other things" sleep 1 - assert_equal "other things", @class.foo + assert_equal "other things", @class.foo end - + threads << Thread.new do @class.foo = "really other things" sleep 1 - assert_equal "really other things", @class.foo + assert_equal "really other things", @class.foo end - + threads.each { |t| t.join } end diff --git a/activesupport/test/core_ext/module/qualified_const_test.rb b/activesupport/test/core_ext/module/qualified_const_test.rb index 1362171b09..dcfac4ced1 100644 --- a/activesupport/test/core_ext/module/qualified_const_test.rb +++ b/activesupport/test/core_ext/module/qualified_const_test.rb @@ -111,8 +111,8 @@ class QualifiedConstTest < ActiveSupport::TestCase private - def assert_raise_with_message(expected_exception, expected_message, &block) - exception = assert_raise(expected_exception, &block) - assert_equal expected_message, exception.message - end + def assert_raise_with_message(expected_exception, expected_message, &block) + exception = assert_raise(expected_exception, &block) + assert_equal expected_message, exception.message + end end diff --git a/activesupport/test/core_ext/module/reachable_test.rb b/activesupport/test/core_ext/module/reachable_test.rb index 01b5f34845..487c7dee16 100644 --- a/activesupport/test/core_ext/module/reachable_test.rb +++ b/activesupport/test/core_ext/module/reachable_test.rb @@ -38,4 +38,4 @@ class AnonymousTest < ActiveSupport::TestCase assert !c.reachable? assert !m.reachable? end -end \ No newline at end of file +end diff --git a/activesupport/test/core_ext/module_test.rb b/activesupport/test/core_ext/module_test.rb index 9a2e52efa7..bfe60e0f5f 100644 --- a/activesupport/test/core_ext/module_test.rb +++ b/activesupport/test/core_ext/module_test.rb @@ -43,9 +43,9 @@ class Someone < Struct.new(:name, :place) private - def private_name - "Private" - end + def private_name + "Private" + end end Invoice = Struct.new(:client) do diff --git a/activesupport/test/core_ext/object/inclusion_test.rb b/activesupport/test/core_ext/object/inclusion_test.rb index 9258c46be5..be211ec7dc 100644 --- a/activesupport/test/core_ext/object/inclusion_test.rb +++ b/activesupport/test/core_ext/object/inclusion_test.rb @@ -46,11 +46,11 @@ class InTest < ActiveSupport::TestCase assert !A.in?(A) assert !A.in?(D) end - + def test_no_method_catching assert_raise(ArgumentError) { 1.in?(1) } end - + def test_presence_in assert_equal "stuff", "stuff".presence_in(%w( lots of stuff )) assert_nil "stuff".presence_in(%w( lots of crap )) diff --git a/activesupport/test/dependencies/conflict.rb b/activesupport/test/dependencies/conflict.rb index e888b7b54c..7eff49bbfa 100644 --- a/activesupport/test/dependencies/conflict.rb +++ b/activesupport/test/dependencies/conflict.rb @@ -1 +1 @@ -Conflict = 1 \ No newline at end of file +Conflict = 1 diff --git a/activesupport/test/dependencies/cross_site_depender.rb b/activesupport/test/dependencies/cross_site_depender.rb index a31015fc5e..fbc3b64f56 100644 --- a/activesupport/test/dependencies/cross_site_depender.rb +++ b/activesupport/test/dependencies/cross_site_depender.rb @@ -1,3 +1,3 @@ class CrossSiteDepender CrossSiteDependency -end \ No newline at end of file +end diff --git a/activesupport/test/dependencies/service_one.rb b/activesupport/test/dependencies/service_one.rb index f43bfea235..afc3042269 100644 --- a/activesupport/test/dependencies/service_one.rb +++ b/activesupport/test/dependencies/service_one.rb @@ -2,4 +2,4 @@ $loaded_service_one ||= 0 $loaded_service_one += 1 class ServiceOne -end \ No newline at end of file +end diff --git a/activesupport/test/dependencies/service_two.rb b/activesupport/test/dependencies/service_two.rb index 5205a78bb8..aabfc3c553 100644 --- a/activesupport/test/dependencies/service_two.rb +++ b/activesupport/test/dependencies/service_two.rb @@ -1,2 +1,2 @@ class ServiceTwo -end \ No newline at end of file +end diff --git a/activesupport/test/dependencies_test_helpers.rb b/activesupport/test/dependencies_test_helpers.rb index 4ee01fda39..9bc63ed89e 100644 --- a/activesupport/test/dependencies_test_helpers.rb +++ b/activesupport/test/dependencies_test_helpers.rb @@ -25,4 +25,4 @@ module DependenciesTestHelpers Object.send(:remove_const, constant) if Object.const_defined?(constant) end end -end \ No newline at end of file +end diff --git a/activesupport/test/descendants_tracker_test_cases.rb b/activesupport/test/descendants_tracker_test_cases.rb index 4fba58bd47..09c5ce1f07 100644 --- a/activesupport/test/descendants_tracker_test_cases.rb +++ b/activesupport/test/descendants_tracker_test_cases.rb @@ -42,24 +42,24 @@ module DescendantsTrackerTestCases protected - def assert_equal_sets(expected, actual) - assert_equal Set.new(expected), Set.new(actual) - end - - def mark_as_autoloaded(*klasses) - # If ActiveSupport::Dependencies is not loaded, forget about autoloading. - # This allows using AS::DescendantsTracker without AS::Dependencies. - if defined? ActiveSupport::Dependencies - old_autoloaded = ActiveSupport::Dependencies.autoloaded_constants.dup - ActiveSupport::Dependencies.autoloaded_constants = klasses.map(&:name) + def assert_equal_sets(expected, actual) + assert_equal Set.new(expected), Set.new(actual) end - old_descendants = ActiveSupport::DescendantsTracker.class_eval("@@direct_descendants").dup - old_descendants.each { |k, v| old_descendants[k] = v.dup } + def mark_as_autoloaded(*klasses) + # If ActiveSupport::Dependencies is not loaded, forget about autoloading. + # This allows using AS::DescendantsTracker without AS::Dependencies. + if defined? ActiveSupport::Dependencies + old_autoloaded = ActiveSupport::Dependencies.autoloaded_constants.dup + ActiveSupport::Dependencies.autoloaded_constants = klasses.map(&:name) + end + + old_descendants = ActiveSupport::DescendantsTracker.class_eval("@@direct_descendants").dup + old_descendants.each { |k, v| old_descendants[k] = v.dup } - yield - ensure - ActiveSupport::Dependencies.autoloaded_constants = old_autoloaded if defined? ActiveSupport::Dependencies - ActiveSupport::DescendantsTracker.class_eval("@@direct_descendants").replace(old_descendants) - end + yield + ensure + ActiveSupport::Dependencies.autoloaded_constants = old_autoloaded if defined? ActiveSupport::Dependencies + ActiveSupport::DescendantsTracker.class_eval("@@direct_descendants").replace(old_descendants) + end end diff --git a/activesupport/test/fixtures/autoload/another_class.rb b/activesupport/test/fixtures/autoload/another_class.rb index a240b3de41..ab6e075ab4 100644 --- a/activesupport/test/fixtures/autoload/another_class.rb +++ b/activesupport/test/fixtures/autoload/another_class.rb @@ -1,2 +1,2 @@ class Fixtures::AnotherClass -end \ No newline at end of file +end diff --git a/activesupport/test/fixtures/autoload/some_class.rb b/activesupport/test/fixtures/autoload/some_class.rb index 13b3c73ef5..30d41eb0bf 100644 --- a/activesupport/test/fixtures/autoload/some_class.rb +++ b/activesupport/test/fixtures/autoload/some_class.rb @@ -1,2 +1,2 @@ class Fixtures::Autoload::SomeClass -end \ No newline at end of file +end diff --git a/activesupport/test/inflector_test_cases.rb b/activesupport/test/inflector_test_cases.rb index 4ee723076e..a8283301b3 100644 --- a/activesupport/test/inflector_test_cases.rb +++ b/activesupport/test/inflector_test_cases.rb @@ -176,12 +176,12 @@ module InflectorTestCases StringToParameterizedPreserveCase = { "Donald E. Knuth" => "Donald-E-Knuth", - "Random text with *(bad)* characters" => "Random-text-with-bad-characters", - "Allow_Under_Scores" => "Allow_Under_Scores", - "Trailing bad characters!@#" => "Trailing-bad-characters", - "!@#Leading bad characters" => "Leading-bad-characters", - "Squeeze separators" => "Squeeze-separators", - "Test with + sign" => "Test-with-sign", + "Random text with *(bad)* characters" => "Random-text-with-bad-characters", + "Allow_Under_Scores" => "Allow_Under_Scores", + "Trailing bad characters!@#" => "Trailing-bad-characters", + "!@#Leading bad characters" => "Leading-bad-characters", + "Squeeze separators" => "Squeeze-separators", + "Test with + sign" => "Test-with-sign", "Test with malformed utf8 \xA9" => "Test-with-malformed-utf8" } @@ -199,11 +199,11 @@ module InflectorTestCases StringToParameterizePreserveCaseWithNoSeparator = { "Donald E. Knuth" => "DonaldEKnuth", "With-some-dashes" => "With-some-dashes", - "Random text with *(bad)* characters" => "Randomtextwithbadcharacters", - "Trailing bad characters!@#" => "Trailingbadcharacters", - "!@#Leading bad characters" => "Leadingbadcharacters", - "Squeeze separators" => "Squeezeseparators", - "Test with + sign" => "Testwithsign", + "Random text with *(bad)* characters" => "Randomtextwithbadcharacters", + "Trailing bad characters!@#" => "Trailingbadcharacters", + "!@#Leading bad characters" => "Leadingbadcharacters", + "Squeeze separators" => "Squeezeseparators", + "Test with + sign" => "Testwithsign", "Test with malformed utf8 \xA9" => "Testwithmalformedutf8" } @@ -220,14 +220,14 @@ module InflectorTestCases } StringToParameterizePreserceCaseWithUnderscore = { - "Donald E. Knuth" => "Donald_E_Knuth", + "Donald E. Knuth" => "Donald_E_Knuth", "Random text with *(bad)* characters" => "Random_text_with_bad_characters", - "With-some-dashes" => "With-some-dashes", - "Allow_Under_Scores" => "Allow_Under_Scores", - "Trailing bad characters!@#" => "Trailing_bad_characters", - "!@#Leading bad characters" => "Leading_bad_characters", - "Squeeze separators" => "Squeeze_separators", - "Test with + sign" => "Test_with_sign", + "With-some-dashes" => "With-some-dashes", + "Allow_Under_Scores" => "Allow_Under_Scores", + "Trailing bad characters!@#" => "Trailing_bad_characters", + "!@#Leading bad characters" => "Leading_bad_characters", + "Squeeze separators" => "Squeeze_separators", + "Test with + sign" => "Test_with_sign", "Test with malformed utf8 \xA9" => "Test_with_malformed_utf8" } diff --git a/activesupport/test/json/decoding_test.rb b/activesupport/test/json/decoding_test.rb index 04eb10aafe..97cc508268 100644 --- a/activesupport/test/json/decoding_test.rb +++ b/activesupport/test/json/decoding_test.rb @@ -107,12 +107,11 @@ class TestJSONDecoding < ActiveSupport::TestCase private - def with_parse_json_times(value) - old_value = ActiveSupport.parse_json_times - ActiveSupport.parse_json_times = value - yield - ensure - ActiveSupport.parse_json_times = old_value - end + def with_parse_json_times(value) + old_value = ActiveSupport.parse_json_times + ActiveSupport.parse_json_times = value + yield + ensure + ActiveSupport.parse_json_times = old_value + end end - diff --git a/activesupport/test/key_generator_test.rb b/activesupport/test/key_generator_test.rb index 705537007a..89db9563ac 100644 --- a/activesupport/test/key_generator_test.rb +++ b/activesupport/test/key_generator_test.rb @@ -7,71 +7,71 @@ rescue LoadError, NameError $stderr.puts "Skipping KeyGenerator test: broken OpenSSL install" else -require "active_support/time" -require "active_support/json" - -class KeyGeneratorTest < ActiveSupport::TestCase - def setup - @secret = SecureRandom.hex(64) - @generator = ActiveSupport::KeyGenerator.new(@secret, iterations: 2) - end - - test "Generating a key of the default length" do - derived_key = @generator.generate_key("some_salt") - assert_kind_of String, derived_key - assert_equal 64, derived_key.length, "Should have generated a key of the default size" - end - - test "Generating a key of an alternative length" do - derived_key = @generator.generate_key("some_salt", 32) - assert_kind_of String, derived_key - assert_equal 32, derived_key.length, "Should have generated a key of the right size" + require "active_support/time" + require "active_support/json" + + class KeyGeneratorTest < ActiveSupport::TestCase + def setup + @secret = SecureRandom.hex(64) + @generator = ActiveSupport::KeyGenerator.new(@secret, iterations: 2) + end + + test "Generating a key of the default length" do + derived_key = @generator.generate_key("some_salt") + assert_kind_of String, derived_key + assert_equal 64, derived_key.length, "Should have generated a key of the default size" + end + + test "Generating a key of an alternative length" do + derived_key = @generator.generate_key("some_salt", 32) + assert_kind_of String, derived_key + assert_equal 32, derived_key.length, "Should have generated a key of the right size" + end + + test "Expected results" do + # For any given set of inputs, this method must continue to return + # the same output: if it changes, any existing values relying on a + # key would break. + + expected = "b129376f68f1ecae788d7433310249d65ceec090ecacd4c872a3a9e9ec78e055739be5cc6956345d5ae38e7e1daa66f1de587dc8da2bf9e8b965af4b3918a122" + assert_equal expected, ActiveSupport::KeyGenerator.new("0" * 64).generate_key("some_salt").unpack("H*").first + + expected = "b129376f68f1ecae788d7433310249d65ceec090ecacd4c872a3a9e9ec78e055" + assert_equal expected, ActiveSupport::KeyGenerator.new("0" * 64).generate_key("some_salt", 32).unpack("H*").first + + expected = "cbea7f7f47df705967dc508f4e446fd99e7797b1d70011c6899cd39bbe62907b8508337d678505a7dc8184e037f1003ba3d19fc5d829454668e91d2518692eae" + assert_equal expected, ActiveSupport::KeyGenerator.new("0" * 64, iterations: 2).generate_key("some_salt").unpack("H*").first + end end - test "Expected results" do - # For any given set of inputs, this method must continue to return - # the same output: if it changes, any existing values relying on a - # key would break. + class CachingKeyGeneratorTest < ActiveSupport::TestCase + def setup + @secret = SecureRandom.hex(64) + @generator = ActiveSupport::KeyGenerator.new(@secret, iterations: 2) + @caching_generator = ActiveSupport::CachingKeyGenerator.new(@generator) + end - expected = "b129376f68f1ecae788d7433310249d65ceec090ecacd4c872a3a9e9ec78e055739be5cc6956345d5ae38e7e1daa66f1de587dc8da2bf9e8b965af4b3918a122" - assert_equal expected, ActiveSupport::KeyGenerator.new("0" * 64).generate_key("some_salt").unpack("H*").first + 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) - expected = "b129376f68f1ecae788d7433310249d65ceec090ecacd4c872a3a9e9ec78e055" - assert_equal expected, ActiveSupport::KeyGenerator.new("0" * 64).generate_key("some_salt", 32).unpack("H*").first + assert_equal derived_key, cached_key + assert_equal derived_key.object_id, cached_key.object_id + end - expected = "cbea7f7f47df705967dc508f4e446fd99e7797b1d70011c6899cd39bbe62907b8508337d678505a7dc8184e037f1003ba3d19fc5d829454668e91d2518692eae" - assert_equal expected, ActiveSupport::KeyGenerator.new("0" * 64, iterations: 2).generate_key("some_salt").unpack("H*").first - end -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) -class CachingKeyGeneratorTest < ActiveSupport::TestCase - def setup - @secret = SecureRandom.hex(64) - @generator = ActiveSupport::KeyGenerator.new(@secret, iterations: 2) - @caching_generator = ActiveSupport::CachingKeyGenerator.new(@generator) - end + assert_not_equal derived_key, different_salt_key + 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) + 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_equal derived_key, cached_key - assert_equal derived_key.object_id, cached_key.object_id + assert_not_equal derived_key, different_length_key + end 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 diff --git a/activesupport/test/lazy_load_hooks_test.rb b/activesupport/test/lazy_load_hooks_test.rb index d08efa429a..3b1959a1c9 100644 --- a/activesupport/test/lazy_load_hooks_test.rb +++ b/activesupport/test/lazy_load_hooks_test.rb @@ -93,4 +93,4 @@ private @incr = incr end end -end \ No newline at end of file +end diff --git a/activesupport/test/message_encryptor_test.rb b/activesupport/test/message_encryptor_test.rb index a4976fa1ea..fb0b1e377d 100644 --- a/activesupport/test/message_encryptor_test.rb +++ b/activesupport/test/message_encryptor_test.rb @@ -90,21 +90,21 @@ class MessageEncryptorTest < ActiveSupport::TestCase private - def assert_not_decrypted(value) - assert_raise(ActiveSupport::MessageEncryptor::InvalidMessage) do - @encryptor.decrypt_and_verify(@verifier.generate(value)) + def assert_not_decrypted(value) + assert_raise(ActiveSupport::MessageEncryptor::InvalidMessage) do + @encryptor.decrypt_and_verify(@verifier.generate(value)) + end end - end - def assert_not_verified(value) - assert_raise(ActiveSupport::MessageVerifier::InvalidSignature) do - @encryptor.decrypt_and_verify(value) + def assert_not_verified(value) + assert_raise(ActiveSupport::MessageVerifier::InvalidSignature) do + @encryptor.decrypt_and_verify(value) + end end - end - def munge(base64_string) - bits = ::Base64.strict_decode64(base64_string) - bits.reverse! - ::Base64.strict_encode64(bits) - end + def munge(base64_string) + bits = ::Base64.strict_decode64(base64_string) + bits.reverse! + ::Base64.strict_encode64(bits) + end end diff --git a/activesupport/test/multibyte_chars_test.rb b/activesupport/test/multibyte_chars_test.rb index 81f05dcd5b..9ca9c7c803 100644 --- a/activesupport/test/multibyte_chars_test.rb +++ b/activesupport/test/multibyte_chars_test.rb @@ -513,7 +513,7 @@ class MultibyteCharsExtrasTest < ActiveSupport::TestCase "аБвг АБВГ" => "Абвг абвг", "АБВГ АБВГ" => "Абвг абвг", "" => "" }.each do |f,t| - assert_equal t, chars(f).capitalize + assert_equal t, chars(f).capitalize end end @@ -720,16 +720,16 @@ class MultibyteCharsExtrasTest < ActiveSupport::TestCase private - def string_from_classes(classes) - # Characters from the character classes as described in UAX #29 - character_from_class = { - l: 0x1100, v: 0x1160, t: 0x11A8, lv: 0xAC00, lvt: 0xAC01, cr: 0x000D, lf: 0x000A, - extend: 0x094D, n: 0x64, spacingmark: 0x0903, r: 0x1F1E6, control: 0x0001 - } - classes.collect do |k| - character_from_class[k.intern] - end.pack("U*") - end + def string_from_classes(classes) + # Characters from the character classes as described in UAX #29 + character_from_class = { + l: 0x1100, v: 0x1160, t: 0x11A8, lv: 0xAC00, lvt: 0xAC01, cr: 0x000D, lf: 0x000A, + extend: 0x094D, n: 0x64, spacingmark: 0x0903, r: 0x1F1E6, control: 0x0001 + } + classes.collect do |k| + character_from_class[k.intern] + end.pack("U*") + end end class MultibyteInternalsTest < ActiveSupport::TestCase diff --git a/activesupport/test/share_lock_test.rb b/activesupport/test/share_lock_test.rb index 168ead2401..8155d46934 100644 --- a/activesupport/test/share_lock_test.rb +++ b/activesupport/test/share_lock_test.rb @@ -489,90 +489,90 @@ class ShareLockTest < ActiveSupport::TestCase private - module CustomAssertions - SUFFICIENT_TIMEOUT = 0.2 + module CustomAssertions + SUFFICIENT_TIMEOUT = 0.2 - private + private - def assert_threads_stuck_but_releasable_by_latch(threads, latch) - assert_threads_stuck threads - latch.count_down - assert_threads_not_stuck threads - end + def assert_threads_stuck_but_releasable_by_latch(threads, latch) + assert_threads_stuck threads + latch.count_down + assert_threads_not_stuck threads + end - def assert_threads_stuck(threads) - sleep(SUFFICIENT_TIMEOUT) # give threads time to do their business - assert(Array(threads).all? { |t| t.join(0.001).nil? }) - end + def assert_threads_stuck(threads) + sleep(SUFFICIENT_TIMEOUT) # give threads time to do their business + assert(Array(threads).all? { |t| t.join(0.001).nil? }) + end - def assert_threads_not_stuck(threads) - assert(Array(threads).all? { |t| t.join(SUFFICIENT_TIMEOUT) }) + def assert_threads_not_stuck(threads) + assert(Array(threads).all? { |t| t.join(SUFFICIENT_TIMEOUT) }) + end end - end - class CustomAssertionsTest < ActiveSupport::TestCase - include CustomAssertions + class CustomAssertionsTest < ActiveSupport::TestCase + include CustomAssertions - def setup - @latch = Concurrent::CountDownLatch.new - @thread = Thread.new { @latch.wait } - end + def setup + @latch = Concurrent::CountDownLatch.new + @thread = Thread.new { @latch.wait } + end - def teardown - @latch.count_down - @thread.join - end + def teardown + @latch.count_down + @thread.join + end - def test_happy_path - assert_threads_stuck_but_releasable_by_latch @thread, @latch - end + def test_happy_path + assert_threads_stuck_but_releasable_by_latch @thread, @latch + end - def test_detects_stuck_thread - assert_raises(Minitest::Assertion) do - assert_threads_not_stuck @thread + def test_detects_stuck_thread + assert_raises(Minitest::Assertion) do + assert_threads_not_stuck @thread + end end - end - def test_detects_free_thread - @latch.count_down - assert_raises(Minitest::Assertion) do - assert_threads_stuck @thread + def test_detects_free_thread + @latch.count_down + assert_raises(Minitest::Assertion) do + assert_threads_stuck @thread + end end - end - def test_detects_already_released - @latch.count_down - assert_raises(Minitest::Assertion) do - assert_threads_stuck_but_releasable_by_latch @thread, @latch + def test_detects_already_released + @latch.count_down + assert_raises(Minitest::Assertion) do + assert_threads_stuck_but_releasable_by_latch @thread, @latch + end end - end - def test_detects_remains_latched - another_latch = Concurrent::CountDownLatch.new - assert_raises(Minitest::Assertion) do - assert_threads_stuck_but_releasable_by_latch @thread, another_latch + def test_detects_remains_latched + another_latch = Concurrent::CountDownLatch.new + assert_raises(Minitest::Assertion) do + assert_threads_stuck_but_releasable_by_latch @thread, another_latch + end end end - end - include CustomAssertions + include CustomAssertions - def with_thread_waiting_in_lock_section(lock_section) - in_section = Concurrent::CountDownLatch.new - section_release = Concurrent::CountDownLatch.new + def with_thread_waiting_in_lock_section(lock_section) + in_section = Concurrent::CountDownLatch.new + section_release = Concurrent::CountDownLatch.new - stuck_thread = Thread.new do - @lock.send(lock_section) do - in_section.count_down - section_release.wait + stuck_thread = Thread.new do + @lock.send(lock_section) do + in_section.count_down + section_release.wait + end end - end - in_section.wait + in_section.wait - yield section_release - ensure - section_release.count_down - stuck_thread.join # clean up - end + yield section_release + ensure + section_release.count_down + stuck_thread.join # clean up + end end diff --git a/activesupport/test/subscriber_test.rb b/activesupport/test/subscriber_test.rb index 5ec8affc9b..9127da35d4 100644 --- a/activesupport/test/subscriber_test.rb +++ b/activesupport/test/subscriber_test.rb @@ -16,9 +16,9 @@ class TestSubscriber < ActiveSupport::Subscriber private - def private_party(event) - events << event - end + def private_party(event) + events << event + end end # Monkey patch subscriber to test that only one subscriber per method is added. diff --git a/activesupport/test/xml_mini/jdom_engine_test.rb b/activesupport/test/xml_mini/jdom_engine_test.rb index fea3711c37..43edd49663 100644 --- a/activesupport/test/xml_mini/jdom_engine_test.rb +++ b/activesupport/test/xml_mini/jdom_engine_test.rb @@ -19,18 +19,18 @@ if RUBY_PLATFORM.include?("java") end def test_file_from_xml - hash = Hash.from_xml(<<-eoxml) + hash = Hash.from_xml(<<-eoxml) eoxml - assert hash.has_key?("blog") - assert hash["blog"].has_key?("logo") + assert hash.has_key?("blog") + assert hash["blog"].has_key?("logo") - file = hash["blog"]["logo"] - assert_equal "logo.png", file.original_filename - assert_equal "image/png", file.content_type + file = hash["blog"]["logo"] + assert_equal "logo.png", file.original_filename + assert_equal "image/png", file.content_type end def test_not_allowed_to_expand_entities_to_files diff --git a/activesupport/test/xml_mini/libxml_engine_test.rb b/activesupport/test/xml_mini/libxml_engine_test.rb index c40145ae5f..d5fd17d06e 100644 --- a/activesupport/test/xml_mini/libxml_engine_test.rb +++ b/activesupport/test/xml_mini/libxml_engine_test.rb @@ -3,56 +3,56 @@ begin rescue LoadError # Skip libxml tests else -require "abstract_unit" -require "active_support/xml_mini" -require "active_support/core_ext/hash/conversions" + require "abstract_unit" + require "active_support/xml_mini" + require "active_support/core_ext/hash/conversions" -class LibxmlEngineTest < ActiveSupport::TestCase - include ActiveSupport + class LibxmlEngineTest < ActiveSupport::TestCase + include ActiveSupport - def setup - @default_backend = XmlMini.backend - XmlMini.backend = "LibXML" + def setup + @default_backend = XmlMini.backend + XmlMini.backend = "LibXML" - LibXML::XML::Error.set_handler(&lambda { |error| }) #silence libxml, exceptions will do - end + LibXML::XML::Error.set_handler(&lambda { |error| }) #silence libxml, exceptions will do + end - def teardown - XmlMini.backend = @default_backend - end + def teardown + XmlMini.backend = @default_backend + end - def test_exception_thrown_on_expansion_attack - assert_raise LibXML::XML::Error do - attack_xml = %{ - - - - - - - - ]> - - &a; - - } - Hash.from_xml(attack_xml) + def test_exception_thrown_on_expansion_attack + assert_raise LibXML::XML::Error do + attack_xml = %{ + + + + + + + + ]> + + &a; + + } + Hash.from_xml(attack_xml) + end end - end - def test_setting_libxml_as_backend - XmlMini.backend = "LibXML" - assert_equal XmlMini_LibXML, XmlMini.backend - end + def test_setting_libxml_as_backend + XmlMini.backend = "LibXML" + assert_equal XmlMini_LibXML, XmlMini.backend + end - def test_blank_returns_empty_hash - assert_equal({}, XmlMini.parse(nil)) - assert_equal({}, XmlMini.parse("")) - end + def test_blank_returns_empty_hash + assert_equal({}, XmlMini.parse(nil)) + assert_equal({}, XmlMini.parse("")) + end - def test_array_type_makes_an_array - assert_equal_rexml(<<-eoxml) + def test_array_type_makes_an_array + assert_equal_rexml(<<-eoxml) a post @@ -60,67 +60,67 @@ class LibxmlEngineTest < ActiveSupport::TestCase eoxml - end + end - def test_one_node_document_as_hash - assert_equal_rexml(<<-eoxml) - - eoxml - end + def test_one_node_document_as_hash + assert_equal_rexml(<<-eoxml) + + eoxml + end - def test_one_node_with_attributes_document_as_hash - assert_equal_rexml(<<-eoxml) - - eoxml - end + def test_one_node_with_attributes_document_as_hash + assert_equal_rexml(<<-eoxml) + + eoxml + end - def test_products_node_with_book_node_as_hash - assert_equal_rexml(<<-eoxml) + def test_products_node_with_book_node_as_hash + assert_equal_rexml(<<-eoxml) eoxml - end + end - def test_products_node_with_two_book_nodes_as_hash - assert_equal_rexml(<<-eoxml) + def test_products_node_with_two_book_nodes_as_hash + assert_equal_rexml(<<-eoxml) eoxml - end + end - def test_single_node_with_content_as_hash - assert_equal_rexml(<<-eoxml) + def test_single_node_with_content_as_hash + assert_equal_rexml(<<-eoxml) hello world eoxml - end + end - def test_children_with_children - assert_equal_rexml(<<-eoxml) + def test_children_with_children + assert_equal_rexml(<<-eoxml) eoxml - end + end - def test_children_with_text - assert_equal_rexml(<<-eoxml) + def test_children_with_text + assert_equal_rexml(<<-eoxml) hello everyone eoxml - end + end - def test_children_with_non_adjacent_text - assert_equal_rexml(<<-eoxml) + def test_children_with_non_adjacent_text + assert_equal_rexml(<<-eoxml) good @@ -129,10 +129,10 @@ class LibxmlEngineTest < ActiveSupport::TestCase morning eoxml - end + end - def test_parse_from_io - io = StringIO.new(<<-eoxml) + def test_parse_from_io + io = StringIO.new(<<-eoxml) good @@ -141,31 +141,31 @@ class LibxmlEngineTest < ActiveSupport::TestCase morning eoxml - assert_equal_rexml(io) - end + assert_equal_rexml(io) + end - def test_children_with_simple_cdata - assert_equal_rexml(<<-eoxml) + def test_children_with_simple_cdata + assert_equal_rexml(<<-eoxml) eoxml - end + end - def test_children_with_multiple_cdata - assert_equal_rexml(<<-eoxml) + def test_children_with_multiple_cdata + assert_equal_rexml(<<-eoxml) eoxml - end + end - def test_children_with_text_and_cdata - assert_equal_rexml(<<-eoxml) + def test_children_with_text_and_cdata + assert_equal_rexml(<<-eoxml) hello @@ -173,32 +173,32 @@ class LibxmlEngineTest < ActiveSupport::TestCase eoxml - end + end - def test_children_with_blank_text - assert_equal_rexml(<<-eoxml) + def test_children_with_blank_text + assert_equal_rexml(<<-eoxml) eoxml - end + end - def test_children_with_blank_text_and_attribute - assert_equal_rexml(<<-eoxml) + def test_children_with_blank_text_and_attribute + assert_equal_rexml(<<-eoxml) eoxml - end + end - private - def assert_equal_rexml(xml) - parsed_xml = XmlMini.parse(xml) - xml.rewind if xml.respond_to?(:rewind) - hash = XmlMini.with_backend("REXML") { XmlMini.parse(xml) } - assert_equal(hash, parsed_xml) - end -end + private + def assert_equal_rexml(xml) + parsed_xml = XmlMini.parse(xml) + xml.rewind if xml.respond_to?(:rewind) + hash = XmlMini.with_backend("REXML") { XmlMini.parse(xml) } + assert_equal(hash, parsed_xml) + end + end end diff --git a/activesupport/test/xml_mini/libxmlsax_engine_test.rb b/activesupport/test/xml_mini/libxmlsax_engine_test.rb index a92cd9da8c..e25fa2813c 100644 --- a/activesupport/test/xml_mini/libxmlsax_engine_test.rb +++ b/activesupport/test/xml_mini/libxmlsax_engine_test.rb @@ -3,25 +3,25 @@ begin rescue LoadError # Skip libxml tests else -require "abstract_unit" -require "active_support/xml_mini" -require "active_support/core_ext/hash/conversions" + require "abstract_unit" + require "active_support/xml_mini" + require "active_support/core_ext/hash/conversions" -class LibXMLSAXEngineTest < ActiveSupport::TestCase - include ActiveSupport + class LibXMLSAXEngineTest < ActiveSupport::TestCase + include ActiveSupport - def setup - @default_backend = XmlMini.backend - XmlMini.backend = "LibXMLSAX" - end + def setup + @default_backend = XmlMini.backend + XmlMini.backend = "LibXMLSAX" + end - def teardown - XmlMini.backend = @default_backend - end + def teardown + XmlMini.backend = @default_backend + end - def test_exception_thrown_on_expansion_attack - assert_raise LibXML::XML::Error do - attack_xml = <<-EOT + def test_exception_thrown_on_expansion_attack + assert_raise LibXML::XML::Error do + attack_xml = <<-EOT @@ -37,22 +37,22 @@ class LibXMLSAXEngineTest < ActiveSupport::TestCase EOT - Hash.from_xml(attack_xml) + Hash.from_xml(attack_xml) + end end - end - def test_setting_libxml_as_backend - XmlMini.backend = "LibXMLSAX" - assert_equal XmlMini_LibXMLSAX, XmlMini.backend - end + def test_setting_libxml_as_backend + XmlMini.backend = "LibXMLSAX" + assert_equal XmlMini_LibXMLSAX, XmlMini.backend + end - def test_blank_returns_empty_hash - assert_equal({}, XmlMini.parse(nil)) - assert_equal({}, XmlMini.parse("")) - end + def test_blank_returns_empty_hash + assert_equal({}, XmlMini.parse(nil)) + assert_equal({}, XmlMini.parse("")) + end - def test_array_type_makes_an_array - assert_equal_rexml(<<-eoxml) + def test_array_type_makes_an_array + assert_equal_rexml(<<-eoxml) a post @@ -60,67 +60,67 @@ class LibXMLSAXEngineTest < ActiveSupport::TestCase eoxml - end + end - def test_one_node_document_as_hash - assert_equal_rexml(<<-eoxml) - - eoxml - end + def test_one_node_document_as_hash + assert_equal_rexml(<<-eoxml) + + eoxml + end - def test_one_node_with_attributes_document_as_hash - assert_equal_rexml(<<-eoxml) - - eoxml - end + def test_one_node_with_attributes_document_as_hash + assert_equal_rexml(<<-eoxml) + + eoxml + end - def test_products_node_with_book_node_as_hash - assert_equal_rexml(<<-eoxml) + def test_products_node_with_book_node_as_hash + assert_equal_rexml(<<-eoxml) eoxml - end + end - def test_products_node_with_two_book_nodes_as_hash - assert_equal_rexml(<<-eoxml) + def test_products_node_with_two_book_nodes_as_hash + assert_equal_rexml(<<-eoxml) eoxml - end + end - def test_single_node_with_content_as_hash - assert_equal_rexml(<<-eoxml) + def test_single_node_with_content_as_hash + assert_equal_rexml(<<-eoxml) hello world eoxml - end + end - def test_children_with_children - assert_equal_rexml(<<-eoxml) + def test_children_with_children + assert_equal_rexml(<<-eoxml) eoxml - end + end - def test_children_with_text - assert_equal_rexml(<<-eoxml) + def test_children_with_text + assert_equal_rexml(<<-eoxml) hello everyone eoxml - end + end - def test_children_with_non_adjacent_text - assert_equal_rexml(<<-eoxml) + def test_children_with_non_adjacent_text + assert_equal_rexml(<<-eoxml) good @@ -129,10 +129,10 @@ class LibXMLSAXEngineTest < ActiveSupport::TestCase morning eoxml - end + end - def test_parse_from_io - io = StringIO.new(<<-eoxml) + def test_parse_from_io + io = StringIO.new(<<-eoxml) good @@ -141,31 +141,31 @@ class LibXMLSAXEngineTest < ActiveSupport::TestCase morning eoxml - assert_equal_rexml(io) - end + assert_equal_rexml(io) + end - def test_children_with_simple_cdata - assert_equal_rexml(<<-eoxml) + def test_children_with_simple_cdata + assert_equal_rexml(<<-eoxml) eoxml - end + end - def test_children_with_multiple_cdata - assert_equal_rexml(<<-eoxml) + def test_children_with_multiple_cdata + assert_equal_rexml(<<-eoxml) eoxml - end + end - def test_children_with_text_and_cdata - assert_equal_rexml(<<-eoxml) + def test_children_with_text_and_cdata + assert_equal_rexml(<<-eoxml) hello @@ -173,23 +173,23 @@ class LibXMLSAXEngineTest < ActiveSupport::TestCase eoxml - end + end - def test_children_with_blank_text - assert_equal_rexml(<<-eoxml) + def test_children_with_blank_text + assert_equal_rexml(<<-eoxml) eoxml - end - - private - def assert_equal_rexml(xml) - parsed_xml = XmlMini.parse(xml) - xml.rewind if xml.respond_to?(:rewind) - hash = XmlMini.with_backend("REXML") { XmlMini.parse(xml) } - assert_equal(hash, parsed_xml) end -end + + private + def assert_equal_rexml(xml) + parsed_xml = XmlMini.parse(xml) + xml.rewind if xml.respond_to?(:rewind) + hash = XmlMini.with_backend("REXML") { XmlMini.parse(xml) } + assert_equal(hash, parsed_xml) + end + end end diff --git a/activesupport/test/xml_mini/nokogiri_engine_test.rb b/activesupport/test/xml_mini/nokogiri_engine_test.rb index dd169e7eb4..44b82da4e4 100644 --- a/activesupport/test/xml_mini/nokogiri_engine_test.rb +++ b/activesupport/test/xml_mini/nokogiri_engine_test.rb @@ -3,38 +3,38 @@ begin rescue LoadError # Skip nokogiri tests else -require "abstract_unit" -require "active_support/xml_mini" -require "active_support/core_ext/hash/conversions" - -class NokogiriEngineTest < ActiveSupport::TestCase - def setup - @default_backend = ActiveSupport::XmlMini.backend - ActiveSupport::XmlMini.backend = "Nokogiri" - end + require "abstract_unit" + require "active_support/xml_mini" + require "active_support/core_ext/hash/conversions" + + class NokogiriEngineTest < ActiveSupport::TestCase + def setup + @default_backend = ActiveSupport::XmlMini.backend + ActiveSupport::XmlMini.backend = "Nokogiri" + end - def teardown - ActiveSupport::XmlMini.backend = @default_backend - end + def teardown + ActiveSupport::XmlMini.backend = @default_backend + end - def test_file_from_xml - hash = Hash.from_xml(<<-eoxml) + def test_file_from_xml + hash = Hash.from_xml(<<-eoxml) eoxml - assert hash.has_key?("blog") - assert hash["blog"].has_key?("logo") + assert hash.has_key?("blog") + assert hash["blog"].has_key?("logo") - file = hash["blog"]["logo"] - assert_equal "logo.png", file.original_filename - assert_equal "image/png", file.content_type - end + file = hash["blog"]["logo"] + assert_equal "logo.png", file.original_filename + assert_equal "image/png", file.content_type + end - def test_exception_thrown_on_expansion_attack - assert_raise Nokogiri::XML::SyntaxError do - attack_xml = <<-EOT + def test_exception_thrown_on_expansion_attack + assert_raise Nokogiri::XML::SyntaxError do + attack_xml = <<-EOT @@ -49,22 +49,22 @@ class NokogiriEngineTest < ActiveSupport::TestCase &a; EOT - Hash.from_xml(attack_xml) + Hash.from_xml(attack_xml) + end end - end - def test_setting_nokogiri_as_backend - ActiveSupport::XmlMini.backend = "Nokogiri" - assert_equal ActiveSupport::XmlMini_Nokogiri, ActiveSupport::XmlMini.backend - end + def test_setting_nokogiri_as_backend + ActiveSupport::XmlMini.backend = "Nokogiri" + assert_equal ActiveSupport::XmlMini_Nokogiri, ActiveSupport::XmlMini.backend + end - def test_blank_returns_empty_hash - assert_equal({}, ActiveSupport::XmlMini.parse(nil)) - assert_equal({}, ActiveSupport::XmlMini.parse("")) - end + def test_blank_returns_empty_hash + assert_equal({}, ActiveSupport::XmlMini.parse(nil)) + assert_equal({}, ActiveSupport::XmlMini.parse("")) + end - def test_array_type_makes_an_array - assert_equal_rexml(<<-eoxml) + def test_array_type_makes_an_array + assert_equal_rexml(<<-eoxml) a post @@ -72,67 +72,67 @@ class NokogiriEngineTest < ActiveSupport::TestCase eoxml - end + end - def test_one_node_document_as_hash - assert_equal_rexml(<<-eoxml) - - eoxml - end + def test_one_node_document_as_hash + assert_equal_rexml(<<-eoxml) + + eoxml + end - def test_one_node_with_attributes_document_as_hash - assert_equal_rexml(<<-eoxml) - - eoxml - end + def test_one_node_with_attributes_document_as_hash + assert_equal_rexml(<<-eoxml) + + eoxml + end - def test_products_node_with_book_node_as_hash - assert_equal_rexml(<<-eoxml) + def test_products_node_with_book_node_as_hash + assert_equal_rexml(<<-eoxml) eoxml - end + end - def test_products_node_with_two_book_nodes_as_hash - assert_equal_rexml(<<-eoxml) + def test_products_node_with_two_book_nodes_as_hash + assert_equal_rexml(<<-eoxml) eoxml - end + end - def test_single_node_with_content_as_hash - assert_equal_rexml(<<-eoxml) + def test_single_node_with_content_as_hash + assert_equal_rexml(<<-eoxml) hello world eoxml - end + end - def test_children_with_children - assert_equal_rexml(<<-eoxml) + def test_children_with_children + assert_equal_rexml(<<-eoxml) eoxml - end + end - def test_children_with_text - assert_equal_rexml(<<-eoxml) + def test_children_with_text + assert_equal_rexml(<<-eoxml) hello everyone eoxml - end + end - def test_children_with_non_adjacent_text - assert_equal_rexml(<<-eoxml) + def test_children_with_non_adjacent_text + assert_equal_rexml(<<-eoxml) good @@ -141,10 +141,10 @@ class NokogiriEngineTest < ActiveSupport::TestCase morning eoxml - end + end - def test_parse_from_io - io = StringIO.new(<<-eoxml) + def test_parse_from_io + io = StringIO.new(<<-eoxml) good @@ -153,31 +153,31 @@ class NokogiriEngineTest < ActiveSupport::TestCase morning eoxml - assert_equal_rexml(io) - end + assert_equal_rexml(io) + end - def test_children_with_simple_cdata - assert_equal_rexml(<<-eoxml) + def test_children_with_simple_cdata + assert_equal_rexml(<<-eoxml) eoxml - end + end - def test_children_with_multiple_cdata - assert_equal_rexml(<<-eoxml) + def test_children_with_multiple_cdata + assert_equal_rexml(<<-eoxml) eoxml - end + end - def test_children_with_text_and_cdata - assert_equal_rexml(<<-eoxml) + def test_children_with_text_and_cdata + assert_equal_rexml(<<-eoxml) hello @@ -185,31 +185,31 @@ class NokogiriEngineTest < ActiveSupport::TestCase eoxml - end + end - def test_children_with_blank_text - assert_equal_rexml(<<-eoxml) + def test_children_with_blank_text + assert_equal_rexml(<<-eoxml) eoxml - end + end - def test_children_with_blank_text_and_attribute - assert_equal_rexml(<<-eoxml) + def test_children_with_blank_text_and_attribute + assert_equal_rexml(<<-eoxml) eoxml - end - - private - def assert_equal_rexml(xml) - parsed_xml = ActiveSupport::XmlMini.parse(xml) - xml.rewind if xml.respond_to?(:rewind) - hash = ActiveSupport::XmlMini.with_backend("REXML") { ActiveSupport::XmlMini.parse(xml) } - assert_equal(hash, parsed_xml) end -end + + private + def assert_equal_rexml(xml) + parsed_xml = ActiveSupport::XmlMini.parse(xml) + xml.rewind if xml.respond_to?(:rewind) + hash = ActiveSupport::XmlMini.with_backend("REXML") { ActiveSupport::XmlMini.parse(xml) } + assert_equal(hash, parsed_xml) + end + end end diff --git a/activesupport/test/xml_mini/nokogirisax_engine_test.rb b/activesupport/test/xml_mini/nokogirisax_engine_test.rb index 9a2bcc3f7e..24b35cadf6 100644 --- a/activesupport/test/xml_mini/nokogirisax_engine_test.rb +++ b/activesupport/test/xml_mini/nokogirisax_engine_test.rb @@ -3,38 +3,38 @@ begin rescue LoadError # Skip nokogiri tests else -require "abstract_unit" -require "active_support/xml_mini" -require "active_support/core_ext/hash/conversions" - -class NokogiriSAXEngineTest < ActiveSupport::TestCase - def setup - @default_backend = ActiveSupport::XmlMini.backend - ActiveSupport::XmlMini.backend = "NokogiriSAX" - end + require "abstract_unit" + require "active_support/xml_mini" + require "active_support/core_ext/hash/conversions" + + class NokogiriSAXEngineTest < ActiveSupport::TestCase + def setup + @default_backend = ActiveSupport::XmlMini.backend + ActiveSupport::XmlMini.backend = "NokogiriSAX" + end - def teardown - ActiveSupport::XmlMini.backend = @default_backend - end + def teardown + ActiveSupport::XmlMini.backend = @default_backend + end - def test_file_from_xml - hash = Hash.from_xml(<<-eoxml) + def test_file_from_xml + hash = Hash.from_xml(<<-eoxml) eoxml - assert hash.has_key?("blog") - assert hash["blog"].has_key?("logo") + assert hash.has_key?("blog") + assert hash["blog"].has_key?("logo") - file = hash["blog"]["logo"] - assert_equal "logo.png", file.original_filename - assert_equal "image/png", file.content_type - end + file = hash["blog"]["logo"] + assert_equal "logo.png", file.original_filename + assert_equal "image/png", file.content_type + end - def test_exception_thrown_on_expansion_attack - assert_raise RuntimeError do - attack_xml = <<-EOT + def test_exception_thrown_on_expansion_attack + assert_raise RuntimeError do + attack_xml = <<-EOT @@ -50,22 +50,22 @@ class NokogiriSAXEngineTest < ActiveSupport::TestCase EOT - Hash.from_xml(attack_xml) + Hash.from_xml(attack_xml) + end end - end - def test_setting_nokogirisax_as_backend - ActiveSupport::XmlMini.backend = "NokogiriSAX" - assert_equal ActiveSupport::XmlMini_NokogiriSAX, ActiveSupport::XmlMini.backend - end + def test_setting_nokogirisax_as_backend + ActiveSupport::XmlMini.backend = "NokogiriSAX" + assert_equal ActiveSupport::XmlMini_NokogiriSAX, ActiveSupport::XmlMini.backend + end - def test_blank_returns_empty_hash - assert_equal({}, ActiveSupport::XmlMini.parse(nil)) - assert_equal({}, ActiveSupport::XmlMini.parse("")) - end + def test_blank_returns_empty_hash + assert_equal({}, ActiveSupport::XmlMini.parse(nil)) + assert_equal({}, ActiveSupport::XmlMini.parse("")) + end - def test_array_type_makes_an_array - assert_equal_rexml(<<-eoxml) + def test_array_type_makes_an_array + assert_equal_rexml(<<-eoxml) a post @@ -73,67 +73,67 @@ class NokogiriSAXEngineTest < ActiveSupport::TestCase eoxml - end + end - def test_one_node_document_as_hash - assert_equal_rexml(<<-eoxml) - - eoxml - end + def test_one_node_document_as_hash + assert_equal_rexml(<<-eoxml) + + eoxml + end - def test_one_node_with_attributes_document_as_hash - assert_equal_rexml(<<-eoxml) - - eoxml - end + def test_one_node_with_attributes_document_as_hash + assert_equal_rexml(<<-eoxml) + + eoxml + end - def test_products_node_with_book_node_as_hash - assert_equal_rexml(<<-eoxml) + def test_products_node_with_book_node_as_hash + assert_equal_rexml(<<-eoxml) eoxml - end + end - def test_products_node_with_two_book_nodes_as_hash - assert_equal_rexml(<<-eoxml) + def test_products_node_with_two_book_nodes_as_hash + assert_equal_rexml(<<-eoxml) eoxml - end + end - def test_single_node_with_content_as_hash - assert_equal_rexml(<<-eoxml) + def test_single_node_with_content_as_hash + assert_equal_rexml(<<-eoxml) hello world eoxml - end + end - def test_children_with_children - assert_equal_rexml(<<-eoxml) + def test_children_with_children + assert_equal_rexml(<<-eoxml) eoxml - end + end - def test_children_with_text - assert_equal_rexml(<<-eoxml) + def test_children_with_text + assert_equal_rexml(<<-eoxml) hello everyone eoxml - end + end - def test_children_with_non_adjacent_text - assert_equal_rexml(<<-eoxml) + def test_children_with_non_adjacent_text + assert_equal_rexml(<<-eoxml) good @@ -142,10 +142,10 @@ class NokogiriSAXEngineTest < ActiveSupport::TestCase morning eoxml - end + end - def test_parse_from_io - io = StringIO.new(<<-eoxml) + def test_parse_from_io + io = StringIO.new(<<-eoxml) good @@ -154,31 +154,31 @@ class NokogiriSAXEngineTest < ActiveSupport::TestCase morning eoxml - assert_equal_rexml(io) - end + assert_equal_rexml(io) + end - def test_children_with_simple_cdata - assert_equal_rexml(<<-eoxml) + def test_children_with_simple_cdata + assert_equal_rexml(<<-eoxml) eoxml - end + end - def test_children_with_multiple_cdata - assert_equal_rexml(<<-eoxml) + def test_children_with_multiple_cdata + assert_equal_rexml(<<-eoxml) eoxml - end + end - def test_children_with_text_and_cdata - assert_equal_rexml(<<-eoxml) + def test_children_with_text_and_cdata + assert_equal_rexml(<<-eoxml) hello @@ -186,31 +186,31 @@ class NokogiriSAXEngineTest < ActiveSupport::TestCase eoxml - end + end - def test_children_with_blank_text - assert_equal_rexml(<<-eoxml) + def test_children_with_blank_text + assert_equal_rexml(<<-eoxml) eoxml - end + end - def test_children_with_blank_text_and_attribute - assert_equal_rexml(<<-eoxml) + def test_children_with_blank_text_and_attribute + assert_equal_rexml(<<-eoxml) eoxml - end - - private - def assert_equal_rexml(xml) - parsed_xml = ActiveSupport::XmlMini.parse(xml) - xml.rewind if xml.respond_to?(:rewind) - hash = ActiveSupport::XmlMini.with_backend("REXML") { ActiveSupport::XmlMini.parse(xml) } - assert_equal(hash, parsed_xml) end -end + + private + def assert_equal_rexml(xml) + parsed_xml = ActiveSupport::XmlMini.parse(xml) + xml.rewind if xml.respond_to?(:rewind) + hash = ActiveSupport::XmlMini.with_backend("REXML") { ActiveSupport::XmlMini.parse(xml) } + assert_equal(hash, parsed_xml) + end + end end diff --git a/activesupport/test/xml_mini/rexml_engine_test.rb b/activesupport/test/xml_mini/rexml_engine_test.rb index 2af98f7fe2..a3bae7a89c 100644 --- a/activesupport/test/xml_mini/rexml_engine_test.rb +++ b/activesupport/test/xml_mini/rexml_engine_test.rb @@ -26,8 +26,8 @@ class REXMLEngineTest < ActiveSupport::TestCase assert hash.has_key?("root") assert hash["root"].has_key?("products") assert_match "good", hash["root"]["__content__"] - products = hash["root"]["products"] - assert products.has_key?("__content__") + products = hash["root"]["products"] + assert products.has_key?("__content__") assert_match "hello everyone", products["__content__"] end -- cgit v1.2.3