diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2014-06-11 14:26:58 -0300 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2014-06-11 14:26:58 -0300 |
commit | b6d3fa130092070aea9dddaec57b3e85b0e7ecce (patch) | |
tree | e957923e3f7a9948e4feab00e58a5cdbe3f19e4d /activesupport/test/core_ext/object/blank_test.rb | |
parent | f3b87be3bb090a9fab006bf03dd37ee40b72735c (diff) | |
parent | 5505131cc1abeb902149c3c21a1a21eab387efe6 (diff) | |
download | rails-b6d3fa130092070aea9dddaec57b3e85b0e7ecce.tar.gz rails-b6d3fa130092070aea9dddaec57b3e85b0e7ecce.tar.bz2 rails-b6d3fa130092070aea9dddaec57b3e85b0e7ecce.zip |
Merge pull request #15642 from akshay-vishnoi/activesupport
Move tests for blank.rb under Object
Diffstat (limited to 'activesupport/test/core_ext/object/blank_test.rb')
-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 |