aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport
diff options
context:
space:
mode:
authorYves Senn <yves.senn@gmail.com>2013-01-05 17:59:36 +0100
committerYves Senn <yves.senn@gmail.com>2013-01-05 18:04:52 +0100
commit947e1d5e85fa87128b7c5e21da55b92826cd7801 (patch)
tree5d86ab00506c39d154226f177cce36245d2fd440 /activesupport
parentfada87e916dd50eb6766cac919de41f0be2a12bc (diff)
downloadrails-947e1d5e85fa87128b7c5e21da55b92826cd7801.tar.gz
rails-947e1d5e85fa87128b7c5e21da55b92826cd7801.tar.bz2
rails-947e1d5e85fa87128b7c5e21da55b92826cd7801.zip
deprecate `assert_blank` and `assert_present`.
They don't add any benefits over `assert object.blank?` and `assert object.present?`
Diffstat (limited to 'activesupport')
-rw-r--r--activesupport/CHANGELOG.md5
-rw-r--r--activesupport/lib/active_support/testing/assertions.rb2
-rw-r--r--activesupport/test/caching_test.rb6
-rw-r--r--activesupport/test/deprecation_test.rb7
-rw-r--r--activesupport/test/test_test.rb36
5 files changed, 36 insertions, 20 deletions
diff --git a/activesupport/CHANGELOG.md b/activesupport/CHANGELOG.md
index cc23ceb02c..08bec2f4ae 100644
--- a/activesupport/CHANGELOG.md
+++ b/activesupport/CHANGELOG.md
@@ -1,5 +1,10 @@
## Rails 4.0.0 (unreleased) ##
+* Deprecate `assert_present` and `assert_blank` in favor of
+ `assert object.blank?` and `assert object.present?`
+
+ *Yves Senn*
+
* Change `String#to_date` to use `Date.parse`. This gives more consistent error
messages and allows the use of partial dates.
diff --git a/activesupport/lib/active_support/testing/assertions.rb b/activesupport/lib/active_support/testing/assertions.rb
index 88aebba5c5..175f7ffe5a 100644
--- a/activesupport/lib/active_support/testing/assertions.rb
+++ b/activesupport/lib/active_support/testing/assertions.rb
@@ -103,6 +103,7 @@ module ActiveSupport
#
# assert_blank [], 'this should be blank'
def assert_blank(object, message=nil)
+ ActiveSupport::Deprecation.warn('"assert_blank" is deprecated. Please use "assert object.blank?" instead')
message ||= "#{object.inspect} is not blank"
assert object.blank?, message
end
@@ -117,6 +118,7 @@ module ActiveSupport
#
# assert_present({ data: 'x' }, 'this should not be blank')
def assert_present(object, message=nil)
+ ActiveSupport::Deprecation.warn('"assert_present" is deprecated. Please use "assert object.present?" instead')
message ||= "#{object.inspect} is blank"
assert object.present?, message
end
diff --git a/activesupport/test/caching_test.rb b/activesupport/test/caching_test.rb
index a2e2c51283..5158bbc196 100644
--- a/activesupport/test/caching_test.rb
+++ b/activesupport/test/caching_test.rb
@@ -675,7 +675,7 @@ class FileStoreTest < ActiveSupport::TestCase
def test_log_exception_when_cache_read_fails
File.expects(:exist?).raises(StandardError, "failed")
@cache.send(:read_entry, "winston", {})
- assert_present @buffer.string
+ assert @buffer.string.present?
end
end
@@ -897,12 +897,12 @@ class CacheStoreLoggerTest < ActiveSupport::TestCase
def test_logging
@cache.fetch('foo') { 'bar' }
- assert_present @buffer.string
+ assert @buffer.string.present?
end
def test_mute_logging
@cache.mute { @cache.fetch('foo') { 'bar' } }
- assert_blank @buffer.string
+ assert @buffer.string.blank?
end
end
diff --git a/activesupport/test/deprecation_test.rb b/activesupport/test/deprecation_test.rb
index 332100f5a1..c1a468ec86 100644
--- a/activesupport/test/deprecation_test.rb
+++ b/activesupport/test/deprecation_test.rb
@@ -119,9 +119,10 @@ class DeprecationTest < ActiveSupport::TestCase
ActiveSupport::Deprecation.behavior = :silence
behavior = ActiveSupport::Deprecation.behavior.first
- assert_blank capture(:stderr) {
+ stderr_output = capture(:stderr) {
assert_nil behavior.call('Some error!', ['call stack!'])
}
+ assert stderr_output.blank?
end
def test_deprecated_instance_variable_proxy
@@ -254,10 +255,10 @@ class DeprecationTest < ActiveSupport::TestCase
klass::OLD.to_s
end
end
-
+
def test_deprecated_instance_variable_with_instance_deprecator
deprecator = deprecator_with_messages
-
+
klass = Class.new() do
def initialize(deprecator)
@request = ActiveSupport::Deprecation::DeprecatedInstanceVariableProxy.new(self, :request, :@request, deprecator)
diff --git a/activesupport/test/test_test.rb b/activesupport/test/test_test.rb
index 0f93c8b59e..3e6ac811a4 100644
--- a/activesupport/test/test_test.rb
+++ b/activesupport/test/test_test.rb
@@ -92,17 +92,21 @@ class AssertBlankTest < ActiveSupport::TestCase
NOT_BLANK = [ EmptyFalse.new, Object.new, true, 0, 1, 'x', [nil], { nil => 0 } ]
def test_assert_blank_true
- BLANK.each { |v| assert_blank v }
+ BLANK.each { |value|
+ assert_deprecated { assert_blank value }
+ }
end
def test_assert_blank_false
NOT_BLANK.each { |v|
- begin
- assert_blank v
- fail 'should not get to here'
- rescue Exception => e
- assert_match(/is not blank/, e.message)
- end
+ assert_deprecated {
+ begin
+ assert_blank v
+ fail 'should not get to here'
+ rescue Exception => e
+ assert_match(/is not blank/, e.message)
+ end
+ }
}
end
end
@@ -112,17 +116,21 @@ class AssertPresentTest < ActiveSupport::TestCase
NOT_BLANK = [ EmptyFalse.new, Object.new, true, 0, 1, 'x', [nil], { nil => 0 } ]
def test_assert_present_true
- NOT_BLANK.each { |v| assert_present v }
+ NOT_BLANK.each { |v|
+ assert_deprecated { assert_present v }
+ }
end
def test_assert_present_false
BLANK.each { |v|
- begin
- assert_present v
- fail 'should not get to here'
- rescue Exception => e
- assert_match(/is blank/, e.message)
- end
+ assert_deprecated {
+ begin
+ assert_present v
+ fail 'should not get to here'
+ rescue Exception => e
+ assert_match(/is blank/, e.message)
+ end
+ }
}
end
end