From 5ae7a9d31d6222b265013ab450f9d30b88113e69 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Thu, 17 Jun 2010 14:10:51 -0700 Subject: when the timezone is nil, a TimeWithZone object should not be constructed. [#4881 state:resolved] Signed-off-by: Jeremy Kemper --- activesupport/test/core_ext/time_with_zone_test.rb | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'activesupport/test') 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 -- cgit v1.2.3 From 8db8c6f4ce3e8dd7f90553ab7866bf9991773b98 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Sat, 19 Jun 2010 16:44:35 +0200 Subject: Add ActiveSupport::DescendantsTracker. --- activesupport/test/descendants_tracker_test.rb | 72 ++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 activesupport/test/descendants_tracker_test.rb (limited to 'activesupport/test') diff --git a/activesupport/test/descendants_tracker_test.rb b/activesupport/test/descendants_tracker_test.rb new file mode 100644 index 0000000000..57c97b45d2 --- /dev/null +++ b/activesupport/test/descendants_tracker_test.rb @@ -0,0 +1,72 @@ +require 'abstract_unit' +require 'test/unit' +require 'active_support' + +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 + + 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 Parent, Child1, Child2, Grandchild1, Grandchild2 do + ActiveSupport::DescendantsTracker.clear + assert_equal Hash.new, ActiveSupport::DescendantsTracker.descendants + 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 = old_descendants + end +end \ No newline at end of file -- cgit v1.2.3 From a2b7fcb07ca47ca2285dee2afe97050532e94d07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Sat, 19 Jun 2010 16:58:12 +0200 Subject: Change callbacks to automatically include DescendantsTracker and rename descendents to descendants. --- activesupport/test/descendants_tracker_test.rb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'activesupport/test') diff --git a/activesupport/test/descendants_tracker_test.rb b/activesupport/test/descendants_tracker_test.rb index 57c97b45d2..e3eccb8aa9 100644 --- a/activesupport/test/descendants_tracker_test.rb +++ b/activesupport/test/descendants_tracker_test.rb @@ -1,6 +1,7 @@ require 'abstract_unit' require 'test/unit' require 'active_support' +require 'active_support/core_ext/hash/slice' class DescendantsTrackerTest < Test::Unit::TestCase class Parent @@ -19,6 +20,8 @@ class DescendantsTrackerTest < Test::Unit::TestCase 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 @@ -32,9 +35,9 @@ class DescendantsTrackerTest < Test::Unit::TestCase end def test_clear_with_autoloaded_parent_children_and_granchildren - mark_as_autoloaded Parent, Child1, Child2, Grandchild1, Grandchild2 do + mark_as_autoloaded *ALL do ActiveSupport::DescendantsTracker.clear - assert_equal Hash.new, ActiveSupport::DescendantsTracker.descendants + assert ActiveSupport::DescendantsTracker.descendants.slice(*ALL).empty? end end -- cgit v1.2.3 From d430db9fd407fd6aee25ca13538d8988dc7ee297 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Sat, 19 Jun 2010 17:16:11 +0200 Subject: Remove descendants warning while executing tests. --- activesupport/test/descendants_tracker_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'activesupport/test') diff --git a/activesupport/test/descendants_tracker_test.rb b/activesupport/test/descendants_tracker_test.rb index e3eccb8aa9..3a424180de 100644 --- a/activesupport/test/descendants_tracker_test.rb +++ b/activesupport/test/descendants_tracker_test.rb @@ -70,6 +70,6 @@ class DescendantsTrackerTest < Test::Unit::TestCase yield ensure ActiveSupport::Dependencies.autoloaded_constants = old_autoloaded - ActiveSupport::DescendantsTracker.descendants = old_descendants + ActiveSupport::DescendantsTracker.descendants.replace(old_descendants) end end \ No newline at end of file -- cgit v1.2.3 From 667522ca9834ce1f173a3421fb0bf0f555324c6f Mon Sep 17 00:00:00 2001 From: Norman Clarke Date: Fri, 28 May 2010 16:36:22 -0300 Subject: Adds titleize/titlecase to AS::Multibyte::Chars MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit [#2794 state:resolved] Signed-off-by: José Valim --- activesupport/test/multibyte_chars_test.rb | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'activesupport/test') 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) -- cgit v1.2.3 From 71703c98ba2bf65a6fed94917b039827cb63bace Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Sun, 20 Jun 2010 13:26:42 +0200 Subject: Add ActiveSupport::FileUpdateChecker. --- activesupport/test/file_update_checker_test.rb | 56 ++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 activesupport/test/file_update_checker_test.rb (limited to 'activesupport/test') 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 -- cgit v1.2.3