aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/test/core_ext
diff options
context:
space:
mode:
Diffstat (limited to 'activesupport/test/core_ext')
-rw-r--r--activesupport/test/core_ext/array_ext_test.rb5
-rw-r--r--activesupport/test/core_ext/class/attribute_accessor_test.rb11
-rw-r--r--activesupport/test/core_ext/class/attribute_test.rb6
-rw-r--r--activesupport/test/core_ext/class/class_inheritable_attributes_test.rb230
-rw-r--r--activesupport/test/core_ext/date_ext_test.rb6
-rw-r--r--activesupport/test/core_ext/module/attr_accessor_with_default_test.rb39
-rw-r--r--activesupport/test/core_ext/module/attribute_accessor_test.rb7
-rw-r--r--activesupport/test/core_ext/string_ext_test.rb13
-rw-r--r--activesupport/test/core_ext/time_ext_test.rb20
9 files changed, 63 insertions, 274 deletions
diff --git a/activesupport/test/core_ext/array_ext_test.rb b/activesupport/test/core_ext/array_ext_test.rb
index 0e5407bc35..e532010b18 100644
--- a/activesupport/test/core_ext/array_ext_test.rb
+++ b/activesupport/test/core_ext/array_ext_test.rb
@@ -456,8 +456,9 @@ class ArrayWrapperTests < Test::Unit::TestCase
assert_equal [o], Array.wrap(o)
end
- def test_wrap_returns_nil_if_to_ary_returns_nil
- assert_nil Array.wrap(NilToAry.new)
+ def test_wrap_returns_wrapped_if_to_ary_returns_nil
+ o = NilToAry.new
+ assert_equal [o], Array.wrap(o)
end
def test_wrap_does_not_complain_if_to_ary_does_not_return_an_array
diff --git a/activesupport/test/core_ext/class/attribute_accessor_test.rb b/activesupport/test/core_ext/class/attribute_accessor_test.rb
index 456f4b7948..6b50f8db37 100644
--- a/activesupport/test/core_ext/class/attribute_accessor_test.rb
+++ b/activesupport/test/core_ext/class/attribute_accessor_test.rb
@@ -5,8 +5,9 @@ class ClassAttributeAccessorTest < Test::Unit::TestCase
def setup
@class = Class.new do
cattr_accessor :foo
- cattr_accessor :bar, :instance_writer => false
- cattr_reader :shaq, :instance_reader => false
+ cattr_accessor :bar, :instance_writer => false
+ cattr_reader :shaq, :instance_reader => false
+ cattr_accessor :camp, :instance_accessor => false
end
@object = @class.new
end
@@ -35,4 +36,10 @@ class ClassAttributeAccessorTest < Test::Unit::TestCase
assert_respond_to @class, :shaq
assert !@object.respond_to?(:shaq)
end
+
+ def test_should_not_create_instance_accessors
+ assert_respond_to @class, :camp
+ assert !@object.respond_to?(:camp)
+ assert !@object.respond_to?(:camp=)
+ end
end
diff --git a/activesupport/test/core_ext/class/attribute_test.rb b/activesupport/test/core_ext/class/attribute_test.rb
index d58b60482b..e290a6e012 100644
--- a/activesupport/test/core_ext/class/attribute_test.rb
+++ b/activesupport/test/core_ext/class/attribute_test.rb
@@ -60,6 +60,12 @@ class ClassAttributeTest < ActiveSupport::TestCase
assert_raise(NoMethodError) { object.setting = 'boom' }
end
+ 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 'works well with singleton classes' do
object = @klass.new
object.singleton_class.setting = 'foo'
diff --git a/activesupport/test/core_ext/class/class_inheritable_attributes_test.rb b/activesupport/test/core_ext/class/class_inheritable_attributes_test.rb
deleted file mode 100644
index 020dfce56a..0000000000
--- a/activesupport/test/core_ext/class/class_inheritable_attributes_test.rb
+++ /dev/null
@@ -1,230 +0,0 @@
-require 'abstract_unit'
-require 'active_support/core_ext/class/inheritable_attributes'
-
-class ClassInheritableAttributesTest < Test::Unit::TestCase
- def setup
- ActiveSupport::Deprecation.silenced = true
- @klass = Class.new
- end
-
- def teardown
- ActiveSupport::Deprecation.silenced = false
- end
-
- def test_reader_declaration
- assert_nothing_raised do
- @klass.class_inheritable_reader :a
- assert_respond_to @klass, :a
- assert_respond_to @klass.new, :a
- end
- end
-
- def test_writer_declaration
- assert_nothing_raised do
- @klass.class_inheritable_writer :a
- assert_respond_to @klass, :a=
- assert_respond_to @klass.new, :a=
- end
- end
-
- def test_writer_declaration_without_instance_writer
- assert_nothing_raised do
- @klass.class_inheritable_writer :a, :instance_writer => false
- assert_respond_to @klass, :a=
- assert !@klass.new.respond_to?(:a=)
- end
- end
-
- def test_accessor_declaration
- assert_nothing_raised do
- @klass.class_inheritable_accessor :a
- assert_respond_to @klass, :a
- assert_respond_to @klass.new, :a
- assert_respond_to @klass, :a=
- assert_respond_to @klass.new, :a=
- end
- end
-
- def test_accessor_declaration_without_instance_writer
- assert_nothing_raised do
- @klass.class_inheritable_accessor :a, :instance_writer => false
- assert_respond_to @klass, :a
- assert_respond_to @klass.new, :a
- assert_respond_to @klass, :a=
- assert !@klass.new.respond_to?(:a=)
- end
- end
-
- def test_array_declaration
- assert_nothing_raised do
- @klass.class_inheritable_array :a
- assert_respond_to @klass, :a
- assert_respond_to @klass.new, :a
- assert_respond_to @klass, :a=
- assert_respond_to @klass.new, :a=
- end
- end
-
- def test_array_declaration_without_instance_writer
- assert_nothing_raised do
- @klass.class_inheritable_array :a, :instance_writer => false
- assert_respond_to @klass, :a
- assert_respond_to @klass.new, :a
- assert_respond_to @klass, :a=
- assert !@klass.new.respond_to?(:a=)
- end
- end
-
- def test_hash_declaration
- assert_nothing_raised do
- @klass.class_inheritable_hash :a
- assert_respond_to @klass, :a
- assert_respond_to @klass.new, :a
- assert_respond_to @klass, :a=
- assert_respond_to @klass.new, :a=
- end
- end
-
- def test_hash_declaration_without_instance_writer
- assert_nothing_raised do
- @klass.class_inheritable_hash :a, :instance_writer => false
- assert_respond_to @klass, :a
- assert_respond_to @klass.new, :a
- assert_respond_to @klass, :a=
- assert !@klass.new.respond_to?(:a=)
- end
- end
-
- def test_reader
- @klass.class_inheritable_reader :a
- assert_nil @klass.a
- assert_nil @klass.new.a
-
- @klass.send(:write_inheritable_attribute, :a, 'a')
-
- assert_equal 'a', @klass.a
- assert_equal 'a', @klass.new.a
- assert_equal @klass.a, @klass.new.a
- assert_equal @klass.a.object_id, @klass.new.a.object_id
- end
-
- def test_writer
- @klass.class_inheritable_reader :a
- @klass.class_inheritable_writer :a
-
- assert_nil @klass.a
- assert_nil @klass.new.a
-
- @klass.a = 'a'
- assert_equal 'a', @klass.a
- @klass.new.a = 'A'
- assert_equal 'A', @klass.a
- end
-
- def test_array
- @klass.class_inheritable_array :a
-
- assert_nil @klass.a
- assert_nil @klass.new.a
-
- @klass.a = %w(a b c)
- assert_equal %w(a b c), @klass.a
- assert_equal %w(a b c), @klass.new.a
-
- @klass.new.a = %w(A B C)
- assert_equal %w(a b c A B C), @klass.a
- assert_equal %w(a b c A B C), @klass.new.a
- end
-
- def test_hash
- @klass.class_inheritable_hash :a
-
- assert_nil @klass.a
- assert_nil @klass.new.a
-
- @klass.a = { :a => 'a' }
- assert_equal({ :a => 'a' }, @klass.a)
- assert_equal({ :a => 'a' }, @klass.new.a)
-
- @klass.new.a = { :b => 'b' }
- assert_equal({ :a => 'a', :b => 'b' }, @klass.a)
- assert_equal({ :a => 'a', :b => 'b' }, @klass.new.a)
- end
-
- def test_inheritance
- @klass.class_inheritable_accessor :a
- @klass.a = 'a'
-
- @sub = eval("class FlogMe < @klass; end; FlogMe")
-
- @klass.class_inheritable_accessor :b
-
- assert_respond_to @sub, :a
- assert_respond_to @sub, :b
- assert_equal @klass.a, @sub.a
- assert_equal @klass.b, @sub.b
- assert_equal 'a', @sub.a
- assert_nil @sub.b
-
- @klass.b = 'b'
- assert_not_equal @klass.b, @sub.b
- assert_equal 'b', @klass.b
- assert_nil @sub.b
-
- @sub.a = 'A'
- assert_not_equal @klass.a, @sub.a
- assert_equal 'a', @klass.a
- assert_equal 'A', @sub.a
-
- @sub.b = 'B'
- assert_not_equal @klass.b, @sub.b
- assert_equal 'b', @klass.b
- assert_equal 'B', @sub.b
- end
-
- def test_array_inheritance
- @klass.class_inheritable_accessor :a
- @klass.a = []
-
- @sub = eval("class SubbyArray < @klass; end; SubbyArray")
-
- assert_equal [], @klass.a
- assert_equal [], @sub.a
-
- @sub.a << :first
-
- assert_equal [:first], @sub.a
- assert_equal [], @klass.a
- end
-
- def test_array_inheritance_
- @klass.class_inheritable_accessor :a
- @klass.a = {}
-
- @sub = eval("class SubbyHash < @klass; end; SubbyHash")
-
- assert_equal Hash.new, @klass.a
- assert_equal Hash.new, @sub.a
-
- @sub.a[:first] = :first
-
- 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_nil @klass.a
- assert_nil @sub.a
- end
-end
diff --git a/activesupport/test/core_ext/date_ext_test.rb b/activesupport/test/core_ext/date_ext_test.rb
index d81693209f..b4f848cd44 100644
--- a/activesupport/test/core_ext/date_ext_test.rb
+++ b/activesupport/test/core_ext/date_ext_test.rb
@@ -454,4 +454,10 @@ class DateExtBehaviorTest < Test::Unit::TestCase
Date.today.freeze.inspect
end
end
+
+ def test_can_freeze_twice
+ assert_nothing_raised do
+ Date.today.freeze.freeze
+ end
+ end
end
diff --git a/activesupport/test/core_ext/module/attr_accessor_with_default_test.rb b/activesupport/test/core_ext/module/attr_accessor_with_default_test.rb
deleted file mode 100644
index 0ecd16b051..0000000000
--- a/activesupport/test/core_ext/module/attr_accessor_with_default_test.rb
+++ /dev/null
@@ -1,39 +0,0 @@
-require 'abstract_unit'
-require 'active_support/core_ext/module/attr_accessor_with_default'
-
-class AttrAccessorWithDefaultTest < ActiveSupport::TestCase
- def setup
- @target = Class.new do
- def helper
- 'helper'
- end
- end
- @instance = @target.new
- end
-
- def test_default_arg
- assert_deprecated do
- @target.attr_accessor_with_default :foo, :bar
- end
- assert_equal(:bar, @instance.foo)
- @instance.foo = nil
- assert_nil(@instance.foo)
- end
-
- def test_default_proc
- assert_deprecated do
- @target.attr_accessor_with_default(:foo) {helper.upcase}
- end
- assert_equal('HELPER', @instance.foo)
- @instance.foo = nil
- assert_nil(@instance.foo)
- end
-
- def test_invalid_args
- assert_raise(ArgumentError) do
- assert_deprecated do
- @target.attr_accessor_with_default :foo
- end
- end
- 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 118fb070a0..29889b51e0 100644
--- a/activesupport/test/core_ext/module/attribute_accessor_test.rb
+++ b/activesupport/test/core_ext/module/attribute_accessor_test.rb
@@ -7,6 +7,7 @@ class ModuleAttributeAccessorTest < Test::Unit::TestCase
mattr_accessor :foo
mattr_accessor :bar, :instance_writer => false
mattr_reader :shaq, :instance_reader => false
+ mattr_accessor :camp, :instance_accessor => false
end
@class = Class.new
@class.instance_eval { include m }
@@ -37,4 +38,10 @@ class ModuleAttributeAccessorTest < Test::Unit::TestCase
assert_respond_to @module, :shaq
assert !@object.respond_to?(:shaq)
end
+
+ def test_should_not_create_instance_accessors
+ assert_respond_to @module, :camp
+ assert !@object.respond_to?(:camp)
+ assert !@object.respond_to?(:camp=)
+ end
end
diff --git a/activesupport/test/core_ext/string_ext_test.rb b/activesupport/test/core_ext/string_ext_test.rb
index 32675c884a..4000cc913a 100644
--- a/activesupport/test/core_ext/string_ext_test.rb
+++ b/activesupport/test/core_ext/string_ext_test.rb
@@ -158,6 +158,7 @@ class StringInflectionsTest < Test::Unit::TestCase
assert_equal Time.local(2005, 2, 27, 23, 50, 19, 275038), "2005-02-27T23:50:19.275038".to_time(:local)
assert_equal DateTime.civil(2039, 2, 27, 23, 50), "2039-02-27 23:50".to_time
assert_equal Time.local_time(2039, 2, 27, 23, 50), "2039-02-27 23:50".to_time(:local)
+ assert_equal Time.utc(2039, 2, 27, 23, 50), "2039-02-27 22:50 -0100".to_time
assert_nil "".to_time
end
@@ -251,7 +252,7 @@ class StringInflectionsTest < Test::Unit::TestCase
# And changes the original string:
assert_equal original, expected
end
-
+
def test_string_inquiry
assert "production".inquiry.production?
assert !"production".inquiry.development?
@@ -353,6 +354,10 @@ class OutputSafetyTest < ActiveSupport::TestCase
test "A fixnum is safe by default" do
assert 5.html_safe?
end
+
+ test "a float is safe by default" do
+ assert 5.7.html_safe?
+ end
test "An object is unsafe by default" do
assert !@object.html_safe?
@@ -451,6 +456,12 @@ class OutputSafetyTest < ActiveSupport::TestCase
assert !'ruby'.encoding_aware?
end
end
+
+ test "call to_param returns a normal string" do
+ string = @string.html_safe
+ assert string.html_safe?
+ assert !string.to_param.html_safe?
+ end
end
class StringExcludeTest < ActiveSupport::TestCase
diff --git a/activesupport/test/core_ext/time_ext_test.rb b/activesupport/test/core_ext/time_ext_test.rb
index 44e02109b1..c4c4381957 100644
--- a/activesupport/test/core_ext/time_ext_test.rb
+++ b/activesupport/test/core_ext/time_ext_test.rb
@@ -767,6 +767,26 @@ class TimeExtCalculationsTest < ActiveSupport::TestCase
assert_equal false, Time === DateTime.civil(2000)
end
+ def test_all_day
+ assert_equal Time.local(2011,6,7,0,0,0)..Time.local(2011,6,7,23,59,59,999999.999), Time.local(2011,6,7,10,10,10).all_day
+ end
+
+ def test_all_week
+ assert_equal Time.local(2011,6,6,0,0,0)..Time.local(2011,6,12,23,59,59,999999.999), Time.local(2011,6,7,10,10,10).all_week
+ end
+
+ def test_all_month
+ assert_equal Time.local(2011,6,1,0,0,0)..Time.local(2011,6,30,23,59,59,999999.999), Time.local(2011,6,7,10,10,10).all_month
+ end
+
+ def test_all_quarter
+ assert_equal Time.local(2011,4,1,0,0,0)..Time.local(2011,6,30,23,59,59,999999.999), Time.local(2011,6,7,10,10,10).all_quarter
+ end
+
+ def test_all_year
+ assert_equal Time.local(2011,1,1,0,0,0)..Time.local(2011,12,31,23,59,59,999999.999), Time.local(2011,6,7,10,10,10).all_year
+ end
+
protected
def with_env_tz(new_tz = 'US/Eastern')
old_tz, ENV['TZ'] = ENV['TZ'], new_tz