Skip to content
Browse files

Improve various test coverage. Closes #8676 [kamal]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@7117 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
1 parent 2cda509 commit 3aadfcef88e57b3f0a0bde9a2bc05d372e2fd93b @jeremy jeremy committed Jun 25, 2007
View
1 activesupport/test/clean_logger_test.rb
@@ -45,6 +45,7 @@ def test_datetime_format
@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
View
12 activesupport/test/core_ext/blank_test.rb
@@ -3,9 +3,21 @@
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
View
16 activesupport/test/core_ext/class/class_inheritable_attributes_test.rb
@@ -205,4 +205,20 @@ def test_array_inheritance_
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
View
10 activesupport/test/core_ext/class_test.rb
@@ -33,4 +33,14 @@ def test_removing_class_in_two_level_namespace
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
View
1 activesupport/test/core_ext/numeric_ext_test.rb
@@ -104,6 +104,7 @@ def test_chaining_duration_operations
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,
View
4 activesupport/test/json/decoding_test.rb
@@ -25,4 +25,8 @@ def test_json_decoding
end
end
end
+
+ def test_failed_json_decoding
+ assert_raises(ActiveSupport::JSON::ParseError) { ActiveSupport::JSON.decode(%({: 1})) }
+ end
end
View
9 activesupport/test/time_zone_test.rb
@@ -80,12 +80,19 @@ def test_all_sorted
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

0 comments on commit 3aadfce

Please sign in to comment.
Something went wrong with that request. Please try again.