diff options
Diffstat (limited to 'activesupport/test')
159 files changed, 4018 insertions, 4040 deletions
diff --git a/activesupport/test/abstract_unit.rb b/activesupport/test/abstract_unit.rb index bab7440397..4e564591b4 100644 --- a/activesupport/test/abstract_unit.rb +++ b/activesupport/test/abstract_unit.rb @@ -1,17 +1,17 @@ ORIG_ARGV = ARGV.dup -require 'active_support/core_ext/kernel/reporting' +require "active_support/core_ext/kernel/reporting" silence_warnings do Encoding.default_internal = "UTF-8" Encoding.default_external = "UTF-8" end -require 'active_support/testing/autorun' -require 'active_support/testing/method_call_assertions' +require "active_support/testing/autorun" +require "active_support/testing/method_call_assertions" -ENV['NO_RELOAD'] = '1' -require 'active_support' +ENV["NO_RELOAD"] = "1" +require "active_support" Thread.abort_on_exception = true @@ -19,18 +19,18 @@ Thread.abort_on_exception = true ActiveSupport::Deprecation.debug = true # Default to old to_time behavior but allow running tests with new behavior -ActiveSupport.to_time_preserves_timezone = ENV['PRESERVE_TIMEZONES'] == '1' +ActiveSupport.to_time_preserves_timezone = ENV["PRESERVE_TIMEZONES"] == "1" # Disable available locale checks to avoid warnings running the test suite. I18n.enforce_available_locales = false # Skips the current run on Rubinius using Minitest::Assertions#skip -def rubinius_skip(message = '') - skip message if RUBY_ENGINE == 'rbx' +def rubinius_skip(message = "") + skip message if RUBY_ENGINE == "rbx" end # Skips the current run on JRuby using Minitest::Assertions#skip -def jruby_skip(message = '') +def jruby_skip(message = "") skip message if defined?(JRUBY_VERSION) end diff --git a/activesupport/test/array_inquirer_test.rb b/activesupport/test/array_inquirer_test.rb index 263ab3802b..4d3f5b001c 100644 --- a/activesupport/test/array_inquirer_test.rb +++ b/activesupport/test/array_inquirer_test.rb @@ -1,9 +1,9 @@ -require 'abstract_unit' -require 'active_support/core_ext/array' +require "abstract_unit" +require "active_support/core_ext/array" class ArrayInquirerTest < ActiveSupport::TestCase def setup - @array_inquirer = ActiveSupport::ArrayInquirer.new([:mobile, :tablet, 'api']) + @array_inquirer = ActiveSupport::ArrayInquirer.new([:mobile, :tablet, "api"]) end def test_individual @@ -19,7 +19,7 @@ class ArrayInquirerTest < ActiveSupport::TestCase end def test_any_string_symbol_mismatch - assert @array_inquirer.any?('mobile') + assert @array_inquirer.any?("mobile") assert @array_inquirer.any?(:api) end @@ -33,7 +33,7 @@ class ArrayInquirerTest < ActiveSupport::TestCase end def test_inquiry - result = [:mobile, :tablet, 'api'].inquiry + result = [:mobile, :tablet, "api"].inquiry assert_instance_of ActiveSupport::ArrayInquirer, result assert_equal @array_inquirer, result diff --git a/activesupport/test/autoload_test.rb b/activesupport/test/autoload_test.rb index c18b007612..c4d6a69212 100644 --- a/activesupport/test/autoload_test.rb +++ b/activesupport/test/autoload_test.rb @@ -1,4 +1,4 @@ -require 'abstract_unit' +require "abstract_unit" class TestAutoloadModule < ActiveSupport::TestCase include ActiveSupport::Testing::Isolation @@ -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/class_folder.rb b/activesupport/test/autoloading_fixtures/class_folder.rb index ad2b27be61..6ee8182214 100644 --- a/activesupport/test/autoloading_fixtures/class_folder.rb +++ b/activesupport/test/autoloading_fixtures/class_folder.rb @@ -1,3 +1,3 @@ class ClassFolder - ConstantInClassFolder = 'indeed' + ConstantInClassFolder = "indeed" end diff --git a/activesupport/test/autoloading_fixtures/class_folder/class_folder_subclass.rb b/activesupport/test/autoloading_fixtures/class_folder/class_folder_subclass.rb index 402609c583..4df069cab6 100644 --- a/activesupport/test/autoloading_fixtures/class_folder/class_folder_subclass.rb +++ b/activesupport/test/autoloading_fixtures/class_folder/class_folder_subclass.rb @@ -1,3 +1,3 @@ class ClassFolder::ClassFolderSubclass < ClassFolder - ConstantInClassFolder = 'indeed' + ConstantInClassFolder = "indeed" 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/raises_arbitrary_exception.rb b/activesupport/test/autoloading_fixtures/raises_arbitrary_exception.rb index 3ca4213c71..829ee917d2 100644 --- a/activesupport/test/autoloading_fixtures/raises_arbitrary_exception.rb +++ b/activesupport/test/autoloading_fixtures/raises_arbitrary_exception.rb @@ -1,4 +1,4 @@ RaisesArbitraryException = 1 _ = A::B # Autoloading recursion, also expected to be watched and discarded. -raise Exception, 'arbitray exception message' +raise Exception, "arbitray exception message" 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/benchmarkable_test.rb b/activesupport/test/benchmarkable_test.rb index 5af041f458..210b9cb9fd 100644 --- a/activesupport/test/benchmarkable_test.rb +++ b/activesupport/test/benchmarkable_test.rb @@ -1,4 +1,4 @@ -require 'abstract_unit' +require "abstract_unit" class BenchmarkableTest < ActiveSupport::TestCase include ActiveSupport::Benchmarkable @@ -36,20 +36,20 @@ class BenchmarkableTest < ActiveSupport::TestCase def test_with_message i_was_run = false - benchmark('test_run') { i_was_run = true } + benchmark("test_run") { i_was_run = true } assert i_was_run - assert_last_logged 'test_run' + assert_last_logged "test_run" end def test_with_silence - assert_difference 'buffer.count', +2 do - benchmark('test_run') do + assert_difference "buffer.count", +2 do + benchmark("test_run") do logger.info "SOMETHING" end end - assert_difference 'buffer.count', +1 do - benchmark('test_run', silence: true) do + assert_difference "buffer.count", +1 do + benchmark("test_run", silence: true) do logger.info "NOTHING" end end @@ -57,20 +57,20 @@ class BenchmarkableTest < ActiveSupport::TestCase def test_within_level logger.level = ActiveSupport::Logger::DEBUG - benchmark('included_debug_run', :level => :debug) { } - assert_last_logged 'included_debug_run' + benchmark("included_debug_run", level: :debug) {} + assert_last_logged "included_debug_run" end def test_outside_level logger.level = ActiveSupport::Logger::ERROR - benchmark('skipped_debug_run', :level => :debug) { } + benchmark("skipped_debug_run", level: :debug) {} assert_no_match(/skipped_debug_run/, buffer.last) ensure logger.level = ActiveSupport::Logger::DEBUG end private - def assert_last_logged(message = 'Benchmarking') + def assert_last_logged(message = "Benchmarking") assert_match(/^#{message} \(.*\)$/, buffer.last) end end diff --git a/activesupport/test/broadcast_logger_test.rb b/activesupport/test/broadcast_logger_test.rb index f95b3e5ad3..4b74f1313e 100644 --- a/activesupport/test/broadcast_logger_test.rb +++ b/activesupport/test/broadcast_logger_test.rb @@ -1,4 +1,4 @@ -require 'abstract_unit' +require "abstract_unit" module ActiveSupport class BroadcastLoggerTest < TestCase @@ -26,8 +26,8 @@ module ActiveSupport test "#close broadcasts to all loggers" do logger.close - assert log1.closed, 'should be closed' - assert log2.closed, 'should be closed' + assert log1.closed, "should be closed" + assert log2.closed, "should be closed" end test "#<< shovels the value into all loggers" do @@ -138,7 +138,7 @@ module ActiveSupport add(::Logger::UNKNOWN, message, &block) end - def << x + def <<(x) @chevrons << x end diff --git a/activesupport/test/caching_test.rb b/activesupport/test/caching_test.rb index d4dec81b28..4e47465726 100644 --- a/activesupport/test/caching_test.rb +++ b/activesupport/test/caching_test.rb @@ -1,9 +1,9 @@ -require 'logger' -require 'abstract_unit' -require 'active_support/cache' -require 'dependencies_test_helpers' +require "logger" +require "abstract_unit" +require "active_support/cache" +require "dependencies_test_helpers" -require 'pathname' +require "pathname" module ActiveSupport module Cache @@ -13,14 +13,14 @@ module ActiveSupport def test_local_cache_cleared_on_close key = "super awesome key" assert_nil LocalCacheRegistry.cache_for key - middleware = Middleware.new('<3', key).new(->(env) { - assert LocalCacheRegistry.cache_for(key), 'should have a cache' + middleware = Middleware.new("<3", key).new(->(env) { + assert LocalCacheRegistry.cache_for(key), "should have a cache" [200, {}, []] }) _, _, body = middleware.call({}) - assert LocalCacheRegistry.cache_for(key), 'should still have a cache' - body.each { } - assert LocalCacheRegistry.cache_for(key), 'should still have a cache' + assert LocalCacheRegistry.cache_for(key), "should still have a cache" + body.each {} + assert LocalCacheRegistry.cache_for(key), "should still have a cache" body.close assert_nil LocalCacheRegistry.cache_for(key) end @@ -28,20 +28,20 @@ module ActiveSupport def test_local_cache_cleared_and_response_should_be_present_on_invalid_parameters_error key = "super awesome key" assert_nil LocalCacheRegistry.cache_for key - middleware = Middleware.new('<3', key).new(->(env) { - assert LocalCacheRegistry.cache_for(key), 'should have a cache' + middleware = Middleware.new("<3", key).new(->(env) { + assert LocalCacheRegistry.cache_for(key), "should have a cache" raise Rack::Utils::InvalidParameterError }) response = middleware.call({}) - assert response, 'response should exist' + assert response, "response should exist" assert_nil LocalCacheRegistry.cache_for(key) end def test_local_cache_cleared_on_exception key = "super awesome key" assert_nil LocalCacheRegistry.cache_for key - middleware = Middleware.new('<3', key).new(->(env) { - assert LocalCacheRegistry.cache_for(key), 'should have a cache' + middleware = Middleware.new("<3", key).new(->(env) { + assert LocalCacheRegistry.cache_for(key), "should have a cache" raise }) assert_raises(RuntimeError) { middleware.call({}) } @@ -64,79 +64,79 @@ class CacheKeyTest < ActiveSupport::TestCase end end - entry = legacy.new 'foo' - assert_equal 'foo', entry.value + entry = legacy.new "foo" + assert_equal "foo", entry.value end def test_expand_cache_key - assert_equal '1/2/true', ActiveSupport::Cache.expand_cache_key([1, '2', true]) - assert_equal 'name/1/2/true', ActiveSupport::Cache.expand_cache_key([1, '2', true], :name) + assert_equal "1/2/true", ActiveSupport::Cache.expand_cache_key([1, "2", true]) + assert_equal "name/1/2/true", ActiveSupport::Cache.expand_cache_key([1, "2", true], :name) end def test_expand_cache_key_with_rails_cache_id - with_env('RAILS_CACHE_ID' => 'c99') do - assert_equal 'c99/foo', ActiveSupport::Cache.expand_cache_key(:foo) - assert_equal 'c99/foo', ActiveSupport::Cache.expand_cache_key([:foo]) - assert_equal 'c99/foo/bar', ActiveSupport::Cache.expand_cache_key([:foo, :bar]) - assert_equal 'nm/c99/foo', ActiveSupport::Cache.expand_cache_key(:foo, :nm) - assert_equal 'nm/c99/foo', ActiveSupport::Cache.expand_cache_key([:foo], :nm) - assert_equal 'nm/c99/foo/bar', ActiveSupport::Cache.expand_cache_key([:foo, :bar], :nm) + with_env("RAILS_CACHE_ID" => "c99") do + assert_equal "c99/foo", ActiveSupport::Cache.expand_cache_key(:foo) + assert_equal "c99/foo", ActiveSupport::Cache.expand_cache_key([:foo]) + assert_equal "c99/foo/bar", ActiveSupport::Cache.expand_cache_key([:foo, :bar]) + assert_equal "nm/c99/foo", ActiveSupport::Cache.expand_cache_key(:foo, :nm) + assert_equal "nm/c99/foo", ActiveSupport::Cache.expand_cache_key([:foo], :nm) + assert_equal "nm/c99/foo/bar", ActiveSupport::Cache.expand_cache_key([:foo, :bar], :nm) end end def test_expand_cache_key_with_rails_app_version - with_env('RAILS_APP_VERSION' => 'rails3') do - assert_equal 'rails3/foo', ActiveSupport::Cache.expand_cache_key(:foo) + with_env("RAILS_APP_VERSION" => "rails3") do + assert_equal "rails3/foo", ActiveSupport::Cache.expand_cache_key(:foo) end end def test_expand_cache_key_rails_cache_id_should_win_over_rails_app_version - with_env('RAILS_CACHE_ID' => 'c99', 'RAILS_APP_VERSION' => 'rails3') do - assert_equal 'c99/foo', ActiveSupport::Cache.expand_cache_key(:foo) + with_env("RAILS_CACHE_ID" => "c99", "RAILS_APP_VERSION" => "rails3") do + assert_equal "c99/foo", ActiveSupport::Cache.expand_cache_key(:foo) end end def test_expand_cache_key_respond_to_cache_key - key = 'foo' + key = "foo" def key.cache_key :foo_key end - assert_equal 'foo_key', ActiveSupport::Cache.expand_cache_key(key) + assert_equal "foo_key", ActiveSupport::Cache.expand_cache_key(key) end def test_expand_cache_key_array_with_something_that_responds_to_cache_key - key = 'foo' + key = "foo" def key.cache_key :foo_key end - assert_equal 'foo_key', ActiveSupport::Cache.expand_cache_key([key]) + assert_equal "foo_key", ActiveSupport::Cache.expand_cache_key([key]) end def test_expand_cache_key_of_nil - assert_equal '', ActiveSupport::Cache.expand_cache_key(nil) + assert_equal "", ActiveSupport::Cache.expand_cache_key(nil) end def test_expand_cache_key_of_false - assert_equal 'false', ActiveSupport::Cache.expand_cache_key(false) + assert_equal "false", ActiveSupport::Cache.expand_cache_key(false) end def test_expand_cache_key_of_true - assert_equal 'true', ActiveSupport::Cache.expand_cache_key(true) + assert_equal "true", ActiveSupport::Cache.expand_cache_key(true) end def test_expand_cache_key_of_array_like_object - assert_equal 'foo/bar/baz', ActiveSupport::Cache.expand_cache_key(%w{foo bar baz}.to_enum) + assert_equal "foo/bar/baz", ActiveSupport::Cache.expand_cache_key(%w{foo bar baz}.to_enum) end 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 @@ -182,16 +182,16 @@ class CacheStoreSettingTest < ActiveSupport::TestCase def test_mem_cache_fragment_cache_store_with_multiple_servers assert_called_with(Dalli::Client, :new, [%w[localhost 192.168.1.1], {}]) do - store = ActiveSupport::Cache.lookup_store :mem_cache_store, "localhost", '192.168.1.1' + store = ActiveSupport::Cache.lookup_store :mem_cache_store, "localhost", "192.168.1.1" assert_kind_of(ActiveSupport::Cache::MemCacheStore, store) end end def test_mem_cache_fragment_cache_store_with_options - assert_called_with(Dalli::Client, :new, [%w[localhost 192.168.1.1], { :timeout => 10 }]) do - store = ActiveSupport::Cache.lookup_store :mem_cache_store, "localhost", '192.168.1.1', :namespace => 'foo', :timeout => 10 + assert_called_with(Dalli::Client, :new, [%w[localhost 192.168.1.1], { timeout: 10 }]) do + store = ActiveSupport::Cache.lookup_store :mem_cache_store, "localhost", "192.168.1.1", namespace: "foo", timeout: 10 assert_kind_of(ActiveSupport::Cache::MemCacheStore, store) - assert_equal 'foo', store.options[:namespace] + assert_equal "foo", store.options[:namespace] end end @@ -204,7 +204,7 @@ end class CacheStoreNamespaceTest < ActiveSupport::TestCase def test_static_namespace - cache = ActiveSupport::Cache.lookup_store(:memory_store, :namespace => "tester") + cache = ActiveSupport::Cache.lookup_store(:memory_store, namespace: "tester") cache.write("foo", "bar") assert_equal "bar", cache.read("foo") assert_equal "bar", cache.instance_variable_get(:@data)["tester:foo"].value @@ -212,15 +212,15 @@ class CacheStoreNamespaceTest < ActiveSupport::TestCase def test_proc_namespace test_val = "tester" - proc = lambda{test_val} - cache = ActiveSupport::Cache.lookup_store(:memory_store, :namespace => proc) + proc = lambda { test_val } + cache = ActiveSupport::Cache.lookup_store(:memory_store, namespace: proc) cache.write("foo", "bar") assert_equal "bar", cache.read("foo") assert_equal "bar", cache.instance_variable_get(:@data)["tester:foo"].value end def test_delete_matched_key_start - cache = ActiveSupport::Cache.lookup_store(:memory_store, :namespace => "tester") + cache = ActiveSupport::Cache.lookup_store(:memory_store, namespace: "tester") cache.write("foo", "bar") cache.write("fu", "baz") cache.delete_matched(/^fo/) @@ -229,7 +229,7 @@ class CacheStoreNamespaceTest < ActiveSupport::TestCase end def test_delete_matched_key - cache = ActiveSupport::Cache.lookup_store(:memory_store, :namespace => "foo") + cache = ActiveSupport::Cache.lookup_store(:memory_store, namespace: "foo") cache.write("foo", "bar") cache.write("fu", "baz") cache.delete_matched(/OO/i) @@ -241,141 +241,141 @@ end # Tests the base functionality that should be identical across all cache stores. module CacheStoreBehavior def test_should_read_and_write_strings - assert @cache.write('foo', 'bar') - assert_equal 'bar', @cache.read('foo') + assert @cache.write("foo", "bar") + assert_equal "bar", @cache.read("foo") end def test_should_overwrite - @cache.write('foo', 'bar') - @cache.write('foo', 'baz') - assert_equal 'baz', @cache.read('foo') + @cache.write("foo", "bar") + @cache.write("foo", "baz") + assert_equal "baz", @cache.read("foo") end def test_fetch_without_cache_miss - @cache.write('foo', 'bar') + @cache.write("foo", "bar") assert_not_called(@cache, :write) do - assert_equal 'bar', @cache.fetch('foo') { 'baz' } + assert_equal "bar", @cache.fetch("foo") { "baz" } end end def test_fetch_with_cache_miss - assert_called_with(@cache, :write, ['foo', 'baz', @cache.options]) do - assert_equal 'baz', @cache.fetch('foo') { 'baz' } + assert_called_with(@cache, :write, ["foo", "baz", @cache.options]) do + assert_equal "baz", @cache.fetch("foo") { "baz" } end end def test_fetch_with_cache_miss_passes_key_to_block cache_miss = false - assert_equal 3, @cache.fetch('foo') { |key| cache_miss = true; key.length } + assert_equal 3, @cache.fetch("foo") { |key| cache_miss = true; key.length } assert cache_miss cache_miss = false - assert_equal 3, @cache.fetch('foo') { |key| cache_miss = true; key.length } + assert_equal 3, @cache.fetch("foo") { |key| cache_miss = true; key.length } assert !cache_miss end def test_fetch_with_forced_cache_miss - @cache.write('foo', 'bar') + @cache.write("foo", "bar") assert_not_called(@cache, :read) do - assert_called_with(@cache, :write, ['foo', 'bar', @cache.options.merge(:force => true)]) do - @cache.fetch('foo', :force => true) { 'bar' } + assert_called_with(@cache, :write, ["foo", "bar", @cache.options.merge(force: true)]) do + @cache.fetch("foo", force: true) { "bar" } end end end def test_fetch_with_cached_nil - @cache.write('foo', nil) + @cache.write("foo", nil) assert_not_called(@cache, :write) do - assert_nil @cache.fetch('foo') { 'baz' } + assert_nil @cache.fetch("foo") { "baz" } end end def test_fetch_with_forced_cache_miss_with_block - @cache.write('foo', 'bar') - assert_equal 'foo_bar', @cache.fetch('foo', force: true) { 'foo_bar' } + @cache.write("foo", "bar") + assert_equal "foo_bar", @cache.fetch("foo", force: true) { "foo_bar" } end def test_fetch_with_forced_cache_miss_without_block - @cache.write('foo', 'bar') + @cache.write("foo", "bar") assert_raises(ArgumentError) do - @cache.fetch('foo', force: true) + @cache.fetch("foo", force: true) end - assert_equal 'bar', @cache.read('foo') + assert_equal "bar", @cache.read("foo") end def test_should_read_and_write_hash - assert @cache.write('foo', {:a => "b"}) - assert_equal({:a => "b"}, @cache.read('foo')) + assert @cache.write("foo", a: "b") + assert_equal({ a: "b" }, @cache.read("foo")) end def test_should_read_and_write_integer - assert @cache.write('foo', 1) - assert_equal 1, @cache.read('foo') + assert @cache.write("foo", 1) + assert_equal 1, @cache.read("foo") end def test_should_read_and_write_nil - assert @cache.write('foo', nil) - assert_equal nil, @cache.read('foo') + assert @cache.write("foo", nil) + assert_equal nil, @cache.read("foo") end def test_should_read_and_write_false - assert @cache.write('foo', false) - assert_equal false, @cache.read('foo') + assert @cache.write("foo", false) + assert_equal false, @cache.read("foo") end def test_read_multi - @cache.write('foo', 'bar') - @cache.write('fu', 'baz') - @cache.write('fud', 'biz') - assert_equal({"foo" => "bar", "fu" => "baz"}, @cache.read_multi('foo', 'fu')) + @cache.write("foo", "bar") + @cache.write("fu", "baz") + @cache.write("fud", "biz") + assert_equal({ "foo" => "bar", "fu" => "baz" }, @cache.read_multi("foo", "fu")) end def test_read_multi_with_expires time = Time.now - @cache.write('foo', 'bar', :expires_in => 10) - @cache.write('fu', 'baz') - @cache.write('fud', 'biz') + @cache.write("foo", "bar", expires_in: 10) + @cache.write("fu", "baz") + @cache.write("fud", "biz") Time.stub(:now, time + 11) do - assert_equal({"fu" => "baz"}, @cache.read_multi('foo', 'fu')) + assert_equal({ "fu" => "baz" }, @cache.read_multi("foo", "fu")) end end def test_fetch_multi - @cache.write('foo', 'bar') - @cache.write('fud', 'biz') + @cache.write("foo", "bar") + @cache.write("fud", "biz") - values = @cache.fetch_multi('foo', 'fu', 'fud') { |value| value * 2 } + values = @cache.fetch_multi("foo", "fu", "fud") { |value| value * 2 } - assert_equal({ 'foo' => 'bar', 'fu' => 'fufu', 'fud' => 'biz' }, values) - assert_equal('fufu', @cache.read('fu')) + assert_equal({ "foo" => "bar", "fu" => "fufu", "fud" => "biz" }, values) + assert_equal("fufu", @cache.read("fu")) end def test_multi_with_objects cache_struct = Struct.new(:cache_key, :title) - foo = cache_struct.new('foo', 'FOO!') - bar = cache_struct.new('bar') + foo = cache_struct.new("foo", "FOO!") + bar = cache_struct.new("bar") - @cache.write('bar', 'BAM!') + @cache.write("bar", "BAM!") values = @cache.fetch_multi(foo, bar) { |object| object.title } - assert_equal({ foo => 'FOO!', bar => 'BAM!' }, values) + assert_equal({ foo => "FOO!", bar => "BAM!" }, values) end def test_read_and_write_compressed_small_data - @cache.write('foo', 'bar', :compress => true) - assert_equal 'bar', @cache.read('foo') + @cache.write("foo", "bar", compress: true) + assert_equal "bar", @cache.read("foo") end def test_read_and_write_compressed_large_data - @cache.write('foo', 'bar', :compress => true, :compress_threshold => 2) - assert_equal 'bar', @cache.read('foo') + @cache.write("foo", "bar", compress: true, compress_threshold: 2) + assert_equal "bar", @cache.read("foo") end def test_read_and_write_compressed_nil - @cache.write('foo', nil, :compress => true) - assert_nil @cache.read('foo') + @cache.write("foo", nil, compress: true) + assert_nil @cache.read("foo") end def test_cache_key @@ -402,7 +402,7 @@ module CacheStoreBehavior end def test_hash_as_cache_key - @cache.write({:foo => 1, :fu => 2}, "bar") + @cache.write({ foo: 1, fu: 2 }, "bar") assert_equal "bar", @cache.read("foo=1/fu=2") end @@ -412,65 +412,65 @@ module CacheStoreBehavior end def test_exist - @cache.write('foo', 'bar') - assert_equal true, @cache.exist?('foo') - assert_equal false, @cache.exist?('bar') + @cache.write("foo", "bar") + assert_equal true, @cache.exist?("foo") + assert_equal false, @cache.exist?("bar") end def test_nil_exist - @cache.write('foo', nil) - assert @cache.exist?('foo') + @cache.write("foo", nil) + assert @cache.exist?("foo") end def test_delete - @cache.write('foo', 'bar') - assert @cache.exist?('foo') - assert @cache.delete('foo') - assert !@cache.exist?('foo') + @cache.write("foo", "bar") + assert @cache.exist?("foo") + assert @cache.delete("foo") + assert !@cache.exist?("foo") end def test_original_store_objects_should_not_be_immutable - bar = 'bar' - @cache.write('foo', bar) - assert_nothing_raised { bar.gsub!(/.*/, 'baz') } + bar = "bar" + @cache.write("foo", bar) + assert_nothing_raised { bar.gsub!(/.*/, "baz") } end def test_expires_in time = Time.local(2008, 4, 24) Time.stub(:now, time) do - @cache.write('foo', 'bar') - assert_equal 'bar', @cache.read('foo') + @cache.write("foo", "bar") + assert_equal "bar", @cache.read("foo") end Time.stub(:now, time + 30) do - assert_equal 'bar', @cache.read('foo') + assert_equal "bar", @cache.read("foo") end Time.stub(:now, time + 61) do - assert_nil @cache.read('foo') + assert_nil @cache.read("foo") end end def test_race_condition_protection_skipped_if_not_defined - @cache.write('foo', 'bar') - time = @cache.send(:read_entry, @cache.send(:normalize_key, 'foo', {}), {}).expires_at + @cache.write("foo", "bar") + time = @cache.send(:read_entry, @cache.send(:normalize_key, "foo", {}), {}).expires_at Time.stub(:now, Time.at(time)) do - result = @cache.fetch('foo') do - assert_equal nil, @cache.read('foo') - 'baz' + result = @cache.fetch("foo") do + assert_equal nil, @cache.read("foo") + "baz" end - assert_equal 'baz', result + assert_equal "baz", result end end def test_race_condition_protection_is_limited time = Time.now - @cache.write('foo', 'bar', :expires_in => 60) + @cache.write("foo", "bar", expires_in: 60) Time.stub(:now, time + 71) do - result = @cache.fetch('foo', :race_condition_ttl => 10) do - assert_equal nil, @cache.read('foo') + result = @cache.fetch("foo", race_condition_ttl: 10) do + assert_equal nil, @cache.read("foo") "baz" end assert_equal "baz", result @@ -479,28 +479,28 @@ module CacheStoreBehavior def test_race_condition_protection_is_safe time = Time.now - @cache.write('foo', 'bar', :expires_in => 60) + @cache.write("foo", "bar", expires_in: 60) Time.stub(:now, time + 61) do begin - @cache.fetch('foo', :race_condition_ttl => 10) do - assert_equal 'bar', @cache.read('foo') + @cache.fetch("foo", race_condition_ttl: 10) do + assert_equal "bar", @cache.read("foo") raise ArgumentError.new end rescue ArgumentError end - assert_equal "bar", @cache.read('foo') + assert_equal "bar", @cache.read("foo") end Time.stub(:now, time + 91) do - assert_nil @cache.read('foo') + assert_nil @cache.read("foo") end end def test_race_condition_protection time = Time.now - @cache.write('foo', 'bar', :expires_in => 60) + @cache.write("foo", "bar", expires_in: 60) Time.stub(:now, time + 61) do - result = @cache.fetch('foo', :race_condition_ttl => 10) do - assert_equal 'bar', @cache.read('foo') + result = @cache.fetch("foo", race_condition_ttl: 10) do + assert_equal "bar", @cache.read("foo") "baz" end assert_equal "baz", result @@ -509,23 +509,23 @@ module CacheStoreBehavior def test_crazy_key_characters crazy_key = "#/:*(<+=> )&$%@?;'\"\'`~-" - assert @cache.write(crazy_key, "1", :raw => true) + assert @cache.write(crazy_key, "1", raw: true) assert_equal "1", @cache.read(crazy_key) assert_equal "1", @cache.fetch(crazy_key) assert @cache.delete(crazy_key) - assert_equal "2", @cache.fetch(crazy_key, :raw => true) { "2" } + assert_equal "2", @cache.fetch(crazy_key, raw: true) { "2" } assert_equal 3, @cache.increment(crazy_key) assert_equal 2, @cache.decrement(crazy_key) end def test_really_long_keys key = "" - 900.times{key << "x"} + 900.times { key << "x" } assert @cache.write(key, "bar") assert_equal "bar", @cache.read(key) assert_equal "bar", @cache.fetch(key) assert_nil @cache.read("#{key}x") - assert_equal({key => "bar"}, @cache.read_multi(key)) + assert_equal({ key => "bar" }, @cache.read_multi(key)) assert @cache.delete(key) end @@ -535,10 +535,10 @@ module CacheStoreBehavior ActiveSupport::Notifications.subscribe "cache_read.active_support" do |*args| @events << ActiveSupport::Notifications::Event.new(*args) end - assert @cache.write(key, "1", :raw => true) + assert @cache.write(key, "1", raw: true) assert @cache.fetch(key) {} assert_equal 1, @events.length - assert_equal 'cache_read.active_support', @events[0].name + assert_equal "cache_read.active_support", @events[0].name assert_equal :fetch, @events[0].payload[:super_operation] assert @events[0].payload[:hit] ensure @@ -552,9 +552,9 @@ module CacheStoreBehavior end assert_not @cache.fetch("bad_key") {} assert_equal 3, @events.length - assert_equal 'cache_read.active_support', @events[0].name - assert_equal 'cache_generate.active_support', @events[1].name - assert_equal 'cache_write.active_support', @events[2].name + assert_equal "cache_read.active_support", @events[0].name + assert_equal "cache_generate.active_support", @events[1].name + assert_equal "cache_write.active_support", @events[2].name assert_equal :fetch, @events[0].payload[:super_operation] assert_not @events[0].payload[:hit] ensure @@ -575,11 +575,11 @@ module EncodedKeyCacheBehavior Encoding.list.each do |encoding| define_method "test_#{encoding.name.underscore}_encoded_values" do key = "foo".force_encoding(encoding) - assert @cache.write(key, "1", :raw => true) + assert @cache.write(key, "1", raw: true) assert_equal "1", @cache.read(key) assert_equal "1", @cache.fetch(key) assert @cache.delete(key) - assert_equal "2", @cache.fetch(key, :raw => true) { "2" } + assert_equal "2", @cache.fetch(key, raw: true) { "2" } assert_equal 3, @cache.increment(key) assert_equal 2, @cache.decrement(key) end @@ -587,18 +587,18 @@ module EncodedKeyCacheBehavior def test_common_utf8_values key = "\xC3\xBCmlaut".force_encoding(Encoding::UTF_8) - assert @cache.write(key, "1", :raw => true) + assert @cache.write(key, "1", raw: true) assert_equal "1", @cache.read(key) assert_equal "1", @cache.fetch(key) assert @cache.delete(key) - assert_equal "2", @cache.fetch(key, :raw => true) { "2" } + assert_equal "2", @cache.fetch(key, raw: true) { "2" } assert_equal 3, @cache.increment(key) assert_equal 2, @cache.decrement(key) end def test_retains_encoding key = "\xC3\xBCmlaut".force_encoding(Encoding::UTF_8) - assert @cache.write(key, "1", :raw => true) + assert @cache.write(key, "1", raw: true) assert_equal Encoding::UTF_8, key.encoding end end @@ -619,122 +619,122 @@ end module CacheIncrementDecrementBehavior def test_increment - @cache.write('foo', 1, :raw => true) - assert_equal 1, @cache.read('foo').to_i - assert_equal 2, @cache.increment('foo') - assert_equal 2, @cache.read('foo').to_i - assert_equal 3, @cache.increment('foo') - assert_equal 3, @cache.read('foo').to_i - assert_nil @cache.increment('bar') + @cache.write("foo", 1, raw: true) + assert_equal 1, @cache.read("foo").to_i + assert_equal 2, @cache.increment("foo") + assert_equal 2, @cache.read("foo").to_i + assert_equal 3, @cache.increment("foo") + assert_equal 3, @cache.read("foo").to_i + assert_nil @cache.increment("bar") end def test_decrement - @cache.write('foo', 3, :raw => true) - assert_equal 3, @cache.read('foo').to_i - assert_equal 2, @cache.decrement('foo') - assert_equal 2, @cache.read('foo').to_i - assert_equal 1, @cache.decrement('foo') - assert_equal 1, @cache.read('foo').to_i - assert_nil @cache.decrement('bar') + @cache.write("foo", 3, raw: true) + assert_equal 3, @cache.read("foo").to_i + assert_equal 2, @cache.decrement("foo") + assert_equal 2, @cache.read("foo").to_i + assert_equal 1, @cache.decrement("foo") + assert_equal 1, @cache.read("foo").to_i + assert_nil @cache.decrement("bar") end end module LocalCacheBehavior def test_local_writes_are_persistent_on_the_remote_cache retval = @cache.with_local_cache do - @cache.write('foo', 'bar') + @cache.write("foo", "bar") end assert retval - assert_equal 'bar', @cache.read('foo') + assert_equal "bar", @cache.read("foo") end def test_clear_also_clears_local_cache @cache.with_local_cache do - @cache.write('foo', 'bar') + @cache.write("foo", "bar") @cache.clear - assert_nil @cache.read('foo') + assert_nil @cache.read("foo") end - assert_nil @cache.read('foo') + assert_nil @cache.read("foo") end def test_local_cache_of_write @cache.with_local_cache do - @cache.write('foo', 'bar') - @peek.delete('foo') - assert_equal 'bar', @cache.read('foo') + @cache.write("foo", "bar") + @peek.delete("foo") + assert_equal "bar", @cache.read("foo") end end def test_local_cache_of_read - @cache.write('foo', 'bar') + @cache.write("foo", "bar") @cache.with_local_cache do - assert_equal 'bar', @cache.read('foo') + assert_equal "bar", @cache.read("foo") end end def test_local_cache_of_read_nil @cache.with_local_cache do - assert_equal nil, @cache.read('foo') - @cache.send(:bypass_local_cache) { @cache.write 'foo', 'bar' } - assert_equal nil, @cache.read('foo') + assert_equal nil, @cache.read("foo") + @cache.send(:bypass_local_cache) { @cache.write "foo", "bar" } + assert_equal nil, @cache.read("foo") end end def test_local_cache_fetch @cache.with_local_cache do - @cache.send(:local_cache).write 'foo', 'bar' - assert_equal 'bar', @cache.send(:local_cache).fetch('foo') + @cache.send(:local_cache).write "foo", "bar" + assert_equal "bar", @cache.send(:local_cache).fetch("foo") end end def test_local_cache_of_write_nil @cache.with_local_cache do - assert @cache.write('foo', nil) - assert_nil @cache.read('foo') - @peek.write('foo', 'bar') - assert_nil @cache.read('foo') + assert @cache.write("foo", nil) + assert_nil @cache.read("foo") + @peek.write("foo", "bar") + assert_nil @cache.read("foo") end end def test_local_cache_of_delete @cache.with_local_cache do - @cache.write('foo', 'bar') - @cache.delete('foo') - assert_nil @cache.read('foo') + @cache.write("foo", "bar") + @cache.delete("foo") + assert_nil @cache.read("foo") end end def test_local_cache_of_exist @cache.with_local_cache do - @cache.write('foo', 'bar') - @peek.delete('foo') - assert @cache.exist?('foo') + @cache.write("foo", "bar") + @peek.delete("foo") + assert @cache.exist?("foo") end end def test_local_cache_of_increment @cache.with_local_cache do - @cache.write('foo', 1, :raw => true) - @peek.write('foo', 2, :raw => true) - @cache.increment('foo') - assert_equal 3, @cache.read('foo') + @cache.write("foo", 1, raw: true) + @peek.write("foo", 2, raw: true) + @cache.increment("foo") + assert_equal 3, @cache.read("foo") end end def test_local_cache_of_decrement @cache.with_local_cache do - @cache.write('foo', 1, :raw => true) - @peek.write('foo', 3, :raw => true) - @cache.decrement('foo') - assert_equal 2, @cache.read('foo') + @cache.write("foo", 1, raw: true) + @peek.write("foo", 3, raw: true) + @cache.decrement("foo") + assert_equal 2, @cache.read("foo") end end def test_middleware app = lambda { |env| - result = @cache.write('foo', 'bar') - assert_equal 'bar', @cache.read('foo') # make sure 'foo' was written + result = @cache.write("foo", "bar") + assert_equal "bar", @cache.read("foo") # make sure 'foo' was written assert result [200, {}, []] } @@ -745,9 +745,9 @@ module LocalCacheBehavior def test_can_call_deprecated_set_cache_value @cache.with_local_cache do assert_deprecated "`set_cache_value` is deprecated" do - @cache.send(:set_cache_value, 1, 'foo', :ignored, {}) + @cache.send(:set_cache_value, 1, "foo", :ignored, {}) end - assert_equal 1, @cache.read('foo') + assert_equal 1, @cache.read("foo") end end end @@ -756,14 +756,14 @@ module AutoloadingCacheBehavior include DependenciesTestHelpers def test_simple_autoloading with_autoloading_fixtures do - @cache.write('foo', EM.new) + @cache.write("foo", EM.new) end remove_constants(:EM) ActiveSupport::Dependencies.clear with_autoloading_fixtures do - assert_kind_of EM, @cache.read('foo') + assert_kind_of EM, @cache.read("foo") end remove_constants(:EM) @@ -772,14 +772,14 @@ module AutoloadingCacheBehavior def test_two_classes_autoloading with_autoloading_fixtures do - @cache.write('foo', [EM.new, ClassFolder.new]) + @cache.write("foo", [EM.new, ClassFolder.new]) end remove_constants(:EM, :ClassFolder) ActiveSupport::Dependencies.clear with_autoloading_fixtures do - loaded = @cache.read('foo') + loaded = @cache.read("foo") assert_kind_of Array, loaded assert_equal 2, loaded.size assert_kind_of EM, loaded[0] @@ -794,9 +794,9 @@ end class FileStoreTest < ActiveSupport::TestCase def setup Dir.mkdir(cache_dir) unless File.exist?(cache_dir) - @cache = ActiveSupport::Cache.lookup_store(:file_store, cache_dir, :expires_in => 60) - @peek = ActiveSupport::Cache.lookup_store(:file_store, cache_dir, :expires_in => 60) - @cache_with_pathname = ActiveSupport::Cache.lookup_store(:file_store, Pathname.new(cache_dir), :expires_in => 60) + @cache = ActiveSupport::Cache.lookup_store(:file_store, cache_dir, expires_in: 60) + @peek = ActiveSupport::Cache.lookup_store(:file_store, cache_dir, expires_in: 60) + @cache_with_pathname = ActiveSupport::Cache.lookup_store(:file_store, Pathname.new(cache_dir), expires_in: 60) @buffer = StringIO.new @cache.logger = ActiveSupport::Logger.new(@buffer) @@ -808,7 +808,7 @@ class FileStoreTest < ActiveSupport::TestCase end def cache_dir - File.join(Dir.pwd, 'tmp_cache') + File.join(Dir.pwd, "tmp_cache") end include CacheStoreBehavior @@ -858,7 +858,7 @@ class FileStoreTest < ActiveSupport::TestCase key = "#{'A' * ActiveSupport::Cache::FileStore::FILENAME_MAX_SIZE}" path = @cache.send(:normalize_key, key, {}) Dir::Tmpname.create(path) do |tmpname, n, opts| - assert File.basename(tmpname+'.lock').length <= 255, "Temp filename too long: #{File.basename(tmpname+'.lock').length}" + assert File.basename(tmpname+".lock").length <= 255, "Temp filename too long: #{File.basename(tmpname+'.lock').length}" end end @@ -867,28 +867,28 @@ class FileStoreTest < ActiveSupport::TestCase def test_key_transformation_max_filename_size key = "#{'A' * ActiveSupport::Cache::FileStore::FILENAME_MAX_SIZE}B" path = @cache.send(:normalize_key, key, {}) - assert path.split('/').all? { |dir_name| dir_name.size <= ActiveSupport::Cache::FileStore::FILENAME_MAX_SIZE} - assert_equal 'B', File.basename(path) + assert path.split("/").all? { |dir_name| dir_name.size <= ActiveSupport::Cache::FileStore::FILENAME_MAX_SIZE } + assert_equal "B", File.basename(path) end # If nothing has been stored in the cache, there is a chance the cache directory does not yet exist # Ensure delete_matched gracefully handles this case def test_delete_matched_when_cache_directory_does_not_exist assert_nothing_raised do - ActiveSupport::Cache::FileStore.new('/test/cache/directory').delete_matched(/does_not_exist/) + ActiveSupport::Cache::FileStore.new("/test/cache/directory").delete_matched(/does_not_exist/) end end def test_delete_does_not_delete_empty_parent_dir - sub_cache_dir = File.join(cache_dir, 'subdir/') + sub_cache_dir = File.join(cache_dir, "subdir/") sub_cache_store = ActiveSupport::Cache::FileStore.new(sub_cache_dir) assert_nothing_raised do - assert sub_cache_store.write('foo', 'bar') - assert sub_cache_store.delete('foo') + assert sub_cache_store.write("foo", "bar") + assert sub_cache_store.delete("foo") end assert File.exist?(cache_dir), "Parent of top level cache dir was deleted!" assert File.exist?(sub_cache_dir), "Top level cache dir was deleted!" - assert Dir.entries(sub_cache_dir).reject {|f| ActiveSupport::Cache::FileStore::EXCLUDED_DIRS.include?(f)}.empty? + assert Dir.entries(sub_cache_dir).reject { |f| ActiveSupport::Cache::FileStore::EXCLUDED_DIRS.include?(f) }.empty? end def test_log_exception_when_cache_read_fails @@ -900,14 +900,14 @@ class FileStoreTest < ActiveSupport::TestCase def test_cleanup_removes_all_expired_entries time = Time.now - @cache.write('foo', 'bar', expires_in: 10) - @cache.write('baz', 'qux') - @cache.write('quux', 'corge', expires_in: 20) + @cache.write("foo", "bar", expires_in: 10) + @cache.write("baz", "qux") + @cache.write("quux", "corge", expires_in: 20) Time.stub(:now, time + 15) do @cache.cleanup - assert_not @cache.exist?('foo') - assert @cache.exist?('baz') - assert @cache.exist?('quux') + assert_not @cache.exist?("foo") + assert @cache.exist?("baz") + assert @cache.exist?("quux") end end @@ -928,7 +928,7 @@ end class MemoryStoreTest < ActiveSupport::TestCase def setup @record_size = ActiveSupport::Cache.lookup_store(:memory_store).send(:cached_size, 1, ActiveSupport::Cache::Entry.new("aaaaaaaaaa")) - @cache = ActiveSupport::Cache.lookup_store(:memory_store, :expires_in => 60, :size => @record_size * 10 + 1) + @cache = ActiveSupport::Cache.lookup_store(:memory_store, expires_in: 60, size: @record_size * 10 + 1) end include CacheStoreBehavior @@ -988,7 +988,7 @@ class MemoryStoreTest < ActiveSupport::TestCase @cache.write(7, "gggggggggg") && sleep(0.001) @cache.write(8, "hhhhhhhhhh") && sleep(0.001) @cache.write(9, "iiiiiiiiii") && sleep(0.001) - long_key = '*' * 2 * @record_size + long_key = "*" * 2 * @record_size @cache.write(long_key, "llllllllll") assert @cache.exist?(long_key) assert @cache.exist?(9) @@ -1022,18 +1022,18 @@ class MemoryStoreTest < ActiveSupport::TestCase def test_write_with_unless_exist assert_equal true, @cache.write(1, "aaaaaaaaaa") - assert_equal false, @cache.write(1, "aaaaaaaaaa", :unless_exist => true) + assert_equal false, @cache.write(1, "aaaaaaaaaa", unless_exist: true) @cache.write(1, nil) - assert_equal false, @cache.write(1, "aaaaaaaaaa", :unless_exist => true) + assert_equal false, @cache.write(1, "aaaaaaaaaa", unless_exist: true) end end class MemCacheStoreTest < ActiveSupport::TestCase - require 'dalli' + require "dalli" begin - ss = Dalli::Client.new('localhost:11211').stats - raise Dalli::DalliError unless ss['localhost:11211'] + ss = Dalli::Client.new("localhost:11211").stats + raise Dalli::DalliError unless ss["localhost:11211"] MEMCACHE_UP = true rescue Dalli::DalliError @@ -1044,7 +1044,7 @@ class MemCacheStoreTest < ActiveSupport::TestCase def setup skip "memcache server is not up" unless MEMCACHE_UP - @cache = ActiveSupport::Cache.lookup_store(:mem_cache_store, :expires_in => 60) + @cache = ActiveSupport::Cache.lookup_store(:mem_cache_store, expires_in: 60) @peek = ActiveSupport::Cache.lookup_store(:mem_cache_store) @data = @cache.instance_variable_get(:@data) @cache.clear @@ -1059,21 +1059,21 @@ class MemCacheStoreTest < ActiveSupport::TestCase include AutoloadingCacheBehavior def test_raw_values - cache = ActiveSupport::Cache.lookup_store(:mem_cache_store, :raw => true) + cache = ActiveSupport::Cache.lookup_store(:mem_cache_store, raw: true) cache.clear cache.write("foo", 2) assert_equal "2", cache.read("foo") end def test_raw_values_with_marshal - cache = ActiveSupport::Cache.lookup_store(:mem_cache_store, :raw => true) + cache = ActiveSupport::Cache.lookup_store(:mem_cache_store, raw: true) cache.clear cache.write("foo", Marshal.dump([])) assert_equal [], cache.read("foo") end def test_local_cache_raw_values - cache = ActiveSupport::Cache.lookup_store(:mem_cache_store, :raw => true) + cache = ActiveSupport::Cache.lookup_store(:mem_cache_store, raw: true) cache.clear cache.with_local_cache do cache.write("foo", 2) @@ -1082,7 +1082,7 @@ class MemCacheStoreTest < ActiveSupport::TestCase end def test_local_cache_raw_values_with_marshal - cache = ActiveSupport::Cache.lookup_store(:mem_cache_store, :raw => true) + cache = ActiveSupport::Cache.lookup_store(:mem_cache_store, raw: true) cache.clear cache.with_local_cache do cache.write("foo", Marshal.dump([])) @@ -1091,11 +1091,11 @@ class MemCacheStoreTest < ActiveSupport::TestCase end def test_read_should_return_a_different_object_id_each_time_it_is_called - @cache.write('foo', 'bar') - value = @cache.read('foo') - assert_not_equal value.object_id, @cache.read('foo').object_id - value << 'bingo' - assert_not_equal value, @cache.read('foo') + @cache.write("foo", "bar") + value = @cache.read("foo") + assert_not_equal value.object_id, @cache.read("foo").object_id + value << "bingo" + assert_not_equal value, @cache.read("foo") end def test_can_call_deprecated_escape_key @@ -1133,12 +1133,12 @@ class NullStoreTest < ActiveSupport::TestCase end def test_increment - @cache.write("name", 1, :raw => true) + @cache.write("name", 1, raw: true) assert_nil @cache.increment("name") end def test_decrement - @cache.write("name", 1, :raw => true) + @cache.write("name", 1, raw: true) assert_nil @cache.increment("name") end @@ -1168,12 +1168,12 @@ class CacheStoreLoggerTest < ActiveSupport::TestCase end def test_logging - @cache.fetch('foo') { 'bar' } + @cache.fetch("foo") { "bar" } assert @buffer.string.present? end def test_log_with_string_namespace - @cache.fetch('foo', {namespace: 'string_namespace'}) { 'bar' } + @cache.fetch("foo", namespace: "string_namespace") { "bar" } assert_match %r{string_namespace:foo}, @buffer.string end @@ -1181,12 +1181,12 @@ class CacheStoreLoggerTest < ActiveSupport::TestCase proc = Proc.new do "proc_namespace" end - @cache.fetch('foo', {:namespace => proc}) { 'bar' } + @cache.fetch("foo", namespace: proc) { "bar" } assert_match %r{proc_namespace:foo}, @buffer.string end def test_mute_logging - @cache.mute { @cache.fetch('foo') { 'bar' } } + @cache.mute { @cache.fetch("foo") { "bar" } } assert @buffer.string.blank? end end @@ -1194,17 +1194,17 @@ end class CacheEntryTest < ActiveSupport::TestCase def test_expired entry = ActiveSupport::Cache::Entry.new("value") - assert !entry.expired?, 'entry not expired' - entry = ActiveSupport::Cache::Entry.new("value", :expires_in => 60) - assert !entry.expired?, 'entry not expired' + assert !entry.expired?, "entry not expired" + entry = ActiveSupport::Cache::Entry.new("value", expires_in: 60) + assert !entry.expired?, "entry not expired" Time.stub(:now, Time.now + 61) do - assert entry.expired?, 'entry is expired' + assert entry.expired?, "entry is expired" end end def test_compress_values value = "value" * 100 - entry = ActiveSupport::Cache::Entry.new(value, :compress => true, :compress_threshold => 1) + entry = ActiveSupport::Cache::Entry.new(value, compress: true, compress_threshold: 1) assert_equal value, entry.value assert(value.bytesize > entry.size, "value is compressed") end diff --git a/activesupport/test/callback_inheritance_test.rb b/activesupport/test/callback_inheritance_test.rb index 1adfe4edf4..9e2f7527e0 100644 --- a/activesupport/test/callback_inheritance_test.rb +++ b/activesupport/test/callback_inheritance_test.rb @@ -1,4 +1,4 @@ -require 'abstract_unit' +require "abstract_unit" class GrandParent include ActiveSupport::Callbacks @@ -9,8 +9,8 @@ class GrandParent end define_callbacks :dispatch - set_callback :dispatch, :before, :before1, :before2, :if => proc {|c| c.action_name == "index" || c.action_name == "update" } - set_callback :dispatch, :after, :after1, :after2, :if => proc {|c| c.action_name == "update" || c.action_name == "delete" } + set_callback :dispatch, :before, :before1, :before2, if: proc { |c| c.action_name == "index" || c.action_name == "update" } + set_callback :dispatch, :after, :after1, :after2, if: proc { |c| c.action_name == "update" || c.action_name == "delete" } def before1 @log << "before1" @@ -37,12 +37,12 @@ class GrandParent end class Parent < GrandParent - skip_callback :dispatch, :before, :before2, :unless => proc {|c| c.action_name == "update" } - skip_callback :dispatch, :after, :after2, :unless => proc {|c| c.action_name == "delete" } + skip_callback :dispatch, :before, :before2, unless: proc { |c| c.action_name == "update" } + skip_callback :dispatch, :after, :after2, unless: proc { |c| c.action_name == "delete" } end class Child < GrandParent - skip_callback :dispatch, :before, :before2, :unless => proc {|c| c.action_name == "update" }, :if => :state_open? + skip_callback :dispatch, :before, :before2, unless: proc { |c| c.action_name == "update" }, if: :state_open? def state_open? @state == :open diff --git a/activesupport/test/callbacks_test.rb b/activesupport/test/callbacks_test.rb index a624473f46..b4e98edd84 100644 --- a/activesupport/test/callbacks_test.rb +++ b/activesupport/test/callbacks_test.rb @@ -1,4 +1,4 @@ -require 'abstract_unit' +require "abstract_unit" module CallbacksTest class Record @@ -61,7 +61,7 @@ module CallbacksTest send(callback_method, callback_symbol(callback_method_sym)) ActiveSupport::Deprecation.silence { send(callback_method, callback_string(callback_method_sym)) } send(callback_method, callback_proc(callback_method_sym)) - send(callback_method, callback_object(callback_method_sym.to_s.gsub(/_save/, ''))) + send(callback_method, callback_object(callback_method_sym.to_s.gsub(/_save/, ""))) send(callback_method, CallbackClass) send(callback_method) { |model| model.history << [callback_method_sym, :block] } end @@ -72,11 +72,11 @@ module CallbacksTest end class PersonSkipper < Person - skip_callback :save, :before, :before_save_method, :if => :yes - skip_callback :save, :after, :after_save_method, :unless => :yes - skip_callback :save, :after, :after_save_method, :if => :no - skip_callback :save, :before, :before_save_method, :unless => :no - skip_callback :save, :before, CallbackClass , :if => :yes + skip_callback :save, :before, :before_save_method, if: :yes + skip_callback :save, :after, :after_save_method, unless: :yes + skip_callback :save, :after, :after_save_method, if: :no + skip_callback :save, :before, :before_save_method, unless: :no + skip_callback :save, :before, CallbackClass , if: :yes def yes; true; end def no; false; end end @@ -89,7 +89,7 @@ module CallbacksTest define_callbacks :dispatch - set_callback :dispatch, :before, :log, :unless => proc {|c| c.action_name == :index || c.action_name == :show } + set_callback :dispatch, :before, :log, unless: proc { |c| c.action_name == :index || c.action_name == :show } set_callback :dispatch, :after, :log2 attr_reader :action_name, :logger @@ -114,7 +114,7 @@ module CallbacksTest end class Child < ParentController - skip_callback :dispatch, :before, :log, :if => proc {|c| c.action_name == :update} + skip_callback :dispatch, :before, :log, if: proc { |c| c.action_name == :update } skip_callback :dispatch, :after, :log2 end @@ -125,10 +125,10 @@ module CallbacksTest super end - before_save Proc.new {|r| r.history << [:before_save, :starts_true, :if] }, :if => :starts_true - before_save Proc.new {|r| r.history << [:before_save, :starts_false, :if] }, :if => :starts_false - before_save Proc.new {|r| r.history << [:before_save, :starts_true, :unless] }, :unless => :starts_true - before_save Proc.new {|r| r.history << [:before_save, :starts_false, :unless] }, :unless => :starts_false + before_save Proc.new { |r| r.history << [:before_save, :starts_true, :if] }, if: :starts_true + before_save Proc.new { |r| r.history << [:before_save, :starts_false, :if] }, if: :starts_false + before_save Proc.new { |r| r.history << [:before_save, :starts_true, :unless] }, unless: :starts_true + before_save Proc.new { |r| r.history << [:before_save, :starts_false, :unless] }, unless: :starts_false def starts_true if @@starts_true @@ -181,27 +181,25 @@ module CallbacksTest end end - - class ConditionalPerson < Record # proc - before_save Proc.new { |r| r.history << [:before_save, :proc] }, :if => Proc.new { |r| true } - before_save Proc.new { |r| r.history << "b00m" }, :if => Proc.new { |r| false } - before_save Proc.new { |r| r.history << [:before_save, :proc] }, :unless => Proc.new { |r| false } - before_save Proc.new { |r| r.history << "b00m" }, :unless => Proc.new { |r| true } + before_save Proc.new { |r| r.history << [:before_save, :proc] }, if: Proc.new { |r| true } + before_save Proc.new { |r| r.history << "b00m" }, if: Proc.new { |r| false } + before_save Proc.new { |r| r.history << [:before_save, :proc] }, unless: Proc.new { |r| false } + before_save Proc.new { |r| r.history << "b00m" }, unless: Proc.new { |r| true } # symbol - before_save Proc.new { |r| r.history << [:before_save, :symbol] }, :if => :yes - before_save Proc.new { |r| r.history << "b00m" }, :if => :no - before_save Proc.new { |r| r.history << [:before_save, :symbol] }, :unless => :no - before_save Proc.new { |r| r.history << "b00m" }, :unless => :yes + before_save Proc.new { |r| r.history << [:before_save, :symbol] }, if: :yes + before_save Proc.new { |r| r.history << "b00m" }, if: :no + before_save Proc.new { |r| r.history << [:before_save, :symbol] }, unless: :no + before_save Proc.new { |r| r.history << "b00m" }, unless: :yes # string - before_save Proc.new { |r| r.history << [:before_save, :string] }, :if => 'yes' - before_save Proc.new { |r| r.history << "b00m" }, :if => 'no' - before_save Proc.new { |r| r.history << [:before_save, :string] }, :unless => 'no' - before_save Proc.new { |r| r.history << "b00m" }, :unless => 'yes' + before_save Proc.new { |r| r.history << [:before_save, :string] }, if: "yes" + before_save Proc.new { |r| r.history << "b00m" }, if: "no" + before_save Proc.new { |r| r.history << [:before_save, :string] }, unless: "no" + before_save Proc.new { |r| r.history << "b00m" }, unless: "yes" # Combined if and unless - before_save Proc.new { |r| r.history << [:before_save, :combined_symbol] }, :if => :yes, :unless => :no - before_save Proc.new { |r| r.history << "b00m" }, :if => :yes, :unless => :yes + before_save Proc.new { |r| r.history << [:before_save, :combined_symbol] }, if: :yes, unless: :no + before_save Proc.new { |r| r.history << "b00m" }, if: :yes, unless: :yes def yes; true; end def other_yes; true; end @@ -225,18 +223,18 @@ module CallbacksTest class AroundPerson < MySuper attr_reader :history - set_callback :save, :before, :nope, :if => :no - set_callback :save, :before, :nope, :unless => :yes + set_callback :save, :before, :nope, if: :no + set_callback :save, :before, :nope, unless: :yes set_callback :save, :after, :tweedle ActiveSupport::Deprecation.silence { set_callback :save, :before, "tweedle_dee" } - set_callback :save, :before, proc {|m| m.history << "yup" } - set_callback :save, :before, :nope, :if => proc { false } - set_callback :save, :before, :nope, :unless => proc { true } - set_callback :save, :before, :yup, :if => proc { true } - set_callback :save, :before, :yup, :unless => proc { false } + set_callback :save, :before, proc { |m| m.history << "yup" } + set_callback :save, :before, :nope, if: proc { false } + set_callback :save, :before, :nope, unless: proc { true } + set_callback :save, :before, :yup, if: proc { true } + set_callback :save, :before, :yup, unless: proc { false } set_callback :save, :around, :tweedle_dum - set_callback :save, :around, :w0tyes, :if => :yes - set_callback :save, :around, :w0tno, :if => :no + set_callback :save, :around, :w0tyes, if: :yes + set_callback :save, :around, :w0tno, if: :no set_callback :save, :around, :tweedle_deedle def no; false; end @@ -323,7 +321,7 @@ module CallbacksTest define_callbacks :save attr_reader :stuff - set_callback :save, :before, :action, :if => :yes + set_callback :save, :before, :action, if: :yes def yes() true end @@ -361,7 +359,6 @@ module CallbacksTest end class ExtendCallbacks - include ActiveSupport::Callbacks define_callbacks :save @@ -453,7 +450,6 @@ module CallbacksTest end class CallbacksTest < ActiveSupport::TestCase - def test_save_person person = Person.new assert_equal [], person.history @@ -491,8 +487,6 @@ module CallbacksTest end end - - class ResetCallbackTest < ActiveSupport::TestCase def test_save_conditional_person person = CleanPerson.new @@ -637,7 +631,7 @@ module CallbacksTest class CustomScopeObject include ActiveSupport::Callbacks - define_callbacks :save, :scope => [:kind, :name] + define_callbacks :save, scope: [:kind, :name] set_callback :save, :before, CallbackObject.new attr_accessor :record @@ -810,7 +804,7 @@ module CallbacksTest class WriterSkipper < Person attr_accessor :age - skip_callback :save, :before, :before_save_method, :if => lambda {self.age > 21} + skip_callback :save, :before, :before_save_method, if: -> { age > 21 } end class WriterCallbacksTest < ActiveSupport::TestCase @@ -885,7 +879,7 @@ module CallbacksTest def test_proc_arity_2 assert_raises(ArgumentError) do - klass = build_class(->(x,y) { }) + klass = build_class(->(x,y) {}) klass.new.run end end @@ -903,7 +897,7 @@ module CallbacksTest Class.new { include ActiveSupport::Callbacks define_callbacks :foo - set_callback :foo, :before, :foo, :if => callback + set_callback :foo, :before, :foo, if: callback def foo; end def run; run_callbacks :foo; end } @@ -918,8 +912,8 @@ module CallbacksTest } klass = Class.new { include ActiveSupport::Callbacks - define_callbacks :foo, :scope => [:name] - set_callback :foo, :before, :foo, :if => callback + define_callbacks :foo, scope: [:name] + set_callback :foo, :before, :foo, if: callback def run; run_callbacks :foo; end private def foo; end @@ -964,7 +958,7 @@ module CallbacksTest def test_proc_arity2 assert_raises(ArgumentError) do - object = build_class(->(a,b) { }).new + object = build_class(->(a,b) {}).new object.run end end diff --git a/activesupport/test/class_cache_test.rb b/activesupport/test/class_cache_test.rb index b96f476ce6..c618fea81a 100644 --- a/activesupport/test/class_cache_test.rb +++ b/activesupport/test/class_cache_test.rb @@ -1,5 +1,5 @@ -require 'abstract_unit' -require 'active_support/dependencies' +require "abstract_unit" +require "active_support/dependencies" module ActiveSupport module Dependencies diff --git a/activesupport/test/clean_backtrace_test.rb b/activesupport/test/clean_backtrace_test.rb index 14cf65ef2d..5ed518cdb0 100644 --- a/activesupport/test/clean_backtrace_test.rb +++ b/activesupport/test/clean_backtrace_test.rb @@ -1,9 +1,9 @@ -require 'abstract_unit' +require "abstract_unit" class BacktraceCleanerFilterTest < ActiveSupport::TestCase def setup @bc = ActiveSupport::BacktraceCleaner.new - @bc.add_filter { |line| line.gsub("/my/prefix", '') } + @bc.add_filter { |line| line.gsub("/my/prefix", "") } end test "backtrace should filter all lines in a backtrace, removing prefixes" do @@ -20,13 +20,12 @@ class BacktraceCleanerFilterTest < ActiveSupport::TestCase test "backtrace should contain unaltered lines if they dont match a filter" do assert_equal "/my/other_prefix/my/class.rb", @bc.clean([ "/my/other_prefix/my/class.rb" ]).first end - end class BacktraceCleanerSilencerTest < ActiveSupport::TestCase def setup @bc = ActiveSupport::BacktraceCleaner.new - @bc.add_silencer { |line| line.include?('mongrel') } + @bc.add_silencer { |line| line.include?("mongrel") } end test "backtrace should not contain lines that match the silencer" do @@ -44,8 +43,8 @@ end class BacktraceCleanerMultipleSilencersTest < ActiveSupport::TestCase def setup @bc = ActiveSupport::BacktraceCleaner.new - @bc.add_silencer { |line| line.include?('mongrel') } - @bc.add_silencer { |line| line.include?('yolo') } + @bc.add_silencer { |line| line.include?("mongrel") } + @bc.add_silencer { |line| line.include?("yolo") } end test "backtrace should not contain lines that match the silencers" do @@ -66,7 +65,7 @@ class BacktraceCleanerFilterAndSilencerTest < ActiveSupport::TestCase def setup @bc = ActiveSupport::BacktraceCleaner.new @bc.add_filter { |line| line.gsub("/mongrel", "") } - @bc.add_silencer { |line| line.include?('mongrel') } + @bc.add_silencer { |line| line.include?("mongrel") } end test "backtrace should not silence lines that has first had their silence hook filtered out" do diff --git a/activesupport/test/clean_logger_test.rb b/activesupport/test/clean_logger_test.rb index 02693a97dc..cf37fc5639 100644 --- a/activesupport/test/clean_logger_test.rb +++ b/activesupport/test/clean_logger_test.rb @@ -1,6 +1,6 @@ -require 'abstract_unit' -require 'stringio' -require 'active_support/logger' +require "abstract_unit" +require "stringio" +require "active_support/logger" class CleanLoggerTest < ActiveSupport::TestCase def setup @@ -9,14 +9,14 @@ class CleanLoggerTest < ActiveSupport::TestCase end def test_format_message - @logger.error 'error' + @logger.error "error" assert_equal "error\n", @out.string end def test_datetime_format @logger.formatter = Logger::Formatter.new @logger.formatter.datetime_format = "%Y-%m-%d" - @logger.debug 'debug' + @logger.debug "debug" assert_equal "%Y-%m-%d", @logger.formatter.datetime_format assert_match(/D, \[\d\d\d\d-\d\d-\d\d#\d+\] DEBUG -- : debug/, @out.string) end diff --git a/activesupport/test/concern_test.rb b/activesupport/test/concern_test.rb index 8ea701cfb7..4af9ce8163 100644 --- a/activesupport/test/concern_test.rb +++ b/activesupport/test/concern_test.rb @@ -1,5 +1,5 @@ -require 'abstract_unit' -require 'active_support/concern' +require "abstract_unit" +require "active_support/concern" class ConcernTest < ActiveSupport::TestCase module Baz @@ -72,7 +72,7 @@ class ConcernTest < ActiveSupport::TestCase def test_class_methods_are_extended @klass.include(Baz) assert_equal "baz", @klass.baz - assert_equal ConcernTest::Baz::ClassMethods, (class << @klass; self.included_modules; end)[0] + assert_equal ConcernTest::Baz::ClassMethods, (class << @klass; included_modules; end)[0] end def test_class_methods_are_extended_only_on_expected_objects diff --git a/activesupport/test/configurable_test.rb b/activesupport/test/configurable_test.rb index 5d22ded2de..c67ea8b222 100644 --- a/activesupport/test/configurable_test.rb +++ b/activesupport/test/configurable_test.rb @@ -1,5 +1,5 @@ -require 'abstract_unit' -require 'active_support/configurable' +require "abstract_unit" +require "active_support/configurable" class ConfigurableActiveSupport < ActiveSupport::TestCase class Parent @@ -111,7 +111,7 @@ class ConfigurableActiveSupport < ActiveSupport::TestCase end end - test 'the config_accessor method should not be publicly callable' do + test "the config_accessor method should not be publicly callable" do assert_raises NoMethodError do Class.new { include ActiveSupport::Configurable diff --git a/activesupport/test/constantize_test_cases.rb b/activesupport/test/constantize_test_cases.rb index 1115bc0fd8..af2db8c991 100644 --- a/activesupport/test/constantize_test_cases.rb +++ b/activesupport/test/constantize_test_cases.rb @@ -1,4 +1,4 @@ -require 'dependencies_test_helpers' +require "dependencies_test_helpers" module Ace module Base @@ -100,10 +100,10 @@ module ConstantizeTestCases assert_nil yield("Ace::Gas::ConstantizeTestCases") assert_nil yield("#<Class:0x7b8b718b>::Nested_1") assert_nil yield("Ace::gas") - assert_nil yield('Object::ABC') - assert_nil yield('Object::Object::Object::ABC') - assert_nil yield('A::Object::B') - assert_nil yield('A::Object::Object::Object::B') + assert_nil yield("Object::ABC") + assert_nil yield("Object::Object::Object::ABC") + assert_nil yield("A::Object::B") + assert_nil yield("A::Object::Object::Object::B") assert_raises(NameError) do with_autoloading_fixtures do diff --git a/activesupport/test/core_ext/array/access_test.rb b/activesupport/test/core_ext/array/access_test.rb index 1d834667f0..a38ea36d00 100644 --- a/activesupport/test/core_ext/array/access_test.rb +++ b/activesupport/test/core_ext/array/access_test.rb @@ -1,5 +1,5 @@ -require 'abstract_unit' -require 'active_support/core_ext/array' +require "abstract_unit" +require "active_support/core_ext/array" class AccessTest < ActiveSupport::TestCase def test_from diff --git a/activesupport/test/core_ext/array/conversions_test.rb b/activesupport/test/core_ext/array/conversions_test.rb index 323b451e02..ccbdab19f0 100644 --- a/activesupport/test/core_ext/array/conversions_test.rb +++ b/activesupport/test/core_ext/array/conversions_test.rb @@ -1,42 +1,42 @@ -require 'abstract_unit' -require 'active_support/core_ext/array' -require 'active_support/core_ext/big_decimal' -require 'active_support/core_ext/hash' -require 'active_support/core_ext/string' +require "abstract_unit" +require "active_support/core_ext/array" +require "active_support/core_ext/big_decimal" +require "active_support/core_ext/hash" +require "active_support/core_ext/string" class ToSentenceTest < ActiveSupport::TestCase def test_plain_array_to_sentence assert_equal "", [].to_sentence - assert_equal "one", ['one'].to_sentence - assert_equal "one and two", ['one', 'two'].to_sentence - assert_equal "one, two, and three", ['one', 'two', 'three'].to_sentence + assert_equal "one", ["one"].to_sentence + assert_equal "one and two", ["one", "two"].to_sentence + assert_equal "one, two, and three", ["one", "two", "three"].to_sentence end def test_to_sentence_with_words_connector - assert_equal "one two, and three", ['one', 'two', 'three'].to_sentence(words_connector: ' ') - assert_equal "one & two, and three", ['one', 'two', 'three'].to_sentence(words_connector: ' & ') - assert_equal "onetwo, and three", ['one', 'two', 'three'].to_sentence(words_connector: nil) + assert_equal "one two, and three", ["one", "two", "three"].to_sentence(words_connector: " ") + assert_equal "one & two, and three", ["one", "two", "three"].to_sentence(words_connector: " & ") + assert_equal "onetwo, and three", ["one", "two", "three"].to_sentence(words_connector: nil) end def test_to_sentence_with_last_word_connector - assert_equal "one, two, and also three", ['one', 'two', 'three'].to_sentence(last_word_connector: ', and also ') - assert_equal "one, twothree", ['one', 'two', 'three'].to_sentence(last_word_connector: nil) - assert_equal "one, two three", ['one', 'two', 'three'].to_sentence(last_word_connector: ' ') - assert_equal "one, two and three", ['one', 'two', 'three'].to_sentence(last_word_connector: ' and ') + assert_equal "one, two, and also three", ["one", "two", "three"].to_sentence(last_word_connector: ", and also ") + assert_equal "one, twothree", ["one", "two", "three"].to_sentence(last_word_connector: nil) + assert_equal "one, two three", ["one", "two", "three"].to_sentence(last_word_connector: " ") + assert_equal "one, two and three", ["one", "two", "three"].to_sentence(last_word_connector: " and ") end def test_to_sentence_with_fallback_string - assert_equal "none", [].to_sentence(fallback_string: 'none') - assert_equal "one, two, and three", ['one', 'two', 'three'].to_sentence(fallback_string: 'none') + assert_equal "none", [].to_sentence(fallback_string: "none") + assert_equal "one, two, and three", ["one", "two", "three"].to_sentence(fallback_string: "none") end def test_two_elements - assert_equal "one and two", ['one', 'two'].to_sentence - assert_equal "one two", ['one', 'two'].to_sentence(two_words_connector: ' ') + assert_equal "one and two", ["one", "two"].to_sentence + assert_equal "one two", ["one", "two"].to_sentence(two_words_connector: " ") end def test_one_element - assert_equal "one", ['one'].to_sentence + assert_equal "one", ["one"].to_sentence end def test_one_element_not_same_object @@ -45,31 +45,31 @@ class ToSentenceTest < ActiveSupport::TestCase end def test_one_non_string_element - assert_equal '1', [1].to_sentence + assert_equal "1", [1].to_sentence end def test_does_not_modify_given_hash - options = { words_connector: ' ' } - assert_equal "one two, and three", ['one', 'two', 'three'].to_sentence(options) - assert_equal({ words_connector: ' ' }, options) + options = { words_connector: " " } + assert_equal "one two, and three", ["one", "two", "three"].to_sentence(options) + assert_equal({ words_connector: " " }, options) end def test_with_blank_elements - assert_equal ", one, , two, and three", [nil, 'one', '', 'two', 'three'].to_sentence + assert_equal ", one, , two, and three", [nil, "one", "", "two", "three"].to_sentence end def test_with_invalid_options exception = assert_raise ArgumentError do - ['one', 'two'].to_sentence(passing: 'invalid option') + ["one", "two"].to_sentence(passing: "invalid option") end assert_equal exception.message, "Unknown key: :passing. Valid keys are: :words_connector, :two_words_connector, :last_word_connector, :locale, :fallback_string" end def test_always_returns_string - assert_instance_of String, [ActiveSupport::SafeBuffer.new('one')].to_sentence - assert_instance_of String, [ActiveSupport::SafeBuffer.new('one'), 'two'].to_sentence - assert_instance_of String, [ActiveSupport::SafeBuffer.new('one'), 'two', 'three'].to_sentence + assert_instance_of String, [ActiveSupport::SafeBuffer.new("one")].to_sentence + assert_instance_of String, [ActiveSupport::SafeBuffer.new("one"), "two"].to_sentence + assert_instance_of String, [ActiveSupport::SafeBuffer.new("one"), "two", "three"].to_sentence end end @@ -93,7 +93,7 @@ class ToXmlTest < ActiveSupport::TestCase def test_to_xml_with_hash_elements xml = [ { name: "David", age: 26, age_in_millis: 820497600000 }, - { name: "Jason", age: 31, age_in_millis: BigDecimal.new('1.0') } + { name: "Jason", age: 31, age_in_millis: BigDecimal.new("1.0") } ].to_xml(skip_instruct: true, indent: 0) assert_equal '<objects type="array"><object>', xml.first(30) @@ -113,7 +113,7 @@ class ToXmlTest < ActiveSupport::TestCase end def test_to_xml_with_non_hash_different_type_elements - xml = [1, 2.0, '3'].to_xml(skip_instruct: true, indent: 0) + xml = [1, 2.0, "3"].to_xml(skip_instruct: true, indent: 0) assert_equal '<objects type="array"><object', xml.first(29) assert xml.include?(%(<object type="integer">1</object>)), xml @@ -176,7 +176,7 @@ class ToXmlTest < ActiveSupport::TestCase def test_to_xml_with_instruct xml = [ { name: "David", age: 26, age_in_millis: 820497600000 }, - { name: "Jason", age: 31, age_in_millis: BigDecimal.new('1.0') } + { name: "Jason", age: 31, age_in_millis: BigDecimal.new("1.0") } ].to_xml(skip_instruct: false, indent: 0) assert_match(/^<\?xml [^>]*/, xml) @@ -186,7 +186,7 @@ class ToXmlTest < ActiveSupport::TestCase def test_to_xml_with_block xml = [ { name: "David", age: 26, age_in_millis: 820497600000 }, - { name: "Jason", age: 31, age_in_millis: BigDecimal.new('1.0') } + { name: "Jason", age: 31, age_in_millis: BigDecimal.new("1.0") } ].to_xml(skip_instruct: true, indent: 0) do |builder| builder.count 2 end diff --git a/activesupport/test/core_ext/array/extract_options_test.rb b/activesupport/test/core_ext/array/extract_options_test.rb index 0481a507cf..1651bee0f6 100644 --- a/activesupport/test/core_ext/array/extract_options_test.rb +++ b/activesupport/test/core_ext/array/extract_options_test.rb @@ -1,6 +1,6 @@ -require 'abstract_unit' -require 'active_support/core_ext/array' -require 'active_support/core_ext/hash' +require "abstract_unit" +require "active_support/core_ext/array" +require "active_support/core_ext/hash" class ExtractOptionsTest < ActiveSupport::TestCase class HashSubclass < Hash diff --git a/activesupport/test/core_ext/array/grouping_test.rb b/activesupport/test/core_ext/array/grouping_test.rb index 0682241f0b..86c9bae131 100644 --- a/activesupport/test/core_ext/array/grouping_test.rb +++ b/activesupport/test/core_ext/array/grouping_test.rb @@ -1,5 +1,5 @@ -require 'abstract_unit' -require 'active_support/core_ext/array' +require "abstract_unit" +require "active_support/core_ext/array" class GroupingTest < ActiveSupport::TestCase def setup @@ -13,27 +13,27 @@ class GroupingTest < ActiveSupport::TestCase def test_in_groups_of_with_perfect_fit groups = [] - ('a'..'i').to_a.in_groups_of(3) do |group| + ("a".."i").to_a.in_groups_of(3) do |group| groups << group end assert_equal [%w(a b c), %w(d e f), %w(g h i)], groups - assert_equal [%w(a b c), %w(d e f), %w(g h i)], ('a'..'i').to_a.in_groups_of(3) + assert_equal [%w(a b c), %w(d e f), %w(g h i)], ("a".."i").to_a.in_groups_of(3) end def test_in_groups_of_with_padding groups = [] - ('a'..'g').to_a.in_groups_of(3) do |group| + ("a".."g").to_a.in_groups_of(3) do |group| groups << group end - assert_equal [%w(a b c), %w(d e f), ['g', nil, nil]], groups + assert_equal [%w(a b c), %w(d e f), ["g", nil, nil]], groups end def test_in_groups_of_pads_with_specified_values groups = [] - ('a'..'g').to_a.in_groups_of(3, 'foo') do |group| + ("a".."g").to_a.in_groups_of(3, "foo") do |group| groups << group end @@ -43,7 +43,7 @@ class GroupingTest < ActiveSupport::TestCase def test_in_groups_of_without_padding groups = [] - ('a'..'g').to_a.in_groups_of(3, false) do |group| + ("a".."g").to_a.in_groups_of(3, false) do |group| groups << group end @@ -83,8 +83,8 @@ class GroupingTest < ActiveSupport::TestCase assert_equal [[1, 2, 3], [4, 5, nil], [6, 7, nil]], array.in_groups(3) - assert_equal [[1, 2, 3], [4, 5, 'foo'], [6, 7, 'foo']], - array.in_groups(3, 'foo') + assert_equal [[1, 2, 3], [4, 5, "foo"], [6, 7, "foo"]], + array.in_groups(3, "foo") end def test_in_groups_without_padding diff --git a/activesupport/test/core_ext/array/prepend_append_test.rb b/activesupport/test/core_ext/array/prepend_append_test.rb index 762aa69b2b..763e26191d 100644 --- a/activesupport/test/core_ext/array/prepend_append_test.rb +++ b/activesupport/test/core_ext/array/prepend_append_test.rb @@ -1,5 +1,5 @@ -require 'abstract_unit' -require 'active_support/core_ext/array' +require "abstract_unit" +require "active_support/core_ext/array" class PrependAppendTest < ActiveSupport::TestCase def test_append diff --git a/activesupport/test/core_ext/array/wrap_test.rb b/activesupport/test/core_ext/array/wrap_test.rb index baf426506f..ae846cb3f2 100644 --- a/activesupport/test/core_ext/array/wrap_test.rb +++ b/activesupport/test/core_ext/array/wrap_test.rb @@ -1,5 +1,5 @@ -require 'abstract_unit' -require 'active_support/core_ext/array' +require "abstract_unit" +require "active_support/core_ext/array" class WrapTest < ActiveSupport::TestCase class FakeCollection diff --git a/activesupport/test/core_ext/bigdecimal_test.rb b/activesupport/test/core_ext/bigdecimal_test.rb index 6e82e3892b..43b659546f 100644 --- a/activesupport/test/core_ext/bigdecimal_test.rb +++ b/activesupport/test/core_ext/bigdecimal_test.rb @@ -1,11 +1,11 @@ -require 'abstract_unit' -require 'active_support/core_ext/big_decimal' +require "abstract_unit" +require "active_support/core_ext/big_decimal" class BigDecimalTest < ActiveSupport::TestCase def test_to_s - bd = BigDecimal.new '0.01' - assert_equal '0.01', bd.to_s - assert_equal '+0.01', bd.to_s('+F') - assert_equal '+0.0 1', bd.to_s('+1F') + bd = BigDecimal.new "0.01" + assert_equal "0.01", bd.to_s + assert_equal "+0.01", bd.to_s("+F") + assert_equal "+0.0 1", bd.to_s("+1F") end end diff --git a/activesupport/test/core_ext/class/attribute_test.rb b/activesupport/test/core_ext/class/attribute_test.rb index e7a1334db3..5a9ec78cc1 100644 --- a/activesupport/test/core_ext/class/attribute_test.rb +++ b/activesupport/test/core_ext/class/attribute_test.rb @@ -1,5 +1,5 @@ -require 'abstract_unit' -require 'active_support/core_ext/class/attribute' +require "abstract_unit" +require "active_support/core_ext/class/attribute" class ClassAttributeTest < ActiveSupport::TestCase def setup @@ -7,17 +7,17 @@ class ClassAttributeTest < ActiveSupport::TestCase @sub = Class.new(@klass) end - test 'defaults to nil' do + test "defaults to nil" do assert_nil @klass.setting assert_nil @sub.setting end - test 'inheritable' do + test "inheritable" do @klass.setting = 1 assert_equal 1, @sub.setting end - test 'overridable' do + test "overridable" do @sub.setting = 1 assert_nil @klass.setting @@ -27,20 +27,20 @@ class ClassAttributeTest < ActiveSupport::TestCase assert_equal 1, Class.new(@sub).setting end - test 'predicate method' do + test "predicate method" do assert_equal false, @klass.setting? @klass.setting = 1 assert_equal true, @klass.setting? end - test 'instance reader delegates to class' do + test "instance reader delegates to class" do assert_nil @klass.new.setting @klass.setting = 1 assert_equal 1, @klass.new.setting end - test 'instance override' do + test "instance override" do object = @klass.new object.setting = 1 assert_nil @klass.setting @@ -48,43 +48,43 @@ class ClassAttributeTest < ActiveSupport::TestCase assert_equal 1, object.setting end - test 'instance predicate' do + test "instance predicate" do object = @klass.new assert_equal false, object.setting? object.setting = 1 assert_equal true, object.setting? end - test 'disabling instance writer' do - object = Class.new { class_attribute :setting, :instance_writer => false }.new - assert_raise(NoMethodError) { object.setting = 'boom' } + test "disabling instance writer" do + object = Class.new { class_attribute :setting, instance_writer: false }.new + assert_raise(NoMethodError) { object.setting = "boom" } end - test 'disabling instance reader' do - object = Class.new { class_attribute :setting, :instance_reader => false }.new + test "disabling instance reader" do + object = Class.new { class_attribute :setting, instance_reader: false }.new assert_raise(NoMethodError) { object.setting } assert_raise(NoMethodError) { object.setting? } end - test 'disabling both instance writer and reader' do - object = Class.new { class_attribute :setting, :instance_accessor => false }.new + test "disabling both instance writer and reader" do + object = Class.new { class_attribute :setting, instance_accessor: false }.new assert_raise(NoMethodError) { object.setting } assert_raise(NoMethodError) { object.setting? } - assert_raise(NoMethodError) { object.setting = 'boom' } + assert_raise(NoMethodError) { object.setting = "boom" } end - test 'disabling instance predicate' do + test "disabling instance predicate" do object = Class.new { class_attribute :setting, instance_predicate: false }.new assert_raise(NoMethodError) { object.setting? } end - test 'works well with singleton classes' do + test "works well with singleton classes" do object = @klass.new - object.singleton_class.setting = 'foo' - assert_equal 'foo', object.setting + object.singleton_class.setting = "foo" + assert_equal "foo", object.setting end - test 'setter returns set value' do + test "setter returns set value" do val = @klass.send(:setting=, 1) assert_equal 1, val end diff --git a/activesupport/test/core_ext/class_test.rb b/activesupport/test/core_ext/class_test.rb index 9c6c579ef7..a9c44907cc 100644 --- a/activesupport/test/core_ext/class_test.rb +++ b/activesupport/test/core_ext/class_test.rb @@ -1,6 +1,6 @@ -require 'abstract_unit' -require 'active_support/core_ext/class' -require 'set' +require "abstract_unit" +require "active_support/core_ext/class" +require "set" class ClassTest < ActiveSupport::TestCase class Parent; end diff --git a/activesupport/test/core_ext/date_and_time_behavior.rb b/activesupport/test/core_ext/date_and_time_behavior.rb index 54df87def8..bf83ac602f 100644 --- a/activesupport/test/core_ext/date_and_time_behavior.rb +++ b/activesupport/test/core_ext/date_and_time_behavior.rb @@ -1,4 +1,4 @@ -require 'abstract_unit' +require "abstract_unit" module DateAndTimeBehavior def test_yesterday diff --git a/activesupport/test/core_ext/date_and_time_compatibility_test.rb b/activesupport/test/core_ext/date_and_time_compatibility_test.rb index 11cb1469da..180b3e12aa 100644 --- a/activesupport/test/core_ext/date_and_time_compatibility_test.rb +++ b/activesupport/test/core_ext/date_and_time_compatibility_test.rb @@ -1,6 +1,6 @@ -require 'abstract_unit' -require 'active_support/time' -require 'time_zone_test_helpers' +require "abstract_unit" +require "active_support/time" +require "time_zone_test_helpers" class DateAndTimeCompatibilityTest < ActiveSupport::TestCase include TimeZoneTestHelpers @@ -10,12 +10,12 @@ class DateAndTimeCompatibilityTest < ActiveSupport::TestCase @date_time = DateTime.new(2016, 4, 23, 14, 11, 12, 0) @utc_offset = 3600 @system_offset = -14400 - @zone = ActiveSupport::TimeZone['London'] + @zone = ActiveSupport::TimeZone["London"] end def test_time_to_time_preserves_timezone with_preserve_timezone(true) do - with_env_tz 'US/Eastern' do + with_env_tz "US/Eastern" do time = Time.new(2016, 4, 23, 15, 11, 12, 3600).to_time assert_instance_of Time, time @@ -27,7 +27,7 @@ class DateAndTimeCompatibilityTest < ActiveSupport::TestCase def test_time_to_time_does_not_preserve_time_zone with_preserve_timezone(false) do - with_env_tz 'US/Eastern' do + with_env_tz "US/Eastern" do time = Time.new(2016, 4, 23, 15, 11, 12, 3600).to_time assert_instance_of Time, time @@ -39,7 +39,7 @@ class DateAndTimeCompatibilityTest < ActiveSupport::TestCase def test_datetime_to_time_preserves_timezone with_preserve_timezone(true) do - with_env_tz 'US/Eastern' do + with_env_tz "US/Eastern" do time = DateTime.new(2016, 4, 23, 15, 11, 12, Rational(1,24)).to_time assert_instance_of Time, time @@ -51,7 +51,7 @@ class DateAndTimeCompatibilityTest < ActiveSupport::TestCase def test_datetime_to_time_does_not_preserve_time_zone with_preserve_timezone(false) do - with_env_tz 'US/Eastern' do + with_env_tz "US/Eastern" do time = DateTime.new(2016, 4, 23, 15, 11, 12, Rational(1,24)).to_time assert_instance_of Time, time @@ -63,7 +63,7 @@ class DateAndTimeCompatibilityTest < ActiveSupport::TestCase def test_twz_to_time_preserves_timezone with_preserve_timezone(true) do - with_env_tz 'US/Eastern' do + with_env_tz "US/Eastern" do time = ActiveSupport::TimeWithZone.new(@utc_time, @zone).to_time assert_instance_of Time, time @@ -83,7 +83,7 @@ class DateAndTimeCompatibilityTest < ActiveSupport::TestCase def test_twz_to_time_does_not_preserve_time_zone with_preserve_timezone(false) do - with_env_tz 'US/Eastern' do + with_env_tz "US/Eastern" do time = ActiveSupport::TimeWithZone.new(@utc_time, @zone).to_time assert_instance_of Time, time @@ -103,7 +103,7 @@ class DateAndTimeCompatibilityTest < ActiveSupport::TestCase def test_string_to_time_preserves_timezone with_preserve_timezone(true) do - with_env_tz 'US/Eastern' do + with_env_tz "US/Eastern" do time = "2016-04-23T15:11:12+01:00".to_time assert_instance_of Time, time @@ -115,7 +115,7 @@ class DateAndTimeCompatibilityTest < ActiveSupport::TestCase def test_string_to_time_does_not_preserve_time_zone with_preserve_timezone(false) do - with_env_tz 'US/Eastern' do + with_env_tz "US/Eastern" do time = "2016-04-23T15:11:12+01:00".to_time assert_instance_of Time, time diff --git a/activesupport/test/core_ext/date_ext_test.rb b/activesupport/test/core_ext/date_ext_test.rb index a7219eee31..0655197335 100644 --- a/activesupport/test/core_ext/date_ext_test.rb +++ b/activesupport/test/core_ext/date_ext_test.rb @@ -1,7 +1,7 @@ -require 'abstract_unit' -require 'active_support/time' -require 'core_ext/date_and_time_behavior' -require 'time_zone_test_helpers' +require "abstract_unit" +require "active_support/time" +require "core_ext/date_and_time_behavior" +require "time_zone_test_helpers" class DateExtCalculationsTest < ActiveSupport::TestCase def date_time_init(year,month,day,*args) @@ -47,7 +47,7 @@ class DateExtCalculationsTest < ActiveSupport::TestCase end def test_to_time - with_env_tz 'US/Eastern' do + with_env_tz "US/Eastern" do assert_equal Time, Date.new(2005, 2, 21).to_time.class assert_equal Time.local(2005, 2, 21), Date.new(2005, 2, 21).to_time assert_equal Time.local(2005, 2, 21).utc_offset, Date.new(2005, 2, 21).to_time.utc_offset @@ -81,10 +81,10 @@ class DateExtCalculationsTest < ActiveSupport::TestCase end def test_change - assert_equal Date.new(2005, 2, 21), Date.new(2005, 2, 11).change(:day => 21) - assert_equal Date.new(2007, 5, 11), Date.new(2005, 2, 11).change(:year => 2007, :month => 5) - assert_equal Date.new(2006,2,22), Date.new(2005,2,22).change(:year => 2006) - assert_equal Date.new(2005,6,22), Date.new(2005,2,22).change(:month => 6) + assert_equal Date.new(2005, 2, 21), Date.new(2005, 2, 11).change(day: 21) + assert_equal Date.new(2007, 5, 11), Date.new(2005, 2, 11).change(year: 2007, month: 5) + assert_equal Date.new(2006,2,22), Date.new(2005,2,22).change(year: 2006) + assert_equal Date.new(2005,6,22), Date.new(2005,2,22).change(month: 6) end def test_sunday @@ -139,34 +139,34 @@ class DateExtCalculationsTest < ActiveSupport::TestCase end def test_advance - assert_equal Date.new(2006,2,28), Date.new(2005,2,28).advance(:years => 1) - assert_equal Date.new(2005,6,28), Date.new(2005,2,28).advance(:months => 4) - assert_equal Date.new(2005,3,21), Date.new(2005,2,28).advance(:weeks => 3) - assert_equal Date.new(2005,3,5), Date.new(2005,2,28).advance(:days => 5) - assert_equal Date.new(2012,9,28), Date.new(2005,2,28).advance(:years => 7, :months => 7) - assert_equal Date.new(2013,10,3), Date.new(2005,2,28).advance(:years => 7, :months => 19, :days => 5) - assert_equal Date.new(2013,10,17), Date.new(2005,2,28).advance(:years => 7, :months => 19, :weeks => 2, :days => 5) - assert_equal Date.new(2005,2,28), Date.new(2004,2,29).advance(:years => 1) #leap day plus one year + assert_equal Date.new(2006,2,28), Date.new(2005,2,28).advance(years: 1) + assert_equal Date.new(2005,6,28), Date.new(2005,2,28).advance(months: 4) + assert_equal Date.new(2005,3,21), Date.new(2005,2,28).advance(weeks: 3) + assert_equal Date.new(2005,3,5), Date.new(2005,2,28).advance(days: 5) + assert_equal Date.new(2012,9,28), Date.new(2005,2,28).advance(years: 7, months: 7) + assert_equal Date.new(2013,10,3), Date.new(2005,2,28).advance(years: 7, months: 19, days: 5) + assert_equal Date.new(2013,10,17), Date.new(2005,2,28).advance(years: 7, months: 19, weeks: 2, days: 5) + assert_equal Date.new(2005,2,28), Date.new(2004,2,29).advance(years: 1) #leap day plus one year end def test_advance_does_first_years_and_then_days - assert_equal Date.new(2012, 2, 29), Date.new(2011, 2, 28).advance(:years => 1, :days => 1) + assert_equal Date.new(2012, 2, 29), Date.new(2011, 2, 28).advance(years: 1, days: 1) # If day was done first we would jump to 2012-03-01 instead. end def test_advance_does_first_months_and_then_days - assert_equal Date.new(2010, 3, 29), Date.new(2010, 2, 28).advance(:months => 1, :days => 1) + assert_equal Date.new(2010, 3, 29), Date.new(2010, 2, 28).advance(months: 1, days: 1) # If day was done first we would jump to 2010-04-01 instead. end def test_advance_in_calendar_reform - assert_equal Date.new(1582,10,15), Date.new(1582,10,4).advance(:days => 1) - assert_equal Date.new(1582,10,4), Date.new(1582,10,15).advance(:days => -1) + assert_equal Date.new(1582,10,15), Date.new(1582,10,4).advance(days: 1) + assert_equal Date.new(1582,10,4), Date.new(1582,10,15).advance(days: -1) 5.upto(14) do |day| - assert_equal Date.new(1582,10,4), Date.new(1582,9,day).advance(:months => 1) - assert_equal Date.new(1582,10,4), Date.new(1582,11,day).advance(:months => -1) - assert_equal Date.new(1582,10,4), Date.new(1581,10,day).advance(:years => 1) - assert_equal Date.new(1582,10,4), Date.new(1583,10,day).advance(:years => -1) + assert_equal Date.new(1582,10,4), Date.new(1582,9,day).advance(months: 1) + assert_equal Date.new(1582,10,4), Date.new(1582,11,day).advance(months: -1) + assert_equal Date.new(1582,10,4), Date.new(1581,10,day).advance(years: 1) + assert_equal Date.new(1582,10,4), Date.new(1583,10,day).advance(years: -1) end end @@ -196,7 +196,7 @@ class DateExtCalculationsTest < ActiveSupport::TestCase end def test_yesterday_constructor_when_zone_is_not_set - with_env_tz 'UTC' do + with_env_tz "UTC" do with_tz_default do assert_equal(Date.today - 1, Date.yesterday) end @@ -204,8 +204,8 @@ class DateExtCalculationsTest < ActiveSupport::TestCase end def test_yesterday_constructor_when_zone_is_set - with_env_tz 'UTC' do - with_tz_default ActiveSupport::TimeZone['Eastern Time (US & Canada)'] do # UTC -5 + with_env_tz "UTC" do + with_tz_default ActiveSupport::TimeZone["Eastern Time (US & Canada)"] do # UTC -5 Time.stub(:now, Time.local(2000, 1, 1)) do assert_equal Date.new(1999, 12, 30), Date.yesterday end @@ -218,7 +218,7 @@ class DateExtCalculationsTest < ActiveSupport::TestCase end def test_tomorrow_constructor_when_zone_is_not_set - with_env_tz 'UTC' do + with_env_tz "UTC" do with_tz_default do assert_equal(Date.today + 1, Date.tomorrow) end @@ -226,8 +226,8 @@ class DateExtCalculationsTest < ActiveSupport::TestCase end def test_tomorrow_constructor_when_zone_is_set - with_env_tz 'UTC' do - with_tz_default ActiveSupport::TimeZone['Europe/Paris'] do # UTC +1 + with_env_tz "UTC" do + with_tz_default ActiveSupport::TimeZone["Europe/Paris"] do # UTC +1 Time.stub(:now, Time.local(1999, 12, 31, 23)) do assert_equal Date.new(2000, 1, 2), Date.tomorrow end @@ -240,8 +240,8 @@ class DateExtCalculationsTest < ActiveSupport::TestCase end def test_since_when_zone_is_set - zone = ActiveSupport::TimeZone['Eastern Time (US & Canada)'] - with_env_tz 'UTC' do + zone = ActiveSupport::TimeZone["Eastern Time (US & Canada)"] + with_env_tz "UTC" do with_tz_default zone do assert_equal zone.local(2005,2,21,0,0,45), Date.new(2005,2,21).since(45) assert_equal zone, Date.new(2005,2,21).since(45).time_zone @@ -254,8 +254,8 @@ class DateExtCalculationsTest < ActiveSupport::TestCase end def test_ago_when_zone_is_set - zone = ActiveSupport::TimeZone['Eastern Time (US & Canada)'] - with_env_tz 'UTC' do + zone = ActiveSupport::TimeZone["Eastern Time (US & Canada)"] + with_env_tz "UTC" do with_tz_default zone do assert_equal zone.local(2005,2,20,23,59,15), Date.new(2005,2,21).ago(45) assert_equal zone, Date.new(2005,2,21).ago(45).time_zone @@ -272,8 +272,8 @@ class DateExtCalculationsTest < ActiveSupport::TestCase end def test_beginning_of_day_when_zone_is_set - zone = ActiveSupport::TimeZone['Eastern Time (US & Canada)'] - with_env_tz 'UTC' do + zone = ActiveSupport::TimeZone["Eastern Time (US & Canada)"] + with_env_tz "UTC" do with_tz_default zone do assert_equal zone.local(2005,2,21,0,0,0), Date.new(2005,2,21).beginning_of_day assert_equal zone, Date.new(2005,2,21).beginning_of_day.time_zone @@ -286,8 +286,8 @@ class DateExtCalculationsTest < ActiveSupport::TestCase end def test_end_of_day_when_zone_is_set - zone = ActiveSupport::TimeZone['Eastern Time (US & Canada)'] - with_env_tz 'UTC' do + zone = ActiveSupport::TimeZone["Eastern Time (US & Canada)"] + with_env_tz "UTC" do with_tz_default zone do assert_equal zone.local(2005,2,21,23,59,59,Rational(999999999, 1000)), Date.new(2005,2,21).end_of_day assert_equal zone, Date.new(2005,2,21).end_of_day.time_zone @@ -330,7 +330,7 @@ class DateExtCalculationsTest < ActiveSupport::TestCase end def test_xmlschema - with_env_tz 'US/Eastern' do + with_env_tz "US/Eastern" do assert_match(/^1980-02-28T00:00:00-05:?00$/, Date.new(1980, 2, 28).xmlschema) assert_match(/^1980-06-28T00:00:00-04:?00$/, Date.new(1980, 6, 28).xmlschema) # these tests are only of interest on platforms where older dates #to_time fail over to DateTime @@ -342,8 +342,8 @@ class DateExtCalculationsTest < ActiveSupport::TestCase end def test_xmlschema_when_zone_is_set - with_env_tz 'UTC' do - with_tz_default ActiveSupport::TimeZone['Eastern Time (US & Canada)'] do # UTC -5 + with_env_tz "UTC" do + with_tz_default ActiveSupport::TimeZone["Eastern Time (US & Canada)"] do # UTC -5 assert_match(/^1980-02-28T00:00:00-05:?00$/, Date.new(1980, 2, 28).xmlschema) assert_match(/^1980-06-28T00:00:00-04:?00$/, Date.new(1980, 6, 28).xmlschema) end @@ -367,7 +367,7 @@ class DateExtCalculationsTest < ActiveSupport::TestCase end def test_current_returns_date_today_when_zone_not_set - with_env_tz 'US/Central' do + with_env_tz "US/Central" do Time.stub(:now, Time.local(1999, 12, 31, 23)) do assert_equal Date.today, Date.current end @@ -375,8 +375,8 @@ class DateExtCalculationsTest < ActiveSupport::TestCase end def test_current_returns_time_zone_today_when_zone_is_set - Time.zone = ActiveSupport::TimeZone['Eastern Time (US & Canada)'] - with_env_tz 'US/Central' do + Time.zone = ActiveSupport::TimeZone["Eastern Time (US & Canada)"] + with_env_tz "US/Central" do assert_equal ::Time.zone.today, Date.current end ensure @@ -384,9 +384,9 @@ class DateExtCalculationsTest < ActiveSupport::TestCase end def test_date_advance_should_not_change_passed_options_hash - options = { :years => 3, :months => 11, :days => 2 } + options = { years: 3, months: 11, days: 2 } Date.new(2005,2,28).advance(options) - assert_equal({ :years => 3, :months => 11, :days => 2 }, options) + assert_equal({ years: 3, months: 11, days: 2 }, options) end end @@ -407,4 +407,3 @@ class DateExtBehaviorTest < ActiveSupport::TestCase end end end - diff --git a/activesupport/test/core_ext/date_time_ext_test.rb b/activesupport/test/core_ext/date_time_ext_test.rb index 306316efcd..f2a50f4693 100644 --- a/activesupport/test/core_ext/date_time_ext_test.rb +++ b/activesupport/test/core_ext/date_time_ext_test.rb @@ -1,7 +1,7 @@ -require 'abstract_unit' -require 'active_support/time' -require 'core_ext/date_and_time_behavior' -require 'time_zone_test_helpers' +require "abstract_unit" +require "active_support/time" +require "core_ext/date_and_time_behavior" +require "time_zone_test_helpers" class DateTimeExtCalculationsTest < ActiveSupport::TestCase def date_time_init(year,month,day,hour,minute,second,*args) @@ -35,13 +35,13 @@ class DateTimeExtCalculationsTest < ActiveSupport::TestCase end def test_custom_date_format - Time::DATE_FORMATS[:custom] = '%Y%m%d%H%M%S' - assert_equal '20050221143000', DateTime.new(2005, 2, 21, 14, 30, 0).to_s(:custom) + Time::DATE_FORMATS[:custom] = "%Y%m%d%H%M%S" + assert_equal "20050221143000", DateTime.new(2005, 2, 21, 14, 30, 0).to_s(:custom) Time::DATE_FORMATS.delete(:custom) end def test_localtime - with_env_tz 'US/Eastern' do + with_env_tz "US/Eastern" do assert_instance_of Time, DateTime.new(2016, 3, 11, 15, 11, 12, 0).localtime assert_equal Time.local(2016, 3, 11, 10, 11, 12), DateTime.new(2016, 3, 11, 15, 11, 12, 0).localtime assert_equal Time.local(2016, 3, 21, 11, 11, 12), DateTime.new(2016, 3, 21, 15, 11, 12, 0).localtime @@ -50,7 +50,7 @@ class DateTimeExtCalculationsTest < ActiveSupport::TestCase end def test_getlocal - with_env_tz 'US/Eastern' do + with_env_tz "US/Eastern" do assert_instance_of Time, DateTime.new(2016, 3, 11, 15, 11, 12, 0).getlocal assert_equal Time.local(2016, 3, 11, 10, 11, 12), DateTime.new(2016, 3, 11, 15, 11, 12, 0).getlocal assert_equal Time.local(2016, 3, 21, 11, 11, 12), DateTime.new(2016, 3, 21, 15, 11, 12, 0).getlocal @@ -67,7 +67,7 @@ class DateTimeExtCalculationsTest < ActiveSupport::TestCase end def test_to_time - with_env_tz 'US/Eastern' do + with_env_tz "US/Eastern" do assert_instance_of Time, DateTime.new(2005, 2, 21, 10, 11, 12, 0).to_time if ActiveSupport.to_time_preserves_timezone @@ -159,47 +159,47 @@ class DateTimeExtCalculationsTest < ActiveSupport::TestCase end def test_change - assert_equal DateTime.civil(2006,2,22,15,15,10), DateTime.civil(2005,2,22,15,15,10).change(:year => 2006) - assert_equal DateTime.civil(2005,6,22,15,15,10), DateTime.civil(2005,2,22,15,15,10).change(:month => 6) - assert_equal DateTime.civil(2012,9,22,15,15,10), DateTime.civil(2005,2,22,15,15,10).change(:year => 2012, :month => 9) - assert_equal DateTime.civil(2005,2,22,16), DateTime.civil(2005,2,22,15,15,10).change(:hour => 16) - assert_equal DateTime.civil(2005,2,22,16,45), DateTime.civil(2005,2,22,15,15,10).change(:hour => 16, :min => 45) - assert_equal DateTime.civil(2005,2,22,15,45), DateTime.civil(2005,2,22,15,15,10).change(:min => 45) + assert_equal DateTime.civil(2006,2,22,15,15,10), DateTime.civil(2005,2,22,15,15,10).change(year: 2006) + assert_equal DateTime.civil(2005,6,22,15,15,10), DateTime.civil(2005,2,22,15,15,10).change(month: 6) + assert_equal DateTime.civil(2012,9,22,15,15,10), DateTime.civil(2005,2,22,15,15,10).change(year: 2012, month: 9) + assert_equal DateTime.civil(2005,2,22,16), DateTime.civil(2005,2,22,15,15,10).change(hour: 16) + assert_equal DateTime.civil(2005,2,22,16,45), DateTime.civil(2005,2,22,15,15,10).change(hour: 16, min: 45) + assert_equal DateTime.civil(2005,2,22,15,45), DateTime.civil(2005,2,22,15,15,10).change(min: 45) # datetime with fractions of a second - assert_equal DateTime.civil(2005,2,1,15,15,10.7), DateTime.civil(2005,2,22,15,15,10.7).change(:day => 1) + assert_equal DateTime.civil(2005,2,1,15,15,10.7), DateTime.civil(2005,2,22,15,15,10.7).change(day: 1) end def test_advance - assert_equal DateTime.civil(2006,2,28,15,15,10), DateTime.civil(2005,2,28,15,15,10).advance(:years => 1) - assert_equal DateTime.civil(2005,6,28,15,15,10), DateTime.civil(2005,2,28,15,15,10).advance(:months => 4) - assert_equal DateTime.civil(2005,3,21,15,15,10), DateTime.civil(2005,2,28,15,15,10).advance(:weeks => 3) - assert_equal DateTime.civil(2005,3,5,15,15,10), DateTime.civil(2005,2,28,15,15,10).advance(:days => 5) - assert_equal DateTime.civil(2012,9,28,15,15,10), DateTime.civil(2005,2,28,15,15,10).advance(:years => 7, :months => 7) - assert_equal DateTime.civil(2013,10,3,15,15,10), DateTime.civil(2005,2,28,15,15,10).advance(:years => 7, :months => 19, :days => 5) - assert_equal DateTime.civil(2013,10,17,15,15,10), DateTime.civil(2005,2,28,15,15,10).advance(:years => 7, :months => 19, :weeks => 2, :days => 5) - assert_equal DateTime.civil(2001,12,27,15,15,10), DateTime.civil(2005,2,28,15,15,10).advance(:years => -3, :months => -2, :days => -1) - assert_equal DateTime.civil(2005,2,28,15,15,10), DateTime.civil(2004,2,29,15,15,10).advance(:years => 1) #leap day plus one year - assert_equal DateTime.civil(2005,2,28,20,15,10), DateTime.civil(2005,2,28,15,15,10).advance(:hours => 5) - assert_equal DateTime.civil(2005,2,28,15,22,10), DateTime.civil(2005,2,28,15,15,10).advance(:minutes => 7) - assert_equal DateTime.civil(2005,2,28,15,15,19), DateTime.civil(2005,2,28,15,15,10).advance(:seconds => 9) - assert_equal DateTime.civil(2005,2,28,20,22,19), DateTime.civil(2005,2,28,15,15,10).advance(:hours => 5, :minutes => 7, :seconds => 9) - assert_equal DateTime.civil(2005,2,28,10,8,1), DateTime.civil(2005,2,28,15,15,10).advance(:hours => -5, :minutes => -7, :seconds => -9) - assert_equal DateTime.civil(2013,10,17,20,22,19), DateTime.civil(2005,2,28,15,15,10).advance(:years => 7, :months => 19, :weeks => 2, :days => 5, :hours => 5, :minutes => 7, :seconds => 9) + assert_equal DateTime.civil(2006,2,28,15,15,10), DateTime.civil(2005,2,28,15,15,10).advance(years: 1) + assert_equal DateTime.civil(2005,6,28,15,15,10), DateTime.civil(2005,2,28,15,15,10).advance(months: 4) + assert_equal DateTime.civil(2005,3,21,15,15,10), DateTime.civil(2005,2,28,15,15,10).advance(weeks: 3) + assert_equal DateTime.civil(2005,3,5,15,15,10), DateTime.civil(2005,2,28,15,15,10).advance(days: 5) + assert_equal DateTime.civil(2012,9,28,15,15,10), DateTime.civil(2005,2,28,15,15,10).advance(years: 7, months: 7) + assert_equal DateTime.civil(2013,10,3,15,15,10), DateTime.civil(2005,2,28,15,15,10).advance(years: 7, months: 19, days: 5) + assert_equal DateTime.civil(2013,10,17,15,15,10), DateTime.civil(2005,2,28,15,15,10).advance(years: 7, months: 19, weeks: 2, days: 5) + assert_equal DateTime.civil(2001,12,27,15,15,10), DateTime.civil(2005,2,28,15,15,10).advance(years: -3, months: -2, days: -1) + assert_equal DateTime.civil(2005,2,28,15,15,10), DateTime.civil(2004,2,29,15,15,10).advance(years: 1) #leap day plus one year + assert_equal DateTime.civil(2005,2,28,20,15,10), DateTime.civil(2005,2,28,15,15,10).advance(hours: 5) + assert_equal DateTime.civil(2005,2,28,15,22,10), DateTime.civil(2005,2,28,15,15,10).advance(minutes: 7) + assert_equal DateTime.civil(2005,2,28,15,15,19), DateTime.civil(2005,2,28,15,15,10).advance(seconds: 9) + assert_equal DateTime.civil(2005,2,28,20,22,19), DateTime.civil(2005,2,28,15,15,10).advance(hours: 5, minutes: 7, seconds: 9) + assert_equal DateTime.civil(2005,2,28,10,8,1), DateTime.civil(2005,2,28,15,15,10).advance(hours: -5, minutes: -7, seconds: -9) + assert_equal DateTime.civil(2013,10,17,20,22,19), DateTime.civil(2005,2,28,15,15,10).advance(years: 7, months: 19, weeks: 2, days: 5, hours: 5, minutes: 7, seconds: 9) end def test_advance_partial_days - assert_equal DateTime.civil(2012,9,29,13,15,10), DateTime.civil(2012,9,28,1,15,10).advance(:days => 1.5) - assert_equal DateTime.civil(2012,9,28,13,15,10), DateTime.civil(2012,9,28,1,15,10).advance(:days => 0.5) - assert_equal DateTime.civil(2012,10,29,13,15,10), DateTime.civil(2012,9,28,1,15,10).advance(:days => 1.5, :months => 1) + assert_equal DateTime.civil(2012,9,29,13,15,10), DateTime.civil(2012,9,28,1,15,10).advance(days: 1.5) + assert_equal DateTime.civil(2012,9,28,13,15,10), DateTime.civil(2012,9,28,1,15,10).advance(days: 0.5) + assert_equal DateTime.civil(2012,10,29,13,15,10), DateTime.civil(2012,9,28,1,15,10).advance(days: 1.5, months: 1) end def test_advanced_processes_first_the_date_deltas_and_then_the_time_deltas # If the time deltas were processed first, the following datetimes would be advanced to 2010/04/01 instead. - assert_equal DateTime.civil(2010, 3, 29), DateTime.civil(2010, 2, 28, 23, 59, 59).advance(:months => 1, :seconds => 1) - assert_equal DateTime.civil(2010, 3, 29), DateTime.civil(2010, 2, 28, 23, 59).advance(:months => 1, :minutes => 1) - assert_equal DateTime.civil(2010, 3, 29), DateTime.civil(2010, 2, 28, 23).advance(:months => 1, :hours => 1) - assert_equal DateTime.civil(2010, 3, 29), DateTime.civil(2010, 2, 28, 22, 58, 59).advance(:months => 1, :hours => 1, :minutes => 1, :seconds => 1) + assert_equal DateTime.civil(2010, 3, 29), DateTime.civil(2010, 2, 28, 23, 59, 59).advance(months: 1, seconds: 1) + assert_equal DateTime.civil(2010, 3, 29), DateTime.civil(2010, 2, 28, 23, 59).advance(months: 1, minutes: 1) + assert_equal DateTime.civil(2010, 3, 29), DateTime.civil(2010, 2, 28, 23).advance(months: 1, hours: 1) + assert_equal DateTime.civil(2010, 3, 29), DateTime.civil(2010, 2, 28, 22, 58, 59).advance(months: 1, hours: 1, minutes: 1, seconds: 1) end def test_last_week @@ -282,7 +282,7 @@ class DateTimeExtCalculationsTest < ActiveSupport::TestCase end def test_current_returns_date_today_when_zone_is_not_set - with_env_tz 'US/Eastern' do + with_env_tz "US/Eastern" do Time.stub(:now, Time.local(1999, 12, 31, 23, 59, 59)) do assert_equal DateTime.new(1999, 12, 31, 23, 59, 59, Rational(-18000, 86400)), DateTime.current end @@ -290,8 +290,8 @@ class DateTimeExtCalculationsTest < ActiveSupport::TestCase end def test_current_returns_time_zone_today_when_zone_is_set - Time.zone = ActiveSupport::TimeZone['Eastern Time (US & Canada)'] - with_env_tz 'US/Eastern' do + Time.zone = ActiveSupport::TimeZone["Eastern Time (US & Canada)"] + with_env_tz "US/Eastern" do Time.stub(:now, Time.local(1999, 12, 31, 23, 59, 59)) do assert_equal DateTime.new(1999, 12, 31, 23, 59, 59, Rational(-18000, 86400)), DateTime.current end @@ -305,7 +305,7 @@ class DateTimeExtCalculationsTest < ActiveSupport::TestCase end def test_current_with_time_zone - with_env_tz 'US/Eastern' do + with_env_tz "US/Eastern" do assert_kind_of DateTime, DateTime.current end end @@ -343,15 +343,15 @@ class DateTimeExtCalculationsTest < ActiveSupport::TestCase end def test_formatted_offset_with_utc - assert_equal '+00:00', DateTime.civil(2000).formatted_offset - assert_equal '+0000', DateTime.civil(2000).formatted_offset(false) - assert_equal 'UTC', DateTime.civil(2000).formatted_offset(true, 'UTC') + assert_equal "+00:00", DateTime.civil(2000).formatted_offset + assert_equal "+0000", DateTime.civil(2000).formatted_offset(false) + assert_equal "UTC", DateTime.civil(2000).formatted_offset(true, "UTC") end def test_formatted_offset_with_local dt = DateTime.civil(2005, 2, 21, 10, 11, 12, Rational(-5, 24)) - assert_equal '-05:00', dt.formatted_offset - assert_equal '-0500', dt.formatted_offset(false) + assert_equal "-05:00", dt.formatted_offset + assert_equal "-0500", dt.formatted_offset(false) end def test_compare_with_time @@ -367,9 +367,9 @@ class DateTimeExtCalculationsTest < ActiveSupport::TestCase end def test_compare_with_time_with_zone - assert_equal 1, DateTime.civil(2000) <=> ActiveSupport::TimeWithZone.new( Time.utc(1999, 12, 31, 23, 59, 59), ActiveSupport::TimeZone['UTC'] ) - assert_equal 0, DateTime.civil(2000) <=> ActiveSupport::TimeWithZone.new( Time.utc(2000, 1, 1, 0, 0, 0), ActiveSupport::TimeZone['UTC'] ) - assert_equal(-1, DateTime.civil(2000) <=> ActiveSupport::TimeWithZone.new( Time.utc(2000, 1, 1, 0, 0, 1), ActiveSupport::TimeZone['UTC'] )) + assert_equal 1, DateTime.civil(2000) <=> ActiveSupport::TimeWithZone.new( Time.utc(1999, 12, 31, 23, 59, 59), ActiveSupport::TimeZone["UTC"] ) + assert_equal 0, DateTime.civil(2000) <=> ActiveSupport::TimeWithZone.new( Time.utc(2000, 1, 1, 0, 0, 0), ActiveSupport::TimeZone["UTC"] ) + assert_equal(-1, DateTime.civil(2000) <=> ActiveSupport::TimeWithZone.new( Time.utc(2000, 1, 1, 0, 0, 1), ActiveSupport::TimeZone["UTC"] )) end def test_compare_with_string diff --git a/activesupport/test/core_ext/digest/uuid_test.rb b/activesupport/test/core_ext/digest/uuid_test.rb index 08e0a1d6e1..866a03259a 100644 --- a/activesupport/test/core_ext/digest/uuid_test.rb +++ b/activesupport/test/core_ext/digest/uuid_test.rb @@ -1,5 +1,5 @@ -require 'abstract_unit' -require 'active_support/core_ext/digest/uuid' +require "abstract_unit" +require "active_support/core_ext/digest/uuid" class DigestUUIDExt < ActiveSupport::TestCase def test_v3_uuids @@ -18,7 +18,7 @@ class DigestUUIDExt < ActiveSupport::TestCase def test_invalid_hash_class assert_raise ArgumentError do - Digest::UUID.uuid_from_hash(Digest::SHA2, Digest::UUID::OID_NAMESPACE, '1.2.3') + Digest::UUID.uuid_from_hash(Digest::SHA2, Digest::UUID::OID_NAMESPACE, "1.2.3") end end end diff --git a/activesupport/test/core_ext/duration_test.rb b/activesupport/test/core_ext/duration_test.rb index a24915dfef..1a2dcba760 100644 --- a/activesupport/test/core_ext/duration_test.rb +++ b/activesupport/test/core_ext/duration_test.rb @@ -1,8 +1,8 @@ -require 'abstract_unit' -require 'active_support/inflector' -require 'active_support/time' -require 'active_support/json' -require 'time_zone_test_helpers' +require "abstract_unit" +require "active_support/inflector" +require "active_support/time" +require "active_support/json" +require "time_zone_test_helpers" class DurationTest < ActiveSupport::TestCase include TimeZoneTestHelpers @@ -29,14 +29,14 @@ class DurationTest < ActiveSupport::TestCase def test_threequals assert ActiveSupport::Duration === 1.day assert !(ActiveSupport::Duration === 1.day.to_i) - assert !(ActiveSupport::Duration === 'foo') + assert !(ActiveSupport::Duration === "foo") end def test_equals assert 1.day == 1.day assert 1.day == 1.day.to_i assert 1.day.to_i == 1.day - assert !(1.day == 'foo') + assert !(1.day == "foo") end def test_to_s @@ -54,28 +54,28 @@ class DurationTest < ActiveSupport::TestCase assert !1.eql?(1.second) assert 1.minute.eql?(180.seconds - 2.minutes) assert !1.minute.eql?(60) - assert !1.minute.eql?('foo') + assert !1.minute.eql?("foo") end def test_inspect - assert_equal '0 seconds', 0.seconds.inspect - assert_equal '1 month', 1.month.inspect - assert_equal '1 month and 1 day', (1.month + 1.day).inspect - assert_equal '6 months and -2 days', (6.months - 2.days).inspect - assert_equal '10 seconds', 10.seconds.inspect - assert_equal '10 years, 2 months, and 1 day', (10.years + 2.months + 1.day).inspect - assert_equal '10 years, 2 months, and 1 day', (10.years + 1.month + 1.day + 1.month).inspect - assert_equal '10 years, 2 months, and 1 day', (1.day + 10.years + 2.months).inspect - assert_equal '7 days', 7.days.inspect - assert_equal '1 week', 1.week.inspect - assert_equal '2 weeks', 1.fortnight.inspect + assert_equal "0 seconds", 0.seconds.inspect + assert_equal "1 month", 1.month.inspect + assert_equal "1 month and 1 day", (1.month + 1.day).inspect + assert_equal "6 months and -2 days", (6.months - 2.days).inspect + assert_equal "10 seconds", 10.seconds.inspect + assert_equal "10 years, 2 months, and 1 day", (10.years + 2.months + 1.day).inspect + assert_equal "10 years, 2 months, and 1 day", (10.years + 1.month + 1.day + 1.month).inspect + assert_equal "10 years, 2 months, and 1 day", (1.day + 10.years + 2.months).inspect + assert_equal "7 days", 7.days.inspect + assert_equal "1 week", 1.week.inspect + assert_equal "2 weeks", 1.fortnight.inspect end def test_inspect_locale current_locale = I18n.default_locale I18n.default_locale = :de - I18n.backend.store_translations(:de, { support: { array: { last_word_connector: ' und ' } } }) - assert_equal '10 years, 1 month und 1 day', (10.years + 1.month + 1.day).inspect + I18n.backend.store_translations(:de, support: { array: { last_word_connector: " und " } }) + assert_equal "10 years, 1 month und 1 day", (10.years + 1.month + 1.day).inspect ensure I18n.default_locale = current_locale end @@ -89,7 +89,7 @@ class DurationTest < ActiveSupport::TestCase end def test_time_plus_duration_returns_same_time_datatype - twz = ActiveSupport::TimeWithZone.new(nil, ActiveSupport::TimeZone['Moscow'] , Time.utc(2016,4,28,00,45)) + twz = ActiveSupport::TimeWithZone.new(nil, ActiveSupport::TimeZone["Moscow"] , Time.utc(2016,4,28,00,45)) now = Time.now.utc %w( second minute hour day week month year ).each do |unit| assert_equal((now + 1.send(unit)).class, Time, "Time + 1.#{unit} must be Time") @@ -99,7 +99,7 @@ class DurationTest < ActiveSupport::TestCase def test_argument_error e = assert_raise ArgumentError do - 1.second.ago('') + 1.second.ago("") end assert_equal 'expected a time or date, got ""', e.message, "ensure ArgumentError is not being raised by dependencies.rb" end @@ -149,7 +149,7 @@ class DurationTest < ActiveSupport::TestCase def test_since_and_ago_anchored_to_time_now_when_time_zone_is_not_set Time.zone = nil - with_env_tz 'US/Eastern' do + with_env_tz "US/Eastern" do Time.stub(:now, Time.local(2000)) do # since assert_not_instance_of ActiveSupport::TimeWithZone, 5.seconds.since @@ -162,17 +162,17 @@ class DurationTest < ActiveSupport::TestCase end def test_since_and_ago_anchored_to_time_zone_now_when_time_zone_is_set - Time.zone = ActiveSupport::TimeZone['Eastern Time (US & Canada)'] - with_env_tz 'US/Eastern' do + Time.zone = ActiveSupport::TimeZone["Eastern Time (US & Canada)"] + with_env_tz "US/Eastern" do Time.stub(:now, Time.local(2000)) do # since assert_instance_of ActiveSupport::TimeWithZone, 5.seconds.since assert_equal Time.utc(2000,1,1,0,0,5), 5.seconds.since.time - assert_equal 'Eastern Time (US & Canada)', 5.seconds.since.time_zone.name + assert_equal "Eastern Time (US & Canada)", 5.seconds.since.time_zone.name # ago assert_instance_of ActiveSupport::TimeWithZone, 5.seconds.ago assert_equal Time.utc(1999,12,31,23,59,55), 5.seconds.ago.time - assert_equal 'Eastern Time (US & Canada)', 5.seconds.ago.time_zone.name + assert_equal "Eastern Time (US & Canada)", 5.seconds.ago.time_zone.name end end ensure @@ -180,13 +180,13 @@ class DurationTest < ActiveSupport::TestCase end def test_adding_hours_across_dst_boundary - with_env_tz 'CET' do + with_env_tz "CET" do assert_equal Time.local(2009,3,29,0,0,0) + 24.hours, Time.local(2009,3,30,1,0,0) end end def test_adding_day_across_dst_boundary - with_env_tz 'CET' do + with_env_tz "CET" do assert_equal Time.local(2009,3,29,0,0,0) + 1.day, Time.local(2009,3,30,0,0,0) end end @@ -194,7 +194,7 @@ class DurationTest < ActiveSupport::TestCase def test_delegation_with_block_works counter = 0 assert_nothing_raised do - 1.minute.times {counter += 1} + 1.minute.times { counter += 1 } end assert_equal counter, 60 end @@ -204,7 +204,7 @@ class DurationTest < ActiveSupport::TestCase end def test_to_json - assert_equal '172800', 2.days.to_json + assert_equal "172800", 2.days.to_json end def test_case_when @@ -260,7 +260,7 @@ class DurationTest < ActiveSupport::TestCase # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. def test_iso8601_parsing_wrong_patterns_with_raise - invalid_patterns = ['', 'P', 'PT', 'P1YT', 'T', 'PW', 'P1Y1W', '~P1Y', '.P1Y', 'P1.5Y0.5M', 'P1.5Y1M', 'P1.5MT10.5S'] + invalid_patterns = ["", "P", "PT", "P1YT", "T", "PW", "P1Y1W", "~P1Y", ".P1Y", "P1.5Y0.5M", "P1.5Y1M", "P1.5MT10.5S"] invalid_patterns.each do |pattern| assert_raise ActiveSupport::Duration::ISO8601Parser::ParsingError, pattern.inspect do ActiveSupport::Duration.parse(pattern) @@ -270,16 +270,16 @@ class DurationTest < ActiveSupport::TestCase def test_iso8601_output expectations = [ - ['P1Y', 1.year ], - ['P1W', 1.week ], - ['P1Y1M', 1.year + 1.month ], - ['P1Y1M1D', 1.year + 1.month + 1.day ], - ['-P1Y1D', -1.year - 1.day ], - ['P1Y-1DT-1S', 1.year - 1.day - 1.second ], # Parts with different signs are exists in PostgreSQL interval datatype. - ['PT1S', 1.second ], - ['PT1.4S', (1.4).seconds ], - ['P1Y1M1DT1H', 1.year + 1.month + 1.day + 1.hour], - ['PT0S', 0.minutes ], + ["P1Y", 1.year ], + ["P1W", 1.week ], + ["P1Y1M", 1.year + 1.month ], + ["P1Y1M1D", 1.year + 1.month + 1.day ], + ["-P1Y1D", -1.year - 1.day ], + ["P1Y-1DT-1S", 1.year - 1.day - 1.second ], # Parts with different signs are exists in PostgreSQL interval datatype. + ["PT1S", 1.second ], + ["PT1.4S", (1.4).seconds ], + ["P1Y1M1DT1H", 1.year + 1.month + 1.day + 1.hour], + ["PT0S", 0.minutes ], ] expectations.each do |expected_output, duration| assert_equal expected_output, duration.iso8601, expected_output.inspect @@ -288,17 +288,17 @@ class DurationTest < ActiveSupport::TestCase def test_iso8601_output_precision expectations = [ - [nil, 'P1Y1MT5.55S', 1.year + 1.month + (5.55).seconds ], - [0, 'P1Y1MT6S', 1.year + 1.month + (5.55).seconds ], - [1, 'P1Y1MT5.5S', 1.year + 1.month + (5.55).seconds ], - [2, 'P1Y1MT5.55S', 1.year + 1.month + (5.55).seconds ], - [3, 'P1Y1MT5.550S', 1.year + 1.month + (5.55).seconds ], - [nil, 'PT1S', 1.second ], - [2, 'PT1.00S', 1.second ], - [nil, 'PT1.4S', (1.4).seconds ], - [0, 'PT1S', (1.4).seconds ], - [1, 'PT1.4S', (1.4).seconds ], - [5, 'PT1.40000S', (1.4).seconds ], + [nil, "P1Y1MT5.55S", 1.year + 1.month + (5.55).seconds ], + [0, "P1Y1MT6S", 1.year + 1.month + (5.55).seconds ], + [1, "P1Y1MT5.5S", 1.year + 1.month + (5.55).seconds ], + [2, "P1Y1MT5.55S", 1.year + 1.month + (5.55).seconds ], + [3, "P1Y1MT5.550S", 1.year + 1.month + (5.55).seconds ], + [nil, "PT1S", 1.second ], + [2, "PT1.00S", 1.second ], + [nil, "PT1.4S", (1.4).seconds ], + [0, "PT1S", (1.4).seconds ], + [1, "PT1.4S", (1.4).seconds ], + [5, "PT1.40000S", (1.4).seconds ], ] expectations.each do |precision, expected_output, duration| assert_equal expected_output, duration.iso8601(precision: precision), expected_output.inspect diff --git a/activesupport/test/core_ext/enumerable_test.rb b/activesupport/test/core_ext/enumerable_test.rb index 99c3236c35..9072957e0e 100644 --- a/activesupport/test/core_ext/enumerable_test.rb +++ b/activesupport/test/core_ext/enumerable_test.rb @@ -1,6 +1,6 @@ -require 'abstract_unit' -require 'active_support/core_ext/array' -require 'active_support/core_ext/enumerable' +require "abstract_unit" +require "active_support/core_ext/array" +require "active_support/core_ext/enumerable" Payment = Struct.new(:price) ExpandedPayment = Struct.new(:dollars, :cents) @@ -33,8 +33,8 @@ class EnumerableTests < ActiveSupport::TestCase assert_equal 60, enum.sum { |i| i * 2 } enum = GenericEnumerable.new(%w(a b c)) - assert_equal 'abc', enum.sum - assert_equal 'aabbcc', enum.sum { |i| i * 2 } + assert_equal "abc", enum.sum + assert_equal "aabbcc", enum.sum { |i| i * 2 } payments = GenericEnumerable.new([ Payment.new(5), Payment.new(15), Payment.new(10) ]) assert_equal 30, payments.sum(&:price) @@ -75,7 +75,7 @@ class EnumerableTests < ActiveSupport::TestCase assert_typed_equal(2.0, sum.real, Float) assert_typed_equal(3.0, sum.imag, Float) - sum = GenericEnumerable.new([1, 2]).sum(10) {|v| v * 2 } + sum = GenericEnumerable.new([1, 2]).sum(10) { |v| v * 2 } assert_typed_equal(16, sum, Integer) end @@ -102,7 +102,7 @@ class EnumerableTests < ActiveSupport::TestCase assert_equal 10, (1..4).sum assert_equal 10, (1..4.5).sum assert_equal 6, (1...4).sum - assert_equal 'abc', ('a'..'c').sum + assert_equal "abc", ("a".."c").sum assert_equal 50_000_005_000_000, (0..10_000_000).sum assert_equal 0, (10..0).sum assert_equal 5, (10..0).sum(5) @@ -120,8 +120,8 @@ class EnumerableTests < ActiveSupport::TestCase assert_equal 60, enum.sum { |i| i * 2 } enum = %w(a b c) - assert_equal 'abc', enum.sum - assert_equal 'aabbcc', enum.sum { |i| i * 2 } + assert_equal "abc", enum.sum + assert_equal "aabbcc", enum.sum { |i| i * 2 } payments = [ Payment.new(5), Payment.new(15), Payment.new(10) ] assert_equal 30, payments.sum(&:price) @@ -162,7 +162,7 @@ class EnumerableTests < ActiveSupport::TestCase assert_typed_equal(2.0, sum.real, Float) assert_typed_equal(3.0, sum.imag, Float) - sum = [1, 2].sum(10) {|v| v * 2 } + sum = [1, 2].sum(10) { |v| v * 2 } assert_typed_equal(16, sum, Integer) end @@ -184,17 +184,17 @@ class EnumerableTests < ActiveSupport::TestCase assert_equal false, GenericEnumerable.new([ 1 ] ).many? assert_equal true, GenericEnumerable.new([ 1, 2 ] ).many? - assert_equal false, GenericEnumerable.new([] ).many? {|x| x > 1 } - assert_equal false, GenericEnumerable.new([ 2 ] ).many? {|x| x > 1 } - assert_equal false, GenericEnumerable.new([ 1, 2 ] ).many? {|x| x > 1 } - assert_equal true, GenericEnumerable.new([ 1, 2, 2 ]).many? {|x| x > 1 } + assert_equal false, GenericEnumerable.new([] ).many? { |x| x > 1 } + assert_equal false, GenericEnumerable.new([ 2 ] ).many? { |x| x > 1 } + assert_equal false, GenericEnumerable.new([ 1, 2 ] ).many? { |x| x > 1 } + assert_equal true, GenericEnumerable.new([ 1, 2, 2 ]).many? { |x| x > 1 } end def test_many_iterates_only_on_what_is_needed infinity = 1.0/0.0 very_long_enum = 0..infinity assert_equal true, very_long_enum.many? - assert_equal true, very_long_enum.many?{|x| x > 100} + assert_equal true, very_long_enum.many? { |x| x > 100 } end def test_exclude? @@ -206,7 +206,7 @@ class EnumerableTests < ActiveSupport::TestCase assert_equal [1, 2, 4], GenericEnumerable.new((1..5).to_a).without(3, 5) assert_equal [1, 2, 4], (1..5).to_a.without(3, 5) assert_equal [1, 2, 4], (1..5).to_set.without(3, 5) - assert_equal({foo: 1, baz: 3}, {foo: 1, bar: 2, baz: 3}.without(:bar)) + assert_equal({ foo: 1, baz: 3 }, { foo: 1, bar: 2, baz: 3 }.without(:bar)) end def test_pluck diff --git a/activesupport/test/core_ext/file_test.rb b/activesupport/test/core_ext/file_test.rb index cde0132b97..df5d09acd0 100644 --- a/activesupport/test/core_ext/file_test.rb +++ b/activesupport/test/core_ext/file_test.rb @@ -1,5 +1,5 @@ -require 'abstract_unit' -require 'active_support/core_ext/file' +require "abstract_unit" +require "active_support/core_ext/file" class AtomicWriteTest < ActiveSupport::TestCase def test_atomic_write_without_errors diff --git a/activesupport/test/core_ext/hash/transform_keys_test.rb b/activesupport/test/core_ext/hash/transform_keys_test.rb index 962d3a30b6..7a11d827f8 100644 --- a/activesupport/test/core_ext/hash/transform_keys_test.rb +++ b/activesupport/test/core_ext/hash/transform_keys_test.rb @@ -1,62 +1,62 @@ -require 'abstract_unit' -require 'active_support/core_ext/hash/keys' +require "abstract_unit" +require "active_support/core_ext/hash/keys" class TransformKeysTest < ActiveSupport::TestCase test "transform_keys returns a new hash with the keys computed from the block" do - original = { a: 'a', b: 'b' } + original = { a: "a", b: "b" } mapped = original.transform_keys { |k| "#{k}!".to_sym } - assert_equal({ a: 'a', b: 'b' }, original) - assert_equal({ a!: 'a', b!: 'b' }, mapped) + assert_equal({ a: "a", b: "b" }, original) + assert_equal({ a!: "a", b!: "b" }, mapped) end test "transform_keys! modifies the keys of the original" do - original = { a: 'a', b: 'b' } + original = { a: "a", b: "b" } mapped = original.transform_keys! { |k| "#{k}!".to_sym } - assert_equal({ a!: 'a', b!: 'b' }, original) + assert_equal({ a!: "a", b!: "b" }, original) assert_same original, mapped end test "transform_keys returns a sized Enumerator if no block is given" do - original = { a: 'a', b: 'b' } + original = { a: "a", b: "b" } enumerator = original.transform_keys assert_equal original.size, enumerator.size assert_equal Enumerator, enumerator.class end test "transform_keys! returns a sized Enumerator if no block is given" do - original = { a: 'a', b: 'b' } + original = { a: "a", b: "b" } enumerator = original.transform_keys! assert_equal original.size, enumerator.size assert_equal Enumerator, enumerator.class end test "transform_keys is chainable with Enumerable methods" do - original = { a: 'a', b: 'b' } + original = { a: "a", b: "b" } mapped = original.transform_keys.with_index { |k, i| [k, i].join.to_sym } - assert_equal({ a0: 'a', b1: 'b' }, mapped) + assert_equal({ a0: "a", b1: "b" }, mapped) end test "transform_keys! is chainable with Enumerable methods" do - original = { a: 'a', b: 'b' } + original = { a: "a", b: "b" } original.transform_keys!.with_index { |k, i| [k, i].join.to_sym } - assert_equal({ a0: 'a', b1: 'b' }, original) + assert_equal({ a0: "a", b1: "b" }, original) end test "transform_keys returns a Hash instance when self is inherited from Hash" do class HashDescendant < ::Hash def initialize(elements = nil) super(elements) - (elements || {}).each_pair{ |key, value| self[key] = value } + (elements || {}).each_pair { |key, value| self[key] = value } end end - original = HashDescendant.new({ a: 'a', b: 'b' }) + original = HashDescendant.new(a: "a", b: "b") mapped = original.transform_keys { |k| "#{k}!".to_sym } - assert_equal({ a: 'a', b: 'b' }, original) - assert_equal({ a!: 'a', b!: 'b' }, mapped) + assert_equal({ a: "a", b: "b" }, original) + assert_equal({ a!: "a", b!: "b" }, mapped) assert_equal(::Hash, mapped.class) end end diff --git a/activesupport/test/core_ext/hash/transform_values_test.rb b/activesupport/test/core_ext/hash/transform_values_test.rb index 114022fbaf..f2ac4ce6ce 100644 --- a/activesupport/test/core_ext/hash/transform_values_test.rb +++ b/activesupport/test/core_ext/hash/transform_values_test.rb @@ -1,75 +1,75 @@ -require 'abstract_unit' -require 'active_support/core_ext/hash/indifferent_access' -require 'active_support/core_ext/hash/transform_values' +require "abstract_unit" +require "active_support/core_ext/hash/indifferent_access" +require "active_support/core_ext/hash/transform_values" class TransformValuesTest < ActiveSupport::TestCase test "transform_values returns a new hash with the values computed from the block" do - original = { a: 'a', b: 'b' } - mapped = original.transform_values { |v| v + '!' } + original = { a: "a", b: "b" } + mapped = original.transform_values { |v| v + "!" } - assert_equal({ a: 'a', b: 'b' }, original) - assert_equal({ a: 'a!', b: 'b!' }, mapped) + assert_equal({ a: "a", b: "b" }, original) + assert_equal({ a: "a!", b: "b!" }, mapped) end test "transform_values! modifies the values of the original" do - original = { a: 'a', b: 'b' } - mapped = original.transform_values! { |v| v + '!' } + original = { a: "a", b: "b" } + mapped = original.transform_values! { |v| v + "!" } - assert_equal({ a: 'a!', b: 'b!' }, original) + assert_equal({ a: "a!", b: "b!" }, original) assert_same original, mapped end test "indifferent access is still indifferent after mapping values" do - original = { a: 'a', b: 'b' }.with_indifferent_access - mapped = original.transform_values { |v| v + '!' } + original = { a: "a", b: "b" }.with_indifferent_access + mapped = original.transform_values { |v| v + "!" } - assert_equal 'a!', mapped[:a] - assert_equal 'a!', mapped['a'] + assert_equal "a!", mapped[:a] + assert_equal "a!", mapped["a"] end # This is to be consistent with the behavior of Ruby's built in methods # (e.g. #select, #reject) as of 2.2 test "default values do not persist during mapping" do - original = Hash.new('foo') - original[:a] = 'a' - mapped = original.transform_values { |v| v + '!' } + original = Hash.new("foo") + original[:a] = "a" + mapped = original.transform_values { |v| v + "!" } - assert_equal 'a!', mapped[:a] + assert_equal "a!", mapped[:a] assert_nil mapped[:b] end test "default procs do not persist after mapping" do - original = Hash.new { 'foo' } - original[:a] = 'a' - mapped = original.transform_values { |v| v + '!' } + original = Hash.new { "foo" } + original[:a] = "a" + mapped = original.transform_values { |v| v + "!" } - assert_equal 'a!', mapped[:a] + assert_equal "a!", mapped[:a] assert_nil mapped[:b] end test "transform_values returns a sized Enumerator if no block is given" do - original = { a: 'a', b: 'b' } + original = { a: "a", b: "b" } enumerator = original.transform_values assert_equal original.size, enumerator.size assert_equal Enumerator, enumerator.class end test "transform_values! returns a sized Enumerator if no block is given" do - original = { a: 'a', b: 'b' } + original = { a: "a", b: "b" } enumerator = original.transform_values! assert_equal original.size, enumerator.size assert_equal Enumerator, enumerator.class end test "transform_values is chainable with Enumerable methods" do - original = { a: 'a', b: 'b' } + original = { a: "a", b: "b" } mapped = original.transform_values.with_index { |v, i| [v, i].join } - assert_equal({ a: 'a0', b: 'b1' }, mapped) + assert_equal({ a: "a0", b: "b1" }, mapped) end test "transform_values! is chainable with Enumerable methods" do - original = { a: 'a', b: 'b' } + original = { a: "a", b: "b" } original.transform_values!.with_index { |v, i| [v, i].join } - assert_equal({ a: 'a0', b: 'b1' }, original) + assert_equal({ a: "a0", b: "b1" }, original) end end diff --git a/activesupport/test/core_ext/hash_ext_test.rb b/activesupport/test/core_ext/hash_ext_test.rb index e8099baa35..e457cb866d 100644 --- a/activesupport/test/core_ext/hash_ext_test.rb +++ b/activesupport/test/core_ext/hash_ext_test.rb @@ -1,11 +1,11 @@ -require 'abstract_unit' -require 'active_support/core_ext/hash' -require 'bigdecimal' -require 'active_support/core_ext/string/access' -require 'active_support/ordered_hash' -require 'active_support/core_ext/object/conversions' -require 'active_support/core_ext/object/deep_dup' -require 'active_support/inflections' +require "abstract_unit" +require "active_support/core_ext/hash" +require "bigdecimal" +require "active_support/core_ext/string/access" +require "active_support/ordered_hash" +require "active_support/core_ext/object/conversions" +require "active_support/core_ext/object/deep_dup" +require "active_support/inflections" class HashExtTest < ActiveSupport::TestCase class IndifferentHash < ActiveSupport::HashWithIndifferentAccess @@ -34,22 +34,22 @@ class HashExtTest < ActiveSupport::TestCase end def setup - @strings = { 'a' => 1, 'b' => 2 } - @nested_strings = { 'a' => { 'b' => { 'c' => 3 } } } - @symbols = { :a => 1, :b => 2 } - @nested_symbols = { :a => { :b => { :c => 3 } } } - @mixed = { :a => 1, 'b' => 2 } - @nested_mixed = { 'a' => { :b => { 'c' => 3 } } } + @strings = { "a" => 1, "b" => 2 } + @nested_strings = { "a" => { "b" => { "c" => 3 } } } + @symbols = { a: 1, b: 2 } + @nested_symbols = { a: { b: { c: 3 } } } + @mixed = { :a => 1, "b" => 2 } + @nested_mixed = { "a" => { b: { "c" => 3 } } } @integers = { 0 => 1, 1 => 2 } - @nested_integers = { 0 => { 1 => { 2 => 3} } } + @nested_integers = { 0 => { 1 => { 2 => 3 } } } @illegal_symbols = { [] => 3 } - @nested_illegal_symbols = { [] => { [] => 3} } - @upcase_strings = { 'A' => 1, 'B' => 2 } - @nested_upcase_strings = { 'A' => { 'B' => { 'C' => 3 } } } - @string_array_of_hashes = { 'a' => [ { 'b' => 2 }, { 'c' => 3 }, 4 ] } - @symbol_array_of_hashes = { :a => [ { :b => 2 }, { :c => 3 }, 4 ] } - @mixed_array_of_hashes = { :a => [ { :b => 2 }, { 'c' => 3 }, 4 ] } - @upcase_array_of_hashes = { 'A' => [ { 'B' => 2 }, { 'C' => 3 }, 4 ] } + @nested_illegal_symbols = { [] => { [] => 3 } } + @upcase_strings = { "A" => 1, "B" => 2 } + @nested_upcase_strings = { "A" => { "B" => { "C" => 3 } } } + @string_array_of_hashes = { "a" => [ { "b" => 2 }, { "c" => 3 }, 4 ] } + @symbol_array_of_hashes = { a: [ { b: 2 }, { c: 3 }, 4 ] } + @mixed_array_of_hashes = { a: [ { b: 2 }, { "c" => 3 }, 4 ] } + @upcase_array_of_hashes = { "A" => [ { "B" => 2 }, { "C" => 3 }, 4 ] } end def test_methods @@ -75,59 +75,59 @@ class HashExtTest < ActiveSupport::TestCase end def test_transform_keys - assert_equal @upcase_strings, @strings.transform_keys{ |key| key.to_s.upcase } - assert_equal @upcase_strings, @symbols.transform_keys{ |key| key.to_s.upcase } - assert_equal @upcase_strings, @mixed.transform_keys{ |key| key.to_s.upcase } + assert_equal @upcase_strings, @strings.transform_keys { |key| key.to_s.upcase } + assert_equal @upcase_strings, @symbols.transform_keys { |key| key.to_s.upcase } + assert_equal @upcase_strings, @mixed.transform_keys { |key| key.to_s.upcase } end def test_transform_keys_not_mutates transformed_hash = @mixed.dup - transformed_hash.transform_keys{ |key| key.to_s.upcase } + transformed_hash.transform_keys { |key| key.to_s.upcase } assert_equal @mixed, transformed_hash end def test_deep_transform_keys - assert_equal @nested_upcase_strings, @nested_symbols.deep_transform_keys{ |key| key.to_s.upcase } - assert_equal @nested_upcase_strings, @nested_strings.deep_transform_keys{ |key| key.to_s.upcase } - assert_equal @nested_upcase_strings, @nested_mixed.deep_transform_keys{ |key| key.to_s.upcase } - assert_equal @upcase_array_of_hashes, @string_array_of_hashes.deep_transform_keys{ |key| key.to_s.upcase } - assert_equal @upcase_array_of_hashes, @symbol_array_of_hashes.deep_transform_keys{ |key| key.to_s.upcase } - assert_equal @upcase_array_of_hashes, @mixed_array_of_hashes.deep_transform_keys{ |key| key.to_s.upcase } + assert_equal @nested_upcase_strings, @nested_symbols.deep_transform_keys { |key| key.to_s.upcase } + assert_equal @nested_upcase_strings, @nested_strings.deep_transform_keys { |key| key.to_s.upcase } + assert_equal @nested_upcase_strings, @nested_mixed.deep_transform_keys { |key| key.to_s.upcase } + assert_equal @upcase_array_of_hashes, @string_array_of_hashes.deep_transform_keys { |key| key.to_s.upcase } + assert_equal @upcase_array_of_hashes, @symbol_array_of_hashes.deep_transform_keys { |key| key.to_s.upcase } + assert_equal @upcase_array_of_hashes, @mixed_array_of_hashes.deep_transform_keys { |key| key.to_s.upcase } end def test_deep_transform_keys_not_mutates transformed_hash = @nested_mixed.deep_dup - transformed_hash.deep_transform_keys{ |key| key.to_s.upcase } + transformed_hash.deep_transform_keys { |key| key.to_s.upcase } assert_equal @nested_mixed, transformed_hash end def test_transform_keys! - assert_equal @upcase_strings, @symbols.dup.transform_keys!{ |key| key.to_s.upcase } - assert_equal @upcase_strings, @strings.dup.transform_keys!{ |key| key.to_s.upcase } - assert_equal @upcase_strings, @mixed.dup.transform_keys!{ |key| key.to_s.upcase } + assert_equal @upcase_strings, @symbols.dup.transform_keys! { |key| key.to_s.upcase } + assert_equal @upcase_strings, @strings.dup.transform_keys! { |key| key.to_s.upcase } + assert_equal @upcase_strings, @mixed.dup.transform_keys! { |key| key.to_s.upcase } end def test_transform_keys_with_bang_mutates transformed_hash = @mixed.dup - transformed_hash.transform_keys!{ |key| key.to_s.upcase } + transformed_hash.transform_keys! { |key| key.to_s.upcase } assert_equal @upcase_strings, transformed_hash - assert_equal @mixed, { :a => 1, "b" => 2 } + assert_equal @mixed, :a => 1, "b" => 2 end def test_deep_transform_keys! - assert_equal @nested_upcase_strings, @nested_symbols.deep_dup.deep_transform_keys!{ |key| key.to_s.upcase } - assert_equal @nested_upcase_strings, @nested_strings.deep_dup.deep_transform_keys!{ |key| key.to_s.upcase } - assert_equal @nested_upcase_strings, @nested_mixed.deep_dup.deep_transform_keys!{ |key| key.to_s.upcase } - assert_equal @upcase_array_of_hashes, @string_array_of_hashes.deep_dup.deep_transform_keys!{ |key| key.to_s.upcase } - assert_equal @upcase_array_of_hashes, @symbol_array_of_hashes.deep_dup.deep_transform_keys!{ |key| key.to_s.upcase } - assert_equal @upcase_array_of_hashes, @mixed_array_of_hashes.deep_dup.deep_transform_keys!{ |key| key.to_s.upcase } + assert_equal @nested_upcase_strings, @nested_symbols.deep_dup.deep_transform_keys! { |key| key.to_s.upcase } + assert_equal @nested_upcase_strings, @nested_strings.deep_dup.deep_transform_keys! { |key| key.to_s.upcase } + assert_equal @nested_upcase_strings, @nested_mixed.deep_dup.deep_transform_keys! { |key| key.to_s.upcase } + assert_equal @upcase_array_of_hashes, @string_array_of_hashes.deep_dup.deep_transform_keys! { |key| key.to_s.upcase } + assert_equal @upcase_array_of_hashes, @symbol_array_of_hashes.deep_dup.deep_transform_keys! { |key| key.to_s.upcase } + assert_equal @upcase_array_of_hashes, @mixed_array_of_hashes.deep_dup.deep_transform_keys! { |key| key.to_s.upcase } end def test_deep_transform_keys_with_bang_mutates transformed_hash = @nested_mixed.deep_dup - transformed_hash.deep_transform_keys!{ |key| key.to_s.upcase } + transformed_hash.deep_transform_keys! { |key| key.to_s.upcase } assert_equal @nested_upcase_strings, transformed_hash - assert_equal @nested_mixed, { 'a' => { :b => { 'c' => 3 } } } + assert_equal @nested_mixed, "a" => { b: { "c" => 3 } } end def test_symbolize_keys @@ -167,7 +167,7 @@ class HashExtTest < ActiveSupport::TestCase transformed_hash = @mixed.dup transformed_hash.deep_symbolize_keys! assert_equal @symbols, transformed_hash - assert_equal @mixed, { :a => 1, "b" => 2 } + assert_equal @mixed, :a => 1, "b" => 2 end def test_deep_symbolize_keys! @@ -183,7 +183,7 @@ class HashExtTest < ActiveSupport::TestCase transformed_hash = @nested_mixed.deep_dup transformed_hash.deep_symbolize_keys! assert_equal @nested_symbols, transformed_hash - assert_equal @nested_mixed, { 'a' => { :b => { 'c' => 3 } } } + assert_equal @nested_mixed, "a" => { b: { "c" => 3 } } end def test_symbolize_keys_preserves_keys_that_cant_be_symbolized @@ -243,7 +243,7 @@ class HashExtTest < ActiveSupport::TestCase transformed_hash = @mixed.dup transformed_hash.stringify_keys! assert_equal @strings, transformed_hash - assert_equal @mixed, { :a => 1, "b" => 2 } + assert_equal @mixed, :a => 1, "b" => 2 end def test_deep_stringify_keys! @@ -259,7 +259,7 @@ class HashExtTest < ActiveSupport::TestCase transformed_hash = @nested_mixed.deep_dup transformed_hash.deep_stringify_keys! assert_equal @nested_strings, transformed_hash - assert_equal @nested_mixed, { 'a' => { :b => { 'c' => 3 } } } + assert_equal @nested_mixed, "a" => { b: { "c" => 3 } } end def test_symbolize_keys_for_hash_with_indifferent_access @@ -276,7 +276,6 @@ class HashExtTest < ActiveSupport::TestCase assert_equal @nested_symbols, @nested_mixed.with_indifferent_access.deep_symbolize_keys end - def test_symbolize_keys_bang_for_hash_with_indifferent_access assert_raise(NoMethodError) { @symbols.with_indifferent_access.dup.symbolize_keys! } assert_raise(NoMethodError) { @strings.with_indifferent_access.dup.symbolize_keys! } @@ -353,31 +352,31 @@ class HashExtTest < ActiveSupport::TestCase @symbols = @symbols.with_indifferent_access @mixed = @mixed.with_indifferent_access - assert_equal 'a', @strings.__send__(:convert_key, :a) + assert_equal "a", @strings.__send__(:convert_key, :a) - assert_equal 1, @strings.fetch('a') + assert_equal 1, @strings.fetch("a") assert_equal 1, @strings.fetch(:a.to_s) assert_equal 1, @strings.fetch(:a) hashes = { :@strings => @strings, :@symbols => @symbols, :@mixed => @mixed } - method_map = { :'[]' => 1, :fetch => 1, :values_at => [1], - :has_key? => true, :include? => true, :key? => true, - :member? => true } + method_map = { '[]': 1, fetch: 1, values_at: [1], + has_key?: true, include?: true, key?: true, + member?: true } hashes.each do |name, hash| method_map.sort_by(&:to_s).each do |meth, expected| - assert_equal(expected, hash.__send__(meth, 'a'), + assert_equal(expected, hash.__send__(meth, "a"), "Calling #{name}.#{meth} 'a'") assert_equal(expected, hash.__send__(meth, :a), "Calling #{name}.#{meth} :a") end end - assert_equal [1, 2], @strings.values_at('a', 'b') + assert_equal [1, 2], @strings.values_at("a", "b") assert_equal [1, 2], @strings.values_at(:a, :b) - assert_equal [1, 2], @symbols.values_at('a', 'b') + assert_equal [1, 2], @symbols.values_at("a", "b") assert_equal [1, 2], @symbols.values_at(:a, :b) - assert_equal [1, 2], @mixed.values_at('a', 'b') + assert_equal [1, 2], @mixed.values_at("a", "b") assert_equal [1, 2], @mixed.values_at(:a, :b) end @@ -412,11 +411,11 @@ class HashExtTest < ActiveSupport::TestCase def test_indifferent_writing hash = HashWithIndifferentAccess.new hash[:a] = 1 - hash['b'] = 2 + hash["b"] = 2 hash[3] = 3 - assert_equal hash['a'], 1 - assert_equal hash['b'], 2 + assert_equal hash["a"], 1 + assert_equal hash["b"], 2 assert_equal hash[:a], 1 assert_equal hash[:b], 2 assert_equal hash[3], 3 @@ -424,56 +423,56 @@ class HashExtTest < ActiveSupport::TestCase def test_indifferent_update hash = HashWithIndifferentAccess.new - hash[:a] = 'a' - hash['b'] = 'b' + hash[:a] = "a" + hash["b"] = "b" updated_with_strings = hash.update(@strings) updated_with_symbols = hash.update(@symbols) updated_with_mixed = hash.update(@mixed) assert_equal updated_with_strings[:a], 1 - assert_equal updated_with_strings['a'], 1 - assert_equal updated_with_strings['b'], 2 + assert_equal updated_with_strings["a"], 1 + assert_equal updated_with_strings["b"], 2 assert_equal updated_with_symbols[:a], 1 - assert_equal updated_with_symbols['b'], 2 + assert_equal updated_with_symbols["b"], 2 assert_equal updated_with_symbols[:b], 2 assert_equal updated_with_mixed[:a], 1 - assert_equal updated_with_mixed['b'], 2 + assert_equal updated_with_mixed["b"], 2 assert [updated_with_strings, updated_with_symbols, updated_with_mixed].all? { |h| h.keys.size == 2 } end def test_update_with_to_hash_conversion hash = HashWithIndifferentAccess.new - hash.update HashByConversion.new({ :a => 1 }) - assert_equal hash['a'], 1 + hash.update HashByConversion.new(a: 1) + assert_equal hash["a"], 1 end def test_indifferent_merging hash = HashWithIndifferentAccess.new - hash[:a] = 'failure' - hash['b'] = 'failure' + hash[:a] = "failure" + hash["b"] = "failure" - other = { 'a' => 1, :b => 2 } + other = { "a" => 1, :b => 2 } merged = hash.merge(other) assert_equal HashWithIndifferentAccess, merged.class assert_equal 1, merged[:a] - assert_equal 2, merged['b'] + assert_equal 2, merged["b"] hash.update(other) assert_equal 1, hash[:a] - assert_equal 2, hash['b'] + assert_equal 2, hash["b"] end def test_merge_with_to_hash_conversion hash = HashWithIndifferentAccess.new - merged = hash.merge HashByConversion.new({ :a => 1 }) - assert_equal merged['a'], 1 + merged = hash.merge HashByConversion.new(a: 1) + assert_equal merged["a"], 1 end def test_indifferent_replace @@ -482,7 +481,7 @@ class HashExtTest < ActiveSupport::TestCase replaced = hash.replace(b: 12) - assert hash.key?('b') + assert hash.key?("b") assert !hash.key?(:a) assert_equal 12, hash[:b] assert_same hash, replaced @@ -494,7 +493,7 @@ class HashExtTest < ActiveSupport::TestCase replaced = hash.replace(HashByConversion.new(b: 12)) - assert hash.key?('b') + assert hash.key?("b") assert !hash.key?(:a) assert_equal 12, hash[:b] assert_same hash, replaced @@ -503,18 +502,18 @@ class HashExtTest < ActiveSupport::TestCase def test_indifferent_merging_with_block hash = HashWithIndifferentAccess.new hash[:a] = 1 - hash['b'] = 3 + hash["b"] = 3 - other = { 'a' => 4, :b => 2, 'c' => 10 } + other = { "a" => 4, :b => 2, "c" => 10 } merged = hash.merge(other) { |key, old, new| old > new ? old : new } assert_equal HashWithIndifferentAccess, merged.class assert_equal 4, merged[:a] - assert_equal 3, merged['b'] + assert_equal 3, merged["b"] assert_equal 10, merged[:c] - other_indifferent = HashWithIndifferentAccess.new('a' => 9, :b => 2) + other_indifferent = HashWithIndifferentAccess.new("a" => 9, :b => 2) merged = hash.merge(other_indifferent) { |key, old, new| old + new } @@ -528,26 +527,26 @@ class HashExtTest < ActiveSupport::TestCase hash.reverse_merge! key: :new_value assert_equal :old_value, hash[:key] - hash = HashWithIndifferentAccess.new('some' => 'value', 'other' => 'value') - hash.reverse_merge!(:some => 'noclobber', :another => 'clobber') - assert_equal 'value', hash[:some] - assert_equal 'clobber', hash[:another] + hash = HashWithIndifferentAccess.new("some" => "value", "other" => "value") + hash.reverse_merge!(some: "noclobber", another: "clobber") + assert_equal "value", hash[:some] + assert_equal "clobber", hash[:another] end def test_indifferent_deleting - get_hash = proc{ { :a => 'foo' }.with_indifferent_access } + get_hash = proc { { a: "foo" }.with_indifferent_access } hash = get_hash.call - assert_equal hash.delete(:a), 'foo' + assert_equal hash.delete(:a), "foo" assert_equal hash.delete(:a), nil hash = get_hash.call - assert_equal hash.delete('a'), 'foo' - assert_equal hash.delete('a'), nil + assert_equal hash.delete("a"), "foo" + assert_equal hash.delete("a"), nil end def test_indifferent_select - hash = ActiveSupport::HashWithIndifferentAccess.new(@strings).select {|k,v| v == 1} + hash = ActiveSupport::HashWithIndifferentAccess.new(@strings).select { |k,v| v == 1 } - assert_equal({ 'a' => 1 }, hash) + assert_equal({ "a" => 1 }, hash) assert_instance_of ActiveSupport::HashWithIndifferentAccess, hash end @@ -557,23 +556,23 @@ class HashExtTest < ActiveSupport::TestCase end def test_indifferent_select_returns_a_hash_when_unchanged - hash = ActiveSupport::HashWithIndifferentAccess.new(@strings).select {|k,v| true} + hash = ActiveSupport::HashWithIndifferentAccess.new(@strings).select { |k,v| true } assert_instance_of ActiveSupport::HashWithIndifferentAccess, hash end def test_indifferent_select_bang indifferent_strings = ActiveSupport::HashWithIndifferentAccess.new(@strings) - indifferent_strings.select! {|k,v| v == 1} + indifferent_strings.select! { |k,v| v == 1 } - assert_equal({ 'a' => 1 }, indifferent_strings) + assert_equal({ "a" => 1 }, indifferent_strings) assert_instance_of ActiveSupport::HashWithIndifferentAccess, indifferent_strings end def test_indifferent_reject - hash = ActiveSupport::HashWithIndifferentAccess.new(@strings).reject {|k,v| v != 1} + hash = ActiveSupport::HashWithIndifferentAccess.new(@strings).reject { |k,v| v != 1 } - assert_equal({ 'a' => 1 }, hash) + assert_equal({ "a" => 1 }, hash) assert_instance_of ActiveSupport::HashWithIndifferentAccess, hash end @@ -584,9 +583,9 @@ class HashExtTest < ActiveSupport::TestCase def test_indifferent_reject_bang indifferent_strings = ActiveSupport::HashWithIndifferentAccess.new(@strings) - indifferent_strings.reject! {|k,v| v != 1} + indifferent_strings.reject! { |k,v| v != 1 } - assert_equal({ 'a' => 1 }, indifferent_strings) + assert_equal({ "a" => 1 }, indifferent_strings) assert_instance_of ActiveSupport::HashWithIndifferentAccess, indifferent_strings end @@ -596,10 +595,10 @@ class HashExtTest < ActiveSupport::TestCase # Should preserve the default value. mixed_with_default = @mixed.dup - mixed_with_default.default = '1234' + mixed_with_default.default = "1234" roundtrip = mixed_with_default.with_indifferent_access.to_hash assert_equal @strings, roundtrip - assert_equal '1234', roundtrip.default + assert_equal "1234", roundtrip.default # Ensure nested hashes are not HashWithIndiffereneAccess new_to_hash = @nested_mixed.with_indifferent_access.to_hash @@ -609,21 +608,21 @@ class HashExtTest < ActiveSupport::TestCase end def test_lookup_returns_the_same_object_that_is_stored_in_hash_indifferent_access - hash = HashWithIndifferentAccess.new {|h, k| h[k] = []} + hash = HashWithIndifferentAccess.new { |h, k| h[k] = [] } hash[:a] << 1 assert_equal [1], hash[:a] end def test_with_indifferent_access_has_no_side_effects_on_existing_hash - hash = {content: [{:foo => :bar, 'bar' => 'baz'}]} + hash = { content: [{ :foo => :bar, "bar" => "baz" }] } hash.with_indifferent_access assert_equal [:foo, "bar"], hash[:content].first.keys end def test_indifferent_hash_with_array_of_hashes - hash = { "urls" => { "url" => [ { "address" => "1" }, { "address" => "2" } ] }}.with_indifferent_access + hash = { "urls" => { "url" => [ { "address" => "1" }, { "address" => "2" } ] } }.with_indifferent_access assert_equal "1", hash[:urls][:url].first[:address] hash = hash.to_hash @@ -635,14 +634,14 @@ class HashExtTest < ActiveSupport::TestCase def test_should_preserve_array_subclass_when_value_is_array array = SubclassingArray.new array << { "address" => "1" } - hash = { "urls" => { "url" => array }}.with_indifferent_access + hash = { "urls" => { "url" => array } }.with_indifferent_access assert_equal SubclassingArray, hash[:urls][:url].class end def test_should_preserve_array_class_when_hash_value_is_frozen_array array = SubclassingArray.new array << { "address" => "1" } - hash = { "urls" => { "url" => array.freeze }}.with_indifferent_access + hash = { "urls" => { "url" => array.freeze } }.with_indifferent_access assert_equal SubclassingArray, hash[:urls][:url].class end @@ -650,9 +649,9 @@ class HashExtTest < ActiveSupport::TestCase h = HashWithIndifferentAccess.new h[:first] = 1 h = h.stringify_keys - assert_equal 1, h['first'] + assert_equal 1, h["first"] h = HashWithIndifferentAccess.new - h['first'] = 1 + h["first"] = 1 h = h.symbolize_keys assert_equal 1, h[:first] end @@ -661,40 +660,40 @@ class HashExtTest < ActiveSupport::TestCase h = HashWithIndifferentAccess.new h[:first] = 1 h = h.deep_stringify_keys - assert_equal 1, h['first'] + assert_equal 1, h["first"] h = HashWithIndifferentAccess.new - h['first'] = 1 + h["first"] = 1 h = h.deep_symbolize_keys assert_equal 1, h[:first] end def test_to_options_on_indifferent_preserves_hash h = HashWithIndifferentAccess.new - h['first'] = 1 + h["first"] = 1 h.to_options! - assert_equal 1, h['first'] + assert_equal 1, h["first"] end def test_to_options_on_indifferent_preserves_works_as_hash_with_dup - h = HashWithIndifferentAccess.new({ a: { b: 'b' } }) + h = HashWithIndifferentAccess.new(a: { b: "b" }) dup = h.dup - dup[:a][:c] = 'c' - assert_equal 'c', h[:a][:c] + dup[:a][:c] = "c" + assert_equal "c", h[:a][:c] end def test_indifferent_sub_hashes - h = {'user' => {'id' => 5}}.with_indifferent_access - ['user', :user].each {|user| [:id, 'id'].each {|id| assert_equal 5, h[user][id], "h[#{user.inspect}][#{id.inspect}] should be 5"}} + h = { "user" => { "id" => 5 } }.with_indifferent_access + ["user", :user].each { |user| [:id, "id"].each { |id| assert_equal 5, h[user][id], "h[#{user.inspect}][#{id.inspect}] should be 5" } } - h = {:user => {:id => 5}}.with_indifferent_access - ['user', :user].each {|user| [:id, 'id'].each {|id| assert_equal 5, h[user][id], "h[#{user.inspect}][#{id.inspect}] should be 5"}} + h = { user: { id: 5 } }.with_indifferent_access + ["user", :user].each { |user| [:id, "id"].each { |id| assert_equal 5, h[user][id], "h[#{user.inspect}][#{id.inspect}] should be 5" } } end def test_indifferent_duplication # Should preserve default value h = HashWithIndifferentAccess.new - h.default = '1234' + h.default = "1234" assert_equal h.default, h.dup.default # Should preserve class for subclasses @@ -704,52 +703,52 @@ class HashExtTest < ActiveSupport::TestCase def test_nested_dig_indifferent_access skip if RUBY_VERSION < "2.3.0" - data = {"this" => {"views" => 1234}}.with_indifferent_access + data = { "this" => { "views" => 1234 } }.with_indifferent_access assert_equal 1234, data.dig(:this, :views) end def test_assert_valid_keys assert_nothing_raised do - { :failure => "stuff", :funny => "business" }.assert_valid_keys([ :failure, :funny ]) - { :failure => "stuff", :funny => "business" }.assert_valid_keys(:failure, :funny) + { failure: "stuff", funny: "business" }.assert_valid_keys([ :failure, :funny ]) + { failure: "stuff", funny: "business" }.assert_valid_keys(:failure, :funny) end # not all valid keys are required to be present assert_nothing_raised do - { :failure => "stuff", :funny => "business" }.assert_valid_keys([ :failure, :funny, :sunny ]) - { :failure => "stuff", :funny => "business" }.assert_valid_keys(:failure, :funny, :sunny) + { failure: "stuff", funny: "business" }.assert_valid_keys([ :failure, :funny, :sunny ]) + { failure: "stuff", funny: "business" }.assert_valid_keys(:failure, :funny, :sunny) end exception = assert_raise ArgumentError do - { :failore => "stuff", :funny => "business" }.assert_valid_keys([ :failure, :funny ]) + { 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, :funny) + { 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 ]) + { failore: "stuff", funny: "business" }.assert_valid_keys([ :failure ]) end assert_equal "Unknown key: :failore. Valid keys are: :failure", exception.message exception = assert_raise ArgumentError do - { :failore => "stuff", :funny => "business" }.assert_valid_keys(:failure) + { failore: "stuff", funny: "business" }.assert_valid_keys(:failure) end assert_equal "Unknown key: :failore. Valid keys are: :failure", exception.message end def test_assorted_keys_not_stringified - original = {Object.new => 2, 1 => 2, [] => true} + original = { Object.new => 2, 1 => 2, [] => true } indiff = original.with_indifferent_access - assert(!indiff.keys.any? {|k| k.kind_of? String}, "A key was converted to a string!") + assert(!indiff.keys.any? { |k| k.kind_of? String }, "A key was converted to a string!") end def test_deep_merge - hash_1 = { :a => "a", :b => "b", :c => { :c1 => "c1", :c2 => "c2", :c3 => { :d1 => "d1" } } } - hash_2 = { :a => 1, :c => { :c1 => 2, :c3 => { :d2 => "d2" } } } - expected = { :a => 1, :b => "b", :c => { :c1 => 2, :c2 => "c2", :c3 => { :d1 => "d1", :d2 => "d2" } } } + hash_1 = { a: "a", b: "b", c: { c1: "c1", c2: "c2", c3: { d1: "d1" } } } + hash_2 = { a: 1, c: { c1: 2, c3: { d2: "d2" } } } + expected = { a: 1, b: "b", c: { c1: 2, c2: "c2", c3: { d1: "d1", d2: "d2" } } } assert_equal expected, hash_1.deep_merge(hash_2) hash_1.deep_merge!(hash_2) @@ -757,9 +756,9 @@ class HashExtTest < ActiveSupport::TestCase end def test_deep_merge_with_block - hash_1 = { :a => "a", :b => "b", :c => { :c1 => "c1", :c2 => "c2", :c3 => { :d1 => "d1" } } } - hash_2 = { :a => 1, :c => { :c1 => 2, :c3 => { :d2 => "d2" } } } - expected = { :a => [:a, "a", 1], :b => "b", :c => { :c1 => [:c1, "c1", 2], :c2 => "c2", :c3 => { :d1 => "d1", :d2 => "d2" } } } + hash_1 = { a: "a", b: "b", c: { c1: "c1", c2: "c2", c3: { d1: "d1" } } } + hash_2 = { a: 1, c: { c1: 2, c3: { d2: "d2" } } } + expected = { a: [:a, "a", 1], b: "b", c: { c1: [:c1, "c1", 2], c2: "c2", c3: { d1: "d1", d2: "d2" } } } assert_equal(expected, hash_1.deep_merge(hash_2) { |k,o,n| [k, o, n] }) hash_1.deep_merge!(hash_2) { |k,o,n| [k, o, n] } @@ -768,8 +767,8 @@ class HashExtTest < ActiveSupport::TestCase def test_deep_merge_with_falsey_values hash_1 = { e: false } - hash_2 = { e: 'e' } - expected = { e: [:e, false, 'e'] } + hash_2 = { e: "e" } + expected = { e: [:e, false, "e"] } assert_equal(expected, hash_1.deep_merge(hash_2) { |k, o, n| [k, o, n] }) hash_1.deep_merge!(hash_2) { |k, o, n| [k, o, n] } @@ -777,9 +776,9 @@ class HashExtTest < ActiveSupport::TestCase end def test_deep_merge_on_indifferent_access - hash_1 = HashWithIndifferentAccess.new({ :a => "a", :b => "b", :c => { :c1 => "c1", :c2 => "c2", :c3 => { :d1 => "d1" } } }) - hash_2 = HashWithIndifferentAccess.new({ :a => 1, :c => { :c1 => 2, :c3 => { :d2 => "d2" } } }) - hash_3 = { :a => 1, :c => { :c1 => 2, :c3 => { :d2 => "d2" } } } + hash_1 = HashWithIndifferentAccess.new(a: "a", b: "b", c: { c1: "c1", c2: "c2", c3: { d1: "d1" } }) + hash_2 = HashWithIndifferentAccess.new(a: 1, c: { c1: 2, c3: { d2: "d2" } }) + hash_3 = { a: 1, c: { c1: 2, c3: { d2: "d2" } } } expected = { "a" => 1, "b" => "b", "c" => { "c1" => 2, "c2" => "c2", "c3" => { "d1" => "d1", "d2" => "d2" } } } assert_equal expected, hash_1.deep_merge(hash_2) assert_equal expected, hash_1.deep_merge(hash_3) @@ -791,9 +790,9 @@ class HashExtTest < ActiveSupport::TestCase def test_store_on_indifferent_access hash = HashWithIndifferentAccess.new hash.store(:test1, 1) - hash.store('test1', 11) + hash.store("test1", 11) hash[:test2] = 2 - hash['test2'] = 22 + hash["test2"] = 22 expected = { "test1" => 11, "test2" => 22 } assert_equal expected, hash end @@ -801,16 +800,16 @@ class HashExtTest < ActiveSupport::TestCase def test_constructor_on_indifferent_access hash = HashWithIndifferentAccess[:foo, 1] assert_equal 1, hash[:foo] - assert_equal 1, hash['foo'] + assert_equal 1, hash["foo"] hash[:foo] = 3 assert_equal 3, hash[:foo] - assert_equal 3, hash['foo'] + assert_equal 3, hash["foo"] end def test_reverse_merge - defaults = { :a => "x", :b => "y", :c => 10 }.freeze - options = { :a => 1, :b => 2 } - expected = { :a => 1, :b => 2, :c => 10 } + defaults = { a: "x", b: "y", c: 10 }.freeze + options = { a: 1, b: 2 } + expected = { a: 1, b: 2, c: 10 } # Should merge defaults into options, creating a new hash. assert_equal expected, options.reverse_merge(defaults) @@ -828,8 +827,8 @@ class HashExtTest < ActiveSupport::TestCase end def test_slice - original = { :a => 'x', :b => 'y', :c => 10 } - expected = { :a => 'x', :b => 'y' } + original = { a: "x", b: "y", c: 10 } + expected = { a: "x", b: "y" } # Should return a new hash with only the given keys. assert_equal expected, original.slice(:a, :b) @@ -837,15 +836,15 @@ class HashExtTest < ActiveSupport::TestCase end def test_slice_inplace - original = { :a => 'x', :b => 'y', :c => 10 } - expected = { :c => 10 } + original = { a: "x", b: "y", c: 10 } + expected = { c: 10 } # Should replace the hash with only the given keys. assert_equal expected, original.slice!(:a, :b) end def test_slice_with_an_array_key - original = { :a => 'x', :b => 'y', :c => 10, [:a, :b] => "an array key" } + original = { :a => "x", :b => "y", :c => 10, [:a, :b] => "an array key" } expected = { [:a, :b] => "an array key", :c => 10 } # Should return a new hash with only the given keys when given an array key. @@ -854,26 +853,26 @@ class HashExtTest < ActiveSupport::TestCase end def test_slice_inplace_with_an_array_key - original = { :a => 'x', :b => 'y', :c => 10, [:a, :b] => "an array key" } - expected = { :a => 'x', :b => 'y' } + original = { :a => "x", :b => "y", :c => 10, [:a, :b] => "an array key" } + expected = { a: "x", b: "y" } # Should replace the hash with only the given keys when given an array key. assert_equal expected, original.slice!([:a, :b], :c) end def test_slice_with_splatted_keys - original = { :a => 'x', :b => 'y', :c => 10, [:a, :b] => "an array key" } - expected = { :a => 'x', :b => "y" } + original = { :a => "x", :b => "y", :c => 10, [:a, :b] => "an array key" } + expected = { a: "x", b: "y" } # Should grab each of the splatted keys. assert_equal expected, original.slice(*[:a, :b]) end def test_indifferent_slice - original = { :a => 'x', :b => 'y', :c => 10 }.with_indifferent_access - expected = { :a => 'x', :b => 'y' }.with_indifferent_access + original = { a: "x", b: "y", c: 10 }.with_indifferent_access + expected = { a: "x", b: "y" }.with_indifferent_access - [['a', 'b'], [:a, :b]].each do |keys| + [["a", "b"], [:a, :b]].each do |keys| # Should return a new hash with only the given keys. assert_equal expected, original.slice(*keys), keys.inspect assert_not_equal expected, original @@ -881,10 +880,10 @@ class HashExtTest < ActiveSupport::TestCase end def test_indifferent_slice_inplace - original = { :a => 'x', :b => 'y', :c => 10 }.with_indifferent_access - expected = { :c => 10 }.with_indifferent_access + original = { a: "x", b: "y", c: 10 }.with_indifferent_access + expected = { c: 10 }.with_indifferent_access - [['a', 'b'], [:a, :b]].each do |keys| + [["a", "b"], [:a, :b]].each do |keys| # Should replace the hash with only the given keys. copy = original.dup assert_equal expected, copy.slice!(*keys) @@ -892,13 +891,13 @@ class HashExtTest < ActiveSupport::TestCase end def test_indifferent_slice_access_with_symbols - original = {'login' => 'bender', 'password' => 'shiny', 'stuff' => 'foo'} + original = { "login" => "bender", "password" => "shiny", "stuff" => "foo" } original = original.with_indifferent_access slice = original.slice(:login, :password) - assert_equal 'bender', slice[:login] - assert_equal 'bender', slice['login'] + assert_equal "bender", slice[:login] + assert_equal "bender", slice["login"] end def test_slice_bang_does_not_override_default @@ -920,17 +919,17 @@ class HashExtTest < ActiveSupport::TestCase end def test_extract - original = {:a => 1, :b => 2, :c => 3, :d => 4} - expected = {:a => 1, :b => 2} - remaining = {:c => 3, :d => 4} + original = { a: 1, b: 2, c: 3, d: 4 } + expected = { a: 1, b: 2 } + remaining = { c: 3, d: 4 } assert_equal expected, original.extract!(:a, :b, :x) assert_equal remaining, original end def test_extract_nils - original = {:a => nil, :b => nil} - expected = {:a => nil} + original = { a: nil, b: nil } + expected = { a: nil } extracted = original.extract!(:a, :x) assert_equal expected, extracted @@ -939,11 +938,11 @@ class HashExtTest < ActiveSupport::TestCase end def test_indifferent_extract - original = {:a => 1, 'b' => 2, :c => 3, 'd' => 4}.with_indifferent_access - expected = {:a => 1, :b => 2}.with_indifferent_access - remaining = {:c => 3, :d => 4}.with_indifferent_access + original = { :a => 1, "b" => 2, :c => 3, "d" => 4 }.with_indifferent_access + expected = { a: 1, b: 2 }.with_indifferent_access + remaining = { c: 3, d: 4 }.with_indifferent_access - [['a', 'b'], [:a, :b]].each do |keys| + [["a", "b"], [:a, :b]].each do |keys| copy = original.dup assert_equal expected, copy.extract!(*keys) assert_equal remaining, copy @@ -951,8 +950,8 @@ class HashExtTest < ActiveSupport::TestCase end def test_except - original = { :a => 'x', :b => 'y', :c => 10 } - expected = { :a => 'x', :b => 'y' } + original = { a: "x", b: "y", c: 10 } + expected = { a: "x", b: "y" } # Should return a new hash without the given keys. assert_equal expected, original.except(:c) @@ -964,8 +963,8 @@ class HashExtTest < ActiveSupport::TestCase end def test_except_with_more_than_one_argument - original = { :a => 'x', :b => 'y', :c => 10 } - expected = { :a => 'x' } + original = { a: "x", b: "y", c: 10 } + expected = { a: "x" } assert_equal expected, original.except(:b, :c) @@ -974,7 +973,7 @@ class HashExtTest < ActiveSupport::TestCase end def test_except_with_original_frozen - original = { :a => 'x', :b => 'y' } + original = { a: "x", b: "y" } original.freeze assert_nothing_raised { original.except(:a) } @@ -982,7 +981,7 @@ class HashExtTest < ActiveSupport::TestCase end def test_except_does_not_delete_values_in_original - original = { :a => 'x', :b => 'y' } + original = { a: "x", b: "y" } assert_not_called(original, :delete) do original.except(:a) end @@ -1024,7 +1023,7 @@ class HashExtTest < ActiveSupport::TestCase def test_new_with_to_hash_conversion hash = HashWithIndifferentAccess.new(HashByConversion.new(a: 1)) - assert hash.key?('a') + assert hash.key?("a") assert_equal 1, hash[:a] end @@ -1081,10 +1080,10 @@ end class IWriteMyOwnXML def to_xml(options = {}) options[:indent] ||= 2 - xml = options[:builder] ||= Builder::XmlMarkup.new(:indent => options[:indent]) + xml = options[:builder] ||= Builder::XmlMarkup.new(indent: options[:indent]) xml.instruct! unless options[:skip_instruct] xml.level_one do - xml.tag!(:second_level, 'content') + xml.tag!(:second_level, "content") end end end @@ -1097,71 +1096,71 @@ class HashExtToParamTests < ActiveSupport::TestCase end def test_string_hash - assert_equal '', {}.to_param - assert_equal 'hello=world', { :hello => "world" }.to_param - assert_equal 'hello=10', { "hello" => 10 }.to_param - assert_equal 'hello=world&say_bye=true', {:hello => "world", "say_bye" => true}.to_param + assert_equal "", {}.to_param + assert_equal "hello=world", { hello: "world" }.to_param + assert_equal "hello=10", { "hello" => 10 }.to_param + assert_equal "hello=world&say_bye=true", { :hello => "world", "say_bye" => true }.to_param end def test_number_hash - assert_equal '10=20&30=40&50=60', {10 => 20, 30 => 40, 50 => 60}.to_param + assert_equal "10=20&30=40&50=60", { 10 => 20, 30 => 40, 50 => 60 }.to_param end def test_to_param_hash - assert_equal 'custom-1=param-1&custom2-1=param2-1', {ToParam.new('custom') => ToParam.new('param'), ToParam.new('custom2') => ToParam.new('param2')}.to_param + assert_equal "custom-1=param-1&custom2-1=param2-1", { ToParam.new("custom") => ToParam.new("param"), ToParam.new("custom2") => ToParam.new("param2") }.to_param end def test_to_param_hash_escapes_its_keys_and_values - assert_equal 'param+1=A+string+with+%2F+characters+%26+that+should+be+%3F+escaped', { 'param 1' => 'A string with / characters & that should be ? escaped' }.to_param + assert_equal "param+1=A+string+with+%2F+characters+%26+that+should+be+%3F+escaped", { "param 1" => "A string with / characters & that should be ? escaped" }.to_param end def test_to_param_orders_by_key_in_ascending_order - assert_equal 'a=2&b=1&c=0', Hash[*%w(b 1 c 0 a 2)].to_param + assert_equal "a=2&b=1&c=0", Hash[*%w(b 1 c 0 a 2)].to_param end end class HashToXmlTest < ActiveSupport::TestCase def setup - @xml_options = { :root => :person, :skip_instruct => true, :indent => 0 } + @xml_options = { root: :person, skip_instruct: true, indent: 0 } end def test_one_level - xml = { :name => "David", :street => "Paulina" }.to_xml(@xml_options) + xml = { name: "David", street: "Paulina" }.to_xml(@xml_options) assert_equal "<person>", xml.first(8) assert xml.include?(%(<street>Paulina</street>)) assert xml.include?(%(<name>David</name>)) end def test_one_level_dasherize_false - xml = { :name => "David", :street_name => "Paulina" }.to_xml(@xml_options.merge(:dasherize => false)) + xml = { name: "David", street_name: "Paulina" }.to_xml(@xml_options.merge(dasherize: false)) assert_equal "<person>", xml.first(8) assert xml.include?(%(<street_name>Paulina</street_name>)) assert xml.include?(%(<name>David</name>)) end def test_one_level_dasherize_true - xml = { :name => "David", :street_name => "Paulina" }.to_xml(@xml_options.merge(:dasherize => true)) + xml = { name: "David", street_name: "Paulina" }.to_xml(@xml_options.merge(dasherize: true)) assert_equal "<person>", xml.first(8) assert xml.include?(%(<street-name>Paulina</street-name>)) assert xml.include?(%(<name>David</name>)) end def test_one_level_camelize_true - xml = { :name => "David", :street_name => "Paulina" }.to_xml(@xml_options.merge(:camelize => true)) + xml = { name: "David", street_name: "Paulina" }.to_xml(@xml_options.merge(camelize: true)) assert_equal "<Person>", xml.first(8) assert xml.include?(%(<StreetName>Paulina</StreetName>)) assert xml.include?(%(<Name>David</Name>)) end def test_one_level_camelize_lower - xml = { :name => "David", :street_name => "Paulina" }.to_xml(@xml_options.merge(:camelize => :lower)) + xml = { name: "David", street_name: "Paulina" }.to_xml(@xml_options.merge(camelize: :lower)) assert_equal "<person>", xml.first(8) assert xml.include?(%(<streetName>Paulina</streetName>)) assert xml.include?(%(<name>David</name>)) end def test_one_level_with_types - xml = { :name => "David", :street => "Paulina", :age => 26, :age_in_millis => 820497600000, :moved_on => Date.new(2005, 11, 15), :resident => :yes }.to_xml(@xml_options) + xml = { name: "David", street: "Paulina", age: 26, age_in_millis: 820497600000, moved_on: Date.new(2005, 11, 15), resident: :yes }.to_xml(@xml_options) assert_equal "<person>", xml.first(8) assert xml.include?(%(<street>Paulina</street>)) assert xml.include?(%(<name>David</name>)) @@ -1172,7 +1171,7 @@ class HashToXmlTest < ActiveSupport::TestCase end def test_one_level_with_nils - xml = { :name => "David", :street => "Paulina", :age => nil }.to_xml(@xml_options) + xml = { name: "David", street: "Paulina", age: nil }.to_xml(@xml_options) assert_equal "<person>", xml.first(8) assert xml.include?(%(<street>Paulina</street>)) assert xml.include?(%(<name>David</name>)) @@ -1180,7 +1179,7 @@ class HashToXmlTest < ActiveSupport::TestCase end def test_one_level_with_skipping_types - xml = { :name => "David", :street => "Paulina", :age => nil }.to_xml(@xml_options.merge(:skip_types => true)) + xml = { name: "David", street: "Paulina", age: nil }.to_xml(@xml_options.merge(skip_types: true)) assert_equal "<person>", xml.first(8) assert xml.include?(%(<street>Paulina</street>)) assert xml.include?(%(<name>David</name>)) @@ -1188,7 +1187,7 @@ class HashToXmlTest < ActiveSupport::TestCase end def test_one_level_with_yielding - xml = { :name => "David", :street => "Paulina" }.to_xml(@xml_options) do |x| + xml = { name: "David", street: "Paulina" }.to_xml(@xml_options) do |x| x.creator("Rails") end @@ -1199,21 +1198,21 @@ class HashToXmlTest < ActiveSupport::TestCase end def test_two_levels - xml = { :name => "David", :address => { :street => "Paulina" } }.to_xml(@xml_options) + xml = { name: "David", address: { street: "Paulina" } }.to_xml(@xml_options) assert_equal "<person>", xml.first(8) assert xml.include?(%(<address><street>Paulina</street></address>)) assert xml.include?(%(<name>David</name>)) end def test_two_levels_with_second_level_overriding_to_xml - xml = { :name => "David", :address => { :street => "Paulina" }, :child => IWriteMyOwnXML.new }.to_xml(@xml_options) + xml = { name: "David", address: { street: "Paulina" }, child: IWriteMyOwnXML.new }.to_xml(@xml_options) assert_equal "<person>", xml.first(8) assert xml.include?(%(<address><street>Paulina</street></address>)) assert xml.include?(%(<level_one><second_level>content</second_level></level_one>)) end def test_two_levels_with_array - xml = { :name => "David", :addresses => [{ :street => "Paulina" }, { :street => "Evergreen" }] }.to_xml(@xml_options) + xml = { name: "David", addresses: [{ street: "Paulina" }, { street: "Evergreen" }] }.to_xml(@xml_options) assert_equal "<person>", xml.first(8) assert xml.include?(%(<addresses type="array"><address>)) assert xml.include?(%(<address><street>Paulina</street></address>)) @@ -1222,14 +1221,14 @@ class HashToXmlTest < ActiveSupport::TestCase end def test_three_levels_with_array - xml = { :name => "David", :addresses => [{ :streets => [ { :name => "Paulina" }, { :name => "Paulina" } ] } ] }.to_xml(@xml_options) + xml = { name: "David", addresses: [{ streets: [ { name: "Paulina" }, { name: "Paulina" } ] } ] }.to_xml(@xml_options) assert xml.include?(%(<addresses type="array"><address><streets type="array"><street><name>)) end def test_timezoned_attributes xml = { - :created_at => Time.utc(1999,2,2), - :local_created_at => Time.utc(1999,2,2).in_time_zone('Eastern Time (US & Canada)') + created_at: Time.utc(1999,2,2), + local_created_at: Time.utc(1999,2,2).in_time_zone("Eastern Time (US & Canada)") }.to_xml(@xml_options) assert_match %r{<created-at type=\"dateTime\">1999-02-02T00:00:00Z</created-at>}, xml assert_match %r{<local-created-at type=\"dateTime\">1999-02-01T19:00:00-05:00</local-created-at>}, xml @@ -1268,17 +1267,17 @@ class HashToXmlTest < ActiveSupport::TestCase EOT expected_topic_hash = { - :title => "The First Topic", - :author_name => "David", - :id => 1, - :approved => false, - :replies_count => 0, - :replies_close_in => 2592000000, - :written_on => Date.new(2003, 7, 16), - :viewed_at => Time.utc(2003, 7, 16, 9, 28), - :content => "Have a nice day", - :author_email_address => "david@loudthinking.com", - :parent_id => nil + title: "The First Topic", + author_name: "David", + id: 1, + approved: false, + replies_count: 0, + replies_close_in: 2592000000, + written_on: Date.new(2003, 7, 16), + viewed_at: Time.utc(2003, 7, 16, 9, 28), + content: "Have a nice day", + author_email_address: "david@loudthinking.com", + parent_id: nil }.stringify_keys assert_equal expected_topic_hash, Hash.from_xml(topics_xml)["topics"].first @@ -1303,18 +1302,18 @@ class HashToXmlTest < ActiveSupport::TestCase EOT expected_topic_hash = { - :title => "The First Topic", - :author_name => "David", - :id => 1, - :approved => true, - :replies_count => 0, - :replies_close_in => 2592000000, - :written_on => Date.new(2003, 7, 16), - :viewed_at => Time.utc(2003, 7, 16, 9, 28), - :author_email_address => "david@loudthinking.com", - :parent_id => nil, - :ad_revenue => BigDecimal("1.50"), - :optimum_viewing_angle => 135.0, + title: "The First Topic", + author_name: "David", + id: 1, + approved: true, + replies_count: 0, + replies_close_in: 2592000000, + written_on: Date.new(2003, 7, 16), + viewed_at: Time.utc(2003, 7, 16, 9, 28), + author_email_address: "david@loudthinking.com", + parent_id: nil, + ad_revenue: BigDecimal("1.50"), + optimum_viewing_angle: 135.0, }.stringify_keys assert_equal expected_topic_hash, Hash.from_xml(topic_xml)["topic"] @@ -1333,12 +1332,12 @@ class HashToXmlTest < ActiveSupport::TestCase EOT expected_topic_hash = { - :title => nil, - :id => nil, - :approved => nil, - :written_on => nil, - :viewed_at => nil, - :parent_id => nil + title: nil, + id: nil, + approved: nil, + written_on: nil, + viewed_at: nil, + parent_id: nil }.stringify_keys assert_equal expected_topic_hash, Hash.from_xml(topic_xml)["topic"] @@ -1377,17 +1376,17 @@ class HashToXmlTest < ActiveSupport::TestCase EOT expected_topic_hash = { - :title => "The First Topic", - :author_name => "David", - :id => 1, - :approved => false, - :replies_count => 0, - :replies_close_in => 2592000000, - :written_on => Date.new(2003, 7, 16), - :viewed_at => Time.utc(2003, 7, 16, 9, 28), - :content => "Have a nice day", - :author_email_address => "david@loudthinking.com", - :parent_id => nil + title: "The First Topic", + author_name: "David", + id: 1, + approved: false, + replies_count: 0, + replies_close_in: 2592000000, + written_on: Date.new(2003, 7, 16), + viewed_at: Time.utc(2003, 7, 16, 9, 28), + content: "Have a nice day", + author_email_address: "david@loudthinking.com", + parent_id: nil }.stringify_keys assert_equal expected_topic_hash, Hash.from_xml(topics_xml)["topics"].first @@ -1403,14 +1402,14 @@ class HashToXmlTest < ActiveSupport::TestCase EOT expected_topic_hash = { - :id => "175756086", - :owner => "55569174@N00", - :secret => "0279bf37a1", - :server => "76", - :title => "Colored Pencil PhotoBooth Fun", - :ispublic => "1", - :isfriend => "0", - :isfamily => "0", + id: "175756086", + owner: "55569174@N00", + secret: "0279bf37a1", + server: "76", + title: "Colored Pencil PhotoBooth Fun", + ispublic: "1", + isfriend: "0", + isfamily: "0", }.stringify_keys assert_equal expected_topic_hash, Hash.from_xml(topic_xml)["rsp"]["photos"]["photo"] @@ -1438,7 +1437,7 @@ class HashToXmlTest < ActiveSupport::TestCase <posts type="array"></posts> </blog> XML - expected_blog_hash = {"blog" => {"posts" => []}} + expected_blog_hash = { "blog" => { "posts" => [] } } assert_equal expected_blog_hash, Hash.from_xml(blog_xml) end @@ -1449,7 +1448,7 @@ class HashToXmlTest < ActiveSupport::TestCase </posts> </blog> XML - expected_blog_hash = {"blog" => {"posts" => []}} + expected_blog_hash = { "blog" => { "posts" => [] } } assert_equal expected_blog_hash, Hash.from_xml(blog_xml) end @@ -1461,7 +1460,7 @@ class HashToXmlTest < ActiveSupport::TestCase </posts> </blog> XML - expected_blog_hash = {"blog" => {"posts" => ["a post"]}} + expected_blog_hash = { "blog" => { "posts" => ["a post"] } } assert_equal expected_blog_hash, Hash.from_xml(blog_xml) end @@ -1474,7 +1473,7 @@ class HashToXmlTest < ActiveSupport::TestCase </posts> </blog> XML - expected_blog_hash = {"blog" => {"posts" => ["a post", "another post"]}} + expected_blog_hash = { "blog" => { "posts" => ["a post", "another post"] } } assert_equal expected_blog_hash, Hash.from_xml(blog_xml) end @@ -1486,12 +1485,12 @@ class HashToXmlTest < ActiveSupport::TestCase </blog> XML hash = Hash.from_xml(blog_xml) - 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_file_from_xml_with_defaults @@ -1501,9 +1500,9 @@ class HashToXmlTest < ActiveSupport::TestCase </logo> </blog> XML - file = Hash.from_xml(blog_xml)['blog']['logo'] - assert_equal 'untitled', file.original_filename - assert_equal 'application/octet-stream', file.content_type + file = Hash.from_xml(blog_xml)["blog"]["logo"] + assert_equal "untitled", file.original_filename + assert_equal "application/octet-stream", file.content_type end def test_tag_with_attrs_and_whitespace @@ -1512,7 +1511,7 @@ class HashToXmlTest < ActiveSupport::TestCase </blog> XML hash = Hash.from_xml(xml) - assert_equal "bacon is the best", hash['blog']['name'] + assert_equal "bacon is the best", hash["blog"]["name"] end def test_empty_cdata_from_xml @@ -1535,13 +1534,13 @@ class HashToXmlTest < ActiveSupport::TestCase EOT expected_bacon_hash = { - :weight => 0.5, - :chunky => true, - :price => BigDecimal("12.50"), - :expires_at => Time.utc(2007,12,25,12,34,56), - :notes => "", - :illustration => "babe.png", - :caption => "That'll do, pig." + weight: 0.5, + chunky: true, + price: BigDecimal("12.50"), + expires_at: Time.utc(2007,12,25,12,34,56), + notes: "", + illustration: "babe.png", + caption: "That'll do, pig." }.stringify_keys assert_equal expected_bacon_hash, Hash.from_xml(bacon_xml)["bacon"] @@ -1557,8 +1556,8 @@ class HashToXmlTest < ActiveSupport::TestCase EOT expected_product_hash = { - :weight => 0.5, - :image => {'type' => 'ProductImage', 'filename' => 'image.gif' }, + weight: 0.5, + image: { "type" => "ProductImage", "filename" => "image.gif" }, }.stringify_keys assert_equal expected_product_hash, Hash.from_xml(product_xml)["product"] @@ -1581,17 +1580,17 @@ class HashToXmlTest < ActiveSupport::TestCase end def test_from_xml_array_one - expected = { 'numbers' => { 'type' => 'Array', 'value' => '1' }} + 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' ] }} + 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 }} + expected = { "product" => { "name" => :value } } assert_equal expected, Hash.from_trusted_xml('<product><name type="symbol">value</name></product>') assert_equal expected, Hash.from_trusted_xml('<product><name type="yaml">:value</name></product>') end @@ -1654,8 +1653,8 @@ class HashToXmlTest < ActiveSupport::TestCase # The XML builder seems to fail miserably when trying to tag something # with the same name as a Kernel method (throw, test, loop, select ...) def test_kernel_method_names_to_xml - hash = { :throw => { :ball => 'red' } } - expected = '<person><throw><ball>red</ball></throw></person>' + hash = { throw: { ball: "red" } } + expected = "<person><throw><ball>red</ball></throw></person>" assert_nothing_raised do assert_equal expected, hash.to_xml(@xml_options) @@ -1670,30 +1669,30 @@ class HashToXmlTest < ActiveSupport::TestCase def test_escaping_to_xml hash = { - :bare_string => 'First & Last Name', - :pre_escaped_string => 'First & Last Name' + bare_string: "First & Last Name", + pre_escaped_string: "First & Last Name" }.stringify_keys - expected_xml = '<person><bare-string>First & Last Name</bare-string><pre-escaped-string>First &amp; Last Name</pre-escaped-string></person>' + expected_xml = "<person><bare-string>First & Last Name</bare-string><pre-escaped-string>First &amp; Last Name</pre-escaped-string></person>" assert_equal expected_xml, hash.to_xml(@xml_options) end def test_unescaping_from_xml - xml_string = '<person><bare-string>First & Last Name</bare-string><pre-escaped-string>First &amp; Last Name</pre-escaped-string></person>' + xml_string = "<person><bare-string>First & Last Name</bare-string><pre-escaped-string>First &amp; Last Name</pre-escaped-string></person>" expected_hash = { - :bare_string => 'First & Last Name', - :pre_escaped_string => 'First & Last Name' + bare_string: "First & Last Name", + pre_escaped_string: "First & Last Name" }.stringify_keys - assert_equal expected_hash, Hash.from_xml(xml_string)['person'] + assert_equal expected_hash, Hash.from_xml(xml_string)["person"] end def test_roundtrip_to_xml_from_xml hash = { - :bare_string => 'First & Last Name', - :pre_escaped_string => 'First & Last Name' + bare_string: "First & Last Name", + pre_escaped_string: "First & Last Name" }.stringify_keys - assert_equal hash, Hash.from_xml(hash.to_xml(@xml_options))['person'] + assert_equal hash, Hash.from_xml(hash.to_xml(@xml_options))["person"] end def test_datetime_xml_type_with_utc_time @@ -1702,7 +1701,7 @@ class HashToXmlTest < ActiveSupport::TestCase <alert_at type="datetime">2008-02-10T15:30:45Z</alert_at> </alert> XML - alert_at = Hash.from_xml(alert_xml)['alert']['alert_at'] + alert_at = Hash.from_xml(alert_xml)["alert"]["alert_at"] assert alert_at.utc? assert_equal Time.utc(2008, 2, 10, 15, 30, 45), alert_at end @@ -1713,7 +1712,7 @@ class HashToXmlTest < ActiveSupport::TestCase <alert_at type="datetime">2008-02-10T10:30:45-05:00</alert_at> </alert> XML - alert_at = Hash.from_xml(alert_xml)['alert']['alert_at'] + alert_at = Hash.from_xml(alert_xml)["alert"]["alert_at"] assert alert_at.utc? assert_equal Time.utc(2008, 2, 10, 15, 30, 45), alert_at end @@ -1724,7 +1723,7 @@ class HashToXmlTest < ActiveSupport::TestCase <alert_at type="datetime">2050-02-10T15:30:45Z</alert_at> </alert> XML - alert_at = Hash.from_xml(alert_xml)['alert']['alert_at'] + alert_at = Hash.from_xml(alert_xml)["alert"]["alert_at"] assert alert_at.utc? assert_equal 2050, alert_at.year assert_equal 2, alert_at.month @@ -1735,20 +1734,20 @@ class HashToXmlTest < ActiveSupport::TestCase end def test_to_xml_dups_options - options = {:skip_instruct => true} + options = { skip_instruct: true } {}.to_xml(options) # :builder, etc, shouldn't be added to options - assert_equal({:skip_instruct => true}, options) + assert_equal({ skip_instruct: true }, options) end def test_expansion_count_is_limited expected = case ActiveSupport::XmlMini.backend.name - when 'ActiveSupport::XmlMini_REXML'; RuntimeError - when 'ActiveSupport::XmlMini_Nokogiri'; Nokogiri::XML::SyntaxError - when 'ActiveSupport::XmlMini_NokogiriSAX'; RuntimeError - when 'ActiveSupport::XmlMini_LibXML'; LibXML::XML::Error - when 'ActiveSupport::XmlMini_LibXMLSAX'; LibXML::XML::Error + when "ActiveSupport::XmlMini_REXML"; RuntimeError + when "ActiveSupport::XmlMini_Nokogiri"; Nokogiri::XML::SyntaxError + when "ActiveSupport::XmlMini_NokogiriSAX"; RuntimeError + when "ActiveSupport::XmlMini_LibXML"; LibXML::XML::Error + when "ActiveSupport::XmlMini_LibXMLSAX"; LibXML::XML::Error end assert_raise expected do diff --git a/activesupport/test/core_ext/integer_ext_test.rb b/activesupport/test/core_ext/integer_ext_test.rb index 41736fb672..137e8ce85f 100644 --- a/activesupport/test/core_ext/integer_ext_test.rb +++ b/activesupport/test/core_ext/integer_ext_test.rb @@ -1,5 +1,5 @@ -require 'abstract_unit' -require 'active_support/core_ext/integer' +require "abstract_unit" +require "active_support/core_ext/integer" class IntegerExtTest < ActiveSupport::TestCase PRIME = 22953686867719691230002707821868552601124472329079 @@ -19,12 +19,12 @@ class IntegerExtTest < ActiveSupport::TestCase def test_ordinalize # These tests are mostly just to ensure that the ordinalize method exists. # Its results are tested comprehensively in the inflector test cases. - assert_equal '1st', 1.ordinalize - assert_equal '8th', 8.ordinalize + assert_equal "1st", 1.ordinalize + assert_equal "8th", 8.ordinalize end def test_ordinal - assert_equal 'st', 1.ordinal - assert_equal 'th', 8.ordinal + assert_equal "st", 1.ordinal + assert_equal "th", 8.ordinal end end diff --git a/activesupport/test/core_ext/kernel/concern_test.rb b/activesupport/test/core_ext/kernel/concern_test.rb index 478a00d2d2..e7e4f99d7e 100644 --- a/activesupport/test/core_ext/kernel/concern_test.rb +++ b/activesupport/test/core_ext/kernel/concern_test.rb @@ -1,9 +1,9 @@ -require 'abstract_unit' -require 'active_support/core_ext/kernel/concern' +require "abstract_unit" +require "active_support/core_ext/kernel/concern" class KernelConcernTest < ActiveSupport::TestCase def test_may_be_defined_at_toplevel - mod = ::TOPLEVEL_BINDING.eval 'concern(:ToplevelConcern) { }' + mod = ::TOPLEVEL_BINDING.eval "concern(:ToplevelConcern) { }" assert_equal mod, ::ToplevelConcern assert_kind_of ActiveSupport::Concern, ::ToplevelConcern assert_not Object.ancestors.include?(::ToplevelConcern), mod.ancestors.inspect diff --git a/activesupport/test/core_ext/kernel_test.rb b/activesupport/test/core_ext/kernel_test.rb index 503e6595cb..db0008b735 100644 --- a/activesupport/test/core_ext/kernel_test.rb +++ b/activesupport/test/core_ext/kernel_test.rb @@ -1,5 +1,5 @@ -require 'abstract_unit' -require 'active_support/core_ext/kernel' +require "abstract_unit" +require "active_support/core_ext/kernel" class KernelTest < ActiveSupport::TestCase def test_silence_warnings diff --git a/activesupport/test/core_ext/load_error_test.rb b/activesupport/test/core_ext/load_error_test.rb index b2a75a2bcc..b50a35b2cb 100644 --- a/activesupport/test/core_ext/load_error_test.rb +++ b/activesupport/test/core_ext/load_error_test.rb @@ -1,6 +1,5 @@ -require 'abstract_unit' -require 'active_support/core_ext/load_error' - +require "abstract_unit" +require "active_support/core_ext/load_error" class TestMissingSourceFile < ActiveSupport::TestCase def test_it_is_deprecated @@ -15,12 +14,12 @@ class TestLoadError < ActiveSupport::TestCase assert_raise(LoadError) { require 'no_this_file_don\'t_exist' } end def test_with_load - assert_raise(LoadError) { load 'nor_does_this_one' } + assert_raise(LoadError) { load "nor_does_this_one" } end def test_path - begin load 'nor/this/one.rb' + begin load "nor/this/one.rb" rescue LoadError => e - assert_equal 'nor/this/one.rb', e.path + assert_equal "nor/this/one.rb", e.path end end end diff --git a/activesupport/test/core_ext/marshal_test.rb b/activesupport/test/core_ext/marshal_test.rb index 380f64c6fd..a899f98705 100644 --- a/activesupport/test/core_ext/marshal_test.rb +++ b/activesupport/test/core_ext/marshal_test.rb @@ -1,6 +1,6 @@ -require 'abstract_unit' -require 'active_support/core_ext/marshal' -require 'dependencies_test_helpers' +require "abstract_unit" +require "active_support/core_ext/marshal" +require "dependencies_test_helpers" class MarshalTest < ActiveSupport::TestCase include ActiveSupport::Testing::Isolation @@ -12,7 +12,7 @@ class MarshalTest < ActiveSupport::TestCase end test "that Marshal#load still works" do - sanity_data = ["test", [1, 2, 3], {a: [1, 2, 3]}, ActiveSupport::TestCase] + sanity_data = ["test", [1, 2, 3], { a: [1, 2, 3] }, ActiveSupport::TestCase] sanity_data.each do |obj| dumped = Marshal.dump(obj) assert_equal Marshal.method(:load).super_method.call(dumped), Marshal.load(dumped) diff --git a/activesupport/test/core_ext/module/anonymous_test.rb b/activesupport/test/core_ext/module/anonymous_test.rb index cb556af772..f885444284 100644 --- a/activesupport/test/core_ext/module/anonymous_test.rb +++ b/activesupport/test/core_ext/module/anonymous_test.rb @@ -1,5 +1,5 @@ -require 'abstract_unit' -require 'active_support/core_ext/module/anonymous' +require "abstract_unit" +require "active_support/core_ext/module/anonymous" class AnonymousTest < ActiveSupport::TestCase test "an anonymous class or module are anonymous" do @@ -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/attr_internal_test.rb b/activesupport/test/core_ext/module/attr_internal_test.rb index 2aea14cf2b..8458e278ee 100644 --- a/activesupport/test/core_ext/module/attr_internal_test.rb +++ b/activesupport/test/core_ext/module/attr_internal_test.rb @@ -1,5 +1,5 @@ -require 'abstract_unit' -require 'active_support/core_ext/module/attr_internal' +require "abstract_unit" +require "active_support/core_ext/module/attr_internal" class AttrInternalTest < ActiveSupport::TestCase def setup @@ -10,44 +10,44 @@ class AttrInternalTest < ActiveSupport::TestCase def test_reader assert_nothing_raised { @target.attr_internal_reader :foo } - assert !@instance.instance_variable_defined?('@_foo') + assert !@instance.instance_variable_defined?("@_foo") assert_raise(NoMethodError) { @instance.foo = 1 } - @instance.instance_variable_set('@_foo', 1) + @instance.instance_variable_set("@_foo", 1) assert_nothing_raised { assert_equal 1, @instance.foo } end def test_writer assert_nothing_raised { @target.attr_internal_writer :foo } - assert !@instance.instance_variable_defined?('@_foo') + assert !@instance.instance_variable_defined?("@_foo") assert_nothing_raised { assert_equal 1, @instance.foo = 1 } - assert_equal 1, @instance.instance_variable_get('@_foo') + assert_equal 1, @instance.instance_variable_get("@_foo") assert_raise(NoMethodError) { @instance.foo } end def test_accessor assert_nothing_raised { @target.attr_internal :foo } - assert !@instance.instance_variable_defined?('@_foo') + assert !@instance.instance_variable_defined?("@_foo") assert_nothing_raised { assert_equal 1, @instance.foo = 1 } - assert_equal 1, @instance.instance_variable_get('@_foo') + assert_equal 1, @instance.instance_variable_get("@_foo") assert_nothing_raised { assert_equal 1, @instance.foo } end def test_naming_format - assert_equal '@_%s', Module.attr_internal_naming_format - assert_nothing_raised { Module.attr_internal_naming_format = '@abc%sdef' } + assert_equal "@_%s", Module.attr_internal_naming_format + assert_nothing_raised { Module.attr_internal_naming_format = "@abc%sdef" } @target.attr_internal :foo - assert !@instance.instance_variable_defined?('@_foo') - assert !@instance.instance_variable_defined?('@abcfoodef') + assert !@instance.instance_variable_defined?("@_foo") + assert !@instance.instance_variable_defined?("@abcfoodef") assert_nothing_raised { @instance.foo = 1 } - assert !@instance.instance_variable_defined?('@_foo') - assert @instance.instance_variable_defined?('@abcfoodef') + assert !@instance.instance_variable_defined?("@_foo") + assert @instance.instance_variable_defined?("@abcfoodef") ensure - Module.attr_internal_naming_format = '@_%s' + Module.attr_internal_naming_format = "@_%s" end 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 a9fd878b80..b816fa50e3 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 @@ -1,5 +1,5 @@ -require 'abstract_unit' -require 'active_support/core_ext/module/attribute_accessors_per_thread' +require "abstract_unit" +require "active_support/core_ext/module/attribute_accessors_per_thread" class ModuleAttributeAccessorPerThreadTest < ActiveSupport::TestCase def setup @@ -8,6 +8,12 @@ class ModuleAttributeAccessorPerThreadTest < ActiveSupport::TestCase thread_mattr_accessor :bar, instance_writer: false thread_mattr_reader :shaq, instance_reader: false thread_mattr_accessor :camp, instance_accessor: false + + def self.name; "MyClass" end + end + + @subclass = Class.new(@class) do + def self.name; "SubMyClass" end end @object = @class.new @@ -57,23 +63,23 @@ class ModuleAttributeAccessorPerThreadTest < ActiveSupport::TestCase def test_values_should_not_bleed_between_threads threads = [] threads << Thread.new do - @class.foo = 'things' + @class.foo = "things" sleep 1 - assert_equal 'things', @class.foo + assert_equal "things", @class.foo end threads << Thread.new do - @class.foo = 'other things' + @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' + @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 @@ -108,8 +114,18 @@ class ModuleAttributeAccessorPerThreadTest < ActiveSupport::TestCase end def test_should_return_same_value_by_class_or_instance_accessor - @class.foo = 'fries' + @class.foo = "fries" assert_equal @class.foo, @object.foo end + + def test_should_not_affect_superclass_if_subclass_set_value + @class.foo = "super" + assert_equal @class.foo, "super" + assert_nil @subclass.foo + + @subclass.foo = "sub" + assert_equal @class.foo, "super" + assert_equal @subclass.foo, "sub" + end end diff --git a/activesupport/test/core_ext/module/attribute_accessor_test.rb b/activesupport/test/core_ext/module/attribute_accessor_test.rb index 0b0f3a2808..464a000d59 100644 --- a/activesupport/test/core_ext/module/attribute_accessor_test.rb +++ b/activesupport/test/core_ext/module/attribute_accessor_test.rb @@ -1,17 +1,17 @@ -require 'abstract_unit' -require 'active_support/core_ext/module/attribute_accessors' +require "abstract_unit" +require "active_support/core_ext/module/attribute_accessors" class ModuleAttributeAccessorTest < ActiveSupport::TestCase def setup m = @module = Module.new do mattr_accessor :foo - mattr_accessor :bar, :instance_writer => false - mattr_reader :shaq, :instance_reader => false - mattr_accessor :camp, :instance_accessor => false + mattr_accessor :bar, instance_writer: false + mattr_reader :shaq, instance_reader: false + mattr_accessor :camp, instance_accessor: false - cattr_accessor(:defa) { 'default_accessor_value' } - cattr_reader(:defr) { 'default_reader_value' } - cattr_writer(:defw) { 'default_writer_value' } + cattr_accessor(:defa) { "default_accessor_value" } + cattr_reader(:defr) { "default_reader_value" } + cattr_writer(:defw) { "default_writer_value" } cattr_accessor(:quux) { :quux } end @class = Class.new @@ -86,14 +86,14 @@ class ModuleAttributeAccessorTest < ActiveSupport::TestCase end def test_should_use_default_value_if_block_passed - assert_equal 'default_accessor_value', @module.defa - assert_equal 'default_reader_value', @module.defr - assert_equal 'default_writer_value', @module.class_variable_get('@@defw') + assert_equal "default_accessor_value", @module.defa + assert_equal "default_reader_value", @module.defr + assert_equal "default_writer_value", @module.class_variable_get("@@defw") end def test_should_not_invoke_default_value_block_multiple_times count = 0 - @module.cattr_accessor(:defcount){ count += 1 } + @module.cattr_accessor(:defcount) { count += 1 } assert_equal 1, count end end diff --git a/activesupport/test/core_ext/module/attribute_aliasing_test.rb b/activesupport/test/core_ext/module/attribute_aliasing_test.rb index 29c3053b47..d8c2dfd6b8 100644 --- a/activesupport/test/core_ext/module/attribute_aliasing_test.rb +++ b/activesupport/test/core_ext/module/attribute_aliasing_test.rb @@ -1,5 +1,5 @@ -require 'abstract_unit' -require 'active_support/core_ext/module/aliasing' +require "abstract_unit" +require "active_support/core_ext/module/aliasing" module AttributeAliasing class Content diff --git a/activesupport/test/core_ext/module/concerning_test.rb b/activesupport/test/core_ext/module/concerning_test.rb index 07d860b71c..038cbf1f2f 100644 --- a/activesupport/test/core_ext/module/concerning_test.rb +++ b/activesupport/test/core_ext/module/concerning_test.rb @@ -1,9 +1,9 @@ -require 'abstract_unit' -require 'active_support/core_ext/module/concerning' +require "abstract_unit" +require "active_support/core_ext/module/concerning" class ModuleConcerningTest < ActiveSupport::TestCase def test_concerning_declares_a_concern_and_includes_it_immediately - klass = Class.new { concerning(:Foo) { } } + klass = Class.new { concerning(:Foo) {} } assert klass.ancestors.include?(klass::Foo), klass.ancestors.inspect end end @@ -24,10 +24,10 @@ class ModuleConcernTest < ActiveSupport::TestCase assert !klass.ancestors.include?(klass::Baz), klass.ancestors.inspect # Public method visibility by default - assert klass::Baz.public_instance_methods.map(&:to_s).include?('should_be_public') + assert klass::Baz.public_instance_methods.map(&:to_s).include?("should_be_public") # Calls included hook - assert_equal 1, Class.new { include klass::Baz }.instance_variable_get('@foo') + assert_equal 1, Class.new { include klass::Baz }.instance_variable_get("@foo") end class Foo diff --git a/activesupport/test/core_ext/module/qualified_const_test.rb b/activesupport/test/core_ext/module/qualified_const_test.rb index a3146cabe1..418bc80ab9 100644 --- a/activesupport/test/core_ext/module/qualified_const_test.rb +++ b/activesupport/test/core_ext/module/qualified_const_test.rb @@ -1,5 +1,5 @@ -require 'abstract_unit' -require 'active_support/core_ext/module/qualified_const' +require "abstract_unit" +require "active_support/core_ext/module/qualified_const" module QualifiedConstTestMod X = false @@ -68,7 +68,7 @@ class QualifiedConstTest < ActiveSupport::TestCase assert_equal 1, QualifiedConstTestMod.qualified_const_get("N::X") assert_equal 2, QualifiedConstTestMod.qualified_const_get("M::C::X") - assert_raise(NameError) { QualifiedConstTestMod.qualified_const_get("M::C::Y")} + assert_raise(NameError) { QualifiedConstTestMod.qualified_const_get("M::C::Y") } end end @@ -89,8 +89,8 @@ class QualifiedConstTest < ActiveSupport::TestCase end ensure silence_warnings do - QualifiedConstTestMod.qualified_const_set('QualifiedConstTestMod::X', false) - QualifiedConstTestMod::M.qualified_const_set('X', 1) + QualifiedConstTestMod.qualified_const_set("QualifiedConstTestMod::X", false) + QualifiedConstTestMod::M.qualified_const_set("X", 1) end end end @@ -98,21 +98,21 @@ class QualifiedConstTest < ActiveSupport::TestCase test "reject absolute paths" do assert_deprecated do - assert_raise_with_message(NameError, "wrong constant name ::X") { Object.qualified_const_defined?("::X")} - assert_raise_with_message(NameError, "wrong constant name ::X") { Object.qualified_const_defined?("::X::Y")} + assert_raise_with_message(NameError, "wrong constant name ::X") { Object.qualified_const_defined?("::X") } + assert_raise_with_message(NameError, "wrong constant name ::X") { Object.qualified_const_defined?("::X::Y") } - assert_raise_with_message(NameError, "wrong constant name ::X") { Object.qualified_const_get("::X")} - assert_raise_with_message(NameError, "wrong constant name ::X") { Object.qualified_const_get("::X::Y")} + assert_raise_with_message(NameError, "wrong constant name ::X") { Object.qualified_const_get("::X") } + assert_raise_with_message(NameError, "wrong constant name ::X") { Object.qualified_const_get("::X::Y") } - assert_raise_with_message(NameError, "wrong constant name ::X") { Object.qualified_const_set("::X", nil)} - assert_raise_with_message(NameError, "wrong constant name ::X") { Object.qualified_const_set("::X::Y", nil)} + assert_raise_with_message(NameError, "wrong constant name ::X") { Object.qualified_const_set("::X", nil) } + assert_raise_with_message(NameError, "wrong constant name ::X") { Object.qualified_const_set("::X::Y", nil) } end end 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 80eb31a5c4..487c7dee16 100644 --- a/activesupport/test/core_ext/module/reachable_test.rb +++ b/activesupport/test/core_ext/module/reachable_test.rb @@ -1,5 +1,5 @@ -require 'abstract_unit' -require 'active_support/core_ext/module/reachable' +require "abstract_unit" +require "active_support/core_ext/module/reachable" class AnonymousTest < ActiveSupport::TestCase test "an anonymous class or module is not reachable" do @@ -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/remove_method_test.rb b/activesupport/test/core_ext/module/remove_method_test.rb index 0d684dc70e..0c627f1e74 100644 --- a/activesupport/test/core_ext/module/remove_method_test.rb +++ b/activesupport/test/core_ext/module/remove_method_test.rb @@ -1,5 +1,5 @@ -require 'abstract_unit' -require 'active_support/core_ext/module/remove_method' +require "abstract_unit" +require "active_support/core_ext/module/remove_method" module RemoveMethodTests class A @@ -26,26 +26,25 @@ module RemoveMethodTests end class RemoveMethodTest < ActiveSupport::TestCase - def test_remove_method_from_an_object - RemoveMethodTests::A.class_eval{ - self.remove_possible_method(:do_something) + RemoveMethodTests::A.class_eval { + remove_possible_method(:do_something) } assert !RemoveMethodTests::A.new.respond_to?(:do_something) end def test_remove_singleton_method_from_an_object - RemoveMethodTests::A.class_eval{ - self.remove_possible_singleton_method(:do_something_else) + RemoveMethodTests::A.class_eval { + remove_possible_singleton_method(:do_something_else) } assert !RemoveMethodTests::A.respond_to?(:do_something_else) end def test_redefine_method_in_an_object - RemoveMethodTests::A.class_eval{ - self.redefine_method(:do_something) { return 100 } - self.redefine_method(:do_something_protected) { return 100 } - self.redefine_method(:do_something_private) { return 100 } + RemoveMethodTests::A.class_eval { + redefine_method(:do_something) { return 100 } + redefine_method(:do_something_protected) { return 100 } + redefine_method(:do_something_private) { return 100 } } assert_equal 100, RemoveMethodTests::A.new.do_something assert_equal 100, RemoveMethodTests::A.new.send(:do_something_protected) @@ -55,5 +54,4 @@ class RemoveMethodTest < ActiveSupport::TestCase assert RemoveMethodTests::A.protected_method_defined? :do_something_protected assert RemoveMethodTests::A.private_method_defined? :do_something_private end - end diff --git a/activesupport/test/core_ext/module_test.rb b/activesupport/test/core_ext/module_test.rb index 566f29b470..36073b28b7 100644 --- a/activesupport/test/core_ext/module_test.rb +++ b/activesupport/test/core_ext/module_test.rb @@ -1,5 +1,5 @@ -require 'abstract_unit' -require 'active_support/core_ext/module' +require "abstract_unit" +require "active_support/core_ext/module" module One Constant1 = "Hello World" @@ -25,56 +25,56 @@ Somewhere = Struct.new(:street, :city) do end class Someone < Struct.new(:name, :place) - delegate :street, :city, :to_f, :to => :place - delegate :name=, :to => :place, :prefix => true - delegate :upcase, :to => "place.city" - delegate :table_name, :to => :class - delegate :table_name, :to => :class, :prefix => true + delegate :street, :city, :to_f, to: :place + delegate :name=, to: :place, prefix: true + delegate :upcase, to: "place.city" + delegate :table_name, to: :class + delegate :table_name, to: :class, prefix: true def self.table_name - 'some_table' + "some_table" end FAILED_DELEGATE_LINE = __LINE__ + 1 - delegate :foo, :to => :place + delegate :foo, to: :place FAILED_DELEGATE_LINE_2 = __LINE__ + 1 - delegate :bar, :to => :place, :allow_nil => true + delegate :bar, to: :place, allow_nil: true private - def private_name - "Private" - end + def private_name + "Private" + end end Invoice = Struct.new(:client) do - delegate :street, :city, :name, :to => :client, :prefix => true - delegate :street, :city, :name, :to => :client, :prefix => :customer + delegate :street, :city, :name, to: :client, prefix: true + delegate :street, :city, :name, to: :client, prefix: :customer end Project = Struct.new(:description, :person) do - delegate :name, :to => :person, :allow_nil => true - delegate :to_f, :to => :description, :allow_nil => true + delegate :name, to: :person, allow_nil: true + delegate :to_f, to: :description, allow_nil: true end Developer = Struct.new(:client) do - delegate :name, :to => :client, :prefix => nil + delegate :name, to: :client, prefix: nil end Event = Struct.new(:case) do - delegate :foo, :to => :case + delegate :foo, to: :case end Tester = Struct.new(:client) do - delegate :name, :to => :client, :prefix => false + delegate :name, to: :client, prefix: false def foo; 1; end end Product = Struct.new(:name) do - delegate :name, :to => :manufacturer, :prefix => true - delegate :name, :to => :type, :prefix => true + delegate :name, to: :manufacturer, prefix: true + delegate :name, to: :type, prefix: true def manufacturer @manufacturer ||= begin @@ -114,15 +114,15 @@ HasBlock = Struct.new(:block) do end class ParameterSet - delegate :[], :[]=, :to => :@params + delegate :[], :[]=, to: :@params def initialize - @params = {:foo => "bar"} + @params = { foo: "bar" } end end class Name - delegate :upcase, :to => :@full_name + delegate :upcase, to: :@full_name def initialize(first, last) @full_name = "#{first} #{last}" @@ -132,8 +132,8 @@ end class SideEffect attr_reader :ints - delegate :to_i, :to => :shift, :allow_nil => true - delegate :to_s, :to => :shift + delegate :to_i, to: :shift, allow_nil: true + delegate :to_s, to: :shift def initialize @ints = [1, 2, 3] @@ -180,8 +180,8 @@ class ModuleTest < ActiveSupport::TestCase end def test_delegation_to_class_method - assert_equal 'some_table', @david.table_name - assert_equal 'some_table', @david.class_table_name + assert_equal "some_table", @david.table_name + assert_equal "some_table", @david.class_table_name end def test_missing_delegation_target @@ -189,7 +189,7 @@ class ModuleTest < ActiveSupport::TestCase Name.send :delegate, :nowhere end assert_raise(ArgumentError) do - Name.send :delegate, :noplace, :tos => :hollywood + Name.send :delegate, :noplace, tos: :hollywood end end @@ -233,7 +233,7 @@ class ModuleTest < ActiveSupport::TestCase def initialize(client) @client = client end - delegate :name, :address, :to => :@client, :prefix => true + delegate :name, :address, to: :@client, prefix: true end end end @@ -261,7 +261,7 @@ class ModuleTest < ActiveSupport::TestCase def test_delegation_with_allow_nil_and_nil_value_and_prefix Project.class_eval do - delegate :name, :to => :person, :allow_nil => true, :prefix => true + delegate :name, to: :person, allow_nil: true, prefix: true end rails = Project.new("Rails") assert_nil rails.person_name @@ -290,7 +290,7 @@ class ModuleTest < ActiveSupport::TestCase assert_nothing_raised do Class.new(parent) do class << self - delegate :parent_method, :to => :superclass + delegate :parent_method, to: :superclass end end end @@ -312,7 +312,7 @@ class ModuleTest < ActiveSupport::TestCase rescue NoMethodError => e file_and_line = "#{__FILE__}:#{Someone::FAILED_DELEGATE_LINE}" # We can't simply check the first line of the backtrace, because JRuby reports the call to __send__ in the backtrace. - assert e.backtrace.any?{|a| a.include?(file_and_line)}, + assert e.backtrace.any? { |a| a.include?(file_and_line) }, "[#{e.backtrace.inspect}] did not include [#{file_and_line}]" end @@ -322,7 +322,7 @@ class ModuleTest < ActiveSupport::TestCase rescue NoMethodError => e file_and_line = "#{__FILE__}:#{Someone::FAILED_DELEGATE_LINE_2}" # We can't simply check the first line of the backtrace, because JRuby reports the call to __send__ in the backtrace. - assert e.backtrace.any?{|a| a.include?(file_and_line)}, + assert e.backtrace.any? { |a| a.include?(file_and_line) }, "[#{e.backtrace.inspect}] did not include [#{file_and_line}]" end @@ -332,12 +332,12 @@ class ModuleTest < ActiveSupport::TestCase assert_equal 1, se.to_i assert_equal [2, 3], se.ints - assert_equal '2', se.to_s + assert_equal "2", se.to_s assert_equal [3], se.ints end def test_delegation_doesnt_mask_nested_no_method_error_on_nil_receiver - product = Product.new('Widget') + product = Product.new("Widget") # Nested NoMethodError is a different name from the delegation assert_raise(NoMethodError) { product.manufacturer_name } @@ -408,11 +408,11 @@ end module BarMethods def bar_with_baz - bar_without_baz << '_with_baz' + bar_without_baz << "_with_baz" end def quux_with_baz! - quux_without_baz! << '_with_baz' + quux_without_baz! << "_with_baz" end def quux_with_baz? @@ -420,17 +420,17 @@ module BarMethods end def quux_with_baz=(v) - send(:quux_without_baz=, v) << '_with_baz' + send(:quux_without_baz=, v) << "_with_baz" end def duck_with_orange - duck_without_orange << '_with_orange' + duck_without_orange << "_with_orange" end end class MethodAliasingTest < ActiveSupport::TestCase def setup - Object.const_set :FooClassWithBarMethod, Class.new { def bar() 'bar' end } + Object.const_set :FooClassWithBarMethod, Class.new { def bar() "bar" end } @instance = FooClassWithBarMethod.new end @@ -461,7 +461,7 @@ class MethodAliasingTest < ActiveSupport::TestCase assert !@instance.respond_to?(method) end - assert_equal 'bar', @instance.bar + assert_equal "bar", @instance.bar FooClassWithBarMethod.class_eval { include BarMethodAliaser } @@ -469,15 +469,15 @@ class MethodAliasingTest < ActiveSupport::TestCase assert_respond_to @instance, method end - assert_equal 'bar_with_baz', @instance.bar - assert_equal 'bar', @instance.bar_without_baz + assert_equal "bar_with_baz", @instance.bar + assert_equal "bar", @instance.bar_without_baz end end def test_alias_method_chain_with_punctuation_method assert_deprecated(/alias_method_chain/) do FooClassWithBarMethod.class_eval do - def quux!; 'quux' end + def quux!; "quux" end end assert !@instance.respond_to?(:quux_with_baz!) @@ -487,17 +487,17 @@ class MethodAliasingTest < ActiveSupport::TestCase end assert_respond_to @instance, :quux_with_baz! - assert_equal 'quux_with_baz', @instance.quux! - assert_equal 'quux', @instance.quux_without_baz! + assert_equal "quux_with_baz", @instance.quux! + assert_equal "quux", @instance.quux_without_baz! end end def test_alias_method_chain_with_same_names_between_predicates_and_bang_methods assert_deprecated(/alias_method_chain/) do FooClassWithBarMethod.class_eval do - def quux!; 'quux!' end + def quux!; "quux!" end def quux?; true end - def quux=(v); 'quux=' end + def quux=(v); "quux=" end end assert !@instance.respond_to?(:quux_with_baz!) @@ -509,32 +509,31 @@ class MethodAliasingTest < ActiveSupport::TestCase assert_respond_to @instance, :quux_with_baz? assert_respond_to @instance, :quux_with_baz= - FooClassWithBarMethod.alias_method_chain :quux!, :baz - assert_equal 'quux!_with_baz', @instance.quux! - assert_equal 'quux!', @instance.quux_without_baz! + assert_equal "quux!_with_baz", @instance.quux! + assert_equal "quux!", @instance.quux_without_baz! FooClassWithBarMethod.alias_method_chain :quux?, :baz assert_equal false, @instance.quux? assert_equal true, @instance.quux_without_baz? FooClassWithBarMethod.alias_method_chain :quux=, :baz - assert_equal 'quux=_with_baz', @instance.send(:quux=, 1234) - assert_equal 'quux=', @instance.send(:quux_without_baz=, 1234) + assert_equal "quux=_with_baz", @instance.send(:quux=, 1234) + assert_equal "quux=", @instance.send(:quux_without_baz=, 1234) end end def test_alias_method_chain_with_feature_punctuation assert_deprecated(/alias_method_chain/) do FooClassWithBarMethod.class_eval do - def quux; 'quux' end - def quux?; 'quux?' end + def quux; "quux" end + def quux?; "quux?" end include BarMethodAliaser alias_method_chain :quux, :baz! end assert_nothing_raised do - assert_equal 'quux_with_baz', @instance.quux_with_baz! + assert_equal "quux_with_baz", @instance.quux_with_baz! end assert_raise(NameError) do @@ -557,15 +556,15 @@ class MethodAliasingTest < ActiveSupport::TestCase end assert_not_nil args - assert_equal 'quux', args[0] - assert_equal '?', args[1] + assert_equal "quux", args[0] + assert_equal "?", args[1] end end def test_alias_method_chain_preserves_private_method_status assert_deprecated(/alias_method_chain/) do FooClassWithBarMethod.class_eval do - def duck; 'duck' end + def duck; "duck" end include BarMethodAliaser private :duck alias_method_chain :duck, :orange @@ -575,7 +574,7 @@ class MethodAliasingTest < ActiveSupport::TestCase @instance.duck end - assert_equal 'duck_with_orange', @instance.instance_eval { duck } + assert_equal "duck_with_orange", @instance.instance_eval { duck } assert FooClassWithBarMethod.private_method_defined?(:duck) end end @@ -583,7 +582,7 @@ class MethodAliasingTest < ActiveSupport::TestCase def test_alias_method_chain_preserves_protected_method_status assert_deprecated(/alias_method_chain/) do FooClassWithBarMethod.class_eval do - def duck; 'duck' end + def duck; "duck" end include BarMethodAliaser protected :duck alias_method_chain :duck, :orange @@ -593,7 +592,7 @@ class MethodAliasingTest < ActiveSupport::TestCase @instance.duck end - assert_equal 'duck_with_orange', @instance.instance_eval { duck } + assert_equal "duck_with_orange", @instance.instance_eval { duck } assert FooClassWithBarMethod.protected_method_defined?(:duck) end end @@ -601,13 +600,13 @@ class MethodAliasingTest < ActiveSupport::TestCase def test_alias_method_chain_preserves_public_method_status assert_deprecated(/alias_method_chain/) do FooClassWithBarMethod.class_eval do - def duck; 'duck' end + def duck; "duck" end include BarMethodAliaser public :duck alias_method_chain :duck, :orange end - assert_equal 'duck_with_orange', @instance.duck + assert_equal "duck_with_orange", @instance.duck assert FooClassWithBarMethod.public_method_defined?(:duck) end end diff --git a/activesupport/test/core_ext/name_error_test.rb b/activesupport/test/core_ext/name_error_test.rb index 7525f80cf0..fdb9493d3c 100644 --- a/activesupport/test/core_ext/name_error_test.rb +++ b/activesupport/test/core_ext/name_error_test.rb @@ -1,5 +1,5 @@ -require 'abstract_unit' -require 'active_support/core_ext/name_error' +require "abstract_unit" +require "active_support/core_ext/name_error" class NameErrorTest < ActiveSupport::TestCase def test_name_error_should_set_missing_name diff --git a/activesupport/test/core_ext/numeric_ext_test.rb b/activesupport/test/core_ext/numeric_ext_test.rb index 69c30a8a9e..5e824747ed 100644 --- a/activesupport/test/core_ext/numeric_ext_test.rb +++ b/activesupport/test/core_ext/numeric_ext_test.rb @@ -1,7 +1,7 @@ -require 'abstract_unit' -require 'active_support/time' -require 'active_support/core_ext/numeric' -require 'active_support/core_ext/integer' +require "abstract_unit" +require "active_support/time" +require "active_support/core_ext/numeric" +require "active_support/core_ext/integer" class NumericExtTimeAndDateTimeTest < ActiveSupport::TestCase def setup @@ -23,41 +23,41 @@ class NumericExtTimeAndDateTimeTest < ActiveSupport::TestCase end def test_irregular_durations - assert_equal @now.advance(:days => 3000), 3000.days.since(@now) - assert_equal @now.advance(:months => 1), 1.month.since(@now) - assert_equal @now.advance(:months => -1), 1.month.until(@now) - assert_equal @now.advance(:years => 20), 20.years.since(@now) - assert_equal @dtnow.advance(:days => 3000), 3000.days.since(@dtnow) - assert_equal @dtnow.advance(:months => 1), 1.month.since(@dtnow) - assert_equal @dtnow.advance(:months => -1), 1.month.until(@dtnow) - assert_equal @dtnow.advance(:years => 20), 20.years.since(@dtnow) + assert_equal @now.advance(days: 3000), 3000.days.since(@now) + assert_equal @now.advance(months: 1), 1.month.since(@now) + assert_equal @now.advance(months: -1), 1.month.until(@now) + assert_equal @now.advance(years: 20), 20.years.since(@now) + assert_equal @dtnow.advance(days: 3000), 3000.days.since(@dtnow) + assert_equal @dtnow.advance(months: 1), 1.month.since(@dtnow) + assert_equal @dtnow.advance(months: -1), 1.month.until(@dtnow) + assert_equal @dtnow.advance(years: 20), 20.years.since(@dtnow) end def test_duration_addition - assert_equal @now.advance(:days => 1).advance(:months => 1), (1.day + 1.month).since(@now) - assert_equal @now.advance(:days => 7), (1.week + 5.seconds - 5.seconds).since(@now) - assert_equal @now.advance(:years => 2), (4.years - 2.years).since(@now) - assert_equal @dtnow.advance(:days => 1).advance(:months => 1), (1.day + 1.month).since(@dtnow) - assert_equal @dtnow.advance(:days => 7), (1.week + 5.seconds - 5.seconds).since(@dtnow) - assert_equal @dtnow.advance(:years => 2), (4.years - 2.years).since(@dtnow) + assert_equal @now.advance(days: 1).advance(months: 1), (1.day + 1.month).since(@now) + assert_equal @now.advance(days: 7), (1.week + 5.seconds - 5.seconds).since(@now) + assert_equal @now.advance(years: 2), (4.years - 2.years).since(@now) + assert_equal @dtnow.advance(days: 1).advance(months: 1), (1.day + 1.month).since(@dtnow) + assert_equal @dtnow.advance(days: 7), (1.week + 5.seconds - 5.seconds).since(@dtnow) + assert_equal @dtnow.advance(years: 2), (4.years - 2.years).since(@dtnow) end def test_time_plus_duration assert_equal @now + 8, @now + 8.seconds assert_equal @now + 22.9, @now + 22.9.seconds - assert_equal @now.advance(:days => 15), @now + 15.days - assert_equal @now.advance(:months => 1), @now + 1.month + assert_equal @now.advance(days: 15), @now + 15.days + assert_equal @now.advance(months: 1), @now + 1.month assert_equal @dtnow.since(8), @dtnow + 8.seconds assert_equal @dtnow.since(22.9), @dtnow + 22.9.seconds - assert_equal @dtnow.advance(:days => 15), @dtnow + 15.days - assert_equal @dtnow.advance(:months => 1), @dtnow + 1.month + assert_equal @dtnow.advance(days: 15), @dtnow + 15.days + assert_equal @dtnow.advance(months: 1), @dtnow + 1.month end def test_chaining_duration_operations - assert_equal @now.advance(:days => 2).advance(:months => -3), @now + 2.days - 3.months - assert_equal @now.advance(:days => 1).advance(:months => 2), @now + 1.day + 2.months - assert_equal @dtnow.advance(:days => 2).advance(:months => -3), @dtnow + 2.days - 3.months - assert_equal @dtnow.advance(:days => 1).advance(:months => 2), @dtnow + 1.day + 2.months + assert_equal @now.advance(days: 2).advance(months: -3), @now + 2.days - 3.months + assert_equal @now.advance(days: 1).advance(months: 2), @now + 1.day + 2.months + assert_equal @dtnow.advance(days: 2).advance(months: -3), @dtnow + 2.days - 3.months + assert_equal @dtnow.advance(days: 1).advance(months: 2), @dtnow + 1.day + 2.months end def test_duration_after_conversion_is_no_longer_accurate @@ -87,8 +87,8 @@ class NumericExtDateTest < ActiveSupport::TestCase end def test_chaining_duration_operations - assert_equal @today.advance(:days => 2).advance(:months => -3), @today + 2.days - 3.months - assert_equal @today.advance(:days => 1).advance(:months => 2), @today + 1.day + 2.months + assert_equal @today.advance(days: 2).advance(months: -3), @today + 2.days - 3.months + assert_equal @today.advance(days: 1).advance(months: 2), @today + 1.day + 2.months end def test_add_one_year_to_leap_day @@ -154,53 +154,52 @@ class NumericExtFormattingTest < ActiveSupport::TestCase def test_to_s__phone assert_equal("555-1234", 5551234.to_s(:phone)) assert_equal("800-555-1212", 8005551212.to_s(:phone)) - assert_equal("(800) 555-1212", 8005551212.to_s(:phone, :area_code => true)) - assert_equal("800 555 1212", 8005551212.to_s(:phone, :delimiter => " ")) - assert_equal("(800) 555-1212 x 123", 8005551212.to_s(:phone, :area_code => true, :extension => 123)) - assert_equal("800-555-1212", 8005551212.to_s(:phone, :extension => " ")) - assert_equal("555.1212", 5551212.to_s(:phone, :delimiter => '.')) - assert_equal("+1-800-555-1212", 8005551212.to_s(:phone, :country_code => 1)) - assert_equal("+18005551212", 8005551212.to_s(:phone, :country_code => 1, :delimiter => '')) + assert_equal("(800) 555-1212", 8005551212.to_s(:phone, area_code: true)) + assert_equal("800 555 1212", 8005551212.to_s(:phone, delimiter: " ")) + assert_equal("(800) 555-1212 x 123", 8005551212.to_s(:phone, area_code: true, extension: 123)) + assert_equal("800-555-1212", 8005551212.to_s(:phone, extension: " ")) + assert_equal("555.1212", 5551212.to_s(:phone, delimiter: ".")) + assert_equal("+1-800-555-1212", 8005551212.to_s(:phone, country_code: 1)) + assert_equal("+18005551212", 8005551212.to_s(:phone, country_code: 1, delimiter: "")) assert_equal("22-555-1212", 225551212.to_s(:phone)) - assert_equal("+45-22-555-1212", 225551212.to_s(:phone, :country_code => 45)) + assert_equal("+45-22-555-1212", 225551212.to_s(:phone, country_code: 45)) end def test_to_s__currency assert_equal("$1,234,567,890.50", 1234567890.50.to_s(:currency)) assert_equal("$1,234,567,890.51", 1234567890.506.to_s(:currency)) assert_equal("-$1,234,567,890.50", -1234567890.50.to_s(:currency)) - assert_equal("-$ 1,234,567,890.50", -1234567890.50.to_s(:currency, :format => "%u %n")) - assert_equal("($1,234,567,890.50)", -1234567890.50.to_s(:currency, :negative_format => "(%u%n)")) - assert_equal("$1,234,567,892", 1234567891.50.to_s(:currency, :precision => 0)) - assert_equal("$1,234,567,890.5", 1234567890.50.to_s(:currency, :precision => 1)) - assert_equal("£1234567890,50", 1234567890.50.to_s(:currency, :unit => "£", :separator => ",", :delimiter => "")) + assert_equal("-$ 1,234,567,890.50", -1234567890.50.to_s(:currency, format: "%u %n")) + assert_equal("($1,234,567,890.50)", -1234567890.50.to_s(:currency, negative_format: "(%u%n)")) + assert_equal("$1,234,567,892", 1234567891.50.to_s(:currency, precision: 0)) + assert_equal("$1,234,567,890.5", 1234567890.50.to_s(:currency, precision: 1)) + assert_equal("£1234567890,50", 1234567890.50.to_s(:currency, unit: "£", separator: ",", delimiter: "")) end - def test_to_s__rounded assert_equal("-111.235", -111.2346.to_s(:rounded)) assert_equal("111.235", 111.2346.to_s(:rounded)) - assert_equal("31.83", 31.825.to_s(:rounded, :precision => 2)) - assert_equal("111.23", 111.2346.to_s(:rounded, :precision => 2)) - assert_equal("111.00", 111.to_s(:rounded, :precision => 2)) - assert_equal("3268", (32.6751 * 100.00).to_s(:rounded, :precision => 0)) - assert_equal("112", 111.50.to_s(:rounded, :precision => 0)) - assert_equal("1234567892", 1234567891.50.to_s(:rounded, :precision => 0)) - assert_equal("0", 0.to_s(:rounded, :precision => 0)) - assert_equal("0.00100", 0.001.to_s(:rounded, :precision => 5)) - assert_equal("0.001", 0.00111.to_s(:rounded, :precision => 3)) - assert_equal("10.00", 9.995.to_s(:rounded, :precision => 2)) - assert_equal("11.00", 10.995.to_s(:rounded, :precision => 2)) - assert_equal("0.00", -0.001.to_s(:rounded, :precision => 2)) + assert_equal("31.83", 31.825.to_s(:rounded, precision: 2)) + assert_equal("111.23", 111.2346.to_s(:rounded, precision: 2)) + assert_equal("111.00", 111.to_s(:rounded, precision: 2)) + assert_equal("3268", (32.6751 * 100.00).to_s(:rounded, precision: 0)) + assert_equal("112", 111.50.to_s(:rounded, precision: 0)) + assert_equal("1234567892", 1234567891.50.to_s(:rounded, precision: 0)) + assert_equal("0", 0.to_s(:rounded, precision: 0)) + assert_equal("0.00100", 0.001.to_s(:rounded, precision: 5)) + assert_equal("0.001", 0.00111.to_s(:rounded, precision: 3)) + assert_equal("10.00", 9.995.to_s(:rounded, precision: 2)) + assert_equal("11.00", 10.995.to_s(:rounded, precision: 2)) + assert_equal("0.00", -0.001.to_s(:rounded, precision: 2)) end def test_to_s__percentage assert_equal("100.000%", 100.to_s(:percentage)) - assert_equal("100%", 100.to_s(:percentage, :precision => 0)) - assert_equal("302.06%", 302.0574.to_s(:percentage, :precision => 2)) - assert_equal("123.4%", 123.400.to_s(:percentage, :precision => 3, :strip_insignificant_zeros => true)) - assert_equal("1.000,000%", 1000.to_s(:percentage, :delimiter => '.', :separator => ',')) - assert_equal("1000.000 %", 1000.to_s(:percentage, :format => "%n %")) + assert_equal("100%", 100.to_s(:percentage, precision: 0)) + assert_equal("302.06%", 302.0574.to_s(:percentage, precision: 2)) + assert_equal("123.4%", 123.400.to_s(:percentage, precision: 3, strip_insignificant_zeros: true)) + assert_equal("1.000,000%", 1000.to_s(:percentage, delimiter: ".", separator: ",")) + assert_equal("1000.000 %", 1000.to_s(:percentage, format: "%n %")) end def test_to_s__delimited @@ -216,181 +215,180 @@ class NumericExtFormattingTest < ActiveSupport::TestCase end def test_to_s__delimited__with_options_hash - assert_equal '12 345 678', 12345678.to_s(:delimited, :delimiter => ' ') - assert_equal '12,345,678-05', 12345678.05.to_s(:delimited, :separator => '-') - assert_equal '12.345.678,05', 12345678.05.to_s(:delimited, :separator => ',', :delimiter => '.') - assert_equal '12.345.678,05', 12345678.05.to_s(:delimited, :delimiter => '.', :separator => ',') + assert_equal "12 345 678", 12345678.to_s(:delimited, delimiter: " ") + assert_equal "12,345,678-05", 12345678.05.to_s(:delimited, separator: "-") + assert_equal "12.345.678,05", 12345678.05.to_s(:delimited, separator: ",", delimiter: ".") + assert_equal "12.345.678,05", 12345678.05.to_s(:delimited, delimiter: ".", separator: ",") end - def test_to_s__rounded_with_custom_delimiter_and_separator - assert_equal '31,83', 31.825.to_s(:rounded, :precision => 2, :separator => ',') - assert_equal '1.231,83', 1231.825.to_s(:rounded, :precision => 2, :separator => ',', :delimiter => '.') + assert_equal "31,83", 31.825.to_s(:rounded, precision: 2, separator: ",") + assert_equal "1.231,83", 1231.825.to_s(:rounded, precision: 2, separator: ",", delimiter: ".") end def test_to_s__rounded__with_significant_digits - assert_equal "124000", 123987.to_s(:rounded, :precision => 3, :significant => true) - assert_equal "120000000", 123987876.to_s(:rounded, :precision => 2, :significant => true ) - assert_equal "9775", 9775.to_s(:rounded, :precision => 4, :significant => true ) - assert_equal "5.4", 5.3923.to_s(:rounded, :precision => 2, :significant => true ) - assert_equal "5", 5.3923.to_s(:rounded, :precision => 1, :significant => true ) - assert_equal "1", 1.232.to_s(:rounded, :precision => 1, :significant => true ) - assert_equal "7", 7.to_s(:rounded, :precision => 1, :significant => true ) - assert_equal "1", 1.to_s(:rounded, :precision => 1, :significant => true ) - assert_equal "53", 52.7923.to_s(:rounded, :precision => 2, :significant => true ) - assert_equal "9775.00", 9775.to_s(:rounded, :precision => 6, :significant => true ) - assert_equal "5.392900", 5.3929.to_s(:rounded, :precision => 7, :significant => true ) - assert_equal "0.0", 0.to_s(:rounded, :precision => 2, :significant => true ) - assert_equal "0", 0.to_s(:rounded, :precision => 1, :significant => true ) - assert_equal "0.0001", 0.0001.to_s(:rounded, :precision => 1, :significant => true ) - assert_equal "0.000100", 0.0001.to_s(:rounded, :precision => 3, :significant => true ) - assert_equal "0.0001", 0.0001111.to_s(:rounded, :precision => 1, :significant => true ) - assert_equal "10.0", 9.995.to_s(:rounded, :precision => 3, :significant => true) - assert_equal "9.99", 9.994.to_s(:rounded, :precision => 3, :significant => true) - assert_equal "11.0", 10.995.to_s(:rounded, :precision => 3, :significant => true) + assert_equal "124000", 123987.to_s(:rounded, precision: 3, significant: true) + assert_equal "120000000", 123987876.to_s(:rounded, precision: 2, significant: true ) + assert_equal "9775", 9775.to_s(:rounded, precision: 4, significant: true ) + assert_equal "5.4", 5.3923.to_s(:rounded, precision: 2, significant: true ) + assert_equal "5", 5.3923.to_s(:rounded, precision: 1, significant: true ) + assert_equal "1", 1.232.to_s(:rounded, precision: 1, significant: true ) + assert_equal "7", 7.to_s(:rounded, precision: 1, significant: true ) + assert_equal "1", 1.to_s(:rounded, precision: 1, significant: true ) + assert_equal "53", 52.7923.to_s(:rounded, precision: 2, significant: true ) + assert_equal "9775.00", 9775.to_s(:rounded, precision: 6, significant: true ) + assert_equal "5.392900", 5.3929.to_s(:rounded, precision: 7, significant: true ) + assert_equal "0.0", 0.to_s(:rounded, precision: 2, significant: true ) + assert_equal "0", 0.to_s(:rounded, precision: 1, significant: true ) + assert_equal "0.0001", 0.0001.to_s(:rounded, precision: 1, significant: true ) + assert_equal "0.000100", 0.0001.to_s(:rounded, precision: 3, significant: true ) + assert_equal "0.0001", 0.0001111.to_s(:rounded, precision: 1, significant: true ) + assert_equal "10.0", 9.995.to_s(:rounded, precision: 3, significant: true) + assert_equal "9.99", 9.994.to_s(:rounded, precision: 3, significant: true) + assert_equal "11.0", 10.995.to_s(:rounded, precision: 3, significant: true) end def test_to_s__rounded__with_strip_insignificant_zeros - assert_equal "9775.43", 9775.43.to_s(:rounded, :precision => 4, :strip_insignificant_zeros => true ) - assert_equal "9775.2", 9775.2.to_s(:rounded, :precision => 6, :significant => true, :strip_insignificant_zeros => true ) - assert_equal "0", 0.to_s(:rounded, :precision => 6, :significant => true, :strip_insignificant_zeros => true ) + assert_equal "9775.43", 9775.43.to_s(:rounded, precision: 4, strip_insignificant_zeros: true ) + assert_equal "9775.2", 9775.2.to_s(:rounded, precision: 6, significant: true, strip_insignificant_zeros: true ) + assert_equal "0", 0.to_s(:rounded, precision: 6, significant: true, strip_insignificant_zeros: true ) end def test_to_s__rounded__with_significant_true_and_zero_precision # Zero precision with significant is a mistake (would always return zero), # so we treat it as if significant was false (increases backwards compatibility for number_to_human_size) - assert_equal "124", 123.987.to_s(:rounded, :precision => 0, :significant => true) - assert_equal "12", 12.to_s(:rounded, :precision => 0, :significant => true ) + assert_equal "124", 123.987.to_s(:rounded, precision: 0, significant: true) + assert_equal "12", 12.to_s(:rounded, precision: 0, significant: true ) end def test_to_s__human_size - assert_equal '0 Bytes', 0.to_s(:human_size) - assert_equal '1 Byte', 1.to_s(:human_size) - assert_equal '3 Bytes', 3.14159265.to_s(:human_size) - assert_equal '123 Bytes', 123.0.to_s(:human_size) - assert_equal '123 Bytes', 123.to_s(:human_size) - assert_equal '1.21 KB', 1234.to_s(:human_size) - assert_equal '12.1 KB', 12345.to_s(:human_size) - assert_equal '1.18 MB', 1234567.to_s(:human_size) - assert_equal '1.15 GB', 1234567890.to_s(:human_size) - assert_equal '1.12 TB', 1234567890123.to_s(:human_size) - assert_equal '1.1 PB', 1234567890123456.to_s(:human_size) - assert_equal '1.07 EB', 1234567890123456789.to_s(:human_size) - assert_equal '1030 EB', exabytes(1026).to_s(:human_size) - assert_equal '444 KB', kilobytes(444).to_s(:human_size) - assert_equal '1020 MB', megabytes(1023).to_s(:human_size) - assert_equal '3 TB', terabytes(3).to_s(:human_size) - assert_equal '1.2 MB', 1234567.to_s(:human_size, :precision => 2) - assert_equal '3 Bytes', 3.14159265.to_s(:human_size, :precision => 4) - assert_equal '1 KB', kilobytes(1.0123).to_s(:human_size, :precision => 2) - assert_equal '1.01 KB', kilobytes(1.0100).to_s(:human_size, :precision => 4) - assert_equal '10 KB', kilobytes(10.000).to_s(:human_size, :precision => 4) - assert_equal '1 Byte', 1.1.to_s(:human_size) - assert_equal '10 Bytes', 10.to_s(:human_size) + assert_equal "0 Bytes", 0.to_s(:human_size) + assert_equal "1 Byte", 1.to_s(:human_size) + assert_equal "3 Bytes", 3.14159265.to_s(:human_size) + assert_equal "123 Bytes", 123.0.to_s(:human_size) + assert_equal "123 Bytes", 123.to_s(:human_size) + assert_equal "1.21 KB", 1234.to_s(:human_size) + assert_equal "12.1 KB", 12345.to_s(:human_size) + assert_equal "1.18 MB", 1234567.to_s(:human_size) + assert_equal "1.15 GB", 1234567890.to_s(:human_size) + assert_equal "1.12 TB", 1234567890123.to_s(:human_size) + assert_equal "1.1 PB", 1234567890123456.to_s(:human_size) + assert_equal "1.07 EB", 1234567890123456789.to_s(:human_size) + assert_equal "1030 EB", exabytes(1026).to_s(:human_size) + assert_equal "444 KB", kilobytes(444).to_s(:human_size) + assert_equal "1020 MB", megabytes(1023).to_s(:human_size) + assert_equal "3 TB", terabytes(3).to_s(:human_size) + assert_equal "1.2 MB", 1234567.to_s(:human_size, precision: 2) + assert_equal "3 Bytes", 3.14159265.to_s(:human_size, precision: 4) + assert_equal "1 KB", kilobytes(1.0123).to_s(:human_size, precision: 2) + assert_equal "1.01 KB", kilobytes(1.0100).to_s(:human_size, precision: 4) + assert_equal "10 KB", kilobytes(10.000).to_s(:human_size, precision: 4) + assert_equal "1 Byte", 1.1.to_s(:human_size) + assert_equal "10 Bytes", 10.to_s(:human_size) end def test_to_s__human_size_with_si_prefix assert_deprecated do - assert_equal '3 Bytes', 3.14159265.to_s(:human_size, :prefix => :si) - assert_equal '123 Bytes', 123.0.to_s(:human_size, :prefix => :si) - assert_equal '123 Bytes', 123.to_s(:human_size, :prefix => :si) - assert_equal '1.23 KB', 1234.to_s(:human_size, :prefix => :si) - assert_equal '12.3 KB', 12345.to_s(:human_size, :prefix => :si) - assert_equal '1.23 MB', 1234567.to_s(:human_size, :prefix => :si) - assert_equal '1.23 GB', 1234567890.to_s(:human_size, :prefix => :si) - assert_equal '1.23 TB', 1234567890123.to_s(:human_size, :prefix => :si) - assert_equal '1.23 PB', 1234567890123456.to_s(:human_size, :prefix => :si) - assert_equal '1.23 EB', 1234567890123456789.to_s(:human_size, :prefix => :si) + assert_equal "3 Bytes", 3.14159265.to_s(:human_size, prefix: :si) + assert_equal "123 Bytes", 123.0.to_s(:human_size, prefix: :si) + assert_equal "123 Bytes", 123.to_s(:human_size, prefix: :si) + assert_equal "1.23 KB", 1234.to_s(:human_size, prefix: :si) + assert_equal "12.3 KB", 12345.to_s(:human_size, prefix: :si) + assert_equal "1.23 MB", 1234567.to_s(:human_size, prefix: :si) + assert_equal "1.23 GB", 1234567890.to_s(:human_size, prefix: :si) + assert_equal "1.23 TB", 1234567890123.to_s(:human_size, prefix: :si) + assert_equal "1.23 PB", 1234567890123456.to_s(:human_size, prefix: :si) + assert_equal "1.23 EB", 1234567890123456789.to_s(:human_size, prefix: :si) end end def test_to_s__human_size_with_options_hash - assert_equal '1.2 MB', 1234567.to_s(:human_size, :precision => 2) - assert_equal '3 Bytes', 3.14159265.to_s(:human_size, :precision => 4) - assert_equal '1 KB', kilobytes(1.0123).to_s(:human_size, :precision => 2) - assert_equal '1.01 KB', kilobytes(1.0100).to_s(:human_size, :precision => 4) - assert_equal '10 KB', kilobytes(10.000).to_s(:human_size, :precision => 4) - assert_equal '1 TB', 1234567890123.to_s(:human_size, :precision => 1) - assert_equal '500 MB', 524288000.to_s(:human_size, :precision=>3) - assert_equal '10 MB', 9961472.to_s(:human_size, :precision=>0) - assert_equal '40 KB', 41010.to_s(:human_size, :precision => 1) - assert_equal '40 KB', 41100.to_s(:human_size, :precision => 2) - assert_equal '1.0 KB', kilobytes(1.0123).to_s(:human_size, :precision => 2, :strip_insignificant_zeros => false) - assert_equal '1.012 KB', kilobytes(1.0123).to_s(:human_size, :precision => 3, :significant => false) - assert_equal '1 KB', kilobytes(1.0123).to_s(:human_size, :precision => 0, :significant => true) #ignores significant it precision is 0 + assert_equal "1.2 MB", 1234567.to_s(:human_size, precision: 2) + assert_equal "3 Bytes", 3.14159265.to_s(:human_size, precision: 4) + assert_equal "1 KB", kilobytes(1.0123).to_s(:human_size, precision: 2) + assert_equal "1.01 KB", kilobytes(1.0100).to_s(:human_size, precision: 4) + assert_equal "10 KB", kilobytes(10.000).to_s(:human_size, precision: 4) + assert_equal "1 TB", 1234567890123.to_s(:human_size, precision: 1) + assert_equal "500 MB", 524288000.to_s(:human_size, precision: 3) + assert_equal "10 MB", 9961472.to_s(:human_size, precision: 0) + assert_equal "40 KB", 41010.to_s(:human_size, precision: 1) + assert_equal "40 KB", 41100.to_s(:human_size, precision: 2) + assert_equal "1.0 KB", kilobytes(1.0123).to_s(:human_size, precision: 2, strip_insignificant_zeros: false) + assert_equal "1.012 KB", kilobytes(1.0123).to_s(:human_size, precision: 3, significant: false) + assert_equal "1 KB", kilobytes(1.0123).to_s(:human_size, precision: 0, significant: true) #ignores significant it precision is 0 end def test_to_s__human_size_with_custom_delimiter_and_separator - assert_equal '1,01 KB', kilobytes(1.0123).to_s(:human_size, :precision => 3, :separator => ',') - assert_equal '1,01 KB', kilobytes(1.0100).to_s(:human_size, :precision => 4, :separator => ',') - assert_equal '1.000,1 TB', terabytes(1000.1).to_s(:human_size, :precision => 5, :delimiter => '.', :separator => ',') + assert_equal "1,01 KB", kilobytes(1.0123).to_s(:human_size, precision: 3, separator: ",") + assert_equal "1,01 KB", kilobytes(1.0100).to_s(:human_size, precision: 4, separator: ",") + assert_equal "1.000,1 TB", terabytes(1000.1).to_s(:human_size, precision: 5, delimiter: ".", separator: ",") end def test_number_to_human - assert_equal '-123', -123.to_s(:human) - assert_equal '-0.5', -0.5.to_s(:human) - assert_equal '0', 0.to_s(:human) - assert_equal '0.5', 0.5.to_s(:human) - assert_equal '123', 123.to_s(:human) - assert_equal '1.23 Thousand', 1234.to_s(:human) - assert_equal '12.3 Thousand', 12345.to_s(:human) - assert_equal '1.23 Million', 1234567.to_s(:human) - assert_equal '1.23 Billion', 1234567890.to_s(:human) - assert_equal '1.23 Trillion', 1234567890123.to_s(:human) - assert_equal '1.23 Quadrillion', 1234567890123456.to_s(:human) - assert_equal '1230 Quadrillion', 1234567890123456789.to_s(:human) - assert_equal '490 Thousand', 489939.to_s(:human, :precision => 2) - assert_equal '489.9 Thousand', 489939.to_s(:human, :precision => 4) - assert_equal '489 Thousand', 489000.to_s(:human, :precision => 4) - assert_equal '489.0 Thousand', 489000.to_s(:human, :precision => 4, :strip_insignificant_zeros => false) - assert_equal '1.2346 Million', 1234567.to_s(:human, :precision => 4, :significant => false) - assert_equal '1,2 Million', 1234567.to_s(:human, :precision => 1, :significant => false, :separator => ',') - assert_equal '1 Million', 1234567.to_s(:human, :precision => 0, :significant => true, :separator => ',') #significant forced to false + assert_equal "-123", -123.to_s(:human) + assert_equal "-0.5", -0.5.to_s(:human) + assert_equal "0", 0.to_s(:human) + assert_equal "0.5", 0.5.to_s(:human) + assert_equal "123", 123.to_s(:human) + assert_equal "1.23 Thousand", 1234.to_s(:human) + assert_equal "12.3 Thousand", 12345.to_s(:human) + assert_equal "1.23 Million", 1234567.to_s(:human) + assert_equal "1.23 Billion", 1234567890.to_s(:human) + assert_equal "1.23 Trillion", 1234567890123.to_s(:human) + assert_equal "1.23 Quadrillion", 1234567890123456.to_s(:human) + assert_equal "1230 Quadrillion", 1234567890123456789.to_s(:human) + assert_equal "490 Thousand", 489939.to_s(:human, precision: 2) + assert_equal "489.9 Thousand", 489939.to_s(:human, precision: 4) + assert_equal "489 Thousand", 489000.to_s(:human, precision: 4) + assert_equal "489.0 Thousand", 489000.to_s(:human, precision: 4, strip_insignificant_zeros: false) + assert_equal "1.2346 Million", 1234567.to_s(:human, precision: 4, significant: false) + assert_equal "1,2 Million", 1234567.to_s(:human, precision: 1, significant: false, separator: ",") + assert_equal "1 Million", 1234567.to_s(:human, precision: 0, significant: true, separator: ",") #significant forced to false end def test_number_to_human_with_custom_units #Only integers - volume = {:unit => "ml", :thousand => "lt", :million => "m3"} - assert_equal '123 lt', 123456.to_s(:human, :units => volume) - assert_equal '12 ml', 12.to_s(:human, :units => volume) - assert_equal '1.23 m3', 1234567.to_s(:human, :units => volume) + volume = { unit: "ml", thousand: "lt", million: "m3" } + assert_equal "123 lt", 123456.to_s(:human, units: volume) + assert_equal "12 ml", 12.to_s(:human, units: volume) + assert_equal "1.23 m3", 1234567.to_s(:human, units: volume) #Including fractionals - distance = {:mili => "mm", :centi => "cm", :deci => "dm", :unit => "m", :ten => "dam", :hundred => "hm", :thousand => "km"} - assert_equal '1.23 mm', 0.00123.to_s(:human, :units => distance) - assert_equal '1.23 cm', 0.0123.to_s(:human, :units => distance) - assert_equal '1.23 dm', 0.123.to_s(:human, :units => distance) - assert_equal '1.23 m', 1.23.to_s(:human, :units => distance) - assert_equal '1.23 dam', 12.3.to_s(:human, :units => distance) - assert_equal '1.23 hm', 123.to_s(:human, :units => distance) - assert_equal '1.23 km', 1230.to_s(:human, :units => distance) - assert_equal '1.23 km', 1230.to_s(:human, :units => distance) - assert_equal '1.23 km', 1230.to_s(:human, :units => distance) - assert_equal '12.3 km', 12300.to_s(:human, :units => distance) + distance = { mili: "mm", centi: "cm", deci: "dm", unit: "m", ten: "dam", hundred: "hm", thousand: "km" } + assert_equal "1.23 mm", 0.00123.to_s(:human, units: distance) + assert_equal "1.23 cm", 0.0123.to_s(:human, units: distance) + assert_equal "1.23 dm", 0.123.to_s(:human, units: distance) + assert_equal "1.23 m", 1.23.to_s(:human, units: distance) + assert_equal "1.23 dam", 12.3.to_s(:human, units: distance) + assert_equal "1.23 hm", 123.to_s(:human, units: distance) + assert_equal "1.23 km", 1230.to_s(:human, units: distance) + assert_equal "1.23 km", 1230.to_s(:human, units: distance) + assert_equal "1.23 km", 1230.to_s(:human, units: distance) + assert_equal "12.3 km", 12300.to_s(:human, units: distance) #The quantifiers don't need to be a continuous sequence - gangster = {:hundred => "hundred bucks", :million => "thousand quids"} - assert_equal '1 hundred bucks', 100.to_s(:human, :units => gangster) - assert_equal '25 hundred bucks', 2500.to_s(:human, :units => gangster) - assert_equal '25 thousand quids', 25000000.to_s(:human, :units => gangster) - assert_equal '12300 thousand quids', 12345000000.to_s(:human, :units => gangster) + gangster = { hundred: "hundred bucks", million: "thousand quids" } + assert_equal "1 hundred bucks", 100.to_s(:human, units: gangster) + assert_equal "25 hundred bucks", 2500.to_s(:human, units: gangster) + assert_equal "25 thousand quids", 25000000.to_s(:human, units: gangster) + assert_equal "12300 thousand quids", 12345000000.to_s(:human, units: gangster) #Spaces are stripped from the resulting string - assert_equal '4', 4.to_s(:human, :units => {:unit => "", :ten => 'tens '}) - assert_equal '4.5 tens', 45.to_s(:human, :units => {:unit => "", :ten => ' tens '}) + assert_equal "4", 4.to_s(:human, units: { unit: "", ten: "tens " }) + assert_equal "4.5 tens", 45.to_s(:human, units: { unit: "", ten: " tens " }) end def test_number_to_human_with_custom_format - assert_equal '123 times Thousand', 123456.to_s(:human, :format => "%n times %u") - volume = {:unit => "ml", :thousand => "lt", :million => "m3"} - assert_equal '123.lt', 123456.to_s(:human, :units => volume, :format => "%n.%u") + assert_equal "123 times Thousand", 123456.to_s(:human, format: "%n times %u") + volume = { unit: "ml", thousand: "lt", million: "m3" } + assert_equal "123.lt", 123456.to_s(:human, units: volume, format: "%n.%u") end def test_to_s__injected_on_proper_types - assert_equal '1.23 Thousand', 1230.to_s(:human) - assert_equal '1.23 Thousand', Float(1230).to_s(:human) - assert_equal '100000 Quadrillion', (100**10).to_s(:human) - assert_equal '1 Million', BigDecimal("1000010").to_s(:human) + assert_equal "1.23 Thousand", 1230.to_s(:human) + assert_equal "1.23 Thousand", Float(1230).to_s(:human) + assert_equal "100000 Quadrillion", (100**10).to_s(:human) + assert_equal "1 Million", BigDecimal("1000010").to_s(:human) end def test_to_formatted_s_is_deprecated @@ -400,23 +398,23 @@ class NumericExtFormattingTest < ActiveSupport::TestCase end def test_to_s_with_invalid_formatter - assert_equal '123', 123.to_s(:invalid) - assert_equal '2.5', 2.5.to_s(:invalid) - assert_equal '100000000000000000000', (100**10).to_s(:invalid) - assert_equal '1000010.0', BigDecimal("1000010").to_s(:invalid) + assert_equal "123", 123.to_s(:invalid) + assert_equal "2.5", 2.5.to_s(:invalid) + assert_equal "100000000000000000000", (100**10).to_s(:invalid) + assert_equal "1000010.0", BigDecimal("1000010").to_s(:invalid) end def test_default_to_s - assert_equal '123', 123.to_s - assert_equal '1111011', 123.to_s(2) + assert_equal "123", 123.to_s + assert_equal "1111011", 123.to_s(2) - assert_equal '2.5', 2.5.to_s + assert_equal "2.5", 2.5.to_s - assert_equal '100000000000000000000', (100**10).to_s - assert_equal '1010110101111000111010111100010110101100011000100000000000000000000', (100**10).to_s(2) + assert_equal "100000000000000000000", (100**10).to_s + assert_equal "1010110101111000111010111100010110101100011000100000000000000000000", (100**10).to_s(2) - assert_equal '1000010.0', BigDecimal("1000010").to_s - assert_equal '10000 10.0', BigDecimal("1000010").to_s('5F') + assert_equal "1000010.0", BigDecimal("1000010").to_s + assert_equal "10000 10.0", BigDecimal("1000010").to_s("5F") end def test_in_milliseconds diff --git a/activesupport/test/core_ext/object/acts_like_test.rb b/activesupport/test/core_ext/object/acts_like_test.rb index e68b1d23cb..631f4e63a8 100644 --- a/activesupport/test/core_ext/object/acts_like_test.rb +++ b/activesupport/test/core_ext/object/acts_like_test.rb @@ -1,5 +1,5 @@ -require 'abstract_unit' -require 'active_support/core_ext/object' +require "abstract_unit" +require "active_support/core_ext/object" class ObjectTests < ActiveSupport::TestCase class DuckTime diff --git a/activesupport/test/core_ext/object/blank_test.rb b/activesupport/test/core_ext/object/blank_test.rb index a142096993..ab0676524e 100644 --- a/activesupport/test/core_ext/object/blank_test.rb +++ b/activesupport/test/core_ext/object/blank_test.rb @@ -1,5 +1,5 @@ -require 'abstract_unit' -require 'active_support/core_ext/object/blank' +require "abstract_unit" +require "active_support/core_ext/object/blank" class BlankTest < ActiveSupport::TestCase class EmptyTrue @@ -14,8 +14,8 @@ class BlankTest < ActiveSupport::TestCase end end - BLANK = [ EmptyTrue.new, nil, false, '', ' ', " \n\t \r ", ' ', "\u00a0", [], {} ] - NOT = [ EmptyFalse.new, Object.new, true, 0, 1, 'a', [nil], { nil => 0 } ] + BLANK = [ EmptyTrue.new, nil, false, "", " ", " \n\t \r ", " ", "\u00a0", [], {} ] + NOT = [ EmptyFalse.new, Object.new, true, 0, 1, "a", [nil], { nil => 0 } ] def test_blank BLANK.each { |v| assert_equal true, v.blank?, "#{v.inspect} should be blank" } diff --git a/activesupport/test/core_ext/object/deep_dup_test.rb b/activesupport/test/core_ext/object/deep_dup_test.rb index aa839201ea..e335ec1b40 100644 --- a/activesupport/test/core_ext/object/deep_dup_test.rb +++ b/activesupport/test/core_ext/object/deep_dup_test.rb @@ -1,8 +1,7 @@ -require 'abstract_unit' -require 'active_support/core_ext/object' +require "abstract_unit" +require "active_support/core_ext/object" class DeepDupTest < ActiveSupport::TestCase - def test_array_deep_dup array = [1, [2, 3]] dup = array.deep_dup @@ -12,15 +11,15 @@ class DeepDupTest < ActiveSupport::TestCase end def test_hash_deep_dup - hash = { :a => { :b => 'b' } } + hash = { a: { b: "b" } } dup = hash.deep_dup - dup[:a][:c] = 'c' + dup[:a][:c] = "c" assert_equal nil, hash[:a][:c] - assert_equal 'c', dup[:a][:c] + assert_equal "c", dup[:a][:c] end def test_array_deep_dup_with_hash_inside - array = [1, { :a => 2, :b => 3 } ] + array = [1, { a: 2, b: 3 } ] dup = array.deep_dup dup[1][:c] = 4 assert_equal nil, array[1][:c] @@ -28,16 +27,16 @@ class DeepDupTest < ActiveSupport::TestCase end def test_hash_deep_dup_with_array_inside - hash = { :a => [1, 2] } + hash = { a: [1, 2] } dup = hash.deep_dup - dup[:a][2] = 'c' + dup[:a][2] = "c" assert_equal nil, hash[:a][2] - assert_equal 'c', dup[:a][2] + assert_equal "c", dup[:a][2] end def test_deep_dup_initialize zero_hash = Hash.new 0 - hash = { :a => zero_hash } + hash = { a: zero_hash } dup = hash.deep_dup assert_equal 0, dup[:a][44] end @@ -55,5 +54,4 @@ class DeepDupTest < ActiveSupport::TestCase dup = hash.deep_dup assert_equal 1, dup.keys.length end - end diff --git a/activesupport/test/core_ext/object/duplicable_test.rb b/activesupport/test/core_ext/object/duplicable_test.rb index 042f5cfb34..2cbfefe235 100644 --- a/activesupport/test/core_ext/object/duplicable_test.rb +++ b/activesupport/test/core_ext/object/duplicable_test.rb @@ -1,12 +1,12 @@ -require 'abstract_unit' -require 'bigdecimal' -require 'active_support/core_ext/object/duplicable' -require 'active_support/core_ext/numeric/time' +require "abstract_unit" +require "bigdecimal" +require "active_support/core_ext/object/duplicable" +require "active_support/core_ext/numeric/time" class DuplicableTest < ActiveSupport::TestCase RAISE_DUP = [nil, false, true, :symbol, 1, 2.3, method(:puts)] - ALLOW_DUP = ['1', Object.new, /foo/, [], {}, Time.now, Class.new, Module.new] - ALLOW_DUP << BigDecimal.new('4.56') + ALLOW_DUP = ["1", Object.new, /foo/, [], {}, Time.now, Class.new, Module.new] + ALLOW_DUP << BigDecimal.new("4.56") def test_duplicable rubinius_skip "* Method#dup is allowed at the moment on Rubinius\n" \ diff --git a/activesupport/test/core_ext/object/inclusion_test.rb b/activesupport/test/core_ext/object/inclusion_test.rb index 32d512eca3..be211ec7dc 100644 --- a/activesupport/test/core_ext/object/inclusion_test.rb +++ b/activesupport/test/core_ext/object/inclusion_test.rb @@ -1,5 +1,5 @@ -require 'abstract_unit' -require 'active_support/core_ext/object/inclusion' +require "abstract_unit" +require "active_support/core_ext/object/inclusion" class InTest < ActiveSupport::TestCase def test_in_array @@ -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/core_ext/object/instance_variables_test.rb b/activesupport/test/core_ext/object/instance_variables_test.rb index 9f4c5dc4f1..5bdb2fbc35 100644 --- a/activesupport/test/core_ext/object/instance_variables_test.rb +++ b/activesupport/test/core_ext/object/instance_variables_test.rb @@ -1,11 +1,11 @@ -require 'abstract_unit' -require 'active_support/core_ext/object' +require "abstract_unit" +require "active_support/core_ext/object" class ObjectInstanceVariableTest < ActiveSupport::TestCase def setup @source, @dest = Object.new, Object.new - @source.instance_variable_set(:@bar, 'bar') - @source.instance_variable_set(:@baz, 'baz') + @source.instance_variable_set(:@bar, "bar") + @source.instance_variable_set(:@baz, "baz") end def test_instance_variable_names @@ -13,19 +13,19 @@ class ObjectInstanceVariableTest < ActiveSupport::TestCase end def test_instance_values - assert_equal({'bar' => 'bar', 'baz' => 'baz'}, @source.instance_values) + assert_equal({ "bar" => "bar", "baz" => "baz" }, @source.instance_values) end def test_instance_exec_passes_arguments_to_block - assert_equal %w(hello goodbye), 'hello'.instance_exec('goodbye') { |v| [self, v] } + assert_equal %w(hello goodbye), "hello".instance_exec("goodbye") { |v| [self, v] } end def test_instance_exec_with_frozen_obj - assert_equal %w(olleh goodbye), 'hello'.freeze.instance_exec('goodbye') { |v| [reverse, v] } + assert_equal %w(olleh goodbye), "hello".freeze.instance_exec("goodbye") { |v| [reverse, v] } end def test_instance_exec_nested - assert_equal %w(goodbye olleh bar), 'hello'.instance_exec('goodbye') { |arg| - [arg] + instance_exec('bar') { |v| [reverse, v] } } + assert_equal %w(goodbye olleh bar), "hello".instance_exec("goodbye") { |arg| + [arg] + instance_exec("bar") { |v| [reverse, v] } } end end diff --git a/activesupport/test/core_ext/object/json_cherry_pick_test.rb b/activesupport/test/core_ext/object/json_cherry_pick_test.rb index 2f7ea3a497..dd4e90918e 100644 --- a/activesupport/test/core_ext/object/json_cherry_pick_test.rb +++ b/activesupport/test/core_ext/object/json_cherry_pick_test.rb @@ -1,4 +1,4 @@ -require 'abstract_unit' +require "abstract_unit" # These test cases were added to test that cherry-picking the json extensions # works correctly, primarily for dependencies problems reported in #16131. They @@ -9,7 +9,7 @@ class JsonCherryPickTest < ActiveSupport::TestCase include ActiveSupport::Testing::Isolation def test_time_as_json - require_or_skip 'active_support/core_ext/object/json' + require_or_skip "active_support/core_ext/object/json" expected = Time.new(2004, 7, 25) actual = Time.parse(expected.as_json) @@ -18,7 +18,7 @@ class JsonCherryPickTest < ActiveSupport::TestCase end def test_date_as_json - require_or_skip 'active_support/core_ext/object/json' + require_or_skip "active_support/core_ext/object/json" expected = Date.new(2004, 7, 25) actual = Date.parse(expected.as_json) @@ -27,7 +27,7 @@ class JsonCherryPickTest < ActiveSupport::TestCase end def test_datetime_as_json - require_or_skip 'active_support/core_ext/object/json' + require_or_skip "active_support/core_ext/object/json" expected = DateTime.new(2004, 7, 25) actual = DateTime.parse(expected.as_json) diff --git a/activesupport/test/core_ext/object/json_gem_encoding_test.rb b/activesupport/test/core_ext/object/json_gem_encoding_test.rb index 2cbb1d590f..f5016d0c2a 100644 --- a/activesupport/test/core_ext/object/json_gem_encoding_test.rb +++ b/activesupport/test/core_ext/object/json_gem_encoding_test.rb @@ -1,6 +1,6 @@ -require 'abstract_unit' -require 'json' -require 'json/encoding_test_cases' +require "abstract_unit" +require "json" +require "json/encoding_test_cases" # These test cases were added to test that we do not interfere with json gem's # output when the AS encoder is loaded, primarily for problems reported in @@ -13,7 +13,7 @@ require 'json/encoding_test_cases' # we need to require this upfront to ensure we don't get a false failure, but # ideally we should just fix the BigDecimal core_ext to not change to_s without # arguments. -require 'active_support/core_ext/big_decimal' +require "active_support/core_ext/big_decimal" class JsonGemEncodingTest < ActiveSupport::TestCase include ActiveSupport::Testing::Isolation @@ -48,7 +48,7 @@ class JsonGemEncodingTest < ActiveSupport::TestCase exception = e end - require_or_skip 'active_support/core_ext/object/json' + require_or_skip "active_support/core_ext/object/json" if exception assert_raises_with_message JSON::GeneratorError, e.message do diff --git a/activesupport/test/core_ext/object/to_param_test.rb b/activesupport/test/core_ext/object/to_param_test.rb index 30a7557dc2..56246b24f3 100644 --- a/activesupport/test/core_ext/object/to_param_test.rb +++ b/activesupport/test/core_ext/object/to_param_test.rb @@ -1,5 +1,5 @@ -require 'abstract_unit' -require 'active_support/core_ext/object/to_param' +require "abstract_unit" +require "active_support/core_ext/object/to_param" class ToParamTest < ActiveSupport::TestCase class CustomString < String @@ -10,8 +10,8 @@ class ToParamTest < ActiveSupport::TestCase def test_object foo = Object.new - def foo.to_s; 'foo' end - assert_equal 'foo', foo.to_param + def foo.to_s; "foo" end + assert_equal "foo", foo.to_param end def test_nil @@ -25,13 +25,13 @@ class ToParamTest < ActiveSupport::TestCase def test_array # Empty Array - assert_equal '', [].to_param + assert_equal "", [].to_param array = [1, 2, 3, 4] assert_equal "1/2/3/4", array.to_param # Array of different objects - array = [1, '3', { a: 1, b: 2 }, nil, true, false, CustomString.new('object')] + array = [1, "3", { a: 1, b: 2 }, nil, true, false, CustomString.new("object")] assert_equal "1/3/a=1&b=2//true/false/custom-object", array.to_param end end diff --git a/activesupport/test/core_ext/object/to_query_test.rb b/activesupport/test/core_ext/object/to_query_test.rb index 09cab3ed35..298c8bf373 100644 --- a/activesupport/test/core_ext/object/to_query_test.rb +++ b/activesupport/test/core_ext/object/to_query_test.rb @@ -1,82 +1,82 @@ -require 'abstract_unit' -require 'active_support/ordered_hash' -require 'active_support/core_ext/object/to_query' -require 'active_support/core_ext/string/output_safety' +require "abstract_unit" +require "active_support/ordered_hash" +require "active_support/core_ext/object/to_query" +require "active_support/core_ext/string/output_safety" class ToQueryTest < ActiveSupport::TestCase def test_simple_conversion - assert_query_equal 'a=10', :a => 10 + assert_query_equal "a=10", a: 10 end def test_cgi_escaping - assert_query_equal 'a%3Ab=c+d', 'a:b' => 'c d' + assert_query_equal "a%3Ab=c+d", "a:b" => "c d" end def test_html_safe_parameter_key - assert_query_equal 'a%3Ab=c+d', 'a:b'.html_safe => 'c d' + assert_query_equal "a%3Ab=c+d", "a:b".html_safe => "c d" end def test_html_safe_parameter_value - assert_query_equal 'a=%5B10%5D', 'a' => '[10]'.html_safe + assert_query_equal "a=%5B10%5D", "a" => "[10]".html_safe end def test_nil_parameter_value empty = Object.new def empty.to_param; nil end - assert_query_equal 'a=', 'a' => empty + assert_query_equal "a=", "a" => empty end def test_nested_conversion - assert_query_equal 'person%5Blogin%5D=seckar&person%5Bname%5D=Nicholas', - :person => Hash[:login, 'seckar', :name, 'Nicholas'] + assert_query_equal "person%5Blogin%5D=seckar&person%5Bname%5D=Nicholas", + person: Hash[:login, "seckar", :name, "Nicholas"] end def test_multiple_nested - assert_query_equal 'account%5Bperson%5D%5Bid%5D=20&person%5Bid%5D=10', - Hash[:account, {:person => {:id => 20}}, :person, {:id => 10}] + assert_query_equal "account%5Bperson%5D%5Bid%5D=20&person%5Bid%5D=10", + Hash[:account, { person: { id: 20 } }, :person, { id: 10 }] end def test_array_values - assert_query_equal 'person%5Bid%5D%5B%5D=10&person%5Bid%5D%5B%5D=20', - :person => {:id => [10, 20]} + assert_query_equal "person%5Bid%5D%5B%5D=10&person%5Bid%5D%5B%5D=20", + person: { id: [10, 20] } end def test_array_values_are_not_sorted - assert_query_equal 'person%5Bid%5D%5B%5D=20&person%5Bid%5D%5B%5D=10', - :person => {:id => [20, 10]} + assert_query_equal "person%5Bid%5D%5B%5D=20&person%5Bid%5D%5B%5D=10", + person: { id: [20, 10] } end def test_empty_array - assert_equal "person%5B%5D=", [].to_query('person') + assert_equal "person%5B%5D=", [].to_query("person") end def test_nested_empty_hash - assert_equal '', + assert_equal "", {}.to_query - assert_query_equal 'a=1&b%5Bc%5D=3', - { a: 1, b: { c: 3, d: {} } } - assert_query_equal '', - { a: {b: {c: {}}} } - assert_query_equal 'b%5Bc%5D=false&b%5Be%5D=&b%5Bf%5D=&p=12', - { p: 12, b: { c: false, e: nil, f: '' } } - assert_query_equal 'b%5Bc%5D=3&b%5Bf%5D=', - { b: { c: 3, k: {}, f: '' } } - assert_query_equal 'b=3', - {a: [], b: 3} + assert_query_equal "a=1&b%5Bc%5D=3", + a: 1, b: { c: 3, d: {} } + assert_query_equal "", + a: { b: { c: {} } } + assert_query_equal "b%5Bc%5D=false&b%5Be%5D=&b%5Bf%5D=&p=12", + p: 12, b: { c: false, e: nil, f: "" } + assert_query_equal "b%5Bc%5D=3&b%5Bf%5D=", + b: { c: 3, k: {}, f: "" } + assert_query_equal "b=3", + a: [], b: 3 end def test_hash_with_namespace - hash = { name: 'Nakshay', nationality: 'Indian' } - assert_equal "user%5Bname%5D=Nakshay&user%5Bnationality%5D=Indian", hash.to_query('user') + hash = { name: "Nakshay", nationality: "Indian" } + assert_equal "user%5Bname%5D=Nakshay&user%5Bnationality%5D=Indian", hash.to_query("user") end def test_hash_sorted_lexicographically - hash = { type: 'human', name: 'Nakshay' } + hash = { type: "human", name: "Nakshay" } assert_equal "name=Nakshay&type=human", hash.to_query end private def assert_query_equal(expected, actual) - assert_equal expected.split('&'), actual.to_query.split('&') + assert_equal expected.split("&"), actual.to_query.split("&") end end diff --git a/activesupport/test/core_ext/object/try_test.rb b/activesupport/test/core_ext/object/try_test.rb index 25bf0207b8..5c8bf59952 100644 --- a/activesupport/test/core_ext/object/try_test.rb +++ b/activesupport/test/core_ext/object/try_test.rb @@ -1,5 +1,5 @@ -require 'abstract_unit' -require 'active_support/core_ext/object' +require "abstract_unit" +require "active_support/core_ext/object" class ObjectTryTest < ActiveSupport::TestCase def setup @@ -15,7 +15,7 @@ class ObjectTryTest < ActiveSupport::TestCase def test_nonexisting_method_with_arguments method = :undefined_method assert !@string.respond_to?(method) - assert_nil @string.try(method, 'llo', 'y') + assert_nil @string.try(method, "llo", "y") end def test_nonexisting_method_bang @@ -27,7 +27,7 @@ class ObjectTryTest < ActiveSupport::TestCase def test_nonexisting_method_with_arguments_bang method = :undefined_method assert !@string.respond_to?(method) - assert_raise(NoMethodError) { @string.try!(method, 'llo', 'y') } + assert_raise(NoMethodError) { @string.try!(method, "llo", "y") } end def test_valid_method @@ -35,11 +35,11 @@ class ObjectTryTest < ActiveSupport::TestCase end def test_argument_forwarding - assert_equal 'Hey', @string.try(:sub, 'llo', 'y') + assert_equal "Hey", @string.try(:sub, "llo", "y") end def test_block_forwarding - assert_equal 'Hey', @string.try(:sub, 'llo') { |match| 'y' } + assert_equal "Hey", @string.try(:sub, "llo") { |match| "y" } end def test_nil_to_type @@ -48,7 +48,7 @@ class ObjectTryTest < ActiveSupport::TestCase end def test_false_try - assert_equal 'false', false.try(:to_s) + assert_equal "false", false.try(:to_s) end def test_try_only_block @@ -78,7 +78,7 @@ class ObjectTryTest < ActiveSupport::TestCase private def private_method - 'private method' + "private method" end end @@ -90,7 +90,7 @@ class ObjectTryTest < ActiveSupport::TestCase private def private_method - 'private method' + "private method" end end @@ -99,22 +99,22 @@ class ObjectTryTest < ActiveSupport::TestCase class Decorator < SimpleDelegator def delegator_method - 'delegator method' + "delegator method" end def reverse - 'overridden reverse' + "overridden reverse" end private def private_delegator_method - 'private delegator method' + "private delegator method" end end def test_try_with_method_on_delegator - assert_equal 'delegator method', Decorator.new(@string).try(:delegator_method) + assert_equal "delegator method", Decorator.new(@string).try(:delegator_method) end def test_try_with_method_on_delegator_target @@ -122,7 +122,7 @@ class ObjectTryTest < ActiveSupport::TestCase end def test_try_with_overridden_method_on_delegator - assert_equal 'overridden reverse', Decorator.new(@string).reverse + assert_equal "overridden reverse", Decorator.new(@string).reverse end def test_try_with_private_method_on_delegator @@ -140,7 +140,7 @@ class ObjectTryTest < ActiveSupport::TestCase private def private_method - 'private method' + "private method" end end @@ -152,7 +152,7 @@ class ObjectTryTest < ActiveSupport::TestCase private def private_method - 'private method' + "private method" end end diff --git a/activesupport/test/core_ext/range_ext_test.rb b/activesupport/test/core_ext/range_ext_test.rb index f28cebda3d..25e6693e4d 100644 --- a/activesupport/test/core_ext/range_ext_test.rb +++ b/activesupport/test/core_ext/range_ext_test.rb @@ -1,7 +1,7 @@ -require 'abstract_unit' -require 'active_support/time' -require 'active_support/core_ext/numeric' -require 'active_support/core_ext/range' +require "abstract_unit" +require "active_support/time" +require "active_support/core_ext/numeric" +require "active_support/core_ext/range" class RangeTest < ActiveSupport::TestCase def test_to_s_from_dates @@ -99,21 +99,21 @@ class RangeTest < ActiveSupport::TestCase end def test_each_on_time_with_zone - twz = ActiveSupport::TimeWithZone.new(nil, ActiveSupport::TimeZone['Eastern Time (US & Canada)'] , Time.utc(2006,11,28,10,30)) + twz = ActiveSupport::TimeWithZone.new(nil, ActiveSupport::TimeZone["Eastern Time (US & Canada)"] , Time.utc(2006,11,28,10,30)) assert_raises TypeError do ((twz - 1.hour)..twz).each {} end end def test_step_on_time_with_zone - twz = ActiveSupport::TimeWithZone.new(nil, ActiveSupport::TimeZone['Eastern Time (US & Canada)'] , Time.utc(2006,11,28,10,30)) + twz = ActiveSupport::TimeWithZone.new(nil, ActiveSupport::TimeZone["Eastern Time (US & Canada)"] , Time.utc(2006,11,28,10,30)) assert_raises TypeError do ((twz - 1.hour)..twz).step(1) {} end end def test_include_on_time_with_zone - twz = ActiveSupport::TimeWithZone.new(nil, ActiveSupport::TimeZone['Eastern Time (US & Canada)'] , Time.utc(2006,11,28,10,30)) + twz = ActiveSupport::TimeWithZone.new(nil, ActiveSupport::TimeZone["Eastern Time (US & Canada)"] , Time.utc(2006,11,28,10,30)) assert_raises TypeError do ((twz - 1.hour)..twz).include?(twz) end diff --git a/activesupport/test/core_ext/regexp_ext_test.rb b/activesupport/test/core_ext/regexp_ext_test.rb index d91e363085..e569a9f234 100644 --- a/activesupport/test/core_ext/regexp_ext_test.rb +++ b/activesupport/test/core_ext/regexp_ext_test.rb @@ -1,5 +1,5 @@ -require 'abstract_unit' -require 'active_support/core_ext/regexp' +require "abstract_unit" +require "active_support/core_ext/regexp" class RegexpExtAccessTests < ActiveSupport::TestCase def test_multiline @@ -10,17 +10,17 @@ class RegexpExtAccessTests < ActiveSupport::TestCase # Based on https://github.com/ruby/ruby/blob/trunk/test/ruby/test_regexp.rb. def test_match_p - /back(...)/ =~ 'backref' + /back(...)/ =~ "backref" # must match here, but not in a separate method, e.g., assert_send, # to check if $~ is affected or not. assert_equal false, //.match?(nil) assert_equal true, //.match?("") assert_equal true, /.../.match?(:abc) assert_raise(TypeError) { /.../.match?(Object.new) } - assert_equal true, /b/.match?('abc') - assert_equal true, /b/.match?('abc', 1) - assert_equal true, /../.match?('abc', 1) - assert_equal true, /../.match?('abc', -2) + assert_equal true, /b/.match?("abc") + assert_equal true, /b/.match?("abc", 1) + assert_equal true, /../.match?("abc", 1) + assert_equal true, /../.match?("abc", -2) assert_equal false, /../.match?("abc", -4) assert_equal false, /../.match?("abc", 4) assert_equal true, /\z/.match?("") @@ -28,7 +28,7 @@ class RegexpExtAccessTests < ActiveSupport::TestCase assert_equal true, /R.../.match?("Ruby") assert_equal false, /R.../.match?("Ruby", 1) assert_equal false, /P.../.match?("Ruby") - assert_equal 'backref', $& - assert_equal 'ref', $1 + assert_equal "backref", $& + assert_equal "ref", $1 end end diff --git a/activesupport/test/core_ext/secure_random_test.rb b/activesupport/test/core_ext/secure_random_test.rb index dfacb7fe9f..fc25f6ab41 100644 --- a/activesupport/test/core_ext/secure_random_test.rb +++ b/activesupport/test/core_ext/secure_random_test.rb @@ -1,5 +1,5 @@ -require 'abstract_unit' -require 'active_support/core_ext/securerandom' +require "abstract_unit" +require "active_support/core_ext/securerandom" class SecureRandomTest < ActiveSupport::TestCase def test_base58 diff --git a/activesupport/test/core_ext/string_ext_test.rb b/activesupport/test/core_ext/string_ext_test.rb index d68a77680b..4b40503d22 100644 --- a/activesupport/test/core_ext/string_ext_test.rb +++ b/activesupport/test/core_ext/string_ext_test.rb @@ -1,16 +1,16 @@ -require 'date' -require 'abstract_unit' -require 'inflector_test_cases' -require 'constantize_test_cases' - -require 'active_support/inflector' -require 'active_support/core_ext/string' -require 'active_support/time' -require 'active_support/core_ext/string/strip' -require 'active_support/core_ext/string/output_safety' -require 'active_support/core_ext/string/indent' -require 'time_zone_test_helpers' -require 'yaml' +require "date" +require "abstract_unit" +require "inflector_test_cases" +require "constantize_test_cases" + +require "active_support/inflector" +require "active_support/core_ext/string" +require "active_support/time" +require "active_support/core_ext/string/strip" +require "active_support/core_ext/string/output_safety" +require "active_support/core_ext/string/indent" +require "time_zone_test_helpers" +require "yaml" class StringInflectionsTest < ActiveSupport::TestCase include InflectorTestCases @@ -18,12 +18,12 @@ class StringInflectionsTest < ActiveSupport::TestCase include TimeZoneTestHelpers def test_strip_heredoc_on_an_empty_string - assert_equal '', ''.strip_heredoc + assert_equal "", "".strip_heredoc end def test_strip_heredoc_on_a_string_with_no_lines - assert_equal 'x', 'x'.strip_heredoc - assert_equal 'x', ' x'.strip_heredoc + assert_equal "x", "x".strip_heredoc + assert_equal "x", " x".strip_heredoc end def test_strip_heredoc_on_a_heredoc_with_no_margin @@ -60,7 +60,7 @@ class StringInflectionsTest < ActiveSupport::TestCase assert_equal("blargles", "blargle".pluralize(2)) end - test 'pluralize with count = 1 still returns new string' do + test "pluralize with count = 1 still returns new string" do name = "Kuldeep" assert_not_same name.pluralize(1), name end @@ -96,7 +96,7 @@ class StringInflectionsTest < ActiveSupport::TestCase end def test_camelize_lower - assert_equal('capital', 'Capital'.camelize(:lower)) + assert_equal("capital", "Capital".camelize(:lower)) end def test_dasherize @@ -164,41 +164,41 @@ class StringInflectionsTest < ActiveSupport::TestCase def test_string_parameterized_no_separator StringToParameterizeWithNoSeparator.each do |normal, slugged| - assert_equal(normal.parameterize(separator: ''), slugged) + assert_equal(normal.parameterize(separator: ""), slugged) end end def test_string_parameterized_no_separator_deprecated StringToParameterizeWithNoSeparator.each do |normal, slugged| assert_deprecated(/Passing the separator argument as a positional parameter is deprecated and will soon be removed. Use `separator: ''` instead./i) do - assert_equal(normal.parameterize(''), slugged) + assert_equal(normal.parameterize(""), slugged) end end end def test_string_parameterized_no_separator_preserve_case StringToParameterizePreserveCaseWithNoSeparator.each do |normal, slugged| - assert_equal(normal.parameterize(separator: '', preserve_case: true), slugged) + assert_equal(normal.parameterize(separator: "", preserve_case: true), slugged) end end def test_string_parameterized_underscore StringToParameterizeWithUnderscore.each do |normal, slugged| - assert_equal(normal.parameterize(separator: '_'), slugged) + assert_equal(normal.parameterize(separator: "_"), slugged) end end def test_string_parameterized_underscore_deprecated StringToParameterizeWithUnderscore.each do |normal, slugged| assert_deprecated(/Passing the separator argument as a positional parameter is deprecated and will soon be removed. Use `separator: '_'` instead./i) do - assert_equal(normal.parameterize('_'), slugged) + assert_equal(normal.parameterize("_"), slugged) end end end def test_string_parameterized_underscore_preserve_case StringToParameterizePreserceCaseWithUnderscore.each do |normal, slugged| - assert_equal(normal.parameterize(separator: '_', preserve_case: true), slugged) + assert_equal(normal.parameterize(separator: "_", preserve_case: true), slugged) end end @@ -215,23 +215,23 @@ class StringInflectionsTest < ActiveSupport::TestCase end def test_humanize_with_html_escape - assert_equal 'Hello', ERB::Util.html_escape("hello").humanize + assert_equal "Hello", ERB::Util.html_escape("hello").humanize end def test_ord - assert_equal 97, 'a'.ord - assert_equal 97, 'abc'.ord + assert_equal 97, "a".ord + assert_equal 97, "abc".ord end def test_starts_ends_with_alias s = "hello" - assert s.starts_with?('h') - assert s.starts_with?('hel') - assert !s.starts_with?('el') + assert s.starts_with?("h") + assert s.starts_with?("hel") + assert !s.starts_with?("el") - assert s.ends_with?('o') - assert s.ends_with?('lo') - assert !s.ends_with?('el') + assert s.ends_with?("o") + assert s.ends_with?("lo") + assert !s.ends_with?("el") end def test_string_squish @@ -263,16 +263,16 @@ class StringInflectionsTest < ActiveSupport::TestCase end def test_truncate_with_omission_and_separator - assert_equal "Hello[...]", "Hello World!".truncate(10, :omission => "[...]") - assert_equal "Hello[...]", "Hello Big World!".truncate(13, :omission => "[...]", :separator => ' ') - assert_equal "Hello Big[...]", "Hello Big World!".truncate(14, :omission => "[...]", :separator => ' ') - assert_equal "Hello Big[...]", "Hello Big World!".truncate(15, :omission => "[...]", :separator => ' ') + assert_equal "Hello[...]", "Hello World!".truncate(10, omission: "[...]") + assert_equal "Hello[...]", "Hello Big World!".truncate(13, omission: "[...]", separator: " ") + assert_equal "Hello Big[...]", "Hello Big World!".truncate(14, omission: "[...]", separator: " ") + assert_equal "Hello Big[...]", "Hello Big World!".truncate(15, omission: "[...]", separator: " ") end def test_truncate_with_omission_and_regexp_separator - assert_equal "Hello[...]", "Hello Big World!".truncate(13, :omission => "[...]", :separator => /\s/) - assert_equal "Hello Big[...]", "Hello Big World!".truncate(14, :omission => "[...]", :separator => /\s/) - assert_equal "Hello Big[...]", "Hello Big World!".truncate(15, :omission => "[...]", :separator => /\s/) + assert_equal "Hello[...]", "Hello Big World!".truncate(13, omission: "[...]", separator: /\s/) + assert_equal "Hello Big[...]", "Hello Big World!".truncate(14, omission: "[...]", separator: /\s/) + assert_equal "Hello Big[...]", "Hello Big World!".truncate(15, omission: "[...]", separator: /\s/) end def test_truncate_words @@ -281,19 +281,19 @@ class StringInflectionsTest < ActiveSupport::TestCase end def test_truncate_words_with_omission - assert_equal "Hello Big World!", "Hello Big World!".truncate_words(3, :omission => "[...]") - assert_equal "Hello Big[...]", "Hello Big World!".truncate_words(2, :omission => "[...]") + assert_equal "Hello Big World!", "Hello Big World!".truncate_words(3, omission: "[...]") + assert_equal "Hello Big[...]", "Hello Big World!".truncate_words(2, omission: "[...]") end def test_truncate_words_with_separator - assert_equal "Hello<br>Big<br>World!...", "Hello<br>Big<br>World!<br>".truncate_words(3, :separator => '<br>') - assert_equal "Hello<br>Big<br>World!", "Hello<br>Big<br>World!".truncate_words(3, :separator => '<br>') - assert_equal "Hello\n<br>Big...", "Hello\n<br>Big<br>Wide<br>World!".truncate_words(2, :separator => '<br>') + assert_equal "Hello<br>Big<br>World!...", "Hello<br>Big<br>World!<br>".truncate_words(3, separator: "<br>") + assert_equal "Hello<br>Big<br>World!", "Hello<br>Big<br>World!".truncate_words(3, separator: "<br>") + assert_equal "Hello\n<br>Big...", "Hello\n<br>Big<br>Wide<br>World!".truncate_words(2, separator: "<br>") end def test_truncate_words_with_separator_and_omission - assert_equal "Hello<br>Big<br>World![...]", "Hello<br>Big<br>World!<br>".truncate_words(3, :omission => "[...]", :separator => '<br>') - assert_equal "Hello<br>Big<br>World!", "Hello<br>Big<br>World!".truncate_words(3, :omission => "[...]", :separator => '<br>') + assert_equal "Hello<br>Big<br>World![...]", "Hello<br>Big<br>World!<br>".truncate_words(3, omission: "[...]", separator: "<br>") + assert_equal "Hello<br>Big<br>World!", "Hello<br>Big<br>World!".truncate_words(3, omission: "[...]", separator: "<br>") end def test_truncate_words_with_complex_string @@ -381,14 +381,14 @@ class StringAccessTest < ActiveSupport::TestCase test "#first returns the first character" do assert_equal "h", "hello".first - assert_equal 'x', 'x'.first + assert_equal "x", "x".first end test "#first with Integer, returns a substring from the beginning to position" do assert_equal "he", "hello".first(2) assert_equal "", "hello".first(0) assert_equal "hello", "hello".first(10) - assert_equal 'x', 'x'.first(4) + assert_equal "x", "x".first(4) end test "#first with Integer >= string length still returns a new string" do @@ -399,14 +399,14 @@ class StringAccessTest < ActiveSupport::TestCase test "#last returns the last character" do assert_equal "o", "hello".last - assert_equal 'x', 'x'.last + assert_equal "x", "x".last end test "#last with Integer, returns a substring from the end to position" do assert_equal "llo", "hello".last(3) assert_equal "hello", "hello".last(10) assert_equal "", "hello".last(0) - assert_equal 'x', 'x'.last(4) + assert_equal "x", "x".last(4) end test "#last with Integer >= string length still returns a new string" do @@ -633,14 +633,14 @@ end class StringBehaviourTest < ActiveSupport::TestCase def test_acts_like_string - assert 'Bambi'.acts_like_string? + assert "Bambi".acts_like_string? end end class CoreExtStringMultibyteTest < ActiveSupport::TestCase - UTF8_STRING = 'こにちわ' - ASCII_STRING = 'ohayo'.encode('US-ASCII') - EUC_JP_STRING = 'さよなら'.encode('EUC-JP') + UTF8_STRING = "こにちわ" + ASCII_STRING = "ohayo".encode("US-ASCII") + EUC_JP_STRING = "さよなら".encode("EUC-JP") INVALID_UTF8_STRING = "\270\236\010\210\245" def test_core_ext_adds_mb_chars @@ -820,8 +820,8 @@ class OutputSafetyTest < ActiveSupport::TestCase assert string.html_safe? end - test 'emits normal string yaml' do - assert_equal 'foo'.to_yaml, 'foo'.html_safe.to_yaml(:foo => 1) + test "emits normal string yaml" do + assert_equal "foo".to_yaml, "foo".html_safe.to_yaml(foo: 1) end test "call to_param returns a normal string" do @@ -832,7 +832,7 @@ class OutputSafetyTest < ActiveSupport::TestCase test "ERB::Util.html_escape should escape unsafe characters" do string = '<>&"\'' - expected = '<>&"'' + expected = "<>&"'" assert_equal expected, ERB::Util.html_escape(string) end @@ -848,7 +848,7 @@ class OutputSafetyTest < ActiveSupport::TestCase end test "ERB::Util.html_escape_once only escapes once" do - string = '1 < 2 & 3' + string = "1 < 2 & 3" escaped_string = "1 < 2 & 3" assert_equal escaped_string, ERB::Util.html_escape_once(string) @@ -863,15 +863,15 @@ class OutputSafetyTest < ActiveSupport::TestCase end class StringExcludeTest < ActiveSupport::TestCase - test 'inverse of #include' do - assert_equal false, 'foo'.exclude?('o') - assert_equal true, 'foo'.exclude?('p') + test "inverse of #include" do + assert_equal false, "foo".exclude?("o") + assert_equal true, "foo".exclude?("p") end end class StringIndentTest < ActiveSupport::TestCase - test 'does not indent strings that only contain newlines (edge cases)' do - ['', "\n", "\n" * 7].each do |str| + test "does not indent strings that only contain newlines (edge cases)" do + ["", "\n", "\n" * 7].each do |str| assert_nil str.indent!(8) assert_equal str, str.indent(8) assert_equal str, str.indent(1, "\t") @@ -893,8 +893,8 @@ class StringIndentTest < ActiveSupport::TestCase # Nothing is said about existing indentation that mixes spaces and tabs, so # there is nothing to test. - test 'uses the indent char if passed' do - assert_equal <<EXPECTED, <<ACTUAL.indent(4, '.') + test "uses the indent char if passed" do + assert_equal <<EXPECTED, <<ACTUAL.indent(4, ".") .... def some_method(x, y) .... some_code .... end @@ -904,7 +904,7 @@ EXPECTED end ACTUAL - assert_equal <<EXPECTED, <<ACTUAL.indent(2, ' ') + assert_equal <<EXPECTED, <<ACTUAL.indent(2, " ") def some_method(x, y) some_code end @@ -919,7 +919,7 @@ ACTUAL assert_equal " foo\n\n bar", "foo\n\nbar".indent(1) end - test 'indents blank lines if told so' do + test "indents blank lines if told so" do assert_equal " foo\n \n bar", "foo\n\nbar".indent(1, nil, true) end end diff --git a/activesupport/test/core_ext/time_ext_test.rb b/activesupport/test/core_ext/time_ext_test.rb index 1205797fac..a6c9a7d5a8 100644 --- a/activesupport/test/core_ext/time_ext_test.rb +++ b/activesupport/test/core_ext/time_ext_test.rb @@ -1,7 +1,7 @@ -require 'abstract_unit' -require 'active_support/time' -require 'core_ext/date_and_time_behavior' -require 'time_zone_test_helpers' +require "abstract_unit" +require "active_support/time" +require "core_ext/date_and_time_behavior" +require "time_zone_test_helpers" class TimeExtCalculationsTest < ActiveSupport::TestCase def date_time_init(year,month,day,hour,minute,second,usec=0) @@ -20,42 +20,42 @@ class TimeExtCalculationsTest < ActiveSupport::TestCase end def test_seconds_since_midnight_at_daylight_savings_time_start - with_env_tz 'US/Eastern' do + with_env_tz "US/Eastern" do # dt: US: 2005 April 3rd 2:00am ST => April 3rd 3:00am DT - assert_equal 2*3600-1, Time.local(2005,4,3,1,59,59).seconds_since_midnight, 'just before DST start' - assert_equal 2*3600+1, Time.local(2005,4,3,3, 0, 1).seconds_since_midnight, 'just after DST start' + assert_equal 2*3600-1, Time.local(2005,4,3,1,59,59).seconds_since_midnight, "just before DST start" + assert_equal 2*3600+1, Time.local(2005,4,3,3, 0, 1).seconds_since_midnight, "just after DST start" end - with_env_tz 'NZ' do + with_env_tz "NZ" do # dt: New Zealand: 2006 October 1st 2:00am ST => October 1st 3:00am DT - assert_equal 2*3600-1, Time.local(2006,10,1,1,59,59).seconds_since_midnight, 'just before DST start' - assert_equal 2*3600+1, Time.local(2006,10,1,3, 0, 1).seconds_since_midnight, 'just after DST start' + assert_equal 2*3600-1, Time.local(2006,10,1,1,59,59).seconds_since_midnight, "just before DST start" + assert_equal 2*3600+1, Time.local(2006,10,1,3, 0, 1).seconds_since_midnight, "just after DST start" end end def test_seconds_since_midnight_at_daylight_savings_time_end - with_env_tz 'US/Eastern' do + with_env_tz "US/Eastern" do # st: US: 2005 October 30th 2:00am DT => October 30th 1:00am ST # avoid setting a time between 1:00 and 2:00 since that requires specifying whether DST is active - assert_equal 1*3600-1, Time.local(2005,10,30,0,59,59).seconds_since_midnight, 'just before DST end' - assert_equal 3*3600+1, Time.local(2005,10,30,2, 0, 1).seconds_since_midnight, 'just after DST end' + assert_equal 1*3600-1, Time.local(2005,10,30,0,59,59).seconds_since_midnight, "just before DST end" + assert_equal 3*3600+1, Time.local(2005,10,30,2, 0, 1).seconds_since_midnight, "just after DST end" # now set a time between 1:00 and 2:00 by specifying whether DST is active # uses: Time.local( sec, min, hour, day, month, year, wday, yday, isdst, tz ) - assert_equal 1*3600+30*60, Time.local(0,30,1,30,10,2005,0,0,true,ENV['TZ']).seconds_since_midnight, 'before DST end' - assert_equal 2*3600+30*60, Time.local(0,30,1,30,10,2005,0,0,false,ENV['TZ']).seconds_since_midnight, 'after DST end' + assert_equal 1*3600+30*60, Time.local(0,30,1,30,10,2005,0,0,true,ENV["TZ"]).seconds_since_midnight, "before DST end" + assert_equal 2*3600+30*60, Time.local(0,30,1,30,10,2005,0,0,false,ENV["TZ"]).seconds_since_midnight, "after DST end" end - with_env_tz 'NZ' do + with_env_tz "NZ" do # st: New Zealand: 2006 March 19th 3:00am DT => March 19th 2:00am ST # avoid setting a time between 2:00 and 3:00 since that requires specifying whether DST is active - assert_equal 2*3600-1, Time.local(2006,3,19,1,59,59).seconds_since_midnight, 'just before DST end' - assert_equal 4*3600+1, Time.local(2006,3,19,3, 0, 1).seconds_since_midnight, 'just after DST end' + assert_equal 2*3600-1, Time.local(2006,3,19,1,59,59).seconds_since_midnight, "just before DST end" + assert_equal 4*3600+1, Time.local(2006,3,19,3, 0, 1).seconds_since_midnight, "just after DST end" # now set a time between 2:00 and 3:00 by specifying whether DST is active # uses: Time.local( sec, min, hour, day, month, year, wday, yday, isdst, tz ) - assert_equal 2*3600+30*60, Time.local(0,30,2,19,3,2006,0,0,true, ENV['TZ']).seconds_since_midnight, 'before DST end' - assert_equal 3*3600+30*60, Time.local(0,30,2,19,3,2006,0,0,false,ENV['TZ']).seconds_since_midnight, 'after DST end' + assert_equal 2*3600+30*60, Time.local(0,30,2,19,3,2006,0,0,true, ENV["TZ"]).seconds_since_midnight, "before DST end" + assert_equal 3*3600+30*60, Time.local(0,30,2,19,3,2006,0,0,false,ENV["TZ"]).seconds_since_midnight, "after DST end" end end @@ -68,42 +68,42 @@ class TimeExtCalculationsTest < ActiveSupport::TestCase end def test_seconds_until_end_of_day_at_daylight_savings_time_start - with_env_tz 'US/Eastern' do + with_env_tz "US/Eastern" do # dt: US: 2005 April 3rd 2:00am ST => April 3rd 3:00am DT - assert_equal 21*3600, Time.local(2005,4,3,1,59,59).seconds_until_end_of_day, 'just before DST start' - assert_equal 21*3600-2, Time.local(2005,4,3,3,0,1).seconds_until_end_of_day, 'just after DST start' + assert_equal 21*3600, Time.local(2005,4,3,1,59,59).seconds_until_end_of_day, "just before DST start" + assert_equal 21*3600-2, Time.local(2005,4,3,3,0,1).seconds_until_end_of_day, "just after DST start" end - with_env_tz 'NZ' do + with_env_tz "NZ" do # dt: New Zealand: 2006 October 1st 2:00am ST => October 1st 3:00am DT - assert_equal 21*3600, Time.local(2006,10,1,1,59,59).seconds_until_end_of_day, 'just before DST start' - assert_equal 21*3600-2, Time.local(2006,10,1,3,0,1).seconds_until_end_of_day, 'just after DST start' + assert_equal 21*3600, Time.local(2006,10,1,1,59,59).seconds_until_end_of_day, "just before DST start" + assert_equal 21*3600-2, Time.local(2006,10,1,3,0,1).seconds_until_end_of_day, "just after DST start" end end def test_seconds_until_end_of_day_at_daylight_savings_time_end - with_env_tz 'US/Eastern' do + with_env_tz "US/Eastern" do # st: US: 2005 October 30th 2:00am DT => October 30th 1:00am ST # avoid setting a time between 1:00 and 2:00 since that requires specifying whether DST is active - assert_equal 24*3600, Time.local(2005,10,30,0,59,59).seconds_until_end_of_day, 'just before DST end' - assert_equal 22*3600-2, Time.local(2005,10,30,2,0,1).seconds_until_end_of_day, 'just after DST end' + assert_equal 24*3600, Time.local(2005,10,30,0,59,59).seconds_until_end_of_day, "just before DST end" + assert_equal 22*3600-2, Time.local(2005,10,30,2,0,1).seconds_until_end_of_day, "just after DST end" # now set a time between 1:00 and 2:00 by specifying whether DST is active # uses: Time.local( sec, min, hour, day, month, year, wday, yday, isdst, tz ) - assert_equal 24*3600-30*60-1, Time.local(0,30,1,30,10,2005,0,0,true,ENV['TZ']).seconds_until_end_of_day, 'before DST end' - assert_equal 23*3600-30*60-1, Time.local(0,30,1,30,10,2005,0,0,false,ENV['TZ']).seconds_until_end_of_day, 'after DST end' + assert_equal 24*3600-30*60-1, Time.local(0,30,1,30,10,2005,0,0,true,ENV["TZ"]).seconds_until_end_of_day, "before DST end" + assert_equal 23*3600-30*60-1, Time.local(0,30,1,30,10,2005,0,0,false,ENV["TZ"]).seconds_until_end_of_day, "after DST end" end - with_env_tz 'NZ' do + with_env_tz "NZ" do # st: New Zealand: 2006 March 19th 3:00am DT => March 19th 2:00am ST # avoid setting a time between 2:00 and 3:00 since that requires specifying whether DST is active - assert_equal 23*3600, Time.local(2006,3,19,1,59,59).seconds_until_end_of_day, 'just before DST end' - assert_equal 21*3600-2, Time.local(2006,3,19,3,0,1).seconds_until_end_of_day, 'just after DST end' + assert_equal 23*3600, Time.local(2006,3,19,1,59,59).seconds_until_end_of_day, "just before DST end" + assert_equal 21*3600-2, Time.local(2006,3,19,3,0,1).seconds_until_end_of_day, "just after DST end" # now set a time between 2:00 and 3:00 by specifying whether DST is active # uses: Time.local( sec, min, hour, day, month, year, wday, yday, isdst, tz ) - assert_equal 23*3600-30*60-1, Time.local(0,30,2,19,3,2006,0,0,true, ENV['TZ']).seconds_until_end_of_day, 'before DST end' - assert_equal 22*3600-30*60-1, Time.local(0,30,2,19,3,2006,0,0,false,ENV['TZ']).seconds_until_end_of_day, 'after DST end' + assert_equal 23*3600-30*60-1, Time.local(0,30,2,19,3,2006,0,0,true, ENV["TZ"]).seconds_until_end_of_day, "before DST end" + assert_equal 22*3600-30*60-1, Time.local(0,30,2,19,3,2006,0,0,false,ENV["TZ"]).seconds_until_end_of_day, "after DST end" end end @@ -123,25 +123,25 @@ class TimeExtCalculationsTest < ActiveSupport::TestCase def test_beginning_of_day assert_equal Time.local(2005,2,4,0,0,0), Time.local(2005,2,4,10,10,10).beginning_of_day - with_env_tz 'US/Eastern' do - assert_equal Time.local(2006,4,2,0,0,0), Time.local(2006,4,2,10,10,10).beginning_of_day, 'start DST' - assert_equal Time.local(2006,10,29,0,0,0), Time.local(2006,10,29,10,10,10).beginning_of_day, 'ends DST' + with_env_tz "US/Eastern" do + assert_equal Time.local(2006,4,2,0,0,0), Time.local(2006,4,2,10,10,10).beginning_of_day, "start DST" + assert_equal Time.local(2006,10,29,0,0,0), Time.local(2006,10,29,10,10,10).beginning_of_day, "ends DST" end - with_env_tz 'NZ' do - assert_equal Time.local(2006,3,19,0,0,0), Time.local(2006,3,19,10,10,10).beginning_of_day, 'ends DST' - assert_equal Time.local(2006,10,1,0,0,0), Time.local(2006,10,1,10,10,10).beginning_of_day, 'start DST' + with_env_tz "NZ" do + assert_equal Time.local(2006,3,19,0,0,0), Time.local(2006,3,19,10,10,10).beginning_of_day, "ends DST" + assert_equal Time.local(2006,10,1,0,0,0), Time.local(2006,10,1,10,10,10).beginning_of_day, "start DST" end end def test_middle_of_day assert_equal Time.local(2005,2,4,12,0,0), Time.local(2005,2,4,10,10,10).middle_of_day - with_env_tz 'US/Eastern' do - assert_equal Time.local(2006,4,2,12,0,0), Time.local(2006,4,2,10,10,10).middle_of_day, 'start DST' - assert_equal Time.local(2006,10,29,12,0,0), Time.local(2006,10,29,10,10,10).middle_of_day, 'ends DST' + with_env_tz "US/Eastern" do + assert_equal Time.local(2006,4,2,12,0,0), Time.local(2006,4,2,10,10,10).middle_of_day, "start DST" + assert_equal Time.local(2006,10,29,12,0,0), Time.local(2006,10,29,10,10,10).middle_of_day, "ends DST" end - with_env_tz 'NZ' do - assert_equal Time.local(2006,3,19,12,0,0), Time.local(2006,3,19,10,10,10).middle_of_day, 'ends DST' - assert_equal Time.local(2006,10,1,12,0,0), Time.local(2006,10,1,10,10,10).middle_of_day, 'start DST' + with_env_tz "NZ" do + assert_equal Time.local(2006,3,19,12,0,0), Time.local(2006,3,19,10,10,10).middle_of_day, "ends DST" + assert_equal Time.local(2006,10,1,12,0,0), Time.local(2006,10,1,10,10,10).middle_of_day, "start DST" end end @@ -155,16 +155,16 @@ class TimeExtCalculationsTest < ActiveSupport::TestCase def test_end_of_day assert_equal Time.local(2007,8,12,23,59,59,Rational(999999999, 1000)), Time.local(2007,8,12,10,10,10).end_of_day - with_env_tz 'US/Eastern' do - assert_equal Time.local(2007,4,2,23,59,59,Rational(999999999, 1000)), Time.local(2007,4,2,10,10,10).end_of_day, 'start DST' - assert_equal Time.local(2007,10,29,23,59,59,Rational(999999999, 1000)), Time.local(2007,10,29,10,10,10).end_of_day, 'ends DST' + with_env_tz "US/Eastern" do + assert_equal Time.local(2007,4,2,23,59,59,Rational(999999999, 1000)), Time.local(2007,4,2,10,10,10).end_of_day, "start DST" + assert_equal Time.local(2007,10,29,23,59,59,Rational(999999999, 1000)), Time.local(2007,10,29,10,10,10).end_of_day, "ends DST" end - with_env_tz 'NZ' do - assert_equal Time.local(2006,3,19,23,59,59,Rational(999999999, 1000)), Time.local(2006,3,19,10,10,10).end_of_day, 'ends DST' - assert_equal Time.local(2006,10,1,23,59,59,Rational(999999999, 1000)), Time.local(2006,10,1,10,10,10).end_of_day, 'start DST' + with_env_tz "NZ" do + assert_equal Time.local(2006,3,19,23,59,59,Rational(999999999, 1000)), Time.local(2006,3,19,10,10,10).end_of_day, "ends DST" + assert_equal Time.local(2006,10,1,23,59,59,Rational(999999999, 1000)), Time.local(2006,10,1,10,10,10).end_of_day, "start DST" end - with_env_tz 'Asia/Yekaterinburg' do - assert_equal Time.local(2015, 2, 8, 23, 59, 59, Rational(999999999, 1000)), Time.new(2015, 2, 8, 8, 0, 0, '+05:00').end_of_day + with_env_tz "Asia/Yekaterinburg" do + assert_equal Time.local(2015, 2, 8, 23, 59, 59, Rational(999999999, 1000)), Time.new(2015, 2, 8, 8, 0, 0, "+05:00").end_of_day end end @@ -188,74 +188,74 @@ class TimeExtCalculationsTest < ActiveSupport::TestCase end def test_daylight_savings_time_crossings_backward_start - with_env_tz 'US/Eastern' do + with_env_tz "US/Eastern" do # dt: US: 2005 April 3rd 4:18am - assert_equal Time.local(2005,4,2,3,18,0), Time.local(2005,4,3,4,18,0).ago(24.hours), 'dt-24.hours=>st' - assert_equal Time.local(2005,4,2,3,18,0), Time.local(2005,4,3,4,18,0).ago(86400), 'dt-86400=>st' - assert_equal Time.local(2005,4,2,3,18,0), Time.local(2005,4,3,4,18,0).ago(86400.seconds), 'dt-86400.seconds=>st' + assert_equal Time.local(2005,4,2,3,18,0), Time.local(2005,4,3,4,18,0).ago(24.hours), "dt-24.hours=>st" + assert_equal Time.local(2005,4,2,3,18,0), Time.local(2005,4,3,4,18,0).ago(86400), "dt-86400=>st" + assert_equal Time.local(2005,4,2,3,18,0), Time.local(2005,4,3,4,18,0).ago(86400.seconds), "dt-86400.seconds=>st" - assert_equal Time.local(2005,4,1,4,18,0), Time.local(2005,4,2,4,18,0).ago(24.hours), 'st-24.hours=>st' - assert_equal Time.local(2005,4,1,4,18,0), Time.local(2005,4,2,4,18,0).ago(86400), 'st-86400=>st' - assert_equal Time.local(2005,4,1,4,18,0), Time.local(2005,4,2,4,18,0).ago(86400.seconds), 'st-86400.seconds=>st' + assert_equal Time.local(2005,4,1,4,18,0), Time.local(2005,4,2,4,18,0).ago(24.hours), "st-24.hours=>st" + assert_equal Time.local(2005,4,1,4,18,0), Time.local(2005,4,2,4,18,0).ago(86400), "st-86400=>st" + assert_equal Time.local(2005,4,1,4,18,0), Time.local(2005,4,2,4,18,0).ago(86400.seconds), "st-86400.seconds=>st" end - with_env_tz 'NZ' do + with_env_tz "NZ" do # dt: New Zealand: 2006 October 1st 4:18am - assert_equal Time.local(2006,9,30,3,18,0), Time.local(2006,10,1,4,18,0).ago(24.hours), 'dt-24.hours=>st' - assert_equal Time.local(2006,9,30,3,18,0), Time.local(2006,10,1,4,18,0).ago(86400), 'dt-86400=>st' - assert_equal Time.local(2006,9,30,3,18,0), Time.local(2006,10,1,4,18,0).ago(86400.seconds), 'dt-86400.seconds=>st' + assert_equal Time.local(2006,9,30,3,18,0), Time.local(2006,10,1,4,18,0).ago(24.hours), "dt-24.hours=>st" + assert_equal Time.local(2006,9,30,3,18,0), Time.local(2006,10,1,4,18,0).ago(86400), "dt-86400=>st" + assert_equal Time.local(2006,9,30,3,18,0), Time.local(2006,10,1,4,18,0).ago(86400.seconds), "dt-86400.seconds=>st" - assert_equal Time.local(2006,9,29,4,18,0), Time.local(2006,9,30,4,18,0).ago(24.hours), 'st-24.hours=>st' - assert_equal Time.local(2006,9,29,4,18,0), Time.local(2006,9,30,4,18,0).ago(86400), 'st-86400=>st' - assert_equal Time.local(2006,9,29,4,18,0), Time.local(2006,9,30,4,18,0).ago(86400.seconds), 'st-86400.seconds=>st' + assert_equal Time.local(2006,9,29,4,18,0), Time.local(2006,9,30,4,18,0).ago(24.hours), "st-24.hours=>st" + assert_equal Time.local(2006,9,29,4,18,0), Time.local(2006,9,30,4,18,0).ago(86400), "st-86400=>st" + assert_equal Time.local(2006,9,29,4,18,0), Time.local(2006,9,30,4,18,0).ago(86400.seconds), "st-86400.seconds=>st" end end def test_daylight_savings_time_crossings_backward_end - with_env_tz 'US/Eastern' do + with_env_tz "US/Eastern" do # st: US: 2005 October 30th 4:03am - assert_equal Time.local(2005,10,29,5,3), Time.local(2005,10,30,4,3,0).ago(24.hours), 'st-24.hours=>dt' - assert_equal Time.local(2005,10,29,5,3), Time.local(2005,10,30,4,3,0).ago(86400), 'st-86400=>dt' - assert_equal Time.local(2005,10,29,5,3), Time.local(2005,10,30,4,3,0).ago(86400.seconds), 'st-86400.seconds=>dt' + assert_equal Time.local(2005,10,29,5,3), Time.local(2005,10,30,4,3,0).ago(24.hours), "st-24.hours=>dt" + assert_equal Time.local(2005,10,29,5,3), Time.local(2005,10,30,4,3,0).ago(86400), "st-86400=>dt" + assert_equal Time.local(2005,10,29,5,3), Time.local(2005,10,30,4,3,0).ago(86400.seconds), "st-86400.seconds=>dt" - assert_equal Time.local(2005,10,28,4,3), Time.local(2005,10,29,4,3,0).ago(24.hours), 'dt-24.hours=>dt' - assert_equal Time.local(2005,10,28,4,3), Time.local(2005,10,29,4,3,0).ago(86400), 'dt-86400=>dt' - assert_equal Time.local(2005,10,28,4,3), Time.local(2005,10,29,4,3,0).ago(86400.seconds), 'dt-86400.seconds=>dt' + assert_equal Time.local(2005,10,28,4,3), Time.local(2005,10,29,4,3,0).ago(24.hours), "dt-24.hours=>dt" + assert_equal Time.local(2005,10,28,4,3), Time.local(2005,10,29,4,3,0).ago(86400), "dt-86400=>dt" + assert_equal Time.local(2005,10,28,4,3), Time.local(2005,10,29,4,3,0).ago(86400.seconds), "dt-86400.seconds=>dt" end - with_env_tz 'NZ' do + with_env_tz "NZ" do # st: New Zealand: 2006 March 19th 4:03am - assert_equal Time.local(2006,3,18,5,3), Time.local(2006,3,19,4,3,0).ago(24.hours), 'st-24.hours=>dt' - assert_equal Time.local(2006,3,18,5,3), Time.local(2006,3,19,4,3,0).ago(86400), 'st-86400=>dt' - assert_equal Time.local(2006,3,18,5,3), Time.local(2006,3,19,4,3,0).ago(86400.seconds), 'st-86400.seconds=>dt' + assert_equal Time.local(2006,3,18,5,3), Time.local(2006,3,19,4,3,0).ago(24.hours), "st-24.hours=>dt" + assert_equal Time.local(2006,3,18,5,3), Time.local(2006,3,19,4,3,0).ago(86400), "st-86400=>dt" + assert_equal Time.local(2006,3,18,5,3), Time.local(2006,3,19,4,3,0).ago(86400.seconds), "st-86400.seconds=>dt" - assert_equal Time.local(2006,3,17,4,3), Time.local(2006,3,18,4,3,0).ago(24.hours), 'dt-24.hours=>dt' - assert_equal Time.local(2006,3,17,4,3), Time.local(2006,3,18,4,3,0).ago(86400), 'dt-86400=>dt' - assert_equal Time.local(2006,3,17,4,3), Time.local(2006,3,18,4,3,0).ago(86400.seconds), 'dt-86400.seconds=>dt' + assert_equal Time.local(2006,3,17,4,3), Time.local(2006,3,18,4,3,0).ago(24.hours), "dt-24.hours=>dt" + assert_equal Time.local(2006,3,17,4,3), Time.local(2006,3,18,4,3,0).ago(86400), "dt-86400=>dt" + assert_equal Time.local(2006,3,17,4,3), Time.local(2006,3,18,4,3,0).ago(86400.seconds), "dt-86400.seconds=>dt" end end def test_daylight_savings_time_crossings_backward_start_1day - with_env_tz 'US/Eastern' do + with_env_tz "US/Eastern" do # dt: US: 2005 April 3rd 4:18am - assert_equal Time.local(2005,4,2,4,18,0), Time.local(2005,4,3,4,18,0).ago(1.day), 'dt-1.day=>st' - assert_equal Time.local(2005,4,1,4,18,0), Time.local(2005,4,2,4,18,0).ago(1.day), 'st-1.day=>st' + assert_equal Time.local(2005,4,2,4,18,0), Time.local(2005,4,3,4,18,0).ago(1.day), "dt-1.day=>st" + assert_equal Time.local(2005,4,1,4,18,0), Time.local(2005,4,2,4,18,0).ago(1.day), "st-1.day=>st" end - with_env_tz 'NZ' do + with_env_tz "NZ" do # dt: New Zealand: 2006 October 1st 4:18am - assert_equal Time.local(2006,9,30,4,18,0), Time.local(2006,10,1,4,18,0).ago(1.day), 'dt-1.day=>st' - assert_equal Time.local(2006,9,29,4,18,0), Time.local(2006,9,30,4,18,0).ago(1.day), 'st-1.day=>st' + assert_equal Time.local(2006,9,30,4,18,0), Time.local(2006,10,1,4,18,0).ago(1.day), "dt-1.day=>st" + assert_equal Time.local(2006,9,29,4,18,0), Time.local(2006,9,30,4,18,0).ago(1.day), "st-1.day=>st" end end def test_daylight_savings_time_crossings_backward_end_1day - with_env_tz 'US/Eastern' do + with_env_tz "US/Eastern" do # st: US: 2005 October 30th 4:03am - assert_equal Time.local(2005,10,29,4,3), Time.local(2005,10,30,4,3,0).ago(1.day), 'st-1.day=>dt' - assert_equal Time.local(2005,10,28,4,3), Time.local(2005,10,29,4,3,0).ago(1.day), 'dt-1.day=>dt' + assert_equal Time.local(2005,10,29,4,3), Time.local(2005,10,30,4,3,0).ago(1.day), "st-1.day=>dt" + assert_equal Time.local(2005,10,28,4,3), Time.local(2005,10,29,4,3,0).ago(1.day), "dt-1.day=>dt" end - with_env_tz 'NZ' do + with_env_tz "NZ" do # st: New Zealand: 2006 March 19th 4:03am - assert_equal Time.local(2006,3,18,4,3), Time.local(2006,3,19,4,3,0).ago(1.day), 'st-1.day=>dt' - assert_equal Time.local(2006,3,17,4,3), Time.local(2006,3,18,4,3,0).ago(1.day), 'dt-1.day=>dt' + assert_equal Time.local(2006,3,18,4,3), Time.local(2006,3,19,4,3,0).ago(1.day), "st-1.day=>dt" + assert_equal Time.local(2006,3,17,4,3), Time.local(2006,3,18,4,3,0).ago(1.day), "dt-1.day=>dt" end end @@ -269,250 +269,250 @@ class TimeExtCalculationsTest < ActiveSupport::TestCase end def test_daylight_savings_time_crossings_forward_start - with_env_tz 'US/Eastern' do + with_env_tz "US/Eastern" do # st: US: 2005 April 2nd 7:27pm - assert_equal Time.local(2005,4,3,20,27,0), Time.local(2005,4,2,19,27,0).since(24.hours), 'st+24.hours=>dt' - assert_equal Time.local(2005,4,3,20,27,0), Time.local(2005,4,2,19,27,0).since(86400), 'st+86400=>dt' - assert_equal Time.local(2005,4,3,20,27,0), Time.local(2005,4,2,19,27,0).since(86400.seconds), 'st+86400.seconds=>dt' + assert_equal Time.local(2005,4,3,20,27,0), Time.local(2005,4,2,19,27,0).since(24.hours), "st+24.hours=>dt" + assert_equal Time.local(2005,4,3,20,27,0), Time.local(2005,4,2,19,27,0).since(86400), "st+86400=>dt" + assert_equal Time.local(2005,4,3,20,27,0), Time.local(2005,4,2,19,27,0).since(86400.seconds), "st+86400.seconds=>dt" - assert_equal Time.local(2005,4,4,19,27,0), Time.local(2005,4,3,19,27,0).since(24.hours), 'dt+24.hours=>dt' - assert_equal Time.local(2005,4,4,19,27,0), Time.local(2005,4,3,19,27,0).since(86400), 'dt+86400=>dt' - assert_equal Time.local(2005,4,4,19,27,0), Time.local(2005,4,3,19,27,0).since(86400.seconds), 'dt+86400.seconds=>dt' + assert_equal Time.local(2005,4,4,19,27,0), Time.local(2005,4,3,19,27,0).since(24.hours), "dt+24.hours=>dt" + assert_equal Time.local(2005,4,4,19,27,0), Time.local(2005,4,3,19,27,0).since(86400), "dt+86400=>dt" + assert_equal Time.local(2005,4,4,19,27,0), Time.local(2005,4,3,19,27,0).since(86400.seconds), "dt+86400.seconds=>dt" end - with_env_tz 'NZ' do + with_env_tz "NZ" do # st: New Zealand: 2006 September 30th 7:27pm - assert_equal Time.local(2006,10,1,20,27,0), Time.local(2006,9,30,19,27,0).since(24.hours), 'st+24.hours=>dt' - assert_equal Time.local(2006,10,1,20,27,0), Time.local(2006,9,30,19,27,0).since(86400), 'st+86400=>dt' - assert_equal Time.local(2006,10,1,20,27,0), Time.local(2006,9,30,19,27,0).since(86400.seconds), 'st+86400.seconds=>dt' + assert_equal Time.local(2006,10,1,20,27,0), Time.local(2006,9,30,19,27,0).since(24.hours), "st+24.hours=>dt" + assert_equal Time.local(2006,10,1,20,27,0), Time.local(2006,9,30,19,27,0).since(86400), "st+86400=>dt" + assert_equal Time.local(2006,10,1,20,27,0), Time.local(2006,9,30,19,27,0).since(86400.seconds), "st+86400.seconds=>dt" - assert_equal Time.local(2006,10,2,19,27,0), Time.local(2006,10,1,19,27,0).since(24.hours), 'dt+24.hours=>dt' - assert_equal Time.local(2006,10,2,19,27,0), Time.local(2006,10,1,19,27,0).since(86400), 'dt+86400=>dt' - assert_equal Time.local(2006,10,2,19,27,0), Time.local(2006,10,1,19,27,0).since(86400.seconds), 'dt+86400.seconds=>dt' + assert_equal Time.local(2006,10,2,19,27,0), Time.local(2006,10,1,19,27,0).since(24.hours), "dt+24.hours=>dt" + assert_equal Time.local(2006,10,2,19,27,0), Time.local(2006,10,1,19,27,0).since(86400), "dt+86400=>dt" + assert_equal Time.local(2006,10,2,19,27,0), Time.local(2006,10,1,19,27,0).since(86400.seconds), "dt+86400.seconds=>dt" end end def test_daylight_savings_time_crossings_forward_start_1day - with_env_tz 'US/Eastern' do + with_env_tz "US/Eastern" do # st: US: 2005 April 2nd 7:27pm - assert_equal Time.local(2005,4,3,19,27,0), Time.local(2005,4,2,19,27,0).since(1.day), 'st+1.day=>dt' - assert_equal Time.local(2005,4,4,19,27,0), Time.local(2005,4,3,19,27,0).since(1.day), 'dt+1.day=>dt' + assert_equal Time.local(2005,4,3,19,27,0), Time.local(2005,4,2,19,27,0).since(1.day), "st+1.day=>dt" + assert_equal Time.local(2005,4,4,19,27,0), Time.local(2005,4,3,19,27,0).since(1.day), "dt+1.day=>dt" end - with_env_tz 'NZ' do + with_env_tz "NZ" do # st: New Zealand: 2006 September 30th 7:27pm - assert_equal Time.local(2006,10,1,19,27,0), Time.local(2006,9,30,19,27,0).since(1.day), 'st+1.day=>dt' - assert_equal Time.local(2006,10,2,19,27,0), Time.local(2006,10,1,19,27,0).since(1.day), 'dt+1.day=>dt' + assert_equal Time.local(2006,10,1,19,27,0), Time.local(2006,9,30,19,27,0).since(1.day), "st+1.day=>dt" + assert_equal Time.local(2006,10,2,19,27,0), Time.local(2006,10,1,19,27,0).since(1.day), "dt+1.day=>dt" end end def test_daylight_savings_time_crossings_forward_start_tomorrow - with_env_tz 'US/Eastern' do + with_env_tz "US/Eastern" do # st: US: 2005 April 2nd 7:27pm - assert_equal Time.local(2005,4,3,19,27,0), Time.local(2005,4,2,19,27,0).tomorrow, 'st+1.day=>dt' - assert_equal Time.local(2005,4,4,19,27,0), Time.local(2005,4,3,19,27,0).tomorrow, 'dt+1.day=>dt' + assert_equal Time.local(2005,4,3,19,27,0), Time.local(2005,4,2,19,27,0).tomorrow, "st+1.day=>dt" + assert_equal Time.local(2005,4,4,19,27,0), Time.local(2005,4,3,19,27,0).tomorrow, "dt+1.day=>dt" end - with_env_tz 'NZ' do + with_env_tz "NZ" do # st: New Zealand: 2006 September 30th 7:27pm - assert_equal Time.local(2006,10,1,19,27,0), Time.local(2006,9,30,19,27,0).tomorrow, 'st+1.day=>dt' - assert_equal Time.local(2006,10,2,19,27,0), Time.local(2006,10,1,19,27,0).tomorrow, 'dt+1.day=>dt' + assert_equal Time.local(2006,10,1,19,27,0), Time.local(2006,9,30,19,27,0).tomorrow, "st+1.day=>dt" + assert_equal Time.local(2006,10,2,19,27,0), Time.local(2006,10,1,19,27,0).tomorrow, "dt+1.day=>dt" end end def test_daylight_savings_time_crossings_backward_start_yesterday - with_env_tz 'US/Eastern' do + with_env_tz "US/Eastern" do # st: US: 2005 April 2nd 7:27pm - assert_equal Time.local(2005,4,2,19,27,0), Time.local(2005,4,3,19,27,0).yesterday, 'dt-1.day=>st' - assert_equal Time.local(2005,4,3,19,27,0), Time.local(2005,4,4,19,27,0).yesterday, 'dt-1.day=>dt' + assert_equal Time.local(2005,4,2,19,27,0), Time.local(2005,4,3,19,27,0).yesterday, "dt-1.day=>st" + assert_equal Time.local(2005,4,3,19,27,0), Time.local(2005,4,4,19,27,0).yesterday, "dt-1.day=>dt" end - with_env_tz 'NZ' do + with_env_tz "NZ" do # st: New Zealand: 2006 September 30th 7:27pm - assert_equal Time.local(2006,9,30,19,27,0), Time.local(2006,10,1,19,27,0).yesterday, 'dt-1.day=>st' - assert_equal Time.local(2006,10,1,19,27,0), Time.local(2006,10,2,19,27,0).yesterday, 'dt-1.day=>dt' + assert_equal Time.local(2006,9,30,19,27,0), Time.local(2006,10,1,19,27,0).yesterday, "dt-1.day=>st" + assert_equal Time.local(2006,10,1,19,27,0), Time.local(2006,10,2,19,27,0).yesterday, "dt-1.day=>dt" end end def test_daylight_savings_time_crossings_forward_end - with_env_tz 'US/Eastern' do + with_env_tz "US/Eastern" do # dt: US: 2005 October 30th 12:45am - assert_equal Time.local(2005,10,30,23,45,0), Time.local(2005,10,30,0,45,0).since(24.hours), 'dt+24.hours=>st' - assert_equal Time.local(2005,10,30,23,45,0), Time.local(2005,10,30,0,45,0).since(86400), 'dt+86400=>st' - assert_equal Time.local(2005,10,30,23,45,0), Time.local(2005,10,30,0,45,0).since(86400.seconds), 'dt+86400.seconds=>st' + assert_equal Time.local(2005,10,30,23,45,0), Time.local(2005,10,30,0,45,0).since(24.hours), "dt+24.hours=>st" + assert_equal Time.local(2005,10,30,23,45,0), Time.local(2005,10,30,0,45,0).since(86400), "dt+86400=>st" + assert_equal Time.local(2005,10,30,23,45,0), Time.local(2005,10,30,0,45,0).since(86400.seconds), "dt+86400.seconds=>st" - assert_equal Time.local(2005,11, 1,0,45,0), Time.local(2005,10,31,0,45,0).since(24.hours), 'st+24.hours=>st' - assert_equal Time.local(2005,11, 1,0,45,0), Time.local(2005,10,31,0,45,0).since(86400), 'st+86400=>st' - assert_equal Time.local(2005,11, 1,0,45,0), Time.local(2005,10,31,0,45,0).since(86400.seconds), 'st+86400.seconds=>st' + assert_equal Time.local(2005,11, 1,0,45,0), Time.local(2005,10,31,0,45,0).since(24.hours), "st+24.hours=>st" + assert_equal Time.local(2005,11, 1,0,45,0), Time.local(2005,10,31,0,45,0).since(86400), "st+86400=>st" + assert_equal Time.local(2005,11, 1,0,45,0), Time.local(2005,10,31,0,45,0).since(86400.seconds), "st+86400.seconds=>st" end - with_env_tz 'NZ' do + with_env_tz "NZ" do # dt: New Zealand: 2006 March 19th 1:45am - assert_equal Time.local(2006,3,20,0,45,0), Time.local(2006,3,19,1,45,0).since(24.hours), 'dt+24.hours=>st' - assert_equal Time.local(2006,3,20,0,45,0), Time.local(2006,3,19,1,45,0).since(86400), 'dt+86400=>st' - assert_equal Time.local(2006,3,20,0,45,0), Time.local(2006,3,19,1,45,0).since(86400.seconds), 'dt+86400.seconds=>st' + assert_equal Time.local(2006,3,20,0,45,0), Time.local(2006,3,19,1,45,0).since(24.hours), "dt+24.hours=>st" + assert_equal Time.local(2006,3,20,0,45,0), Time.local(2006,3,19,1,45,0).since(86400), "dt+86400=>st" + assert_equal Time.local(2006,3,20,0,45,0), Time.local(2006,3,19,1,45,0).since(86400.seconds), "dt+86400.seconds=>st" - assert_equal Time.local(2006,3,21,1,45,0), Time.local(2006,3,20,1,45,0).since(24.hours), 'st+24.hours=>st' - assert_equal Time.local(2006,3,21,1,45,0), Time.local(2006,3,20,1,45,0).since(86400), 'st+86400=>st' - assert_equal Time.local(2006,3,21,1,45,0), Time.local(2006,3,20,1,45,0).since(86400.seconds), 'st+86400.seconds=>st' + assert_equal Time.local(2006,3,21,1,45,0), Time.local(2006,3,20,1,45,0).since(24.hours), "st+24.hours=>st" + assert_equal Time.local(2006,3,21,1,45,0), Time.local(2006,3,20,1,45,0).since(86400), "st+86400=>st" + assert_equal Time.local(2006,3,21,1,45,0), Time.local(2006,3,20,1,45,0).since(86400.seconds), "st+86400.seconds=>st" end end def test_daylight_savings_time_crossings_forward_end_1day - with_env_tz 'US/Eastern' do + with_env_tz "US/Eastern" do # dt: US: 2005 October 30th 12:45am - assert_equal Time.local(2005,10,31,0,45,0), Time.local(2005,10,30,0,45,0).since(1.day), 'dt+1.day=>st' - assert_equal Time.local(2005,11, 1,0,45,0), Time.local(2005,10,31,0,45,0).since(1.day), 'st+1.day=>st' + assert_equal Time.local(2005,10,31,0,45,0), Time.local(2005,10,30,0,45,0).since(1.day), "dt+1.day=>st" + assert_equal Time.local(2005,11, 1,0,45,0), Time.local(2005,10,31,0,45,0).since(1.day), "st+1.day=>st" end - with_env_tz 'NZ' do + with_env_tz "NZ" do # dt: New Zealand: 2006 March 19th 1:45am - assert_equal Time.local(2006,3,20,1,45,0), Time.local(2006,3,19,1,45,0).since(1.day), 'dt+1.day=>st' - assert_equal Time.local(2006,3,21,1,45,0), Time.local(2006,3,20,1,45,0).since(1.day), 'st+1.day=>st' + assert_equal Time.local(2006,3,20,1,45,0), Time.local(2006,3,19,1,45,0).since(1.day), "dt+1.day=>st" + assert_equal Time.local(2006,3,21,1,45,0), Time.local(2006,3,20,1,45,0).since(1.day), "st+1.day=>st" end end def test_daylight_savings_time_crossings_forward_end_tomorrow - with_env_tz 'US/Eastern' do + with_env_tz "US/Eastern" do # dt: US: 2005 October 30th 12:45am - assert_equal Time.local(2005,10,31,0,45,0), Time.local(2005,10,30,0,45,0).tomorrow, 'dt+1.day=>st' - assert_equal Time.local(2005,11, 1,0,45,0), Time.local(2005,10,31,0,45,0).tomorrow, 'st+1.day=>st' + assert_equal Time.local(2005,10,31,0,45,0), Time.local(2005,10,30,0,45,0).tomorrow, "dt+1.day=>st" + assert_equal Time.local(2005,11, 1,0,45,0), Time.local(2005,10,31,0,45,0).tomorrow, "st+1.day=>st" end - with_env_tz 'NZ' do + with_env_tz "NZ" do # dt: New Zealand: 2006 March 19th 1:45am - assert_equal Time.local(2006,3,20,1,45,0), Time.local(2006,3,19,1,45,0).tomorrow, 'dt+1.day=>st' - assert_equal Time.local(2006,3,21,1,45,0), Time.local(2006,3,20,1,45,0).tomorrow, 'st+1.day=>st' + assert_equal Time.local(2006,3,20,1,45,0), Time.local(2006,3,19,1,45,0).tomorrow, "dt+1.day=>st" + assert_equal Time.local(2006,3,21,1,45,0), Time.local(2006,3,20,1,45,0).tomorrow, "st+1.day=>st" end end def test_daylight_savings_time_crossings_backward_end_yesterday - with_env_tz 'US/Eastern' do + with_env_tz "US/Eastern" do # dt: US: 2005 October 30th 12:45am - assert_equal Time.local(2005,10,30,0,45,0), Time.local(2005,10,31,0,45,0).yesterday, 'st-1.day=>dt' - assert_equal Time.local(2005,10, 31,0,45,0), Time.local(2005,11,1,0,45,0).yesterday, 'st-1.day=>st' + assert_equal Time.local(2005,10,30,0,45,0), Time.local(2005,10,31,0,45,0).yesterday, "st-1.day=>dt" + assert_equal Time.local(2005,10, 31,0,45,0), Time.local(2005,11,1,0,45,0).yesterday, "st-1.day=>st" end - with_env_tz 'NZ' do + with_env_tz "NZ" do # dt: New Zealand: 2006 March 19th 1:45am - assert_equal Time.local(2006,3,19,1,45,0), Time.local(2006,3,20,1,45,0).yesterday, 'st-1.day=>dt' - assert_equal Time.local(2006,3,20,1,45,0), Time.local(2006,3,21,1,45,0).yesterday, 'st-1.day=>st' + assert_equal Time.local(2006,3,19,1,45,0), Time.local(2006,3,20,1,45,0).yesterday, "st-1.day=>dt" + assert_equal Time.local(2006,3,20,1,45,0), Time.local(2006,3,21,1,45,0).yesterday, "st-1.day=>st" end end def test_change - assert_equal Time.local(2006,2,22,15,15,10), Time.local(2005,2,22,15,15,10).change(:year => 2006) - assert_equal Time.local(2005,6,22,15,15,10), Time.local(2005,2,22,15,15,10).change(:month => 6) - assert_equal Time.local(2012,9,22,15,15,10), Time.local(2005,2,22,15,15,10).change(:year => 2012, :month => 9) - assert_equal Time.local(2005,2,22,16), Time.local(2005,2,22,15,15,10).change(:hour => 16) - assert_equal Time.local(2005,2,22,16,45), Time.local(2005,2,22,15,15,10).change(:hour => 16, :min => 45) - assert_equal Time.local(2005,2,22,15,45), Time.local(2005,2,22,15,15,10).change(:min => 45) - - assert_equal Time.local(2005,1,2, 5, 0, 0, 0), Time.local(2005,1,2,11,22,33,44).change(:hour => 5) - assert_equal Time.local(2005,1,2,11, 6, 0, 0), Time.local(2005,1,2,11,22,33,44).change(:min => 6) - assert_equal Time.local(2005,1,2,11,22, 7, 0), Time.local(2005,1,2,11,22,33,44).change(:sec => 7) - assert_equal Time.local(2005,1,2,11,22,33, 8), Time.local(2005,1,2,11,22,33,44).change(:usec => 8) - assert_equal Time.local(2005,1,2,11,22,33, 8), Time.local(2005,1,2,11,22,33,2).change(:nsec => 8000) - assert_raise(ArgumentError) { Time.local(2005,1,2,11,22,33, 8).change(:usec => 1, :nsec => 1) } - assert_nothing_raised { Time.new(2015, 5, 9, 10, 00, 00, '+03:00').change(nsec: 999999999) } + assert_equal Time.local(2006,2,22,15,15,10), Time.local(2005,2,22,15,15,10).change(year: 2006) + assert_equal Time.local(2005,6,22,15,15,10), Time.local(2005,2,22,15,15,10).change(month: 6) + assert_equal Time.local(2012,9,22,15,15,10), Time.local(2005,2,22,15,15,10).change(year: 2012, month: 9) + assert_equal Time.local(2005,2,22,16), Time.local(2005,2,22,15,15,10).change(hour: 16) + assert_equal Time.local(2005,2,22,16,45), Time.local(2005,2,22,15,15,10).change(hour: 16, min: 45) + assert_equal Time.local(2005,2,22,15,45), Time.local(2005,2,22,15,15,10).change(min: 45) + + assert_equal Time.local(2005,1,2, 5, 0, 0, 0), Time.local(2005,1,2,11,22,33,44).change(hour: 5) + assert_equal Time.local(2005,1,2,11, 6, 0, 0), Time.local(2005,1,2,11,22,33,44).change(min: 6) + assert_equal Time.local(2005,1,2,11,22, 7, 0), Time.local(2005,1,2,11,22,33,44).change(sec: 7) + assert_equal Time.local(2005,1,2,11,22,33, 8), Time.local(2005,1,2,11,22,33,44).change(usec: 8) + assert_equal Time.local(2005,1,2,11,22,33, 8), Time.local(2005,1,2,11,22,33,2).change(nsec: 8000) + assert_raise(ArgumentError) { Time.local(2005,1,2,11,22,33, 8).change(usec: 1, nsec: 1) } + assert_nothing_raised { Time.new(2015, 5, 9, 10, 00, 00, "+03:00").change(nsec: 999999999) } end def test_utc_change - assert_equal Time.utc(2006,2,22,15,15,10), Time.utc(2005,2,22,15,15,10).change(:year => 2006) - assert_equal Time.utc(2005,6,22,15,15,10), Time.utc(2005,2,22,15,15,10).change(:month => 6) - assert_equal Time.utc(2012,9,22,15,15,10), Time.utc(2005,2,22,15,15,10).change(:year => 2012, :month => 9) - assert_equal Time.utc(2005,2,22,16), Time.utc(2005,2,22,15,15,10).change(:hour => 16) - assert_equal Time.utc(2005,2,22,16,45), Time.utc(2005,2,22,15,15,10).change(:hour => 16, :min => 45) - assert_equal Time.utc(2005,2,22,15,45), Time.utc(2005,2,22,15,15,10).change(:min => 45) - assert_equal Time.utc(2005,1,2,11,22,33,8), Time.utc(2005,1,2,11,22,33,2).change(:nsec => 8000) + assert_equal Time.utc(2006,2,22,15,15,10), Time.utc(2005,2,22,15,15,10).change(year: 2006) + assert_equal Time.utc(2005,6,22,15,15,10), Time.utc(2005,2,22,15,15,10).change(month: 6) + assert_equal Time.utc(2012,9,22,15,15,10), Time.utc(2005,2,22,15,15,10).change(year: 2012, month: 9) + assert_equal Time.utc(2005,2,22,16), Time.utc(2005,2,22,15,15,10).change(hour: 16) + assert_equal Time.utc(2005,2,22,16,45), Time.utc(2005,2,22,15,15,10).change(hour: 16, min: 45) + assert_equal Time.utc(2005,2,22,15,45), Time.utc(2005,2,22,15,15,10).change(min: 45) + assert_equal Time.utc(2005,1,2,11,22,33,8), Time.utc(2005,1,2,11,22,33,2).change(nsec: 8000) end def test_offset_change - assert_equal Time.new(2006,2,22,15,15,10,"-08:00"), Time.new(2005,2,22,15,15,10,"-08:00").change(:year => 2006) - assert_equal Time.new(2005,6,22,15,15,10,"-08:00"), Time.new(2005,2,22,15,15,10,"-08:00").change(:month => 6) - assert_equal Time.new(2012,9,22,15,15,10,"-08:00"), Time.new(2005,2,22,15,15,10,"-08:00").change(:year => 2012, :month => 9) - assert_equal Time.new(2005,2,22,16,0,0,"-08:00"), Time.new(2005,2,22,15,15,10,"-08:00").change(:hour => 16) - assert_equal Time.new(2005,2,22,16,45,0,"-08:00"), Time.new(2005,2,22,15,15,10,"-08:00").change(:hour => 16, :min => 45) - assert_equal Time.new(2005,2,22,15,45,0,"-08:00"), Time.new(2005,2,22,15,15,10,"-08:00").change(:min => 45) - assert_equal Time.new(2005,2,22,15,15,10,"-08:00"), Time.new(2005,2,22,15,15,0,"-08:00").change(:sec => 10) - assert_equal 10, Time.new(2005,2,22,15,15,0,"-08:00").change(:usec => 10).usec - assert_equal 10, Time.new(2005,2,22,15,15,0,"-08:00").change(:nsec => 10).nsec - assert_raise(ArgumentError) { Time.new(2005, 2, 22, 15, 15, 45, "-08:00").change(:usec => 1000000) } - assert_raise(ArgumentError) { Time.new(2005, 2, 22, 15, 15, 45, "-08:00").change(:nsec => 1000000000) } + assert_equal Time.new(2006,2,22,15,15,10,"-08:00"), Time.new(2005,2,22,15,15,10,"-08:00").change(year: 2006) + assert_equal Time.new(2005,6,22,15,15,10,"-08:00"), Time.new(2005,2,22,15,15,10,"-08:00").change(month: 6) + assert_equal Time.new(2012,9,22,15,15,10,"-08:00"), Time.new(2005,2,22,15,15,10,"-08:00").change(year: 2012, month: 9) + assert_equal Time.new(2005,2,22,16,0,0,"-08:00"), Time.new(2005,2,22,15,15,10,"-08:00").change(hour: 16) + assert_equal Time.new(2005,2,22,16,45,0,"-08:00"), Time.new(2005,2,22,15,15,10,"-08:00").change(hour: 16, min: 45) + assert_equal Time.new(2005,2,22,15,45,0,"-08:00"), Time.new(2005,2,22,15,15,10,"-08:00").change(min: 45) + assert_equal Time.new(2005,2,22,15,15,10,"-08:00"), Time.new(2005,2,22,15,15,0,"-08:00").change(sec: 10) + assert_equal 10, Time.new(2005,2,22,15,15,0,"-08:00").change(usec: 10).usec + assert_equal 10, Time.new(2005,2,22,15,15,0,"-08:00").change(nsec: 10).nsec + assert_raise(ArgumentError) { Time.new(2005, 2, 22, 15, 15, 45, "-08:00").change(usec: 1000000) } + assert_raise(ArgumentError) { Time.new(2005, 2, 22, 15, 15, 45, "-08:00").change(nsec: 1000000000) } end def test_advance - assert_equal Time.local(2006,2,28,15,15,10), Time.local(2005,2,28,15,15,10).advance(:years => 1) - assert_equal Time.local(2005,6,28,15,15,10), Time.local(2005,2,28,15,15,10).advance(:months => 4) - assert_equal Time.local(2005,3,21,15,15,10), Time.local(2005,2,28,15,15,10).advance(:weeks => 3) - assert_equal Time.local(2005,3,25,3,15,10), Time.local(2005,2,28,15,15,10).advance(:weeks => 3.5) - assert_in_delta Time.local(2005,3,26,12,51,10), Time.local(2005,2,28,15,15,10).advance(:weeks => 3.7), 1 - assert_equal Time.local(2005,3,5,15,15,10), Time.local(2005,2,28,15,15,10).advance(:days => 5) - assert_equal Time.local(2005,3,6,3,15,10), Time.local(2005,2,28,15,15,10).advance(:days => 5.5) - assert_in_delta Time.local(2005,3,6,8,3,10), Time.local(2005,2,28,15,15,10).advance(:days => 5.7), 1 - assert_equal Time.local(2012,9,28,15,15,10), Time.local(2005,2,28,15,15,10).advance(:years => 7, :months => 7) - assert_equal Time.local(2013,10,3,15,15,10), Time.local(2005,2,28,15,15,10).advance(:years => 7, :months => 19, :days => 5) - assert_equal Time.local(2013,10,17,15,15,10), Time.local(2005,2,28,15,15,10).advance(:years => 7, :months => 19, :weeks => 2, :days => 5) - assert_equal Time.local(2001,12,27,15,15,10), Time.local(2005,2,28,15,15,10).advance(:years => -3, :months => -2, :days => -1) - assert_equal Time.local(2005,2,28,15,15,10), Time.local(2004,2,29,15,15,10).advance(:years => 1) #leap day plus one year - assert_equal Time.local(2005,2,28,20,15,10), Time.local(2005,2,28,15,15,10).advance(:hours => 5) - assert_equal Time.local(2005,2,28,15,22,10), Time.local(2005,2,28,15,15,10).advance(:minutes => 7) - assert_equal Time.local(2005,2,28,15,15,19), Time.local(2005,2,28,15,15,10).advance(:seconds => 9) - assert_equal Time.local(2005,2,28,20,22,19), Time.local(2005,2,28,15,15,10).advance(:hours => 5, :minutes => 7, :seconds => 9) - assert_equal Time.local(2005,2,28,10,8,1), Time.local(2005,2,28,15,15,10).advance(:hours => -5, :minutes => -7, :seconds => -9) - assert_equal Time.local(2013,10,17,20,22,19), Time.local(2005,2,28,15,15,10).advance(:years => 7, :months => 19, :weeks => 2, :days => 5, :hours => 5, :minutes => 7, :seconds => 9) + assert_equal Time.local(2006,2,28,15,15,10), Time.local(2005,2,28,15,15,10).advance(years: 1) + assert_equal Time.local(2005,6,28,15,15,10), Time.local(2005,2,28,15,15,10).advance(months: 4) + assert_equal Time.local(2005,3,21,15,15,10), Time.local(2005,2,28,15,15,10).advance(weeks: 3) + assert_equal Time.local(2005,3,25,3,15,10), Time.local(2005,2,28,15,15,10).advance(weeks: 3.5) + assert_in_delta Time.local(2005,3,26,12,51,10), Time.local(2005,2,28,15,15,10).advance(weeks: 3.7), 1 + assert_equal Time.local(2005,3,5,15,15,10), Time.local(2005,2,28,15,15,10).advance(days: 5) + assert_equal Time.local(2005,3,6,3,15,10), Time.local(2005,2,28,15,15,10).advance(days: 5.5) + assert_in_delta Time.local(2005,3,6,8,3,10), Time.local(2005,2,28,15,15,10).advance(days: 5.7), 1 + assert_equal Time.local(2012,9,28,15,15,10), Time.local(2005,2,28,15,15,10).advance(years: 7, months: 7) + assert_equal Time.local(2013,10,3,15,15,10), Time.local(2005,2,28,15,15,10).advance(years: 7, months: 19, days: 5) + assert_equal Time.local(2013,10,17,15,15,10), Time.local(2005,2,28,15,15,10).advance(years: 7, months: 19, weeks: 2, days: 5) + assert_equal Time.local(2001,12,27,15,15,10), Time.local(2005,2,28,15,15,10).advance(years: -3, months: -2, days: -1) + assert_equal Time.local(2005,2,28,15,15,10), Time.local(2004,2,29,15,15,10).advance(years: 1) #leap day plus one year + assert_equal Time.local(2005,2,28,20,15,10), Time.local(2005,2,28,15,15,10).advance(hours: 5) + assert_equal Time.local(2005,2,28,15,22,10), Time.local(2005,2,28,15,15,10).advance(minutes: 7) + assert_equal Time.local(2005,2,28,15,15,19), Time.local(2005,2,28,15,15,10).advance(seconds: 9) + assert_equal Time.local(2005,2,28,20,22,19), Time.local(2005,2,28,15,15,10).advance(hours: 5, minutes: 7, seconds: 9) + assert_equal Time.local(2005,2,28,10,8,1), Time.local(2005,2,28,15,15,10).advance(hours: -5, minutes: -7, seconds: -9) + assert_equal Time.local(2013,10,17,20,22,19), Time.local(2005,2,28,15,15,10).advance(years: 7, months: 19, weeks: 2, days: 5, hours: 5, minutes: 7, seconds: 9) end def test_utc_advance - assert_equal Time.utc(2006,2,22,15,15,10), Time.utc(2005,2,22,15,15,10).advance(:years => 1) - assert_equal Time.utc(2005,6,22,15,15,10), Time.utc(2005,2,22,15,15,10).advance(:months => 4) - assert_equal Time.utc(2005,3,21,15,15,10), Time.utc(2005,2,28,15,15,10).advance(:weeks => 3) - assert_equal Time.utc(2005,3,25,3,15,10), Time.utc(2005,2,28,15,15,10).advance(:weeks => 3.5) - assert_in_delta Time.utc(2005,3,26,12,51,10), Time.utc(2005,2,28,15,15,10).advance(:weeks => 3.7), 1 - assert_equal Time.utc(2005,3,5,15,15,10), Time.utc(2005,2,28,15,15,10).advance(:days => 5) - assert_equal Time.utc(2005,3,6,3,15,10), Time.utc(2005,2,28,15,15,10).advance(:days => 5.5) - assert_in_delta Time.utc(2005,3,6,8,3,10), Time.utc(2005,2,28,15,15,10).advance(:days => 5.7), 1 - assert_equal Time.utc(2012,9,22,15,15,10), Time.utc(2005,2,22,15,15,10).advance(:years => 7, :months => 7) - assert_equal Time.utc(2013,10,3,15,15,10), Time.utc(2005,2,22,15,15,10).advance(:years => 7, :months => 19, :days => 11) - assert_equal Time.utc(2013,10,17,15,15,10), Time.utc(2005,2,28,15,15,10).advance(:years => 7, :months => 19, :weeks => 2, :days => 5) - assert_equal Time.utc(2001,12,27,15,15,10), Time.utc(2005,2,28,15,15,10).advance(:years => -3, :months => -2, :days => -1) - assert_equal Time.utc(2005,2,28,15,15,10), Time.utc(2004,2,29,15,15,10).advance(:years => 1) #leap day plus one year - assert_equal Time.utc(2005,2,28,20,15,10), Time.utc(2005,2,28,15,15,10).advance(:hours => 5) - assert_equal Time.utc(2005,2,28,15,22,10), Time.utc(2005,2,28,15,15,10).advance(:minutes => 7) - assert_equal Time.utc(2005,2,28,15,15,19), Time.utc(2005,2,28,15,15,10).advance(:seconds => 9) - assert_equal Time.utc(2005,2,28,20,22,19), Time.utc(2005,2,28,15,15,10).advance(:hours => 5, :minutes => 7, :seconds => 9) - assert_equal Time.utc(2005,2,28,10,8,1), Time.utc(2005,2,28,15,15,10).advance(:hours => -5, :minutes => -7, :seconds => -9) - assert_equal Time.utc(2013,10,17,20,22,19), Time.utc(2005,2,28,15,15,10).advance(:years => 7, :months => 19, :weeks => 2, :days => 5, :hours => 5, :minutes => 7, :seconds => 9) + assert_equal Time.utc(2006,2,22,15,15,10), Time.utc(2005,2,22,15,15,10).advance(years: 1) + assert_equal Time.utc(2005,6,22,15,15,10), Time.utc(2005,2,22,15,15,10).advance(months: 4) + assert_equal Time.utc(2005,3,21,15,15,10), Time.utc(2005,2,28,15,15,10).advance(weeks: 3) + assert_equal Time.utc(2005,3,25,3,15,10), Time.utc(2005,2,28,15,15,10).advance(weeks: 3.5) + assert_in_delta Time.utc(2005,3,26,12,51,10), Time.utc(2005,2,28,15,15,10).advance(weeks: 3.7), 1 + assert_equal Time.utc(2005,3,5,15,15,10), Time.utc(2005,2,28,15,15,10).advance(days: 5) + assert_equal Time.utc(2005,3,6,3,15,10), Time.utc(2005,2,28,15,15,10).advance(days: 5.5) + assert_in_delta Time.utc(2005,3,6,8,3,10), Time.utc(2005,2,28,15,15,10).advance(days: 5.7), 1 + assert_equal Time.utc(2012,9,22,15,15,10), Time.utc(2005,2,22,15,15,10).advance(years: 7, months: 7) + assert_equal Time.utc(2013,10,3,15,15,10), Time.utc(2005,2,22,15,15,10).advance(years: 7, months: 19, days: 11) + assert_equal Time.utc(2013,10,17,15,15,10), Time.utc(2005,2,28,15,15,10).advance(years: 7, months: 19, weeks: 2, days: 5) + assert_equal Time.utc(2001,12,27,15,15,10), Time.utc(2005,2,28,15,15,10).advance(years: -3, months: -2, days: -1) + assert_equal Time.utc(2005,2,28,15,15,10), Time.utc(2004,2,29,15,15,10).advance(years: 1) #leap day plus one year + assert_equal Time.utc(2005,2,28,20,15,10), Time.utc(2005,2,28,15,15,10).advance(hours: 5) + assert_equal Time.utc(2005,2,28,15,22,10), Time.utc(2005,2,28,15,15,10).advance(minutes: 7) + assert_equal Time.utc(2005,2,28,15,15,19), Time.utc(2005,2,28,15,15,10).advance(seconds: 9) + assert_equal Time.utc(2005,2,28,20,22,19), Time.utc(2005,2,28,15,15,10).advance(hours: 5, minutes: 7, seconds: 9) + assert_equal Time.utc(2005,2,28,10,8,1), Time.utc(2005,2,28,15,15,10).advance(hours: -5, minutes: -7, seconds: -9) + assert_equal Time.utc(2013,10,17,20,22,19), Time.utc(2005,2,28,15,15,10).advance(years: 7, months: 19, weeks: 2, days: 5, hours: 5, minutes: 7, seconds: 9) end def test_offset_advance - assert_equal Time.new(2006,2,22,15,15,10,'-08:00'), Time.new(2005,2,22,15,15,10,'-08:00').advance(:years => 1) - assert_equal Time.new(2005,6,22,15,15,10,'-08:00'), Time.new(2005,2,22,15,15,10,'-08:00').advance(:months => 4) - assert_equal Time.new(2005,3,21,15,15,10,'-08:00'), Time.new(2005,2,28,15,15,10,'-08:00').advance(:weeks => 3) - assert_equal Time.new(2005,3,25,3,15,10,'-08:00'), Time.new(2005,2,28,15,15,10,'-08:00').advance(:weeks => 3.5) - assert_in_delta Time.new(2005,3,26,12,51,10,'-08:00'), Time.new(2005,2,28,15,15,10,'-08:00').advance(:weeks => 3.7), 1 - assert_equal Time.new(2005,3,5,15,15,10,'-08:00'), Time.new(2005,2,28,15,15,10,'-08:00').advance(:days => 5) - assert_equal Time.new(2005,3,6,3,15,10,'-08:00'), Time.new(2005,2,28,15,15,10,'-08:00').advance(:days => 5.5) - assert_in_delta Time.new(2005,3,6,8,3,10,'-08:00'), Time.new(2005,2,28,15,15,10,'-08:00').advance(:days => 5.7), 1 - assert_equal Time.new(2012,9,22,15,15,10,'-08:00'), Time.new(2005,2,22,15,15,10,'-08:00').advance(:years => 7, :months => 7) - assert_equal Time.new(2013,10,3,15,15,10,'-08:00'), Time.new(2005,2,22,15,15,10,'-08:00').advance(:years => 7, :months => 19, :days => 11) - assert_equal Time.new(2013,10,17,15,15,10,'-08:00'), Time.new(2005,2,28,15,15,10,'-08:00').advance(:years => 7, :months => 19, :weeks => 2, :days => 5) - assert_equal Time.new(2001,12,27,15,15,10,'-08:00'), Time.new(2005,2,28,15,15,10,'-08:00').advance(:years => -3, :months => -2, :days => -1) - assert_equal Time.new(2005,2,28,15,15,10,'-08:00'), Time.new(2004,2,29,15,15,10,'-08:00').advance(:years => 1) #leap day plus one year - assert_equal Time.new(2005,2,28,20,15,10,'-08:00'), Time.new(2005,2,28,15,15,10,'-08:00').advance(:hours => 5) - assert_equal Time.new(2005,2,28,15,22,10,'-08:00'), Time.new(2005,2,28,15,15,10,'-08:00').advance(:minutes => 7) - assert_equal Time.new(2005,2,28,15,15,19,'-08:00'), Time.new(2005,2,28,15,15,10,'-08:00').advance(:seconds => 9) - assert_equal Time.new(2005,2,28,20,22,19,'-08:00'), Time.new(2005,2,28,15,15,10,'-08:00').advance(:hours => 5, :minutes => 7, :seconds => 9) - assert_equal Time.new(2005,2,28,10,8,1,'-08:00'), Time.new(2005,2,28,15,15,10,'-08:00').advance(:hours => -5, :minutes => -7, :seconds => -9) - assert_equal Time.new(2013,10,17,20,22,19,'-08:00'), Time.new(2005,2,28,15,15,10,'-08:00').advance(:years => 7, :months => 19, :weeks => 2, :days => 5, :hours => 5, :minutes => 7, :seconds => 9) + assert_equal Time.new(2006,2,22,15,15,10,"-08:00"), Time.new(2005,2,22,15,15,10,"-08:00").advance(years: 1) + assert_equal Time.new(2005,6,22,15,15,10,"-08:00"), Time.new(2005,2,22,15,15,10,"-08:00").advance(months: 4) + assert_equal Time.new(2005,3,21,15,15,10,"-08:00"), Time.new(2005,2,28,15,15,10,"-08:00").advance(weeks: 3) + assert_equal Time.new(2005,3,25,3,15,10,"-08:00"), Time.new(2005,2,28,15,15,10,"-08:00").advance(weeks: 3.5) + assert_in_delta Time.new(2005,3,26,12,51,10,"-08:00"), Time.new(2005,2,28,15,15,10,"-08:00").advance(weeks: 3.7), 1 + assert_equal Time.new(2005,3,5,15,15,10,"-08:00"), Time.new(2005,2,28,15,15,10,"-08:00").advance(days: 5) + assert_equal Time.new(2005,3,6,3,15,10,"-08:00"), Time.new(2005,2,28,15,15,10,"-08:00").advance(days: 5.5) + assert_in_delta Time.new(2005,3,6,8,3,10,"-08:00"), Time.new(2005,2,28,15,15,10,"-08:00").advance(days: 5.7), 1 + assert_equal Time.new(2012,9,22,15,15,10,"-08:00"), Time.new(2005,2,22,15,15,10,"-08:00").advance(years: 7, months: 7) + assert_equal Time.new(2013,10,3,15,15,10,"-08:00"), Time.new(2005,2,22,15,15,10,"-08:00").advance(years: 7, months: 19, days: 11) + assert_equal Time.new(2013,10,17,15,15,10,"-08:00"), Time.new(2005,2,28,15,15,10,"-08:00").advance(years: 7, months: 19, weeks: 2, days: 5) + assert_equal Time.new(2001,12,27,15,15,10,"-08:00"), Time.new(2005,2,28,15,15,10,"-08:00").advance(years: -3, months: -2, days: -1) + assert_equal Time.new(2005,2,28,15,15,10,"-08:00"), Time.new(2004,2,29,15,15,10,"-08:00").advance(years: 1) #leap day plus one year + assert_equal Time.new(2005,2,28,20,15,10,"-08:00"), Time.new(2005,2,28,15,15,10,"-08:00").advance(hours: 5) + assert_equal Time.new(2005,2,28,15,22,10,"-08:00"), Time.new(2005,2,28,15,15,10,"-08:00").advance(minutes: 7) + assert_equal Time.new(2005,2,28,15,15,19,"-08:00"), Time.new(2005,2,28,15,15,10,"-08:00").advance(seconds: 9) + assert_equal Time.new(2005,2,28,20,22,19,"-08:00"), Time.new(2005,2,28,15,15,10,"-08:00").advance(hours: 5, minutes: 7, seconds: 9) + assert_equal Time.new(2005,2,28,10,8,1,"-08:00"), Time.new(2005,2,28,15,15,10,"-08:00").advance(hours: -5, minutes: -7, seconds: -9) + assert_equal Time.new(2013,10,17,20,22,19,"-08:00"), Time.new(2005,2,28,15,15,10,"-08:00").advance(years: 7, months: 19, weeks: 2, days: 5, hours: 5, minutes: 7, seconds: 9) end def test_advance_with_nsec t = Time.at(0, Rational(108635108, 1000)) - assert_equal t, t.advance(:months => 0) + assert_equal t, t.advance(months: 0) end def test_advance_gregorian_proleptic - assert_equal Time.local(1582,10,14,15,15,10), Time.local(1582,10,15,15,15,10).advance(:days => -1) - assert_equal Time.local(1582,10,15,15,15,10), Time.local(1582,10,14,15,15,10).advance(:days => 1) - assert_equal Time.local(1582,10,5,15,15,10), Time.local(1582,10,4,15,15,10).advance(:days => 1) - assert_equal Time.local(1582,10,4,15,15,10), Time.local(1582,10,5,15,15,10).advance(:days => -1) + assert_equal Time.local(1582,10,14,15,15,10), Time.local(1582,10,15,15,15,10).advance(days: -1) + assert_equal Time.local(1582,10,15,15,15,10), Time.local(1582,10,14,15,15,10).advance(days: 1) + assert_equal Time.local(1582,10,5,15,15,10), Time.local(1582,10,4,15,15,10).advance(days: 1) + assert_equal Time.local(1582,10,4,15,15,10), Time.local(1582,10,5,15,15,10).advance(days: -1) end def test_last_week - with_env_tz 'US/Eastern' do + with_env_tz "US/Eastern" do assert_equal Time.local(2005,2,21), Time.local(2005,3,1,15,15,10).last_week assert_equal Time.local(2005,2,22), Time.local(2005,3,1,15,15,10).last_week(:tuesday) assert_equal Time.local(2005,2,25), Time.local(2005,3,1,15,15,10).last_week(:friday) @@ -522,20 +522,20 @@ class TimeExtCalculationsTest < ActiveSupport::TestCase end def test_next_week_near_daylight_start - with_env_tz 'US/Eastern' do - assert_equal Time.local(2006,4,3), Time.local(2006,4,2,23,1,0).next_week, 'just crossed standard => daylight' + with_env_tz "US/Eastern" do + assert_equal Time.local(2006,4,3), Time.local(2006,4,2,23,1,0).next_week, "just crossed standard => daylight" end - with_env_tz 'NZ' do - assert_equal Time.local(2006,10,2), Time.local(2006,10,1,23,1,0).next_week, 'just crossed standard => daylight' + with_env_tz "NZ" do + assert_equal Time.local(2006,10,2), Time.local(2006,10,1,23,1,0).next_week, "just crossed standard => daylight" end end def test_next_week_near_daylight_end - with_env_tz 'US/Eastern' do - assert_equal Time.local(2006,10,30), Time.local(2006,10,29,23,1,0).next_week, 'just crossed daylight => standard' + with_env_tz "US/Eastern" do + assert_equal Time.local(2006,10,30), Time.local(2006,10,29,23,1,0).next_week, "just crossed daylight => standard" end - with_env_tz 'NZ' do - assert_equal Time.local(2006,3,20), Time.local(2006,3,19,23,1,0).next_week, 'just crossed daylight => standard' + with_env_tz "NZ" do + assert_equal Time.local(2006,3,20), Time.local(2006,3,19,23,1,0).next_week, "just crossed daylight => standard" end end @@ -564,8 +564,8 @@ class TimeExtCalculationsTest < ActiveSupport::TestCase end def test_custom_date_format - Time::DATE_FORMATS[:custom] = '%Y%m%d%H%M%S' - assert_equal '20050221143000', Time.local(2005, 2, 21, 14, 30, 0).to_s(:custom) + Time::DATE_FORMATS[:custom] = "%Y%m%d%H%M%S" + assert_equal "20050221143000", Time.local(2005, 2, 21, 14, 30, 0).to_s(:custom) Time::DATE_FORMATS.delete(:custom) end @@ -575,17 +575,17 @@ class TimeExtCalculationsTest < ActiveSupport::TestCase def test_to_datetime assert_equal Time.utc(2005, 2, 21, 17, 44, 30).to_datetime, DateTime.civil(2005, 2, 21, 17, 44, 30, 0) - with_env_tz 'US/Eastern' do + with_env_tz "US/Eastern" do assert_equal Time.local(2005, 2, 21, 17, 44, 30).to_datetime, DateTime.civil(2005, 2, 21, 17, 44, 30, Rational(Time.local(2005, 2, 21, 17, 44, 30).utc_offset, 86400)) end - with_env_tz 'NZ' do + with_env_tz "NZ" do assert_equal Time.local(2005, 2, 21, 17, 44, 30).to_datetime, DateTime.civil(2005, 2, 21, 17, 44, 30, Rational(Time.local(2005, 2, 21, 17, 44, 30).utc_offset, 86400)) end assert_equal ::Date::ITALY, Time.utc(2005, 2, 21, 17, 44, 30).to_datetime.start # use Ruby's default start value end def test_to_time - with_env_tz 'US/Eastern' do + with_env_tz "US/Eastern" do assert_equal Time, Time.local(2005, 2, 21, 17, 44, 30).to_time.class assert_equal Time.local(2005, 2, 21, 17, 44, 30), Time.local(2005, 2, 21, 17, 44, 30).to_time assert_equal Time.local(2005, 2, 21, 17, 44, 30).utc_offset, Time.local(2005, 2, 21, 17, 44, 30).to_time.utc_offset @@ -677,7 +677,7 @@ class TimeExtCalculationsTest < ActiveSupport::TestCase end def test_past_with_time_current_as_time_local - with_env_tz 'US/Eastern' do + with_env_tz "US/Eastern" do Time.stub(:current, Time.local(2005,2,10,15,30,45)) do assert_equal true, Time.local(2005,2,10,15,30,44).past? assert_equal false, Time.local(2005,2,10,15,30,45).past? @@ -690,8 +690,8 @@ class TimeExtCalculationsTest < ActiveSupport::TestCase end def test_past_with_time_current_as_time_with_zone - with_env_tz 'US/Eastern' do - twz = Time.utc(2005,2,10,15,30,45).in_time_zone('Central Time (US & Canada)') + with_env_tz "US/Eastern" do + twz = Time.utc(2005,2,10,15,30,45).in_time_zone("Central Time (US & Canada)") Time.stub(:current, twz) do assert_equal true, Time.local(2005,2,10,10,30,44).past? assert_equal false, Time.local(2005,2,10,10,30,45).past? @@ -704,7 +704,7 @@ class TimeExtCalculationsTest < ActiveSupport::TestCase end def test_future_with_time_current_as_time_local - with_env_tz 'US/Eastern' do + with_env_tz "US/Eastern" do Time.stub(:current, Time.local(2005,2,10,15,30,45)) do assert_equal false, Time.local(2005,2,10,15,30,44).future? assert_equal false, Time.local(2005,2,10,15,30,45).future? @@ -717,8 +717,8 @@ class TimeExtCalculationsTest < ActiveSupport::TestCase end def test_future_with_time_current_as_time_with_zone - with_env_tz 'US/Eastern' do - twz = Time.utc(2005,2,10,15,30,45).in_time_zone('Central Time (US & Canada)') + with_env_tz "US/Eastern" do + twz = Time.utc(2005,2,10,15,30,45).in_time_zone("Central Time (US & Canada)") Time.stub(:current, twz) do assert_equal false, Time.local(2005,2,10,10,30,44).future? assert_equal false, Time.local(2005,2,10,10,30,45).future? @@ -735,17 +735,17 @@ class TimeExtCalculationsTest < ActiveSupport::TestCase end def test_formatted_offset_with_utc - assert_equal '+00:00', Time.utc(2000).formatted_offset - assert_equal '+0000', Time.utc(2000).formatted_offset(false) - assert_equal 'UTC', Time.utc(2000).formatted_offset(true, 'UTC') + assert_equal "+00:00", Time.utc(2000).formatted_offset + assert_equal "+0000", Time.utc(2000).formatted_offset(false) + assert_equal "UTC", Time.utc(2000).formatted_offset(true, "UTC") end def test_formatted_offset_with_local - with_env_tz 'US/Eastern' do - assert_equal '-05:00', Time.local(2000).formatted_offset - assert_equal '-0500', Time.local(2000).formatted_offset(false) - assert_equal '-04:00', Time.local(2000, 7).formatted_offset - assert_equal '-0400', Time.local(2000, 7).formatted_offset(false) + with_env_tz "US/Eastern" do + assert_equal "-05:00", Time.local(2000).formatted_offset + assert_equal "-0500", Time.local(2000).formatted_offset(false) + assert_equal "-04:00", Time.local(2000, 7).formatted_offset + assert_equal "-0400", Time.local(2000, 7).formatted_offset(false) end end @@ -762,16 +762,16 @@ class TimeExtCalculationsTest < ActiveSupport::TestCase end def test_compare_with_time_with_zone - assert_equal 1, Time.utc(2000) <=> ActiveSupport::TimeWithZone.new( Time.utc(1999, 12, 31, 23, 59, 59), ActiveSupport::TimeZone['UTC'] ) - assert_equal 0, Time.utc(2000) <=> ActiveSupport::TimeWithZone.new( Time.utc(2000, 1, 1, 0, 0, 0), ActiveSupport::TimeZone['UTC'] ) - assert_equal(-1, Time.utc(2000) <=> ActiveSupport::TimeWithZone.new( Time.utc(2000, 1, 1, 0, 0, 1), ActiveSupport::TimeZone['UTC'] )) + assert_equal 1, Time.utc(2000) <=> ActiveSupport::TimeWithZone.new( Time.utc(1999, 12, 31, 23, 59, 59), ActiveSupport::TimeZone["UTC"] ) + assert_equal 0, Time.utc(2000) <=> ActiveSupport::TimeWithZone.new( Time.utc(2000, 1, 1, 0, 0, 0), ActiveSupport::TimeZone["UTC"] ) + assert_equal(-1, Time.utc(2000) <=> ActiveSupport::TimeWithZone.new( Time.utc(2000, 1, 1, 0, 0, 1), ActiveSupport::TimeZone["UTC"] )) end def test_compare_with_string assert_equal 1, Time.utc(2000) <=> Time.utc(1999, 12, 31, 23, 59, 59, 999).to_s assert_equal 0, Time.utc(2000) <=> Time.utc(2000, 1, 1, 0, 0, 0).to_s assert_equal( -1, Time.utc(2000) <=> Time.utc(2000, 1, 1, 0, 0, 1, 0).to_s) - assert_equal nil, Time.utc(2000) <=> 'Invalid as Time' + assert_equal nil, Time.utc(2000) <=> "Invalid as Time" end def test_at_with_datetime @@ -786,42 +786,42 @@ class TimeExtCalculationsTest < ActiveSupport::TestCase end def test_at_with_datetime_returns_local_time - with_env_tz 'US/Eastern' do - dt = DateTime.civil(2000, 1, 1, 0, 0, 0, '+0') + with_env_tz "US/Eastern" do + dt = DateTime.civil(2000, 1, 1, 0, 0, 0, "+0") assert_equal Time.local(1999, 12, 31, 19, 0, 0), Time.at(dt) - assert_equal 'EST', Time.at(dt).zone + assert_equal "EST", Time.at(dt).zone assert_equal(-18000, Time.at(dt).utc_offset) # Daylight savings - dt = DateTime.civil(2000, 7, 1, 1, 0, 0, '+1') + dt = DateTime.civil(2000, 7, 1, 1, 0, 0, "+1") assert_equal Time.local(2000, 6, 30, 20, 0, 0), Time.at(dt) - assert_equal 'EDT', Time.at(dt).zone + assert_equal "EDT", Time.at(dt).zone assert_equal(-14400, Time.at(dt).utc_offset) end end def test_at_with_time_with_zone - assert_equal Time.utc(2000, 1, 1, 0, 0, 0), Time.at(ActiveSupport::TimeWithZone.new(Time.utc(2000, 1, 1, 0, 0, 0), ActiveSupport::TimeZone['UTC'])) + assert_equal Time.utc(2000, 1, 1, 0, 0, 0), Time.at(ActiveSupport::TimeWithZone.new(Time.utc(2000, 1, 1, 0, 0, 0), ActiveSupport::TimeZone["UTC"])) # Only test this if the underlying Time.at raises a TypeError begin Time.at_without_coercion(Time.now, 0) rescue TypeError - assert_raise(TypeError) { assert_equal(Time.utc(2000, 1, 1, 0, 0, 0), Time.at(ActiveSupport::TimeWithZone.new(Time.utc(2000, 1, 1, 0, 0, 0), ActiveSupport::TimeZone['UTC']), 0)) } + assert_raise(TypeError) { assert_equal(Time.utc(2000, 1, 1, 0, 0, 0), Time.at(ActiveSupport::TimeWithZone.new(Time.utc(2000, 1, 1, 0, 0, 0), ActiveSupport::TimeZone["UTC"]), 0)) } end end def test_at_with_time_with_zone_returns_local_time - with_env_tz 'US/Eastern' do - twz = ActiveSupport::TimeWithZone.new(Time.utc(2000, 1, 1, 0, 0, 0), ActiveSupport::TimeZone['London']) + with_env_tz "US/Eastern" do + twz = ActiveSupport::TimeWithZone.new(Time.utc(2000, 1, 1, 0, 0, 0), ActiveSupport::TimeZone["London"]) assert_equal Time.local(1999, 12, 31, 19, 0, 0), Time.at(twz) - assert_equal 'EST', Time.at(twz).zone + assert_equal "EST", Time.at(twz).zone assert_equal(-18000, Time.at(twz).utc_offset) # Daylight savings - twz = ActiveSupport::TimeWithZone.new(Time.utc(2000, 7, 1, 0, 0, 0), ActiveSupport::TimeZone['London']) + twz = ActiveSupport::TimeWithZone.new(Time.utc(2000, 7, 1, 0, 0, 0), ActiveSupport::TimeZone["London"]) assert_equal Time.local(2000, 6, 30, 20, 0, 0), Time.at(twz) - assert_equal 'EDT', Time.at(twz).zone + assert_equal "EDT", Time.at(twz).zone assert_equal(-14400, Time.at(twz).utc_offset) end end @@ -831,33 +831,33 @@ class TimeExtCalculationsTest < ActiveSupport::TestCase end def test_at_with_utc_time - with_env_tz 'US/Eastern' do + with_env_tz "US/Eastern" do assert_equal Time.utc(2000), Time.at(Time.utc(2000)) - assert_equal 'UTC', Time.at(Time.utc(2000)).zone + assert_equal "UTC", Time.at(Time.utc(2000)).zone assert_equal(0, Time.at(Time.utc(2000)).utc_offset) end end def test_at_with_local_time - with_env_tz 'US/Eastern' do + with_env_tz "US/Eastern" do assert_equal Time.local(2000), Time.at(Time.local(2000)) - assert_equal 'EST', Time.at(Time.local(2000)).zone + assert_equal "EST", Time.at(Time.local(2000)).zone assert_equal(-18000, Time.at(Time.local(2000)).utc_offset) assert_equal Time.local(2000, 7, 1), Time.at(Time.local(2000, 7, 1)) - assert_equal 'EDT', Time.at(Time.local(2000, 7, 1)).zone + assert_equal "EDT", Time.at(Time.local(2000, 7, 1)).zone assert_equal(-14400, Time.at(Time.local(2000, 7, 1)).utc_offset) end end def test_eql? - assert_equal true, Time.utc(2000).eql?( ActiveSupport::TimeWithZone.new(Time.utc(2000), ActiveSupport::TimeZone['UTC']) ) + assert_equal true, Time.utc(2000).eql?( ActiveSupport::TimeWithZone.new(Time.utc(2000), ActiveSupport::TimeZone["UTC"]) ) assert_equal true, Time.utc(2000).eql?( ActiveSupport::TimeWithZone.new(Time.utc(2000), ActiveSupport::TimeZone["Hawaii"]) ) - assert_equal false,Time.utc(2000, 1, 1, 0, 0, 1).eql?( ActiveSupport::TimeWithZone.new(Time.utc(2000), ActiveSupport::TimeZone['UTC']) ) + assert_equal false,Time.utc(2000, 1, 1, 0, 0, 1).eql?( ActiveSupport::TimeWithZone.new(Time.utc(2000), ActiveSupport::TimeZone["UTC"]) ) end def test_minus_with_time_with_zone - assert_equal 86_400.0, Time.utc(2000, 1, 2) - ActiveSupport::TimeWithZone.new( Time.utc(2000, 1, 1), ActiveSupport::TimeZone['UTC'] ) + assert_equal 86_400.0, Time.utc(2000, 1, 2) - ActiveSupport::TimeWithZone.new( Time.utc(2000, 1, 1), ActiveSupport::TimeZone["UTC"] ) end def test_minus_with_datetime @@ -865,7 +865,7 @@ class TimeExtCalculationsTest < ActiveSupport::TestCase end def test_time_created_with_local_constructor_cannot_represent_times_during_hour_skipped_by_dst - with_env_tz 'US/Eastern' do + with_env_tz "US/Eastern" do # On Apr 2 2006 at 2:00AM in US, clocks were moved forward to 3:00AM. # Therefore, 2AM EST doesn't exist for this date; Time.local fails over to 3:00AM EDT assert_equal Time.local(2006, 4, 2, 3), Time.local(2006, 4, 2, 2) @@ -875,11 +875,11 @@ class TimeExtCalculationsTest < ActiveSupport::TestCase def test_case_equality assert Time === Time.utc(2000) - assert Time === ActiveSupport::TimeWithZone.new(Time.utc(2000), ActiveSupport::TimeZone['UTC']) + assert Time === ActiveSupport::TimeWithZone.new(Time.utc(2000), ActiveSupport::TimeZone["UTC"]) assert Time === Class.new(Time).utc(2000) assert_equal false, Time === DateTime.civil(2000) assert_equal false, Class.new(Time) === Time.utc(2000) - assert_equal false, Class.new(Time) === ActiveSupport::TimeWithZone.new(Time.utc(2000), ActiveSupport::TimeZone['UTC']) + assert_equal false, Class.new(Time) === ActiveSupport::TimeWithZone.new(Time.utc(2000), ActiveSupport::TimeZone["UTC"]) end def test_all_day @@ -942,7 +942,7 @@ class TimeExtMarshalingTest < ActiveSupport::TestCase end def test_marshalling_preserves_fractional_seconds - t = Time.parse('00:00:00.500') + t = Time.parse("00:00:00.500") unmarshaled = Marshal.load(Marshal.dump(t)) assert_equal t.to_f, unmarshaled.to_f assert_equal t, unmarshaled diff --git a/activesupport/test/core_ext/time_with_zone_test.rb b/activesupport/test/core_ext/time_with_zone_test.rb index c873b28211..6ab1368e53 100644 --- a/activesupport/test/core_ext/time_with_zone_test.rb +++ b/activesupport/test/core_ext/time_with_zone_test.rb @@ -1,15 +1,15 @@ -require 'abstract_unit' -require 'active_support/time' -require 'time_zone_test_helpers' -require 'active_support/core_ext/string/strip' -require 'yaml' +require "abstract_unit" +require "active_support/time" +require "time_zone_test_helpers" +require "active_support/core_ext/string/strip" +require "yaml" class TimeWithZoneTest < ActiveSupport::TestCase include TimeZoneTestHelpers def setup @utc = Time.utc(2000, 1, 1, 0) - @time_zone = ActiveSupport::TimeZone['Eastern Time (US & Canada)'] + @time_zone = ActiveSupport::TimeZone["Eastern Time (US & Canada)"] @twz = ActiveSupport::TimeWithZone.new(@utc, @time_zone) @dt_twz = ActiveSupport::TimeWithZone.new(@utc.to_datetime, @time_zone) end @@ -29,21 +29,21 @@ class TimeWithZoneTest < ActiveSupport::TestCase end def test_in_time_zone - Time.use_zone 'Alaska' do - assert_equal ActiveSupport::TimeWithZone.new(@utc, ActiveSupport::TimeZone['Alaska']), @twz.in_time_zone + Time.use_zone "Alaska" do + assert_equal ActiveSupport::TimeWithZone.new(@utc, ActiveSupport::TimeZone["Alaska"]), @twz.in_time_zone end end def test_in_time_zone_with_argument - assert_equal ActiveSupport::TimeWithZone.new(@utc, ActiveSupport::TimeZone['Alaska']), @twz.in_time_zone('Alaska') + assert_equal ActiveSupport::TimeWithZone.new(@utc, ActiveSupport::TimeZone["Alaska"]), @twz.in_time_zone("Alaska") end def test_in_time_zone_with_new_zone_equal_to_old_zone_does_not_create_new_object - assert_equal @twz.object_id, @twz.in_time_zone(ActiveSupport::TimeZone['Eastern Time (US & Canada)']).object_id + assert_equal @twz.object_id, @twz.in_time_zone(ActiveSupport::TimeZone["Eastern Time (US & Canada)"]).object_id end def test_in_time_zone_with_bad_argument - assert_raise(ArgumentError) { @twz.in_time_zone('No such timezone exists') } + assert_raise(ArgumentError) { @twz.in_time_zone("No such timezone exists") } assert_raise(ArgumentError) { @twz.in_time_zone(-15.hours) } assert_raise(ArgumentError) { @twz.in_time_zone(Object.new) } end @@ -57,26 +57,26 @@ class TimeWithZoneTest < ActiveSupport::TestCase def test_utc? assert_equal false, @twz.utc? - assert_equal true, ActiveSupport::TimeWithZone.new(Time.utc(2000), ActiveSupport::TimeZone['UTC']).utc? - assert_equal true, ActiveSupport::TimeWithZone.new(Time.utc(2000), ActiveSupport::TimeZone['Etc/UTC']).utc? - assert_equal true, ActiveSupport::TimeWithZone.new(Time.utc(2000), ActiveSupport::TimeZone['Universal']).utc? - assert_equal true, ActiveSupport::TimeWithZone.new(Time.utc(2000), ActiveSupport::TimeZone['UCT']).utc? - assert_equal true, ActiveSupport::TimeWithZone.new(Time.utc(2000), ActiveSupport::TimeZone['Etc/UCT']).utc? - assert_equal true, ActiveSupport::TimeWithZone.new(Time.utc(2000), ActiveSupport::TimeZone['Etc/Universal']).utc? + assert_equal true, ActiveSupport::TimeWithZone.new(Time.utc(2000), ActiveSupport::TimeZone["UTC"]).utc? + assert_equal true, ActiveSupport::TimeWithZone.new(Time.utc(2000), ActiveSupport::TimeZone["Etc/UTC"]).utc? + assert_equal true, ActiveSupport::TimeWithZone.new(Time.utc(2000), ActiveSupport::TimeZone["Universal"]).utc? + assert_equal true, ActiveSupport::TimeWithZone.new(Time.utc(2000), ActiveSupport::TimeZone["UCT"]).utc? + assert_equal true, ActiveSupport::TimeWithZone.new(Time.utc(2000), ActiveSupport::TimeZone["Etc/UCT"]).utc? + assert_equal true, ActiveSupport::TimeWithZone.new(Time.utc(2000), ActiveSupport::TimeZone["Etc/Universal"]).utc? - assert_equal false, ActiveSupport::TimeWithZone.new(Time.utc(2000), ActiveSupport::TimeZone['Africa/Abidjan']).utc? - assert_equal false, ActiveSupport::TimeWithZone.new(Time.utc(2000), ActiveSupport::TimeZone['Africa/Banjul']).utc? - assert_equal false, ActiveSupport::TimeWithZone.new(Time.utc(2000), ActiveSupport::TimeZone['Africa/Freetown']).utc? - assert_equal false, ActiveSupport::TimeWithZone.new(Time.utc(2000), ActiveSupport::TimeZone['GMT']).utc? - assert_equal false, ActiveSupport::TimeWithZone.new(Time.utc(2000), ActiveSupport::TimeZone['GMT0']).utc? - assert_equal false, ActiveSupport::TimeWithZone.new(Time.utc(2000), ActiveSupport::TimeZone['Greenwich']).utc? - assert_equal false, ActiveSupport::TimeWithZone.new(Time.utc(2000), ActiveSupport::TimeZone['Iceland']).utc? - assert_equal false, ActiveSupport::TimeWithZone.new(Time.utc(2000), ActiveSupport::TimeZone['Africa/Monrovia']).utc? + assert_equal false, ActiveSupport::TimeWithZone.new(Time.utc(2000), ActiveSupport::TimeZone["Africa/Abidjan"]).utc? + assert_equal false, ActiveSupport::TimeWithZone.new(Time.utc(2000), ActiveSupport::TimeZone["Africa/Banjul"]).utc? + assert_equal false, ActiveSupport::TimeWithZone.new(Time.utc(2000), ActiveSupport::TimeZone["Africa/Freetown"]).utc? + assert_equal false, ActiveSupport::TimeWithZone.new(Time.utc(2000), ActiveSupport::TimeZone["GMT"]).utc? + assert_equal false, ActiveSupport::TimeWithZone.new(Time.utc(2000), ActiveSupport::TimeZone["GMT0"]).utc? + assert_equal false, ActiveSupport::TimeWithZone.new(Time.utc(2000), ActiveSupport::TimeZone["Greenwich"]).utc? + assert_equal false, ActiveSupport::TimeWithZone.new(Time.utc(2000), ActiveSupport::TimeZone["Iceland"]).utc? + assert_equal false, ActiveSupport::TimeWithZone.new(Time.utc(2000), ActiveSupport::TimeZone["Africa/Monrovia"]).utc? end def test_formatted_offset - assert_equal '-05:00', @twz.formatted_offset - assert_equal '-04:00', ActiveSupport::TimeWithZone.new(Time.utc(2000, 6), @time_zone).formatted_offset #dst + assert_equal "-05:00", @twz.formatted_offset + assert_equal "-04:00", ActiveSupport::TimeWithZone.new(Time.utc(2000, 6), @time_zone).formatted_offset #dst end def test_dst? @@ -85,8 +85,8 @@ class TimeWithZoneTest < ActiveSupport::TestCase end def test_zone - assert_equal 'EST', @twz.zone - assert_equal 'EDT', ActiveSupport::TimeWithZone.new(Time.utc(2000, 6), @time_zone).zone #dst + assert_equal "EST", @twz.zone + assert_equal "EDT", ActiveSupport::TimeWithZone.new(Time.utc(2000, 6), @time_zone).zone #dst end def test_nsec @@ -98,28 +98,28 @@ class TimeWithZoneTest < ActiveSupport::TestCase end def test_strftime - assert_equal '1999-12-31 19:00:00 EST -0500', @twz.strftime('%Y-%m-%d %H:%M:%S %Z %z') + assert_equal "1999-12-31 19:00:00 EST -0500", @twz.strftime("%Y-%m-%d %H:%M:%S %Z %z") end def test_strftime_with_escaping - assert_equal '%Z %z', @twz.strftime('%%Z %%z') - assert_equal '%EST %-0500', @twz.strftime('%%%Z %%%z') + assert_equal "%Z %z", @twz.strftime("%%Z %%z") + assert_equal "%EST %-0500", @twz.strftime("%%%Z %%%z") end def test_inspect - assert_equal 'Fri, 31 Dec 1999 19:00:00 EST -05:00', @twz.inspect + assert_equal "Fri, 31 Dec 1999 19:00:00 EST -05:00", @twz.inspect end def test_to_s - assert_equal '1999-12-31 19:00:00 -0500', @twz.to_s + assert_equal "1999-12-31 19:00:00 -0500", @twz.to_s end def test_to_formatted_s - assert_equal '1999-12-31 19:00:00 -0500', @twz.to_formatted_s + assert_equal "1999-12-31 19:00:00 -0500", @twz.to_formatted_s end def test_to_s_db - assert_equal '2000-01-01 00:00:00', @twz.to_s(:db) + assert_equal "2000-01-01 00:00:00", @twz.to_s(:db) end def test_xmlschema @@ -166,7 +166,7 @@ class TimeWithZoneTest < ActiveSupport::TestCase time: 1999-12-31 19:00:00.000000000 Z EOF - assert_equal(yaml, { 'twz' => @twz }.to_yaml) + assert_equal(yaml, { "twz" => @twz }.to_yaml) end def test_yaml_load @@ -191,11 +191,11 @@ class TimeWithZoneTest < ActiveSupport::TestCase time: 1999-12-31 19:00:00.000000000 Z EOF - assert_equal({ 'twz' => @twz }, YAML.load(yaml)) + assert_equal({ "twz" => @twz }, YAML.load(yaml)) end def test_httpdate - assert_equal 'Sat, 01 Jan 2000 00:00:00 GMT', @twz.httpdate + assert_equal "Sat, 01 Jan 2000 00:00:00 GMT", @twz.httpdate end def test_rfc2822 @@ -215,9 +215,9 @@ class TimeWithZoneTest < ActiveSupport::TestCase end def test_compare_with_time_with_zone - assert_equal 1, @twz <=> ActiveSupport::TimeWithZone.new( Time.utc(1999, 12, 31, 23, 59, 59), ActiveSupport::TimeZone['UTC'] ) - assert_equal 0, @twz <=> ActiveSupport::TimeWithZone.new( Time.utc(2000, 1, 1, 0, 0, 0), ActiveSupport::TimeZone['UTC'] ) - assert_equal(-1, @twz <=> ActiveSupport::TimeWithZone.new( Time.utc(2000, 1, 1, 0, 0, 1), ActiveSupport::TimeZone['UTC'] )) + assert_equal 1, @twz <=> ActiveSupport::TimeWithZone.new( Time.utc(1999, 12, 31, 23, 59, 59), ActiveSupport::TimeZone["UTC"] ) + assert_equal 0, @twz <=> ActiveSupport::TimeWithZone.new( Time.utc(2000, 1, 1, 0, 0, 0), ActiveSupport::TimeZone["UTC"] ) + assert_equal(-1, @twz <=> ActiveSupport::TimeWithZone.new( Time.utc(2000, 1, 1, 0, 0, 1), ActiveSupport::TimeZone["UTC"] )) end def test_between? @@ -235,7 +235,7 @@ class TimeWithZoneTest < ActiveSupport::TestCase end def test_past_with_time_current_as_time_local - with_env_tz 'US/Eastern' do + with_env_tz "US/Eastern" do Time.stub(:current, Time.local(2005,2,10,15,30,45)) do assert_equal true, ActiveSupport::TimeWithZone.new( nil, @time_zone, Time.local(2005,2,10,15,30,44)).past? assert_equal false, ActiveSupport::TimeWithZone.new( nil, @time_zone, Time.local(2005,2,10,15,30,45)).past? @@ -254,7 +254,7 @@ class TimeWithZoneTest < ActiveSupport::TestCase end def test_future_with_time_current_as_time_local - with_env_tz 'US/Eastern' do + with_env_tz "US/Eastern" do Time.stub(:current, Time.local(2005,2,10,15,30,45)) do assert_equal false, ActiveSupport::TimeWithZone.new( nil, @time_zone, Time.local(2005,2,10,15,30,44)).future? assert_equal false, ActiveSupport::TimeWithZone.new( nil, @time_zone, Time.local(2005,2,10,15,30,45)).future? @@ -322,38 +322,38 @@ class TimeWithZoneTest < ActiveSupport::TestCase end def test_minus_with_time - assert_equal 86_400.0, ActiveSupport::TimeWithZone.new( Time.utc(2000, 1, 2), ActiveSupport::TimeZone['UTC'] ) - Time.utc(2000, 1, 1) - assert_equal 86_400.0, ActiveSupport::TimeWithZone.new( Time.utc(2000, 1, 2), ActiveSupport::TimeZone['Hawaii'] ) - Time.utc(2000, 1, 1) + assert_equal 86_400.0, ActiveSupport::TimeWithZone.new( Time.utc(2000, 1, 2), ActiveSupport::TimeZone["UTC"] ) - Time.utc(2000, 1, 1) + assert_equal 86_400.0, ActiveSupport::TimeWithZone.new( Time.utc(2000, 1, 2), ActiveSupport::TimeZone["Hawaii"] ) - Time.utc(2000, 1, 1) end def test_minus_with_time_precision - assert_equal 86_399.999999998, ActiveSupport::TimeWithZone.new( Time.utc(2000, 1, 2, 23, 59, 59, Rational(999999999, 1000)), ActiveSupport::TimeZone['UTC'] ) - Time.utc(2000, 1, 2, 0, 0, 0, Rational(1, 1000)) - assert_equal 86_399.999999998, ActiveSupport::TimeWithZone.new( Time.utc(2000, 1, 2, 23, 59, 59, Rational(999999999, 1000)), ActiveSupport::TimeZone['Hawaii'] ) - Time.utc(2000, 1, 2, 0, 0, 0, Rational(1, 1000)) + assert_equal 86_399.999999998, ActiveSupport::TimeWithZone.new( Time.utc(2000, 1, 2, 23, 59, 59, Rational(999999999, 1000)), ActiveSupport::TimeZone["UTC"] ) - Time.utc(2000, 1, 2, 0, 0, 0, Rational(1, 1000)) + assert_equal 86_399.999999998, ActiveSupport::TimeWithZone.new( Time.utc(2000, 1, 2, 23, 59, 59, Rational(999999999, 1000)), ActiveSupport::TimeZone["Hawaii"] ) - Time.utc(2000, 1, 2, 0, 0, 0, Rational(1, 1000)) end def test_minus_with_time_with_zone - twz1 = ActiveSupport::TimeWithZone.new( Time.utc(2000, 1, 1), ActiveSupport::TimeZone['UTC'] ) - twz2 = ActiveSupport::TimeWithZone.new( Time.utc(2000, 1, 2), ActiveSupport::TimeZone['UTC'] ) + twz1 = ActiveSupport::TimeWithZone.new( Time.utc(2000, 1, 1), ActiveSupport::TimeZone["UTC"] ) + twz2 = ActiveSupport::TimeWithZone.new( Time.utc(2000, 1, 2), ActiveSupport::TimeZone["UTC"] ) assert_equal 86_400.0, twz2 - twz1 end def test_minus_with_time_with_zone_precision - twz1 = ActiveSupport::TimeWithZone.new( Time.utc(2000, 1, 1, 0, 0, 0, Rational(1, 1000)), ActiveSupport::TimeZone['UTC'] ) - twz2 = ActiveSupport::TimeWithZone.new( Time.utc(2000, 1, 1, 23, 59, 59, Rational(999999999, 1000)), ActiveSupport::TimeZone['UTC'] ) + twz1 = ActiveSupport::TimeWithZone.new( Time.utc(2000, 1, 1, 0, 0, 0, Rational(1, 1000)), ActiveSupport::TimeZone["UTC"] ) + twz2 = ActiveSupport::TimeWithZone.new( Time.utc(2000, 1, 1, 23, 59, 59, Rational(999999999, 1000)), ActiveSupport::TimeZone["UTC"] ) assert_equal 86_399.999999998, twz2 - twz1 end def test_minus_with_datetime - assert_equal 86_400.0, ActiveSupport::TimeWithZone.new( Time.utc(2000, 1, 2), ActiveSupport::TimeZone['UTC'] ) - DateTime.civil(2000, 1, 1) + assert_equal 86_400.0, ActiveSupport::TimeWithZone.new( Time.utc(2000, 1, 2), ActiveSupport::TimeZone["UTC"] ) - DateTime.civil(2000, 1, 1) end def test_minus_with_datetime_precision - assert_equal 86_399.999999999, ActiveSupport::TimeWithZone.new( Time.utc(2000, 1, 1, 23, 59, 59, Rational(999999999, 1000)), ActiveSupport::TimeZone['UTC'] ) - DateTime.civil(2000, 1, 1) + assert_equal 86_399.999999999, ActiveSupport::TimeWithZone.new( Time.utc(2000, 1, 1, 23, 59, 59, Rational(999999999, 1000)), ActiveSupport::TimeZone["UTC"] ) - DateTime.civil(2000, 1, 1) end def test_minus_with_wrapped_datetime - assert_equal 86_400.0, ActiveSupport::TimeWithZone.new( DateTime.civil(2000, 1, 2), ActiveSupport::TimeZone['UTC'] ) - Time.utc(2000, 1, 1) - assert_equal 86_400.0, ActiveSupport::TimeWithZone.new( DateTime.civil(2000, 1, 2), ActiveSupport::TimeZone['UTC'] ) - DateTime.civil(2000, 1, 1) + assert_equal 86_400.0, ActiveSupport::TimeWithZone.new( DateTime.civil(2000, 1, 2), ActiveSupport::TimeZone["UTC"] ) - Time.utc(2000, 1, 1) + assert_equal 86_400.0, ActiveSupport::TimeWithZone.new( DateTime.civil(2000, 1, 2), ActiveSupport::TimeZone["UTC"] ) - DateTime.civil(2000, 1, 1) end def test_plus_and_minus_enforce_spring_dst_rules @@ -361,15 +361,15 @@ class TimeWithZoneTest < ActiveSupport::TestCase twz = ActiveSupport::TimeWithZone.new(utc, @time_zone) assert_equal Time.utc(2006,4,2,1,59,59), twz.time assert_equal false, twz.dst? - assert_equal 'EST', twz.zone + assert_equal "EST", twz.zone twz = twz + 1 assert_equal Time.utc(2006,4,2,3), twz.time # adding 1 sec springs forward to 3:00AM EDT assert_equal true, twz.dst? - assert_equal 'EDT', twz.zone + assert_equal "EDT", twz.zone twz = twz - 1 # subtracting 1 second takes goes back to 1:59:59AM EST assert_equal Time.utc(2006,4,2,1,59,59), twz.time assert_equal false, twz.dst? - assert_equal 'EST', twz.zone + assert_equal "EST", twz.zone end def test_plus_and_minus_enforce_fall_dst_rules @@ -377,29 +377,29 @@ class TimeWithZoneTest < ActiveSupport::TestCase twz = ActiveSupport::TimeWithZone.new(utc, @time_zone) assert_equal Time.utc(2006,10,29,1,59,59), twz.time assert_equal true, twz.dst? - assert_equal 'EDT', twz.zone + assert_equal "EDT", twz.zone twz = twz + 1 assert_equal Time.utc(2006,10,29,1), twz.time # adding 1 sec falls back from 1:59:59 EDT to 1:00AM EST assert_equal false, twz.dst? - assert_equal 'EST', twz.zone + assert_equal "EST", twz.zone twz = twz - 1 assert_equal Time.utc(2006,10,29,1,59,59), twz.time # subtracting 1 sec goes back to 1:59:59AM EDT assert_equal true, twz.dst? - assert_equal 'EDT', twz.zone + assert_equal "EDT", twz.zone end def test_to_a - assert_equal [45, 30, 5, 1, 2, 2000, 2, 32, false, "HST"], ActiveSupport::TimeWithZone.new( Time.utc(2000, 2, 1, 15, 30, 45), ActiveSupport::TimeZone['Hawaii'] ).to_a + assert_equal [45, 30, 5, 1, 2, 2000, 2, 32, false, "HST"], ActiveSupport::TimeWithZone.new( Time.utc(2000, 2, 1, 15, 30, 45), ActiveSupport::TimeZone["Hawaii"] ).to_a end def test_to_f - result = ActiveSupport::TimeWithZone.new( Time.utc(2000, 1, 1), ActiveSupport::TimeZone['Hawaii'] ).to_f + result = ActiveSupport::TimeWithZone.new( Time.utc(2000, 1, 1), ActiveSupport::TimeZone["Hawaii"] ).to_f assert_equal 946684800.0, result assert_kind_of Float, result end def test_to_i - result = ActiveSupport::TimeWithZone.new( Time.utc(2000, 1, 1), ActiveSupport::TimeZone['Hawaii'] ).to_i + result = ActiveSupport::TimeWithZone.new( Time.utc(2000, 1, 1), ActiveSupport::TimeZone["Hawaii"] ).to_i assert_equal 946684800, result assert_kind_of Integer, result end @@ -411,18 +411,18 @@ class TimeWithZoneTest < ActiveSupport::TestCase end def test_to_r - result = ActiveSupport::TimeWithZone.new(Time.utc(2000, 1, 1), ActiveSupport::TimeZone['Hawaii']).to_r + result = ActiveSupport::TimeWithZone.new(Time.utc(2000, 1, 1), ActiveSupport::TimeZone["Hawaii"]).to_r assert_equal Rational(946684800, 1), result assert_kind_of Rational, result end def test_time_at - time = ActiveSupport::TimeWithZone.new(Time.utc(2000, 1, 1), ActiveSupport::TimeZone['Hawaii']) + time = ActiveSupport::TimeWithZone.new(Time.utc(2000, 1, 1), ActiveSupport::TimeZone["Hawaii"]) assert_equal time, Time.at(time) end def test_to_time - with_env_tz 'US/Eastern' do + with_env_tz "US/Eastern" do assert_equal Time, @twz.to_time.class assert_equal Time.local(1999, 12, 31, 19), @twz.to_time assert_equal Time.local(1999, 12, 31, 19).utc_offset, @twz.to_time.utc_offset @@ -431,13 +431,13 @@ class TimeWithZoneTest < ActiveSupport::TestCase def test_to_date # 1 sec before midnight Jan 1 EST - assert_equal Date.new(1999, 12, 31), ActiveSupport::TimeWithZone.new( Time.utc(2000, 1, 1, 4, 59, 59), ActiveSupport::TimeZone['Eastern Time (US & Canada)'] ).to_date + assert_equal Date.new(1999, 12, 31), ActiveSupport::TimeWithZone.new( Time.utc(2000, 1, 1, 4, 59, 59), ActiveSupport::TimeZone["Eastern Time (US & Canada)"] ).to_date # midnight Jan 1 EST - assert_equal Date.new(2000, 1, 1), ActiveSupport::TimeWithZone.new( Time.utc(2000, 1, 1, 5, 0, 0), ActiveSupport::TimeZone['Eastern Time (US & Canada)'] ).to_date + assert_equal Date.new(2000, 1, 1), ActiveSupport::TimeWithZone.new( Time.utc(2000, 1, 1, 5, 0, 0), ActiveSupport::TimeZone["Eastern Time (US & Canada)"] ).to_date # 1 sec before midnight Jan 2 EST - assert_equal Date.new(2000, 1, 1), ActiveSupport::TimeWithZone.new( Time.utc(2000, 1, 2, 4, 59, 59), ActiveSupport::TimeZone['Eastern Time (US & Canada)'] ).to_date + assert_equal Date.new(2000, 1, 1), ActiveSupport::TimeWithZone.new( Time.utc(2000, 1, 2, 4, 59, 59), ActiveSupport::TimeZone["Eastern Time (US & Canada)"] ).to_date # midnight Jan 2 EST - assert_equal Date.new(2000, 1, 2), ActiveSupport::TimeWithZone.new( Time.utc(2000, 1, 2, 5, 0, 0), ActiveSupport::TimeZone['Eastern Time (US & Canada)'] ).to_date + assert_equal Date.new(2000, 1, 2), ActiveSupport::TimeWithZone.new( Time.utc(2000, 1, 2, 5, 0, 0), ActiveSupport::TimeZone["Eastern Time (US & Canada)"] ).to_date end def test_to_datetime @@ -462,7 +462,7 @@ class TimeWithZoneTest < ActiveSupport::TestCase end def test_class_name - assert_equal 'Time', ActiveSupport::TimeWithZone.name + assert_equal "Time", ActiveSupport::TimeWithZone.name end def test_method_missing_with_time_return_value @@ -475,19 +475,19 @@ class TimeWithZoneTest < ActiveSupport::TestCase mtime = Marshal.load(marshal_str) assert_equal Time.utc(2000, 1, 1, 0), mtime.utc assert mtime.utc.utc? - assert_equal ActiveSupport::TimeZone['Eastern Time (US & Canada)'], mtime.time_zone + assert_equal ActiveSupport::TimeZone["Eastern Time (US & Canada)"], mtime.time_zone assert_equal Time.utc(1999, 12, 31, 19), mtime.time assert mtime.time.utc? assert_equal @twz.inspect, mtime.inspect end def test_marshal_dump_and_load_with_tzinfo_identifier - twz = ActiveSupport::TimeWithZone.new(@utc, TZInfo::Timezone.get('America/New_York')) + twz = ActiveSupport::TimeWithZone.new(@utc, TZInfo::Timezone.get("America/New_York")) marshal_str = Marshal.dump(twz) mtime = Marshal.load(marshal_str) assert_equal Time.utc(2000, 1, 1, 0), mtime.utc assert mtime.utc.utc? - assert_equal 'America/New_York', mtime.time_zone.name + assert_equal "America/New_York", mtime.time_zone.name assert_equal Time.utc(1999, 12, 31, 19), mtime.time assert mtime.time.utc? assert_equal @twz.inspect, mtime.inspect @@ -508,8 +508,8 @@ class TimeWithZoneTest < ActiveSupport::TestCase def test_method_missing_with_non_time_return_value time = @twz.time - def time.foo; 'bar'; end - assert_equal 'bar', @twz.foo + def time.foo; "bar"; end + assert_equal "bar", @twz.foo end def test_date_part_value_methods @@ -543,9 +543,9 @@ class TimeWithZoneTest < ActiveSupport::TestCase end def test_utc_to_local_conversion_saves_period_in_instance_variable - assert_nil @twz.instance_variable_get('@period') + assert_nil @twz.instance_variable_get("@period") @twz.time - assert_kind_of TZInfo::TimezonePeriod, @twz.instance_variable_get('@period') + assert_kind_of TZInfo::TimezonePeriod, @twz.instance_variable_get("@period") end def test_instance_created_with_local_time_returns_correct_utc_time @@ -557,14 +557,14 @@ class TimeWithZoneTest < ActiveSupport::TestCase twz = ActiveSupport::TimeWithZone.new(nil, @time_zone, Time.utc(2006,4,2,2)) # first second of DST assert_equal Time.utc(2006,4,2,3), twz.time # springs forward to 3AM assert_equal true, twz.dst? - assert_equal 'EDT', twz.zone + assert_equal "EDT", twz.zone end def test_instance_created_with_local_time_enforces_fall_dst_rules twz = ActiveSupport::TimeWithZone.new(nil, @time_zone, Time.utc(2006,10,29,1)) # 1AM can be either DST or non-DST; we'll pick DST assert_equal Time.utc(2006,10,29,1), twz.time assert_equal true, twz.dst? - assert_equal 'EDT', twz.zone + assert_equal "EDT", twz.zone end def test_ruby_19_weekday_name_query_methods @@ -584,33 +584,33 @@ class TimeWithZoneTest < ActiveSupport::TestCase def test_change assert_equal "Fri, 31 Dec 1999 19:00:00 EST -05:00", @twz.inspect - assert_equal "Mon, 31 Dec 2001 19:00:00 EST -05:00", @twz.change(:year => 2001).inspect - assert_equal "Wed, 31 Mar 1999 19:00:00 EST -05:00", @twz.change(:month => 3).inspect - assert_equal "Wed, 03 Mar 1999 19:00:00 EST -05:00", @twz.change(:month => 2).inspect - assert_equal "Wed, 15 Dec 1999 19:00:00 EST -05:00", @twz.change(:day => 15).inspect - assert_equal "Fri, 31 Dec 1999 06:00:00 EST -05:00", @twz.change(:hour => 6).inspect - assert_equal "Fri, 31 Dec 1999 19:15:00 EST -05:00", @twz.change(:min => 15).inspect - assert_equal "Fri, 31 Dec 1999 19:00:30 EST -05:00", @twz.change(:sec => 30).inspect + assert_equal "Mon, 31 Dec 2001 19:00:00 EST -05:00", @twz.change(year: 2001).inspect + assert_equal "Wed, 31 Mar 1999 19:00:00 EST -05:00", @twz.change(month: 3).inspect + assert_equal "Wed, 03 Mar 1999 19:00:00 EST -05:00", @twz.change(month: 2).inspect + assert_equal "Wed, 15 Dec 1999 19:00:00 EST -05:00", @twz.change(day: 15).inspect + assert_equal "Fri, 31 Dec 1999 06:00:00 EST -05:00", @twz.change(hour: 6).inspect + assert_equal "Fri, 31 Dec 1999 19:15:00 EST -05:00", @twz.change(min: 15).inspect + assert_equal "Fri, 31 Dec 1999 19:00:30 EST -05:00", @twz.change(sec: 30).inspect end def test_change_at_dst_boundary - twz = ActiveSupport::TimeWithZone.new(Time.at(1319936400).getutc, ActiveSupport::TimeZone['Madrid']) - assert_equal twz, twz.change(:min => 0) + twz = ActiveSupport::TimeWithZone.new(Time.at(1319936400).getutc, ActiveSupport::TimeZone["Madrid"]) + assert_equal twz, twz.change(min: 0) end def test_round_at_dst_boundary - twz = ActiveSupport::TimeWithZone.new(Time.at(1319936400).getutc, ActiveSupport::TimeZone['Madrid']) + twz = ActiveSupport::TimeWithZone.new(Time.at(1319936400).getutc, ActiveSupport::TimeZone["Madrid"]) assert_equal twz, twz.round end def test_advance assert_equal "Fri, 31 Dec 1999 19:00:00 EST -05:00", @twz.inspect - assert_equal "Mon, 31 Dec 2001 19:00:00 EST -05:00", @twz.advance(:years => 2).inspect - assert_equal "Fri, 31 Mar 2000 19:00:00 EST -05:00", @twz.advance(:months => 3).inspect - assert_equal "Tue, 04 Jan 2000 19:00:00 EST -05:00", @twz.advance(:days => 4).inspect - assert_equal "Sat, 01 Jan 2000 01:00:00 EST -05:00", @twz.advance(:hours => 6).inspect - assert_equal "Fri, 31 Dec 1999 19:15:00 EST -05:00", @twz.advance(:minutes => 15).inspect - assert_equal "Fri, 31 Dec 1999 19:00:30 EST -05:00", @twz.advance(:seconds => 30).inspect + assert_equal "Mon, 31 Dec 2001 19:00:00 EST -05:00", @twz.advance(years: 2).inspect + assert_equal "Fri, 31 Mar 2000 19:00:00 EST -05:00", @twz.advance(months: 3).inspect + assert_equal "Tue, 04 Jan 2000 19:00:00 EST -05:00", @twz.advance(days: 4).inspect + assert_equal "Sat, 01 Jan 2000 01:00:00 EST -05:00", @twz.advance(hours: 6).inspect + assert_equal "Fri, 31 Dec 1999 19:15:00 EST -05:00", @twz.advance(minutes: 15).inspect + assert_equal "Fri, 31 Dec 1999 19:00:30 EST -05:00", @twz.advance(seconds: 30).inspect end def test_beginning_of_year @@ -685,7 +685,7 @@ class TimeWithZoneTest < ActiveSupport::TestCase def test_advance_1_year_from_leap_day twz = ActiveSupport::TimeWithZone.new(nil, @time_zone, Time.utc(2004,2,29)) - assert_equal "Mon, 28 Feb 2005 00:00:00 EST -05:00", twz.advance(:years => 1).inspect + assert_equal "Mon, 28 Feb 2005 00:00:00 EST -05:00", twz.advance(years: 1).inspect assert_equal "Mon, 28 Feb 2005 00:00:00 EST -05:00", twz.years_since(1).inspect assert_equal "Mon, 28 Feb 2005 00:00:00 EST -05:00", twz.since(1.year).inspect assert_equal "Mon, 28 Feb 2005 00:00:00 EST -05:00", (twz + 1.year).inspect @@ -693,7 +693,7 @@ class TimeWithZoneTest < ActiveSupport::TestCase def test_advance_1_month_from_last_day_of_january twz = ActiveSupport::TimeWithZone.new(nil, @time_zone, Time.utc(2005,1,31)) - assert_equal "Mon, 28 Feb 2005 00:00:00 EST -05:00", twz.advance(:months => 1).inspect + assert_equal "Mon, 28 Feb 2005 00:00:00 EST -05:00", twz.advance(months: 1).inspect assert_equal "Mon, 28 Feb 2005 00:00:00 EST -05:00", twz.months_since(1).inspect assert_equal "Mon, 28 Feb 2005 00:00:00 EST -05:00", twz.since(1.month).inspect assert_equal "Mon, 28 Feb 2005 00:00:00 EST -05:00", (twz + 1.month).inspect @@ -701,7 +701,7 @@ class TimeWithZoneTest < ActiveSupport::TestCase def test_advance_1_month_from_last_day_of_january_during_leap_year twz = ActiveSupport::TimeWithZone.new(nil, @time_zone, Time.utc(2000,1,31)) - assert_equal "Tue, 29 Feb 2000 00:00:00 EST -05:00", twz.advance(:months => 1).inspect + assert_equal "Tue, 29 Feb 2000 00:00:00 EST -05:00", twz.advance(months: 1).inspect assert_equal "Tue, 29 Feb 2000 00:00:00 EST -05:00", twz.months_since(1).inspect assert_equal "Tue, 29 Feb 2000 00:00:00 EST -05:00", twz.since(1.month).inspect assert_equal "Tue, 29 Feb 2000 00:00:00 EST -05:00", (twz + 1.month).inspect @@ -709,7 +709,7 @@ class TimeWithZoneTest < ActiveSupport::TestCase def test_advance_1_month_into_spring_dst_gap twz = ActiveSupport::TimeWithZone.new(nil, @time_zone, Time.utc(2006,3,2,2)) - assert_equal "Sun, 02 Apr 2006 03:00:00 EDT -04:00", twz.advance(:months => 1).inspect + assert_equal "Sun, 02 Apr 2006 03:00:00 EDT -04:00", twz.advance(months: 1).inspect assert_equal "Sun, 02 Apr 2006 03:00:00 EDT -04:00", twz.months_since(1).inspect assert_equal "Sun, 02 Apr 2006 03:00:00 EDT -04:00", twz.since(1.month).inspect assert_equal "Sun, 02 Apr 2006 03:00:00 EDT -04:00", (twz + 1.month).inspect @@ -717,7 +717,7 @@ class TimeWithZoneTest < ActiveSupport::TestCase def test_advance_1_second_into_spring_dst_gap twz = ActiveSupport::TimeWithZone.new(nil, @time_zone, Time.utc(2006,4,2,1,59,59)) - assert_equal "Sun, 02 Apr 2006 03:00:00 EDT -04:00", twz.advance(:seconds => 1).inspect + assert_equal "Sun, 02 Apr 2006 03:00:00 EDT -04:00", twz.advance(seconds: 1).inspect assert_equal "Sun, 02 Apr 2006 03:00:00 EDT -04:00", (twz + 1).inspect assert_equal "Sun, 02 Apr 2006 03:00:00 EDT -04:00", twz.since(1).inspect assert_equal "Sun, 02 Apr 2006 03:00:00 EDT -04:00", twz.since(1.second).inspect @@ -728,7 +728,7 @@ class TimeWithZoneTest < ActiveSupport::TestCase twz = ActiveSupport::TimeWithZone.new(nil, @time_zone, Time.utc(2006,4,1,10,30)) # In 2006, spring DST transition occurred Apr 2 at 2AM; this day was only 23 hours long # When we advance 1 day, we want to end up at the same time on the next day - assert_equal "Sun, 02 Apr 2006 10:30:00 EDT -04:00", twz.advance(:days => 1).inspect + assert_equal "Sun, 02 Apr 2006 10:30:00 EDT -04:00", twz.advance(days: 1).inspect assert_equal "Sun, 02 Apr 2006 10:30:00 EDT -04:00", twz.since(1.days).inspect assert_equal "Sun, 02 Apr 2006 10:30:00 EDT -04:00", (twz + 1.days).inspect assert_equal "Sun, 02 Apr 2006 10:30:01 EDT -04:00", twz.since(1.days + 1.second).inspect @@ -739,7 +739,7 @@ class TimeWithZoneTest < ActiveSupport::TestCase twz = ActiveSupport::TimeWithZone.new(nil, @time_zone, Time.utc(2006,4,2,10,30)) # In 2006, spring DST transition occurred Apr 2 at 2AM; this day was only 23 hours long # When we advance back 1 day, we want to end up at the same time on the previous day - assert_equal "Sat, 01 Apr 2006 10:30:00 EST -05:00", twz.advance(:days => -1).inspect + assert_equal "Sat, 01 Apr 2006 10:30:00 EST -05:00", twz.advance(days: -1).inspect assert_equal "Sat, 01 Apr 2006 10:30:00 EST -05:00", twz.ago(1.days).inspect assert_equal "Sat, 01 Apr 2006 10:30:00 EST -05:00", (twz - 1.days).inspect assert_equal "Sat, 01 Apr 2006 10:30:01 EST -05:00", twz.ago(1.days - 1.second).inspect @@ -753,13 +753,13 @@ class TimeWithZoneTest < ActiveSupport::TestCase assert_equal "Sun, 02 Apr 2006 11:30:00 EDT -04:00", (twz + 86400.seconds).inspect assert_equal "Sun, 02 Apr 2006 11:30:00 EDT -04:00", twz.since(86400).inspect assert_equal "Sun, 02 Apr 2006 11:30:00 EDT -04:00", twz.since(86400.seconds).inspect - assert_equal "Sun, 02 Apr 2006 11:30:00 EDT -04:00", twz.advance(:seconds => 86400).inspect + assert_equal "Sun, 02 Apr 2006 11:30:00 EDT -04:00", twz.advance(seconds: 86400).inspect assert_equal "Sun, 02 Apr 2006 11:30:00 EDT -04:00", (twz + 1440.minutes).inspect assert_equal "Sun, 02 Apr 2006 11:30:00 EDT -04:00", twz.since(1440.minutes).inspect - assert_equal "Sun, 02 Apr 2006 11:30:00 EDT -04:00", twz.advance(:minutes => 1440).inspect + assert_equal "Sun, 02 Apr 2006 11:30:00 EDT -04:00", twz.advance(minutes: 1440).inspect assert_equal "Sun, 02 Apr 2006 11:30:00 EDT -04:00", (twz + 24.hours).inspect assert_equal "Sun, 02 Apr 2006 11:30:00 EDT -04:00", twz.since(24.hours).inspect - assert_equal "Sun, 02 Apr 2006 11:30:00 EDT -04:00", twz.advance(:hours => 24).inspect + assert_equal "Sun, 02 Apr 2006 11:30:00 EDT -04:00", twz.advance(hours: 24).inspect end def test_advance_1_day_expressed_as_number_of_seconds_minutes_or_hours_across_spring_dst_transition_backwards @@ -770,20 +770,20 @@ class TimeWithZoneTest < ActiveSupport::TestCase assert_equal "Sat, 01 Apr 2006 10:30:00 EST -05:00", (twz - 86400.seconds).inspect assert_equal "Sat, 01 Apr 2006 10:30:00 EST -05:00", twz.ago(86400).inspect assert_equal "Sat, 01 Apr 2006 10:30:00 EST -05:00", twz.ago(86400.seconds).inspect - assert_equal "Sat, 01 Apr 2006 10:30:00 EST -05:00", twz.advance(:seconds => -86400).inspect + assert_equal "Sat, 01 Apr 2006 10:30:00 EST -05:00", twz.advance(seconds: -86400).inspect assert_equal "Sat, 01 Apr 2006 10:30:00 EST -05:00", (twz - 1440.minutes).inspect assert_equal "Sat, 01 Apr 2006 10:30:00 EST -05:00", twz.ago(1440.minutes).inspect - assert_equal "Sat, 01 Apr 2006 10:30:00 EST -05:00", twz.advance(:minutes => -1440).inspect + assert_equal "Sat, 01 Apr 2006 10:30:00 EST -05:00", twz.advance(minutes: -1440).inspect assert_equal "Sat, 01 Apr 2006 10:30:00 EST -05:00", (twz - 24.hours).inspect assert_equal "Sat, 01 Apr 2006 10:30:00 EST -05:00", twz.ago(24.hours).inspect - assert_equal "Sat, 01 Apr 2006 10:30:00 EST -05:00", twz.advance(:hours => -24).inspect + assert_equal "Sat, 01 Apr 2006 10:30:00 EST -05:00", twz.advance(hours: -24).inspect end def test_advance_1_day_across_fall_dst_transition twz = ActiveSupport::TimeWithZone.new(nil, @time_zone, Time.utc(2006,10,28,10,30)) # In 2006, fall DST transition occurred Oct 29 at 2AM; this day was 25 hours long # When we advance 1 day, we want to end up at the same time on the next day - assert_equal "Sun, 29 Oct 2006 10:30:00 EST -05:00", twz.advance(:days => 1).inspect + assert_equal "Sun, 29 Oct 2006 10:30:00 EST -05:00", twz.advance(days: 1).inspect assert_equal "Sun, 29 Oct 2006 10:30:00 EST -05:00", twz.since(1.days).inspect assert_equal "Sun, 29 Oct 2006 10:30:00 EST -05:00", (twz + 1.days).inspect assert_equal "Sun, 29 Oct 2006 10:30:01 EST -05:00", twz.since(1.days + 1.second).inspect @@ -794,7 +794,7 @@ class TimeWithZoneTest < ActiveSupport::TestCase twz = ActiveSupport::TimeWithZone.new(nil, @time_zone, Time.utc(2006,10,29,10,30)) # In 2006, fall DST transition occurred Oct 29 at 2AM; this day was 25 hours long # When we advance backwards 1 day, we want to end up at the same time on the previous day - assert_equal "Sat, 28 Oct 2006 10:30:00 EDT -04:00", twz.advance(:days => -1).inspect + assert_equal "Sat, 28 Oct 2006 10:30:00 EDT -04:00", twz.advance(days: -1).inspect assert_equal "Sat, 28 Oct 2006 10:30:00 EDT -04:00", twz.ago(1.days).inspect assert_equal "Sat, 28 Oct 2006 10:30:00 EDT -04:00", (twz - 1.days).inspect assert_equal "Sat, 28 Oct 2006 10:30:01 EDT -04:00", twz.ago(1.days - 1.second).inspect @@ -808,13 +808,13 @@ class TimeWithZoneTest < ActiveSupport::TestCase assert_equal "Sun, 29 Oct 2006 09:30:00 EST -05:00", (twz + 86400.seconds).inspect assert_equal "Sun, 29 Oct 2006 09:30:00 EST -05:00", twz.since(86400).inspect assert_equal "Sun, 29 Oct 2006 09:30:00 EST -05:00", twz.since(86400.seconds).inspect - assert_equal "Sun, 29 Oct 2006 09:30:00 EST -05:00", twz.advance(:seconds => 86400).inspect + assert_equal "Sun, 29 Oct 2006 09:30:00 EST -05:00", twz.advance(seconds: 86400).inspect assert_equal "Sun, 29 Oct 2006 09:30:00 EST -05:00", (twz + 1440.minutes).inspect assert_equal "Sun, 29 Oct 2006 09:30:00 EST -05:00", twz.since(1440.minutes).inspect - assert_equal "Sun, 29 Oct 2006 09:30:00 EST -05:00", twz.advance(:minutes => 1440).inspect + assert_equal "Sun, 29 Oct 2006 09:30:00 EST -05:00", twz.advance(minutes: 1440).inspect assert_equal "Sun, 29 Oct 2006 09:30:00 EST -05:00", (twz + 24.hours).inspect assert_equal "Sun, 29 Oct 2006 09:30:00 EST -05:00", twz.since(24.hours).inspect - assert_equal "Sun, 29 Oct 2006 09:30:00 EST -05:00", twz.advance(:hours => 24).inspect + assert_equal "Sun, 29 Oct 2006 09:30:00 EST -05:00", twz.advance(hours: 24).inspect end def test_advance_1_day_expressed_as_number_of_seconds_minutes_or_hours_across_fall_dst_transition_backwards @@ -825,18 +825,18 @@ class TimeWithZoneTest < ActiveSupport::TestCase assert_equal "Sat, 28 Oct 2006 10:30:00 EDT -04:00", (twz - 86400.seconds).inspect assert_equal "Sat, 28 Oct 2006 10:30:00 EDT -04:00", twz.ago(86400).inspect assert_equal "Sat, 28 Oct 2006 10:30:00 EDT -04:00", twz.ago(86400.seconds).inspect - assert_equal "Sat, 28 Oct 2006 10:30:00 EDT -04:00", twz.advance(:seconds => -86400).inspect + assert_equal "Sat, 28 Oct 2006 10:30:00 EDT -04:00", twz.advance(seconds: -86400).inspect assert_equal "Sat, 28 Oct 2006 10:30:00 EDT -04:00", (twz - 1440.minutes).inspect assert_equal "Sat, 28 Oct 2006 10:30:00 EDT -04:00", twz.ago(1440.minutes).inspect - assert_equal "Sat, 28 Oct 2006 10:30:00 EDT -04:00", twz.advance(:minutes => -1440).inspect + assert_equal "Sat, 28 Oct 2006 10:30:00 EDT -04:00", twz.advance(minutes: -1440).inspect assert_equal "Sat, 28 Oct 2006 10:30:00 EDT -04:00", (twz - 24.hours).inspect assert_equal "Sat, 28 Oct 2006 10:30:00 EDT -04:00", twz.ago(24.hours).inspect - assert_equal "Sat, 28 Oct 2006 10:30:00 EDT -04:00", twz.advance(:hours => -24).inspect + assert_equal "Sat, 28 Oct 2006 10:30:00 EDT -04:00", twz.advance(hours: -24).inspect end def test_advance_1_week_across_spring_dst_transition twz = ActiveSupport::TimeWithZone.new(nil, @time_zone, Time.utc(2006,4,1,10,30)) - assert_equal "Sat, 08 Apr 2006 10:30:00 EDT -04:00", twz.advance(:weeks => 1).inspect + assert_equal "Sat, 08 Apr 2006 10:30:00 EDT -04:00", twz.advance(weeks: 1).inspect assert_equal "Sat, 08 Apr 2006 10:30:00 EDT -04:00", twz.weeks_since(1).inspect assert_equal "Sat, 08 Apr 2006 10:30:00 EDT -04:00", twz.since(1.week).inspect assert_equal "Sat, 08 Apr 2006 10:30:00 EDT -04:00", (twz + 1.week).inspect @@ -844,7 +844,7 @@ class TimeWithZoneTest < ActiveSupport::TestCase def test_advance_1_week_across_spring_dst_transition_backwards twz = ActiveSupport::TimeWithZone.new(nil, @time_zone, Time.utc(2006,4,8,10,30)) - assert_equal "Sat, 01 Apr 2006 10:30:00 EST -05:00", twz.advance(:weeks => -1).inspect + assert_equal "Sat, 01 Apr 2006 10:30:00 EST -05:00", twz.advance(weeks: -1).inspect assert_equal "Sat, 01 Apr 2006 10:30:00 EST -05:00", twz.weeks_ago(1).inspect assert_equal "Sat, 01 Apr 2006 10:30:00 EST -05:00", twz.ago(1.week).inspect assert_equal "Sat, 01 Apr 2006 10:30:00 EST -05:00", (twz - 1.week).inspect @@ -852,7 +852,7 @@ class TimeWithZoneTest < ActiveSupport::TestCase def test_advance_1_week_across_fall_dst_transition twz = ActiveSupport::TimeWithZone.new(nil, @time_zone, Time.utc(2006,10,28,10,30)) - assert_equal "Sat, 04 Nov 2006 10:30:00 EST -05:00", twz.advance(:weeks => 1).inspect + assert_equal "Sat, 04 Nov 2006 10:30:00 EST -05:00", twz.advance(weeks: 1).inspect assert_equal "Sat, 04 Nov 2006 10:30:00 EST -05:00", twz.weeks_since(1).inspect assert_equal "Sat, 04 Nov 2006 10:30:00 EST -05:00", twz.since(1.week).inspect assert_equal "Sat, 04 Nov 2006 10:30:00 EST -05:00", (twz + 1.week).inspect @@ -860,7 +860,7 @@ class TimeWithZoneTest < ActiveSupport::TestCase def test_advance_1_week_across_fall_dst_transition_backwards twz = ActiveSupport::TimeWithZone.new(nil, @time_zone, Time.utc(2006,11,4,10,30)) - assert_equal "Sat, 28 Oct 2006 10:30:00 EDT -04:00", twz.advance(:weeks => -1).inspect + assert_equal "Sat, 28 Oct 2006 10:30:00 EDT -04:00", twz.advance(weeks: -1).inspect assert_equal "Sat, 28 Oct 2006 10:30:00 EDT -04:00", twz.weeks_ago(1).inspect assert_equal "Sat, 28 Oct 2006 10:30:00 EDT -04:00", twz.ago(1.week).inspect assert_equal "Sat, 28 Oct 2006 10:30:00 EDT -04:00", (twz - 1.week).inspect @@ -868,7 +868,7 @@ class TimeWithZoneTest < ActiveSupport::TestCase def test_advance_1_month_across_spring_dst_transition twz = ActiveSupport::TimeWithZone.new(nil, @time_zone, Time.utc(2006,4,1,10,30)) - assert_equal "Mon, 01 May 2006 10:30:00 EDT -04:00", twz.advance(:months => 1).inspect + assert_equal "Mon, 01 May 2006 10:30:00 EDT -04:00", twz.advance(months: 1).inspect assert_equal "Mon, 01 May 2006 10:30:00 EDT -04:00", twz.months_since(1).inspect assert_equal "Mon, 01 May 2006 10:30:00 EDT -04:00", twz.since(1.month).inspect assert_equal "Mon, 01 May 2006 10:30:00 EDT -04:00", (twz + 1.month).inspect @@ -876,7 +876,7 @@ class TimeWithZoneTest < ActiveSupport::TestCase def test_advance_1_month_across_spring_dst_transition_backwards twz = ActiveSupport::TimeWithZone.new(nil, @time_zone, Time.utc(2006,5,1,10,30)) - assert_equal "Sat, 01 Apr 2006 10:30:00 EST -05:00", twz.advance(:months => -1).inspect + assert_equal "Sat, 01 Apr 2006 10:30:00 EST -05:00", twz.advance(months: -1).inspect assert_equal "Sat, 01 Apr 2006 10:30:00 EST -05:00", twz.months_ago(1).inspect assert_equal "Sat, 01 Apr 2006 10:30:00 EST -05:00", twz.ago(1.month).inspect assert_equal "Sat, 01 Apr 2006 10:30:00 EST -05:00", (twz - 1.month).inspect @@ -884,7 +884,7 @@ class TimeWithZoneTest < ActiveSupport::TestCase def test_advance_1_month_across_fall_dst_transition twz = ActiveSupport::TimeWithZone.new(nil, @time_zone, Time.utc(2006,10,28,10,30)) - assert_equal "Tue, 28 Nov 2006 10:30:00 EST -05:00", twz.advance(:months => 1).inspect + assert_equal "Tue, 28 Nov 2006 10:30:00 EST -05:00", twz.advance(months: 1).inspect assert_equal "Tue, 28 Nov 2006 10:30:00 EST -05:00", twz.months_since(1).inspect assert_equal "Tue, 28 Nov 2006 10:30:00 EST -05:00", twz.since(1.month).inspect assert_equal "Tue, 28 Nov 2006 10:30:00 EST -05:00", (twz + 1.month).inspect @@ -892,7 +892,7 @@ class TimeWithZoneTest < ActiveSupport::TestCase def test_advance_1_month_across_fall_dst_transition_backwards twz = ActiveSupport::TimeWithZone.new(nil, @time_zone, Time.utc(2006,11,28,10,30)) - assert_equal "Sat, 28 Oct 2006 10:30:00 EDT -04:00", twz.advance(:months => -1).inspect + assert_equal "Sat, 28 Oct 2006 10:30:00 EDT -04:00", twz.advance(months: -1).inspect assert_equal "Sat, 28 Oct 2006 10:30:00 EDT -04:00", twz.months_ago(1).inspect assert_equal "Sat, 28 Oct 2006 10:30:00 EDT -04:00", twz.ago(1.month).inspect assert_equal "Sat, 28 Oct 2006 10:30:00 EDT -04:00", (twz - 1.month).inspect @@ -900,20 +900,20 @@ class TimeWithZoneTest < ActiveSupport::TestCase def test_advance_1_year twz = ActiveSupport::TimeWithZone.new(nil, @time_zone, Time.utc(2008,2,15,10,30)) - assert_equal "Sun, 15 Feb 2009 10:30:00 EST -05:00", twz.advance(:years => 1).inspect + assert_equal "Sun, 15 Feb 2009 10:30:00 EST -05:00", twz.advance(years: 1).inspect assert_equal "Sun, 15 Feb 2009 10:30:00 EST -05:00", twz.years_since(1).inspect assert_equal "Sun, 15 Feb 2009 10:30:00 EST -05:00", (twz + 1.year).inspect - assert_equal "Thu, 15 Feb 2007 10:30:00 EST -05:00", twz.advance(:years => -1).inspect + assert_equal "Thu, 15 Feb 2007 10:30:00 EST -05:00", twz.advance(years: -1).inspect assert_equal "Thu, 15 Feb 2007 10:30:00 EST -05:00", twz.years_ago(1).inspect assert_equal "Thu, 15 Feb 2007 10:30:00 EST -05:00", (twz - 1.year).inspect end def test_advance_1_year_during_dst twz = ActiveSupport::TimeWithZone.new(nil, @time_zone, Time.utc(2008,7,15,10,30)) - assert_equal "Wed, 15 Jul 2009 10:30:00 EDT -04:00", twz.advance(:years => 1).inspect + assert_equal "Wed, 15 Jul 2009 10:30:00 EDT -04:00", twz.advance(years: 1).inspect assert_equal "Wed, 15 Jul 2009 10:30:00 EDT -04:00", twz.years_since(1).inspect assert_equal "Wed, 15 Jul 2009 10:30:00 EDT -04:00", (twz + 1.year).inspect - assert_equal "Sun, 15 Jul 2007 10:30:00 EDT -04:00", twz.advance(:years => -1).inspect + assert_equal "Sun, 15 Jul 2007 10:30:00 EDT -04:00", twz.advance(years: -1).inspect assert_equal "Sun, 15 Jul 2007 10:30:00 EDT -04:00", twz.years_ago(1).inspect assert_equal "Sun, 15 Jul 2007 10:30:00 EDT -04:00", (twz - 1.year).inspect end @@ -941,13 +941,13 @@ class TimeWithZoneMethodsForTimeAndDateTimeTest < ActiveSupport::TestCase end def test_in_time_zone - Time.use_zone 'Alaska' do - assert_equal 'Fri, 31 Dec 1999 15:00:00 AKST -09:00', @t.in_time_zone.inspect - assert_equal 'Fri, 31 Dec 1999 15:00:00 AKST -09:00', @dt.in_time_zone.inspect + Time.use_zone "Alaska" do + assert_equal "Fri, 31 Dec 1999 15:00:00 AKST -09:00", @t.in_time_zone.inspect + assert_equal "Fri, 31 Dec 1999 15:00:00 AKST -09:00", @dt.in_time_zone.inspect end - Time.use_zone 'Hawaii' do - assert_equal 'Fri, 31 Dec 1999 14:00:00 HST -10:00', @t.in_time_zone.inspect - assert_equal 'Fri, 31 Dec 1999 14:00:00 HST -10:00', @dt.in_time_zone.inspect + Time.use_zone "Hawaii" do + assert_equal "Fri, 31 Dec 1999 14:00:00 HST -10:00", @t.in_time_zone.inspect + assert_equal "Fri, 31 Dec 1999 14:00:00 HST -10:00", @dt.in_time_zone.inspect end Time.use_zone nil do assert_equal @t, @t.in_time_zone @@ -957,20 +957,20 @@ class TimeWithZoneMethodsForTimeAndDateTimeTest < ActiveSupport::TestCase def test_nil_time_zone Time.use_zone nil do - assert !@t.in_time_zone.respond_to?(:period), 'no period method' - assert !@dt.in_time_zone.respond_to?(:period), 'no period method' + assert !@t.in_time_zone.respond_to?(:period), "no period method" + assert !@dt.in_time_zone.respond_to?(:period), "no period method" end end def test_in_time_zone_with_argument - Time.use_zone 'Eastern Time (US & Canada)' do # Time.zone will not affect #in_time_zone(zone) - assert_equal 'Fri, 31 Dec 1999 15:00:00 AKST -09:00', @t.in_time_zone('Alaska').inspect - assert_equal 'Fri, 31 Dec 1999 15:00:00 AKST -09:00', @dt.in_time_zone('Alaska').inspect - assert_equal 'Fri, 31 Dec 1999 14:00:00 HST -10:00', @t.in_time_zone('Hawaii').inspect - assert_equal 'Fri, 31 Dec 1999 14:00:00 HST -10:00', @dt.in_time_zone('Hawaii').inspect - assert_equal 'Sat, 01 Jan 2000 00:00:00 UTC +00:00', @t.in_time_zone('UTC').inspect - assert_equal 'Sat, 01 Jan 2000 00:00:00 UTC +00:00', @dt.in_time_zone('UTC').inspect - assert_equal 'Fri, 31 Dec 1999 15:00:00 AKST -09:00', @t.in_time_zone(-9.hours).inspect + Time.use_zone "Eastern Time (US & Canada)" do # Time.zone will not affect #in_time_zone(zone) + assert_equal "Fri, 31 Dec 1999 15:00:00 AKST -09:00", @t.in_time_zone("Alaska").inspect + assert_equal "Fri, 31 Dec 1999 15:00:00 AKST -09:00", @dt.in_time_zone("Alaska").inspect + assert_equal "Fri, 31 Dec 1999 14:00:00 HST -10:00", @t.in_time_zone("Hawaii").inspect + assert_equal "Fri, 31 Dec 1999 14:00:00 HST -10:00", @dt.in_time_zone("Hawaii").inspect + assert_equal "Sat, 01 Jan 2000 00:00:00 UTC +00:00", @t.in_time_zone("UTC").inspect + assert_equal "Sat, 01 Jan 2000 00:00:00 UTC +00:00", @dt.in_time_zone("UTC").inspect + assert_equal "Fri, 31 Dec 1999 15:00:00 AKST -09:00", @t.in_time_zone(-9.hours).inspect end end @@ -984,119 +984,119 @@ class TimeWithZoneMethodsForTimeAndDateTimeTest < ActiveSupport::TestCase end def test_in_time_zone_with_time_local_instance - with_env_tz 'US/Eastern' do + with_env_tz "US/Eastern" do time = Time.local(1999, 12, 31, 19) # == Time.utc(2000) - assert_equal 'Fri, 31 Dec 1999 15:00:00 AKST -09:00', time.in_time_zone('Alaska').inspect + assert_equal "Fri, 31 Dec 1999 15:00:00 AKST -09:00", time.in_time_zone("Alaska").inspect end end def test_localtime - Time.zone = ActiveSupport::TimeZone['Eastern Time (US & Canada)'] + Time.zone = ActiveSupport::TimeZone["Eastern Time (US & Canada)"] assert_equal @dt.in_time_zone.localtime, @dt.in_time_zone.utc.to_time.getlocal end def test_use_zone - Time.zone = 'Alaska' - Time.use_zone 'Hawaii' do - assert_equal ActiveSupport::TimeZone['Hawaii'], Time.zone + Time.zone = "Alaska" + Time.use_zone "Hawaii" do + assert_equal ActiveSupport::TimeZone["Hawaii"], Time.zone end - assert_equal ActiveSupport::TimeZone['Alaska'], Time.zone + assert_equal ActiveSupport::TimeZone["Alaska"], Time.zone end def test_use_zone_with_exception_raised - Time.zone = 'Alaska' + Time.zone = "Alaska" assert_raise RuntimeError do - Time.use_zone('Hawaii') { raise RuntimeError } + Time.use_zone("Hawaii") { raise RuntimeError } end - assert_equal ActiveSupport::TimeZone['Alaska'], Time.zone + assert_equal ActiveSupport::TimeZone["Alaska"], Time.zone end def test_use_zone_raises_on_invalid_timezone - Time.zone = 'Alaska' + Time.zone = "Alaska" assert_raise ArgumentError do - Time.use_zone("No such timezone exists") { } + Time.use_zone("No such timezone exists") {} end - assert_equal ActiveSupport::TimeZone['Alaska'], Time.zone + assert_equal ActiveSupport::TimeZone["Alaska"], Time.zone end def test_time_zone_getter_and_setter - Time.zone = ActiveSupport::TimeZone['Alaska'] - assert_equal ActiveSupport::TimeZone['Alaska'], Time.zone - Time.zone = 'Alaska' - assert_equal ActiveSupport::TimeZone['Alaska'], Time.zone + Time.zone = ActiveSupport::TimeZone["Alaska"] + assert_equal ActiveSupport::TimeZone["Alaska"], Time.zone + Time.zone = "Alaska" + assert_equal ActiveSupport::TimeZone["Alaska"], Time.zone Time.zone = -9.hours - assert_equal ActiveSupport::TimeZone['Alaska'], Time.zone + assert_equal ActiveSupport::TimeZone["Alaska"], Time.zone Time.zone = nil assert_equal nil, Time.zone end def test_time_zone_getter_and_setter_with_zone_default_set old_zone_default = Time.zone_default - Time.zone_default = ActiveSupport::TimeZone['Alaska'] - assert_equal ActiveSupport::TimeZone['Alaska'], Time.zone - Time.zone = ActiveSupport::TimeZone['Hawaii'] - assert_equal ActiveSupport::TimeZone['Hawaii'], Time.zone + Time.zone_default = ActiveSupport::TimeZone["Alaska"] + assert_equal ActiveSupport::TimeZone["Alaska"], Time.zone + Time.zone = ActiveSupport::TimeZone["Hawaii"] + assert_equal ActiveSupport::TimeZone["Hawaii"], Time.zone Time.zone = nil - assert_equal ActiveSupport::TimeZone['Alaska'], Time.zone + assert_equal ActiveSupport::TimeZone["Alaska"], Time.zone ensure Time.zone_default = old_zone_default end def test_time_zone_setter_is_thread_safe - Time.use_zone 'Paris' do - t1 = Thread.new { Time.zone = 'Alaska' }.join - t2 = Thread.new { Time.zone = 'Hawaii' }.join + Time.use_zone "Paris" do + t1 = Thread.new { Time.zone = "Alaska" }.join + t2 = Thread.new { Time.zone = "Hawaii" }.join assert t1.stop?, "Thread 1 did not finish running" assert t2.stop?, "Thread 2 did not finish running" - assert_equal ActiveSupport::TimeZone['Paris'], Time.zone - assert_equal ActiveSupport::TimeZone['Alaska'], t1[:time_zone] - assert_equal ActiveSupport::TimeZone['Hawaii'], t2[:time_zone] + assert_equal ActiveSupport::TimeZone["Paris"], Time.zone + assert_equal ActiveSupport::TimeZone["Alaska"], t1[:time_zone] + assert_equal ActiveSupport::TimeZone["Hawaii"], t2[:time_zone] end end def test_time_zone_setter_with_tzinfo_timezone_object_wraps_in_rails_time_zone - tzinfo = TZInfo::Timezone.get('America/New_York') + tzinfo = TZInfo::Timezone.get("America/New_York") Time.zone = tzinfo assert_kind_of ActiveSupport::TimeZone, Time.zone assert_equal tzinfo, Time.zone.tzinfo - assert_equal 'America/New_York', Time.zone.name + assert_equal "America/New_York", Time.zone.name assert_equal(-18_000, Time.zone.utc_offset) end def test_time_zone_setter_with_tzinfo_timezone_identifier_does_lookup_and_wraps_in_rails_time_zone - Time.zone = 'America/New_York' + Time.zone = "America/New_York" assert_kind_of ActiveSupport::TimeZone, Time.zone - assert_equal 'America/New_York', Time.zone.tzinfo.name - assert_equal 'America/New_York', Time.zone.name + assert_equal "America/New_York", Time.zone.tzinfo.name + assert_equal "America/New_York", Time.zone.name assert_equal(-18_000, Time.zone.utc_offset) end def test_time_zone_setter_with_invalid_zone - assert_raise(ArgumentError){ Time.zone = "No such timezone exists" } - assert_raise(ArgumentError){ Time.zone = -15.hours } - assert_raise(ArgumentError){ Time.zone = Object.new } + assert_raise(ArgumentError) { Time.zone = "No such timezone exists" } + assert_raise(ArgumentError) { Time.zone = -15.hours } + assert_raise(ArgumentError) { Time.zone = Object.new } end def test_find_zone_without_bang_returns_nil_if_time_zone_can_not_be_found - assert_nil Time.find_zone('No such timezone exists') + assert_nil Time.find_zone("No such timezone exists") assert_nil Time.find_zone(-15.hours) assert_nil Time.find_zone(Object.new) end def test_find_zone_with_bang_raises_if_time_zone_can_not_be_found - assert_raise(ArgumentError) { Time.find_zone!('No such timezone exists') } + assert_raise(ArgumentError) { Time.find_zone!("No such timezone exists") } assert_raise(ArgumentError) { Time.find_zone!(-15.hours) } assert_raise(ArgumentError) { Time.find_zone!(Object.new) } end def test_time_zone_setter_with_find_zone_without_bang - assert_nil Time.zone = Time.find_zone('No such timezone exists') + assert_nil Time.zone = Time.find_zone("No such timezone exists") assert_nil Time.zone = Time.find_zone(-15.hours) assert_nil Time.zone = Time.find_zone(Object.new) end def test_current_returns_time_now_when_zone_not_set - with_env_tz 'US/Eastern' do + with_env_tz "US/Eastern" do Time.stub(:now, Time.local(2000)) do assert_equal false, Time.current.is_a?(ActiveSupport::TimeWithZone) assert_equal Time.local(2000), Time.current @@ -1105,22 +1105,22 @@ class TimeWithZoneMethodsForTimeAndDateTimeTest < ActiveSupport::TestCase end def test_current_returns_time_zone_now_when_zone_set - Time.zone = ActiveSupport::TimeZone['Eastern Time (US & Canada)'] - with_env_tz 'US/Eastern' do + Time.zone = ActiveSupport::TimeZone["Eastern Time (US & Canada)"] + with_env_tz "US/Eastern" do Time.stub(:now, Time.local(2000)) do assert_equal true, Time.current.is_a?(ActiveSupport::TimeWithZone) - assert_equal 'Eastern Time (US & Canada)', Time.current.time_zone.name + assert_equal "Eastern Time (US & Canada)", Time.current.time_zone.name assert_equal Time.utc(2000), Time.current.time end end end def test_time_in_time_zone_doesnt_affect_receiver - with_env_tz 'Europe/London' do + with_env_tz "Europe/London" do time = Time.local(2000, 7, 1) - time_with_zone = time.in_time_zone('Eastern Time (US & Canada)') + time_with_zone = time.in_time_zone("Eastern Time (US & Canada)") assert_equal Time.utc(2000, 6, 30, 23, 0, 0), time_with_zone - assert_not time.utc?, 'time expected to be local, but is UTC' + assert_not time.utc?, "time expected to be local, but is UTC" end end end @@ -1133,11 +1133,11 @@ class TimeWithZoneMethodsForDate < ActiveSupport::TestCase end def test_in_time_zone - with_tz_default 'Alaska' do - assert_equal 'Sat, 01 Jan 2000 00:00:00 AKST -09:00', @d.in_time_zone.inspect + with_tz_default "Alaska" do + assert_equal "Sat, 01 Jan 2000 00:00:00 AKST -09:00", @d.in_time_zone.inspect end - with_tz_default 'Hawaii' do - assert_equal 'Sat, 01 Jan 2000 00:00:00 HST -10:00', @d.in_time_zone.inspect + with_tz_default "Hawaii" do + assert_equal "Sat, 01 Jan 2000 00:00:00 HST -10:00", @d.in_time_zone.inspect end with_tz_default nil do assert_equal @d.to_time, @d.in_time_zone @@ -1146,16 +1146,16 @@ class TimeWithZoneMethodsForDate < ActiveSupport::TestCase def test_nil_time_zone with_tz_default nil do - assert !@d.in_time_zone.respond_to?(:period), 'no period method' + assert !@d.in_time_zone.respond_to?(:period), "no period method" end end def test_in_time_zone_with_argument - with_tz_default 'Eastern Time (US & Canada)' do # Time.zone will not affect #in_time_zone(zone) - assert_equal 'Sat, 01 Jan 2000 00:00:00 AKST -09:00', @d.in_time_zone('Alaska').inspect - assert_equal 'Sat, 01 Jan 2000 00:00:00 HST -10:00', @d.in_time_zone('Hawaii').inspect - assert_equal 'Sat, 01 Jan 2000 00:00:00 UTC +00:00', @d.in_time_zone('UTC').inspect - assert_equal 'Sat, 01 Jan 2000 00:00:00 AKST -09:00', @d.in_time_zone(-9.hours).inspect + with_tz_default "Eastern Time (US & Canada)" do # Time.zone will not affect #in_time_zone(zone) + assert_equal "Sat, 01 Jan 2000 00:00:00 AKST -09:00", @d.in_time_zone("Alaska").inspect + assert_equal "Sat, 01 Jan 2000 00:00:00 HST -10:00", @d.in_time_zone("Hawaii").inspect + assert_equal "Sat, 01 Jan 2000 00:00:00 UTC +00:00", @d.in_time_zone("UTC").inspect + assert_equal "Sat, 01 Jan 2000 00:00:00 AKST -09:00", @d.in_time_zone(-9.hours).inspect end end @@ -1176,15 +1176,15 @@ class TimeWithZoneMethodsForString < ActiveSupport::TestCase end def test_in_time_zone - with_tz_default 'Alaska' do - assert_equal 'Sat, 01 Jan 2000 00:00:00 AKST -09:00', @s.in_time_zone.inspect - assert_equal 'Fri, 31 Dec 1999 15:00:00 AKST -09:00', @u.in_time_zone.inspect - assert_equal 'Fri, 31 Dec 1999 15:00:00 AKST -09:00', @z.in_time_zone.inspect + with_tz_default "Alaska" do + assert_equal "Sat, 01 Jan 2000 00:00:00 AKST -09:00", @s.in_time_zone.inspect + assert_equal "Fri, 31 Dec 1999 15:00:00 AKST -09:00", @u.in_time_zone.inspect + assert_equal "Fri, 31 Dec 1999 15:00:00 AKST -09:00", @z.in_time_zone.inspect end - with_tz_default 'Hawaii' do - assert_equal 'Sat, 01 Jan 2000 00:00:00 HST -10:00', @s.in_time_zone.inspect - assert_equal 'Fri, 31 Dec 1999 14:00:00 HST -10:00', @u.in_time_zone.inspect - assert_equal 'Fri, 31 Dec 1999 14:00:00 HST -10:00', @z.in_time_zone.inspect + with_tz_default "Hawaii" do + assert_equal "Sat, 01 Jan 2000 00:00:00 HST -10:00", @s.in_time_zone.inspect + assert_equal "Fri, 31 Dec 1999 14:00:00 HST -10:00", @u.in_time_zone.inspect + assert_equal "Fri, 31 Dec 1999 14:00:00 HST -10:00", @z.in_time_zone.inspect end with_tz_default nil do assert_equal @s.to_time, @s.in_time_zone @@ -1195,26 +1195,26 @@ class TimeWithZoneMethodsForString < ActiveSupport::TestCase def test_nil_time_zone with_tz_default nil do - assert !@s.in_time_zone.respond_to?(:period), 'no period method' - assert !@u.in_time_zone.respond_to?(:period), 'no period method' - assert !@z.in_time_zone.respond_to?(:period), 'no period method' + assert !@s.in_time_zone.respond_to?(:period), "no period method" + assert !@u.in_time_zone.respond_to?(:period), "no period method" + assert !@z.in_time_zone.respond_to?(:period), "no period method" end end def test_in_time_zone_with_argument - with_tz_default 'Eastern Time (US & Canada)' do # Time.zone will not affect #in_time_zone(zone) - assert_equal 'Sat, 01 Jan 2000 00:00:00 AKST -09:00', @s.in_time_zone('Alaska').inspect - assert_equal 'Fri, 31 Dec 1999 15:00:00 AKST -09:00', @u.in_time_zone('Alaska').inspect - assert_equal 'Fri, 31 Dec 1999 15:00:00 AKST -09:00', @z.in_time_zone('Alaska').inspect - assert_equal 'Sat, 01 Jan 2000 00:00:00 HST -10:00', @s.in_time_zone('Hawaii').inspect - assert_equal 'Fri, 31 Dec 1999 14:00:00 HST -10:00', @u.in_time_zone('Hawaii').inspect - assert_equal 'Fri, 31 Dec 1999 14:00:00 HST -10:00', @z.in_time_zone('Hawaii').inspect - assert_equal 'Sat, 01 Jan 2000 00:00:00 UTC +00:00', @s.in_time_zone('UTC').inspect - assert_equal 'Sat, 01 Jan 2000 00:00:00 UTC +00:00', @u.in_time_zone('UTC').inspect - assert_equal 'Sat, 01 Jan 2000 00:00:00 UTC +00:00', @z.in_time_zone('UTC').inspect - assert_equal 'Sat, 01 Jan 2000 00:00:00 AKST -09:00', @s.in_time_zone(-9.hours).inspect - assert_equal 'Fri, 31 Dec 1999 15:00:00 AKST -09:00', @u.in_time_zone(-9.hours).inspect - assert_equal 'Fri, 31 Dec 1999 15:00:00 AKST -09:00', @z.in_time_zone(-9.hours).inspect + with_tz_default "Eastern Time (US & Canada)" do # Time.zone will not affect #in_time_zone(zone) + assert_equal "Sat, 01 Jan 2000 00:00:00 AKST -09:00", @s.in_time_zone("Alaska").inspect + assert_equal "Fri, 31 Dec 1999 15:00:00 AKST -09:00", @u.in_time_zone("Alaska").inspect + assert_equal "Fri, 31 Dec 1999 15:00:00 AKST -09:00", @z.in_time_zone("Alaska").inspect + assert_equal "Sat, 01 Jan 2000 00:00:00 HST -10:00", @s.in_time_zone("Hawaii").inspect + assert_equal "Fri, 31 Dec 1999 14:00:00 HST -10:00", @u.in_time_zone("Hawaii").inspect + assert_equal "Fri, 31 Dec 1999 14:00:00 HST -10:00", @z.in_time_zone("Hawaii").inspect + assert_equal "Sat, 01 Jan 2000 00:00:00 UTC +00:00", @s.in_time_zone("UTC").inspect + assert_equal "Sat, 01 Jan 2000 00:00:00 UTC +00:00", @u.in_time_zone("UTC").inspect + assert_equal "Sat, 01 Jan 2000 00:00:00 UTC +00:00", @z.in_time_zone("UTC").inspect + assert_equal "Sat, 01 Jan 2000 00:00:00 AKST -09:00", @s.in_time_zone(-9.hours).inspect + assert_equal "Fri, 31 Dec 1999 15:00:00 AKST -09:00", @u.in_time_zone(-9.hours).inspect + assert_equal "Fri, 31 Dec 1999 15:00:00 AKST -09:00", @z.in_time_zone(-9.hours).inspect end end diff --git a/activesupport/test/core_ext/uri_ext_test.rb b/activesupport/test/core_ext/uri_ext_test.rb index 1694fe7e72..0f13ca9c0e 100644 --- a/activesupport/test/core_ext/uri_ext_test.rb +++ b/activesupport/test/core_ext/uri_ext_test.rb @@ -1,6 +1,6 @@ -require 'abstract_unit' -require 'uri' -require 'active_support/core_ext/uri' +require "abstract_unit" +require "uri" +require "active_support/core_ext/uri" class URIExtTest < ActiveSupport::TestCase def test_uri_decode_handle_multibyte 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/mutual_one.rb b/activesupport/test/dependencies/mutual_one.rb index 576eb31711..05f08f82d3 100644 --- a/activesupport/test/dependencies/mutual_one.rb +++ b/activesupport/test/dependencies/mutual_one.rb @@ -1,4 +1,4 @@ $mutual_dependencies_count += 1 -require_dependency 'mutual_two' -require_dependency 'mutual_two.rb' -require_dependency 'mutual_two' +require_dependency "mutual_two" +require_dependency "mutual_two.rb" +require_dependency "mutual_two" diff --git a/activesupport/test/dependencies/mutual_two.rb b/activesupport/test/dependencies/mutual_two.rb index fdbc2dcd84..1d87d334af 100644 --- a/activesupport/test/dependencies/mutual_two.rb +++ b/activesupport/test/dependencies/mutual_two.rb @@ -1,4 +1,4 @@ $mutual_dependencies_count += 1 -require_dependency 'mutual_one.rb' -require_dependency 'mutual_one' -require_dependency 'mutual_one.rb' +require_dependency "mutual_one.rb" +require_dependency "mutual_one" +require_dependency "mutual_one.rb" diff --git a/activesupport/test/dependencies/raises_exception.rb b/activesupport/test/dependencies/raises_exception.rb index dd745ac20e..0a56680fe3 100644 --- a/activesupport/test/dependencies/raises_exception.rb +++ b/activesupport/test/dependencies/raises_exception.rb @@ -1,3 +1,3 @@ $raises_exception_load_count += 1 -raise Exception, 'Loading me failed, so do not add to loaded or history.' +raise Exception, "Loading me failed, so do not add to loaded or history." $raises_exception_load_count += 1 diff --git a/activesupport/test/dependencies/raises_exception_without_blame_file.rb b/activesupport/test/dependencies/raises_exception_without_blame_file.rb index 4b2da6ff30..7c3856b1e6 100644 --- a/activesupport/test/dependencies/raises_exception_without_blame_file.rb +++ b/activesupport/test/dependencies/raises_exception_without_blame_file.rb @@ -1,4 +1,4 @@ -exception = Exception.new('I am not blamable!') +exception = Exception.new("I am not blamable!") class << exception undef_method(:blame_file!) end diff --git a/activesupport/test/dependencies/requires_nonexistent0.rb b/activesupport/test/dependencies/requires_nonexistent0.rb index 7e24b3916c..7f8a0d8419 100644 --- a/activesupport/test/dependencies/requires_nonexistent0.rb +++ b/activesupport/test/dependencies/requires_nonexistent0.rb @@ -1 +1 @@ -require 'RMagickDontExistDude' +require "RMagickDontExistDude" diff --git a/activesupport/test/dependencies/requires_nonexistent1.rb b/activesupport/test/dependencies/requires_nonexistent1.rb index 41e6668164..0055177d67 100644 --- a/activesupport/test/dependencies/requires_nonexistent1.rb +++ b/activesupport/test/dependencies/requires_nonexistent1.rb @@ -1 +1 @@ -require_dependency 'requires_nonexistent0' +require_dependency "requires_nonexistent0" 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.rb b/activesupport/test/dependencies_test.rb index 04e7b24d30..e0edb4a086 100644 --- a/activesupport/test/dependencies_test.rb +++ b/activesupport/test/dependencies_test.rb @@ -1,7 +1,7 @@ -require 'abstract_unit' -require 'pp' -require 'active_support/dependencies' -require 'dependencies_test_helpers' +require "abstract_unit" +require "pp" +require "active_support/dependencies" +require "dependencies_test_helpers" module ModuleWithMissing mattr_accessor :missing_count @@ -29,18 +29,18 @@ class DependenciesTest < ActiveSupport::TestCase def test_depend_on_path expected = assert_raises(LoadError) do - Kernel.require 'omgwtfbbq' + Kernel.require "omgwtfbbq" end e = assert_raises(LoadError) do - ActiveSupport::Dependencies.depend_on 'omgwtfbbq' + ActiveSupport::Dependencies.depend_on "omgwtfbbq" end assert_equal expected.path, e.path end def test_require_dependency_accepts_an_object_which_implements_to_path o = Object.new - def o.to_path; 'dependencies/service_one'; end + def o.to_path; "dependencies/service_one"; end assert_nothing_raised { require_dependency o } @@ -51,8 +51,8 @@ class DependenciesTest < ActiveSupport::TestCase def test_tracking_loaded_files with_loading do - require_dependency 'dependencies/service_one' - require_dependency 'dependencies/service_two' + require_dependency "dependencies/service_one" + require_dependency "dependencies/service_two" assert_equal 2, ActiveSupport::Dependencies.loaded.size end ensure @@ -61,8 +61,8 @@ class DependenciesTest < ActiveSupport::TestCase def test_tracking_identical_loaded_files with_loading do - require_dependency 'dependencies/service_one' - require_dependency 'dependencies/service_one' + require_dependency "dependencies/service_one" + require_dependency "dependencies/service_one" assert_equal 1, ActiveSupport::Dependencies.loaded.size end ensure @@ -75,16 +75,16 @@ class DependenciesTest < ActiveSupport::TestCase def test_dependency_which_raises_exception_isnt_added_to_loaded_set with_loading do - filename = 'dependencies/raises_exception' + filename = "dependencies/raises_exception" expanded = File.expand_path(filename) $raises_exception_load_count = 0 5.times do |count| - e = assert_raise Exception, 'should have loaded dependencies/raises_exception which raises an exception' do + e = assert_raise Exception, "should have loaded dependencies/raises_exception which raises an exception" do require_dependency filename end - assert_equal 'Loading me failed, so do not add to loaded or history.', e.message + assert_equal "Loading me failed, so do not add to loaded or history.", e.message assert_equal count + 1, $raises_exception_load_count assert_not ActiveSupport::Dependencies.loaded.include?(expanded) @@ -95,13 +95,13 @@ class DependenciesTest < ActiveSupport::TestCase def test_dependency_which_raises_doesnt_blindly_call_blame_file! with_loading do - filename = 'dependencies/raises_exception_without_blame_file' + filename = "dependencies/raises_exception_without_blame_file" assert_raises(Exception) { require_dependency filename } end end def test_warnings_should_be_enabled_on_first_load - with_loading 'dependencies' do + with_loading "dependencies" do old_warnings, ActiveSupport::Dependencies.warnings_on_first_load = ActiveSupport::Dependencies.warnings_on_first_load, true filename = "check_warnings" expanded = File.expand_path("#{File.dirname(__FILE__)}/dependencies/#{filename}") @@ -112,7 +112,7 @@ class DependenciesTest < ActiveSupport::TestCase silence_warnings { require_dependency filename } assert_equal 1, $check_warnings_load_count - assert_equal true, $checked_verbose, 'On first load warnings should be enabled.' + assert_equal true, $checked_verbose, "On first load warnings should be enabled." assert ActiveSupport::Dependencies.loaded.include?(expanded) ActiveSupport::Dependencies.clear @@ -121,7 +121,7 @@ class DependenciesTest < ActiveSupport::TestCase silence_warnings { require_dependency filename } assert_equal 2, $check_warnings_load_count - assert_equal nil, $checked_verbose, 'After first load warnings should be left alone.' + assert_equal nil, $checked_verbose, "After first load warnings should be left alone." assert ActiveSupport::Dependencies.loaded.include?(expanded) ActiveSupport::Dependencies.clear @@ -130,7 +130,7 @@ class DependenciesTest < ActiveSupport::TestCase enable_warnings { require_dependency filename } assert_equal 3, $check_warnings_load_count - assert_equal true, $checked_verbose, 'After first load warnings should be left alone.' + assert_equal true, $checked_verbose, "After first load warnings should be left alone." assert ActiveSupport::Dependencies.loaded.include?(expanded) ActiveSupport::Dependencies.warnings_on_first_load = old_warnings @@ -138,15 +138,15 @@ class DependenciesTest < ActiveSupport::TestCase end def test_mutual_dependencies_dont_infinite_loop - with_loading 'dependencies' do + with_loading "dependencies" do $mutual_dependencies_count = 0 - assert_nothing_raised { require_dependency 'mutual_one' } + assert_nothing_raised { require_dependency "mutual_one" } assert_equal 2, $mutual_dependencies_count ActiveSupport::Dependencies.clear $mutual_dependencies_count = 0 - assert_nothing_raised { require_dependency 'mutual_two' } + assert_nothing_raised { require_dependency "mutual_two" } assert_equal 2, $mutual_dependencies_count end end @@ -167,7 +167,7 @@ class DependenciesTest < ActiveSupport::TestCase def test_require_dependency_does_not_assume_any_particular_constant_is_defined with_autoloading_fixtures do - require_dependency 'typo' + require_dependency "typo" assert_equal 1, TypO end end @@ -175,7 +175,7 @@ class DependenciesTest < ActiveSupport::TestCase # Regression, see https://github.com/rails/rails/issues/16468. def test_require_dependency_interaction_with_autoloading with_autoloading_fixtures do - require_dependency 'typo' + require_dependency "typo" assert_equal 1, TypO e = assert_raise(LoadError) { Typo } @@ -253,7 +253,7 @@ class DependenciesTest < ActiveSupport::TestCase with_autoloading_fixtures do assert_kind_of Class, ClassFolder::ClassFolderSubclass assert_kind_of Class, ClassFolder - assert_equal 'indeed', ClassFolder::ClassFolderSubclass::ConstantInClassFolder + assert_equal "indeed", ClassFolder::ClassFolderSubclass::ConstantInClassFolder end ensure remove_constants(:ClassFolder) @@ -271,7 +271,7 @@ class DependenciesTest < ActiveSupport::TestCase def test_raising_discards_autoloaded_constants with_autoloading_fixtures do - assert_raises(Exception, 'arbitray exception message') { RaisesArbitraryException } + assert_raises(Exception, "arbitray exception message") { RaisesArbitraryException } assert_not defined?(A) assert_not defined?(RaisesArbitraryException) end @@ -336,7 +336,7 @@ class DependenciesTest < ActiveSupport::TestCase $:.push(path) with_loading do - assert_equal true, require('loaded_constant') + assert_equal true, require("loaded_constant") end ensure remove_constants(:LoadedConstant) @@ -350,7 +350,7 @@ class DependenciesTest < ActiveSupport::TestCase with_loading do Object.module_eval "module LoadedConstant; end" - assert_equal true, require('loaded_constant') + assert_equal true, require("loaded_constant") end ensure remove_constants(:LoadedConstant) @@ -363,8 +363,8 @@ class DependenciesTest < ActiveSupport::TestCase $:.push(path) with_loading do - require 'loaded_constant' - assert_equal false, require('loaded_constant') + require "loaded_constant" + assert_equal false, require("loaded_constant") end ensure remove_constants(:LoadedConstant) @@ -373,7 +373,7 @@ class DependenciesTest < ActiveSupport::TestCase def test_require_raises_load_error_when_file_not_found with_loading do - assert_raise(LoadError) { require 'this_file_dont_exist_dude' } + assert_raise(LoadError) { require "this_file_dont_exist_dude" } end end @@ -383,8 +383,8 @@ class DependenciesTest < ActiveSupport::TestCase $:.push(path) with_loading do - assert_equal true, load('loaded_constant.rb') - assert_equal true, load('loaded_constant.rb') + assert_equal true, load("loaded_constant.rb") + assert_equal true, load("loaded_constant.rb") end ensure remove_constants(:LoadedConstant) @@ -393,7 +393,7 @@ class DependenciesTest < ActiveSupport::TestCase def test_load_raises_load_error_when_file_not_found with_loading do - assert_raise(LoadError) { load 'this_file_dont_exist_dude.rb' } + assert_raise(LoadError) { load "this_file_dont_exist_dude.rb" } end end @@ -429,38 +429,38 @@ class DependenciesTest < ActiveSupport::TestCase end def test_loadable_constants_for_path_should_handle_empty_autoloads - assert_equal [], ActiveSupport::Dependencies.loadable_constants_for_path('hello') + assert_equal [], ActiveSupport::Dependencies.loadable_constants_for_path("hello") end def test_loadable_constants_for_path_should_handle_relative_paths - fake_root = 'dependencies' - relative_root = File.dirname(__FILE__) + '/dependencies' - ['', '/'].each do |suffix| + fake_root = "dependencies" + relative_root = File.dirname(__FILE__) + "/dependencies" + ["", "/"].each do |suffix| with_loading fake_root + suffix do - assert_equal ["A::B"], ActiveSupport::Dependencies.loadable_constants_for_path(relative_root + '/a/b') + assert_equal ["A::B"], ActiveSupport::Dependencies.loadable_constants_for_path(relative_root + "/a/b") end end end def test_loadable_constants_for_path_should_provide_all_results - fake_root = '/usr/apps/backpack' - with_loading fake_root, fake_root + '/lib' do + fake_root = "/usr/apps/backpack" + with_loading fake_root, fake_root + "/lib" do root = ActiveSupport::Dependencies.autoload_paths.first - assert_equal ["Lib::A::B", "A::B"], ActiveSupport::Dependencies.loadable_constants_for_path(root + '/lib/a/b') + assert_equal ["Lib::A::B", "A::B"], ActiveSupport::Dependencies.loadable_constants_for_path(root + "/lib/a/b") end end def test_loadable_constants_for_path_should_uniq_results - fake_root = '/usr/apps/backpack/lib' - with_loading fake_root, fake_root + '/' do + fake_root = "/usr/apps/backpack/lib" + with_loading fake_root, fake_root + "/" do root = ActiveSupport::Dependencies.autoload_paths.first - assert_equal ["A::B"], ActiveSupport::Dependencies.loadable_constants_for_path(root + '/a/b') + assert_equal ["A::B"], ActiveSupport::Dependencies.loadable_constants_for_path(root + "/a/b") end end def test_loadable_constants_with_load_path_without_trailing_slash - path = File.dirname(__FILE__) + '/autoloading_fixtures/class_folder/inline_class.rb' - with_loading 'autoloading_fixtures/class/' do + path = File.dirname(__FILE__) + "/autoloading_fixtures/class_folder/inline_class.rb" + with_loading "autoloading_fixtures/class/" do assert_equal [], ActiveSupport::Dependencies.loadable_constants_for_path(path) end end @@ -524,29 +524,29 @@ class DependenciesTest < ActiveSupport::TestCase end def test_file_search - with_loading 'dependencies' do + with_loading "dependencies" do root = ActiveSupport::Dependencies.autoload_paths.first - assert_equal nil, ActiveSupport::Dependencies.search_for_file('service_three') - assert_equal nil, ActiveSupport::Dependencies.search_for_file('service_three.rb') - assert_equal root + '/service_one.rb', ActiveSupport::Dependencies.search_for_file('service_one') - assert_equal root + '/service_one.rb', ActiveSupport::Dependencies.search_for_file('service_one.rb') + assert_equal nil, ActiveSupport::Dependencies.search_for_file("service_three") + assert_equal nil, ActiveSupport::Dependencies.search_for_file("service_three.rb") + assert_equal root + "/service_one.rb", ActiveSupport::Dependencies.search_for_file("service_one") + assert_equal root + "/service_one.rb", ActiveSupport::Dependencies.search_for_file("service_one.rb") end end def test_file_search_uses_first_in_load_path - with_loading 'dependencies', 'autoloading_fixtures' do + with_loading "dependencies", "autoloading_fixtures" do deps, autoload = ActiveSupport::Dependencies.autoload_paths assert_match %r/dependencies/, deps assert_match %r/autoloading_fixtures/, autoload - assert_equal deps + '/conflict.rb', ActiveSupport::Dependencies.search_for_file('conflict') + assert_equal deps + "/conflict.rb", ActiveSupport::Dependencies.search_for_file("conflict") end - with_loading 'autoloading_fixtures', 'dependencies' do + with_loading "autoloading_fixtures", "dependencies" do autoload, deps = ActiveSupport::Dependencies.autoload_paths assert_match %r/dependencies/, deps assert_match %r/autoloading_fixtures/, autoload - assert_equal autoload + '/conflict.rb', ActiveSupport::Dependencies.search_for_file('conflict') + assert_equal autoload + "/conflict.rb", ActiveSupport::Dependencies.search_for_file("conflict") end end @@ -584,11 +584,11 @@ class DependenciesTest < ActiveSupport::TestCase def test_const_missing_in_anonymous_modules_raises_if_the_constant_belongs_to_Object with_autoloading_fixtures do - require_dependency 'em' + require_dependency "em" mod = Module.new e = assert_raise(NameError) { mod::EM } - assert_equal 'EM cannot be autoloaded from an anonymous class or module', e.message + assert_equal "EM cannot be autoloaded from an anonymous class or module", e.message assert_equal :EM, e.name end ensure @@ -596,7 +596,7 @@ class DependenciesTest < ActiveSupport::TestCase end def test_removal_from_tree_should_be_detected - with_loading 'dependencies' do + with_loading "dependencies" do c = ServiceOne ActiveSupport::Dependencies.clear assert_not defined?(ServiceOne) @@ -610,7 +610,7 @@ class DependenciesTest < ActiveSupport::TestCase end def test_references_should_work - with_loading 'dependencies' do + with_loading "dependencies" do c = ActiveSupport::Dependencies.reference("ServiceOne") service_one_first = ServiceOne assert_equal service_one_first, c.get("ServiceOne") @@ -625,7 +625,7 @@ class DependenciesTest < ActiveSupport::TestCase end def test_constantize_shortcut_for_cached_constant_lookups - with_loading 'dependencies' do + with_loading "dependencies" do assert_equal ServiceOne, ActiveSupport::Dependencies.constantize("ServiceOne") end ensure @@ -633,7 +633,7 @@ class DependenciesTest < ActiveSupport::TestCase end def test_nested_load_error_isnt_rescued - with_loading 'dependencies' do + with_loading "dependencies" do assert_raise(LoadError) do RequiresNonexistent1 end @@ -659,7 +659,7 @@ class DependenciesTest < ActiveSupport::TestCase def test_autoload_once_pathnames_do_not_add_to_autoloaded_constants with_autoloading_fixtures do - pathnames = ActiveSupport::Dependencies.autoload_paths.collect{|p| Pathname.new(p)} + pathnames = ActiveSupport::Dependencies.autoload_paths.collect { |p| Pathname.new(p) } ActiveSupport::Dependencies.autoload_paths = pathnames ActiveSupport::Dependencies.autoload_once_paths = pathnames @@ -677,7 +677,7 @@ class DependenciesTest < ActiveSupport::TestCase def test_application_should_special_case_application_controller with_autoloading_fixtures do - require_dependency 'application' + require_dependency "application" assert_equal 10, ApplicationController assert ActiveSupport::Dependencies.autoloaded?(:ApplicationController) end @@ -687,14 +687,14 @@ class DependenciesTest < ActiveSupport::TestCase def test_preexisting_constants_are_not_marked_as_autoloaded with_autoloading_fixtures do - require_dependency 'em' + require_dependency "em" assert ActiveSupport::Dependencies.autoloaded?(:EM) ActiveSupport::Dependencies.clear end Object.const_set :EM, Class.new with_autoloading_fixtures do - require_dependency 'em' + require_dependency "em" assert ! ActiveSupport::Dependencies.autoloaded?(:EM), "EM shouldn't be marked autoloaded!" ActiveSupport::Dependencies.clear end @@ -756,15 +756,15 @@ class DependenciesTest < ActiveSupport::TestCase end def test_new_contants_in_without_constants - assert_equal [], (ActiveSupport::Dependencies.new_constants_in(Object) { }) - assert ActiveSupport::Dependencies.constant_watch_stack.all? {|k,v| v.empty? } + assert_equal [], (ActiveSupport::Dependencies.new_constants_in(Object) {}) + assert ActiveSupport::Dependencies.constant_watch_stack.all? { |k,v| v.empty? } end def test_new_constants_in_with_a_single_constant assert_equal ["Hello"], ActiveSupport::Dependencies.new_constants_in(Object) { Object.const_set :Hello, 10 }.map(&:to_s) - assert ActiveSupport::Dependencies.constant_watch_stack.all? {|k,v| v.empty? } + assert ActiveSupport::Dependencies.constant_watch_stack.all? { |k,v| v.empty? } ensure remove_constants(:Hello) end @@ -781,7 +781,7 @@ class DependenciesTest < ActiveSupport::TestCase end assert_equal ["OuterAfter", "OuterBefore"], outer.sort.map(&:to_s) - assert ActiveSupport::Dependencies.constant_watch_stack.all? {|k,v| v.empty? } + assert ActiveSupport::Dependencies.constant_watch_stack.all? { |k,v| v.empty? } ensure remove_constants(:OuterBefore, :Inner, :OuterAfter) end @@ -800,7 +800,7 @@ class DependenciesTest < ActiveSupport::TestCase M.const_set :OuterAfter, 30 end assert_equal ["M::OuterAfter", "M::OuterBefore"], outer.sort - assert ActiveSupport::Dependencies.constant_watch_stack.all? {|k,v| v.empty? } + assert ActiveSupport::Dependencies.constant_watch_stack.all? { |k,v| v.empty? } ensure remove_constants(:M) end @@ -818,7 +818,7 @@ class DependenciesTest < ActiveSupport::TestCase M.const_set :OuterAfter, 30 end assert_equal ["M::OuterAfter", "M::OuterBefore"], outer.sort - assert ActiveSupport::Dependencies.constant_watch_stack.all? {|k,v| v.empty? } + assert ActiveSupport::Dependencies.constant_watch_stack.all? { |k,v| v.empty? } ensure remove_constants(:M) end @@ -841,7 +841,7 @@ class DependenciesTest < ActiveSupport::TestCase assert_not defined?(MultipleConstantFile) assert_not defined?(SiblingConstant) - require_dependency 'multiple_constant_file' + require_dependency "multiple_constant_file" assert defined?(MultipleConstantFile) assert defined?(SiblingConstant) assert ActiveSupport::Dependencies.autoloaded?(:MultipleConstantFile) @@ -881,7 +881,7 @@ class DependenciesTest < ActiveSupport::TestCase assert_not defined?(ClassFolder::NestedClass) assert_not defined?(ClassFolder::SiblingClass) - require_dependency 'class_folder/nested_class' + require_dependency "class_folder/nested_class" assert defined?(ClassFolder::NestedClass) assert defined?(ClassFolder::SiblingClass) @@ -959,7 +959,7 @@ class DependenciesTest < ActiveSupport::TestCase e = assert_raise NameError do ::RaisesNameError::FooBarBaz.object_id end - assert_equal 'uninitialized constant RaisesNameError::FooBarBaz', e.message + assert_equal "uninitialized constant RaisesNameError::FooBarBaz", e.message assert !defined?(::RaisesNameError), "::RaisesNameError is defined but it should have failed!" end @@ -974,8 +974,8 @@ class DependenciesTest < ActiveSupport::TestCase end def test_remove_constant_handles_double_colon_at_start - Object.const_set 'DeleteMe', Module.new - DeleteMe.const_set 'OrMe', Module.new + Object.const_set "DeleteMe", Module.new + DeleteMe.const_set "OrMe", Module.new ActiveSupport::Dependencies.remove_constant "::DeleteMe::OrMe" assert_not defined?(DeleteMe::OrMe) assert defined?(DeleteMe) @@ -986,9 +986,9 @@ class DependenciesTest < ActiveSupport::TestCase end def test_remove_constant_does_not_trigger_loading_autoloads - constant = 'ShouldNotBeAutoloaded' + constant = "ShouldNotBeAutoloaded" Object.class_eval do - autoload constant, File.expand_path('../autoloading_fixtures/should_not_be_required', __FILE__) + autoload constant, File.expand_path("../autoloading_fixtures/should_not_be_required", __FILE__) end assert_nil ActiveSupport::Dependencies.remove_constant(constant), "Kernel#autoload has been triggered by remove_constant" @@ -1001,8 +1001,8 @@ class DependenciesTest < ActiveSupport::TestCase with_autoloading_fixtures do _ = ::A # assignment to silence parse-time warning "possibly useless use of :: in void context" _ = ::A::B # assignment to silence parse-time warning "possibly useless use of :: in void context" - ActiveSupport::Dependencies.remove_constant('A') - ActiveSupport::Dependencies.remove_constant('A::B') + ActiveSupport::Dependencies.remove_constant("A") + ActiveSupport::Dependencies.remove_constant("A::B") assert_not defined?(A) end ensure @@ -1036,10 +1036,9 @@ class DependenciesTest < ActiveSupport::TestCase remove_constants(:A) end - def test_autoload_once_paths_should_behave_when_recursively_loading old_path = ActiveSupport::Dependencies.autoload_once_paths - with_loading 'dependencies', 'autoloading_fixtures' do + with_loading "dependencies", "autoloading_fixtures" do ActiveSupport::Dependencies.autoload_once_paths = [ActiveSupport::Dependencies.autoload_paths.last] assert_not defined?(CrossSiteDependency) assert_nothing_raised { CrossSiteDepender.nil? } diff --git a/activesupport/test/dependencies_test_helpers.rb b/activesupport/test/dependencies_test_helpers.rb index e4d5197112..9bc63ed89e 100644 --- a/activesupport/test/dependencies_test_helpers.rb +++ b/activesupport/test/dependencies_test_helpers.rb @@ -17,7 +17,7 @@ module DependenciesTestHelpers end def with_autoloading_fixtures(&block) - with_loading 'autoloading_fixtures', &block + with_loading "autoloading_fixtures", &block end def remove_constants(*constants) @@ -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/deprecation/method_wrappers_test.rb b/activesupport/test/deprecation/method_wrappers_test.rb index 9a4ca2b217..85d057bb02 100644 --- a/activesupport/test/deprecation/method_wrappers_test.rb +++ b/activesupport/test/deprecation/method_wrappers_test.rb @@ -1,5 +1,5 @@ -require 'abstract_unit' -require 'active_support/deprecation' +require "abstract_unit" +require "active_support/deprecation" class MethodWrappersTest < ActiveSupport::TestCase def setup @@ -11,7 +11,7 @@ class MethodWrappersTest < ActiveSupport::TestCase def test_deprecate_methods_warning_default warning = /old_method is deprecated and will be removed from Rails \d.\d \(use new_method instead\)/ - ActiveSupport::Deprecation.deprecate_methods(@klass, :old_method => :new_method) + ActiveSupport::Deprecation.deprecate_methods(@klass, old_method: :new_method) assert_deprecated(warning) { assert_equal "abc", @klass.new.old_method } end @@ -19,7 +19,7 @@ class MethodWrappersTest < ActiveSupport::TestCase def test_deprecate_methods_warning_with_optional_deprecator warning = /old_method is deprecated and will be removed from MyGem next-release \(use new_method instead\)/ deprecator = ActiveSupport::Deprecation.new("next-release", "MyGem") - ActiveSupport::Deprecation.deprecate_methods(@klass, :old_method => :new_method, :deprecator => deprecator) + ActiveSupport::Deprecation.deprecate_methods(@klass, old_method: :new_method, deprecator: deprecator) assert_deprecated(warning, deprecator) { assert_equal "abc", @klass.new.old_method } end @@ -27,7 +27,7 @@ class MethodWrappersTest < ActiveSupport::TestCase def test_deprecate_methods_warning_when_deprecated_with_custom_deprecator warning = /old_method is deprecated and will be removed from MyGem next-release \(use new_method instead\)/ deprecator = ActiveSupport::Deprecation.new("next-release", "MyGem") - deprecator.deprecate_methods(@klass, :old_method => :new_method) + deprecator.deprecate_methods(@klass, old_method: :new_method) assert_deprecated(warning, deprecator) { assert_equal "abc", @klass.new.old_method } end diff --git a/activesupport/test/deprecation/proxy_wrappers_test.rb b/activesupport/test/deprecation/proxy_wrappers_test.rb index e4f0f0f7c2..67afd75c44 100644 --- a/activesupport/test/deprecation/proxy_wrappers_test.rb +++ b/activesupport/test/deprecation/proxy_wrappers_test.rb @@ -1,5 +1,5 @@ -require 'abstract_unit' -require 'active_support/deprecation' +require "abstract_unit" +require "active_support/deprecation" class ProxyWrappersTest < ActiveSupport::TestCase Waffles = false diff --git a/activesupport/test/deprecation_test.rb b/activesupport/test/deprecation_test.rb index dbde3d2e15..e2a3331cfa 100644 --- a/activesupport/test/deprecation_test.rb +++ b/activesupport/test/deprecation_test.rb @@ -1,16 +1,16 @@ -require 'abstract_unit' -require 'active_support/testing/stream' +require "abstract_unit" +require "active_support/testing/stream" class Deprecatee def initialize @request = ActiveSupport::Deprecation::DeprecatedInstanceVariableProxy.new(self, :request) - @_request = 'there we go' + @_request = "there we go" end def request; @_request end def old_request; @request end def partially(foo = nil) - ActiveSupport::Deprecation.warn('calling with foo=nil is out') if foo.nil? + ActiveSupport::Deprecation.warn("calling with foo=nil is out") if foo.nil? end def not() 2 end @@ -24,7 +24,7 @@ class Deprecatee def c; end def d; end def e; end - deprecate :a, :b, :c => :e, :d => "you now need to do something extra for this one" + deprecate :a, :b, c: :e, d: "you now need to do something extra for this one" def f=(v); end deprecate :f= @@ -32,10 +32,9 @@ class Deprecatee module B C = 1 end - A = ActiveSupport::Deprecation::DeprecatedConstantProxy.new('Deprecatee::A', 'Deprecatee::B::C') + A = ActiveSupport::Deprecation::DeprecatedConstantProxy.new("Deprecatee::A", "Deprecatee::B::C") end - class DeprecationTest < ActiveSupport::TestCase include ActiveSupport::Testing::Stream @@ -79,7 +78,7 @@ class DeprecationTest < ActiveSupport::TestCase end def test_deprecate_object - deprecated_object = ActiveSupport::Deprecation::DeprecatedObjectProxy.new(Object.new, ':bomb:') + deprecated_object = ActiveSupport::Deprecation::DeprecatedObjectProxy.new(Object.new, ":bomb:") assert_deprecated(/:bomb:/) { deprecated_object.to_s } end @@ -104,7 +103,7 @@ class DeprecationTest < ActiveSupport::TestCase def test_raise_behaviour ActiveSupport::Deprecation.behavior = :raise - message = 'Revise this deprecated stuff now!' + message = "Revise this deprecated stuff now!" callstack = caller_locations e = assert_raise ActiveSupport::DeprecationException do @@ -119,7 +118,7 @@ class DeprecationTest < ActiveSupport::TestCase behavior = ActiveSupport::Deprecation.behavior.first content = capture(:stderr) { - assert_nil behavior.call('Some error!', ['call stack!']) + assert_nil behavior.call("Some error!", ["call stack!"]) } assert_match(/Some error!/, content) assert_match(/call stack!/, content) @@ -129,7 +128,7 @@ class DeprecationTest < ActiveSupport::TestCase ActiveSupport::Deprecation.behavior = :stderr content = capture(:stderr) { - ActiveSupport::Deprecation.warn('Instance error!', ['instance call stack!']) + ActiveSupport::Deprecation.warn("Instance error!", ["instance call stack!"]) } assert_match(/Instance error!/, content) @@ -141,7 +140,7 @@ class DeprecationTest < ActiveSupport::TestCase behavior = ActiveSupport::Deprecation.behavior.first stderr_output = capture(:stderr) { - assert_nil behavior.call('Some error!', ['call stack!']) + assert_nil behavior.call("Some error!", ["call stack!"]) } assert stderr_output.empty? end @@ -149,8 +148,8 @@ class DeprecationTest < ActiveSupport::TestCase def test_deprecated_instance_variable_proxy assert_not_deprecated { @dtc.request.size } - assert_deprecated('@request.size') { assert_equal @dtc.request.size, @dtc.old_request.size } - assert_deprecated('@request.to_s') { assert_equal @dtc.request.to_s, @dtc.old_request.to_s } + assert_deprecated("@request.size") { assert_equal @dtc.request.size, @dtc.old_request.size } + assert_deprecated("@request.to_s") { assert_equal @dtc.request.to_s, @dtc.old_request.to_s } end def test_deprecated_instance_variable_proxy_shouldnt_warn_on_inspect @@ -159,7 +158,7 @@ class DeprecationTest < ActiveSupport::TestCase def test_deprecated_constant_proxy assert_not_deprecated { Deprecatee::B::C } - assert_deprecated('Deprecatee::A') { assert_equal Deprecatee::B::C, Deprecatee::A } + assert_deprecated("Deprecatee::A") { assert_equal Deprecatee::B::C, Deprecatee::A } assert_not_deprecated { assert_equal Deprecatee::B::C.class, Deprecatee::A.class } end @@ -178,12 +177,12 @@ class DeprecationTest < ActiveSupport::TestCase end def test_assert_deprecated_matches_any_warning - assert_deprecated 'abc' do - ActiveSupport::Deprecation.warn 'abc' - ActiveSupport::Deprecation.warn 'def' + assert_deprecated "abc" do + ActiveSupport::Deprecation.warn "abc" + ActiveSupport::Deprecation.warn "def" end rescue Minitest::Assertion - flunk 'assert_deprecated should match any warning in block, not just the last one' + flunk "assert_deprecated should match any warning in block, not just the last one" end def test_assert_not_deprecated_returns_result_of_block @@ -191,17 +190,17 @@ class DeprecationTest < ActiveSupport::TestCase end def test_assert_deprecated_returns_result_of_block - result = assert_deprecated('abc') do - ActiveSupport::Deprecation.warn 'abc' + result = assert_deprecated("abc") do + ActiveSupport::Deprecation.warn "abc" 123 end assert_equal 123, result end def test_assert_deprecated_warn_work_with_default_behavior - ActiveSupport::Deprecation.instance_variable_set('@behavior', nil) - assert_deprecated('abc') do - ActiveSupport::Deprecation.warn 'abc' + ActiveSupport::Deprecation.instance_variable_set("@behavior", nil) + assert_deprecated("abc") do + ActiveSupport::Deprecation.warn "abc" end end @@ -280,7 +279,7 @@ class DeprecationTest < ActiveSupport::TestCase def test_deprecated_constant_with_deprecator_given deprecator = deprecator_with_messages klass = Class.new - klass.const_set(:OLD, ActiveSupport::Deprecation::DeprecatedConstantProxy.new('klass::OLD', 'Object', deprecator) ) + klass.const_set(:OLD, ActiveSupport::Deprecation::DeprecatedConstantProxy.new("klass::OLD", "Object", deprecator) ) assert_difference("deprecator.messages.size") do klass::OLD.to_s end @@ -353,7 +352,7 @@ class DeprecationTest < ActiveSupport::TestCase end def test_custom_gem_name - deprecator = ActiveSupport::Deprecation.new('2.0', 'Custom') + deprecator = ActiveSupport::Deprecation.new("2.0", "Custom") deprecator.send(:deprecated_method_warning, :deprecated_method, "You are calling deprecated method").tap do |message| assert_match(/is deprecated and will be removed from Custom/, message) @@ -364,11 +363,10 @@ class DeprecationTest < ActiveSupport::TestCase def deprecator_with_messages klass = Class.new(ActiveSupport::Deprecation) deprecator = klass.new - deprecator.behavior = Proc.new{|message, callstack| deprecator.messages << message} + deprecator.behavior = Proc.new { |message, callstack| deprecator.messages << message } def deprecator.messages @messages ||= [] end deprecator end - end diff --git a/activesupport/test/descendants_tracker_test_cases.rb b/activesupport/test/descendants_tracker_test_cases.rb index 69e046998e..09c5ce1f07 100644 --- a/activesupport/test/descendants_tracker_test_cases.rb +++ b/activesupport/test/descendants_tracker_test_cases.rb @@ -1,4 +1,4 @@ -require 'set' +require "set" module DescendantsTrackerTestCases class Parent @@ -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/descendants_tracker_with_autoloading_test.rb b/activesupport/test/descendants_tracker_with_autoloading_test.rb index a2ae066a21..e202667a8a 100644 --- a/activesupport/test/descendants_tracker_with_autoloading_test.rb +++ b/activesupport/test/descendants_tracker_with_autoloading_test.rb @@ -1,7 +1,7 @@ -require 'abstract_unit' -require 'active_support/descendants_tracker' -require 'active_support/dependencies' -require 'descendants_tracker_test_cases' +require "abstract_unit" +require "active_support/descendants_tracker" +require "active_support/dependencies" +require "descendants_tracker_test_cases" class DescendantsTrackerWithAutoloadingTest < ActiveSupport::TestCase include DescendantsTrackerTestCases diff --git a/activesupport/test/descendants_tracker_without_autoloading_test.rb b/activesupport/test/descendants_tracker_without_autoloading_test.rb index 00b449af51..72adc30ace 100644 --- a/activesupport/test/descendants_tracker_without_autoloading_test.rb +++ b/activesupport/test/descendants_tracker_without_autoloading_test.rb @@ -1,6 +1,6 @@ -require 'abstract_unit' -require 'active_support/descendants_tracker' -require 'descendants_tracker_test_cases' +require "abstract_unit" +require "active_support/descendants_tracker" +require "descendants_tracker_test_cases" class DescendantsTrackerWithoutAutoloadingTest < ActiveSupport::TestCase include DescendantsTrackerTestCases diff --git a/activesupport/test/evented_file_update_checker_test.rb b/activesupport/test/evented_file_update_checker_test.rb index 2cb2d8167f..cc47318974 100644 --- a/activesupport/test/evented_file_update_checker_test.rb +++ b/activesupport/test/evented_file_update_checker_test.rb @@ -1,12 +1,12 @@ -require 'abstract_unit' -require 'pathname' -require 'file_update_checker_shared_tests' +require "abstract_unit" +require "pathname" +require "file_update_checker_shared_tests" class EventedFileUpdateCheckerTest < ActiveSupport::TestCase include FileUpdateCheckerSharedTests def setup - skip if ENV['LISTEN'] == '0' + skip if ENV["LISTEN"] == "0" super end @@ -35,10 +35,10 @@ class EventedFileUpdateCheckerTest < ActiveSupport::TestCase wait end - test 'notifies forked processes' do + test "notifies forked processes" do FileUtils.touch(tmpfiles) - checker = new_checker(tmpfiles) { } + checker = new_checker(tmpfiles) {} assert !checker.updated? # Pipes used for flow controll across fork. @@ -87,33 +87,33 @@ class EventedFileUpdateCheckerPathHelperTest < ActiveSupport::TestCase @ph = ActiveSupport::EventedFileUpdateChecker::PathHelper.new end - test '#xpath returns the expanded path as a Pathname object' do + test "#xpath returns the expanded path as a Pathname object" do assert_equal pn(__FILE__).expand_path, @ph.xpath(__FILE__) end - test '#normalize_extension returns a bare extension as is' do - assert_equal 'rb', @ph.normalize_extension('rb') + test "#normalize_extension returns a bare extension as is" do + assert_equal "rb", @ph.normalize_extension("rb") end - test '#normalize_extension removes a leading dot' do - assert_equal 'rb', @ph.normalize_extension('.rb') + test "#normalize_extension removes a leading dot" do + assert_equal "rb", @ph.normalize_extension(".rb") end - test '#normalize_extension supports symbols' do - assert_equal 'rb', @ph.normalize_extension(:rb) + test "#normalize_extension supports symbols" do + assert_equal "rb", @ph.normalize_extension(:rb) end - test '#longest_common_subpath finds the longest common subpath, if there is one' do + test "#longest_common_subpath finds the longest common subpath, if there is one" do paths = %w( /foo/bar /foo/baz /foo/bar/baz/woo/zoo ).map { |path| pn(path) } - assert_equal pn('/foo'), @ph.longest_common_subpath(paths) + assert_equal pn("/foo"), @ph.longest_common_subpath(paths) end - test '#longest_common_subpath returns the root directory as an edge case' do + test "#longest_common_subpath returns the root directory as an edge case" do paths = %w( /foo/bar /foo/baz @@ -121,30 +121,30 @@ class EventedFileUpdateCheckerPathHelperTest < ActiveSupport::TestCase /wadus ).map { |path| pn(path) } - assert_equal pn('/'), @ph.longest_common_subpath(paths) + assert_equal pn("/"), @ph.longest_common_subpath(paths) end - test '#longest_common_subpath returns nil for an empty collection' do + test "#longest_common_subpath returns nil for an empty collection" do assert_nil @ph.longest_common_subpath([]) end - test '#existing_parent returns the most specific existing ascendant' do + test "#existing_parent returns the most specific existing ascendant" do wd = Pathname.getwd assert_equal wd, @ph.existing_parent(wd) - assert_equal wd, @ph.existing_parent(wd.join('non-existing/directory')) - assert_equal pn('/'), @ph.existing_parent(pn('/non-existing/directory')) + assert_equal wd, @ph.existing_parent(wd.join("non-existing/directory")) + assert_equal pn("/"), @ph.existing_parent(pn("/non-existing/directory")) end - test '#filter_out_descendants returns the same collection if there are no descendants (empty)' do + test "#filter_out_descendants returns the same collection if there are no descendants (empty)" do assert_equal [], @ph.filter_out_descendants([]) end - test '#filter_out_descendants returns the same collection if there are no descendants (one)' do - assert_equal ['/foo'], @ph.filter_out_descendants(['/foo']) + test "#filter_out_descendants returns the same collection if there are no descendants (one)" do + assert_equal ["/foo"], @ph.filter_out_descendants(["/foo"]) end - test '#filter_out_descendants returns the same collection if there are no descendants (several)' do + test "#filter_out_descendants returns the same collection if there are no descendants (several)" do paths = %w( /Rails.root/app/controllers /Rails.root/app/models @@ -154,7 +154,7 @@ class EventedFileUpdateCheckerPathHelperTest < ActiveSupport::TestCase assert_equal paths, @ph.filter_out_descendants(paths) end - test '#filter_out_descendants filters out descendants preserving order' do + test "#filter_out_descendants filters out descendants preserving order" do paths = %w( /Rails.root/app/controllers /Rails.root/app/controllers/concerns @@ -166,7 +166,7 @@ class EventedFileUpdateCheckerPathHelperTest < ActiveSupport::TestCase assert_equal paths.values_at(0, 2, 4), @ph.filter_out_descendants(paths) end - test '#filter_out_descendants works on path units' do + test "#filter_out_descendants works on path units" do paths = %w( /foo/bar /foo/barrrr @@ -175,7 +175,7 @@ class EventedFileUpdateCheckerPathHelperTest < ActiveSupport::TestCase assert_equal paths, @ph.filter_out_descendants(paths) end - test '#filter_out_descendants deals correctly with the root directory' do + test "#filter_out_descendants deals correctly with the root directory" do paths = %w( / /foo @@ -185,7 +185,7 @@ class EventedFileUpdateCheckerPathHelperTest < ActiveSupport::TestCase assert_equal paths.values_at(0), @ph.filter_out_descendants(paths) end - test '#filter_out_descendants preserves duplicates' do + test "#filter_out_descendants preserves duplicates" do paths = %w( /foo /foo/bar diff --git a/activesupport/test/executor_test.rb b/activesupport/test/executor_test.rb index d9b389461a..0b56ea008f 100644 --- a/activesupport/test/executor_test.rb +++ b/activesupport/test/executor_test.rb @@ -1,4 +1,4 @@ -require 'abstract_unit' +require "abstract_unit" class ExecutorTest < ActiveSupport::TestCase class DummyError < RuntimeError @@ -21,7 +21,7 @@ class ExecutorTest < ActiveSupport::TestCase executor.to_run { @foo = true } executor.to_complete { result = @foo } - executor.wrap { } + executor.wrap {} assert result end @@ -83,7 +83,7 @@ class ExecutorTest < ActiveSupport::TestCase executor.register_hook(hook) - executor.wrap { } + executor.wrap {} assert_equal :some_state, supplied_state end @@ -103,7 +103,7 @@ class ExecutorTest < ActiveSupport::TestCase executor.register_hook(hook) - executor.wrap { } + executor.wrap {} assert_equal nil, supplied_state end @@ -127,7 +127,7 @@ class ExecutorTest < ActiveSupport::TestCase executor.register_hook(hook) assert_raises(DummyError) do - executor.wrap { } + executor.wrap {} end assert_equal :none, supplied_state @@ -152,7 +152,7 @@ class ExecutorTest < ActiveSupport::TestCase end assert_raises(DummyError) do - executor.wrap { } + executor.wrap {} end assert_equal :some_state, supplied_state diff --git a/activesupport/test/file_update_checker_shared_tests.rb b/activesupport/test/file_update_checker_shared_tests.rb index 40ae0c7617..cd6a58e840 100644 --- a/activesupport/test/file_update_checker_shared_tests.rb +++ b/activesupport/test/file_update_checker_shared_tests.rb @@ -1,4 +1,4 @@ -require 'fileutils' +require "fileutils" module FileUpdateCheckerSharedTests extend ActiveSupport::Testing::Declarative @@ -22,8 +22,8 @@ module FileUpdateCheckerSharedTests end end - test 'should not execute the block if no paths are given' do - silence_warnings { require 'listen' } + test "should not execute the block if no paths are given" do + silence_warnings { require "listen" } i = 0 checker = new_checker { i += 1 } @@ -32,7 +32,7 @@ module FileUpdateCheckerSharedTests assert_equal 0, i end - test 'should not execute the block if no files change' do + test "should not execute the block if no files change" do i = 0 FileUtils.touch(tmpfiles) @@ -43,7 +43,7 @@ module FileUpdateCheckerSharedTests assert_equal 0, i end - test 'should execute the block once when files are created' do + test "should execute the block once when files are created" do i = 0 checker = new_checker(tmpfiles) { i += 1 } @@ -54,7 +54,7 @@ module FileUpdateCheckerSharedTests assert_equal 1, i end - test 'should execute the block once when files are modified' do + test "should execute the block once when files are modified" do i = 0 FileUtils.touch(tmpfiles) @@ -67,7 +67,7 @@ module FileUpdateCheckerSharedTests assert_equal 1, i end - test 'should execute the block once when files are deleted' do + test "should execute the block once when files are deleted" do i = 0 FileUtils.touch(tmpfiles) @@ -80,8 +80,7 @@ module FileUpdateCheckerSharedTests assert_equal 1, i end - - test 'updated should become true when watched files are created' do + test "updated should become true when watched files are created" do i = 0 checker = new_checker(tmpfiles) { i += 1 } @@ -92,8 +91,7 @@ module FileUpdateCheckerSharedTests assert checker.updated? end - - test 'updated should become true when watched files are modified' do + test "updated should become true when watched files are modified" do i = 0 FileUtils.touch(tmpfiles) @@ -106,7 +104,7 @@ module FileUpdateCheckerSharedTests assert checker.updated? end - test 'updated should become true when watched files are deleted' do + test "updated should become true when watched files are deleted" do i = 0 FileUtils.touch(tmpfiles) @@ -119,7 +117,7 @@ module FileUpdateCheckerSharedTests assert checker.updated? end - test 'should be robust to handle files with wrong modified time' do + test "should be robust to handle files with wrong modified time" do i = 0 FileUtils.touch(tmpfiles) @@ -136,7 +134,7 @@ module FileUpdateCheckerSharedTests assert_equal 1, i end - test 'should return max_time for files with mtime = Time.at(0)' do + test "should return max_time for files with mtime = Time.at(0)" do i = 0 FileUtils.touch(tmpfiles) @@ -152,7 +150,7 @@ module FileUpdateCheckerSharedTests assert_equal 1, i end - test 'should cache updated result until execute' do + test "should cache updated result until execute" do i = 0 checker = new_checker(tmpfiles) { i += 1 } @@ -165,48 +163,48 @@ module FileUpdateCheckerSharedTests assert !checker.updated? end - test 'should execute the block if files change in a watched directory one extension' do + test "should execute the block if files change in a watched directory one extension" do i = 0 checker = new_checker([], tmpdir => :rb) { i += 1 } - touch(tmpfile('foo.rb')) + touch(tmpfile("foo.rb")) assert checker.execute_if_updated assert_equal 1, i end - test 'should execute the block if files change in a watched directory several extensions' do + test "should execute the block if files change in a watched directory several extensions" do i = 0 checker = new_checker([], tmpdir => [:rb, :txt]) { i += 1 } - touch(tmpfile('foo.rb')) + touch(tmpfile("foo.rb")) assert checker.execute_if_updated assert_equal 1, i - touch(tmpfile('foo.txt')) + touch(tmpfile("foo.txt")) assert checker.execute_if_updated assert_equal 2, i end - test 'should not execute the block if the file extension is not watched' do + test "should not execute the block if the file extension is not watched" do i = 0 checker = new_checker([], tmpdir => :txt) { i += 1 } - touch(tmpfile('foo.rb')) + touch(tmpfile("foo.rb")) assert !checker.execute_if_updated assert_equal 0, i end - test 'does not assume files exist on instantiation' do + test "does not assume files exist on instantiation" do i = 0 - non_existing = tmpfile('non_existing.rb') + non_existing = tmpfile("non_existing.rb") checker = new_checker([non_existing]) { i += 1 } touch(non_existing) @@ -215,12 +213,12 @@ module FileUpdateCheckerSharedTests assert_equal 1, i end - test 'detects files in new subdirectories' do + test "detects files in new subdirectories" do i = 0 checker = new_checker([], tmpdir => :rb) { i += 1 } - subdir = tmpfile('subdir') + subdir = tmpfile("subdir") mkdir(subdir) wait @@ -233,15 +231,15 @@ module FileUpdateCheckerSharedTests assert_equal 1, i end - test 'looked up extensions are inherited in subdirectories not listening to them' do + test "looked up extensions are inherited in subdirectories not listening to them" do i = 0 - subdir = tmpfile('subdir') + subdir = tmpfile("subdir") mkdir(subdir) checker = new_checker([], tmpdir => :rb, subdir => :txt) { i += 1 } - touch(tmpfile('new.txt')) + touch(tmpfile("new.txt")) assert !checker.execute_if_updated assert_equal 0, i diff --git a/activesupport/test/file_update_checker_test.rb b/activesupport/test/file_update_checker_test.rb index 752f7836cd..55b0b46644 100644 --- a/activesupport/test/file_update_checker_test.rb +++ b/activesupport/test/file_update_checker_test.rb @@ -1,5 +1,5 @@ -require 'abstract_unit' -require 'file_update_checker_shared_tests' +require "abstract_unit" +require "file_update_checker_shared_tests" class FileUpdateCheckerTest < ActiveSupport::TestCase include FileUpdateCheckerSharedTests 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/gzip_test.rb b/activesupport/test/gzip_test.rb index 0e3cf3b429..d88408b55c 100644 --- a/activesupport/test/gzip_test.rb +++ b/activesupport/test/gzip_test.rb @@ -1,5 +1,5 @@ -require 'abstract_unit' -require 'active_support/core_ext/object/blank' +require "abstract_unit" +require "active_support/core_ext/object/blank" class GzipTest < ActiveSupport::TestCase def test_compress_should_decompress_to_the_same_value @@ -13,9 +13,9 @@ class GzipTest < ActiveSupport::TestCase end def test_compress_should_return_a_binary_string - compressed = ActiveSupport::Gzip.compress('') + compressed = ActiveSupport::Gzip.compress("") - assert_equal Encoding.find('binary'), compressed.encoding + assert_equal Encoding.find("binary"), compressed.encoding assert !compressed.blank?, "a compressed blank string should not be blank" end diff --git a/activesupport/test/i18n_test.rb b/activesupport/test/i18n_test.rb index 3faa15e7fd..7d88d2dc6b 100644 --- a/activesupport/test/i18n_test.rb +++ b/activesupport/test/i18n_test.rb @@ -1,6 +1,6 @@ -require 'abstract_unit' -require 'active_support/time' -require 'active_support/core_ext/array/conversions' +require "abstract_unit" +require "active_support/time" +require "active_support/core_ext/array/conversions" class I18nTest < ActiveSupport::TestCase def setup @@ -18,15 +18,15 @@ class I18nTest < ActiveSupport::TestCase end def test_date_localization_with_default_format - assert_equal @date.strftime("%Y-%m-%d"), I18n.localize(@date, :format => :default) + assert_equal @date.strftime("%Y-%m-%d"), I18n.localize(@date, format: :default) end def test_date_localization_with_short_format - assert_equal @date.strftime("%b %d"), I18n.localize(@date, :format => :short) + assert_equal @date.strftime("%b %d"), I18n.localize(@date, format: :short) end def test_date_localization_with_long_format - assert_equal @date.strftime("%B %d, %Y"), I18n.localize(@date, :format => :long) + assert_equal @date.strftime("%B %d, %Y"), I18n.localize(@date, format: :long) end def test_time_localization_should_use_default_format @@ -34,15 +34,15 @@ class I18nTest < ActiveSupport::TestCase end def test_time_localization_with_default_format - assert_equal @time.strftime("%a, %d %b %Y %H:%M:%S %z"), I18n.localize(@time, :format => :default) + assert_equal @time.strftime("%a, %d %b %Y %H:%M:%S %z"), I18n.localize(@time, format: :default) end def test_time_localization_with_short_format - assert_equal @time.strftime("%d %b %H:%M"), I18n.localize(@time, :format => :short) + assert_equal @time.strftime("%d %b %H:%M"), I18n.localize(@time, format: :short) end def test_time_localization_with_long_format - assert_equal @time.strftime("%B %d, %Y %H:%M"), I18n.localize(@time, :format => :long) + assert_equal @time.strftime("%B %d, %Y %H:%M"), I18n.localize(@time, format: :long) end def test_day_names @@ -66,39 +66,39 @@ class I18nTest < ActiveSupport::TestCase end def test_time_am - assert_equal 'am', I18n.translate(:'time.am') + assert_equal "am", I18n.translate(:'time.am') end def test_time_pm - assert_equal 'pm', I18n.translate(:'time.pm') + assert_equal "pm", I18n.translate(:'time.pm') end def test_words_connector - assert_equal ', ', I18n.translate(:'support.array.words_connector') + assert_equal ", ", I18n.translate(:'support.array.words_connector') end def test_two_words_connector - assert_equal ' and ', I18n.translate(:'support.array.two_words_connector') + assert_equal " and ", I18n.translate(:'support.array.two_words_connector') end def test_last_word_connector - assert_equal ', and ', I18n.translate(:'support.array.last_word_connector') + assert_equal ", and ", I18n.translate(:'support.array.last_word_connector') end def test_to_sentence default_two_words_connector = I18n.translate(:'support.array.two_words_connector') default_last_word_connector = I18n.translate(:'support.array.last_word_connector') - assert_equal 'a, b, and c', %w[a b c].to_sentence - I18n.backend.store_translations 'en', :support => { :array => { :two_words_connector => ' & ' } } - assert_equal 'a & b', %w[a b].to_sentence - I18n.backend.store_translations 'en', :support => { :array => { :last_word_connector => ' and ' } } - assert_equal 'a, b and c', %w[a b c].to_sentence + assert_equal "a, b, and c", %w[a b c].to_sentence + I18n.backend.store_translations "en", support: { array: { two_words_connector: " & " } } + assert_equal "a & b", %w[a b].to_sentence + I18n.backend.store_translations "en", support: { array: { last_word_connector: " and " } } + assert_equal "a, b and c", %w[a b c].to_sentence ensure - I18n.backend.store_translations 'en', :support => { :array => { :two_words_connector => default_two_words_connector } } - I18n.backend.store_translations 'en', :support => { :array => { :last_word_connector => default_last_word_connector } } + I18n.backend.store_translations "en", support: { array: { two_words_connector: default_two_words_connector } } + I18n.backend.store_translations "en", support: { array: { last_word_connector: default_last_word_connector } } end def test_to_sentence_with_empty_i18n_store - assert_equal 'a, b, and c', %w[a b c].to_sentence(locale: 'empty') + assert_equal "a, b, and c", %w[a b c].to_sentence(locale: "empty") end end diff --git a/activesupport/test/inflector_test.rb b/activesupport/test/inflector_test.rb index 06cd41c86d..39e8c611e5 100644 --- a/activesupport/test/inflector_test.rb +++ b/activesupport/test/inflector_test.rb @@ -1,8 +1,8 @@ -require 'abstract_unit' -require 'active_support/inflector' +require "abstract_unit" +require "active_support/inflector" -require 'inflector_test_cases' -require 'constantize_test_cases' +require "inflector_test_cases" +require "constantize_test_cases" class InflectorTest < ActiveSupport::TestCase include InflectorTestCases @@ -80,7 +80,6 @@ class InflectorTest < ActiveSupport::TestCase end end - def test_overwrite_previous_inflectors assert_equal("series", ActiveSupport::Inflector.singularize("series")) ActiveSupport::Inflector.inflections.singular "series", "serie" @@ -101,11 +100,11 @@ class InflectorTest < ActiveSupport::TestCase end def test_camelize_with_lower_downcases_the_first_letter - assert_equal('capital', ActiveSupport::Inflector.camelize('Capital', false)) + assert_equal("capital", ActiveSupport::Inflector.camelize("Capital", false)) end def test_camelize_with_underscores - assert_equal("CamelCase", ActiveSupport::Inflector.camelize('Camel_Case')) + assert_equal("CamelCase", ActiveSupport::Inflector.camelize("Camel_Case")) end def test_acronyms @@ -269,7 +268,7 @@ class InflectorTest < ActiveSupport::TestCase def test_parameterize_with_custom_separator jruby_skip "UTF-8 to UTF8-MAC Converter is unavailable" StringToParameterizeWithUnderscore.each do |some_string, parameterized_string| - assert_equal(parameterized_string, ActiveSupport::Inflector.parameterize(some_string, separator: '_')) + assert_equal(parameterized_string, ActiveSupport::Inflector.parameterize(some_string, separator: "_")) end end @@ -277,7 +276,7 @@ class InflectorTest < ActiveSupport::TestCase jruby_skip "UTF-8 to UTF8-MAC Converter is unavailable" StringToParameterizeWithUnderscore.each do |some_string, parameterized_string| assert_deprecated(/Passing the separator argument as a positional parameter is deprecated and will soon be removed. Use `separator: '_'` instead./i) do - assert_equal(parameterized_string, ActiveSupport::Inflector.parameterize(some_string, '_')) + assert_equal(parameterized_string, ActiveSupport::Inflector.parameterize(some_string, "_")) end end end @@ -285,7 +284,7 @@ class InflectorTest < ActiveSupport::TestCase def test_parameterize_with_multi_character_separator jruby_skip "UTF-8 to UTF8-MAC Converter is unavailable" StringToParameterized.each do |some_string, parameterized_string| - assert_equal(parameterized_string.gsub('-', '__sep__'), ActiveSupport::Inflector.parameterize(some_string, separator: '__sep__')) + assert_equal(parameterized_string.gsub("-", "__sep__"), ActiveSupport::Inflector.parameterize(some_string, separator: "__sep__")) end end @@ -293,7 +292,7 @@ class InflectorTest < ActiveSupport::TestCase jruby_skip "UTF-8 to UTF8-MAC Converter is unavailable" StringToParameterized.each do |some_string, parameterized_string| assert_deprecated(/Passing the separator argument as a positional parameter is deprecated and will soon be removed. Use `separator: '__sep__'` instead./i) do - assert_equal(parameterized_string.gsub('-', '__sep__'), ActiveSupport::Inflector.parameterize(some_string, '__sep__')) + assert_equal(parameterized_string.gsub("-", "__sep__"), ActiveSupport::Inflector.parameterize(some_string, "__sep__")) end end end @@ -307,12 +306,12 @@ class InflectorTest < ActiveSupport::TestCase def test_classify_with_symbol assert_nothing_raised do - assert_equal 'FooBar', ActiveSupport::Inflector.classify(:foo_bars) + assert_equal "FooBar", ActiveSupport::Inflector.classify(:foo_bars) end end def test_classify_with_leading_schema_name - assert_equal 'FooBar', ActiveSupport::Inflector.classify('schema.foo_bar') + assert_equal "FooBar", ActiveSupport::Inflector.classify("schema.foo_bar") end def test_humanize @@ -403,24 +402,24 @@ class InflectorTest < ActiveSupport::TestCase def test_inflector_locality ActiveSupport::Inflector.inflections(:es) do |inflect| - inflect.plural(/$/, 's') - inflect.plural(/z$/i, 'ces') + inflect.plural(/$/, "s") + inflect.plural(/z$/i, "ces") - inflect.singular(/s$/, '') - inflect.singular(/es$/, '') + inflect.singular(/s$/, "") + inflect.singular(/es$/, "") - inflect.irregular('el', 'los') + inflect.irregular("el", "los") end - assert_equal('hijos', 'hijo'.pluralize(:es)) - assert_equal('luces', 'luz'.pluralize(:es)) - assert_equal('luzs', 'luz'.pluralize) + assert_equal("hijos", "hijo".pluralize(:es)) + assert_equal("luces", "luz".pluralize(:es)) + assert_equal("luzs", "luz".pluralize) - assert_equal('sociedad', 'sociedades'.singularize(:es)) - assert_equal('sociedade', 'sociedades'.singularize) + assert_equal("sociedad", "sociedades".singularize(:es)) + assert_equal("sociedade", "sociedades".singularize) - assert_equal('los', 'el'.pluralize(:es)) - assert_equal('els', 'el'.pluralize) + assert_equal("los", "el".pluralize(:es)) + assert_equal("els", "el".pluralize) ActiveSupport::Inflector.inflections(:es) { |inflect| inflect.clear } @@ -435,7 +434,7 @@ class InflectorTest < ActiveSupport::TestCase # ensure any data is present inflect.plural(/(quiz)$/i, '\1zes') inflect.singular(/(database)s$/i, '\1') - inflect.uncountable('series') + inflect.uncountable("series") inflect.human("col_rpted_bugs", "Reported bugs") inflect.clear :all @@ -452,7 +451,7 @@ class InflectorTest < ActiveSupport::TestCase # ensure any data is present inflect.plural(/(quiz)$/i, '\1zes') inflect.singular(/(database)s$/i, '\1') - inflect.uncountable('series') + inflect.uncountable("series") inflect.human("col_rpted_bugs", "Reported bugs") inflect.clear diff --git a/activesupport/test/inflector_test_cases.rb b/activesupport/test/inflector_test_cases.rb index c7dc1dadb6..a8283301b3 100644 --- a/activesupport/test/inflector_test_cases.rb +++ b/activesupport/test/inflector_test_cases.rb @@ -128,10 +128,10 @@ module InflectorTestCases } SymbolToLowerCamel = { - :product => 'product', - :special_guest => 'specialGuest', - :application_controller => 'applicationController', - :area51_controller => 'area51Controller' + product: "product", + special_guest: "specialGuest", + application_controller: "applicationController", + area51_controller: "area51Controller" } CamelToUnderscoreWithoutReverse = { @@ -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" } @@ -241,11 +241,11 @@ module InflectorTestCases } UnderscoreToHuman = { - 'employee_salary' => 'Employee salary', - 'employee_id' => 'Employee', - 'underground' => 'Underground', - '_id' => 'Id', - '_external_id' => 'External' + "employee_salary" => "Employee salary", + "employee_id" => "Employee", + "underground" => "Underground", + "_id" => "Id", + "_external_id" => "External" } UnderscoreToHumanWithoutCapitalize = { @@ -255,20 +255,20 @@ module InflectorTestCases } MixtureToTitleCase = { - 'active_record' => 'Active Record', - 'ActiveRecord' => 'Active Record', - 'action web service' => 'Action Web Service', - 'Action Web Service' => 'Action Web Service', - 'Action web service' => 'Action Web Service', - 'actionwebservice' => 'Actionwebservice', - 'Actionwebservice' => 'Actionwebservice', + "active_record" => "Active Record", + "ActiveRecord" => "Active Record", + "action web service" => "Action Web Service", + "Action Web Service" => "Action Web Service", + "Action web service" => "Action Web Service", + "actionwebservice" => "Actionwebservice", + "Actionwebservice" => "Actionwebservice", "david's code" => "David's Code", "David's code" => "David's Code", "david's Code" => "David's Code", "sgt. pepper's" => "Sgt. Pepper's", "i've just seen a face" => "I've Just Seen A Face", "maybe you'll be there" => "Maybe You'll Be There", - "¿por qué?" => '¿Por Qué?', + "¿por qué?" => "¿Por Qué?", "Fred’s" => "Fred’s", "Fred`s" => "Fred`s", ActiveSupport::SafeBuffer.new("confirmation num") => "Confirmation Num" @@ -345,13 +345,13 @@ module InflectorTestCases } Irregularities = { - 'person' => 'people', - 'man' => 'men', - 'child' => 'children', - 'sex' => 'sexes', - 'move' => 'moves', - 'cow' => 'kine', # Test inflections with different starting letters - 'zombie' => 'zombies', - 'genus' => 'genera' + "person" => "people", + "man" => "men", + "child" => "children", + "sex" => "sexes", + "move" => "moves", + "cow" => "kine", # Test inflections with different starting letters + "zombie" => "zombies", + "genus" => "genera" } end diff --git a/activesupport/test/json/decoding_test.rb b/activesupport/test/json/decoding_test.rb index 887ef1681d..dd8382754b 100644 --- a/activesupport/test/json/decoding_test.rb +++ b/activesupport/test/json/decoding_test.rb @@ -1,7 +1,7 @@ -require 'abstract_unit' -require 'active_support/json' -require 'active_support/time' -require 'time_zone_test_helpers' +require "abstract_unit" +require "active_support/json" +require "active_support/time" +require "time_zone_test_helpers" class TestJSONDecoding < ActiveSupport::TestCase include TimeZoneTestHelpers @@ -13,70 +13,70 @@ class TestJSONDecoding < ActiveSupport::TestCase end TESTS = { - %q({"returnTo":{"\/categories":"\/"}}) => {"returnTo" => {"/categories" => "/"}}, - %q({"return\\"To\\":":{"\/categories":"\/"}}) => {"return\"To\":" => {"/categories" => "/"}}, - %q({"returnTo":{"\/categories":1}}) => {"returnTo" => {"/categories" => 1}}, - %({"returnTo":[1,"a"]}) => {"returnTo" => [1, "a"]}, - %({"returnTo":[1,"\\"a\\",", "b"]}) => {"returnTo" => [1, "\"a\",", "b"]}, - %({"a": "'", "b": "5,000"}) => {"a" => "'", "b" => "5,000"}, - %({"a": "a's, b's and c's", "b": "5,000"}) => {"a" => "a's, b's and c's", "b" => "5,000"}, + %q({"returnTo":{"\/categories":"\/"}}) => { "returnTo" => { "/categories" => "/" } }, + %q({"return\\"To\\":":{"\/categories":"\/"}}) => { "return\"To\":" => { "/categories" => "/" } }, + %q({"returnTo":{"\/categories":1}}) => { "returnTo" => { "/categories" => 1 } }, + %({"returnTo":[1,"a"]}) => { "returnTo" => [1, "a"] }, + %({"returnTo":[1,"\\"a\\",", "b"]}) => { "returnTo" => [1, "\"a\",", "b"] }, + %({"a": "'", "b": "5,000"}) => { "a" => "'", "b" => "5,000" }, + %({"a": "a's, b's and c's", "b": "5,000"}) => { "a" => "a's, b's and c's", "b" => "5,000" }, # multibyte - %({"matzue": "松江", "asakusa": "浅草"}) => {"matzue" => "松江", "asakusa" => "浅草"}, - %({"a": "2007-01-01"}) => {'a' => Date.new(2007, 1, 1)}, - %({"a": "2007-01-01 01:12:34 Z"}) => {'a' => Time.utc(2007, 1, 1, 1, 12, 34)}, + %({"matzue": "松江", "asakusa": "浅草"}) => { "matzue" => "松江", "asakusa" => "浅草" }, + %({"a": "2007-01-01"}) => { "a" => Date.new(2007, 1, 1) }, + %({"a": "2007-01-01 01:12:34 Z"}) => { "a" => Time.utc(2007, 1, 1, 1, 12, 34) }, %(["2007-01-01 01:12:34 Z"]) => [Time.utc(2007, 1, 1, 1, 12, 34)], %(["2007-01-01 01:12:34 Z", "2007-01-01 01:12:35 Z"]) => [Time.utc(2007, 1, 1, 1, 12, 34), Time.utc(2007, 1, 1, 1, 12, 35)], # no time zone - %({"a": "2007-01-01 01:12:34"}) => {'a' => Time.new(2007, 1, 1, 1, 12, 34, "-05:00")}, + %({"a": "2007-01-01 01:12:34"}) => { "a" => Time.new(2007, 1, 1, 1, 12, 34, "-05:00") }, # invalid date - %({"a": "1089-10-40"}) => {'a' => "1089-10-40"}, + %({"a": "1089-10-40"}) => { "a" => "1089-10-40" }, # xmlschema date notation - %({"a": "2009-08-10T19:01:02"}) => {'a' => Time.new(2009, 8, 10, 19, 1, 2, "-04:00")}, - %({"a": "2009-08-10T19:01:02Z"}) => {'a' => Time.utc(2009, 8, 10, 19, 1, 2)}, - %({"a": "2009-08-10T19:01:02+02:00"}) => {'a' => Time.utc(2009, 8, 10, 17, 1, 2)}, - %({"a": "2009-08-10T19:01:02-05:00"}) => {'a' => Time.utc(2009, 8, 11, 00, 1, 2)}, + %({"a": "2009-08-10T19:01:02"}) => { "a" => Time.new(2009, 8, 10, 19, 1, 2, "-04:00") }, + %({"a": "2009-08-10T19:01:02Z"}) => { "a" => Time.utc(2009, 8, 10, 19, 1, 2) }, + %({"a": "2009-08-10T19:01:02+02:00"}) => { "a" => Time.utc(2009, 8, 10, 17, 1, 2) }, + %({"a": "2009-08-10T19:01:02-05:00"}) => { "a" => Time.utc(2009, 8, 11, 00, 1, 2) }, # needs to be *exact* - %({"a": " 2007-01-01 01:12:34 Z "}) => {'a' => " 2007-01-01 01:12:34 Z "}, - %({"a": "2007-01-01 : it's your birthday"}) => {'a' => "2007-01-01 : it's your birthday"}, + %({"a": " 2007-01-01 01:12:34 Z "}) => { "a" => " 2007-01-01 01:12:34 Z " }, + %({"a": "2007-01-01 : it's your birthday"}) => { "a" => "2007-01-01 : it's your birthday" }, %([]) => [], %({}) => {}, - %({"a":1}) => {"a" => 1}, - %({"a": ""}) => {"a" => ""}, - %({"a":"\\""}) => {"a" => "\""}, - %({"a": null}) => {"a" => nil}, - %({"a": true}) => {"a" => true}, - %({"a": false}) => {"a" => false}, - %q({"bad":"\\\\","trailing":""}) => {"bad" => "\\", "trailing" => ""}, - %q({"a": "http:\/\/test.host\/posts\/1"}) => {"a" => "http://test.host/posts/1"}, - %q({"a": "\u003cunicode\u0020escape\u003e"}) => {"a" => "<unicode escape>"}, - %q({"a": "\\\\u0020skip double backslashes"}) => {"a" => "\\u0020skip double backslashes"}, - %q({"a": "\u003cbr /\u003e"}) => {'a' => "<br />"}, - %q({"b":["\u003ci\u003e","\u003cb\u003e","\u003cu\u003e"]}) => {'b' => ["<i>","<b>","<u>"]}, + %({"a":1}) => { "a" => 1 }, + %({"a": ""}) => { "a" => "" }, + %({"a":"\\""}) => { "a" => "\"" }, + %({"a": null}) => { "a" => nil }, + %({"a": true}) => { "a" => true }, + %({"a": false}) => { "a" => false }, + '{"bad":"\\\\","trailing":""}' => { "bad" => "\\", "trailing" => "" }, + %q({"a": "http:\/\/test.host\/posts\/1"}) => { "a" => "http://test.host/posts/1" }, + %q({"a": "\u003cunicode\u0020escape\u003e"}) => { "a" => "<unicode escape>" }, + '{"a": "\\\\u0020skip double backslashes"}' => { "a" => "\\u0020skip double backslashes" }, + %q({"a": "\u003cbr /\u003e"}) => { "a" => "<br />" }, + %q({"b":["\u003ci\u003e","\u003cb\u003e","\u003cu\u003e"]}) => { "b" => ["<i>","<b>","<u>"] }, # test combination of dates and escaped or unicode encoded data in arrays %q([{"d":"1970-01-01", "s":"\u0020escape"},{"d":"1970-01-01", "s":"\u0020escape"}]) => - [{'d' => Date.new(1970, 1, 1), 's' => ' escape'},{'d' => Date.new(1970, 1, 1), 's' => ' escape'}], + [{ "d" => Date.new(1970, 1, 1), "s" => " escape" },{ "d" => Date.new(1970, 1, 1), "s" => " escape" }], %q([{"d":"1970-01-01","s":"http:\/\/example.com"},{"d":"1970-01-01","s":"http:\/\/example.com"}]) => - [{'d' => Date.new(1970, 1, 1), 's' => 'http://example.com'}, - {'d' => Date.new(1970, 1, 1), 's' => 'http://example.com'}], + [{ "d" => Date.new(1970, 1, 1), "s" => "http://example.com" }, + { "d" => Date.new(1970, 1, 1), "s" => "http://example.com" }], # tests escaping of "\n" char with Yaml backend - %q({"a":"\n"}) => {"a"=>"\n"}, - %q({"a":"\u000a"}) => {"a"=>"\n"}, - %q({"a":"Line1\u000aLine2"}) => {"a"=>"Line1\nLine2"}, + %q({"a":"\n"}) => { "a"=>"\n" }, + %q({"a":"\u000a"}) => { "a"=>"\n" }, + %q({"a":"Line1\u000aLine2"}) => { "a"=>"Line1\nLine2" }, # prevent json unmarshalling - %q({"json_class":"TestJSONDecoding::Foo"}) => {"json_class"=>"TestJSONDecoding::Foo"}, + '{"json_class":"TestJSONDecoding::Foo"}' => { "json_class"=>"TestJSONDecoding::Foo" }, # json "fragments" - these are invalid JSON, but ActionPack relies on this - %q("a string") => "a string", - %q(1.1) => 1.1, - %q(1) => 1, - %q(-1) => -1, - %q(true) => true, - %q(false) => false, - %q(null) => nil + '"a string"' => "a string", + "1.1" => 1.1, + "1" => 1, + "-1" => -1, + "true" => true, + "false" => false, + "null" => nil } TESTS.each_with_index do |(json, expected), index| test "json decodes #{index}" do - with_tz_default 'Eastern Time (US & Canada)' do + with_tz_default "Eastern Time (US & Canada)" do with_parse_json_times(true) do silence_warnings do assert_equal expected, ActiveSupport::JSON.decode(json), "JSON decoding \ @@ -89,7 +89,7 @@ class TestJSONDecoding < ActiveSupport::TestCase test "json decodes time json with time parsing disabled" do with_parse_json_times(false) do - expected = {"a" => "2007-01-01 01:12:34 Z"} + expected = { "a" => "2007-01-01 01:12:34 Z" } assert_equal expected, ActiveSupport::JSON.decode(%({"a": "2007-01-01 01:12:34 Z"})) end end @@ -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/json/encoding_test.rb b/activesupport/test/json/encoding_test.rb index 8cb3b1a9bb..d125cc939f 100644 --- a/activesupport/test/json/encoding_test.rb +++ b/activesupport/test/json/encoding_test.rb @@ -1,18 +1,18 @@ -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' -require 'json/encoding_test_cases' +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" +require "json/encoding_test_cases" class TestJSONEncoding < ActiveSupport::TestCase include TimeZoneTestHelpers def sorted_json(json) - if json.start_with?('{') && json.end_with?('}') - '{' + json[1..-2].split(',').sort.join(',') + '}' + if json.start_with?("{") && json.end_with?("}") + "{" + json[1..-2].split(",").sort.join(",") + "}" else json end @@ -47,12 +47,12 @@ class TestJSONEncoding < ActiveSupport::TestCase end def test_hash_encoding - assert_equal %({\"a\":\"b\"}), ActiveSupport::JSON.encode(:a => :b) - assert_equal %({\"a\":1}), ActiveSupport::JSON.encode('a' => 1) - assert_equal %({\"a\":[1,2]}), ActiveSupport::JSON.encode('a' => [1,2]) + assert_equal %({\"a\":\"b\"}), ActiveSupport::JSON.encode(a: :b) + assert_equal %({\"a\":1}), ActiveSupport::JSON.encode("a" => 1) + assert_equal %({\"a\":[1,2]}), ActiveSupport::JSON.encode("a" => [1,2]) assert_equal %({"1":2}), ActiveSupport::JSON.encode(1 => 2) - assert_equal %({\"a\":\"b\",\"c\":\"d\"}), sorted_json(ActiveSupport::JSON.encode(:a => :b, :c => :d)) + assert_equal %({\"a\":\"b\",\"c\":\"d\"}), sorted_json(ActiveSupport::JSON.encode(a: :b, c: :d)) end def test_hash_keys_encoding @@ -63,24 +63,24 @@ class TestJSONEncoding < ActiveSupport::TestCase end def test_utf8_string_encoded_properly - result = ActiveSupport::JSON.encode('€2.99') + result = ActiveSupport::JSON.encode("€2.99") assert_equal '"€2.99"', result assert_equal(Encoding::UTF_8, result.encoding) - result = ActiveSupport::JSON.encode('✎☺') + result = ActiveSupport::JSON.encode("✎☺") assert_equal '"✎☺"', result assert_equal(Encoding::UTF_8, result.encoding) end def test_non_utf8_string_transcodes - s = '二'.encode('Shift_JIS') + s = "二".encode("Shift_JIS") result = ActiveSupport::JSON.encode(s) assert_equal '"二"', result assert_equal Encoding::UTF_8, result.encoding end def test_wide_utf8_chars - w = '𠜎' + w = "𠜎" result = ActiveSupport::JSON.encode(w) assert_equal '"𠜎"', result end @@ -89,25 +89,25 @@ class TestJSONEncoding < ActiveSupport::TestCase hash = { string: "𐒑" } json = ActiveSupport::JSON.encode(hash) decoded_hash = ActiveSupport::JSON.decode(json) - assert_equal "𐒑", decoded_hash['string'] + assert_equal "𐒑", decoded_hash["string"] end def test_hash_key_identifiers_are_always_quoted - values = {0 => 0, 1 => 1, :_ => :_, "$" => "$", "a" => "a", :A => :A, :A0 => :A0, "A0B" => "A0B"} + values = { 0 => 0, 1 => 1, :_ => :_, "$" => "$", "a" => "a", :A => :A, :A0 => :A0, "A0B" => "A0B" } assert_equal %w( "$" "A" "A0" "A0B" "_" "a" "0" "1" ).sort, object_keys(ActiveSupport::JSON.encode(values)) end def test_hash_should_allow_key_filtering_with_only - assert_equal %({"a":1}), ActiveSupport::JSON.encode({'a' => 1, :b => 2, :c => 3}, :only => 'a') + assert_equal %({"a":1}), ActiveSupport::JSON.encode({ "a" => 1, :b => 2, :c => 3 }, only: "a") end def test_hash_should_allow_key_filtering_with_except - assert_equal %({"b":2}), ActiveSupport::JSON.encode({'foo' => 'bar', :b => 2, :c => 3}, :except => ['foo', :c]) + assert_equal %({"b":2}), ActiveSupport::JSON.encode({ "foo" => "bar", :b => 2, :c => 3 }, except: ["foo", :c]) end def test_time_to_json_includes_local_offset with_standard_json_time_format(true) do - with_env_tz 'US/Eastern' do + with_env_tz "US/Eastern" do assert_equal %("2005-02-01T15:15:10.000-05:00"), ActiveSupport::JSON.encode(Time.local(2005,2,1,15,15,10)) end end @@ -115,7 +115,7 @@ class TestJSONEncoding < ActiveSupport::TestCase def test_hash_with_time_to_json with_standard_json_time_format(false) do - assert_equal '{"time":"2009/01/01 00:00:00 +0000"}', { :time => Time.utc(2009) }.to_json + assert_equal '{"time":"2009/01/01 00:00:00 +0000"}', { time: Time.utc(2009) }.to_json end end @@ -123,8 +123,8 @@ class TestJSONEncoding < ActiveSupport::TestCase assert_nothing_raised do hash = { "CHI" => { - :display_name => "chicago", - :latitude => 123.234 + display_name: "chicago", + latitude: 123.234 } } ActiveSupport::JSON.encode(hash) @@ -133,64 +133,64 @@ class TestJSONEncoding < ActiveSupport::TestCase def test_hash_like_with_options h = JSONTest::Hashlike.new - json = h.to_json :only => [:foo] + json = h.to_json only: [:foo] - assert_equal({"foo"=>"hello"}, JSON.parse(json)) + assert_equal({ "foo"=>"hello" }, JSON.parse(json)) end def test_object_to_json_with_options obj = Object.new obj.instance_variable_set :@foo, "hello" obj.instance_variable_set :@bar, "world" - json = obj.to_json :only => ["foo"] + json = obj.to_json only: ["foo"] - assert_equal({"foo"=>"hello"}, JSON.parse(json)) + assert_equal({ "foo"=>"hello" }, JSON.parse(json)) end def test_struct_to_json_with_options struct = Struct.new(:foo, :bar).new struct.foo = "hello" struct.bar = "world" - json = struct.to_json :only => [:foo] + json = struct.to_json only: [:foo] - assert_equal({"foo"=>"hello"}, JSON.parse(json)) + assert_equal({ "foo"=>"hello" }, JSON.parse(json)) end def test_hash_should_pass_encoding_options_to_children_in_as_json person = { - :name => 'John', - :address => { - :city => 'London', - :country => 'UK' + name: "John", + address: { + city: "London", + country: "UK" } } - json = person.as_json :only => [:address, :city] + json = person.as_json only: [:address, :city] - assert_equal({ 'address' => { 'city' => 'London' }}, json) + assert_equal({ "address" => { "city" => "London" } }, json) end def test_hash_should_pass_encoding_options_to_children_in_to_json person = { - :name => 'John', - :address => { - :city => 'London', - :country => 'UK' + name: "John", + address: { + city: "London", + country: "UK" } } - json = person.to_json :only => [:address, :city] + json = person.to_json only: [:address, :city] assert_equal(%({"address":{"city":"London"}}), json) end def test_array_should_pass_encoding_options_to_children_in_as_json people = [ - { :name => 'John', :address => { :city => 'London', :country => 'UK' }}, - { :name => 'Jean', :address => { :city => 'Paris' , :country => 'France' }} + { name: "John", address: { city: "London", country: "UK" } }, + { name: "Jean", address: { city: "Paris" , country: "France" } } ] - json = people.as_json :only => [:address, :city] + json = people.as_json only: [:address, :city] expected = [ - { 'address' => { 'city' => 'London' }}, - { 'address' => { 'city' => 'Paris' }} + { "address" => { "city" => "London" } }, + { "address" => { "city" => "Paris" } } ] assert_equal(expected, json) @@ -198,10 +198,10 @@ class TestJSONEncoding < ActiveSupport::TestCase def test_array_should_pass_encoding_options_to_children_in_to_json people = [ - { :name => 'John', :address => { :city => 'London', :country => 'UK' }}, - { :name => 'Jean', :address => { :city => 'Paris' , :country => 'France' }} + { name: "John", address: { city: "London", country: "UK" } }, + { name: "Jean", address: { city: "Paris" , country: "France" } } ] - json = people.to_json :only => [:address, :city] + json = people.to_json only: [:address, :city] assert_equal(%([{"address":{"city":"London"}},{"address":{"city":"Paris"}}]), json) end @@ -210,8 +210,8 @@ class TestJSONEncoding < ActiveSupport::TestCase include Enumerable def initialize() @people = [ - { :name => 'John', :address => { :city => 'London', :country => 'UK' }}, - { :name => 'Jean', :address => { :city => 'Paris' , :country => 'France' }} + { name: "John", address: { city: "London", country: "UK" } }, + { name: "Jean", address: { city: "Paris" , country: "France" } } ] end def each(*, &blk) @@ -223,32 +223,32 @@ class TestJSONEncoding < ActiveSupport::TestCase end def test_enumerable_should_generate_json_with_as_json - json = People.new.as_json :only => [:address, :city] + json = People.new.as_json only: [:address, :city] expected = [ - { 'address' => { 'city' => 'London' }}, - { 'address' => { 'city' => 'Paris' }} + { "address" => { "city" => "London" } }, + { "address" => { "city" => "Paris" } } ] assert_equal(expected, json) end def test_enumerable_should_generate_json_with_to_json - json = People.new.to_json :only => [:address, :city] + json = People.new.to_json only: [:address, :city] assert_equal(%([{"address":{"city":"London"}},{"address":{"city":"Paris"}}]), json) end def test_enumerable_should_pass_encoding_options_to_children_in_as_json - json = People.new.each.as_json :only => [:address, :city] + json = People.new.each.as_json only: [:address, :city] expected = [ - { 'address' => { 'city' => 'London' }}, - { 'address' => { 'city' => 'Paris' }} + { "address" => { "city" => "London" } }, + { "address" => { "city" => "Paris" } } ] assert_equal(expected, json) end def test_enumerable_should_pass_encoding_options_to_children_in_to_json - json = People.new.each.to_json :only => [:address, :city] + json = People.new.each.to_json only: [:address, :city] assert_equal(%([{"address":{"city":"London"}},{"address":{"city":"Paris"}}]), json) end @@ -267,9 +267,9 @@ class TestJSONEncoding < ActiveSupport::TestCase f.foo = "hello" f.bar = "world" - hash = {"foo" => f, "other_hash" => {"foo" => "other_foo", "test" => "other_test"}} - assert_equal({"foo"=>{"foo"=>"hello","bar"=>"world"}, - "other_hash" => {"foo"=>"other_foo","test"=>"other_test"}}, ActiveSupport::JSON.decode(hash.to_json)) + hash = { "foo" => f, "other_hash" => { "foo" => "other_foo", "test" => "other_test" } } + assert_equal({ "foo"=>{ "foo"=>"hello","bar"=>"world" }, + "other_hash" => { "foo"=>"other_foo","test"=>"other_test" } }, ActiveSupport::JSON.decode(hash.to_json)) end def test_array_to_json_should_not_keep_options_around @@ -277,9 +277,9 @@ class TestJSONEncoding < ActiveSupport::TestCase f.foo = "hello" f.bar = "world" - array = [f, {"foo" => "other_foo", "test" => "other_test"}] - assert_equal([{"foo"=>"hello","bar"=>"world"}, - {"foo"=>"other_foo","test"=>"other_test"}], ActiveSupport::JSON.decode(array.to_json)) + array = [f, { "foo" => "other_foo", "test" => "other_test" }] + assert_equal([{ "foo"=>"hello","bar"=>"world" }, + { "foo"=>"other_foo","test"=>"other_test" }], ActiveSupport::JSON.decode(array.to_json)) end class OptionsTest @@ -290,7 +290,7 @@ class TestJSONEncoding < ActiveSupport::TestCase def test_hash_as_json_without_options json = { foo: OptionsTest.new }.as_json - assert_equal({"foo" => :default}, json) + assert_equal({ "foo" => :default }, json) end def test_array_as_json_without_options @@ -299,13 +299,12 @@ class TestJSONEncoding < ActiveSupport::TestCase end def test_struct_encoding - Struct.new('UserNameAndEmail', :name, :email) - Struct.new('UserNameAndDate', :name, :date) - Struct.new('Custom', :name, :sub) - user_email = Struct::UserNameAndEmail.new 'David', 'sample@example.com' - user_birthday = Struct::UserNameAndDate.new 'David', Date.new(2010, 01, 01) - custom = Struct::Custom.new 'David', user_birthday - + Struct.new("UserNameAndEmail", :name, :email) + Struct.new("UserNameAndDate", :name, :date) + Struct.new("Custom", :name, :sub) + user_email = Struct::UserNameAndEmail.new "David", "sample@example.com" + user_birthday = Struct::UserNameAndDate.new "David", Date.new(2010, 01, 01) + custom = Struct::Custom.new "David", user_birthday json_strings = "" json_string_and_date = "" @@ -317,15 +316,15 @@ class TestJSONEncoding < ActiveSupport::TestCase json_custom = custom.to_json end - assert_equal({"name" => "David", + assert_equal({ "name" => "David", "sub" => { "name" => "David", - "date" => "2010-01-01" }}, ActiveSupport::JSON.decode(json_custom)) + "date" => "2010-01-01" } }, ActiveSupport::JSON.decode(json_custom)) - assert_equal({"name" => "David", "email" => "sample@example.com"}, + assert_equal({ "name" => "David", "email" => "sample@example.com" }, ActiveSupport::JSON.decode(json_strings)) - assert_equal({"name" => "David", "date" => "2010-01-01"}, + assert_equal({ "name" => "David", "date" => "2010-01-01" }, ActiveSupport::JSON.decode(json_string_and_date)) end @@ -382,7 +381,7 @@ EXPECTED def test_twz_to_json_with_use_standard_json_time_format_config_set_to_false with_standard_json_time_format(false) do - zone = ActiveSupport::TimeZone['Eastern Time (US & Canada)'] + zone = ActiveSupport::TimeZone["Eastern Time (US & Canada)"] time = ActiveSupport::TimeWithZone.new(Time.utc(2000), zone) assert_equal "\"1999/12/31 19:00:00 -0500\"", ActiveSupport::JSON.encode(time) end @@ -390,7 +389,7 @@ EXPECTED def test_twz_to_json_with_use_standard_json_time_format_config_set_to_true with_standard_json_time_format(true) do - zone = ActiveSupport::TimeZone['Eastern Time (US & Canada)'] + zone = ActiveSupport::TimeZone["Eastern Time (US & Canada)"] time = ActiveSupport::TimeWithZone.new(Time.utc(2000), zone) assert_equal "\"1999-12-31T19:00:00.000-05:00\"", ActiveSupport::JSON.encode(time) end @@ -399,7 +398,7 @@ EXPECTED def test_twz_to_json_with_custom_time_precision with_standard_json_time_format(true) do with_time_precision(0) do - zone = ActiveSupport::TimeZone['Eastern Time (US & Canada)'] + zone = ActiveSupport::TimeZone["Eastern Time (US & Canada)"] time = ActiveSupport::TimeWithZone.new(Time.utc(2000), zone) assert_equal "\"1999-12-31T19:00:00-05:00\"", ActiveSupport::JSON.encode(time) end @@ -423,7 +422,7 @@ EXPECTED end def test_twz_to_json_when_wrapping_a_date_time - zone = ActiveSupport::TimeZone['Eastern Time (US & Canada)'] + zone = ActiveSupport::TimeZone["Eastern Time (US & Canada)"] time = ActiveSupport::TimeWithZone.new(DateTime.new(2000), zone) assert_equal '"1999-12-31T19:00:00.000-05:00"', ActiveSupport::JSON.encode(time) end diff --git a/activesupport/test/json/encoding_test_cases.rb b/activesupport/test/json/encoding_test_cases.rb index e043fadf56..ff2ed3a788 100644 --- a/activesupport/test/json/encoding_test_cases.rb +++ b/activesupport/test/json/encoding_test_cases.rb @@ -1,4 +1,4 @@ -require 'bigdecimal' +require "bigdecimal" module JSONTest class Foo @@ -9,7 +9,7 @@ module JSONTest class Hashlike def to_hash - { :foo => "hello", :bar => "world" } + { foo: "hello", bar: "world" } end end @@ -39,20 +39,20 @@ module JSONTest [ 0.0/0.0, %(null) ], [ 1.0/0.0, %(null) ], [ -1.0/0.0, %(null) ], - [ BigDecimal('0.0')/BigDecimal('0.0'), %(null) ], - [ BigDecimal('2.5'), %("#{BigDecimal('2.5')}") ]] + [ BigDecimal("0.0")/BigDecimal("0.0"), %(null) ], + [ BigDecimal("2.5"), %("#{BigDecimal('2.5')}") ]] - StringTests = [[ 'this is the <string>', %("this is the \\u003cstring\\u003e")], + StringTests = [[ "this is the <string>", %("this is the \\u003cstring\\u003e")], [ 'a "string" with quotes & an ampersand', %("a \\"string\\" with quotes \\u0026 an ampersand") ], - [ 'http://test.host/posts/1', %("http://test.host/posts/1")], + [ "http://test.host/posts/1", %("http://test.host/posts/1")], [ "Control characters: \x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f\u2028\u2029", %("Control characters: \\u0000\\u0001\\u0002\\u0003\\u0004\\u0005\\u0006\\u0007\\b\\t\\n\\u000b\\f\\r\\u000e\\u000f\\u0010\\u0011\\u0012\\u0013\\u0014\\u0015\\u0016\\u0017\\u0018\\u0019\\u001a\\u001b\\u001c\\u001d\\u001e\\u001f\\u2028\\u2029") ]] - ArrayTests = [[ ['a', 'b', 'c'], %([\"a\",\"b\",\"c\"]) ], - [ [1, 'a', :b, nil, false], %([1,\"a\",\"b\",null,false]) ]] + ArrayTests = [[ ["a", "b", "c"], %([\"a\",\"b\",\"c\"]) ], + [ [1, "a", :b, nil, false], %([1,\"a\",\"b\",null,false]) ]] - HashTests = [[ {foo: "bar"}, %({\"foo\":\"bar\"}) ], - [ {1 => 1, 2 => 'a', 3 => :b, 4 => nil, 5 => false}, %({\"1\":1,\"2\":\"a\",\"3\":\"b\",\"4\":null,\"5\":false}) ]] + HashTests = [[ { foo: "bar" }, %({\"foo\":\"bar\"}) ], + [ { 1 => 1, 2 => "a", 3 => :b, 4 => nil, 5 => false }, %({\"1\":1,\"2\":\"a\",\"3\":\"b\",\"4\":null,\"5\":false}) ]] RangeTests = [[ 1..2, %("1..2")], [ 1...2, %("1...2")], @@ -67,18 +67,18 @@ module JSONTest StructTests = [[ MyStruct.new(:foo, "bar"), %({\"name\":\"foo\",\"value\":\"bar\"}) ], [ MyStruct.new(nil, nil), %({\"name\":null,\"value\":null}) ]] CustomTests = [[ Custom.new("custom"), '"custom"' ], - [ Custom.new(nil), 'null' ], + [ Custom.new(nil), "null" ], [ Custom.new(:a), '"a"' ], [ Custom.new([ :foo, "bar" ]), '["foo","bar"]' ], - [ Custom.new({ :foo => "hello", :bar => "world" }), '{"bar":"world","foo":"hello"}' ], + [ Custom.new(foo: "hello", bar: "world"), '{"bar":"world","foo":"hello"}' ], [ Custom.new(Hashlike.new), '{"bar":"world","foo":"hello"}' ], [ Custom.new(Custom.new(Custom.new(:a))), '"a"' ]] RegexpTests = [[ /^a/, '"(?-mix:^a)"' ], [/^\w{1,2}[a-z]+/ix, '"(?ix-m:^\\\\w{1,2}[a-z]+)"']] - URITests = [[ URI.parse('http://example.com'), %("http://example.com") ]] + URITests = [[ URI.parse("http://example.com"), %("http://example.com") ]] - PathnameTests = [[ Pathname.new('lib/index.rb'), %("lib/index.rb") ]] + PathnameTests = [[ Pathname.new("lib/index.rb"), %("lib/index.rb") ]] DateTests = [[ Date.new(2005,2,1), %("2005/02/01") ]] TimeTests = [[ Time.utc(2005,2,1,15,15,10), %("2005/02/01 15:15:10 +0000") ]] @@ -87,6 +87,6 @@ module JSONTest StandardDateTests = [[ Date.new(2005,2,1), %("2005-02-01") ]] StandardTimeTests = [[ Time.utc(2005,2,1,15,15,10), %("2005-02-01T15:15:10.000Z") ]] StandardDateTimeTests = [[ DateTime.civil(2005,2,1,15,15,10), %("2005-02-01T15:15:10.000+00:00") ]] - StandardStringTests = [[ 'this is the <string>', %("this is the <string>")]] + StandardStringTests = [[ "this is the <string>", %("this is the <string>")]] end end diff --git a/activesupport/test/key_generator_test.rb b/activesupport/test/key_generator_test.rb index b60077460e..89db9563ac 100644 --- a/activesupport/test/key_generator_test.rb +++ b/activesupport/test/key_generator_test.rb @@ -1,77 +1,77 @@ -require 'abstract_unit' +require "abstract_unit" begin - require 'openssl' + require "openssl" OpenSSL::PKCS5 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 7851634dbf..3b1959a1c9 100644 --- a/activesupport/test/lazy_load_hooks_test.rb +++ b/activesupport/test/lazy_load_hooks_test.rb @@ -1,4 +1,4 @@ -require 'abstract_unit' +require "abstract_unit" class LazyLoadHooksTest < ActiveSupport::TestCase def test_basic_hook @@ -63,7 +63,7 @@ class LazyLoadHooksTest < ActiveSupport::TestCase def test_hook_with_yield_true i = 0 - ActiveSupport.on_load(:contextual_yield, :yield => true) do |obj| + ActiveSupport.on_load(:contextual_yield, yield: true) do |obj| i += obj.incr + incr_amt end assert_equal 0, i @@ -75,7 +75,7 @@ class LazyLoadHooksTest < ActiveSupport::TestCase i = 0 ActiveSupport.run_load_hooks(:contextual_yield_after, FakeContext.new(2)) assert_equal 0, i - ActiveSupport.on_load(:contextual_yield_after, :yield => true) do |obj| + ActiveSupport.on_load(:contextual_yield_after, yield: true) do |obj| i += obj.incr + incr_amt end assert_equal 7, i @@ -93,4 +93,4 @@ private @incr = incr end end -end
\ No newline at end of file +end diff --git a/activesupport/test/log_subscriber_test.rb b/activesupport/test/log_subscriber_test.rb index 998a6887c5..f6496ef7d6 100644 --- a/activesupport/test/log_subscriber_test.rb +++ b/activesupport/test/log_subscriber_test.rb @@ -1,5 +1,5 @@ -require 'abstract_unit' -require 'active_support/log_subscriber/test_helper' +require "abstract_unit" +require "active_support/log_subscriber/test_helper" class MyLogSubscriber < ActiveSupport::LogSubscriber attr_reader :event @@ -116,7 +116,7 @@ class SyncLogSubscriberTest < ActiveSupport::TestCase wait assert_equal 1, @logger.logged(:info).size - assert_equal 'some_event.my_log_subscriber', @logger.logged(:info).last + assert_equal "some_event.my_log_subscriber", @logger.logged(:info).last assert_equal 1, @logger.logged(:error).size assert_match 'Could not log "puke.my_log_subscriber" event. RuntimeError: puke', @logger.logged(:error).last diff --git a/activesupport/test/logger_test.rb b/activesupport/test/logger_test.rb index dfc5f3fdf4..ece4167de9 100644 --- a/activesupport/test/logger_test.rb +++ b/activesupport/test/logger_test.rb @@ -1,9 +1,9 @@ -require 'abstract_unit' -require 'multibyte_test_helpers' -require 'stringio' -require 'fileutils' -require 'tempfile' -require 'concurrent/atomics' +require "abstract_unit" +require "multibyte_test_helpers" +require "stringio" +require "fileutils" +require "tempfile" +require "concurrent/atomics" class LoggerTest < ActiveSupport::TestCase include MultibyteTestHelpers @@ -26,12 +26,12 @@ class LoggerTest < ActiveSupport::TestCase end def test_write_binary_data_to_existing_file - t = Tempfile.new ['development', 'log'] + t = Tempfile.new ["development", "log"] t.binmode - t.write 'hi mom!' + t.write "hi mom!" t.close - f = File.open(t.path, 'w') + f = File.open(t.path, "w") f.binmode logger = Logger.new f @@ -47,9 +47,9 @@ class LoggerTest < ActiveSupport::TestCase end def test_write_binary_data_create_file - fname = File.join Dir.tmpdir, 'lol', 'rofl.log' + fname = File.join Dir.tmpdir, "lol", "rofl.log" FileUtils.mkdir_p File.dirname(fname) - f = File.open(fname, 'w') + f = File.open(fname, "w") f.binmode logger = Logger.new f @@ -78,13 +78,13 @@ class LoggerTest < ActiveSupport::TestCase def test_should_add_message_passed_as_block_when_using_add @logger.level = Logger::INFO - @logger.add(Logger::INFO) {@message} + @logger.add(Logger::INFO) { @message } assert @output.string.include?(@message) end def test_should_add_message_passed_as_block_when_using_shortcut @logger.level = Logger::INFO - @logger.info {@message} + @logger.info { @message } assert @output.string.include?(@message) end @@ -96,14 +96,14 @@ class LoggerTest < ActiveSupport::TestCase def test_should_convert_message_to_string_when_passed_in_block @logger.level = Logger::INFO - @logger.info {@integer_message} + @logger.info { @integer_message } assert @output.string.include?(@integer_message.to_s) end def test_should_not_evaluate_block_if_message_wont_be_logged @logger.level = Logger::INFO evaluated = false - @logger.add(Logger::DEBUG) {evaluated = true} + @logger.add(Logger::DEBUG) { evaluated = true } assert evaluated == false end @@ -115,7 +115,7 @@ class LoggerTest < ActiveSupport::TestCase def test_should_know_if_its_loglevel_is_below_a_given_level Logger::Severity.constants.each do |level| - next if level.to_s == 'UNKNOWN' + next if level.to_s == "UNKNOWN" @logger.level = Logger::Severity.const_get(level) - 1 assert @logger.send("#{level.downcase}?"), "didn't know if it was #{level.downcase}? or below" end diff --git a/activesupport/test/message_encryptor_test.rb b/activesupport/test/message_encryptor_test.rb index 5dfa187f36..fb0b1e377d 100644 --- a/activesupport/test/message_encryptor_test.rb +++ b/activesupport/test/message_encryptor_test.rb @@ -1,7 +1,7 @@ -require 'abstract_unit' -require 'openssl' -require 'active_support/time' -require 'active_support/json' +require "abstract_unit" +require "openssl" +require "active_support/time" +require "active_support/json" class MessageEncryptorTest < ActiveSupport::TestCase class JSONSerializer @@ -16,9 +16,9 @@ class MessageEncryptorTest < ActiveSupport::TestCase def setup @secret = SecureRandom.random_bytes(32) - @verifier = ActiveSupport::MessageVerifier.new(@secret, :serializer => ActiveSupport::MessageEncryptor::NullSerializer) + @verifier = ActiveSupport::MessageVerifier.new(@secret, serializer: ActiveSupport::MessageEncryptor::NullSerializer) @encryptor = ActiveSupport::MessageEncryptor.new(@secret) - @data = { :some => "data", :now => Time.local(2010) } + @data = { some: "data", now: Time.local(2010) } end def test_encrypting_twice_yields_differing_cipher_text @@ -51,8 +51,8 @@ class MessageEncryptorTest < ActiveSupport::TestCase def test_alternative_serialization_method prev = ActiveSupport.use_standard_json_time_format ActiveSupport.use_standard_json_time_format = true - encryptor = ActiveSupport::MessageEncryptor.new(SecureRandom.random_bytes(32), SecureRandom.random_bytes(128), :serializer => JSONSerializer.new) - message = encryptor.encrypt_and_sign({ :foo => 123, 'bar' => Time.utc(2010) }) + encryptor = ActiveSupport::MessageEncryptor.new(SecureRandom.random_bytes(32), SecureRandom.random_bytes(128), serializer: JSONSerializer.new) + message = encryptor.encrypt_and_sign(:foo => 123, "bar" => Time.utc(2010)) exp = { "foo" => 123, "bar" => "2010-01-01T00:00:00.000Z" } assert_equal exp, encryptor.decrypt_and_verify(message) ensure @@ -71,13 +71,13 @@ class MessageEncryptorTest < ActiveSupport::TestCase end def test_aead_mode_encryption - encryptor = ActiveSupport::MessageEncryptor.new(@secret, cipher: 'aes-256-gcm') + encryptor = ActiveSupport::MessageEncryptor.new(@secret, cipher: "aes-256-gcm") message = encryptor.encrypt_and_sign(@data) assert_equal @data, encryptor.decrypt_and_verify(message) end def test_messing_with_aead_values_causes_failures - encryptor = ActiveSupport::MessageEncryptor.new(@secret, cipher: 'aes-256-gcm') + encryptor = ActiveSupport::MessageEncryptor.new(@secret, cipher: "aes-256-gcm") text, iv, auth_tag = encryptor.encrypt_and_sign(@data).split("--") assert_not_decrypted([iv, text, auth_tag] * "--") assert_not_decrypted([munge(text), iv, auth_tag] * "--") @@ -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/message_verifier_test.rb b/activesupport/test/message_verifier_test.rb index 668d78492e..d56a46b250 100644 --- a/activesupport/test/message_verifier_test.rb +++ b/activesupport/test/message_verifier_test.rb @@ -1,10 +1,9 @@ -require 'abstract_unit' -require 'openssl' -require 'active_support/time' -require 'active_support/json' +require "abstract_unit" +require "openssl" +require "active_support/time" +require "active_support/json" class MessageVerifierTest < ActiveSupport::TestCase - class JSONSerializer def dump(value) ActiveSupport::JSON.encode(value) @@ -17,7 +16,7 @@ class MessageVerifierTest < ActiveSupport::TestCase def setup @verifier = ActiveSupport::MessageVerifier.new("Hey, I'm a secret!") - @data = { :some => "data", :now => Time.local(2010) } + @data = { some: "data", now: Time.local(2010) } end def test_valid_message @@ -49,8 +48,8 @@ class MessageVerifierTest < ActiveSupport::TestCase def test_alternative_serialization_method prev = ActiveSupport.use_standard_json_time_format ActiveSupport.use_standard_json_time_format = true - verifier = ActiveSupport::MessageVerifier.new("Hey, I'm a secret!", :serializer => JSONSerializer.new) - message = verifier.generate({ :foo => 123, 'bar' => Time.utc(2010) }) + verifier = ActiveSupport::MessageVerifier.new("Hey, I'm a secret!", serializer: JSONSerializer.new) + message = verifier.generate(:foo => 123, "bar" => Time.utc(2010)) exp = { "foo" => 123, "bar" => "2010-01-01T00:00:00.000Z" } assert_equal exp, verifier.verified(message) assert_equal exp, verifier.verify(message) @@ -81,6 +80,6 @@ class MessageVerifierTest < ActiveSupport::TestCase exception = assert_raise(ArgumentError) do ActiveSupport::MessageVerifier.new(nil) end - assert_equal exception.message, 'Secret should not be nil.' + assert_equal exception.message, "Secret should not be nil." end end diff --git a/activesupport/test/multibyte_chars_test.rb b/activesupport/test/multibyte_chars_test.rb index c1e0b19248..54429f4aab 100644 --- a/activesupport/test/multibyte_chars_test.rb +++ b/activesupport/test/multibyte_chars_test.rb @@ -1,6 +1,6 @@ -require 'abstract_unit' -require 'multibyte_test_helpers' -require 'active_support/core_ext/string/multibyte' +require "abstract_unit" +require "multibyte_test_helpers" +require "active_support/core_ext/string/multibyte" class MultibyteCharsTest < ActiveSupport::TestCase include MultibyteTestHelpers @@ -16,7 +16,7 @@ class MultibyteCharsTest < ActiveSupport::TestCase end def test_should_allow_method_calls_to_string - @chars.wrapped_string.singleton_class.class_eval { def __method_for_multibyte_testing; 'result'; end } + @chars.wrapped_string.singleton_class.class_eval { def __method_for_multibyte_testing; "result"; end } assert_nothing_raised do @chars.__method_for_multibyte_testing @@ -27,14 +27,14 @@ class MultibyteCharsTest < ActiveSupport::TestCase end def test_forwarded_method_calls_should_return_new_chars_instance - @chars.wrapped_string.singleton_class.class_eval { def __method_for_multibyte_testing; 'result'; end } + @chars.wrapped_string.singleton_class.class_eval { def __method_for_multibyte_testing; "result"; end } assert_kind_of @proxy_class, @chars.__method_for_multibyte_testing assert_not_equal @chars.object_id, @chars.__method_for_multibyte_testing.object_id end def test_forwarded_bang_method_calls_should_return_the_original_chars_instance_when_result_is_not_nil - @chars.wrapped_string.singleton_class.class_eval { def __method_for_multibyte_testing!; 'result'; end } + @chars.wrapped_string.singleton_class.class_eval { def __method_for_multibyte_testing!; "result"; end } assert_kind_of @proxy_class, @chars.__method_for_multibyte_testing! assert_equal @chars.object_id, @chars.__method_for_multibyte_testing!.object_id @@ -51,7 +51,7 @@ class MultibyteCharsTest < ActiveSupport::TestCase end def test_forwarded_method_with_non_string_result_should_be_returned_vertabim - str = '' + str = "" 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,15 +59,15 @@ class MultibyteCharsTest < ActiveSupport::TestCase end def test_should_concatenate - mb_a = 'a'.mb_chars - mb_b = 'b'.mb_chars - assert_equal 'ab', mb_a + 'b' - assert_equal 'ab', 'a' + mb_b - assert_equal 'ab', mb_a + mb_b + mb_a = "a".mb_chars + mb_b = "b".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 'abb', mb_a << mb_b + assert_equal "ab", mb_a << "b" + assert_equal "ab", "a" << mb_b + assert_equal "abb", mb_a << mb_b end def test_consumes_utf8_strings @@ -77,8 +77,8 @@ class MultibyteCharsTest < ActiveSupport::TestCase end 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".mb_chars + "b").class + assert_equal ActiveSupport::Multibyte.proxy_class, ("a".mb_chars << "b").class end def test_ascii_strings_are_treated_at_utf8_strings @@ -86,10 +86,10 @@ class MultibyteCharsTest < ActiveSupport::TestCase end 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".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)) end def test_should_return_string_as_json @@ -150,24 +150,24 @@ class MultibyteCharsUTF8BehaviourTest < ActiveSupport::TestCase end def test_string_methods_are_chainable - assert chars('').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) - assert chars('').rstrip.kind_of?(ActiveSupport::Multibyte.proxy_class) - assert chars('').lstrip.kind_of?(ActiveSupport::Multibyte.proxy_class) - assert chars('').strip.kind_of?(ActiveSupport::Multibyte.proxy_class) - assert chars('').reverse.kind_of?(ActiveSupport::Multibyte.proxy_class) - assert chars(' ').slice(0).kind_of?(ActiveSupport::Multibyte.proxy_class) - assert chars('').limit(0).kind_of?(ActiveSupport::Multibyte.proxy_class) - assert chars('').upcase.kind_of?(ActiveSupport::Multibyte.proxy_class) - assert chars('').downcase.kind_of?(ActiveSupport::Multibyte.proxy_class) - assert chars('').capitalize.kind_of?(ActiveSupport::Multibyte.proxy_class) - assert chars('').normalize.kind_of?(ActiveSupport::Multibyte.proxy_class) - assert chars('').decompose.kind_of?(ActiveSupport::Multibyte.proxy_class) - assert chars('').compose.kind_of?(ActiveSupport::Multibyte.proxy_class) - assert chars('').tidy_bytes.kind_of?(ActiveSupport::Multibyte.proxy_class) - assert chars('').swapcase.kind_of?(ActiveSupport::Multibyte.proxy_class) + assert chars("").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) + assert chars("").rstrip.kind_of?(ActiveSupport::Multibyte.proxy_class) + assert chars("").lstrip.kind_of?(ActiveSupport::Multibyte.proxy_class) + assert chars("").strip.kind_of?(ActiveSupport::Multibyte.proxy_class) + assert chars("").reverse.kind_of?(ActiveSupport::Multibyte.proxy_class) + assert chars(" ").slice(0).kind_of?(ActiveSupport::Multibyte.proxy_class) + assert chars("").limit(0).kind_of?(ActiveSupport::Multibyte.proxy_class) + assert chars("").upcase.kind_of?(ActiveSupport::Multibyte.proxy_class) + assert chars("").downcase.kind_of?(ActiveSupport::Multibyte.proxy_class) + assert chars("").capitalize.kind_of?(ActiveSupport::Multibyte.proxy_class) + assert chars("").normalize.kind_of?(ActiveSupport::Multibyte.proxy_class) + assert chars("").decompose.kind_of?(ActiveSupport::Multibyte.proxy_class) + assert chars("").compose.kind_of?(ActiveSupport::Multibyte.proxy_class) + assert chars("").tidy_bytes.kind_of?(ActiveSupport::Multibyte.proxy_class) + assert chars("").swapcase.kind_of?(ActiveSupport::Multibyte.proxy_class) end def test_should_be_equal_to_the_wrapped_string @@ -176,8 +176,8 @@ class MultibyteCharsUTF8BehaviourTest < ActiveSupport::TestCase end def test_should_not_be_equal_to_an_other_string - assert_not_equal @chars, 'other' - assert_not_equal 'other', @chars + assert_not_equal @chars, "other" + assert_not_equal "other", @chars end def test_sortability @@ -195,29 +195,29 @@ class MultibyteCharsUTF8BehaviourTest < ActiveSupport::TestCase end def test_should_use_character_offsets_for_insert_offsets - assert_equal '', ''.mb_chars.insert(0, '') - assert_equal 'こわにちわ', @chars.insert(1, 'わ') - assert_equal 'こわわわにちわ', @chars.insert(2, 'わわ') - assert_equal 'わこわわわにちわ', @chars.insert(0, 'わ') - assert_equal 'わこわわわにちわ', @chars.wrapped_string + assert_equal "", "".mb_chars.insert(0, "") + assert_equal "こわにちわ", @chars.insert(1, "わ") + assert_equal "こわわわにちわ", @chars.insert(2, "わわ") + assert_equal "わこわわわにちわ", @chars.insert(0, "わ") + assert_equal "わこわわわにちわ", @chars.wrapped_string end def test_insert_should_be_destructive - @chars.insert(1, 'わ') - assert_equal 'こわにちわ', @chars + @chars.insert(1, "わ") + assert_equal "こわにちわ", @chars end def test_insert_throws_index_error - assert_raise(IndexError) { @chars.insert(-12, 'わ')} - assert_raise(IndexError) { @chars.insert(12, 'わ') } + assert_raise(IndexError) { @chars.insert(-12, "わ") } + assert_raise(IndexError) { @chars.insert(12, "わ") } end def test_should_know_if_one_includes_the_other - assert @chars.include?('') - assert @chars.include?('ち') - assert @chars.include?('わ') - assert !@chars.include?('こちわ') - assert !@chars.include?('a') + assert @chars.include?("") + assert @chars.include?("ち") + assert @chars.include?("わ") + assert !@chars.include?("こちわ") + assert !@chars.include?("a") end def test_include_raises_when_nil_is_passed @@ -227,62 +227,62 @@ class MultibyteCharsUTF8BehaviourTest < ActiveSupport::TestCase end def test_index_should_return_character_offset - assert_nil @chars.index('u') - assert_equal 0, @chars.index('こに') - assert_equal 2, @chars.index('ち') - assert_equal 2, @chars.index('ち', -2) - assert_equal nil, @chars.index('ち', -1) - assert_equal 3, @chars.index('わ') - assert_equal 5, 'ééxééx'.mb_chars.index('x', 4) + assert_nil @chars.index("u") + assert_equal 0, @chars.index("こに") + assert_equal 2, @chars.index("ち") + assert_equal 2, @chars.index("ち", -2) + assert_equal nil, @chars.index("ち", -1) + assert_equal 3, @chars.index("わ") + assert_equal 5, "ééxééx".mb_chars.index("x", 4) end def test_rindex_should_return_character_offset - assert_nil @chars.rindex('u') - assert_equal 1, @chars.rindex('に') - assert_equal 2, @chars.rindex('ち', -2) - assert_nil @chars.rindex('ち', -3) - assert_equal 6, 'Café périferôl'.mb_chars.rindex('é') - assert_equal 13, 'Café périferôl'.mb_chars.rindex(/\w/u) + assert_nil @chars.rindex("u") + assert_equal 1, @chars.rindex("に") + assert_equal 2, @chars.rindex("ち", -2) + assert_nil @chars.rindex("ち", -3) + assert_equal 6, "Café périferôl".mb_chars.rindex("é") + assert_equal 13, "Café périferôl".mb_chars.rindex(/\w/u) end def test_indexed_insert_should_take_character_offsets - @chars[2] = 'a' - assert_equal 'こにaわ', @chars - @chars[2] = 'ηη' - assert_equal 'こにηηわ', @chars - @chars[3, 2] = 'λλλ' - assert_equal 'こにηλλλ', @chars + @chars[2] = "a" + assert_equal "こにaわ", @chars + @chars[2] = "ηη" + assert_equal "こにηηわ", @chars + @chars[3, 2] = "λλλ" + assert_equal "こにηλλλ", @chars @chars[1, 0] = "λ" - assert_equal 'こλにηλλλ', @chars + assert_equal "こλにηλλλ", @chars @chars[4..6] = "ηη" - assert_equal 'こλにηηη', @chars + assert_equal "こλにηηη", @chars @chars[/ηη/] = "λλλ" - assert_equal 'こλにλλλη', @chars + assert_equal "こλにλλλη", @chars @chars[/(λλ)(.)/, 2] = "α" - assert_equal 'こλにλλαη', @chars + assert_equal "こλにλλαη", @chars @chars["α"] = "¢" - assert_equal 'こλにλλ¢η', @chars + assert_equal "こλにλλ¢η", @chars @chars["λλ"] = "ααα" - assert_equal 'こλにααα¢η', @chars + assert_equal "こλにααα¢η", @chars end def test_indexed_insert_should_raise_on_index_overflow before = @chars.to_s - assert_raise(IndexError) { @chars[10] = 'a' } - assert_raise(IndexError) { @chars[10, 4] = 'a' } - assert_raise(IndexError) { @chars[/ii/] = 'a' } - assert_raise(IndexError) { @chars[/()/, 10] = 'a' } + assert_raise(IndexError) { @chars[10] = "a" } + assert_raise(IndexError) { @chars[10, 4] = "a" } + assert_raise(IndexError) { @chars[/ii/] = "a" } + assert_raise(IndexError) { @chars[/()/, 10] = "a" } assert_equal before, @chars end def test_indexed_insert_should_raise_on_range_overflow before = @chars.to_s - assert_raise(RangeError) { @chars[10..12] = 'a' } + assert_raise(RangeError) { @chars[10..12] = "a" } assert_equal before, @chars end def test_rjust_should_raise_argument_errors_on_bad_arguments - assert_raise(ArgumentError) { @chars.rjust(10, '') } + assert_raise(ArgumentError) { @chars.rjust(10, "") } assert_raise(ArgumentError) { @chars.rjust } end @@ -292,15 +292,15 @@ class MultibyteCharsUTF8BehaviourTest < ActiveSupport::TestCase assert_equal UNICODE_STRING, @chars.rjust(4) assert_equal " #{UNICODE_STRING}", @chars.rjust(5) assert_equal " #{UNICODE_STRING}", @chars.rjust(7) - assert_equal "---#{UNICODE_STRING}", @chars.rjust(7, '-') - assert_equal "ααα#{UNICODE_STRING}", @chars.rjust(7, 'α') - assert_equal "aba#{UNICODE_STRING}", @chars.rjust(7, 'ab') - assert_equal "αηα#{UNICODE_STRING}", @chars.rjust(7, 'αη') - assert_equal "αηαη#{UNICODE_STRING}", @chars.rjust(8, 'αη') + assert_equal "---#{UNICODE_STRING}", @chars.rjust(7, "-") + assert_equal "ααα#{UNICODE_STRING}", @chars.rjust(7, "α") + assert_equal "aba#{UNICODE_STRING}", @chars.rjust(7, "ab") + assert_equal "αηα#{UNICODE_STRING}", @chars.rjust(7, "αη") + assert_equal "αηαη#{UNICODE_STRING}", @chars.rjust(8, "αη") end def test_ljust_should_raise_argument_errors_on_bad_arguments - assert_raise(ArgumentError) { @chars.ljust(10, '') } + assert_raise(ArgumentError) { @chars.ljust(10, "") } assert_raise(ArgumentError) { @chars.ljust } end @@ -310,15 +310,15 @@ class MultibyteCharsUTF8BehaviourTest < ActiveSupport::TestCase assert_equal UNICODE_STRING, @chars.ljust(4) assert_equal "#{UNICODE_STRING} ", @chars.ljust(5) assert_equal "#{UNICODE_STRING} ", @chars.ljust(7) - assert_equal "#{UNICODE_STRING}---", @chars.ljust(7, '-') - assert_equal "#{UNICODE_STRING}ααα", @chars.ljust(7, 'α') - assert_equal "#{UNICODE_STRING}aba", @chars.ljust(7, 'ab') - assert_equal "#{UNICODE_STRING}αηα", @chars.ljust(7, 'αη') - assert_equal "#{UNICODE_STRING}αηαη", @chars.ljust(8, 'αη') + assert_equal "#{UNICODE_STRING}---", @chars.ljust(7, "-") + assert_equal "#{UNICODE_STRING}ααα", @chars.ljust(7, "α") + assert_equal "#{UNICODE_STRING}aba", @chars.ljust(7, "ab") + assert_equal "#{UNICODE_STRING}αηα", @chars.ljust(7, "αη") + assert_equal "#{UNICODE_STRING}αηαη", @chars.ljust(8, "αη") end def test_center_should_raise_argument_errors_on_bad_arguments - assert_raise(ArgumentError) { @chars.center(10, '') } + assert_raise(ArgumentError) { @chars.center(10, "") } assert_raise(ArgumentError) { @chars.center } end @@ -329,15 +329,15 @@ class MultibyteCharsUTF8BehaviourTest < ActiveSupport::TestCase assert_equal "#{UNICODE_STRING} ", @chars.center(5) assert_equal " #{UNICODE_STRING} ", @chars.center(6) assert_equal " #{UNICODE_STRING} ", @chars.center(7) - assert_equal "--#{UNICODE_STRING}--", @chars.center(8, '-') - assert_equal "--#{UNICODE_STRING}---", @chars.center(9, '-') - assert_equal "αα#{UNICODE_STRING}αα", @chars.center(8, 'α') - assert_equal "αα#{UNICODE_STRING}ααα", @chars.center(9, 'α') - assert_equal "a#{UNICODE_STRING}ab", @chars.center(7, 'ab') - assert_equal "ab#{UNICODE_STRING}ab", @chars.center(8, 'ab') - assert_equal "abab#{UNICODE_STRING}abab", @chars.center(12, 'ab') - assert_equal "α#{UNICODE_STRING}αη", @chars.center(7, 'αη') - assert_equal "αη#{UNICODE_STRING}αη", @chars.center(8, 'αη') + assert_equal "--#{UNICODE_STRING}--", @chars.center(8, "-") + assert_equal "--#{UNICODE_STRING}---", @chars.center(9, "-") + assert_equal "αα#{UNICODE_STRING}αα", @chars.center(8, "α") + assert_equal "αα#{UNICODE_STRING}ααα", @chars.center(9, "α") + assert_equal "a#{UNICODE_STRING}ab", @chars.center(7, "ab") + assert_equal "ab#{UNICODE_STRING}ab", @chars.center(8, "ab") + assert_equal "abab#{UNICODE_STRING}abab", @chars.center(12, "ab") + assert_equal "α#{UNICODE_STRING}αη", @chars.center(7, "αη") + assert_equal "αη#{UNICODE_STRING}αη", @chars.center(8, "αη") end def test_lstrip_strips_whitespace_from_the_left_of_the_string @@ -367,20 +367,20 @@ class MultibyteCharsUTF8BehaviourTest < ActiveSupport::TestCase end def test_size_returns_characters_instead_of_bytes - assert_equal 0, ''.mb_chars.size + assert_equal 0, "".mb_chars.size assert_equal 4, @chars.size assert_equal 4, @chars.length assert_equal 5, ASCII_STRING.mb_chars.size end def test_reverse_reverses_characters - assert_equal '', ''.mb_chars.reverse - assert_equal 'わちにこ', @chars.reverse + assert_equal "", "".mb_chars.reverse + assert_equal "わちにこ", @chars.reverse end def test_reverse_should_work_with_normalized_strings - str = 'bös' - reversed_str = 'söb' + str = "bös" + reversed_str = "söb" assert_equal chars(reversed_str).normalize(:kc), chars(str).normalize(:kc).reverse assert_equal chars(reversed_str).normalize(:c), chars(str).normalize(:c).reverse assert_equal chars(reversed_str).normalize(:d), chars(str).normalize(:d).reverse @@ -390,27 +390,27 @@ class MultibyteCharsUTF8BehaviourTest < ActiveSupport::TestCase end def test_slice_should_take_character_offsets - assert_equal nil, ''.mb_chars.slice(0) - assert_equal 'こ', @chars.slice(0) - assert_equal 'わ', @chars.slice(3) - assert_equal nil, ''.mb_chars.slice(-1..1) - assert_equal nil, ''.mb_chars.slice(-1, 1) - assert_equal '', ''.mb_chars.slice(0..10) - assert_equal 'にちわ', @chars.slice(1..3) - assert_equal 'にちわ', @chars.slice(1, 3) - assert_equal 'こ', @chars.slice(0, 1) - assert_equal 'ちわ', @chars.slice(2..10) - assert_equal '', @chars.slice(4..10) - assert_equal 'に', @chars.slice(/に/u) - assert_equal 'にち', @chars.slice(/に./u) + assert_equal nil, "".mb_chars.slice(0) + assert_equal "こ", @chars.slice(0) + assert_equal "わ", @chars.slice(3) + assert_equal nil, "".mb_chars.slice(-1..1) + assert_equal nil, "".mb_chars.slice(-1, 1) + assert_equal "", "".mb_chars.slice(0..10) + assert_equal "にちわ", @chars.slice(1..3) + assert_equal "にちわ", @chars.slice(1, 3) + assert_equal "こ", @chars.slice(0, 1) + assert_equal "ちわ", @chars.slice(2..10) + assert_equal "", @chars.slice(4..10) + assert_equal "に", @chars.slice(/に/u) + assert_equal "にち", @chars.slice(/に./u) assert_equal nil, @chars.slice(/unknown/u) - assert_equal 'にち', @chars.slice(/(にち)/u, 1) + assert_equal "にち", @chars.slice(/(にち)/u, 1) assert_equal nil, @chars.slice(/(にち)/u, 2) assert_equal nil, @chars.slice(7..6) end def test_slice_bang_returns_sliced_out_substring - assert_equal 'にち', @chars.slice!(1..2) + assert_equal "にち", @chars.slice!(1..2) end def test_slice_bang_returns_nil_on_out_of_bound_arguments @@ -418,17 +418,17 @@ class MultibyteCharsUTF8BehaviourTest < ActiveSupport::TestCase end def test_slice_bang_removes_the_slice_from_the_receiver - chars = 'úüù'.mb_chars + chars = "úüù".mb_chars chars.slice!(0,2) - assert_equal 'ù', chars + assert_equal "ù", chars end def test_slice_bang_returns_nil_and_does_not_modify_receiver_if_out_of_bounds - string = 'úüù' + string = "úüù" chars = string.mb_chars assert_nil chars.slice!(4, 5) - assert_equal 'úüù', chars - assert_equal 'úüù', string + assert_equal "úüù", chars + assert_equal "úüù", string end def test_slice_should_throw_exceptions_on_invalid_arguments @@ -442,48 +442,48 @@ class MultibyteCharsUTF8BehaviourTest < ActiveSupport::TestCase end def test_upcase_should_upcase_ascii_characters - assert_equal '', ''.mb_chars.upcase - assert_equal 'ABC', 'aBc'.mb_chars.upcase + assert_equal "", "".mb_chars.upcase + assert_equal "ABC", "aBc".mb_chars.upcase end def test_downcase_should_downcase_ascii_characters - assert_equal '', ''.mb_chars.downcase - assert_equal 'abc', 'aBc'.mb_chars.downcase + assert_equal "", "".mb_chars.downcase + assert_equal "abc", "aBc".mb_chars.downcase end def test_swapcase_should_swap_ascii_characters - assert_equal '', ''.mb_chars.swapcase - assert_equal 'AbC', 'aBc'.mb_chars.swapcase + assert_equal "", "".mb_chars.swapcase + assert_equal "AbC", "aBc".mb_chars.swapcase end def test_capitalize_should_work_on_ascii_characters - assert_equal '', ''.mb_chars.capitalize - assert_equal 'Abc', 'abc'.mb_chars.capitalize + assert_equal "", "".mb_chars.capitalize + assert_equal "Abc", "abc".mb_chars.capitalize end def test_titleize_should_work_on_ascii_characters - assert_equal '', ''.mb_chars.titleize - assert_equal 'Abc Abc', 'abc abc'.mb_chars.titleize + assert_equal "", "".mb_chars.titleize + assert_equal "Abc Abc", "abc abc".mb_chars.titleize end def test_respond_to_knows_which_methods_the_proxy_responds_to - assert ''.mb_chars.respond_to?(:slice) # Defined on Chars - assert ''.mb_chars.respond_to?(:capitalize!) # Defined on Chars - assert ''.mb_chars.respond_to?(:gsub) # Defined on String - assert !''.mb_chars.respond_to?(:undefined_method) # Not defined + assert "".mb_chars.respond_to?(:slice) # Defined on Chars + assert "".mb_chars.respond_to?(:capitalize!) # Defined on Chars + assert "".mb_chars.respond_to?(:gsub) # Defined on String + assert !"".mb_chars.respond_to?(:undefined_method) # Not defined end def test_method_works_for_proxyed_methods - assert_equal 'll', 'hello'.mb_chars.method(:slice).call(2..3) # Defined on Chars - chars = 'hello'.mb_chars - assert_equal 'Hello', chars.method(:capitalize!).call # Defined on Chars - assert_equal 'Hello', chars - assert_equal 'jello', 'hello'.mb_chars.method(:gsub).call(/h/, 'j') # Defined on String - assert_raise(NameError){ ''.mb_chars.method(:undefined_method) } # Not defined + assert_equal "ll", "hello".mb_chars.method(:slice).call(2..3) # Defined on Chars + chars = "hello".mb_chars + assert_equal "Hello", chars.method(:capitalize!).call # Defined on Chars + assert_equal "Hello", chars + assert_equal "jello", "hello".mb_chars.method(:gsub).call(/h/, "j") # Defined on String + assert_raise(NameError) { "".mb_chars.method(:undefined_method) } # Not defined end def test_acts_like_string - assert 'Bambi'.mb_chars.acts_like_string? + assert "Bambi".mb_chars.acts_like_string? end end @@ -495,25 +495,25 @@ class MultibyteCharsExtrasTest < ActiveSupport::TestCase def test_upcase_should_be_unicode_aware assert_equal "АБВГД\0F", chars("аБвгд\0f").upcase - assert_equal 'こにちわ', chars('こにちわ').upcase + assert_equal "こにちわ", chars("こにちわ").upcase end def test_downcase_should_be_unicode_aware assert_equal "абвгд\0f", chars("аБвгд\0F").downcase - assert_equal 'こにちわ', chars('こにちわ').downcase + assert_equal "こにちわ", chars("こにちわ").downcase end def test_swapcase_should_be_unicode_aware assert_equal "аaéÜ\0f", chars("АAÉü\0F").swapcase - assert_equal 'こにちわ', chars('こにちわ').swapcase + assert_equal "こにちわ", chars("こにちわ").swapcase end def test_capitalize_should_be_unicode_aware - { 'аБвг аБвг' => 'Абвг абвг', - 'аБвг АБВГ' => 'Абвг абвг', - 'АБВГ АБВГ' => 'Абвг абвг', - '' => '' }.each do |f,t| - assert_equal t, chars(f).capitalize + { "аБвг аБвг" => "Абвг абвг", + "аБвг АБВГ" => "Абвг абвг", + "АБВГ АБВГ" => "Абвг абвг", + "" => "" }.each do |f,t| + assert_equal t, chars(f).capitalize end end @@ -527,7 +527,7 @@ class MultibyteCharsExtrasTest < ActiveSupport::TestCase end def test_limit_should_not_break_on_blank_strings - example = chars('') + example = chars("") assert_equal example, example.limit(0) assert_equal example, example.limit(1) end @@ -537,23 +537,23 @@ class MultibyteCharsExtrasTest < ActiveSupport::TestCase bytesize = UNICODE_STRING.bytesize assert_equal UNICODE_STRING, example.limit(bytesize) - assert_equal '', example.limit(0) - assert_equal '', example.limit(1) - assert_equal 'こ', example.limit(3) - assert_equal 'こに', example.limit(6) - assert_equal 'こに', example.limit(8) - assert_equal 'こにち', example.limit(9) - assert_equal 'こにちわ', example.limit(50) + assert_equal "", example.limit(0) + assert_equal "", example.limit(1) + assert_equal "こ", example.limit(3) + assert_equal "こに", example.limit(6) + assert_equal "こに", example.limit(8) + assert_equal "こにち", example.limit(9) + assert_equal "こにちわ", example.limit(50) end def test_limit_should_work_on_an_ascii_string ascii = chars(ASCII_STRING) assert_equal ASCII_STRING, ascii.limit(ASCII_STRING.length) - assert_equal '', ascii.limit(0) - assert_equal 'o', ascii.limit(1) - assert_equal 'oh', ascii.limit(2) - assert_equal 'ohay', ascii.limit(4) - assert_equal 'ohayo', ascii.limit(50) + assert_equal "", ascii.limit(0) + assert_equal "o", ascii.limit(1) + assert_equal "oh", ascii.limit(2) + assert_equal "ohay", ascii.limit(4) + assert_equal "ohayo", ascii.limit(50) end def test_limit_should_keep_under_the_specified_byte_limit @@ -565,7 +565,7 @@ class MultibyteCharsExtrasTest < ActiveSupport::TestCase def test_composition_exclusion_is_set_up_properly # Normalization of DEVANAGARI LETTER QA breaks when composition exclusion isn't used correctly - qa = [0x915, 0x93c].pack('U*') + qa = [0x915, 0x93c].pack("U*") assert_equal qa, chars(qa).normalize(:c) end @@ -575,7 +575,7 @@ class MultibyteCharsExtrasTest < ActiveSupport::TestCase [ [0x0B47, 0x0300, 0x0B3E], [0x1100, 0x0300, 0x1161] - ].map { |c| c.pack('U*') }.each do |c| + ].map { |c| c.pack("U*") }.each do |c| assert_equal_codepoints c, chars(c).normalize(:c) end end @@ -599,7 +599,7 @@ class MultibyteCharsExtrasTest < ActiveSupport::TestCase 323 # COMBINING DOT BELOW ].pack("U*") - assert_equal_codepoints '', chars('').normalize + assert_equal_codepoints "", chars("").normalize assert_equal_codepoints [44,105,106,328,323].pack("U*"), chars(comp_str).normalize(:kc).to_s assert_equal_codepoints [44,307,328,323].pack("U*"), chars(comp_str).normalize(:c).to_s assert_equal_codepoints [44,307,110,780,78,769].pack("U*"), chars(comp_str).normalize(:d).to_s @@ -608,10 +608,10 @@ class MultibyteCharsExtrasTest < ActiveSupport::TestCase def test_should_compute_grapheme_length [ - ['', 0], - ['abc', 3], - ['こにちわ', 4], - [[0x0924, 0x094D, 0x0930].pack('U*'), 2], + ["", 0], + ["abc", 3], + ["こにちわ", 4], + [[0x0924, 0x094D, 0x0930].pack("U*"), 2], # GB3 [%w(cr lf), 1], # GB4 @@ -699,9 +699,9 @@ class MultibyteCharsExtrasTest < ActiveSupport::TestCase end byte_string = "\270\236\010\210\245" - tidy_string = [0xb8, 0x17e, 0x8, 0x2c6, 0xa5].pack('U*') + tidy_string = [0xb8, 0x17e, 0x8, 0x2c6, 0xa5].pack("U*") assert_equal_codepoints tidy_string, chars(byte_string).tidy_bytes - assert_nothing_raised { chars(byte_string).tidy_bytes.to_s.unpack('U*') } + assert_nothing_raised { chars(byte_string).tidy_bytes.to_s.unpack("U*") } # UTF-8 leading byte followed by too few continuation bytes assert_equal_codepoints "\xc3\xb0\xc2\xa5\xc2\xa4\x21", chars("\xf0\xa5\xa4\x21").tidy_bytes @@ -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/multibyte_conformance_test.rb b/activesupport/test/multibyte_conformance_test.rb index 50ec6442ff..bf004d7924 100644 --- a/activesupport/test/multibyte_conformance_test.rb +++ b/activesupport/test/multibyte_conformance_test.rb @@ -1,14 +1,14 @@ -require 'abstract_unit' -require 'multibyte_test_helpers' +require "abstract_unit" +require "multibyte_test_helpers" -require 'fileutils' -require 'open-uri' -require 'tmpdir' +require "fileutils" +require "open-uri" +require "tmpdir" class MultibyteConformanceTest < ActiveSupport::TestCase include MultibyteTestHelpers - UNIDATA_FILE = '/NormalizationTest.txt' + UNIDATA_FILE = "/NormalizationTest.txt" FileUtils.mkdir_p(CACHE_DIR) RUN_P = begin Downloader.download(UNIDATA_URL + UNIDATA_FILE, CACHE_DIR + UNIDATA_FILE) @@ -84,17 +84,17 @@ class MultibyteConformanceTest < ActiveSupport::TestCase protected def each_line_of_norm_tests(&block) - File.open(File.join(CACHE_DIR, UNIDATA_FILE), 'r') do | f | + File.open(File.join(CACHE_DIR, UNIDATA_FILE), "r") do | f | until f.eof? line = f.gets.chomp! - next if line.empty? || line.start_with?('#') + next if line.empty? || line.start_with?("#") cols, comment = line.split("#") cols = cols.split(";").map(&:strip).reject(&:empty?) next unless cols.length == 5 # codepoints are in hex in the test suite, pack wants them as integers - cols.map!{|c| c.split.map{|codepoint| codepoint.to_i(16)}.pack("U*") } + cols.map! { |c| c.split.map { |codepoint| codepoint.to_i(16) }.pack("U*") } cols << comment yield(*cols) @@ -103,6 +103,6 @@ class MultibyteConformanceTest < ActiveSupport::TestCase end def inspect_codepoints(str) - str.to_s.unpack("U*").map{|cp| cp.to_s(16) }.join(' ') + str.to_s.unpack("U*").map { |cp| cp.to_s(16) }.join(" ") end end diff --git a/activesupport/test/multibyte_grapheme_break_conformance_test.rb b/activesupport/test/multibyte_grapheme_break_conformance_test.rb index 1d52a56971..5dc42df08d 100644 --- a/activesupport/test/multibyte_grapheme_break_conformance_test.rb +++ b/activesupport/test/multibyte_grapheme_break_conformance_test.rb @@ -1,16 +1,16 @@ # encoding: utf-8 -require 'abstract_unit' -require 'multibyte_test_helpers' +require "abstract_unit" +require "multibyte_test_helpers" -require 'fileutils' -require 'open-uri' -require 'tmpdir' +require "fileutils" +require "open-uri" +require "tmpdir" class MultibyteGraphemeBreakConformanceTest < ActiveSupport::TestCase include MultibyteTestHelpers - UNIDATA_FILE = '/auxiliary/GraphemeBreakTest.txt' + UNIDATA_FILE = "/auxiliary/GraphemeBreakTest.txt" RUN_P = begin Downloader.download(UNIDATA_URL + UNIDATA_FILE, CACHE_DIR + UNIDATA_FILE) rescue @@ -32,20 +32,20 @@ class MultibyteGraphemeBreakConformanceTest < ActiveSupport::TestCase def each_line_of_break_tests(&block) lines = 0 max_test_lines = 0 # Don't limit below 21, because that's the header of the testfile - File.open(File.join(CACHE_DIR, UNIDATA_FILE), 'r') do | f | + File.open(File.join(CACHE_DIR, UNIDATA_FILE), "r") do | f | until f.eof? || (max_test_lines > 21 and lines > max_test_lines) lines += 1 line = f.gets.chomp! - next if line.empty? || line.start_with?('#') + next if line.empty? || line.start_with?("#") cols, comment = line.split("#") # Cluster breaks are represented by ÷ - clusters = cols.split("÷").map{|e| e.strip}.reject{|e| e.empty? } + clusters = cols.split("÷").map { |e| e.strip }.reject { |e| e.empty? } clusters = clusters.map do |cluster| # Codepoints within each cluster are separated by × - codepoints = cluster.split("×").map{|e| e.strip}.reject{|e| e.empty? } + codepoints = cluster.split("×").map { |e| e.strip }.reject { |e| e.empty? } # codepoints are in hex in the test suite, pack wants them as integers - codepoints.map{|codepoint| codepoint.to_i(16)} + codepoints.map { |codepoint| codepoint.to_i(16) } end # The tests contain a solitary U+D800 <Non Private Use High diff --git a/activesupport/test/multibyte_normalization_conformance_test.rb b/activesupport/test/multibyte_normalization_conformance_test.rb index 4b940a2054..716e6487aa 100644 --- a/activesupport/test/multibyte_normalization_conformance_test.rb +++ b/activesupport/test/multibyte_normalization_conformance_test.rb @@ -1,16 +1,16 @@ # encoding: utf-8 -require 'abstract_unit' -require 'multibyte_test_helpers' +require "abstract_unit" +require "multibyte_test_helpers" -require 'fileutils' -require 'open-uri' -require 'tmpdir' +require "fileutils" +require "open-uri" +require "tmpdir" class MultibyteNormalizationConformanceTest < ActiveSupport::TestCase include MultibyteTestHelpers - UNIDATA_FILE = '/NormalizationTest.txt' + UNIDATA_FILE = "/NormalizationTest.txt" RUN_P = begin Downloader.download(UNIDATA_URL + UNIDATA_FILE, CACHE_DIR + UNIDATA_FILE) rescue @@ -87,18 +87,18 @@ class MultibyteNormalizationConformanceTest < ActiveSupport::TestCase def each_line_of_norm_tests(&block) lines = 0 max_test_lines = 0 # Don't limit below 38, because that's the header of the testfile - File.open(File.join(CACHE_DIR, UNIDATA_FILE), 'r') do | f | + File.open(File.join(CACHE_DIR, UNIDATA_FILE), "r") do | f | until f.eof? || (max_test_lines > 38 and lines > max_test_lines) lines += 1 line = f.gets.chomp! - next if line.empty? || line.start_with?('#') + next if line.empty? || line.start_with?("#") cols, comment = line.split("#") - cols = cols.split(";").map{|e| e.strip}.reject{|e| e.empty? } + cols = cols.split(";").map { |e| e.strip }.reject { |e| e.empty? } next unless cols.length == 5 # codepoints are in hex in the test suite, pack wants them as integers - cols.map!{|c| c.split.map{|codepoint| codepoint.to_i(16)}.pack("U*") } + cols.map! { |c| c.split.map { |codepoint| codepoint.to_i(16) }.pack("U*") } cols << comment yield(*cols) @@ -107,6 +107,6 @@ class MultibyteNormalizationConformanceTest < ActiveSupport::TestCase end def inspect_codepoints(str) - str.to_s.unpack("U*").map{|cp| cp.to_s(16) }.join(' ') + str.to_s.unpack("U*").map { |cp| cp.to_s(16) }.join(" ") end end diff --git a/activesupport/test/multibyte_proxy_test.rb b/activesupport/test/multibyte_proxy_test.rb index 360cf57302..c303097f80 100644 --- a/activesupport/test/multibyte_proxy_test.rb +++ b/activesupport/test/multibyte_proxy_test.rb @@ -1,4 +1,4 @@ -require 'abstract_unit' +require "abstract_unit" class MultibyteProxyText < ActiveSupport::TestCase class AsciiOnlyEncoder @@ -6,7 +6,7 @@ class MultibyteProxyText < ActiveSupport::TestCase alias to_s wrapped_string def initialize(string) - @wrapped_string = string.gsub(/[^\u0000-\u007F]/, '?') + @wrapped_string = string.gsub(/[^\u0000-\u007F]/, "?") end end diff --git a/activesupport/test/multibyte_test_helpers.rb b/activesupport/test/multibyte_test_helpers.rb index 0ada8bc032..22c586c50d 100644 --- a/activesupport/test/multibyte_test_helpers.rb +++ b/activesupport/test/multibyte_test_helpers.rb @@ -6,7 +6,7 @@ module MultibyteTestHelpers system "mkdir -p #{File.dirname(to)}" end open(from) do |source| - File.open(to, 'w') do |target| + File.open(to, "w") do |target| source.each_line do |l| target.write l end @@ -21,8 +21,8 @@ module MultibyteTestHelpers CACHE_DIR = "#{Dir.tmpdir}/cache/unicode_conformance" FileUtils.mkdir_p(CACHE_DIR) - UNICODE_STRING = 'こにちわ'.freeze - ASCII_STRING = 'ohayo'.freeze + UNICODE_STRING = "こにちわ".freeze + ASCII_STRING = "ohayo".freeze BYTE_STRING = "\270\236\010\210\245".force_encoding("ASCII-8BIT").freeze def chars(str) @@ -30,7 +30,7 @@ module MultibyteTestHelpers end def inspect_codepoints(str) - str.to_s.unpack("U*").map{|cp| cp.to_s(16) }.join(' ') + str.to_s.unpack("U*").map { |cp| cp.to_s(16) }.join(" ") end def assert_equal_codepoints(expected, actual, message=nil) diff --git a/activesupport/test/multibyte_unicode_database_test.rb b/activesupport/test/multibyte_unicode_database_test.rb index dd33641ec2..3724782930 100644 --- a/activesupport/test/multibyte_unicode_database_test.rb +++ b/activesupport/test/multibyte_unicode_database_test.rb @@ -1,8 +1,6 @@ -require 'abstract_unit' - +require "abstract_unit" class MultibyteUnicodeDatabaseTest < ActiveSupport::TestCase - include ActiveSupport::Multibyte::Unicode def setup diff --git a/activesupport/test/notifications/evented_notification_test.rb b/activesupport/test/notifications/evented_notification_test.rb index f690ad43fc..688971c858 100644 --- a/activesupport/test/notifications/evented_notification_test.rb +++ b/activesupport/test/notifications/evented_notification_test.rb @@ -1,4 +1,4 @@ -require 'abstract_unit' +require "abstract_unit" module ActiveSupport module Notifications @@ -28,26 +28,26 @@ module ActiveSupport def test_evented_listener notifier = Fanout.new listener = Listener.new - notifier.subscribe 'hi', listener - notifier.start 'hi', 1, {} - notifier.start 'hi', 2, {} - notifier.finish 'hi', 2, {} - notifier.finish 'hi', 1, {} + notifier.subscribe "hi", listener + notifier.start "hi", 1, {} + notifier.start "hi", 2, {} + notifier.finish "hi", 2, {} + notifier.finish "hi", 1, {} assert_equal 4, listener.events.length assert_equal [ - [:start, 'hi', 1, {}], - [:start, 'hi', 2, {}], - [:finish, 'hi', 2, {}], - [:finish, 'hi', 1, {}], + [:start, "hi", 1, {}], + [:start, "hi", 2, {}], + [:finish, "hi", 2, {}], + [:finish, "hi", 1, {}], ], listener.events end def test_evented_listener_no_events notifier = Fanout.new listener = Listener.new - notifier.subscribe 'hi', listener - notifier.start 'world', 1, {} + notifier.subscribe "hi", listener + notifier.start "world", 1, {} assert_equal 0, listener.events.length end @@ -55,31 +55,31 @@ module ActiveSupport notifier = Fanout.new listener = Listener.new notifier.subscribe nil, listener - notifier.start 'hello', 1, {} - notifier.start 'world', 1, {} - notifier.finish 'world', 1, {} - notifier.finish 'hello', 1, {} + notifier.start "hello", 1, {} + notifier.start "world", 1, {} + notifier.finish "world", 1, {} + notifier.finish "hello", 1, {} assert_equal 4, listener.events.length assert_equal [ - [:start, 'hello', 1, {}], - [:start, 'world', 1, {}], - [:finish, 'world', 1, {}], - [:finish, 'hello', 1, {}], + [:start, "hello", 1, {}], + [:start, "world", 1, {}], + [:finish, "world", 1, {}], + [:finish, "hello", 1, {}], ], listener.events end def test_evented_listener_priority notifier = Fanout.new listener = ListenerWithTimedSupport.new - notifier.subscribe 'hi', listener + notifier.subscribe "hi", listener - notifier.start 'hi', 1, {} - notifier.finish 'hi', 1, {} + notifier.start "hi", 1, {} + notifier.finish "hi", 1, {} assert_equal [ - [:start, 'hi', 1, {}], - [:finish, 'hi', 1, {}] + [:start, "hi", 1, {}], + [:finish, "hi", 1, {}] ], listener.events end end diff --git a/activesupport/test/notifications/instrumenter_test.rb b/activesupport/test/notifications/instrumenter_test.rb index f46e96f636..e454e6897b 100644 --- a/activesupport/test/notifications/instrumenter_test.rb +++ b/activesupport/test/notifications/instrumenter_test.rb @@ -1,5 +1,5 @@ -require 'abstract_unit' -require 'active_support/notifications/instrumenter' +require "abstract_unit" +require "active_support/notifications/instrumenter" module ActiveSupport module Notifications @@ -22,7 +22,7 @@ module ActiveSupport super @notifier = TestNotifier.new @instrumenter = Instrumenter.new @notifier - @payload = { :foo => Object.new } + @payload = { foo: Object.new } end def test_instrument @@ -39,7 +39,7 @@ module ActiveSupport assert_equal 1, notifier.finishes.size name, _, payload = notifier.finishes.first assert_equal "awesome", name - assert_equal Hash[:result => 2], payload + assert_equal Hash[result: 2], payload end def test_start diff --git a/activesupport/test/notifications_test.rb b/activesupport/test/notifications_test.rb index 1cb17e6197..a6f0d82e8a 100644 --- a/activesupport/test/notifications_test.rb +++ b/activesupport/test/notifications_test.rb @@ -1,5 +1,5 @@ -require 'abstract_unit' -require 'active_support/core_ext/module/delegation' +require "abstract_unit" +require "active_support/core_ext/module/delegation" module Notifications class TestCase < ActiveSupport::TestCase @@ -31,7 +31,7 @@ module Notifications expected = [name, name] events = [] - callback = lambda {|*_| events << _.first} + callback = lambda { |*_| events << _.first } ActiveSupport::Notifications.subscribed(callback, name) do ActiveSupport::Notifications.instrument(name) ActiveSupport::Notifications.instrument(name2) @@ -49,10 +49,10 @@ module Notifications old_notifier = ActiveSupport::Notifications.notifier ActiveSupport::Notifications.notifier = ActiveSupport::Notifications::Fanout.new - ActiveSupport::Notifications.subscribe('foo', TestSubscriber.new) + ActiveSupport::Notifications.subscribe("foo", TestSubscriber.new) - ActiveSupport::Notifications.instrument('foo') do - ActiveSupport::Notifications.subscribe('foo') {} + ActiveSupport::Notifications.instrument("foo") do + ActiveSupport::Notifications.subscribe("foo") {} end ensure ActiveSupport::Notifications.notifier = old_notifier @@ -141,26 +141,26 @@ module Notifications def test_log_subscriber_with_string events = [] - @notifier.subscribe('1') { |*args| events << args } + @notifier.subscribe("1") { |*args| events << args } - @notifier.publish '1' - @notifier.publish '1.a' - @notifier.publish 'a.1' + @notifier.publish "1" + @notifier.publish "1.a" + @notifier.publish "a.1" @notifier.wait - assert_equal [['1']], events + assert_equal [["1"]], events end def test_log_subscriber_with_pattern events = [] @notifier.subscribe(/\d/) { |*args| events << args } - @notifier.publish '1' - @notifier.publish 'a.1' - @notifier.publish '1.a' + @notifier.publish "1" + @notifier.publish "a.1" + @notifier.publish "1.a" @notifier.wait - assert_equal [['1'], ['a.1'], ['1.a']], events + assert_equal [["1"], ["a.1"], ["1.a"]], events end def test_multiple_log_subscribers @@ -188,7 +188,7 @@ module Notifications end class InstrumentationTest < TestCase - delegate :instrument, :to => ActiveSupport::Notifications + delegate :instrument, to: ActiveSupport::Notifications def test_instrument_returns_block_result assert_equal 2, instrument(:awesome) { 1 + 1 } @@ -198,7 +198,7 @@ module Notifications assert_equal 2, instrument(:awesome) { |p| p[:result] = 1 + 1 } assert_equal 1, @events.size assert_equal :awesome, @events.first.name - assert_equal Hash[:result => 2], @events.first.payload + assert_equal Hash[result: 2], @events.first.payload end def test_instrumenter_exposes_its_id @@ -206,24 +206,24 @@ module Notifications end def test_nested_events_can_be_instrumented - instrument(:awesome, :payload => "notifications") do - instrument(:wot, :payload => "child") do + instrument(:awesome, payload: "notifications") do + instrument(:wot, payload: "child") do 1 + 1 end assert_equal 1, @events.size assert_equal :wot, @events.first.name - assert_equal Hash[:payload => "child"], @events.first.payload + assert_equal Hash[payload: "child"], @events.first.payload end assert_equal 2, @events.size assert_equal :awesome, @events.last.name - assert_equal Hash[:payload => "notifications"], @events.last.payload + assert_equal Hash[payload: "notifications"], @events.last.payload end def test_instrument_publishes_when_exception_is_raised begin - instrument(:awesome, :payload => "notifications") do + instrument(:awesome, payload: "notifications") do raise "FAIL" end rescue RuntimeError => e @@ -231,15 +231,15 @@ module Notifications end assert_equal 1, @events.size - assert_equal Hash[:payload => "notifications", - :exception => ["RuntimeError", "FAIL"], :exception_object => e], @events.last.payload + assert_equal Hash[payload: "notifications", + exception: ["RuntimeError", "FAIL"], exception_object: e], @events.last.payload end def test_event_is_pushed_even_without_block - instrument(:awesome, :payload => "notifications") + instrument(:awesome, payload: "notifications") assert_equal 1, @events.size assert_equal :awesome, @events.last.name - assert_equal Hash[:payload => "notifications"], @events.last.payload + assert_equal Hash[payload: "notifications"], @events.last.payload end end @@ -254,8 +254,8 @@ module Notifications end def test_events_consumes_information_given_as_payload - event = event(:foo, Time.now, Time.now + 1, random_id, :payload => :bar) - assert_equal Hash[:payload => :bar], event.payload + event = event(:foo, Time.now, Time.now + 1, random_id, payload: :bar) + assert_equal Hash[payload: :bar], event.payload end def test_event_is_parent_based_on_children diff --git a/activesupport/test/number_helper_i18n_test.rb b/activesupport/test/number_helper_i18n_test.rb index e6925e9083..4f58e6607a 100644 --- a/activesupport/test/number_helper_i18n_test.rb +++ b/activesupport/test/number_helper_i18n_test.rb @@ -1,46 +1,46 @@ -require 'abstract_unit' -require 'active_support/number_helper' +require "abstract_unit" +require "active_support/number_helper" module ActiveSupport class NumberHelperI18nTest < ActiveSupport::TestCase include ActiveSupport::NumberHelper def setup - I18n.backend.store_translations 'ts', - :number => { - :format => { :precision => 3, :delimiter => ',', :separator => '.', :significant => false, :strip_insignificant_zeros => false }, - :currency => { :format => { :unit => '&$', :format => '%u - %n', :negative_format => '(%u - %n)', :precision => 2 } }, - :human => { - :format => { - :precision => 2, - :significant => true, - :strip_insignificant_zeros => true + I18n.backend.store_translations "ts", + number: { + format: { precision: 3, delimiter: ",", separator: ".", significant: false, strip_insignificant_zeros: false }, + currency: { format: { unit: "&$", format: "%u - %n", negative_format: "(%u - %n)", precision: 2 } }, + human: { + format: { + precision: 2, + significant: true, + strip_insignificant_zeros: true }, - :storage_units => { - :format => "%n %u", - :units => { - :byte => "b", - :kb => "k" + storage_units: { + format: "%n %u", + units: { + byte: "b", + kb: "k" } }, - :decimal_units => { - :format => "%n %u", - :units => { - :deci => {:one => "Tenth", :other => "Tenths"}, - :unit => "u", - :ten => {:one => "Ten", :other => "Tens"}, - :thousand => "t", - :million => "m", - :billion =>"b", - :trillion =>"t" , - :quadrillion =>"q" + decimal_units: { + format: "%n %u", + units: { + deci: { one: "Tenth", other: "Tenths" }, + unit: "u", + ten: { one: "Ten", other: "Tens" }, + thousand: "t", + million: "m", + billion: "b", + trillion: "t" , + quadrillion: "q" } } }, - :percentage => { :format => {:delimiter => '', :precision => 2, :strip_insignificant_zeros => true} }, - :precision => { :format => {:delimiter => '', :significant => true} } + percentage: { format: { delimiter: "", precision: 2, strip_insignificant_zeros: true } }, + precision: { format: { delimiter: "", significant: true } } }, - :custom_units_for_number_to_human => {:mili => "mm", :centi => "cm", :deci => "dm", :unit => "m", :ten => "dam", :hundred => "hm", :thousand => "km"} + custom_units_for_number_to_human: { mili: "mm", centi: "cm", deci: "dm", unit: "m", ten: "dam", hundred: "hm", thousand: "km" } end def teardown @@ -48,101 +48,101 @@ module ActiveSupport end def test_number_to_i18n_currency - assert_equal("&$ - 10.00", number_to_currency(10, :locale => 'ts')) - assert_equal("(&$ - 10.00)", number_to_currency(-10, :locale => 'ts')) - assert_equal("-10.00 - &$", number_to_currency(-10, :locale => 'ts', :format => "%n - %u")) + assert_equal("&$ - 10.00", number_to_currency(10, locale: "ts")) + assert_equal("(&$ - 10.00)", number_to_currency(-10, locale: "ts")) + assert_equal("-10.00 - &$", number_to_currency(-10, locale: "ts", format: "%n - %u")) end def test_number_to_currency_with_empty_i18n_store - assert_equal("$10.00", number_to_currency(10, :locale => 'empty')) - assert_equal("-$10.00", number_to_currency(-10, :locale => 'empty')) + assert_equal("$10.00", number_to_currency(10, locale: "empty")) + assert_equal("-$10.00", number_to_currency(-10, locale: "empty")) end def test_locale_default_format_has_precedence_over_helper_defaults - I18n.backend.store_translations 'ts', - { :number => { :format => { :separator => ";" } } } + I18n.backend.store_translations "ts", + number: { format: { separator: ";" } } - assert_equal("&$ - 10;00", number_to_currency(10, :locale => 'ts')) + assert_equal("&$ - 10;00", number_to_currency(10, locale: "ts")) end def test_number_to_currency_without_currency_negative_format - I18n.backend.store_translations 'no_negative_format', :number => { - :currency => { :format => { :unit => '@', :format => '%n %u' } } + I18n.backend.store_translations "no_negative_format", number: { + currency: { format: { unit: "@", format: "%n %u" } } } - assert_equal("-10.00 @", number_to_currency(-10, :locale => 'no_negative_format')) + assert_equal("-10.00 @", number_to_currency(-10, locale: "no_negative_format")) end def test_number_with_i18n_precision #Delimiter was set to "" - assert_equal("10000", number_to_rounded(10000, :locale => 'ts')) + assert_equal("10000", number_to_rounded(10000, locale: "ts")) #Precision inherited and significant was set - assert_equal("1.00", number_to_rounded(1.0, :locale => 'ts')) + assert_equal("1.00", number_to_rounded(1.0, locale: "ts")) end def test_number_with_i18n_precision_and_empty_i18n_store - assert_equal("123456789.123", number_to_rounded(123456789.123456789, :locale => 'empty')) - assert_equal("1.000", number_to_rounded(1.0000, :locale => 'empty')) + assert_equal("123456789.123", number_to_rounded(123456789.123456789, locale: "empty")) + assert_equal("1.000", number_to_rounded(1.0000, locale: "empty")) end def test_number_with_i18n_delimiter #Delimiter "," and separator "." - assert_equal("1,000,000.234", number_to_delimited(1000000.234, :locale => 'ts')) + assert_equal("1,000,000.234", number_to_delimited(1000000.234, locale: "ts")) end def test_number_with_i18n_delimiter_and_empty_i18n_store - assert_equal("1,000,000.234", number_to_delimited(1000000.234, :locale => 'empty')) + assert_equal("1,000,000.234", number_to_delimited(1000000.234, locale: "empty")) end def test_number_to_i18n_percentage # to see if strip_insignificant_zeros is true - assert_equal("1%", number_to_percentage(1, :locale => 'ts')) + assert_equal("1%", number_to_percentage(1, locale: "ts")) # precision is 2, significant should be inherited - assert_equal("1.24%", number_to_percentage(1.2434, :locale => 'ts')) + assert_equal("1.24%", number_to_percentage(1.2434, locale: "ts")) # no delimiter - assert_equal("12434%", number_to_percentage(12434, :locale => 'ts')) + assert_equal("12434%", number_to_percentage(12434, locale: "ts")) end def test_number_to_i18n_percentage_and_empty_i18n_store - assert_equal("1.000%", number_to_percentage(1, :locale => 'empty')) - assert_equal("1.243%", number_to_percentage(1.2434, :locale => 'empty')) - assert_equal("12434.000%", number_to_percentage(12434, :locale => 'empty')) + assert_equal("1.000%", number_to_percentage(1, locale: "empty")) + assert_equal("1.243%", number_to_percentage(1.2434, locale: "empty")) + assert_equal("12434.000%", number_to_percentage(12434, locale: "empty")) end def test_number_to_i18n_human_size #b for bytes and k for kbytes - assert_equal("2 k", number_to_human_size(2048, :locale => 'ts')) - assert_equal("42 b", number_to_human_size(42, :locale => 'ts')) + assert_equal("2 k", number_to_human_size(2048, locale: "ts")) + assert_equal("42 b", number_to_human_size(42, locale: "ts")) end def test_number_to_i18n_human_size_with_empty_i18n_store - assert_equal("2 KB", number_to_human_size(2048, :locale => 'empty')) - assert_equal("42 Bytes", number_to_human_size(42, :locale => 'empty')) + assert_equal("2 KB", number_to_human_size(2048, locale: "empty")) + assert_equal("42 Bytes", number_to_human_size(42, locale: "empty")) end def test_number_to_human_with_default_translation_scope #Using t for thousand - assert_equal "2 t", number_to_human(2000, :locale => 'ts') + assert_equal "2 t", number_to_human(2000, locale: "ts") #Significant was set to true with precision 2, using b for billion - assert_equal "1.2 b", number_to_human(1234567890, :locale => 'ts') + assert_equal "1.2 b", number_to_human(1234567890, locale: "ts") #Using pluralization (Ten/Tens and Tenth/Tenths) - assert_equal "1 Tenth", number_to_human(0.1, :locale => 'ts') - assert_equal "1.3 Tenth", number_to_human(0.134, :locale => 'ts') - assert_equal "2 Tenths", number_to_human(0.2, :locale => 'ts') - assert_equal "1 Ten", number_to_human(10, :locale => 'ts') - assert_equal "1.2 Ten", number_to_human(12, :locale => 'ts') - assert_equal "2 Tens", number_to_human(20, :locale => 'ts') + assert_equal "1 Tenth", number_to_human(0.1, locale: "ts") + assert_equal "1.3 Tenth", number_to_human(0.134, locale: "ts") + assert_equal "2 Tenths", number_to_human(0.2, locale: "ts") + assert_equal "1 Ten", number_to_human(10, locale: "ts") + assert_equal "1.2 Ten", number_to_human(12, locale: "ts") + assert_equal "2 Tens", number_to_human(20, locale: "ts") end def test_number_to_human_with_empty_i18n_store - assert_equal "2 Thousand", number_to_human(2000, :locale => 'empty') - assert_equal "1.23 Billion", number_to_human(1234567890, :locale => 'empty') + assert_equal "2 Thousand", number_to_human(2000, locale: "empty") + assert_equal "1.23 Billion", number_to_human(1234567890, locale: "empty") end def test_number_to_human_with_custom_translation_scope #Significant was set to true with precision 2, with custom translated units - assert_equal "4.3 cm", number_to_human(0.0432, :locale => 'ts', :units => :custom_units_for_number_to_human) + assert_equal "4.3 cm", number_to_human(0.0432, locale: "ts", units: :custom_units_for_number_to_human) end end end diff --git a/activesupport/test/number_helper_test.rb b/activesupport/test/number_helper_test.rb index 074c872efc..1a59210018 100644 --- a/activesupport/test/number_helper_test.rb +++ b/activesupport/test/number_helper_test.rb @@ -1,11 +1,10 @@ -require 'abstract_unit' -require 'active_support/number_helper' -require 'active_support/core_ext/string/output_safety' +require "abstract_unit" +require "active_support/number_helper" +require "active_support/core_ext/string/output_safety" module ActiveSupport module NumberHelper class NumberHelperTest < ActiveSupport::TestCase - class TestClassWithInstanceNumberHelpers include ActiveSupport::NumberHelper end @@ -46,17 +45,17 @@ module ActiveSupport [@instance_with_helpers, TestClassWithClassNumberHelpers, ActiveSupport::NumberHelper].each do |number_helper| assert_equal("555-1234", number_helper.number_to_phone(5551234)) assert_equal("800-555-1212", number_helper.number_to_phone(8005551212)) - assert_equal("(800) 555-1212", number_helper.number_to_phone(8005551212, {:area_code => true})) - assert_equal("", number_helper.number_to_phone("", {:area_code => true})) - assert_equal("800 555 1212", number_helper.number_to_phone(8005551212, {:delimiter => " "})) - assert_equal("(800) 555-1212 x 123", number_helper.number_to_phone(8005551212, {:area_code => true, :extension => 123})) - assert_equal("800-555-1212", number_helper.number_to_phone(8005551212, :extension => " ")) - assert_equal("555.1212", number_helper.number_to_phone(5551212, :delimiter => '.')) + assert_equal("(800) 555-1212", number_helper.number_to_phone(8005551212, area_code: true)) + assert_equal("", number_helper.number_to_phone("", area_code: true)) + assert_equal("800 555 1212", number_helper.number_to_phone(8005551212, delimiter: " ")) + assert_equal("(800) 555-1212 x 123", number_helper.number_to_phone(8005551212, area_code: true, extension: 123)) + assert_equal("800-555-1212", number_helper.number_to_phone(8005551212, extension: " ")) + assert_equal("555.1212", number_helper.number_to_phone(5551212, delimiter: ".")) assert_equal("800-555-1212", number_helper.number_to_phone("8005551212")) - assert_equal("+1-800-555-1212", number_helper.number_to_phone(8005551212, :country_code => 1)) - assert_equal("+18005551212", number_helper.number_to_phone(8005551212, :country_code => 1, :delimiter => '')) + assert_equal("+1-800-555-1212", number_helper.number_to_phone(8005551212, country_code: 1)) + assert_equal("+18005551212", number_helper.number_to_phone(8005551212, country_code: 1, delimiter: "")) assert_equal("22-555-1212", number_helper.number_to_phone(225551212)) - assert_equal("+45-22-555-1212", number_helper.number_to_phone(225551212, :country_code => 45)) + assert_equal("+45-22-555-1212", number_helper.number_to_phone(225551212, country_code: 45)) assert_equal("(755) 6123-4567", number_helper.number_to_phone(75561234567, pattern: /(\d{3,4})(\d{4})(\d{4})/, area_code: true)) assert_equal("133-1234-5678", number_helper.number_to_phone(13312345678, pattern: /(\d{3})(\d{4})(\d{4})/)) end @@ -67,28 +66,28 @@ module ActiveSupport assert_equal("$1,234,567,890.50", number_helper.number_to_currency(1234567890.50)) assert_equal("$1,234,567,890.51", number_helper.number_to_currency(1234567890.506)) assert_equal("-$1,234,567,890.50", number_helper.number_to_currency(-1234567890.50)) - assert_equal("-$ 1,234,567,890.50", number_helper.number_to_currency(-1234567890.50, {:format => "%u %n"})) - assert_equal("($1,234,567,890.50)", number_helper.number_to_currency(-1234567890.50, {:negative_format => "(%u%n)"})) - assert_equal("$1,234,567,892", number_helper.number_to_currency(1234567891.50, {:precision => 0})) - assert_equal("$1,234,567,890.5", number_helper.number_to_currency(1234567890.50, {:precision => 1})) - assert_equal("£1234567890,50", number_helper.number_to_currency(1234567890.50, {:unit => "£", :separator => ",", :delimiter => ""})) + assert_equal("-$ 1,234,567,890.50", number_helper.number_to_currency(-1234567890.50, format: "%u %n")) + assert_equal("($1,234,567,890.50)", number_helper.number_to_currency(-1234567890.50, negative_format: "(%u%n)")) + assert_equal("$1,234,567,892", number_helper.number_to_currency(1234567891.50, precision: 0)) + assert_equal("$1,234,567,890.5", number_helper.number_to_currency(1234567890.50, precision: 1)) + assert_equal("£1234567890,50", number_helper.number_to_currency(1234567890.50, unit: "£", separator: ",", delimiter: "")) assert_equal("$1,234,567,890.50", number_helper.number_to_currency("1234567890.50")) - assert_equal("1,234,567,890.50 Kč", number_helper.number_to_currency("1234567890.50", {:unit => "Kč", :format => "%n %u"})) - assert_equal("1,234,567,890.50 - Kč", number_helper.number_to_currency("-1234567890.50", {:unit => "Kč", :format => "%n %u", :negative_format => "%n - %u"})) - assert_equal("0.00", number_helper.number_to_currency(+0.0, {:unit => "", :negative_format => "(%n)"})) + assert_equal("1,234,567,890.50 Kč", number_helper.number_to_currency("1234567890.50", unit: "Kč", format: "%n %u")) + assert_equal("1,234,567,890.50 - Kč", number_helper.number_to_currency("-1234567890.50", unit: "Kč", format: "%n %u", negative_format: "%n - %u")) + assert_equal("0.00", number_helper.number_to_currency(+0.0, unit: "", negative_format: "(%n)")) end end def test_number_to_percentage [@instance_with_helpers, TestClassWithClassNumberHelpers, ActiveSupport::NumberHelper].each do |number_helper| assert_equal("100.000%", number_helper.number_to_percentage(100)) - assert_equal("100%", number_helper.number_to_percentage(100, {:precision => 0})) - assert_equal("302.06%", number_helper.number_to_percentage(302.0574, {:precision => 2})) + assert_equal("100%", number_helper.number_to_percentage(100, precision: 0)) + assert_equal("302.06%", number_helper.number_to_percentage(302.0574, precision: 2)) assert_equal("100.000%", number_helper.number_to_percentage("100")) assert_equal("1000.000%", number_helper.number_to_percentage("1000")) - assert_equal("123.4%", number_helper.number_to_percentage(123.400, :precision => 3, :strip_insignificant_zeros => true)) - assert_equal("1.000,000%", number_helper.number_to_percentage(1000, :delimiter => '.', :separator => ',')) - assert_equal("1000.000 %", number_helper.number_to_percentage(1000, :format => "%n %")) + assert_equal("123.4%", number_helper.number_to_percentage(123.400, precision: 3, strip_insignificant_zeros: true)) + assert_equal("1.000,000%", number_helper.number_to_percentage(1000, delimiter: ".", separator: ",")) + assert_equal("1000.000 %", number_helper.number_to_percentage(1000, format: "%n %")) assert_equal("98a%", number_helper.number_to_percentage("98a")) assert_equal("NaN%", number_helper.number_to_percentage(Float::NAN)) assert_equal("Inf%", number_helper.number_to_percentage(Float::INFINITY)) @@ -122,9 +121,9 @@ module ActiveSupport def test_to_delimited_with_options_hash [@instance_with_helpers, TestClassWithClassNumberHelpers, ActiveSupport::NumberHelper].each do |number_helper| - assert_equal '12 345 678', number_helper.number_to_delimited(12345678, :delimiter => ' ') - assert_equal '12,345,678-05', number_helper.number_to_delimited(12345678.05, :separator => '-') - assert_equal '12.345.678,05', number_helper.number_to_delimited(12345678.05, :separator => ',', :delimiter => '.') + assert_equal "12 345 678", number_helper.number_to_delimited(12345678, delimiter: " ") + assert_equal "12,345,678-05", number_helper.number_to_delimited(12345678.05, separator: "-") + assert_equal "12.345.678,05", number_helper.number_to_delimited(12345678.05, separator: ",", delimiter: ".") end end @@ -132,77 +131,77 @@ module ActiveSupport [@instance_with_helpers, TestClassWithClassNumberHelpers, ActiveSupport::NumberHelper].each do |number_helper| assert_equal("-111.235", number_helper.number_to_rounded(-111.2346)) assert_equal("111.235", number_helper.number_to_rounded(111.2346)) - assert_equal("31.83", number_helper.number_to_rounded(31.825, :precision => 2)) - assert_equal("111.23", number_helper.number_to_rounded(111.2346, :precision => 2)) - assert_equal("111.00", number_helper.number_to_rounded(111, :precision => 2)) + assert_equal("31.83", number_helper.number_to_rounded(31.825, precision: 2)) + assert_equal("111.23", number_helper.number_to_rounded(111.2346, precision: 2)) + assert_equal("111.00", number_helper.number_to_rounded(111, precision: 2)) assert_equal("111.235", number_helper.number_to_rounded("111.2346")) - assert_equal("31.83", number_helper.number_to_rounded("31.825", :precision => 2)) - assert_equal("3268", number_helper.number_to_rounded((32.6751 * 100.00), :precision => 0)) - assert_equal("112", number_helper.number_to_rounded(111.50, :precision => 0)) - assert_equal("1234567892", number_helper.number_to_rounded(1234567891.50, :precision => 0)) - assert_equal("0", number_helper.number_to_rounded(0, :precision => 0)) - assert_equal("0.00100", number_helper.number_to_rounded(0.001, :precision => 5)) - assert_equal("0.001", number_helper.number_to_rounded(0.00111, :precision => 3)) - assert_equal("10.00", number_helper.number_to_rounded(9.995, :precision => 2)) - assert_equal("11.00", number_helper.number_to_rounded(10.995, :precision => 2)) - assert_equal("0.00", number_helper.number_to_rounded(-0.001, :precision => 2)) - - assert_equal("111.23460000000000000000", number_helper.number_to_rounded(111.2346, :precision => 20)) - assert_equal("111.23460000000000000000", number_helper.number_to_rounded(Rational(1112346, 10000), :precision => 20)) - assert_equal("111.23460000000000000000", number_helper.number_to_rounded('111.2346', :precision => 20)) - assert_equal("111.23460000000000000000", number_helper.number_to_rounded(BigDecimal(111.2346, Float::DIG), :precision => 20)) - assert_equal("111.2346" + "0"*96, number_helper.number_to_rounded('111.2346', :precision => 100)) - assert_equal("111.2346", number_helper.number_to_rounded(Rational(1112346, 10000), :precision => 4)) - assert_equal('0.00', number_helper.number_to_rounded(Rational(0, 1), :precision => 2)) + assert_equal("31.83", number_helper.number_to_rounded("31.825", precision: 2)) + assert_equal("3268", number_helper.number_to_rounded((32.6751 * 100.00), precision: 0)) + assert_equal("112", number_helper.number_to_rounded(111.50, precision: 0)) + assert_equal("1234567892", number_helper.number_to_rounded(1234567891.50, precision: 0)) + assert_equal("0", number_helper.number_to_rounded(0, precision: 0)) + assert_equal("0.00100", number_helper.number_to_rounded(0.001, precision: 5)) + assert_equal("0.001", number_helper.number_to_rounded(0.00111, precision: 3)) + assert_equal("10.00", number_helper.number_to_rounded(9.995, precision: 2)) + assert_equal("11.00", number_helper.number_to_rounded(10.995, precision: 2)) + assert_equal("0.00", number_helper.number_to_rounded(-0.001, precision: 2)) + + assert_equal("111.23460000000000000000", number_helper.number_to_rounded(111.2346, precision: 20)) + assert_equal("111.23460000000000000000", number_helper.number_to_rounded(Rational(1112346, 10000), precision: 20)) + assert_equal("111.23460000000000000000", number_helper.number_to_rounded("111.2346", precision: 20)) + assert_equal("111.23460000000000000000", number_helper.number_to_rounded(BigDecimal(111.2346, Float::DIG), precision: 20)) + assert_equal("111.2346" + "0"*96, number_helper.number_to_rounded("111.2346", precision: 100)) + assert_equal("111.2346", number_helper.number_to_rounded(Rational(1112346, 10000), precision: 4)) + assert_equal("0.00", number_helper.number_to_rounded(Rational(0, 1), precision: 2)) end end def test_to_rounded_with_custom_delimiter_and_separator [@instance_with_helpers, TestClassWithClassNumberHelpers, ActiveSupport::NumberHelper].each do |number_helper| - assert_equal '31,83', number_helper.number_to_rounded(31.825, :precision => 2, :separator => ',') - assert_equal '1.231,83', number_helper.number_to_rounded(1231.825, :precision => 2, :separator => ',', :delimiter => '.') + assert_equal "31,83", number_helper.number_to_rounded(31.825, precision: 2, separator: ",") + assert_equal "1.231,83", number_helper.number_to_rounded(1231.825, precision: 2, separator: ",", delimiter: ".") end end def test_to_rounded_with_significant_digits [@instance_with_helpers, TestClassWithClassNumberHelpers, ActiveSupport::NumberHelper].each do |number_helper| - assert_equal "124000", number_helper.number_to_rounded(123987, :precision => 3, :significant => true) - assert_equal "120000000", number_helper.number_to_rounded(123987876, :precision => 2, :significant => true ) - assert_equal "40000", number_helper.number_to_rounded("43523", :precision => 1, :significant => true ) - assert_equal "9775", number_helper.number_to_rounded(9775, :precision => 4, :significant => true ) - assert_equal "5.4", number_helper.number_to_rounded(5.3923, :precision => 2, :significant => true ) - assert_equal "5", number_helper.number_to_rounded(5.3923, :precision => 1, :significant => true ) - assert_equal "1", number_helper.number_to_rounded(1.232, :precision => 1, :significant => true ) - assert_equal "7", number_helper.number_to_rounded(7, :precision => 1, :significant => true ) - assert_equal "1", number_helper.number_to_rounded(1, :precision => 1, :significant => true ) - assert_equal "53", number_helper.number_to_rounded(52.7923, :precision => 2, :significant => true ) - assert_equal "9775.00", number_helper.number_to_rounded(9775, :precision => 6, :significant => true ) - assert_equal "5.392900", number_helper.number_to_rounded(5.3929, :precision => 7, :significant => true ) - assert_equal "0.0", number_helper.number_to_rounded(0, :precision => 2, :significant => true ) - assert_equal "0", number_helper.number_to_rounded(0, :precision => 1, :significant => true ) - assert_equal "0.0001", number_helper.number_to_rounded(0.0001, :precision => 1, :significant => true ) - assert_equal "0.000100", number_helper.number_to_rounded(0.0001, :precision => 3, :significant => true ) - assert_equal "0.0001", number_helper.number_to_rounded(0.0001111, :precision => 1, :significant => true ) - assert_equal "10.0", number_helper.number_to_rounded(9.995, :precision => 3, :significant => true) - assert_equal "9.99", number_helper.number_to_rounded(9.994, :precision => 3, :significant => true) - assert_equal "11.0", number_helper.number_to_rounded(10.995, :precision => 3, :significant => true) - - assert_equal "9775.0000000000000000", number_helper.number_to_rounded(9775, :precision => 20, :significant => true ) - assert_equal "9775.0000000000000000", number_helper.number_to_rounded(9775.0, :precision => 20, :significant => true ) - assert_equal "9775.0000000000000000", number_helper.number_to_rounded(Rational(9775, 1), :precision => 20, :significant => true ) - assert_equal "97.750000000000000000", number_helper.number_to_rounded(Rational(9775, 100), :precision => 20, :significant => true ) - assert_equal "9775.0000000000000000", number_helper.number_to_rounded(BigDecimal(9775), :precision => 20, :significant => true ) - assert_equal "9775.0000000000000000", number_helper.number_to_rounded("9775", :precision => 20, :significant => true ) - assert_equal "9775." + "0"*96, number_helper.number_to_rounded("9775", :precision => 100, :significant => true ) - assert_equal("97.7", number_helper.number_to_rounded(Rational(9772, 100), :precision => 3, :significant => true)) + assert_equal "124000", number_helper.number_to_rounded(123987, precision: 3, significant: true) + assert_equal "120000000", number_helper.number_to_rounded(123987876, precision: 2, significant: true ) + assert_equal "40000", number_helper.number_to_rounded("43523", precision: 1, significant: true ) + assert_equal "9775", number_helper.number_to_rounded(9775, precision: 4, significant: true ) + assert_equal "5.4", number_helper.number_to_rounded(5.3923, precision: 2, significant: true ) + assert_equal "5", number_helper.number_to_rounded(5.3923, precision: 1, significant: true ) + assert_equal "1", number_helper.number_to_rounded(1.232, precision: 1, significant: true ) + assert_equal "7", number_helper.number_to_rounded(7, precision: 1, significant: true ) + assert_equal "1", number_helper.number_to_rounded(1, precision: 1, significant: true ) + assert_equal "53", number_helper.number_to_rounded(52.7923, precision: 2, significant: true ) + assert_equal "9775.00", number_helper.number_to_rounded(9775, precision: 6, significant: true ) + assert_equal "5.392900", number_helper.number_to_rounded(5.3929, precision: 7, significant: true ) + assert_equal "0.0", number_helper.number_to_rounded(0, precision: 2, significant: true ) + assert_equal "0", number_helper.number_to_rounded(0, precision: 1, significant: true ) + assert_equal "0.0001", number_helper.number_to_rounded(0.0001, precision: 1, significant: true ) + assert_equal "0.000100", number_helper.number_to_rounded(0.0001, precision: 3, significant: true ) + assert_equal "0.0001", number_helper.number_to_rounded(0.0001111, precision: 1, significant: true ) + assert_equal "10.0", number_helper.number_to_rounded(9.995, precision: 3, significant: true) + assert_equal "9.99", number_helper.number_to_rounded(9.994, precision: 3, significant: true) + assert_equal "11.0", number_helper.number_to_rounded(10.995, precision: 3, significant: true) + + assert_equal "9775.0000000000000000", number_helper.number_to_rounded(9775, precision: 20, significant: true ) + assert_equal "9775.0000000000000000", number_helper.number_to_rounded(9775.0, precision: 20, significant: true ) + assert_equal "9775.0000000000000000", number_helper.number_to_rounded(Rational(9775, 1), precision: 20, significant: true ) + assert_equal "97.750000000000000000", number_helper.number_to_rounded(Rational(9775, 100), precision: 20, significant: true ) + assert_equal "9775.0000000000000000", number_helper.number_to_rounded(BigDecimal(9775), precision: 20, significant: true ) + assert_equal "9775.0000000000000000", number_helper.number_to_rounded("9775", precision: 20, significant: true ) + assert_equal "9775." + "0"*96, number_helper.number_to_rounded("9775", precision: 100, significant: true ) + assert_equal("97.7", number_helper.number_to_rounded(Rational(9772, 100), precision: 3, significant: true)) end end def test_to_rounded_with_strip_insignificant_zeros [@instance_with_helpers, TestClassWithClassNumberHelpers, ActiveSupport::NumberHelper].each do |number_helper| - assert_equal "9775.43", number_helper.number_to_rounded(9775.43, :precision => 4, :strip_insignificant_zeros => true ) - assert_equal "9775.2", number_helper.number_to_rounded(9775.2, :precision => 6, :significant => true, :strip_insignificant_zeros => true ) - assert_equal "0", number_helper.number_to_rounded(0, :precision => 6, :significant => true, :strip_insignificant_zeros => true ) + assert_equal "9775.43", number_helper.number_to_rounded(9775.43, precision: 4, strip_insignificant_zeros: true ) + assert_equal "9775.2", number_helper.number_to_rounded(9775.2, precision: 6, significant: true, strip_insignificant_zeros: true ) + assert_equal "0", number_helper.number_to_rounded(0, precision: 6, significant: true, strip_insignificant_zeros: true ) end end @@ -210,156 +209,156 @@ module ActiveSupport [@instance_with_helpers, TestClassWithClassNumberHelpers, ActiveSupport::NumberHelper].each do |number_helper| # Zero precision with significant is a mistake (would always return zero), # so we treat it as if significant was false (increases backwards compatibility for number_to_human_size) - assert_equal "124", number_helper.number_to_rounded(123.987, :precision => 0, :significant => true) - assert_equal "12", number_helper.number_to_rounded(12, :precision => 0, :significant => true ) - assert_equal "12", number_helper.number_to_rounded("12.3", :precision => 0, :significant => true ) + assert_equal "124", number_helper.number_to_rounded(123.987, precision: 0, significant: true) + assert_equal "12", number_helper.number_to_rounded(12, precision: 0, significant: true ) + assert_equal "12", number_helper.number_to_rounded("12.3", precision: 0, significant: true ) end end def test_number_number_to_human_size [@instance_with_helpers, TestClassWithClassNumberHelpers, ActiveSupport::NumberHelper].each do |number_helper| - assert_equal '0 Bytes', number_helper.number_to_human_size(0) - assert_equal '1 Byte', number_helper.number_to_human_size(1) - assert_equal '3 Bytes', number_helper.number_to_human_size(3.14159265) - assert_equal '123 Bytes', number_helper.number_to_human_size(123.0) - assert_equal '123 Bytes', number_helper.number_to_human_size(123) - assert_equal '1.21 KB', number_helper.number_to_human_size(1234) - assert_equal '12.1 KB', number_helper.number_to_human_size(12345) - assert_equal '1.18 MB', number_helper.number_to_human_size(1234567) - assert_equal '1.15 GB', number_helper.number_to_human_size(1234567890) - assert_equal '1.12 TB', number_helper.number_to_human_size(1234567890123) - assert_equal '1.1 PB', number_helper.number_to_human_size(1234567890123456) - assert_equal '1.07 EB', number_helper.number_to_human_size(1234567890123456789) - assert_equal '1030 EB', number_helper.number_to_human_size(exabytes(1026)) - assert_equal '444 KB', number_helper.number_to_human_size(kilobytes(444)) - assert_equal '1020 MB', number_helper.number_to_human_size(megabytes(1023)) - assert_equal '3 TB', number_helper.number_to_human_size(terabytes(3)) - assert_equal '1.2 MB', number_helper.number_to_human_size(1234567, :precision => 2) - assert_equal '3 Bytes', number_helper.number_to_human_size(3.14159265, :precision => 4) - assert_equal '123 Bytes', number_helper.number_to_human_size('123') - assert_equal '1 KB', number_helper.number_to_human_size(kilobytes(1.0123), :precision => 2) - assert_equal '1.01 KB', number_helper.number_to_human_size(kilobytes(1.0100), :precision => 4) - assert_equal '10 KB', number_helper.number_to_human_size(kilobytes(10.000), :precision => 4) - assert_equal '1 Byte', number_helper.number_to_human_size(1.1) - assert_equal '10 Bytes', number_helper.number_to_human_size(10) + assert_equal "0 Bytes", number_helper.number_to_human_size(0) + assert_equal "1 Byte", number_helper.number_to_human_size(1) + assert_equal "3 Bytes", number_helper.number_to_human_size(3.14159265) + assert_equal "123 Bytes", number_helper.number_to_human_size(123.0) + assert_equal "123 Bytes", number_helper.number_to_human_size(123) + assert_equal "1.21 KB", number_helper.number_to_human_size(1234) + assert_equal "12.1 KB", number_helper.number_to_human_size(12345) + assert_equal "1.18 MB", number_helper.number_to_human_size(1234567) + assert_equal "1.15 GB", number_helper.number_to_human_size(1234567890) + assert_equal "1.12 TB", number_helper.number_to_human_size(1234567890123) + assert_equal "1.1 PB", number_helper.number_to_human_size(1234567890123456) + assert_equal "1.07 EB", number_helper.number_to_human_size(1234567890123456789) + assert_equal "1030 EB", number_helper.number_to_human_size(exabytes(1026)) + assert_equal "444 KB", number_helper.number_to_human_size(kilobytes(444)) + assert_equal "1020 MB", number_helper.number_to_human_size(megabytes(1023)) + assert_equal "3 TB", number_helper.number_to_human_size(terabytes(3)) + assert_equal "1.2 MB", number_helper.number_to_human_size(1234567, precision: 2) + assert_equal "3 Bytes", number_helper.number_to_human_size(3.14159265, precision: 4) + assert_equal "123 Bytes", number_helper.number_to_human_size("123") + assert_equal "1 KB", number_helper.number_to_human_size(kilobytes(1.0123), precision: 2) + assert_equal "1.01 KB", number_helper.number_to_human_size(kilobytes(1.0100), precision: 4) + assert_equal "10 KB", number_helper.number_to_human_size(kilobytes(10.000), precision: 4) + assert_equal "1 Byte", number_helper.number_to_human_size(1.1) + assert_equal "10 Bytes", number_helper.number_to_human_size(10) end end def test_number_to_human_size_with_si_prefix assert_deprecated do [@instance_with_helpers, TestClassWithClassNumberHelpers, ActiveSupport::NumberHelper].each do |number_helper| - assert_equal '3 Bytes', number_helper.number_to_human_size(3.14159265, :prefix => :si) - assert_equal '123 Bytes', number_helper.number_to_human_size(123.0, :prefix => :si) - assert_equal '123 Bytes', number_helper.number_to_human_size(123, :prefix => :si) - assert_equal '1.23 KB', number_helper.number_to_human_size(1234, :prefix => :si) - assert_equal '12.3 KB', number_helper.number_to_human_size(12345, :prefix => :si) - assert_equal '1.23 MB', number_helper.number_to_human_size(1234567, :prefix => :si) - assert_equal '1.23 GB', number_helper.number_to_human_size(1234567890, :prefix => :si) - assert_equal '1.23 TB', number_helper.number_to_human_size(1234567890123, :prefix => :si) - assert_equal '1.23 PB', number_helper.number_to_human_size(1234567890123456, :prefix => :si) - assert_equal '1.23 EB', number_helper.number_to_human_size(1234567890123456789, :prefix => :si) + assert_equal "3 Bytes", number_helper.number_to_human_size(3.14159265, prefix: :si) + assert_equal "123 Bytes", number_helper.number_to_human_size(123.0, prefix: :si) + assert_equal "123 Bytes", number_helper.number_to_human_size(123, prefix: :si) + assert_equal "1.23 KB", number_helper.number_to_human_size(1234, prefix: :si) + assert_equal "12.3 KB", number_helper.number_to_human_size(12345, prefix: :si) + assert_equal "1.23 MB", number_helper.number_to_human_size(1234567, prefix: :si) + assert_equal "1.23 GB", number_helper.number_to_human_size(1234567890, prefix: :si) + assert_equal "1.23 TB", number_helper.number_to_human_size(1234567890123, prefix: :si) + assert_equal "1.23 PB", number_helper.number_to_human_size(1234567890123456, prefix: :si) + assert_equal "1.23 EB", number_helper.number_to_human_size(1234567890123456789, prefix: :si) end end end def test_number_to_human_size_with_options_hash [@instance_with_helpers, TestClassWithClassNumberHelpers, ActiveSupport::NumberHelper].each do |number_helper| - assert_equal '1.2 MB', number_helper.number_to_human_size(1234567, :precision => 2) - assert_equal '3 Bytes', number_helper.number_to_human_size(3.14159265, :precision => 4) - assert_equal '1 KB', number_helper.number_to_human_size(kilobytes(1.0123), :precision => 2) - assert_equal '1.01 KB', number_helper.number_to_human_size(kilobytes(1.0100), :precision => 4) - assert_equal '10 KB', number_helper.number_to_human_size(kilobytes(10.000), :precision => 4) - assert_equal '1 TB', number_helper.number_to_human_size(1234567890123, :precision => 1) - assert_equal '500 MB', number_helper.number_to_human_size(524288000, :precision=>3) - assert_equal '10 MB', number_helper.number_to_human_size(9961472, :precision=>0) - assert_equal '40 KB', number_helper.number_to_human_size(41010, :precision => 1) - assert_equal '40 KB', number_helper.number_to_human_size(41100, :precision => 2) - assert_equal '1.0 KB', number_helper.number_to_human_size(kilobytes(1.0123), :precision => 2, :strip_insignificant_zeros => false) - assert_equal '1.012 KB', number_helper.number_to_human_size(kilobytes(1.0123), :precision => 3, :significant => false) - assert_equal '1 KB', number_helper.number_to_human_size(kilobytes(1.0123), :precision => 0, :significant => true) #ignores significant it precision is 0 + assert_equal "1.2 MB", number_helper.number_to_human_size(1234567, precision: 2) + assert_equal "3 Bytes", number_helper.number_to_human_size(3.14159265, precision: 4) + assert_equal "1 KB", number_helper.number_to_human_size(kilobytes(1.0123), precision: 2) + assert_equal "1.01 KB", number_helper.number_to_human_size(kilobytes(1.0100), precision: 4) + assert_equal "10 KB", number_helper.number_to_human_size(kilobytes(10.000), precision: 4) + assert_equal "1 TB", number_helper.number_to_human_size(1234567890123, precision: 1) + assert_equal "500 MB", number_helper.number_to_human_size(524288000, precision: 3) + assert_equal "10 MB", number_helper.number_to_human_size(9961472, precision: 0) + assert_equal "40 KB", number_helper.number_to_human_size(41010, precision: 1) + assert_equal "40 KB", number_helper.number_to_human_size(41100, precision: 2) + assert_equal "1.0 KB", number_helper.number_to_human_size(kilobytes(1.0123), precision: 2, strip_insignificant_zeros: false) + assert_equal "1.012 KB", number_helper.number_to_human_size(kilobytes(1.0123), precision: 3, significant: false) + assert_equal "1 KB", number_helper.number_to_human_size(kilobytes(1.0123), precision: 0, significant: true) #ignores significant it precision is 0 end end def test_number_to_human_size_with_custom_delimiter_and_separator [@instance_with_helpers, TestClassWithClassNumberHelpers, ActiveSupport::NumberHelper].each do |number_helper| - assert_equal '1,01 KB', number_helper.number_to_human_size(kilobytes(1.0123), :precision => 3, :separator => ',') - assert_equal '1,01 KB', number_helper.number_to_human_size(kilobytes(1.0100), :precision => 4, :separator => ',') - assert_equal '1.000,1 TB', number_helper.number_to_human_size(terabytes(1000.1), :precision => 5, :delimiter => '.', :separator => ',') + assert_equal "1,01 KB", number_helper.number_to_human_size(kilobytes(1.0123), precision: 3, separator: ",") + assert_equal "1,01 KB", number_helper.number_to_human_size(kilobytes(1.0100), precision: 4, separator: ",") + assert_equal "1.000,1 TB", number_helper.number_to_human_size(terabytes(1000.1), precision: 5, delimiter: ".", separator: ",") end end def test_number_to_human [@instance_with_helpers, TestClassWithClassNumberHelpers, ActiveSupport::NumberHelper].each do |number_helper| - assert_equal '-123', number_helper.number_to_human(-123) - assert_equal '-0.5', number_helper.number_to_human(-0.5) - assert_equal '0', number_helper.number_to_human(0) - assert_equal '0.5', number_helper.number_to_human(0.5) - assert_equal '123', number_helper.number_to_human(123) - assert_equal '1.23 Thousand', number_helper.number_to_human(1234) - assert_equal '12.3 Thousand', number_helper.number_to_human(12345) - assert_equal '1.23 Million', number_helper.number_to_human(1234567) - assert_equal '1.23 Billion', number_helper.number_to_human(1234567890) - assert_equal '1.23 Trillion', number_helper.number_to_human(1234567890123) - assert_equal '1.23 Quadrillion', number_helper.number_to_human(1234567890123456) - assert_equal '1230 Quadrillion', number_helper.number_to_human(1234567890123456789) - assert_equal '490 Thousand', number_helper.number_to_human(489939, :precision => 2) - assert_equal '489.9 Thousand', number_helper.number_to_human(489939, :precision => 4) - assert_equal '489 Thousand', number_helper.number_to_human(489000, :precision => 4) - assert_equal '489.0 Thousand', number_helper.number_to_human(489000, :precision => 4, :strip_insignificant_zeros => false) - assert_equal '1.2346 Million', number_helper.number_to_human(1234567, :precision => 4, :significant => false) - assert_equal '1,2 Million', number_helper.number_to_human(1234567, :precision => 1, :significant => false, :separator => ',') - assert_equal '1 Million', number_helper.number_to_human(1234567, :precision => 0, :significant => true, :separator => ',') #significant forced to false - assert_equal '1 Million', number_helper.number_to_human(999999) - assert_equal '1 Billion', number_helper.number_to_human(999999999) + assert_equal "-123", number_helper.number_to_human(-123) + assert_equal "-0.5", number_helper.number_to_human(-0.5) + assert_equal "0", number_helper.number_to_human(0) + assert_equal "0.5", number_helper.number_to_human(0.5) + assert_equal "123", number_helper.number_to_human(123) + assert_equal "1.23 Thousand", number_helper.number_to_human(1234) + assert_equal "12.3 Thousand", number_helper.number_to_human(12345) + assert_equal "1.23 Million", number_helper.number_to_human(1234567) + assert_equal "1.23 Billion", number_helper.number_to_human(1234567890) + assert_equal "1.23 Trillion", number_helper.number_to_human(1234567890123) + assert_equal "1.23 Quadrillion", number_helper.number_to_human(1234567890123456) + assert_equal "1230 Quadrillion", number_helper.number_to_human(1234567890123456789) + assert_equal "490 Thousand", number_helper.number_to_human(489939, precision: 2) + assert_equal "489.9 Thousand", number_helper.number_to_human(489939, precision: 4) + assert_equal "489 Thousand", number_helper.number_to_human(489000, precision: 4) + assert_equal "489.0 Thousand", number_helper.number_to_human(489000, precision: 4, strip_insignificant_zeros: false) + assert_equal "1.2346 Million", number_helper.number_to_human(1234567, precision: 4, significant: false) + assert_equal "1,2 Million", number_helper.number_to_human(1234567, precision: 1, significant: false, separator: ",") + assert_equal "1 Million", number_helper.number_to_human(1234567, precision: 0, significant: true, separator: ",") #significant forced to false + assert_equal "1 Million", number_helper.number_to_human(999999) + assert_equal "1 Billion", number_helper.number_to_human(999999999) end end def test_number_to_human_with_custom_units [@instance_with_helpers, TestClassWithClassNumberHelpers, ActiveSupport::NumberHelper].each do |number_helper| #Only integers - volume = {:unit => "ml", :thousand => "lt", :million => "m3"} - assert_equal '123 lt', number_helper.number_to_human(123456, :units => volume) - assert_equal '12 ml', number_helper.number_to_human(12, :units => volume) - assert_equal '1.23 m3', number_helper.number_to_human(1234567, :units => volume) + volume = { unit: "ml", thousand: "lt", million: "m3" } + assert_equal "123 lt", number_helper.number_to_human(123456, units: volume) + assert_equal "12 ml", number_helper.number_to_human(12, units: volume) + assert_equal "1.23 m3", number_helper.number_to_human(1234567, units: volume) #Including fractionals - distance = {:mili => "mm", :centi => "cm", :deci => "dm", :unit => "m", :ten => "dam", :hundred => "hm", :thousand => "km"} - assert_equal '1.23 mm', number_helper.number_to_human(0.00123, :units => distance) - assert_equal '1.23 cm', number_helper.number_to_human(0.0123, :units => distance) - assert_equal '1.23 dm', number_helper.number_to_human(0.123, :units => distance) - assert_equal '1.23 m', number_helper.number_to_human(1.23, :units => distance) - assert_equal '1.23 dam', number_helper.number_to_human(12.3, :units => distance) - assert_equal '1.23 hm', number_helper.number_to_human(123, :units => distance) - assert_equal '1.23 km', number_helper.number_to_human(1230, :units => distance) - assert_equal '1.23 km', number_helper.number_to_human(1230, :units => distance) - assert_equal '1.23 km', number_helper.number_to_human(1230, :units => distance) - assert_equal '12.3 km', number_helper.number_to_human(12300, :units => distance) + distance = { mili: "mm", centi: "cm", deci: "dm", unit: "m", ten: "dam", hundred: "hm", thousand: "km" } + assert_equal "1.23 mm", number_helper.number_to_human(0.00123, units: distance) + assert_equal "1.23 cm", number_helper.number_to_human(0.0123, units: distance) + assert_equal "1.23 dm", number_helper.number_to_human(0.123, units: distance) + assert_equal "1.23 m", number_helper.number_to_human(1.23, units: distance) + assert_equal "1.23 dam", number_helper.number_to_human(12.3, units: distance) + assert_equal "1.23 hm", number_helper.number_to_human(123, units: distance) + assert_equal "1.23 km", number_helper.number_to_human(1230, units: distance) + assert_equal "1.23 km", number_helper.number_to_human(1230, units: distance) + assert_equal "1.23 km", number_helper.number_to_human(1230, units: distance) + assert_equal "12.3 km", number_helper.number_to_human(12300, units: distance) #The quantifiers don't need to be a continuous sequence - gangster = {:hundred => "hundred bucks", :million => "thousand quids"} - assert_equal '1 hundred bucks', number_helper.number_to_human(100, :units => gangster) - assert_equal '25 hundred bucks', number_helper.number_to_human(2500, :units => gangster) - assert_equal '25 thousand quids', number_helper.number_to_human(25000000, :units => gangster) - assert_equal '12300 thousand quids', number_helper.number_to_human(12345000000, :units => gangster) + gangster = { hundred: "hundred bucks", million: "thousand quids" } + assert_equal "1 hundred bucks", number_helper.number_to_human(100, units: gangster) + assert_equal "25 hundred bucks", number_helper.number_to_human(2500, units: gangster) + assert_equal "25 thousand quids", number_helper.number_to_human(25000000, units: gangster) + assert_equal "12300 thousand quids", number_helper.number_to_human(12345000000, units: gangster) #Spaces are stripped from the resulting string - assert_equal '4', number_helper.number_to_human(4, :units => {:unit => "", :ten => 'tens '}) - assert_equal '4.5 tens', number_helper.number_to_human(45, :units => {:unit => "", :ten => ' tens '}) + assert_equal "4", number_helper.number_to_human(4, units: { unit: "", ten: "tens " }) + assert_equal "4.5 tens", number_helper.number_to_human(45, units: { unit: "", ten: " tens " }) end end def test_number_to_human_with_custom_units_that_are_missing_the_needed_key [@instance_with_helpers, TestClassWithClassNumberHelpers, ActiveSupport::NumberHelper].each do |number_helper| - assert_equal '123', number_helper.number_to_human(123, units: { thousand: 'k'}) - assert_equal '123', number_helper.number_to_human(123, units: {}) + assert_equal "123", number_helper.number_to_human(123, units: { thousand: "k" }) + assert_equal "123", number_helper.number_to_human(123, units: {}) end end def test_number_to_human_with_custom_format [@instance_with_helpers, TestClassWithClassNumberHelpers, ActiveSupport::NumberHelper].each do |number_helper| - assert_equal '123 times Thousand', number_helper.number_to_human(123456, :format => "%n times %u") - volume = {:unit => "ml", :thousand => "lt", :million => "m3"} - assert_equal '123.lt', number_helper.number_to_human(123456, :units => volume, :format => "%n.%u") + assert_equal "123 times Thousand", number_helper.number_to_human(123456, format: "%n times %u") + volume = { unit: "ml", thousand: "lt", million: "m3" } + assert_equal "123.lt", number_helper.number_to_human(123456, units: volume, format: "%n.%u") end end @@ -377,34 +376,34 @@ module ActiveSupport def test_number_helpers_do_not_mutate_options_hash [@instance_with_helpers, TestClassWithClassNumberHelpers, ActiveSupport::NumberHelper].each do |number_helper| - options = { 'raise' => true } + options = { "raise" => true } number_helper.number_to_phone(1, options) - assert_equal({ 'raise' => true }, options) + assert_equal({ "raise" => true }, options) number_helper.number_to_currency(1, options) - assert_equal({ 'raise' => true }, options) + assert_equal({ "raise" => true }, options) number_helper.number_to_percentage(1, options) - assert_equal({ 'raise' => true }, options) + assert_equal({ "raise" => true }, options) number_helper.number_to_delimited(1, options) - assert_equal({ 'raise' => true }, options) + assert_equal({ "raise" => true }, options) number_helper.number_to_rounded(1, options) - assert_equal({ 'raise' => true }, options) + assert_equal({ "raise" => true }, options) number_helper.number_to_human_size(1, options) - assert_equal({ 'raise' => true }, options) + assert_equal({ "raise" => true }, options) number_helper.number_to_human(1, options) - assert_equal({ 'raise' => true }, options) + assert_equal({ "raise" => true }, options) end end def test_number_helpers_should_return_non_numeric_param_unchanged [@instance_with_helpers, TestClassWithClassNumberHelpers, ActiveSupport::NumberHelper].each do |number_helper| - assert_equal("+1-x x 123", number_helper.number_to_phone("x", :country_code => 1, :extension => 123)) + assert_equal("+1-x x 123", number_helper.number_to_phone("x", country_code: 1, extension: 123)) assert_equal("x", number_helper.number_to_phone("x")) assert_equal("$x.", number_helper.number_to_currency("x.")) assert_equal("$x", number_helper.number_to_currency("x")) @@ -412,11 +411,10 @@ module ActiveSupport assert_equal("x", number_helper.number_to_delimited("x")) assert_equal("x.", number_helper.number_to_rounded("x.")) assert_equal("x", number_helper.number_to_rounded("x")) - assert_equal "x", number_helper.number_to_human_size('x') - assert_equal "x", number_helper.number_to_human('x') + assert_equal "x", number_helper.number_to_human_size("x") + assert_equal "x", number_helper.number_to_human("x") end end - end end end diff --git a/activesupport/test/option_merger_test.rb b/activesupport/test/option_merger_test.rb index 4c0364e68b..c5a6d304ee 100644 --- a/activesupport/test/option_merger_test.rb +++ b/activesupport/test/option_merger_test.rb @@ -1,13 +1,13 @@ -require 'abstract_unit' -require 'active_support/core_ext/object/with_options' +require "abstract_unit" +require "active_support/core_ext/object/with_options" class OptionMergerTest < ActiveSupport::TestCase def setup - @options = {:hello => 'world'} + @options = { hello: "world" } end def test_method_with_options_merges_options_when_options_are_present - local_options = {:cool => true} + local_options = { cool: true } with_options(@options) do |o| assert_equal local_options, method_with_options(local_options) @@ -24,7 +24,7 @@ class OptionMergerTest < ActiveSupport::TestCase end def test_method_with_options_allows_to_overwrite_options - local_options = {:hello => 'moon'} + local_options = { hello: "moon" } assert_equal @options.keys, local_options.keys with_options(@options) do |o| @@ -40,34 +40,34 @@ class OptionMergerTest < ActiveSupport::TestCase end def test_nested_method_with_options_containing_hashes_merge - with_options :conditions => { :method => :get } do |outer| - outer.with_options :conditions => { :domain => "www" } do |inner| - expected = { :conditions => { :method => :get, :domain => "www" } } + with_options conditions: { method: :get } do |outer| + outer.with_options conditions: { domain: "www" } do |inner| + expected = { conditions: { method: :get, domain: "www" } } assert_equal expected, inner.method_with_options end end end def test_nested_method_with_options_containing_hashes_overwrite - with_options :conditions => { :method => :get, :domain => "www" } do |outer| - outer.with_options :conditions => { :method => :post } do |inner| - expected = { :conditions => { :method => :post, :domain => "www" } } + with_options conditions: { method: :get, domain: "www" } do |outer| + outer.with_options conditions: { method: :post } do |inner| + expected = { conditions: { method: :post, domain: "www" } } assert_equal expected, inner.method_with_options end end end def test_nested_method_with_options_containing_hashes_going_deep - with_options :html => { :class => "foo", :style => { :margin => 0, :display => "block" } } do |outer| - outer.with_options :html => { :title => "bar", :style => { :margin => "1em", :color => "#fff" } } do |inner| - expected = { :html => { :class => "foo", :title => "bar", :style => { :margin => "1em", :display => "block", :color => "#fff" } } } + with_options html: { class: "foo", style: { margin: 0, display: "block" } } do |outer| + outer.with_options html: { title: "bar", style: { margin: "1em", color: "#fff" } } do |inner| + expected = { html: { class: "foo", title: "bar", style: { margin: "1em", display: "block", color: "#fff" } } } assert_equal expected, inner.method_with_options end end end def test_nested_method_with_options_using_lambda - local_lambda = lambda { { :lambda => true } } + local_lambda = lambda { { lambda: true } } with_options(@options) do |o| assert_equal @options.merge(local_lambda.call), o.method_with_options(local_lambda).call @@ -76,7 +76,7 @@ class OptionMergerTest < ActiveSupport::TestCase # Needed when counting objects with the ObjectSpace def test_option_merger_class_method - assert_equal ActiveSupport::OptionMerger, ActiveSupport::OptionMerger.new('', '').class + assert_equal ActiveSupport::OptionMerger, ActiveSupport::OptionMerger.new("", "").class end def test_option_merger_implicit_receiver diff --git a/activesupport/test/ordered_hash_test.rb b/activesupport/test/ordered_hash_test.rb index 460a61613e..d2dfc34040 100644 --- a/activesupport/test/ordered_hash_test.rb +++ b/activesupport/test/ordered_hash_test.rb @@ -1,8 +1,8 @@ -require 'abstract_unit' -require 'active_support/json' -require 'active_support/core_ext/object/json' -require 'active_support/core_ext/hash/indifferent_access' -require 'active_support/core_ext/array/extract_options' +require "abstract_unit" +require "active_support/json" +require "active_support/core_ext/object/json" +require "active_support/core_ext/hash/indifferent_access" +require "active_support/core_ext/array/extract_options" class OrderedHashTest < ActiveSupport::TestCase def setup @@ -27,7 +27,7 @@ class OrderedHashTest < ActiveSupport::TestCase end def test_assignment - key, value = 'purple', '5422a8' + key, value = "purple", "5422a8" @ordered_hash[key] = value assert_equal @keys.length + 1, @ordered_hash.length @@ -37,8 +37,8 @@ class OrderedHashTest < ActiveSupport::TestCase end def test_delete - key, value = 'white', 'ffffff' - bad_key = 'black' + key, value = "white", "ffffff" + bad_key = "black" @ordered_hash[key] = value assert_equal @keys.length + 1, @ordered_hash.length @@ -60,22 +60,22 @@ class OrderedHashTest < ActiveSupport::TestCase end def test_has_key - assert_equal true, @ordered_hash.has_key?('blue') - assert_equal true, @ordered_hash.key?('blue') - assert_equal true, @ordered_hash.include?('blue') - assert_equal true, @ordered_hash.member?('blue') + assert_equal true, @ordered_hash.has_key?("blue") + assert_equal true, @ordered_hash.key?("blue") + assert_equal true, @ordered_hash.include?("blue") + assert_equal true, @ordered_hash.member?("blue") - assert_equal false, @ordered_hash.has_key?('indigo') - assert_equal false, @ordered_hash.key?('indigo') - assert_equal false, @ordered_hash.include?('indigo') - assert_equal false, @ordered_hash.member?('indigo') + assert_equal false, @ordered_hash.has_key?("indigo") + assert_equal false, @ordered_hash.key?("indigo") + assert_equal false, @ordered_hash.include?("indigo") + assert_equal false, @ordered_hash.member?("indigo") end def test_has_value - assert_equal true, @ordered_hash.has_value?('000099') - assert_equal true, @ordered_hash.value?('000099') - assert_equal false, @ordered_hash.has_value?('ABCABC') - assert_equal false, @ordered_hash.value?('ABCABC') + assert_equal true, @ordered_hash.has_value?("000099") + assert_equal true, @ordered_hash.value?("000099") + assert_equal false, @ordered_hash.has_value?("ABCABC") + assert_equal false, @ordered_hash.value?("ABCABC") end def test_each_key @@ -94,13 +94,13 @@ class OrderedHashTest < ActiveSupport::TestCase def test_each values = [] - assert_equal @ordered_hash, @ordered_hash.each {|key, value| values << value} + assert_equal @ordered_hash, @ordered_hash.each { |key, value| values << value } assert_equal @values, values assert_kind_of Enumerator, @ordered_hash.each end def test_each_with_index - @ordered_hash.each_with_index { |pair, index| assert_equal [@keys[index], @values[index]], pair} + @ordered_hash.each_with_index { |pair, index| assert_equal [@keys[index], @values[index]], pair } end def test_each_pair @@ -127,24 +127,24 @@ class OrderedHashTest < ActiveSupport::TestCase def test_delete_if copy = @ordered_hash.dup - copy.delete('pink') - assert_equal copy, @ordered_hash.delete_if { |k, _| k == 'pink' } - assert !@ordered_hash.keys.include?('pink') + copy.delete("pink") + assert_equal copy, @ordered_hash.delete_if { |k, _| k == "pink" } + assert !@ordered_hash.keys.include?("pink") end def test_reject! - (copy = @ordered_hash.dup).delete('pink') - @ordered_hash.reject! { |k, _| k == 'pink' } + (copy = @ordered_hash.dup).delete("pink") + @ordered_hash.reject! { |k, _| k == "pink" } assert_equal copy, @ordered_hash - assert !@ordered_hash.keys.include?('pink') + assert !@ordered_hash.keys.include?("pink") end def test_reject copy = @ordered_hash.dup - new_ordered_hash = @ordered_hash.reject { |k, _| k == 'pink' } + new_ordered_hash = @ordered_hash.reject { |k, _| k == "pink" } assert_equal copy, @ordered_hash - assert !new_ordered_hash.keys.include?('pink') - assert @ordered_hash.keys.include?('pink') + assert !new_ordered_hash.keys.include?("pink") + assert @ordered_hash.keys.include?("pink") assert_instance_of ActiveSupport::OrderedHash, new_ordered_hash end @@ -155,18 +155,18 @@ class OrderedHashTest < ActiveSupport::TestCase def test_merge other_hash = ActiveSupport::OrderedHash.new - other_hash['purple'] = '800080' - other_hash['violet'] = 'ee82ee' + other_hash["purple"] = "800080" + other_hash["violet"] = "ee82ee" merged = @ordered_hash.merge other_hash assert_equal merged.length, @ordered_hash.length + other_hash.length - assert_equal @keys + ['purple', 'violet'], merged.keys + assert_equal @keys + ["purple", "violet"], merged.keys end def test_merge_with_block hash = ActiveSupport::OrderedHash.new hash[:a] = 0 hash[:b] = 0 - merged = hash.merge(:b => 2, :c => 7) do |key, old_value, new_value| + merged = hash.merge(b: 2, c: 7) do |key, old_value, new_value| new_value + 1 end @@ -179,7 +179,7 @@ class OrderedHashTest < ActiveSupport::TestCase hash = ActiveSupport::OrderedHash.new hash[:a] = 0 hash[:b] = 0 - hash.merge!(:a => 1, :c => 7) do |key, old_value, new_value| + hash.merge!(a: 1, c: 7) do |key, old_value, new_value| new_value + 3 end @@ -220,11 +220,11 @@ class OrderedHashTest < ActiveSupport::TestCase alternate = ActiveSupport::OrderedHash[ [ [1, 2], [3, 4], - [ 'missing value' ] + [ "missing value" ] ]] assert_kind_of ActiveSupport::OrderedHash, alternate - assert_equal [1, 3, 'missing value'], alternate.keys + assert_equal [1, 3, "missing value"], alternate.keys assert_equal [2, 4, nil ], alternate.values end @@ -235,14 +235,14 @@ class OrderedHashTest < ActiveSupport::TestCase end def test_replace_updates_keys - @other_ordered_hash = ActiveSupport::OrderedHash[:black, '000000', :white, '000000'] + @other_ordered_hash = ActiveSupport::OrderedHash[:black, "000000", :white, "000000"] original = @ordered_hash.replace(@other_ordered_hash) assert_same original, @ordered_hash assert_equal @other_ordered_hash.keys, @ordered_hash.keys end def test_nested_under_indifferent_access - flash = {:a => ActiveSupport::OrderedHash[:b, 1, :c, 2]}.with_indifferent_access + flash = { a: ActiveSupport::OrderedHash[:b, 1, :c, 2] }.with_indifferent_access assert_kind_of ActiveSupport::OrderedHash, flash[:a] end @@ -295,17 +295,17 @@ class OrderedHashTest < ActiveSupport::TestCase def test_psych_serialize_tag yaml = Psych.dump(@ordered_hash) - assert_match '!omap', yaml + assert_match "!omap", yaml end def test_has_yaml_tag @ordered_hash[:array] = %w(a b c) - assert_match '!omap', YAML.dump(@ordered_hash) + assert_match "!omap", YAML.dump(@ordered_hash) end def test_update_sets_keys @updated_ordered_hash = ActiveSupport::OrderedHash.new - @updated_ordered_hash.update(:name => "Bob") + @updated_ordered_hash.update(name: "Bob") assert_equal [:name], @updated_ordered_hash.keys end diff --git a/activesupport/test/ordered_options_test.rb b/activesupport/test/ordered_options_test.rb index 18767a3536..0417911289 100644 --- a/activesupport/test/ordered_options_test.rb +++ b/activesupport/test/ordered_options_test.rb @@ -1,5 +1,5 @@ -require 'abstract_unit' -require 'active_support/ordered_options' +require "abstract_unit" +require "active_support/ordered_options" class OrderedOptionsTest < ActiveSupport::TestCase def test_usage diff --git a/activesupport/test/reloader_test.rb b/activesupport/test/reloader_test.rb index 958cb49993..67d8c4b0e3 100644 --- a/activesupport/test/reloader_test.rb +++ b/activesupport/test/reloader_test.rb @@ -1,4 +1,4 @@ -require 'abstract_unit' +require "abstract_unit" class ReloaderTest < ActiveSupport::TestCase def test_prepare_callback @@ -21,13 +21,13 @@ class ReloaderTest < ActiveSupport::TestCase r = new_reloader { true } invoked = false r.to_run { invoked = true } - r.wrap { } + r.wrap {} assert invoked r = new_reloader { false } invoked = false r.to_run { invoked = true } - r.wrap { } + r.wrap {} assert !invoked end @@ -39,7 +39,7 @@ class ReloaderTest < ActiveSupport::TestCase reloader.executor.to_run { called << :executor_run } reloader.executor.to_complete { called << :executor_complete } - reloader.wrap { } + reloader.wrap {} assert_equal [:executor_run, :reloader_run, :prepare, :reloader_complete, :executor_complete], called called = [] @@ -49,7 +49,7 @@ class ReloaderTest < ActiveSupport::TestCase reloader.check = lambda { false } called = [] - reloader.wrap { } + reloader.wrap {} assert_equal [:executor_run, :executor_complete], called called = [] diff --git a/activesupport/test/rescuable_test.rb b/activesupport/test/rescuable_test.rb index e42e6d2973..7e5c3d1a8f 100644 --- a/activesupport/test/rescuable_test.rb +++ b/activesupport/test/rescuable_test.rb @@ -1,4 +1,4 @@ -require 'abstract_unit' +require "abstract_unit" class WraithAttack < StandardError end @@ -24,12 +24,12 @@ class Stargate include ActiveSupport::Rescuable - rescue_from WraithAttack, :with => :sos_first + rescue_from WraithAttack, with: :sos_first - rescue_from WraithAttack, :with => :sos + rescue_from WraithAttack, with: :sos - rescue_from 'NuclearExplosion' do - @result = 'alldead' + rescue_from "NuclearExplosion" do + @result = "alldead" end rescue_from MadRonon do |e| @@ -37,7 +37,7 @@ class Stargate end rescue_from WeirdError do - @result = 'weird' + @result = "weird" end def dispatch(method) @@ -63,7 +63,7 @@ class Stargate ronanize rescue # This is the exception we'll handle that doesn't have a cause. - raise 'unhandled RuntimeError with a handleable cause' + raise "unhandled RuntimeError with a handleable cause" end def weird @@ -77,11 +77,11 @@ class Stargate end def sos - @result = 'killed' + @result = "killed" end def sos_first - @result = 'sos_first' + @result = "sos_first" end end @@ -90,14 +90,13 @@ class CoolStargate < Stargate include ActiveSupport::Rescuable - rescue_from CoolError, :with => :sos_cool_error + rescue_from CoolError, with: :sos_cool_error def sos_cool_error - @result = 'sos_cool_error' + @result = "sos_cool_error" end end - class RescuableTest < ActiveSupport::TestCase def setup @stargate = Stargate.new @@ -106,22 +105,22 @@ class RescuableTest < ActiveSupport::TestCase def test_rescue_from_with_method @stargate.dispatch :attack - assert_equal 'killed', @stargate.result + assert_equal "killed", @stargate.result end def test_rescue_from_with_block @stargate.dispatch :nuke - assert_equal 'alldead', @stargate.result + assert_equal "alldead", @stargate.result end def test_rescue_from_with_block_with_args @stargate.dispatch :ronanize - assert_equal 'dex', @stargate.result + assert_equal "dex", @stargate.result end def test_rescue_from_error_dispatchers_with_case_operator @stargate.dispatch :weird - assert_equal 'weird', @stargate.result + assert_equal "weird", @stargate.result end def test_rescues_defined_later_are_added_at_end_of_the_rescue_handlers_array @@ -138,6 +137,6 @@ class RescuableTest < ActiveSupport::TestCase def test_rescue_falls_back_to_exception_cause @stargate.dispatch :fall_back_to_cause - assert_equal 'unhandled RuntimeError with a handleable cause', @stargate.result + assert_equal "unhandled RuntimeError with a handleable cause", @stargate.result end end diff --git a/activesupport/test/safe_buffer_test.rb b/activesupport/test/safe_buffer_test.rb index 18fb6d2fbf..4d083ab773 100644 --- a/activesupport/test/safe_buffer_test.rb +++ b/activesupport/test/safe_buffer_test.rb @@ -1,6 +1,6 @@ -require 'abstract_unit' -require 'active_support/core_ext/string/inflections' -require 'yaml' +require "abstract_unit" +require "active_support/core_ext/string/inflections" +require "yaml" class SafeBufferTest < ActiveSupport::TestCase def setup @@ -8,7 +8,7 @@ class SafeBufferTest < ActiveSupport::TestCase end def test_titleize - assert_equal 'Foo', "foo".html_safe.titleize + assert_equal "Foo", "foo".html_safe.titleize end test "Should look like a string" do @@ -46,26 +46,26 @@ class SafeBufferTest < ActiveSupport::TestCase end test "Should be converted to_yaml" do - str = 'hello!' + str = "hello!" buf = ActiveSupport::SafeBuffer.new str yaml = buf.to_yaml assert_match(/^--- #{str}/, yaml) - assert_equal 'hello!', YAML.load(yaml) + assert_equal "hello!", YAML.load(yaml) end test "Should work in nested to_yaml conversion" do - str = 'hello!' - data = { 'str' => ActiveSupport::SafeBuffer.new(str) } + str = "hello!" + data = { "str" => ActiveSupport::SafeBuffer.new(str) } yaml = YAML.dump data - assert_equal({'str' => str}, YAML.load(yaml)) + assert_equal({ "str" => str }, YAML.load(yaml)) end test "Should work with primitive-like-strings in to_yaml conversion" do - assert_equal 'true', YAML.load(ActiveSupport::SafeBuffer.new('true').to_yaml) - assert_equal 'false', YAML.load(ActiveSupport::SafeBuffer.new('false').to_yaml) - assert_equal '1', YAML.load(ActiveSupport::SafeBuffer.new('1').to_yaml) - assert_equal '1.1', YAML.load(ActiveSupport::SafeBuffer.new('1.1').to_yaml) + assert_equal "true", YAML.load(ActiveSupport::SafeBuffer.new("true").to_yaml) + assert_equal "false", YAML.load(ActiveSupport::SafeBuffer.new("false").to_yaml) + assert_equal "1", YAML.load(ActiveSupport::SafeBuffer.new("1").to_yaml) + assert_equal "1.1", YAML.load(ActiveSupport::SafeBuffer.new("1.1").to_yaml) end test "Should work with underscore" do @@ -74,31 +74,31 @@ class SafeBufferTest < ActiveSupport::TestCase end test "Should not return safe buffer from gsub" do - altered_buffer = @buffer.gsub('', 'asdf') - assert_equal 'asdf', altered_buffer + altered_buffer = @buffer.gsub("", "asdf") + assert_equal "asdf", altered_buffer assert !altered_buffer.html_safe? end test "Should not return safe buffer from gsub!" do - @buffer.gsub!('', 'asdf') - assert_equal 'asdf', @buffer + @buffer.gsub!("", "asdf") + assert_equal "asdf", @buffer assert !@buffer.html_safe? end test "Should escape dirty buffers on add" do clean = "hello".html_safe - @buffer.gsub!('', '<>') + @buffer.gsub!("", "<>") assert_equal "hello<>", clean + @buffer end test "Should concat as a normal string when safe" do clean = "hello".html_safe - @buffer.gsub!('', '<>') + @buffer.gsub!("", "<>") assert_equal "<>hello", @buffer + clean end test "Should preserve html_safe? status on copy" do - @buffer.gsub!('', '<>') + @buffer.gsub!("", "<>") assert !@buffer.dup.html_safe? end @@ -110,7 +110,7 @@ class SafeBufferTest < ActiveSupport::TestCase end test "Should raise an error when safe_concat is called on unsafe buffers" do - @buffer.gsub!('', '<>') + @buffer.gsub!("", "<>") assert_raise ActiveSupport::SafeBuffer::SafeConcatError do @buffer.safe_concat "BUSTED" end @@ -121,12 +121,12 @@ class SafeBufferTest < ActiveSupport::TestCase end test "clone_empty returns an empty buffer" do - assert_equal '', ActiveSupport::SafeBuffer.new('foo').clone_empty + assert_equal "", ActiveSupport::SafeBuffer.new("foo").clone_empty end test "clone_empty keeps the original dirtyness" do assert @buffer.clone_empty.html_safe? - assert !@buffer.gsub!('', '').clone_empty.html_safe? + assert !@buffer.gsub!("", "").clone_empty.html_safe? end test "Should be safe when sliced if original value was safe" do @@ -136,7 +136,7 @@ class SafeBufferTest < ActiveSupport::TestCase end test "Should continue unsafe on slice" do - x = 'foo'.html_safe.gsub!('f', '<script>alert("lolpwnd");</script>') + x = "foo".html_safe.gsub!("f", '<script>alert("lolpwnd");</script>') # calling gsub! makes the dirty flag true assert !x.html_safe?, "should not be safe" @@ -148,33 +148,33 @@ class SafeBufferTest < ActiveSupport::TestCase assert !y.html_safe?, "should not be safe" end - test 'Should work with interpolation (array argument)' do - x = 'foo %s bar'.html_safe % ['qux'] - assert_equal 'foo qux bar', x + test "Should work with interpolation (array argument)" do + x = "foo %s bar".html_safe % ["qux"] + assert_equal "foo qux bar", x end - test 'Should work with interpolation (hash argument)' do - x = 'foo %{x} bar'.html_safe % { x: 'qux' } - assert_equal 'foo qux bar', x + test "Should work with interpolation (hash argument)" do + x = "foo %{x} bar".html_safe % { x: "qux" } + assert_equal "foo qux bar", x end - test 'Should escape unsafe interpolated args' do - x = 'foo %{x} bar'.html_safe % { x: '<br/>' } - assert_equal 'foo <br/> bar', x + test "Should escape unsafe interpolated args" do + x = "foo %{x} bar".html_safe % { x: "<br/>" } + assert_equal "foo <br/> bar", x end - test 'Should not escape safe interpolated args' do - x = 'foo %{x} bar'.html_safe % { x: '<br/>'.html_safe } - assert_equal 'foo <br/> bar', x + test "Should not escape safe interpolated args" do + x = "foo %{x} bar".html_safe % { x: "<br/>".html_safe } + assert_equal "foo <br/> bar", x end - test 'Should interpolate to a safe string' do - x = 'foo %{x} bar'.html_safe % { x: 'qux' } - assert x.html_safe?, 'should be safe' + test "Should interpolate to a safe string" do + x = "foo %{x} bar".html_safe % { x: "qux" } + assert x.html_safe?, "should be safe" end - test 'Should not affect frozen objects when accessing characters' do - x = 'Hello'.html_safe + test "Should not affect frozen objects when accessing characters" do + x = "Hello".html_safe assert_equal x[/a/, 1], nil end end diff --git a/activesupport/test/security_utils_test.rb b/activesupport/test/security_utils_test.rb index 08d2e3baa6..842bdd469d 100644 --- a/activesupport/test/security_utils_test.rb +++ b/activesupport/test/security_utils_test.rb @@ -1,9 +1,9 @@ -require 'abstract_unit' -require 'active_support/security_utils' +require "abstract_unit" +require "active_support/security_utils" class SecurityUtilsTest < ActiveSupport::TestCase def test_secure_compare_should_perform_string_comparison - assert ActiveSupport::SecurityUtils.secure_compare('a', 'a') - assert !ActiveSupport::SecurityUtils.secure_compare('a', 'b') + assert ActiveSupport::SecurityUtils.secure_compare("a", "a") + assert !ActiveSupport::SecurityUtils.secure_compare("a", "b") end end diff --git a/activesupport/test/share_lock_test.rb b/activesupport/test/share_lock_test.rb index acefa185a8..a5970591fa 100644 --- a/activesupport/test/share_lock_test.rb +++ b/activesupport/test/share_lock_test.rb @@ -1,6 +1,6 @@ -require 'abstract_unit' -require 'concurrent/atomic/count_down_latch' -require 'active_support/concurrency/share_lock' +require "abstract_unit" +require "concurrent/atomic/count_down_latch" +require "active_support/concurrency/share_lock" class ShareLockTest < ActiveSupport::TestCase def setup @@ -17,7 +17,7 @@ class ShareLockTest < ActiveSupport::TestCase def test_sharing_doesnt_block with_thread_waiting_in_lock_section(:sharing) do |sharing_thread_latch| - assert_threads_not_stuck(Thread.new {@lock.sharing {} }) + assert_threads_not_stuck(Thread.new { @lock.sharing {} }) end end @@ -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/string_inquirer_test.rb b/activesupport/test/string_inquirer_test.rb index a2ed577eb0..d41e4d6800 100644 --- a/activesupport/test/string_inquirer_test.rb +++ b/activesupport/test/string_inquirer_test.rb @@ -1,8 +1,8 @@ -require 'abstract_unit' +require "abstract_unit" class StringInquirerTest < ActiveSupport::TestCase def setup - @string_inquirer = ActiveSupport::StringInquirer.new('production') + @string_inquirer = ActiveSupport::StringInquirer.new("production") end def test_match diff --git a/activesupport/test/subscriber_test.rb b/activesupport/test/subscriber_test.rb index a88d8d9eba..9127da35d4 100644 --- a/activesupport/test/subscriber_test.rb +++ b/activesupport/test/subscriber_test.rb @@ -1,5 +1,5 @@ -require 'abstract_unit' -require 'active_support/subscriber' +require "abstract_unit" +require "active_support/subscriber" class TestSubscriber < ActiveSupport::Subscriber attach_to :doodle @@ -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/tagged_logging_test.rb b/activesupport/test/tagged_logging_test.rb index 917fa46c96..2469e827d4 100644 --- a/activesupport/test/tagged_logging_test.rb +++ b/activesupport/test/tagged_logging_test.rb @@ -1,6 +1,6 @@ -require 'abstract_unit' -require 'active_support/logger' -require 'active_support/tagged_logging' +require "abstract_unit" +require "active_support/logger" +require "active_support/tagged_logging" class TaggedLoggingTest < ActiveSupport::TestCase class MyLogger < ::ActiveSupport::Logger @@ -14,7 +14,7 @@ class TaggedLoggingTest < ActiveSupport::TestCase @logger = ActiveSupport::TaggedLogging.new(MyLogger.new(@output)) end - test 'sets logger.formatter if missing and extends it with a tagging API' do + test "sets logger.formatter if missing and extends it with a tagging API" do logger = Logger.new(StringIO.new) assert_nil logger.formatter ActiveSupport::TaggedLogging.new(logger) @@ -43,14 +43,14 @@ class TaggedLoggingTest < ActiveSupport::TestCase end test "push and pop tags directly" do - assert_equal %w(A B C), @logger.push_tags('A', ['B', ' ', ['C']]) - @logger.info 'a' + assert_equal %w(A B C), @logger.push_tags("A", ["B", " ", ["C"]]) + @logger.info "a" assert_equal %w(C), @logger.pop_tags - @logger.info 'b' + @logger.info "b" assert_equal %w(B), @logger.pop_tags(1) - @logger.info 'c' + @logger.info "c" assert_equal [], @logger.clear_tags! - @logger.info 'd' + @logger.info "d" assert_equal "[A] [B] [C] a\n[A] [B] b\n[A] c\nd\n", @output.string end diff --git a/activesupport/test/test_case_test.rb b/activesupport/test/test_case_test.rb index 772c3cfca7..d3d2ed8d7a 100644 --- a/activesupport/test/test_case_test.rb +++ b/activesupport/test/test_case_test.rb @@ -1,4 +1,4 @@ -require 'abstract_unit' +require "abstract_unit" class AssertDifferenceTest < ActiveSupport::TestCase def setup @@ -20,21 +20,21 @@ class AssertDifferenceTest < ActiveSupport::TestCase assert_equal true, assert_not(false) e = assert_raises(Minitest::Assertion) { assert_not true } - assert_equal 'Expected true to be nil or false', e.message + assert_equal "Expected true to be nil or false", e.message - e = assert_raises(Minitest::Assertion) { assert_not true, 'custom' } - assert_equal 'custom', e.message + e = assert_raises(Minitest::Assertion) { assert_not true, "custom" } + assert_equal "custom", e.message end def test_assert_no_difference_pass - assert_no_difference '@object.num' do + assert_no_difference "@object.num" do # ... end end def test_assert_no_difference_fail error = assert_raises(Minitest::Assertion) do - assert_no_difference '@object.num' do + assert_no_difference "@object.num" do @object.increment end end @@ -43,7 +43,7 @@ class AssertDifferenceTest < ActiveSupport::TestCase def test_assert_no_difference_with_message_fail error = assert_raises(Minitest::Assertion) do - assert_no_difference '@object.num', 'Object Changed' do + assert_no_difference "@object.num", "Object Changed" do @object.increment end end @@ -51,13 +51,13 @@ class AssertDifferenceTest < ActiveSupport::TestCase end def test_assert_difference - assert_difference '@object.num', +1 do + assert_difference "@object.num", +1 do @object.increment end end def test_assert_difference_retval - incremented = assert_difference '@object.num', +1 do + incremented = assert_difference "@object.num", +1 do @object.increment end @@ -65,40 +65,40 @@ class AssertDifferenceTest < ActiveSupport::TestCase end def test_assert_difference_with_implicit_difference - assert_difference '@object.num' do + assert_difference "@object.num" do @object.increment end end def test_arbitrary_expression - assert_difference '@object.num + 1', +2 do + assert_difference "@object.num + 1", +2 do @object.increment @object.increment end end def test_negative_differences - assert_difference '@object.num', -1 do + assert_difference "@object.num", -1 do @object.decrement end end def test_expression_is_evaluated_in_the_appropriate_scope silence_warnings do - local_scope = local_scope = 'foo' - assert_difference('local_scope; @object.num') { @object.increment } + local_scope = local_scope = "foo" + assert_difference("local_scope; @object.num") { @object.increment } end end def test_array_of_expressions - assert_difference [ '@object.num', '@object.num + 1' ], +1 do + assert_difference [ "@object.num", "@object.num + 1" ], +1 do @object.increment end end def test_array_of_expressions_identify_failure assert_raises(Minitest::Assertion) do - assert_difference ['@object.num', '1 + 1'] do + assert_difference ["@object.num", "1 + 1"] do @object.increment end end @@ -106,14 +106,14 @@ class AssertDifferenceTest < ActiveSupport::TestCase def test_array_of_expressions_identify_failure_when_message_provided assert_raises(Minitest::Assertion) do - assert_difference ['@object.num', '1 + 1'], 1, 'something went wrong' do + assert_difference ["@object.num", "1 + 1"], 1, "something went wrong" do @object.increment end end end def test_assert_changes_pass - assert_changes '@object.num' do + assert_changes "@object.num" do @object.increment end end @@ -125,42 +125,42 @@ class AssertDifferenceTest < ActiveSupport::TestCase end def test_assert_changes_with_from_option - assert_changes '@object.num', from: 0 do + assert_changes "@object.num", from: 0 do @object.increment end end def test_assert_changes_with_from_option_with_wrong_value assert_raises Minitest::Assertion do - assert_changes '@object.num', from: -1 do + assert_changes "@object.num", from: -1 do @object.increment end end end def test_assert_changes_with_to_option - assert_changes '@object.num', to: 1 do + assert_changes "@object.num", to: 1 do @object.increment end end def test_assert_changes_with_wrong_to_option assert_raises Minitest::Assertion do - assert_changes '@object.num', to: 2 do + assert_changes "@object.num", to: 2 do @object.increment end end end def test_assert_changes_with_from_option_and_to_option - assert_changes '@object.num', from: 0, to: 1 do + assert_changes "@object.num", from: 0, to: 1 do @object.increment end end def test_assert_changes_with_from_and_to_options_and_wrong_to_value assert_raises Minitest::Assertion do - assert_changes '@object.num', from: 0, to: 2 do + assert_changes "@object.num", from: 0, to: 2 do @object.increment end end @@ -189,7 +189,7 @@ class AssertDifferenceTest < ActiveSupport::TestCase def test_assert_changes_with_to_and_case_operator token = nil - assert_changes 'token', to: /\w{32}/ do + assert_changes "token", to: /\w{32}/ do token = SecureRandom.hex end end @@ -197,20 +197,20 @@ class AssertDifferenceTest < ActiveSupport::TestCase def test_assert_changes_with_to_and_from_and_case_operator token = SecureRandom.hex - assert_changes 'token', from: /\w{32}/, to: /\w{32}/ do + assert_changes "token", from: /\w{32}/, to: /\w{32}/ do token = SecureRandom.hex end end def test_assert_no_changes_pass - assert_no_changes '@object.num' do + assert_no_changes "@object.num" do # ... end end def test_assert_no_changes_with_message error = assert_raises Minitest::Assertion do - assert_no_changes '@object.num', '@object.num should not change' do + assert_no_changes "@object.num", "@object.num should not change" do @object.increment end end @@ -276,7 +276,7 @@ end class TestCaseTaggedLoggingTest < ActiveSupport::TestCase def before_setup - require 'stringio' + require "stringio" @out = StringIO.new self.tagged_logger = ActiveSupport::TaggedLogging.new(Logger.new(@out)) super diff --git a/activesupport/test/testing/constant_lookup_test.rb b/activesupport/test/testing/constant_lookup_test.rb index 0f16419c8b..00e69fcdb5 100644 --- a/activesupport/test/testing/constant_lookup_test.rb +++ b/activesupport/test/testing/constant_lookup_test.rb @@ -1,5 +1,5 @@ -require 'abstract_unit' -require 'dependencies_test_helpers' +require "abstract_unit" +require "dependencies_test_helpers" class Foo; end class Bar < Foo @@ -69,7 +69,7 @@ class ConstantLookupTest < ActiveSupport::TestCase def test_does_not_swallow_exception_on_no_name_error_within_constant assert_raises(NameError) do with_autoloading_fixtures do - self.class.determine_constant_from_test_name('RaisesNameError') + self.class.determine_constant_from_test_name("RaisesNameError") end end end diff --git a/activesupport/test/testing/file_fixtures_test.rb b/activesupport/test/testing/file_fixtures_test.rb index d98987fb8d..e44fe58ce9 100644 --- a/activesupport/test/testing/file_fixtures_test.rb +++ b/activesupport/test/testing/file_fixtures_test.rb @@ -1,6 +1,6 @@ -require 'abstract_unit' +require "abstract_unit" -require 'pathname' +require "pathname" class FileFixturesTest < ActiveSupport::TestCase self.file_fixture_path = File.expand_path("../../file_fixtures", __FILE__) diff --git a/activesupport/test/testing/method_call_assertions_test.rb b/activesupport/test/testing/method_call_assertions_test.rb index 3e5ba7c079..7887933b15 100644 --- a/activesupport/test/testing/method_call_assertions_test.rb +++ b/activesupport/test/testing/method_call_assertions_test.rb @@ -1,5 +1,5 @@ -require 'abstract_unit' -require 'active_support/testing/method_call_assertions' +require "abstract_unit" +require "active_support/testing/method_call_assertions" class MethodCallAssertionsTest < ActiveSupport::TestCase include ActiveSupport::Testing::MethodCallAssertions @@ -51,7 +51,7 @@ class MethodCallAssertionsTest < ActiveSupport::TestCase def test_assert_called_with_message error = assert_raises(Minitest::Assertion) do - assert_called(@object, :increment, 'dang it') do + assert_called(@object, :increment, "dang it") do # Call nothing... end end diff --git a/activesupport/test/time_travel_test.rb b/activesupport/test/time_travel_test.rb index e75237e5a4..c68be329bc 100644 --- a/activesupport/test/time_travel_test.rb +++ b/activesupport/test/time_travel_test.rb @@ -1,6 +1,6 @@ -require 'abstract_unit' -require 'active_support/core_ext/date_time' -require 'active_support/core_ext/numeric/time' +require "abstract_unit" +require "active_support/core_ext/date_time" +require "active_support/core_ext/numeric/time" class TimeTravelTest < ActiveSupport::TestCase def test_time_helper_travel diff --git a/activesupport/test/time_zone_test.rb b/activesupport/test/time_zone_test.rb index 76cbb5ce8b..f89b608270 100644 --- a/activesupport/test/time_zone_test.rb +++ b/activesupport/test/time_zone_test.rb @@ -1,25 +1,25 @@ -require 'abstract_unit' -require 'active_support/time' -require 'time_zone_test_helpers' -require 'yaml' +require "abstract_unit" +require "active_support/time" +require "time_zone_test_helpers" +require "yaml" class TimeZoneTest < ActiveSupport::TestCase include TimeZoneTestHelpers def test_utc_to_local - zone = ActiveSupport::TimeZone['Eastern Time (US & Canada)'] + zone = ActiveSupport::TimeZone["Eastern Time (US & Canada)"] assert_equal Time.utc(1999, 12, 31, 19), zone.utc_to_local(Time.utc(2000, 1)) # standard offset -0500 assert_equal Time.utc(2000, 6, 30, 20), zone.utc_to_local(Time.utc(2000, 7)) # dst offset -0400 end def test_local_to_utc - zone = ActiveSupport::TimeZone['Eastern Time (US & Canada)'] + zone = ActiveSupport::TimeZone["Eastern Time (US & Canada)"] assert_equal Time.utc(2000, 1, 1, 5), zone.local_to_utc(Time.utc(2000, 1)) # standard offset -0500 assert_equal Time.utc(2000, 7, 1, 4), zone.local_to_utc(Time.utc(2000, 7)) # dst offset -0400 end def test_period_for_local - zone = ActiveSupport::TimeZone['Eastern Time (US & Canada)'] + zone = ActiveSupport::TimeZone["Eastern Time (US & Canada)"] assert_instance_of TZInfo::TimezonePeriod, zone.period_for_local(Time.utc(2000)) end @@ -39,7 +39,7 @@ class TimeZoneTest < ActiveSupport::TestCase end ActiveSupport::TimeZone.all.each do |zone| - name = zone.name.downcase.gsub(/[^a-z]/, '_') + name = zone.name.downcase.gsub(/[^a-z]/, "_") define_method("test_from_#{name}_to_map") do assert_instance_of ActiveSupport::TimeZone, ActiveSupport::TimeZone[zone.name] end @@ -51,8 +51,8 @@ class TimeZoneTest < ActiveSupport::TestCase end def test_now - with_env_tz 'US/Eastern' do - zone = ActiveSupport::TimeZone['Eastern Time (US & Canada)'].dup + with_env_tz "US/Eastern" do + zone = ActiveSupport::TimeZone["Eastern Time (US & Canada)"].dup def zone.time_now; Time.local(2000); end assert_instance_of ActiveSupport::TimeWithZone, zone.now assert_equal Time.utc(2000,1,1,5), zone.now.utc @@ -62,8 +62,8 @@ class TimeZoneTest < ActiveSupport::TestCase end def test_now_enforces_spring_dst_rules - with_env_tz 'US/Eastern' do - zone = ActiveSupport::TimeZone['Eastern Time (US & Canada)'].dup + with_env_tz "US/Eastern" do + zone = ActiveSupport::TimeZone["Eastern Time (US & Canada)"].dup def zone.time_now Time.local(2006,4,2,2) # 2AM springs forward to 3AM end @@ -74,8 +74,8 @@ class TimeZoneTest < ActiveSupport::TestCase end def test_now_enforces_fall_dst_rules - with_env_tz 'US/Eastern' do - zone = ActiveSupport::TimeZone['Eastern Time (US & Canada)'].dup + with_env_tz "US/Eastern" do + zone = ActiveSupport::TimeZone["Eastern Time (US & Canada)"].dup def zone.time_now Time.at(1162098000) # equivalent to 1AM DST end @@ -85,52 +85,52 @@ class TimeZoneTest < ActiveSupport::TestCase end def test_unknown_timezones_delegation_to_tzinfo - zone = ActiveSupport::TimeZone['America/Montevideo'] + zone = ActiveSupport::TimeZone["America/Montevideo"] assert_equal ActiveSupport::TimeZone, zone.class - assert_equal zone.object_id, ActiveSupport::TimeZone['America/Montevideo'].object_id + assert_equal zone.object_id, ActiveSupport::TimeZone["America/Montevideo"].object_id assert_equal Time.utc(2010, 1, 31, 22), zone.utc_to_local(Time.utc(2010, 2)) # daylight saving offset -0200 assert_equal Time.utc(2010, 3, 31, 21), zone.utc_to_local(Time.utc(2010, 4)) # standard offset -0300 end def test_today travel_to(Time.utc(2000, 1, 1, 4, 59, 59)) # 1 sec before midnight Jan 1 EST - assert_equal Date.new(1999, 12, 31), ActiveSupport::TimeZone['Eastern Time (US & Canada)'].today + assert_equal Date.new(1999, 12, 31), ActiveSupport::TimeZone["Eastern Time (US & Canada)"].today travel_to(Time.utc(2000, 1, 1, 5)) # midnight Jan 1 EST - assert_equal Date.new(2000, 1, 1), ActiveSupport::TimeZone['Eastern Time (US & Canada)'].today + assert_equal Date.new(2000, 1, 1), ActiveSupport::TimeZone["Eastern Time (US & Canada)"].today travel_to(Time.utc(2000, 1, 2, 4, 59, 59)) # 1 sec before midnight Jan 2 EST - assert_equal Date.new(2000, 1, 1), ActiveSupport::TimeZone['Eastern Time (US & Canada)'].today + assert_equal Date.new(2000, 1, 1), ActiveSupport::TimeZone["Eastern Time (US & Canada)"].today travel_to(Time.utc(2000, 1, 2, 5)) # midnight Jan 2 EST - assert_equal Date.new(2000, 1, 2), ActiveSupport::TimeZone['Eastern Time (US & Canada)'].today + assert_equal Date.new(2000, 1, 2), ActiveSupport::TimeZone["Eastern Time (US & Canada)"].today travel_back end def test_tomorrow travel_to(Time.utc(2000, 1, 1, 4, 59, 59)) # 1 sec before midnight Jan 1 EST - assert_equal Date.new(2000, 1, 1), ActiveSupport::TimeZone['Eastern Time (US & Canada)'].tomorrow + assert_equal Date.new(2000, 1, 1), ActiveSupport::TimeZone["Eastern Time (US & Canada)"].tomorrow travel_to(Time.utc(2000, 1, 1, 5)) # midnight Jan 1 EST - assert_equal Date.new(2000, 1, 2), ActiveSupport::TimeZone['Eastern Time (US & Canada)'].tomorrow + assert_equal Date.new(2000, 1, 2), ActiveSupport::TimeZone["Eastern Time (US & Canada)"].tomorrow travel_to(Time.utc(2000, 1, 2, 4, 59, 59)) # 1 sec before midnight Jan 2 EST - assert_equal Date.new(2000, 1, 2), ActiveSupport::TimeZone['Eastern Time (US & Canada)'].tomorrow + assert_equal Date.new(2000, 1, 2), ActiveSupport::TimeZone["Eastern Time (US & Canada)"].tomorrow travel_to(Time.utc(2000, 1, 2, 5)) # midnight Jan 2 EST - assert_equal Date.new(2000, 1, 3), ActiveSupport::TimeZone['Eastern Time (US & Canada)'].tomorrow + assert_equal Date.new(2000, 1, 3), ActiveSupport::TimeZone["Eastern Time (US & Canada)"].tomorrow travel_back end def test_yesterday travel_to(Time.utc(2000, 1, 1, 4, 59, 59)) # 1 sec before midnight Jan 1 EST - assert_equal Date.new(1999, 12, 30), ActiveSupport::TimeZone['Eastern Time (US & Canada)'].yesterday + assert_equal Date.new(1999, 12, 30), ActiveSupport::TimeZone["Eastern Time (US & Canada)"].yesterday travel_to(Time.utc(2000, 1, 1, 5)) # midnight Jan 1 EST - assert_equal Date.new(1999, 12, 31), ActiveSupport::TimeZone['Eastern Time (US & Canada)'].yesterday + assert_equal Date.new(1999, 12, 31), ActiveSupport::TimeZone["Eastern Time (US & Canada)"].yesterday travel_to(Time.utc(2000, 1, 2, 4, 59, 59)) # 1 sec before midnight Jan 2 EST - assert_equal Date.new(1999, 12, 31), ActiveSupport::TimeZone['Eastern Time (US & Canada)'].yesterday + assert_equal Date.new(1999, 12, 31), ActiveSupport::TimeZone["Eastern Time (US & Canada)"].yesterday travel_to(Time.utc(2000, 1, 2, 5)) # midnight Jan 2 EST - assert_equal Date.new(2000, 1, 1), ActiveSupport::TimeZone['Eastern Time (US & Canada)'].yesterday + assert_equal Date.new(2000, 1, 1), ActiveSupport::TimeZone["Eastern Time (US & Canada)"].yesterday travel_back end def test_travel_to_a_date with_env_tz do - Time.use_zone('Hawaii') do + Time.use_zone("Hawaii") do date = Date.new(2014, 2, 18) time = date.midnight @@ -167,37 +167,37 @@ class TimeZoneTest < ActiveSupport::TestCase end def test_local_enforces_spring_dst_rules - zone = ActiveSupport::TimeZone['Eastern Time (US & Canada)'] + zone = ActiveSupport::TimeZone["Eastern Time (US & Canada)"] twz = zone.local(2006,4,2,1,59,59) # 1 second before DST start assert_equal Time.utc(2006,4,2,1,59,59), twz.time assert_equal Time.utc(2006,4,2,6,59,59), twz.utc assert_equal false, twz.dst? - assert_equal 'EST', twz.zone + assert_equal "EST", twz.zone twz2 = zone.local(2006,4,2,2) # 2AM does not exist because at 2AM, time springs forward to 3AM assert_equal Time.utc(2006,4,2,3), twz2.time # twz is created for 3AM assert_equal Time.utc(2006,4,2,7), twz2.utc assert_equal true, twz2.dst? - assert_equal 'EDT', twz2.zone + assert_equal "EDT", twz2.zone twz3 = zone.local(2006,4,2,2,30) # 2:30AM does not exist because at 2AM, time springs forward to 3AM assert_equal Time.utc(2006,4,2,3,30), twz3.time # twz is created for 3:30AM assert_equal Time.utc(2006,4,2,7,30), twz3.utc assert_equal true, twz3.dst? - assert_equal 'EDT', twz3.zone + assert_equal "EDT", twz3.zone end def test_local_enforces_fall_dst_rules # 1AM during fall DST transition is ambiguous, it could be either DST or non-DST 1AM # Mirroring Time.local behavior, this method selects the DST time - zone = ActiveSupport::TimeZone['Eastern Time (US & Canada)'] + zone = ActiveSupport::TimeZone["Eastern Time (US & Canada)"] twz = zone.local(2006,10,29,1) assert_equal Time.utc(2006,10,29,1), twz.time assert_equal Time.utc(2006,10,29,5), twz.utc assert_equal true, twz.dst? - assert_equal 'EDT', twz.zone + assert_equal "EDT", twz.zone end def test_at - zone = ActiveSupport::TimeZone['Eastern Time (US & Canada)'] + zone = ActiveSupport::TimeZone["Eastern Time (US & Canada)"] secs = 946684800.0 twz = zone.at(secs) assert_equal Time.utc(1999,12,31,19), twz.time @@ -207,7 +207,7 @@ class TimeZoneTest < ActiveSupport::TestCase end def test_at_with_old_date - zone = ActiveSupport::TimeZone['Eastern Time (US & Canada)'] + zone = ActiveSupport::TimeZone["Eastern Time (US & Canada)"] secs = DateTime.civil(1850).to_f twz = zone.at(secs) assert_equal [1850, 1, 1, 0], [twz.utc.year, twz.utc.mon, twz.utc.day, twz.utc.hour] @@ -216,8 +216,8 @@ class TimeZoneTest < ActiveSupport::TestCase end def test_parse - zone = ActiveSupport::TimeZone['Eastern Time (US & Canada)'] - twz = zone.parse('1999-12-31 19:00:00') + zone = ActiveSupport::TimeZone["Eastern Time (US & Canada)"] + twz = zone.parse("1999-12-31 19:00:00") assert_equal Time.utc(1999,12,31,19), twz.time assert_equal Time.utc(2000), twz.utc assert_equal zone, twz.time_zone @@ -226,97 +226,97 @@ class TimeZoneTest < ActiveSupport::TestCase def test_parse_string_with_timezone (-11..13).each do |timezone_offset| zone = ActiveSupport::TimeZone[timezone_offset] - twz = zone.parse('1999-12-31 19:00:00') + twz = zone.parse("1999-12-31 19:00:00") assert_equal twz, zone.parse(twz.to_s) end end def test_parse_with_old_date - zone = ActiveSupport::TimeZone['Eastern Time (US & Canada)'] - twz = zone.parse('1883-12-31 19:00:00') + zone = ActiveSupport::TimeZone["Eastern Time (US & Canada)"] + twz = zone.parse("1883-12-31 19:00:00") assert_equal [0,0,19,31,12,1883], twz.to_a[0,6] assert_equal zone, twz.time_zone end def test_parse_far_future_date_with_time_zone_offset_in_string - zone = ActiveSupport::TimeZone['Eastern Time (US & Canada)'] - twz = zone.parse('2050-12-31 19:00:00 -10:00') # i.e., 2050-01-01 05:00:00 UTC + zone = ActiveSupport::TimeZone["Eastern Time (US & Canada)"] + twz = zone.parse("2050-12-31 19:00:00 -10:00") # i.e., 2050-01-01 05:00:00 UTC assert_equal [0,0,0,1,1,2051], twz.to_a[0,6] assert_equal zone, twz.time_zone end def test_parse_returns_nil_when_string_without_date_information_is_passed_in - zone = ActiveSupport::TimeZone['Eastern Time (US & Canada)'] - assert_nil zone.parse('foobar') - assert_nil zone.parse(' ') + zone = ActiveSupport::TimeZone["Eastern Time (US & Canada)"] + assert_nil zone.parse("foobar") + assert_nil zone.parse(" ") end def test_parse_with_incomplete_date - zone = ActiveSupport::TimeZone['Eastern Time (US & Canada)'] + zone = ActiveSupport::TimeZone["Eastern Time (US & Canada)"] zone.stub(:now, zone.local(1999,12,31)) do - twz = zone.parse('19:00:00') + twz = zone.parse("19:00:00") assert_equal Time.utc(1999,12,31,19), twz.time end end def test_parse_with_day_omitted - with_env_tz 'US/Eastern' do - zone = ActiveSupport::TimeZone['Eastern Time (US & Canada)'] - assert_equal Time.local(2000, 2, 1), zone.parse('Feb', Time.local(2000, 1, 1)) - assert_equal Time.local(2005, 2, 1), zone.parse('Feb 2005', Time.local(2000, 1, 1)) - assert_equal Time.local(2005, 2, 2), zone.parse('2 Feb 2005', Time.local(2000, 1, 1)) + with_env_tz "US/Eastern" do + zone = ActiveSupport::TimeZone["Eastern Time (US & Canada)"] + assert_equal Time.local(2000, 2, 1), zone.parse("Feb", Time.local(2000, 1, 1)) + assert_equal Time.local(2005, 2, 1), zone.parse("Feb 2005", Time.local(2000, 1, 1)) + assert_equal Time.local(2005, 2, 2), zone.parse("2 Feb 2005", Time.local(2000, 1, 1)) end end def test_parse_should_not_black_out_system_timezone_dst_jump - with_env_tz('EET') do - zone = ActiveSupport::TimeZone['Pacific Time (US & Canada)'] - twz = zone.parse('2012-03-25 03:29:00') + with_env_tz("EET") do + zone = ActiveSupport::TimeZone["Pacific Time (US & Canada)"] + twz = zone.parse("2012-03-25 03:29:00") assert_equal [0, 29, 3, 25, 3, 2012], twz.to_a[0,6] end end def test_parse_should_black_out_app_timezone_dst_jump - with_env_tz('EET') do - zone = ActiveSupport::TimeZone['Pacific Time (US & Canada)'] - twz = zone.parse('2012-03-11 02:29:00') + with_env_tz("EET") do + zone = ActiveSupport::TimeZone["Pacific Time (US & Canada)"] + twz = zone.parse("2012-03-11 02:29:00") assert_equal [0, 29, 3, 11, 3, 2012], twz.to_a[0,6] end end def test_parse_with_missing_time_components - zone = ActiveSupport::TimeZone['Eastern Time (US & Canada)'] + zone = ActiveSupport::TimeZone["Eastern Time (US & Canada)"] zone.stub(:now, zone.local(1999, 12, 31, 12, 59, 59)) do - twz = zone.parse('2012-12-01') + twz = zone.parse("2012-12-01") assert_equal Time.utc(2012, 12, 1), twz.time end end def test_parse_with_javascript_date - zone = ActiveSupport::TimeZone['Eastern Time (US & Canada)'] + zone = ActiveSupport::TimeZone["Eastern Time (US & Canada)"] twz = zone.parse("Mon May 28 2012 00:00:00 GMT-0700 (PDT)") assert_equal Time.utc(2012, 5, 28, 7, 0, 0), twz.utc end def test_parse_doesnt_use_local_dst - with_env_tz 'US/Eastern' do - zone = ActiveSupport::TimeZone['UTC'] - twz = zone.parse('2013-03-10 02:00:00') + with_env_tz "US/Eastern" do + zone = ActiveSupport::TimeZone["UTC"] + twz = zone.parse("2013-03-10 02:00:00") assert_equal Time.utc(2013, 3, 10, 2, 0, 0), twz.time end end def test_parse_handles_dst_jump - with_env_tz 'US/Eastern' do - zone = ActiveSupport::TimeZone['Eastern Time (US & Canada)'] - twz = zone.parse('2013-03-10 02:00:00') + with_env_tz "US/Eastern" do + zone = ActiveSupport::TimeZone["Eastern Time (US & Canada)"] + twz = zone.parse("2013-03-10 02:00:00") assert_equal Time.utc(2013, 3, 10, 3, 0, 0), twz.time end end def test_strptime - zone = ActiveSupport::TimeZone['Eastern Time (US & Canada)'] - twz = zone.strptime('1999-12-31 12:00:00', '%Y-%m-%d %H:%M:%S') + zone = ActiveSupport::TimeZone["Eastern Time (US & Canada)"] + twz = zone.strptime("1999-12-31 12:00:00", "%Y-%m-%d %H:%M:%S") assert_equal Time.utc(1999,12,31,17), twz assert_equal Time.utc(1999,12,31,12), twz.time assert_equal Time.utc(1999,12,31,17), twz.utc @@ -324,9 +324,9 @@ class TimeZoneTest < ActiveSupport::TestCase end def test_strptime_with_nondefault_time_zone - with_tz_default ActiveSupport::TimeZone['Pacific Time (US & Canada)'] do - zone = ActiveSupport::TimeZone['Eastern Time (US & Canada)'] - twz = zone.strptime('1999-12-31 12:00:00', '%Y-%m-%d %H:%M:%S') + with_tz_default ActiveSupport::TimeZone["Pacific Time (US & Canada)"] do + zone = ActiveSupport::TimeZone["Eastern Time (US & Canada)"] + twz = zone.strptime("1999-12-31 12:00:00", "%Y-%m-%d %H:%M:%S") assert_equal Time.utc(1999,12,31,17), twz assert_equal Time.utc(1999,12,31,12), twz.time assert_equal Time.utc(1999,12,31,17), twz.utc @@ -335,8 +335,8 @@ class TimeZoneTest < ActiveSupport::TestCase end def test_strptime_with_explicit_time_zone_as_abbrev - zone = ActiveSupport::TimeZone['Eastern Time (US & Canada)'] - twz = zone.strptime('1999-12-31 12:00:00 PST', '%Y-%m-%d %H:%M:%S %Z') + zone = ActiveSupport::TimeZone["Eastern Time (US & Canada)"] + twz = zone.strptime("1999-12-31 12:00:00 PST", "%Y-%m-%d %H:%M:%S %Z") assert_equal Time.utc(1999,12,31,20), twz assert_equal Time.utc(1999,12,31,15), twz.time assert_equal Time.utc(1999,12,31,20), twz.utc @@ -344,8 +344,8 @@ class TimeZoneTest < ActiveSupport::TestCase end def test_strptime_with_explicit_time_zone_as_h_offset - zone = ActiveSupport::TimeZone['Eastern Time (US & Canada)'] - twz = zone.strptime('1999-12-31 12:00:00 -08', '%Y-%m-%d %H:%M:%S %:::z') + zone = ActiveSupport::TimeZone["Eastern Time (US & Canada)"] + twz = zone.strptime("1999-12-31 12:00:00 -08", "%Y-%m-%d %H:%M:%S %:::z") assert_equal Time.utc(1999,12,31,20), twz assert_equal Time.utc(1999,12,31,15), twz.time assert_equal Time.utc(1999,12,31,20), twz.utc @@ -353,8 +353,8 @@ class TimeZoneTest < ActiveSupport::TestCase end def test_strptime_with_explicit_time_zone_as_hm_offset - zone = ActiveSupport::TimeZone['Eastern Time (US & Canada)'] - twz = zone.strptime('1999-12-31 12:00:00 -08:00', '%Y-%m-%d %H:%M:%S %:z') + zone = ActiveSupport::TimeZone["Eastern Time (US & Canada)"] + twz = zone.strptime("1999-12-31 12:00:00 -08:00", "%Y-%m-%d %H:%M:%S %:z") assert_equal Time.utc(1999,12,31,20), twz assert_equal Time.utc(1999,12,31,15), twz.time assert_equal Time.utc(1999,12,31,20), twz.utc @@ -362,8 +362,8 @@ class TimeZoneTest < ActiveSupport::TestCase end def test_strptime_with_explicit_time_zone_as_hms_offset - zone = ActiveSupport::TimeZone['Eastern Time (US & Canada)'] - twz = zone.strptime('1999-12-31 12:00:00 -08:00:00', '%Y-%m-%d %H:%M:%S %::z') + zone = ActiveSupport::TimeZone["Eastern Time (US & Canada)"] + twz = zone.strptime("1999-12-31 12:00:00 -08:00:00", "%Y-%m-%d %H:%M:%S %::z") assert_equal Time.utc(1999,12,31,20), twz assert_equal Time.utc(1999,12,31,15), twz.time assert_equal Time.utc(1999,12,31,20), twz.utc @@ -371,8 +371,8 @@ class TimeZoneTest < ActiveSupport::TestCase end def test_strptime_with_almost_explicit_time_zone - zone = ActiveSupport::TimeZone['Eastern Time (US & Canada)'] - twz = zone.strptime('1999-12-31 12:00:00 %Z', '%Y-%m-%d %H:%M:%S %%Z') + zone = ActiveSupport::TimeZone["Eastern Time (US & Canada)"] + twz = zone.strptime("1999-12-31 12:00:00 %Z", "%Y-%m-%d %H:%M:%S %%Z") assert_equal Time.utc(1999,12,31,17), twz assert_equal Time.utc(1999,12,31,12), twz.time assert_equal Time.utc(1999,12,31,17), twz.utc @@ -380,36 +380,36 @@ class TimeZoneTest < ActiveSupport::TestCase end def test_strptime_with_day_omitted - with_env_tz 'US/Eastern' do - zone = ActiveSupport::TimeZone['Eastern Time (US & Canada)'] - assert_equal Time.local(2000, 2, 1), zone.strptime('Feb', '%b', Time.local(2000, 1, 1)) - assert_equal Time.local(2005, 2, 1), zone.strptime('Feb 2005', '%b %Y', Time.local(2000, 1, 1)) - assert_equal Time.local(2005, 2, 2), zone.strptime('2 Feb 2005', '%e %b %Y', Time.local(2000, 1, 1)) + with_env_tz "US/Eastern" do + zone = ActiveSupport::TimeZone["Eastern Time (US & Canada)"] + assert_equal Time.local(2000, 2, 1), zone.strptime("Feb", "%b", Time.local(2000, 1, 1)) + assert_equal Time.local(2005, 2, 1), zone.strptime("Feb 2005", "%b %Y", Time.local(2000, 1, 1)) + assert_equal Time.local(2005, 2, 2), zone.strptime("2 Feb 2005", "%e %b %Y", Time.local(2000, 1, 1)) end end def test_strptime_with_malformed_string - with_env_tz 'US/Eastern' do - zone = ActiveSupport::TimeZone['Eastern Time (US & Canada)'] - assert_raise(ArgumentError) { zone.strptime('1999-12-31', '%Y/%m/%d') } + with_env_tz "US/Eastern" do + zone = ActiveSupport::TimeZone["Eastern Time (US & Canada)"] + assert_raise(ArgumentError) { zone.strptime("1999-12-31", "%Y/%m/%d") } end end def test_utc_offset_lazy_loaded_from_tzinfo_when_not_passed_in_to_initialize - tzinfo = TZInfo::Timezone.get('America/New_York') + tzinfo = TZInfo::Timezone.get("America/New_York") zone = ActiveSupport::TimeZone.create(tzinfo.name, nil, tzinfo) - assert_equal nil, zone.instance_variable_get('@utc_offset') + assert_equal nil, zone.instance_variable_get("@utc_offset") assert_equal(-18_000, zone.utc_offset) end def test_utc_offset_is_not_cached_when_current_period_gets_stale - tz = ActiveSupport::TimeZone.create('Moscow') + tz = ActiveSupport::TimeZone.create("Moscow") travel_to(Time.utc(2014, 10, 25, 21)) do # 1 hour before TZ change - assert_equal 14400, tz.utc_offset, 'utc_offset should be initialized according to current_period' + assert_equal 14400, tz.utc_offset, "utc_offset should be initialized according to current_period" end travel_to(Time.utc(2014, 10, 25, 22)) do # after TZ change - assert_equal 10800, tz.utc_offset, 'utc_offset should not be cached when current_period gets stale' + assert_equal 10800, tz.utc_offset, "utc_offset should not be cached when current_period gets stale" end end @@ -432,48 +432,48 @@ class TimeZoneTest < ActiveSupport::TestCase end def test_formatted_offset_positive - zone = ActiveSupport::TimeZone['New Delhi'] + zone = ActiveSupport::TimeZone["New Delhi"] assert_equal "+05:30", zone.formatted_offset assert_equal "+0530", zone.formatted_offset(false) end def test_formatted_offset_negative - zone = ActiveSupport::TimeZone['Eastern Time (US & Canada)'] + zone = ActiveSupport::TimeZone["Eastern Time (US & Canada)"] assert_equal "-05:00", zone.formatted_offset assert_equal "-0500", zone.formatted_offset(false) end def test_z_format_strings - zone = ActiveSupport::TimeZone['Tokyo'] + zone = ActiveSupport::TimeZone["Tokyo"] twz = zone.now - assert_equal '+0900', twz.strftime('%z') - assert_equal '+09:00', twz.strftime('%:z') - assert_equal '+09:00:00', twz.strftime('%::z') + assert_equal "+0900", twz.strftime("%z") + assert_equal "+09:00", twz.strftime("%:z") + assert_equal "+09:00:00", twz.strftime("%::z") end def test_formatted_offset_zero - zone = ActiveSupport::TimeZone['London'] + zone = ActiveSupport::TimeZone["London"] assert_equal "+00:00", zone.formatted_offset - assert_equal "UTC", zone.formatted_offset(true, 'UTC') + assert_equal "UTC", zone.formatted_offset(true, "UTC") end def test_zone_compare - zone1 = ActiveSupport::TimeZone['Central Time (US & Canada)'] # offset -0600 - zone2 = ActiveSupport::TimeZone['Eastern Time (US & Canada)'] # offset -0500 + zone1 = ActiveSupport::TimeZone["Central Time (US & Canada)"] # offset -0600 + zone2 = ActiveSupport::TimeZone["Eastern Time (US & Canada)"] # offset -0500 assert zone1 < zone2 assert zone2 > zone1 assert zone1 == zone1 end def test_zone_match - zone = ActiveSupport::TimeZone['Eastern Time (US & Canada)'] + zone = ActiveSupport::TimeZone["Eastern Time (US & Canada)"] assert zone =~ /Eastern/ assert zone =~ /New_York/ assert zone !~ /Nonexistent_Place/ end def test_to_s - assert_equal "(GMT+05:30) New Delhi", ActiveSupport::TimeZone['New Delhi'].to_s + assert_equal "(GMT+05:30) New Delhi", ActiveSupport::TimeZone["New Delhi"].to_s end def test_all_sorted diff --git a/activesupport/test/time_zone_test_helpers.rb b/activesupport/test/time_zone_test_helpers.rb index eb6f7d0f85..e1d615d154 100644 --- a/activesupport/test/time_zone_test_helpers.rb +++ b/activesupport/test/time_zone_test_helpers.rb @@ -7,11 +7,11 @@ module TimeZoneTestHelpers Time.zone = old_tz end - def with_env_tz(new_tz = 'US/Eastern') - old_tz, ENV['TZ'] = ENV['TZ'], new_tz + def with_env_tz(new_tz = "US/Eastern") + old_tz, ENV["TZ"] = ENV["TZ"], new_tz yield ensure - old_tz ? ENV['TZ'] = old_tz : ENV.delete('TZ') + old_tz ? ENV["TZ"] = old_tz : ENV.delete("TZ") end def with_preserve_timezone(value) diff --git a/activesupport/test/transliterate_test.rb b/activesupport/test/transliterate_test.rb index 378421fedd..040ddd25fc 100644 --- a/activesupport/test/transliterate_test.rb +++ b/activesupport/test/transliterate_test.rb @@ -1,5 +1,5 @@ -require 'abstract_unit' -require 'active_support/inflector/transliterate' +require "abstract_unit" +require "active_support/inflector/transliterate" class TransliterateTest < ActiveSupport::TestCase def test_transliterate_should_not_change_ascii_chars @@ -13,7 +13,7 @@ class TransliterateTest < ActiveSupport::TestCase # create string with range of Unicode's western characters with # diacritics, excluding the division and multiplication signs which for # some reason or other are floating in the middle of all the letters. - string = (0xC0..0x17E).to_a.reject {|c| [0xD7, 0xF7].include?(c)}.pack("U*") + string = (0xC0..0x17E).to_a.reject { |c| [0xD7, 0xF7].include?(c) }.pack("U*") string.each_char do |char| assert_match %r{^[a-zA-Z']*$}, ActiveSupport::Inflector.transliterate(char) end @@ -21,7 +21,7 @@ class TransliterateTest < ActiveSupport::TestCase def test_transliterate_should_work_with_custom_i18n_rules_and_uncomposed_utf8 char = [117, 776].pack("U*") # "ü" as ASCII "u" plus COMBINING DIAERESIS - I18n.backend.store_translations(:de, :i18n => {:transliterate => {:rule => {"ü" => "ue"}}}) + I18n.backend.store_translations(:de, i18n: { transliterate: { rule: { "ü" => "ue" } } }) default_locale, I18n.locale = I18n.locale, :de assert_equal "ue", ActiveSupport::Inflector.transliterate(char) ensure diff --git a/activesupport/test/xml_mini/jdom_engine_test.rb b/activesupport/test/xml_mini/jdom_engine_test.rb index 34e213b718..a776ad25c4 100644 --- a/activesupport/test/xml_mini/jdom_engine_test.rb +++ b/activesupport/test/xml_mini/jdom_engine_test.rb @@ -1,17 +1,16 @@ -if RUBY_PLATFORM.include?('java') - require 'abstract_unit' - require 'active_support/xml_mini' - require 'active_support/core_ext/hash/conversions' - +if RUBY_PLATFORM.include?("java") + require "abstract_unit" + require "active_support/xml_mini" + require "active_support/core_ext/hash/conversions" class JDOMEngineTest < ActiveSupport::TestCase include ActiveSupport - FILES_DIR = File.dirname(__FILE__) + '/../fixtures/xml' + FILES_DIR = File.dirname(__FILE__) + "/../fixtures/xml" def setup @default_backend = XmlMini.backend - XmlMini.backend = 'JDOM' + XmlMini.backend = "JDOM" end def teardown @@ -19,18 +18,18 @@ if RUBY_PLATFORM.include?('java') end def test_file_from_xml - hash = Hash.from_xml(<<-eoxml) + hash = Hash.from_xml(<<-eoxml) <blog> <logo type="file" name="logo.png" content_type="image/png"> </logo> </blog> 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 @@ -40,7 +39,7 @@ if RUBY_PLATFORM.include?('java') ]> <member>x&a;</member> EOT - assert_equal 'x', Hash.from_xml(attack_xml)["member"] + assert_equal "x", Hash.from_xml(attack_xml)["member"] end def test_not_allowed_to_expand_parameter_entities_to_files @@ -52,17 +51,16 @@ if RUBY_PLATFORM.include?('java') <member>x&a;</member> EOT assert_raise Java::OrgXmlSax::SAXParseException do - assert_equal 'x', Hash.from_xml(attack_xml)["member"] + assert_equal "x", Hash.from_xml(attack_xml)["member"] end end - def test_not_allowed_to_load_external_doctypes attack_xml = <<-EOT <!DOCTYPE member SYSTEM "file://#{FILES_DIR}/jdom_doctype.dtd"> <member>x&a;</member> EOT - assert_equal 'x', Hash.from_xml(attack_xml)["member"] + assert_equal "x", Hash.from_xml(attack_xml)["member"] end def test_exception_thrown_on_expansion_attack @@ -86,13 +84,13 @@ if RUBY_PLATFORM.include?('java') end def test_setting_JDOM_as_backend - XmlMini.backend = 'JDOM' + XmlMini.backend = "JDOM" assert_equal XmlMini_JDOM, XmlMini.backend end def test_blank_returns_empty_hash assert_equal({}, XmlMini.parse(nil)) - assert_equal({}, XmlMini.parse('')) + assert_equal({}, XmlMini.parse("")) end def test_array_type_makes_an_array @@ -178,7 +176,7 @@ if RUBY_PLATFORM.include?('java') private def assert_equal_rexml(xml) parsed_xml = XmlMini.parse(xml) - hash = XmlMini.with_backend('REXML') { XmlMini.parse(xml) } + hash = XmlMini.with_backend("REXML") { XmlMini.parse(xml) } assert_equal(hash, parsed_xml) end end diff --git a/activesupport/test/xml_mini/libxml_engine_test.rb b/activesupport/test/xml_mini/libxml_engine_test.rb index a8df2e1f7b..81b0d3c407 100644 --- a/activesupport/test/xml_mini/libxml_engine_test.rb +++ b/activesupport/test/xml_mini/libxml_engine_test.rb @@ -1,58 +1,58 @@ begin - require 'libxml' + require "libxml" 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 = %{<?xml version="1.0" encoding="UTF-8"?> - <!DOCTYPE member [ - <!ENTITY a "&b;&b;&b;&b;&b;&b;&b;&b;&b;&b;"> - <!ENTITY b "&c;&c;&c;&c;&c;&c;&c;&c;&c;&c;"> - <!ENTITY c "&d;&d;&d;&d;&d;&d;&d;&d;&d;&d;"> - <!ENTITY d "&e;&e;&e;&e;&e;&e;&e;&e;&e;&e;"> - <!ENTITY e "&f;&f;&f;&f;&f;&f;&f;&f;&f;&f;"> - <!ENTITY f "&g;&g;&g;&g;&g;&g;&g;&g;&g;&g;"> - <!ENTITY g "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"> - ]> - <member> - &a; - </member> - } - Hash.from_xml(attack_xml) + def test_exception_thrown_on_expansion_attack + assert_raise LibXML::XML::Error do + attack_xml = %{<?xml version="1.0" encoding="UTF-8"?> + <!DOCTYPE member [ + <!ENTITY a "&b;&b;&b;&b;&b;&b;&b;&b;&b;&b;"> + <!ENTITY b "&c;&c;&c;&c;&c;&c;&c;&c;&c;&c;"> + <!ENTITY c "&d;&d;&d;&d;&d;&d;&d;&d;&d;&d;"> + <!ENTITY d "&e;&e;&e;&e;&e;&e;&e;&e;&e;&e;"> + <!ENTITY e "&f;&f;&f;&f;&f;&f;&f;&f;&f;&f;"> + <!ENTITY f "&g;&g;&g;&g;&g;&g;&g;&g;&g;&g;"> + <!ENTITY g "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"> + ]> + <member> + &a; + </member> + } + 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) <blog> <posts type="array"> <post>a post</post> @@ -60,67 +60,67 @@ class LibxmlEngineTest < ActiveSupport::TestCase </posts> </blog> eoxml - end + end - def test_one_node_document_as_hash - assert_equal_rexml(<<-eoxml) - <products/> - eoxml - end + def test_one_node_document_as_hash + assert_equal_rexml(<<-eoxml) + <products/> + eoxml + end - def test_one_node_with_attributes_document_as_hash - assert_equal_rexml(<<-eoxml) - <products foo="bar"/> - eoxml - end + def test_one_node_with_attributes_document_as_hash + assert_equal_rexml(<<-eoxml) + <products foo="bar"/> + 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) <products> <book name="awesome" id="12345" /> </products> 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) <products> <book name="awesome" id="12345" /> <book name="america" id="67890" /> </products> 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) <products> hello world </products> eoxml - end + end - def test_children_with_children - assert_equal_rexml(<<-eoxml) + def test_children_with_children + assert_equal_rexml(<<-eoxml) <root> <products> <book name="america" id="67890" /> </products> </root> eoxml - end + end - def test_children_with_text - assert_equal_rexml(<<-eoxml) + def test_children_with_text + assert_equal_rexml(<<-eoxml) <root> <products> hello everyone </products> </root> 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) <root> good <products> @@ -129,10 +129,10 @@ class LibxmlEngineTest < ActiveSupport::TestCase morning </root> eoxml - end + end - def test_parse_from_io - io = StringIO.new(<<-eoxml) + def test_parse_from_io + io = StringIO.new(<<-eoxml) <root> good <products> @@ -141,31 +141,31 @@ class LibxmlEngineTest < ActiveSupport::TestCase morning </root> 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) <root> <products> <![CDATA[cdatablock]]> </products> </root> eoxml - end + end - def test_children_with_multiple_cdata - assert_equal_rexml(<<-eoxml) + def test_children_with_multiple_cdata + assert_equal_rexml(<<-eoxml) <root> <products> <![CDATA[cdatablock1]]><![CDATA[cdatablock2]]> </products> </root> 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) <root> <products> hello <![CDATA[cdatablock]]> @@ -173,32 +173,31 @@ class LibxmlEngineTest < ActiveSupport::TestCase </products> </root> eoxml - end + end - def test_children_with_blank_text - assert_equal_rexml(<<-eoxml) + def test_children_with_blank_text + assert_equal_rexml(<<-eoxml) <root> <products> </products> </root> 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) <root> <products type="file"> </products> </root> 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/libxmlsax_engine_test.rb b/activesupport/test/xml_mini/libxmlsax_engine_test.rb index d6d90639e2..e25fa2813c 100644 --- a/activesupport/test/xml_mini/libxmlsax_engine_test.rb +++ b/activesupport/test/xml_mini/libxmlsax_engine_test.rb @@ -1,27 +1,27 @@ begin - require 'libxml' + require "libxml" 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 <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE member [ <!ENTITY a "&b;&b;&b;&b;&b;&b;&b;&b;&b;&b;"> @@ -37,22 +37,22 @@ class LibXMLSAXEngineTest < ActiveSupport::TestCase </member> 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) <blog> <posts type="array"> <post>a post</post> @@ -60,67 +60,67 @@ class LibXMLSAXEngineTest < ActiveSupport::TestCase </posts> </blog> eoxml - end + end - def test_one_node_document_as_hash - assert_equal_rexml(<<-eoxml) - <products/> - eoxml - end + def test_one_node_document_as_hash + assert_equal_rexml(<<-eoxml) + <products/> + eoxml + end - def test_one_node_with_attributes_document_as_hash - assert_equal_rexml(<<-eoxml) - <products foo="bar"/> - eoxml - end + def test_one_node_with_attributes_document_as_hash + assert_equal_rexml(<<-eoxml) + <products foo="bar"/> + 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) <products> <book name="awesome" id="12345" /> </products> 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) <products> <book name="awesome" id="12345" /> <book name="america" id="67890" /> </products> 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) <products> hello world </products> eoxml - end + end - def test_children_with_children - assert_equal_rexml(<<-eoxml) + def test_children_with_children + assert_equal_rexml(<<-eoxml) <root> <products> <book name="america" id="67890" /> </products> </root> eoxml - end + end - def test_children_with_text - assert_equal_rexml(<<-eoxml) + def test_children_with_text + assert_equal_rexml(<<-eoxml) <root> <products> hello everyone </products> </root> 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) <root> good <products> @@ -129,10 +129,10 @@ class LibXMLSAXEngineTest < ActiveSupport::TestCase morning </root> eoxml - end + end - def test_parse_from_io - io = StringIO.new(<<-eoxml) + def test_parse_from_io + io = StringIO.new(<<-eoxml) <root> good <products> @@ -141,31 +141,31 @@ class LibXMLSAXEngineTest < ActiveSupport::TestCase morning </root> 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) <root> <products> <![CDATA[cdatablock]]> </products> </root> eoxml - end + end - def test_children_with_multiple_cdata - assert_equal_rexml(<<-eoxml) + def test_children_with_multiple_cdata + assert_equal_rexml(<<-eoxml) <root> <products> <![CDATA[cdatablock1]]><![CDATA[cdatablock2]]> </products> </root> 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) <root> <products> hello <![CDATA[cdatablock]]> @@ -173,23 +173,23 @@ class LibXMLSAXEngineTest < ActiveSupport::TestCase </products> </root> eoxml - end + end - def test_children_with_blank_text - assert_equal_rexml(<<-eoxml) + def test_children_with_blank_text + assert_equal_rexml(<<-eoxml) <root> <products> </products> </root> 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 1314c9065a..44b82da4e4 100644 --- a/activesupport/test/xml_mini/nokogiri_engine_test.rb +++ b/activesupport/test/xml_mini/nokogiri_engine_test.rb @@ -1,40 +1,40 @@ begin - require 'nokogiri' + require "nokogiri" 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) <blog> <logo type="file" name="logo.png" content_type="image/png"> </logo> </blog> 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 <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE member [ <!ENTITY a "&b;&b;&b;&b;&b;&b;&b;&b;&b;&b;"> @@ -49,22 +49,22 @@ class NokogiriEngineTest < ActiveSupport::TestCase &a; </member> 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) <blog> <posts type="array"> <post>a post</post> @@ -72,67 +72,67 @@ class NokogiriEngineTest < ActiveSupport::TestCase </posts> </blog> eoxml - end + end - def test_one_node_document_as_hash - assert_equal_rexml(<<-eoxml) - <products/> - eoxml - end + def test_one_node_document_as_hash + assert_equal_rexml(<<-eoxml) + <products/> + eoxml + end - def test_one_node_with_attributes_document_as_hash - assert_equal_rexml(<<-eoxml) - <products foo="bar"/> - eoxml - end + def test_one_node_with_attributes_document_as_hash + assert_equal_rexml(<<-eoxml) + <products foo="bar"/> + 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) <products> <book name="awesome" id="12345" /> </products> 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) <products> <book name="awesome" id="12345" /> <book name="america" id="67890" /> </products> 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) <products> hello world </products> eoxml - end + end - def test_children_with_children - assert_equal_rexml(<<-eoxml) + def test_children_with_children + assert_equal_rexml(<<-eoxml) <root> <products> <book name="america" id="67890" /> </products> </root> eoxml - end + end - def test_children_with_text - assert_equal_rexml(<<-eoxml) + def test_children_with_text + assert_equal_rexml(<<-eoxml) <root> <products> hello everyone </products> </root> 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) <root> good <products> @@ -141,10 +141,10 @@ class NokogiriEngineTest < ActiveSupport::TestCase morning </root> eoxml - end + end - def test_parse_from_io - io = StringIO.new(<<-eoxml) + def test_parse_from_io + io = StringIO.new(<<-eoxml) <root> good <products> @@ -153,31 +153,31 @@ class NokogiriEngineTest < ActiveSupport::TestCase morning </root> 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) <root> <products> <![CDATA[cdatablock]]> </products> </root> eoxml - end + end - def test_children_with_multiple_cdata - assert_equal_rexml(<<-eoxml) + def test_children_with_multiple_cdata + assert_equal_rexml(<<-eoxml) <root> <products> <![CDATA[cdatablock1]]><![CDATA[cdatablock2]]> </products> </root> 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) <root> <products> hello <![CDATA[cdatablock]]> @@ -185,31 +185,31 @@ class NokogiriEngineTest < ActiveSupport::TestCase </products> </root> eoxml - end + end - def test_children_with_blank_text - assert_equal_rexml(<<-eoxml) + def test_children_with_blank_text + assert_equal_rexml(<<-eoxml) <root> <products> </products> </root> 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) <root> <products type="file"> </products> </root> 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 7978a50921..24b35cadf6 100644 --- a/activesupport/test/xml_mini/nokogirisax_engine_test.rb +++ b/activesupport/test/xml_mini/nokogirisax_engine_test.rb @@ -1,40 +1,40 @@ begin - require 'nokogiri' + require "nokogiri" 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) <blog> <logo type="file" name="logo.png" content_type="image/png"> </logo> </blog> 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 <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE member [ <!ENTITY a "&b;&b;&b;&b;&b;&b;&b;&b;&b;&b;"> @@ -50,22 +50,22 @@ class NokogiriSAXEngineTest < ActiveSupport::TestCase </member> 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) <blog> <posts type="array"> <post>a post</post> @@ -73,67 +73,67 @@ class NokogiriSAXEngineTest < ActiveSupport::TestCase </posts> </blog> eoxml - end + end - def test_one_node_document_as_hash - assert_equal_rexml(<<-eoxml) - <products/> - eoxml - end + def test_one_node_document_as_hash + assert_equal_rexml(<<-eoxml) + <products/> + eoxml + end - def test_one_node_with_attributes_document_as_hash - assert_equal_rexml(<<-eoxml) - <products foo="bar"/> - eoxml - end + def test_one_node_with_attributes_document_as_hash + assert_equal_rexml(<<-eoxml) + <products foo="bar"/> + 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) <products> <book name="awesome" id="12345" /> </products> 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) <products> <book name="awesome" id="12345" /> <book name="america" id="67890" /> </products> 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) <products> hello world </products> eoxml - end + end - def test_children_with_children - assert_equal_rexml(<<-eoxml) + def test_children_with_children + assert_equal_rexml(<<-eoxml) <root> <products> <book name="america" id="67890" /> </products> </root> eoxml - end + end - def test_children_with_text - assert_equal_rexml(<<-eoxml) + def test_children_with_text + assert_equal_rexml(<<-eoxml) <root> <products> hello everyone </products> </root> 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) <root> good <products> @@ -142,10 +142,10 @@ class NokogiriSAXEngineTest < ActiveSupport::TestCase morning </root> eoxml - end + end - def test_parse_from_io - io = StringIO.new(<<-eoxml) + def test_parse_from_io + io = StringIO.new(<<-eoxml) <root> good <products> @@ -154,31 +154,31 @@ class NokogiriSAXEngineTest < ActiveSupport::TestCase morning </root> 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) <root> <products> <![CDATA[cdatablock]]> </products> </root> eoxml - end + end - def test_children_with_multiple_cdata - assert_equal_rexml(<<-eoxml) + def test_children_with_multiple_cdata + assert_equal_rexml(<<-eoxml) <root> <products> <![CDATA[cdatablock1]]><![CDATA[cdatablock2]]> </products> </root> 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) <root> <products> hello <![CDATA[cdatablock]]> @@ -186,31 +186,31 @@ class NokogiriSAXEngineTest < ActiveSupport::TestCase </products> </root> eoxml - end + end - def test_children_with_blank_text - assert_equal_rexml(<<-eoxml) + def test_children_with_blank_text + assert_equal_rexml(<<-eoxml) <root> <products> </products> </root> 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) <root> <products type="file"> </products> </root> 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 6e9ce7ac11..dc62f3f671 100644 --- a/activesupport/test/xml_mini/rexml_engine_test.rb +++ b/activesupport/test/xml_mini/rexml_engine_test.rb @@ -1,5 +1,5 @@ -require 'abstract_unit' -require 'active_support/xml_mini' +require "abstract_unit" +require "active_support/xml_mini" class REXMLEngineTest < ActiveSupport::TestCase def test_default_is_rexml @@ -7,12 +7,12 @@ class REXMLEngineTest < ActiveSupport::TestCase end def test_set_rexml_as_backend - ActiveSupport::XmlMini.backend = 'REXML' + ActiveSupport::XmlMini.backend = "REXML" assert_equal ActiveSupport::XmlMini_REXML, ActiveSupport::XmlMini.backend end def test_parse_from_io - ActiveSupport::XmlMini.backend = 'REXML' + ActiveSupport::XmlMini.backend = "REXML" io = StringIO.new(<<-eoxml) <root> good @@ -23,23 +23,22 @@ class REXMLEngineTest < ActiveSupport::TestCase </root> eoxml hash = ActiveSupport::XmlMini.parse(io) - 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__") - assert_match 'hello everyone', products['__content__'] + 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__") + assert_match "hello everyone", products["__content__"] end def test_parse_from_empty_string - ActiveSupport::XmlMini.backend = 'REXML' + ActiveSupport::XmlMini.backend = "REXML" assert_equal({}, ActiveSupport::XmlMini.parse("")) end def test_parse_from_frozen_string - ActiveSupport::XmlMini.backend = 'REXML' + ActiveSupport::XmlMini.backend = "REXML" xml_string = "<root></root>".freeze - assert_equal({"root" => {}}, ActiveSupport::XmlMini.parse(xml_string)) + assert_equal({ "root" => {} }, ActiveSupport::XmlMini.parse(xml_string)) end - end diff --git a/activesupport/test/xml_mini_test.rb b/activesupport/test/xml_mini_test.rb index 55e8181b54..b15ccfb764 100644 --- a/activesupport/test/xml_mini_test.rb +++ b/activesupport/test/xml_mini_test.rb @@ -1,9 +1,9 @@ -require 'abstract_unit' -require 'active_support/xml_mini' -require 'active_support/builder' -require 'active_support/core_ext/hash' -require 'active_support/core_ext/big_decimal' -require 'yaml' +require "abstract_unit" +require "active_support/xml_mini" +require "active_support/builder" +require "active_support/core_ext/hash" +require "active_support/core_ext/big_decimal" +require "yaml" module XmlMiniTest class RenameKeyTest < ActiveSupport::TestCase @@ -12,23 +12,23 @@ module XmlMiniTest end def test_rename_key_dasherizes_with_dasherize_true - assert_equal "my-key", ActiveSupport::XmlMini.rename_key("my_key", :dasherize => true) + assert_equal "my-key", ActiveSupport::XmlMini.rename_key("my_key", dasherize: true) end def test_rename_key_does_nothing_with_dasherize_false - assert_equal "my_key", ActiveSupport::XmlMini.rename_key("my_key", :dasherize => false) + assert_equal "my_key", ActiveSupport::XmlMini.rename_key("my_key", dasherize: false) end def test_rename_key_camelizes_with_camelize_true - assert_equal "MyKey", ActiveSupport::XmlMini.rename_key("my_key", :camelize => true) + assert_equal "MyKey", ActiveSupport::XmlMini.rename_key("my_key", camelize: true) end def test_rename_key_lower_camelizes_with_camelize_lower - assert_equal "myKey", ActiveSupport::XmlMini.rename_key("my_key", :camelize => :lower) + assert_equal "myKey", ActiveSupport::XmlMini.rename_key("my_key", camelize: :lower) end def test_rename_key_lower_camelizes_with_camelize_upper - assert_equal "MyKey", ActiveSupport::XmlMini.rename_key("my_key", :camelize => :upper) + assert_equal "MyKey", ActiveSupport::XmlMini.rename_key("my_key", camelize: :upper) end def test_rename_key_does_not_dasherize_leading_underscores @@ -63,16 +63,16 @@ module XmlMiniTest def setup @xml = ActiveSupport::XmlMini - @options = {:skip_instruct => true, :builder => Builder::XmlMarkup.new} + @options = { skip_instruct: true, builder: Builder::XmlMarkup.new } end test "#to_tag accepts a callable object and passes options with the builder" do - @xml.to_tag(:some_tag, lambda {|o| o[:builder].br }, @options) + @xml.to_tag(:some_tag, lambda { |o| o[:builder].br }, @options) assert_xml "<br/>" end test "#to_tag accepts a callable object and passes options and tag name" do - @xml.to_tag(:tag, lambda {|o, t| o[:builder].b(t) }, @options) + @xml.to_tag(:tag, lambda { |o, t| o[:builder].b(t) }, @options) assert_xml "<b>tag</b>" end @@ -92,7 +92,7 @@ module XmlMiniTest end test "#to_tag should use the type value in the options hash" do - @xml.to_tag(:b, "blue", @options.merge(type: 'color')) + @xml.to_tag(:b, "blue", @options.merge(type: "color")) assert_xml( "<b type=\"color\">blue</b>" ) end @@ -122,7 +122,7 @@ module XmlMiniTest end test "#to_tag accepts datetime types" do - @xml.to_tag(:b, DateTime.new(2001,2,3,4,5,6,'+7'), @options) + @xml.to_tag(:b, DateTime.new(2001,2,3,4,5,6,"+7"), @options) assert_xml( "<b type=\"dateTime\">2001-02-03T04:05:06+07:00</b>") end @@ -233,22 +233,22 @@ module XmlMiniTest end def test_symbol - parser = @parsing['symbol'] - assert_equal :symbol, parser.call('symbol') + parser = @parsing["symbol"] + assert_equal :symbol, parser.call("symbol") assert_equal :symbol, parser.call(:symbol) assert_equal :'123', parser.call(123) assert_raises(ArgumentError) { parser.call(Date.new(2013,11,12,02,11)) } end def test_date - parser = @parsing['date'] + parser = @parsing["date"] assert_equal Date.new(2013,11,12), parser.call("2013-11-12T0211Z") assert_raises(TypeError) { parser.call(1384190018) } assert_raises(ArgumentError) { parser.call("not really a date") } end def test_datetime - parser = @parsing['datetime'] + parser = @parsing["datetime"] assert_equal Time.new(2013,11,12,02,11,00,0), parser.call("2013-11-12T02:11:00Z") assert_equal DateTime.new(2013,11,12), parser.call("2013-11-12T0211Z") assert_equal DateTime.new(2013,11,12,02,11), parser.call("2013-11-12T02:11Z") @@ -257,7 +257,7 @@ module XmlMiniTest end def test_integer - parser = @parsing['integer'] + parser = @parsing["integer"] assert_equal 123, parser.call(123) assert_equal 123, parser.call(123.003) assert_equal 123, parser.call("123") @@ -266,7 +266,7 @@ module XmlMiniTest end def test_float - parser = @parsing['float'] + parser = @parsing["float"] assert_equal 123, parser.call("123") assert_equal 123.003, parser.call("123.003") assert_equal 123.0, parser.call("123,003") @@ -277,7 +277,7 @@ module XmlMiniTest end def test_decimal - parser = @parsing['decimal'] + parser = @parsing["decimal"] assert_equal 123, parser.call("123") assert_equal 123.003, parser.call("123.003") assert_equal 123.0, parser.call("123,003") @@ -288,7 +288,7 @@ module XmlMiniTest end def test_boolean - parser = @parsing['boolean'] + parser = @parsing["boolean"] [1, true, "1"].each do |value| assert parser.call(value) end @@ -299,7 +299,7 @@ module XmlMiniTest end def test_string - parser = @parsing['string'] + parser = @parsing["string"] assert_equal "123", parser.call(123) assert_equal "123", parser.call("123") assert_equal "[]", parser.call("[]") @@ -317,13 +317,13 @@ product: YAML expected = { "product"=> [ - {"sku"=>"BL394D", "quantity"=>4, "description"=>"Basketball"} + { "sku"=>"BL394D", "quantity"=>4, "description"=>"Basketball" } ] } - parser = @parsing['yaml'] + parser = @parsing["yaml"] assert_equal(expected, parser.call(yaml)) - assert_equal({1 => 'test'}, parser.call({1 => 'test'})) - assert_equal({"1 => 'test'"=>nil}, parser.call("{1 => 'test'}")) + assert_equal({ 1 => "test" }, parser.call(1 => "test")) + assert_equal({ "1 => 'test'"=>nil }, parser.call("{1 => 'test'}")) end def test_base64Binary_and_binary @@ -341,12 +341,12 @@ in the continued and indefatigable generation of knowledge, exceeds the short vehemence of any carnal pleasure. EXPECTED - parser = @parsing['base64Binary'] + parser = @parsing["base64Binary"] assert_equal expected_base64.gsub(/\n/," ").strip, parser.call(base64) parser.call("NON BASE64 INPUT") - parser = @parsing['binary'] - assert_equal expected_base64.gsub(/\n/," ").strip, parser.call(base64, 'encoding' => 'base64') + parser = @parsing["binary"] + assert_equal expected_base64.gsub(/\n/," ").strip, parser.call(base64, "encoding" => "base64") assert_equal "IGNORED INPUT", parser.call("IGNORED INPUT", {}) end end |