diff options
Diffstat (limited to 'activesupport/test')
-rw-r--r-- | activesupport/test/core_ext/time_with_zone_test.rb | 7 | ||||
-rw-r--r-- | activesupport/test/descendants_tracker_test.rb | 75 | ||||
-rw-r--r-- | activesupport/test/file_update_checker_test.rb | 56 | ||||
-rw-r--r-- | activesupport/test/multibyte_chars_test.rb | 14 |
4 files changed, 152 insertions, 0 deletions
diff --git a/activesupport/test/core_ext/time_with_zone_test.rb b/activesupport/test/core_ext/time_with_zone_test.rb index 2cf5bd6ea9..cf11f4d28f 100644 --- a/activesupport/test/core_ext/time_with_zone_test.rb +++ b/activesupport/test/core_ext/time_with_zone_test.rb @@ -737,6 +737,13 @@ class TimeWithZoneMethodsForTimeAndDateTimeTest < Test::Unit::TestCase end end + 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' + 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 diff --git a/activesupport/test/descendants_tracker_test.rb b/activesupport/test/descendants_tracker_test.rb new file mode 100644 index 0000000000..3a424180de --- /dev/null +++ b/activesupport/test/descendants_tracker_test.rb @@ -0,0 +1,75 @@ +require 'abstract_unit' +require 'test/unit' +require 'active_support' +require 'active_support/core_ext/hash/slice' + +class DescendantsTrackerTest < Test::Unit::TestCase + class Parent + extend ActiveSupport::DescendantsTracker + end + + class Child1 < Parent + end + + class Child2 < Parent + end + + class Grandchild1 < Child1 + end + + class Grandchild2 < Child1 + end + + ALL = [Parent, Child1, Child2, Grandchild1, Grandchild2] + + def test_descendants + assert_equal [Child1, Grandchild1, Grandchild2, Child2], Parent.descendants + assert_equal [Grandchild1, Grandchild2], Child1.descendants + assert_equal [], Child2.descendants + end + + def test_direct_descendants + assert_equal [Child1, Child2], Parent.direct_descendants + assert_equal [Grandchild1, Grandchild2], Child1.direct_descendants + assert_equal [], Child2.direct_descendants + end + + def test_clear_with_autoloaded_parent_children_and_granchildren + mark_as_autoloaded *ALL do + ActiveSupport::DescendantsTracker.clear + assert ActiveSupport::DescendantsTracker.descendants.slice(*ALL).empty? + end + end + + def test_clear_with_autoloaded_children_and_granchildren + mark_as_autoloaded Child1, Grandchild1, Grandchild2 do + ActiveSupport::DescendantsTracker.clear + assert_equal [Child2], Parent.descendants + assert_equal [], Child2.descendants + end + end + + def test_clear_with_autoloaded_granchildren + mark_as_autoloaded Grandchild1, Grandchild2 do + ActiveSupport::DescendantsTracker.clear + assert_equal [Child1, Child2], Parent.descendants + assert_equal [], Child1.descendants + assert_equal [], Child2.descendants + end + end + + protected + + def mark_as_autoloaded(*klasses) + old_autoloaded = ActiveSupport::Dependencies.autoloaded_constants.dup + ActiveSupport::Dependencies.autoloaded_constants = klasses.map(&:name) + + old_descendants = ActiveSupport::DescendantsTracker.descendants.dup + old_descendants.each { |k, v| old_descendants[k] = v.dup } + + yield + ensure + ActiveSupport::Dependencies.autoloaded_constants = old_autoloaded + ActiveSupport::DescendantsTracker.descendants.replace(old_descendants) + end +end
\ No newline at end of file diff --git a/activesupport/test/file_update_checker_test.rb b/activesupport/test/file_update_checker_test.rb new file mode 100644 index 0000000000..baf29cc337 --- /dev/null +++ b/activesupport/test/file_update_checker_test.rb @@ -0,0 +1,56 @@ +require 'abstract_unit' +require 'test/unit' +require 'active_support' +require 'fileutils' + +MTIME_FIXTURES_PATH = File.expand_path("../fixtures", __FILE__) + +class FileUpdateCheckerTest < Test::Unit::TestCase + FILES = %w(1.txt 2.txt 3.txt) + + def setup + FileUtils.touch(FILES) + end + + def teardown + FileUtils.rm(FILES) + end + + def test_should_not_execute_the_block_if_no_paths_are_given + i = 0 + checker = ActiveSupport::FileUpdateChecker.new([]){ i += 1 } + checker.execute_if_updated + assert_equal 0, i + end + + def test_should_invoke_the_block_on_first_call_if_it_does_not_calculate_last_updated_at_on_load + i = 0 + checker = ActiveSupport::FileUpdateChecker.new(FILES){ i += 1 } + checker.execute_if_updated + assert_equal 1, i + end + + def test_should_not_invoke_the_block_on_first_call_if_it_calculates_last_updated_at_on_load + i = 0 + checker = ActiveSupport::FileUpdateChecker.new(FILES, true){ i += 1 } + checker.execute_if_updated + assert_equal 0, i + end + + def test_should_not_invoke_the_block_if_no_file_has_changed + i = 0 + checker = ActiveSupport::FileUpdateChecker.new(FILES){ i += 1 } + 5.times { checker.execute_if_updated } + assert_equal 1, i + end + + def test_should_invoke_the_block_if_a_file_has_changed + i = 0 + checker = ActiveSupport::FileUpdateChecker.new(FILES){ i += 1 } + checker.execute_if_updated + sleep(1) + FileUtils.touch(FILES) + checker.execute_if_updated + assert_equal 2, i + end +end diff --git a/activesupport/test/multibyte_chars_test.rb b/activesupport/test/multibyte_chars_test.rb index f7a5834527..602828ef5f 100644 --- a/activesupport/test/multibyte_chars_test.rb +++ b/activesupport/test/multibyte_chars_test.rb @@ -443,6 +443,11 @@ class MultibyteCharsUTF8BehaviourTest < Test::Unit::TestCase 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 + 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 @@ -480,6 +485,15 @@ class MultibyteCharsExtrasTest < Test::Unit::TestCase end end + def test_titleize_should_be_unicode_aware + assert_equal "Él Que Se Enteró", chars("ÉL QUE SE ENTERÓ").titleize + assert_equal "Абвг Абвг", chars("аБвг аБвг").titleize + end + + def test_titleize_should_not_affect_characters_that_do_not_case_fold + assert_equal "日本語", chars("日本語").titleize + end + def test_limit_should_not_break_on_blank_strings example = chars('') assert_equal example, example.limit(0) |