aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeremy Kemper <jeremy@bitsweat.net>2007-06-25 18:22:31 +0000
committerJeremy Kemper <jeremy@bitsweat.net>2007-06-25 18:22:31 +0000
commit3aadfcef88e57b3f0a0bde9a2bc05d372e2fd93b (patch)
tree9b1e05803d0c60aa39a3ff6a037bf77fb9f4a164
parent2cda5096b8c02b1fbabc2857472ee03d7ecfe047 (diff)
downloadrails-3aadfcef88e57b3f0a0bde9a2bc05d372e2fd93b.tar.gz
rails-3aadfcef88e57b3f0a0bde9a2bc05d372e2fd93b.tar.bz2
rails-3aadfcef88e57b3f0a0bde9a2bc05d372e2fd93b.zip
Improve various test coverage. Closes #8676 [kamal]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@7117 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
-rw-r--r--activesupport/test/clean_logger_test.rb1
-rw-r--r--activesupport/test/core_ext/blank_test.rb12
-rw-r--r--activesupport/test/core_ext/class/class_inheritable_attributes_test.rb16
-rw-r--r--activesupport/test/core_ext/class_test.rb10
-rw-r--r--activesupport/test/core_ext/numeric_ext_test.rb1
-rw-r--r--activesupport/test/json/decoding_test.rb4
-rw-r--r--activesupport/test/time_zone_test.rb9
7 files changed, 52 insertions, 1 deletions
diff --git a/activesupport/test/clean_logger_test.rb b/activesupport/test/clean_logger_test.rb
index b972869c90..cf7b5c6036 100644
--- a/activesupport/test/clean_logger_test.rb
+++ b/activesupport/test/clean_logger_test.rb
@@ -45,6 +45,7 @@ class CleanLoggerTest < Test::Unit::TestCase
@logger.formatter = Logger::Formatter.new
@logger.datetime_format = "%Y-%m-%d"
@logger.debug 'debug'
+ assert_equal "%Y-%m-%d", @logger.datetime_format
assert_match(/D, \[\d\d\d\d-\d\d-\d\d#\d+\] DEBUG -- : debug/, @out.string)
end
end
diff --git a/activesupport/test/core_ext/blank_test.rb b/activesupport/test/core_ext/blank_test.rb
index 0fce470fd5..76a0b39978 100644
--- a/activesupport/test/core_ext/blank_test.rb
+++ b/activesupport/test/core_ext/blank_test.rb
@@ -3,9 +3,21 @@ require File.dirname(__FILE__) + '/../abstract_unit'
class BlankTest < Test::Unit::TestCase
BLANK = [nil, false, '', ' ', " \n\t \r ", [], {}]
NOT = [true, 0, 1, 'a', [nil], { nil => 0 }]
+
+ class EmptyObject
+ def empty?
+ true
+ end
+ alias :strip :empty?
+ end
+ class NoStripObject < EmptyObject; undef :strip; end
+ class NoEmptyStripObject < NoStripObject; undef :empty?; end
def test_blank
BLANK.each { |v| assert v.blank? }
NOT.each { |v| assert !v.blank? }
+ assert EmptyObject.new.blank?
+ assert NoStripObject.new.blank?
+ assert !NoEmptyStripObject.new.blank?
end
end
diff --git a/activesupport/test/core_ext/class/class_inheritable_attributes_test.rb b/activesupport/test/core_ext/class/class_inheritable_attributes_test.rb
index 8b11e680af..c0bb7acb3d 100644
--- a/activesupport/test/core_ext/class/class_inheritable_attributes_test.rb
+++ b/activesupport/test/core_ext/class/class_inheritable_attributes_test.rb
@@ -205,4 +205,20 @@ class ClassInheritableAttributesTest < Test::Unit::TestCase
assert_equal 1, @sub.a.keys.size
assert_equal 0, @klass.a.keys.size
end
+
+ def test_reset_inheritable_attributes
+ @klass.class_inheritable_accessor :a
+ @klass.a = 'a'
+
+ @sub = eval("class Inheriting < @klass; end; Inheriting")
+
+ assert_equal 'a', @klass.a
+ assert_equal 'a', @sub.a
+
+ @klass.reset_inheritable_attributes
+ @sub = eval("class NotInheriting < @klass; end; NotInheriting")
+
+ assert_equal nil, @klass.a
+ assert_equal nil, @sub.a
+ end
end
diff --git a/activesupport/test/core_ext/class_test.rb b/activesupport/test/core_ext/class_test.rb
index bcb96f5e33..e1b38a1e07 100644
--- a/activesupport/test/core_ext/class_test.rb
+++ b/activesupport/test/core_ext/class_test.rb
@@ -33,4 +33,14 @@ class ClassTest < Test::Unit::TestCase
Class.remove_class(Y::Z::C)
assert_raises(NameError) { Y::Z::C.is_a?(Class) }
end
+
+ def test_retrieving_subclasses
+ @parent = eval("class D; end; D")
+ @sub = eval("class E < D; end; E")
+ @subofsub = eval("class F < E; end; F")
+ assert @parent.subclasses.all? { |i| [@sub.to_s, @subofsub.to_s].include?(i) }
+ assert_equal 2, @parent.subclasses.size
+ assert_equal [@subofsub.to_s], @sub.subclasses
+ assert_equal [], @subofsub.subclasses
+ end
end
diff --git a/activesupport/test/core_ext/numeric_ext_test.rb b/activesupport/test/core_ext/numeric_ext_test.rb
index e69704878b..bbbd706aa1 100644
--- a/activesupport/test/core_ext/numeric_ext_test.rb
+++ b/activesupport/test/core_ext/numeric_ext_test.rb
@@ -104,6 +104,7 @@ end
class NumericExtSizeTest < Test::Unit::TestCase
def test_unit_in_terms_of_another
relationships = {
+ 1024.bytes => 1.kilobyte,
1024.kilobytes => 1.megabyte,
3584.0.kilobytes => 3.5.megabytes,
3584.0.megabytes => 3.5.gigabytes,
diff --git a/activesupport/test/json/decoding_test.rb b/activesupport/test/json/decoding_test.rb
index 77253b6dad..acdde21858 100644
--- a/activesupport/test/json/decoding_test.rb
+++ b/activesupport/test/json/decoding_test.rb
@@ -25,4 +25,8 @@ class TestJSONDecoding < Test::Unit::TestCase
end
end
end
+
+ def test_failed_json_decoding
+ assert_raises(ActiveSupport::JSON::ParseError) { ActiveSupport::JSON.decode(%({: 1})) }
+ end
end
diff --git a/activesupport/test/time_zone_test.rb b/activesupport/test/time_zone_test.rb
index 3cdf5582bf..080ccef8ac 100644
--- a/activesupport/test/time_zone_test.rb
+++ b/activesupport/test/time_zone_test.rb
@@ -80,12 +80,19 @@ class TimeZoneTest < Test::Unit::TestCase
def test_index
assert_nil TimeZone["bogus"]
assert_not_nil TimeZone["Central Time (US & Canada)"]
+ assert_not_nil TimeZone[8]
+ assert_raises(ArgumentError) { TimeZone[false] }
end
-
+
def test_new
a = TimeZone.new("Berlin")
b = TimeZone.new("Berlin")
assert_same a, b
assert_nil TimeZone.new("bogus")
end
+
+ def test_us_zones
+ assert TimeZone.us_zones.include?(TimeZone["Hawaii"])
+ assert !TimeZone.us_zones.include?(TimeZone["Kuala Lumpur"])
+ end
end