aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support
diff options
context:
space:
mode:
authorVijay Dev <vijaydev.cse@gmail.com>2012-06-22 22:15:27 +0530
committerVijay Dev <vijaydev.cse@gmail.com>2012-06-22 22:15:27 +0530
commit35ee8fa3d8b3ad49179f86af2bec2e53af335ac9 (patch)
tree5929e772a461c683c54c1fd66b303516e5d0df33 /activesupport/lib/active_support
parentfb8cf55868d555b7f06215db5976c8aaf083d30b (diff)
parent6285675db1cf983ba6c15442aedb457c8041f5ee (diff)
downloadrails-35ee8fa3d8b3ad49179f86af2bec2e53af335ac9.tar.gz
rails-35ee8fa3d8b3ad49179f86af2bec2e53af335ac9.tar.bz2
rails-35ee8fa3d8b3ad49179f86af2bec2e53af335ac9.zip
Merge branch 'master' of github.com:lifo/docrails
Diffstat (limited to 'activesupport/lib/active_support')
-rw-r--r--activesupport/lib/active_support/deprecation/method_wrappers.rb20
-rw-r--r--activesupport/lib/active_support/deprecation/reporting.rb11
-rw-r--r--activesupport/lib/active_support/test_case.rb5
-rw-r--r--activesupport/lib/active_support/testing/assertions.rb57
4 files changed, 69 insertions, 24 deletions
diff --git a/activesupport/lib/active_support/deprecation/method_wrappers.rb b/activesupport/lib/active_support/deprecation/method_wrappers.rb
index c5de5e6a95..257b70e34a 100644
--- a/activesupport/lib/active_support/deprecation/method_wrappers.rb
+++ b/activesupport/lib/active_support/deprecation/method_wrappers.rb
@@ -4,6 +4,26 @@ require 'active_support/core_ext/array/extract_options'
module ActiveSupport
module Deprecation
# Declare that a method has been deprecated.
+ #
+ # module Fred
+ # extend self
+ #
+ # def foo; end
+ # def bar; end
+ # def baz; end
+ # end
+ #
+ # ActiveSupport::Deprecation.deprecate_methods(Fred, :foo, bar: :qux, baz: 'use Bar#baz instead')
+ # # => [:foo, :bar, :baz]
+ #
+ # Fred.foo
+ # # => "DEPRECATION WARNING: foo is deprecated and will be removed from Rails 4.1."
+ #
+ # Fred.bar
+ # # => "DEPRECATION WARNING: bar is deprecated and will be removed from Rails 4.1 (use qux instead)."
+ #
+ # Fred.baz
+ # # => "DEPRECATION WARNING: baz is deprecated and will be removed from Rails 4.1 (use Bar#baz instead)."
def self.deprecate_methods(target_module, *method_names)
options = method_names.extract_options!
method_names += options.keys
diff --git a/activesupport/lib/active_support/deprecation/reporting.rb b/activesupport/lib/active_support/deprecation/reporting.rb
index 5d7e241d1a..a1e9618084 100644
--- a/activesupport/lib/active_support/deprecation/reporting.rb
+++ b/activesupport/lib/active_support/deprecation/reporting.rb
@@ -3,7 +3,8 @@ module ActiveSupport
class << self
attr_accessor :silenced
- # Outputs a deprecation warning to the output configured by <tt>ActiveSupport::Deprecation.behavior</tt>
+ # Outputs a deprecation warning to the output configured by
+ # <tt>ActiveSupport::Deprecation.behavior</tt>.
#
# ActiveSupport::Deprecation.warn("something broke!")
# # => "DEPRECATION WARNING: something broke! (called from your_code.rb:1)"
@@ -15,6 +16,14 @@ module ActiveSupport
end
# Silence deprecation warnings within the block.
+ #
+ # ActiveSupport::Deprecation.warn("something broke!")
+ # # => "DEPRECATION WARNING: something broke! (called from your_code.rb:1)"
+ #
+ # ActiveSupport::Deprecation.silence do
+ # ActiveSupport::Deprecation.warn("something broke!")
+ # end
+ # # => nil
def silence
old_silenced, @silenced = @silenced, true
yield
diff --git a/activesupport/lib/active_support/test_case.rb b/activesupport/lib/active_support/test_case.rb
index 14ceb7072e..e2b46a235a 100644
--- a/activesupport/lib/active_support/test_case.rb
+++ b/activesupport/lib/active_support/test_case.rb
@@ -47,6 +47,11 @@ module ActiveSupport
alias :assert_no_match :refute_match
alias :assert_not_same :refute_same
+ # Fails if the block raises an exception.
+ #
+ # assert_nothing_raised do
+ # ...
+ # end
def assert_nothing_raised(*args)
yield
end
diff --git a/activesupport/lib/active_support/testing/assertions.rb b/activesupport/lib/active_support/testing/assertions.rb
index d84595fa8f..ee1a647ed8 100644
--- a/activesupport/lib/active_support/testing/assertions.rb
+++ b/activesupport/lib/active_support/testing/assertions.rb
@@ -3,45 +3,46 @@ require 'active_support/core_ext/object/blank'
module ActiveSupport
module Testing
module Assertions
- # Test numeric difference between the return value of an expression as a result of what is evaluated
- # in the yielded block.
+ # Test numeric difference between the return value of an expression as a
+ # result of what is evaluated in the yielded block.
#
# assert_difference 'Article.count' do
- # post :create, :article => {...}
+ # post :create, article: {...}
# end
#
# An arbitrary expression is passed in and evaluated.
#
# assert_difference 'assigns(:article).comments(:reload).size' do
- # post :create, :comment => {...}
+ # post :create, comment: {...}
# end
#
- # An arbitrary positive or negative difference can be specified. The default is +1.
+ # An arbitrary positive or negative difference can be specified.
+ # The default is <tt>1</tt>.
#
# assert_difference 'Article.count', -1 do
- # post :delete, :id => ...
+ # post :delete, id: ...
# end
#
# An array of expressions can also be passed in and evaluated.
#
- # assert_difference [ 'Article.count', 'Post.count' ], +2 do
- # post :create, :article => {...}
+ # assert_difference [ 'Article.count', 'Post.count' ], 2 do
+ # post :create, article: {...}
# end
#
# A lambda or a list of lambdas can be passed in and evaluated:
#
# assert_difference lambda { Article.count }, 2 do
- # post :create, :article => {...}
+ # post :create, article: {...}
# end
#
# assert_difference [->{ Article.count }, ->{ Post.count }], 2 do
- # post :create, :article => {...}
+ # post :create, article: {...}
# end
#
- # A error message can be specified.
+ # An error message can be specified.
#
- # assert_difference 'Article.count', -1, "An Article should be destroyed" do
- # post :delete, :id => ...
+ # assert_difference 'Article.count', -1, 'An Article should be destroyed' do
+ # post :delete, id: ...
# end
def assert_difference(expression, difference = 1, message = nil, &block)
expressions = Array(expression)
@@ -60,33 +61,43 @@ module ActiveSupport
end
end
- # Assertion that the numeric result of evaluating an expression is not changed before and after
- # invoking the passed in block.
+ # Assertion that the numeric result of evaluating an expression is not
+ # changed before and after invoking the passed in block.
#
# assert_no_difference 'Article.count' do
- # post :create, :article => invalid_attributes
+ # post :create, article: invalid_attributes
# end
#
- # A error message can be specified.
+ # An error message can be specified.
#
- # assert_no_difference 'Article.count', "An Article should not be created" do
- # post :create, :article => invalid_attributes
+ # assert_no_difference 'Article.count', 'An Article should not be created' do
+ # post :create, article: invalid_attributes
# end
def assert_no_difference(expression, message = nil, &block)
assert_difference expression, 0, message, &block
end
- # Test if an expression is blank. Passes if object.blank? is true.
+ # Test if an expression is blank. Passes if <tt>object.blank?</tt> is +true+.
#
- # assert_blank [] # => true
+ # assert_blank [] # => true
+ # assert_blank [[]] # => [[]] is not blank
+ #
+ # An error message can be specified.
+ #
+ # assert_blank [], 'this should be blank'
def assert_blank(object, message=nil)
message ||= "#{object.inspect} is not blank"
assert object.blank?, message
end
- # Test if an expression is not blank. Passes if object.present? is true.
+ # Test if an expression is not blank. Passes if <tt>object.present?</tt> is +true+.
+ #
+ # assert_present({ data: 'x' }) # => true
+ # assert_present({}) # => {} is blank
+ #
+ # An error message can be specified.
#
- # assert_present({:data => 'x' }) # => true
+ # assert_present({ data: 'x' }, 'this should not be blank')
def assert_present(object, message=nil)
message ||= "#{object.inspect} is blank"
assert object.present?, message