aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport
diff options
context:
space:
mode:
authorJosé Valim <jose.valim@gmail.com>2011-05-16 11:19:11 -0400
committerJosé Valim <jose.valim@gmail.com>2011-05-16 11:31:34 -0400
commit673372152032a886ba9196c69348386834590eab (patch)
tree4c2b85f05c084d91e916091924f510593bda87c9 /activesupport
parent40fa51123d47053da9b5ed7d38ba7c1b6432a651 (diff)
downloadrails-673372152032a886ba9196c69348386834590eab.tar.gz
rails-673372152032a886ba9196c69348386834590eab.tar.bz2
rails-673372152032a886ba9196c69348386834590eab.zip
Deprecate attr_accessor_with_default.
Diffstat (limited to 'activesupport')
-rw-r--r--activesupport/lib/active_support/core_ext/module/attr_accessor_with_default.rb1
-rw-r--r--activesupport/test/core_ext/module/attr_accessor_with_default_test.rb16
2 files changed, 13 insertions, 4 deletions
diff --git a/activesupport/lib/active_support/core_ext/module/attr_accessor_with_default.rb b/activesupport/lib/active_support/core_ext/module/attr_accessor_with_default.rb
index e3259a0a84..984f6fb957 100644
--- a/activesupport/lib/active_support/core_ext/module/attr_accessor_with_default.rb
+++ b/activesupport/lib/active_support/core_ext/module/attr_accessor_with_default.rb
@@ -19,6 +19,7 @@ class Module
# attr_accessor_with_default(:element_name) { name.underscore }
#
def attr_accessor_with_default(sym, default = Proc.new)
+ ActiveSupport::Deprecation.warn "attr_accessor_with_default is deprecated. Use Ruby instead!"
define_method(sym, block_given? ? default : Proc.new { default })
module_eval(<<-EVAL, __FILE__, __LINE__ + 1)
def #{sym}=(value) # def age=(value)
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
index b9b60c4d6d..0ecd16b051 100644
--- a/activesupport/test/core_ext/module/attr_accessor_with_default_test.rb
+++ b/activesupport/test/core_ext/module/attr_accessor_with_default_test.rb
@@ -1,7 +1,7 @@
require 'abstract_unit'
require 'active_support/core_ext/module/attr_accessor_with_default'
-class AttrAccessorWithDefaultTest < Test::Unit::TestCase
+class AttrAccessorWithDefaultTest < ActiveSupport::TestCase
def setup
@target = Class.new do
def helper
@@ -12,20 +12,28 @@ class AttrAccessorWithDefaultTest < Test::Unit::TestCase
end
def test_default_arg
- @target.attr_accessor_with_default :foo, :bar
+ 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
- @target.attr_accessor_with_default(:foo) {helper.upcase}
+ 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) {@target.attr_accessor_with_default :foo}
+ assert_raise(ArgumentError) do
+ assert_deprecated do
+ @target.attr_accessor_with_default :foo
+ end
+ end
end
end