diff options
author | Akshay Vishnoi <akshay.vishnoi@vinsol.com> | 2014-06-11 22:53:05 +0530 |
---|---|---|
committer | Akshay Vishnoi <akshay.vishnoi@vinsol.com> | 2014-06-11 22:53:05 +0530 |
commit | 5505131cc1abeb902149c3c21a1a21eab387efe6 (patch) | |
tree | e957923e3f7a9948e4feab00e58a5cdbe3f19e4d /activesupport/test/core_ext/object | |
parent | f3b87be3bb090a9fab006bf03dd37ee40b72735c (diff) | |
download | rails-5505131cc1abeb902149c3c21a1a21eab387efe6.tar.gz rails-5505131cc1abeb902149c3c21a1a21eab387efe6.tar.bz2 rails-5505131cc1abeb902149c3c21a1a21eab387efe6.zip |
Move test for blank.rb under object
Diffstat (limited to 'activesupport/test/core_ext/object')
-rw-r--r-- | activesupport/test/core_ext/object/blank_test.rb | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/activesupport/test/core_ext/object/blank_test.rb b/activesupport/test/core_ext/object/blank_test.rb new file mode 100644 index 0000000000..246bc7fa61 --- /dev/null +++ b/activesupport/test/core_ext/object/blank_test.rb @@ -0,0 +1,36 @@ +# encoding: utf-8 + +require 'abstract_unit' +require 'active_support/core_ext/object/blank' + +class BlankTest < ActiveSupport::TestCase + class EmptyTrue + def empty? + 0 + end + end + + class EmptyFalse + def empty? + nil + end + end + + BLANK = [ EmptyTrue.new, nil, false, '', ' ', " \n\t \r ", ' ', "\u00a0", [], {} ] + NOT = [ EmptyFalse.new, Object.new, true, 0, 1, 'a', [nil], { nil => 0 } ] + + def test_blank + BLANK.each { |v| assert_equal true, v.blank?, "#{v.inspect} should be blank" } + NOT.each { |v| assert_equal false, v.blank?, "#{v.inspect} should not be blank" } + end + + def test_present + BLANK.each { |v| assert_equal false, v.present?, "#{v.inspect} should not be present" } + NOT.each { |v| assert_equal true, v.present?, "#{v.inspect} should be present" } + end + + def test_presence + BLANK.each { |v| assert_equal nil, v.presence, "#{v.inspect}.presence should return nil" } + NOT.each { |v| assert_equal v, v.presence, "#{v.inspect}.presence should return self" } + end +end |